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

Add test to ensure gas estimate is sufficient #1010

Merged
merged 4 commits into from
Nov 19, 2021
Merged
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
36 changes: 18 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/tests/test-gas/test-gas-contract-creation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ describeDevMoonbeam("Estimate Gas - Contract creation", (context) => {
from: GENESIS_ACCOUNT,
data: contract.byteCode,
})
).to.equal(127607);
).to.equal(150926);
Copy link
Collaborator

Choose a reason for hiding this comment

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

@tgmichel we should have followed your instinct and spend more time on it when you found this when unexpected :)

});
});
25 changes: 25 additions & 0 deletions tests/tests/test-gas/test-gas-estimation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import chaiAsPromised from "chai-as-promised";

import { describeDevMoonbeam } from "../../util/setup-dev-tests";

import { TransactionReceipt } from "web3-core";
import { getCompiled } from "../../util/contracts";
import { GENESIS_ACCOUNT } from "../../util/constants";

import { createContract } from "../../util/transactions";
import { Contract } from "web3-eth-contract";

Expand Down Expand Up @@ -53,3 +57,24 @@ describeDevMoonbeam("Estimate Gas - Multiply", (context) => {
).to.be.rejectedWith("gas required exceeds allowance 21900");
});
});

describeDevMoonbeam("Estimate Gas - Supplied estimate is sufficient", (context) => {
it("should estimate sufficient gas for creation", async function () {
const contract = await getCompiled("Incrementer");
// ask RPC for an gas estimate of deploying this contract
const estimate = await context.web3.eth.estimateGas({
from: GENESIS_ACCOUNT,
data: contract.byteCode,
});

// attempt a transaction with our estimated gas
const { rawTx } = await createContract(context.web3, "Incrementer", { gas: estimate });
const { txResults } = await context.createBlock({ transactions: [rawTx] });
const receipt: TransactionReceipt = await context.web3.eth.getTransactionReceipt(
txResults[0].result
);

// the transaction should succeed because the estimate should have been sufficient
expect(receipt.status).to.equal(true);
});
});