Skip to content

Commit

Permalink
tx: cleanup error msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
jochem-brouwer committed Nov 10, 2024
1 parent 8910a40 commit 03b7caf
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 63 deletions.
18 changes: 6 additions & 12 deletions packages/tx/src/1559/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,16 @@ export class FeeMarket1559Tx implements TransactionInterface<TransactionType.Fee
})

if (this.gasLimit * this.maxFeePerGas > MAX_INTEGER) {
const msg = this._errorMsg('gasLimit * maxFeePerGas cannot exceed MAX_INTEGER (2^256-1)')
const msg = Legacy.errorMsg(
this,
'gasLimit * maxFeePerGas cannot exceed MAX_INTEGER (2^256-1)',
)
throw new Error(msg)
}

if (this.maxFeePerGas < this.maxPriorityFeePerGas) {
const msg = this._errorMsg(
const msg = Legacy.errorMsg(
this,
'maxFeePerGas cannot be less than maxPriorityFeePerGas (The total must be the larger of the two)',
)
throw new Error(msg)
Expand Down Expand Up @@ -374,14 +378,4 @@ export class FeeMarket1559Tx implements TransactionInterface<TransactionType.Fee
errorStr += ` maxFeePerGas=${this.maxFeePerGas} maxPriorityFeePerGas=${this.maxPriorityFeePerGas}`
return errorStr
}

/**
* Internal helper function to create an annotated error message
*
* @param msg Base error message
* @hidden
*/
protected _errorMsg(msg: string) {
return Legacy.errorMsg(this, msg)
}
}
12 changes: 1 addition & 11 deletions packages/tx/src/2930/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class AccessList2930Tx implements TransactionInterface<TransactionType.Ac
valueBoundaryCheck({ gasPrice: this.gasPrice })

if (this.gasPrice * this.gasLimit > MAX_INTEGER) {
const msg = this._errorMsg('gasLimit * gasPrice cannot exceed MAX_INTEGER')
const msg = Legacy.errorMsg(this, 'gasLimit * gasPrice cannot exceed MAX_INTEGER')
throw new Error(msg)
}

Expand Down Expand Up @@ -348,14 +348,4 @@ export class AccessList2930Tx implements TransactionInterface<TransactionType.Ac
errorStr += ` gasPrice=${this.gasPrice} accessListCount=${this.accessList?.length ?? 0}`
return errorStr
}

/**
* Internal helper function to create an annotated error message
*
* @param msg Base error message
* @hidden
*/
protected _errorMsg(msg: string) {
return Legacy.errorMsg(this, msg)
}
}
32 changes: 15 additions & 17 deletions packages/tx/src/4844/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,16 @@ export class Blob4844Tx implements TransactionInterface<TransactionType.BlobEIP4
validateNotArray(txData)

if (this.gasLimit * this.maxFeePerGas > MAX_INTEGER) {
const msg = this._errorMsg('gasLimit * maxFeePerGas cannot exceed MAX_INTEGER (2^256-1)')
const msg = Legacy.errorMsg(
this,
'gasLimit * maxFeePerGas cannot exceed MAX_INTEGER (2^256-1)',
)

Check warning on line 138 in packages/tx/src/4844/tx.ts

View check run for this annotation

Codecov / codecov/patch

packages/tx/src/4844/tx.ts#L135-L138

Added lines #L135 - L138 were not covered by tests
throw new Error(msg)
}

