Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ module.exports = {
'ME-',
'ANT-',
'CGARD-',
'CGD-',
'CHALO-',
'CECHO-',
'CSHLD-',
Expand Down
9 changes: 7 additions & 2 deletions modules/abstract-eth/src/lib/transactionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,13 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
this.validateValue(new BigNumber(fee.gasLimit));
}
if (fee.eip1559) {
this.validateValue(new BigNumber(fee.eip1559.maxFeePerGas));
this.validateValue(new BigNumber(fee.eip1559.maxPriorityFeePerGas));
const maxFee = new BigNumber(fee.eip1559.maxFeePerGas);
const priorityFee = new BigNumber(fee.eip1559.maxPriorityFeePerGas);
this.validateValue(maxFee);
this.validateValue(priorityFee);
if (priorityFee.isGreaterThan(maxFee)) {
throw new BuildTransactionError('maxPriorityFeePerGas cannot exceed maxFeePerGas');
}
}
if (fee.gasPrice) {
this.validateValue(new BigNumber(fee.gasPrice));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,17 @@ export async function testRecoveryTransactionWithoutData(txBuilder: TransactionB
await txBuilder.build().should.be.rejectedWith('Invalid transaction: missing contract call data field');
});
}

export function testEip1559PriorityFeeExceedsMaxFee(txBuilder: TransactionBuilder) {
it('fail when maxPriorityFeePerGas exceeds maxFeePerGas', () => {
(() =>
txBuilder.fee({
eip1559: {
maxFeePerGas: '1000000000',
maxPriorityFeePerGas: '9000000000',
},
fee: '1000000000',
gasLimit: '21000',
})).should.throw('maxPriorityFeePerGas cannot exceed maxFeePerGas');
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,26 @@ describe('Eth Transaction builder wallet initialization', function () {
should.doesNotThrow(() => txBuilder.fee({ fee: '10' }));
});

it('eip1559 maxPriorityFeePerGas must not exceed maxFeePerGas', () => {
const txBuilder: any = getBuilder('eth');
assert.throws(
() =>
txBuilder.fee({
fee: '1000000000',
gasLimit: '21000',
eip1559: { maxFeePerGas: '1000000000', maxPriorityFeePerGas: '9000000000' },
}),
/maxPriorityFeePerGas cannot exceed maxFeePerGas/
);
should.doesNotThrow(() =>
txBuilder.fee({
fee: '1000000000',
gasLimit: '21000',
eip1559: { maxFeePerGas: '1000000000', maxPriorityFeePerGas: '1000000000' },
})
);
});

it('a private key', () => {
const txBuilder: any = getBuilder('eth');
assert.throws(() => txBuilder.validateKey({ key: 'abc' }), /Invalid key/);
Expand Down
Loading