Skip to content

Commit

Permalink
Add evm estimate gas tests (#282)
Browse files Browse the repository at this point in the history
* Add estimate gas tests

* Fix CI
  • Loading branch information
boundless-forest authored Feb 16, 2023
1 parent a3403ce commit 62c77fd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ on:
- main
paths:
- "**.rs"
- "**.ts"
- "**.toml"
- "**lock"
- "**.json"
Expand Down
33 changes: 32 additions & 1 deletion tests/ethereum/test-gas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import Web3 from "web3";
import { describe } from "mocha";
import { step } from "mocha-steps";
import { expect } from "chai";
import { HOST_HTTP_URL, FAITH, FAITH_P, EXTRINSIC_GAS_LIMIT, customRequest } from "../config";
import {
HOST_HTTP_URL,
FAITH,
FAITH_P,
EXTRINSIC_GAS_LIMIT,
customRequest,
DEFAULT_GAS,
} from "../config";
import { incrementerInfo } from "./contracts/contracts_info";
import { AbiItem } from "web3-utils";

Expand All @@ -12,6 +19,30 @@ describe("Test transaction gas limit", () => {
const inc = new web3.eth.Contract(incrementerInfo.abi as AbiItem[]);
const data = inc.deploy({ data: incrementerInfo.bytecode, arguments: [5] });

it("Test contract create estimate gas", async () => {
expect(
await web3.eth.estimateGas({
from: FAITH,
data: data.encodeABI(),
})
).to.equal(144926);
}).timeout(60000);

it("Test contract call estimate gas", async () => {
let tx = await web3.eth.accounts.signTransaction(
{
from: FAITH,
data: data.encodeABI(),
gas: DEFAULT_GAS,
},
FAITH_P
);
let receipt = await web3.eth.sendSignedTransaction(tx.rawTransaction);
inc.options.address = receipt.contractAddress;

expect(await inc.methods.increment(3).estimateGas()).to.equal(28340);
}).timeout(60000);

it("Test transaction gas limit < `EXTRINSIC_GAS_LIMIT`", async () => {
let tx = await web3.eth.accounts.signTransaction(
{
Expand Down

0 comments on commit 62c77fd

Please sign in to comment.