Skip to content

Commit 389957f

Browse files
authored
Change default max transaction fee (#811)
* Edit max transaction fee Signed-off-by: nikolay <[email protected]> * Remove margin Signed-off-by: nikolay <[email protected]> * Add tests Signed-off-by: nikolay <[email protected]> Signed-off-by: nikolay <[email protected]>
1 parent 51ff96b commit 389957f

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

packages/relay/src/lib/clients/sdkClient.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ export class SDKClient {
227227
ethereumTransaction.setEthereumData(ethereumTransactionData.toBytes()).setCallDataFileId(fileId)
228228
}
229229

230+
const tinybarsGasFee = await this.getTinyBarGasFee('eth_sendRawTransaction');
231+
ethereumTransaction.setMaxTransactionFee(Hbar.fromTinybars(Math.floor(tinybarsGasFee * constants.BLOCK_GAS_LIMIT)));
232+
230233
return this.executeTransaction(ethereumTransaction, callerName, requestId);
231234
}
232235

packages/server/tests/acceptance/rpc.spec.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,55 @@ describe('@api RPC Server Acceptance Tests', function () {
690690
expect(info.created_contract_ids.length).to.be.equal(1);
691691
});
692692

693+
it('should execute "eth_sendRawTransaction" and deploy a contract with more than 2 HBAR transaction fee and less than max transaction fee', async function () {
694+
const balanceBefore = await relay.getBalance(accounts[2].wallet.address, 'latest', requestId);
695+
696+
const gasPrice = await relay.gasPrice(requestId);
697+
const transaction = {
698+
type: 2,
699+
chainId: Number(CHAIN_ID),
700+
nonce: await relay.getAccountNonce('0x' + accounts[2].address, requestId),
701+
maxPriorityFeePerGas: gasPrice,
702+
maxFeePerGas: gasPrice,
703+
gasLimit: constants.BLOCK_GAS_LIMIT,
704+
data: '0x' + '00'.repeat(40000)
705+
};
706+
707+
const signedTx = await accounts[2].wallet.signTransaction(transaction);
708+
const transactionHash = await relay.call('eth_sendRawTransaction', [signedTx], requestId);
709+
const info = await mirrorNode.get(`/contracts/results/${transactionHash}`, requestId);
710+
const balanceAfter = await relay.getBalance(accounts[2].wallet.address, 'latest', requestId);
711+
expect(info).to.have.property('contract_id');
712+
expect(info.contract_id).to.not.be.null;
713+
expect(info).to.have.property('created_contract_ids');
714+
expect(info.created_contract_ids.length).to.be.equal(1);
715+
const diffInHbars = (balanceBefore - balanceAfter) / constants.TINYBAR_TO_WEIBAR_COEF / 100_000_000;
716+
expect(diffInHbars).to.be.greaterThan(2);
717+
expect(diffInHbars).to.be.lessThan(gasPrice * constants.BLOCK_GAS_LIMIT / constants.TINYBAR_TO_WEIBAR_COEF / 100_000_000);
718+
});
719+
720+
it('should execute "eth_sendRawTransaction" and deploy a contract with more than max transaction fee', async function () {
721+
const gasPrice = await relay.gasPrice(requestId);
722+
const transaction = {
723+
type: 2,
724+
chainId: Number(CHAIN_ID),
725+
nonce: await relay.getAccountNonce('0x' + accounts[2].address, requestId),
726+
maxPriorityFeePerGas: gasPrice,
727+
maxFeePerGas: gasPrice,
728+
gasLimit: constants.BLOCK_GAS_LIMIT,
729+
data: '0x' + '00'.repeat(60000)
730+
};
731+
732+
const signedTx = await accounts[2].wallet.signTransaction(transaction);
733+
let hasError = false;
734+
try {
735+
await relay.call('eth_sendRawTransaction', [signedTx], requestId);
736+
} catch (e) {
737+
hasError = true;
738+
}
739+
expect(hasError).to.be.true;
740+
});
741+
693742
describe('Prechecks', async function () {
694743
it('should fail "eth_sendRawTransaction" for transaction with incorrect chain_id', async function () {
695744
const transaction = {

0 commit comments

Comments
 (0)