if (this.maxFeePerGas < this.maxPriorityFeePerGas) {
const msg = this._errorMsg(
const msg = Legacy.errorMsg(
this,

Check warning on line 144 in packages/tx/src/4844/tx.ts

View check run for this annotation

Codecov / codecov/patch

packages/tx/src/4844/tx.ts#L143-L144

Added lines #L143 - L144 were not covered by tests
'maxFeePerGas cannot be less than maxPriorityFeePerGas (The total must be the larger of the two)',
)
throw new Error(msg)
Expand All @@ -156,24 +160,28 @@ export class Blob4844Tx implements TransactionInterface<TransactionType.BlobEIP4
for (const hash of this.blobVersionedHashes) {
if (hash.length !== 66) {
// 66 is the length of a 32 byte hash as a PrefixedHexString
const msg = this._errorMsg('versioned hash is invalid length')
const msg = Legacy.errorMsg(this, 'versioned hash is invalid length')
throw new Error(msg)
}
if (BigInt(parseInt(hash.slice(2, 4))) !== this.common.param('blobCommitmentVersionKzg')) {
// We check the first "byte" of the hash (starts at position 2 since hash is a PrefixedHexString)
const msg = this._errorMsg('versioned hash does not start with KZG commitment version')
const msg = Legacy.errorMsg(
this,
'versioned hash does not start with KZG commitment version',
)
throw new Error(msg)
}
}
if (this.blobVersionedHashes.length > LIMIT_BLOBS_PER_TX) {
const msg = this._errorMsg(`tx can contain at most ${LIMIT_BLOBS_PER_TX} blobs`)
const msg = Legacy.errorMsg(this, `tx can contain at most ${LIMIT_BLOBS_PER_TX} blobs`)

Check warning on line 176 in packages/tx/src/4844/tx.ts

View check run for this annotation

Codecov / codecov/patch

packages/tx/src/4844/tx.ts#L176

Added line #L176 was not covered by tests
throw new Error(msg)
} else if (this.blobVersionedHashes.length === 0) {
const msg = this._errorMsg(`tx should contain at least one blob`)
const msg = Legacy.errorMsg(this, `tx should contain at least one blob`)
throw new Error(msg)
}
if (this.to === undefined) {
const msg = this._errorMsg(
const msg = Legacy.errorMsg(
this,

Check warning on line 184 in packages/tx/src/4844/tx.ts

View check run for this annotation

Codecov / codecov/patch

packages/tx/src/4844/tx.ts#L183-L184

Added lines #L183 - L184 were not covered by tests
`tx should have a "to" field and cannot be used to create contracts`,
)
throw new Error(msg)
Expand Down Expand Up @@ -449,16 +457,6 @@ export class Blob4844Tx implements TransactionInterface<TransactionType.BlobEIP4
return errorStr
}

/**
* Internal helper function to create an annotated error message
*
* @param msg Base error message
* @hidden
*/
protected _errorMsg(msg: string) {
return Legacy.errorMsg(this, msg)
}

/**
* @returns the number of blobs included with this transaction
*/
Expand Down
21 changes: 8 additions & 13 deletions packages/tx/src/7702/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,16 @@ export class EOACode7702Tx implements TransactionInterface<TransactionType.EOACo
validateNotArray(txData)

if (this.gasLimit * this.maxFeePerGas > MAX_INTEGER) {
const msg = this._errorMsg('gasLimit * maxFeePerGas cannot exceed MAX_INTEGER (2^256-1)')
const msg = Legacy.errorMsg(
this,
'gasLimit * maxFeePerGas cannot exceed MAX_INTEGER (2^256-1)',
)

Check warning on line 137 in packages/tx/src/7702/tx.ts

View check run for this annotation

Codecov / codecov/patch

packages/tx/src/7702/tx.ts#L134-L137

Added lines #L134 - L137 were not covered by tests
throw new Error(msg)
}

if (this.maxFeePerGas < this.maxPriorityFeePerGas) {
const msg = this._errorMsg(
const msg = Legacy.errorMsg(
this,

Check warning on line 143 in packages/tx/src/7702/tx.ts

View check run for this annotation

Codecov / codecov/patch

packages/tx/src/7702/tx.ts#L142-L143

Added lines #L142 - L143 were not covered by tests
'maxFeePerGas cannot be less than maxPriorityFeePerGas (The total must be the larger of the two)',
)
throw new Error(msg)
Expand All @@ -146,7 +150,8 @@ export class EOACode7702Tx implements TransactionInterface<TransactionType.EOACo
Legacy.validateHighS(this)

if (this.to === undefined) {
const msg = this._errorMsg(
const msg = Legacy.errorMsg(
this,

Check warning on line 154 in packages/tx/src/7702/tx.ts

View check run for this annotation

Codecov / codecov/patch

packages/tx/src/7702/tx.ts#L153-L154

Added lines #L153 - L154 were not covered by tests
`tx should have a "to" field and cannot be used to create contracts`,
)
throw new Error(msg)
Expand Down Expand Up @@ -398,14 +403,4 @@ export class EOACode7702Tx implements TransactionInterface<TransactionType.EOACo
errorStr += ` maxFeePerGas=${this.maxFeePerGas} maxPriorityFeePerGas=${this.maxPriorityFeePerGas}`
return errorStr
}

/**
* Internal helper function to create an annotated error message
*
* @param msg Base error message
* @hidden
*/
protected _errorMsg(msg: string) {
return Legacy.errorMsg(this, msg)
}
}
10 changes: 0 additions & 10 deletions packages/tx/src/legacy/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,4 @@ export class LegacyTx implements TransactionInterface<TransactionType.Legacy> {
errorStr += ` gasPrice=${this.gasPrice}`
return errorStr
}

/**
* Internal helper function to create an annotated error message
*
* @param msg Base error message
* @hidden
*/
/*protected _errorMsg(msg: string) {
return Legacy.errorMsg(this, msg)
}*/
}

0 comments on commit 03b7caf

Please sign in to comment.