Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defaultTransactionTypeParser Refactor #6102

Merged
merged 19 commits into from
May 20, 2023

Conversation

spacesailor24
Copy link
Contributor

closes #6065

@spacesailor24 spacesailor24 added the 4.x 4.0 related label May 18, 2023
@spacesailor24 spacesailor24 self-assigned this May 18, 2023
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented May 18, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7f676c9
Status: ✅  Deploy successful!
Preview URL: https://d3df5286.web3-js-docs.pages.dev
Branch Preview URL: https://wyatt-4-x-6065-transaction-t.web3-js-docs.pages.dev

View logs

@github-actions
Copy link

github-actions bot commented May 18, 2023

Bundle Stats

Hey there, this message comes from a github action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Asset Old size New size Diff Diff %
Total 643 KB 645 KB 1.81 KB 0.28%
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

No assets were smaller

Unchanged

Asset Old size New size Diff Diff %
web3.min.js 627 KB 628 KB 1.81 KB 0.29%
../lib/commonjs/index.d.ts 8.43 KB 8.43 KB 0 0.00%
../lib/commonjs/accounts.d.ts 3.67 KB 3.67 KB 0 0.00%
../lib/commonjs/types.d.ts 2.37 KB 2.37 KB 0 0.00%
../lib/commonjs/abi.d.ts 1000 bytes 1000 bytes 0 0.00%
../lib/commonjs/web3.d.ts 808 bytes 808 bytes 0 0.00%
../lib/commonjs/eth.exports.d.ts 280 bytes 280 bytes 0 0.00%
../lib/commonjs/providers.exports.d.ts 148 bytes 148 bytes 0 0.00%
../lib/commonjs/version.d.ts 60 bytes 60 bytes 0 0.00%

@codecov
Copy link

codecov bot commented May 18, 2023

Codecov Report

Merging #6102 (7f676c9) into 4.x (ed5a7f8) will decrease coverage by 0.53%.
The diff coverage is 97.95%.

Additional details and impacted files
@@            Coverage Diff             @@
##              4.x    #6102      +/-   ##
==========================================
- Coverage   87.94%   87.41%   -0.53%     
==========================================
  Files         199      199              
  Lines        7572     7612      +40     
  Branches     2055     2063       +8     
==========================================
- Hits         6659     6654       -5     
- Misses        913      958      +45     
Flag Coverage Δ
UnitTests 87.41% <97.95%> (-0.53%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
web3 ∅ <ø> (∅)
web3-core ∅ <ø> (∅)
web3-errors ∅ <ø> (∅)
web3-eth ∅ <ø> (∅)
web3-eth-abi ∅ <ø> (∅)
web3-eth-accounts ∅ <ø> (∅)
web3-eth-contract ∅ <ø> (∅)
web3-eth-ens ∅ <ø> (∅)
web3-eth-iban ∅ <ø> (∅)
web3-eth-personal ∅ <ø> (∅)
web3-net ∅ <ø> (∅)
web3-providers-http ∅ <ø> (∅)
web3-providers-ipc ∅ <ø> (∅)
web3-providers-ws ∅ <ø> (∅)
web3-rpc-methods ∅ <ø> (∅)
web3-utils ∅ <ø> (∅)
web3-validator ∅ <ø> (∅)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The types for these tests were updated to 0x0 because they all use gasLimit

Comment on lines 24 to 58
// undefined is treated as null for JSON schema validator
const type0x0TransactionSchema = {
type: 'object',
properties: {
accessList: {
type: 'null',
},
maxFeePerGas: {
type: 'null',
},
maxPriorityFeePerGas: {
type: 'null',
},
},
};
const type0x1TransactionSchema = {
type: 'object',
properties: {
maxFeePerGas: {
type: 'null',
},
maxPriorityFeePerGas: {
type: 'null',
},
},
};
const type0x2TransactionSchema = {
type: 'object',
properties: {
gasPrice: {
type: 'null',
},
},
};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe these should go in schemas.ts since they aren't complete schemas of the transaction object

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just tiny suggestion, if its Tx type schema like ( TypeSchemaFor0x1Tx , TypeSchemaFor0x2Tx ) it will more readable and can be moved to schema file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdevcs
I'll rename them to: transactionType0x0Schema, but I don't think they should be moved to schemas.ts because then they'll be exported from web3-eth package and these type shouldn't be any where else as they are an incomplete representation of what a typed transaction is (i.e. they don't contain the other fields of a transaction)

I experimented with doing something like:

export const transactionType0x0Schema = {
	type: 'object',
	properties: {
		...transactionSchema.properties,
		accessList: {
			type: 'null',
		},
		maxFeePerGas: {
			type: 'null',
		},
		maxPriorityFeePerGas: {
			type: 'null',
		},
	}
};

but now the function validateTxTypeAndHandleErrors in defaultTransactionTypeParser is validating the entire transaction object which is out of scope of defaultTransactionTypeParser. This function is only concerned about returning the detected tx type, or throwing an error for an invalid tx object regarding types and their appropriate properties, not the rest of the tx object

I think it's okay to keep these type specified here so that they're are exported from the package and because they are only used for defaultTransactionTypeParser

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because then they'll be exported from web3-eth package

that make sense to not export it, with current code that you added.

@jdevcs
Copy link
Contributor

jdevcs commented May 19, 2023

Thanks @spacesailor24

@@ -74,6 +74,7 @@ export const ERR_TX_DATA_AND_INPUT = 425;
export const ERR_TX_POLLING_TIMEOUT = 426;
export const ERR_TX_RECEIPT_MISSING_OR_BLOCKHASH_NULL = 427;
export const ERR_TX_RECEIPT_MISSING_BLOCK_NUMBER = 428;
export const ERR_TX_INVALID_PROPERTIES_FOR_TYPE = 429;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ok that we have the same code for two different errors?
ERR_TX_INVALID_PROPERTIES_FOR_TYPE & ERR_TX_LOCAL_WALLET_NOT_AVAILABLE

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, good catch, updated here

@spacesailor24 spacesailor24 requested review from avkos and jdevcs May 19, 2023 19:58
Copy link
Contributor

@avkos avkos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
BTW. Would be great to increase test coverage, thanks

@spacesailor24
Copy link
Contributor Author

LGTM. BTW. Would be great to increase test coverage, thanks

@avkos This is the only line not covered by tests, and it's sorta irrelevant as it just a catch-all for any error that not a validation error

image

@djrann13 djrann13 linked an issue May 20, 2023 that may be closed by this pull request
@djrann13 djrann13 removed a link to an issue May 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x 4.0 related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

transaction type error
4 participants