Skip to content

Commit

Permalink
chore: use populateTransaction function to get tx object for estimati…
Browse files Browse the repository at this point in the history
…ng gas
  • Loading branch information
blockchainguyy committed Feb 6, 2024
1 parent 557e219 commit 88fd581
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions test/RpcCompatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,31 +240,31 @@ describe('RpcCompatibility', () => {
expect(code).to.equal(TestRpcCompatibility.deployedBytecode);
});

it('should support RPC method eth_estimateGas', async () => {
const newValue = 300;
const txParams = {
to: rpcCompatibilityContract.address,
data: rpcCompatibilityContract.interface.encodeFunctionData('updateValue', [newValue]),
};

const estimatedGas = await provider.send('eth_estimateGas', [txParams]);
const gas = BigNumber.from(estimatedGas);

expect(estimatedGas).to.be.a('string');
expect(gas).to.be.gt(0);
expect(gas).to.be.lt(30000); // report if gas estimation does not matches Ethereum's behavior to adjust core configuration if necessary.
});
describe('eth_estimateGas', () => {
it('should support RPC method eth_estimateGas like ethereum mainnet', async () => {
const newValue = 300;
const txParams = {
to: rpcCompatibilityContract.address,
data: rpcCompatibilityContract.interface.encodeFunctionData('updateValue', [newValue]),
};

it('should send tx with estimated gas', async () => {
const newValue = 300;
const txParams = {
to: rpcCompatibilityContract.address,
data: rpcCompatibilityContract.interface.encodeFunctionData('updateValue', [newValue]),
};
const estimatedGas = await provider.send('eth_estimateGas', [txParams]);
const gas = BigNumber.from(estimatedGas);

const estimatedGas = await provider.estimateGas(txParams);
const receipt = await rpcCompatibilityContract.updateValue(newValue, { gasLimit: estimatedGas }).then((tx) => tx.wait());
await checkReceipt(receipt, newValue);
expect(estimatedGas).to.be.a('string');
expect(gas).to.be.gt(0);
expect(gas).to.be.lt(30000); // report if gas estimation does not matches Ethereum's behavior to adjust core configuration if necessary.
});

it('should send tx with estimated gas', async () => {
const newValue = 300;
const tx = await signer.populateTransaction(await rpcCompatibilityContract.populateTransaction.updateValue(newValue));

const estimatedGas = await provider.estimateGas(tx);
const receipt = await rpcCompatibilityContract.updateValue(newValue, { gasLimit: estimatedGas }).then((tx) => tx.wait());

await checkReceipt(receipt, newValue);
});
});

it('should support RPC method eth_gasPrice', async () => {
Expand Down

0 comments on commit 88fd581

Please sign in to comment.