Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
fix:slow tests sometimes timeout (#537)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmurdoch authored Jan 20, 2020
1 parent 27d59d9 commit 144745a
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions test/gas/gas.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const memdown = require("memdown");
const assert = require("assert");
const bootstrap = require("../helpers/contract/bootstrap");
const confirmGasPrice = require("./lib/confirmGasPrice");
Expand Down Expand Up @@ -65,7 +66,8 @@ describe("Gas", function() {
};

ContractFactory = await bootstrap(factory, ganacheProviderOptions, hardfork);
TestDepth = await bootstrap(testDepth, ganacheProviderOptions, hardfork);
// memdown makes the test that uses TestDepth about 20% faster, so we use it here because CI makes us sad.
TestDepth = await bootstrap(testDepth, Object.assign({ db: memdown() }, ganacheProviderOptions), hardfork);
Donation = await bootstrap(donation, ganacheProviderOptions, hardfork);
Fib = await bootstrap(fib, ganacheProviderOptions, hardfork);
NonZero = await bootstrap(nonZero, ganacheProviderOptions, hardfork);
Expand Down Expand Up @@ -169,7 +171,7 @@ describe("Gas", function() {
if (hardfork !== "byzantium") {
it("Should estimate gas perfectly with EIP150 - DELEGATECALL", async() => {
const { accounts, instance } = TestDepth;
const depth = 10;
const depth = 3;
const promises = Array(depth)
.fill(0)
.map((_, i) => {
Expand Down Expand Up @@ -200,7 +202,7 @@ describe("Gas", function() {
});
});
await Promise.all(promises);
}).timeout(5000);
}).timeout(3000);

it("Should estimate gas perfectly with EIP150 - CREATE2", async() => {
const { accounts, instance, web3 } = Create2;
Expand Down Expand Up @@ -575,15 +577,13 @@ describe("Gas", function() {
assert.strictEqual(receipt.gasUsed, receipt.cumulativeGasUsed);
});

// Unskip this test once byzantium passes
it("account Rsclear/Rselfdestruct/Refunds in gasEstimate w/many transactions in a block", async function() {
const { abi, bytecode, provider } = context;
const options = {
blockTime: 0.5, // seconds
seed,
hardfork
};
const { accounts, web3 } = await initializeTestProvider(options);
const { send, accounts, web3 } = await initializeTestProvider(options);

const transactions = [
{
Expand Down Expand Up @@ -618,7 +618,7 @@ describe("Gas", function() {

// prime storage by making sure it is set to 0
await instance.methods.reset().send({ from: accounts[0], gas: 5000000 });

await send("miner_stop");
const hashes = await Promise.all(
transactions.map((transaction) => {
const promiEvent = web3.eth.sendTransaction(transaction);
Expand All @@ -639,8 +639,16 @@ describe("Gas", function() {

const method = instance.methods.triggerAllRefunds();
const gasEstimate = await method.estimateGas({ from: accounts[0] });

const { gasUsed } = await method.send({ from: accounts[0], gas: gasEstimate });
const prom = method.send({ from: accounts[0], gas: gasEstimate });
await new Promise((resolve) => {
prom.once("transactionHash", resolve);
});
await send("evm_mine");
// web3 doesn't subscribe fast enough to newHeads after issuing the previous send
// we we mine another block to give it an additional newHeads notification. /shrug
await send("evm_mine");
const rec = await prom;
const { gasUsed } = rec;

let transactionCostMinusRefund = gasEstimate - RSELFDESTRUCT_REFUND - RSCLEAR_REFUND;
switch (provider.options.hardfork) {
Expand Down Expand Up @@ -721,7 +729,7 @@ describe("Gas", function() {
currentBlock.gasUsed,
"Total Gas should be equal to the currentBlock.gasUsed"
);
}).timeout(10000);
});

it("clears mapping storage slots", async function() {
const { accounts, instance } = context;
Expand Down

0 comments on commit 144745a

Please sign in to comment.