Skip to content

Commit

Permalink
allow block mode customization on e2e tests (#904)
Browse files Browse the repository at this point in the history
* refactor e2e tests into separate folder depending on block-mode

* improve

* improve

* enable conditional on mining mode on hardhat

* improve condition

* initial e2e multiple txs test

* fix

* fix naming
  • Loading branch information
gabriel-aranha-cw authored May 23, 2024
1 parent d97f6a8 commit acaaba7
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 40 deletions.
54 changes: 42 additions & 12 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,64 @@ on:
- 'Cargo.toml'

jobs:
e2e-stratus:
name: E2E Stratus in-memory
e2e-automine-stratus:
name: E2E Automine Stratus in-memory
uses: ./.github/workflows/_setup-e2e.yml
with:
justfile_recipe: 'e2e-stratus'
justfile_recipe: 'e2e-stratus automine'

concurrency:
group: ${{ github.workflow }}-inmemory-${{ github.ref || github.run_id }}
group: ${{ github.workflow }}-automine-inmemory-${{ github.ref || github.run_id }}
cancel-in-progress: true

e2e-stratus-postgres:
name: E2E Stratus Postgres
e2e-automine-stratus-postgres:
name: E2E Automine Stratus Postgres
uses: ./.github/workflows/_setup-e2e.yml
with:
justfile_recipe: 'e2e-stratus-postgres'
justfile_recipe: 'e2e-stratus-postgres automine'

concurrency:
group: ${{ github.workflow }}-postgres-${{ github.ref || github.run_id }}
group: ${{ github.workflow }}-automine-postgres-${{ github.ref || github.run_id }}
cancel-in-progress: true

e2e-stratus-rocks:
name: E2E Stratus Rocks
e2e-automine-stratus-rocks:
name: E2E Automine Stratus Rocks
uses: ./.github/workflows/_setup-e2e.yml
with:
justfile_recipe: 'e2e-stratus-rocks'
justfile_recipe: 'e2e-stratus-rocks automine'

concurrency:
group: ${{ github.workflow }}-rocks-${{ github.ref || github.run_id }}
group: ${{ github.workflow }}-automine-rocks-${{ github.ref || github.run_id }}
cancel-in-progress: true

e2e-external-stratus:
name: E2E External Stratus in-memory
uses: ./.github/workflows/_setup-e2e.yml
with:
justfile_recipe: 'e2e-stratus external'

concurrency:
group: ${{ github.workflow }}-external-inmemory-${{ github.ref || github.run_id }}
cancel-in-progress: true

e2e-external-stratus-postgres:
name: E2E External Stratus Postgres
uses: ./.github/workflows/_setup-e2e.yml
with:
justfile_recipe: 'e2e-stratus-postgres external'

concurrency:
group: ${{ github.workflow }}-external-postgres-${{ github.ref || github.run_id }}
cancel-in-progress: true

e2e-external-stratus-rocks:
name: E2E External Stratus Rocks
uses: ./.github/workflows/_setup-e2e.yml
with:
justfile_recipe: 'e2e-stratus-rocks external'

concurrency:
group: ${{ github.workflow }}-external-rocks-${{ github.ref || github.run_id }}
cancel-in-progress: true

e2e-clock-stratus:
Expand Down
3 changes: 2 additions & 1 deletion e2e/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const config: HardhatUserConfig = {
gasPrice: 0,
initialBaseFeePerGas: 0,
mining: {
auto: true,
auto: process.env.BLOCK_MODE === 'automine',
interval: process.env.BLOCK_MODE === 'automine' ? undefined : 0
},
accounts: {
mnemonic: ACCOUNTS_MNEMONIC,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect } from "chai";
import { Block } from "web3-types";

import { ALICE, BOB } from "./helpers/account";
import { isStratus } from "./helpers/network";
import { ALICE, BOB } from "../helpers/account";
import { isStratus } from "../helpers/network";
import {
CHAIN_ID,
CHAIN_ID_DEC,
Expand All @@ -15,7 +15,7 @@ import {
sendReset,
subscribeAndGetEvent,
subscribeAndGetEventWithContract,
} from "./helpers/rpc";
} from "../helpers/rpc";

describe("JSON-RPC", () => {
describe("State", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { expect } from "chai";

import { TestContractBalances, TestContractCounter } from "../typechain-types";
import { ALICE, BOB, CHARLIE, randomAccounts } from "./helpers/account";
import { ALICE, BOB, CHARLIE, randomAccounts } from "../helpers/account";
import {
TX_PARAMS,
deployTestContractBalances,
deployTestContractCounter,
sendGetNonce,
sendRawTransactions,
sendReset,
} from "./helpers/rpc";
} from "../helpers/rpc";

describe("Transaction: parallel TestContractBalances", async () => {
var _contract: TestContractBalances;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from "chai";

import { TEST_ACCOUNTS, randomAccounts } from "./helpers/account";
import { sendGetBalance, sendRawTransactions, sendReset } from "./helpers/rpc";
import { TEST_ACCOUNTS, randomAccounts } from "../helpers/account";
import { sendGetBalance, sendRawTransactions, sendReset } from "../helpers/rpc";

describe("Transaction: parallel transfer", () => {
it("Resets blockchain", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from "chai";

import { TestContractBalances } from "../typechain-types";
import { CHARLIE } from "./helpers/account";
import { CHARLIE } from "../helpers/account";
import {
calculateSlotPosition,
CHAIN_ID,
Expand All @@ -14,7 +14,7 @@ import {
sendReset,
toHex,
toPaddedHex,
} from "./helpers/rpc";
} from "../helpers/rpc";
import { Transaction } from "web3-types";
import { network } from "hardhat";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { expect } from "chai";
import { keccak256 } from "ethers";
import { Block, Transaction, TransactionReceipt } from "web3-types";

import { ALICE, Account, BOB, randomAccounts } from "./helpers/account";
import { isStratus } from "./helpers/network";
import { ALICE, Account, BOB, randomAccounts } from "../helpers/account";
import { isStratus } from "../helpers/network";
import {
CHAIN_ID,
HASH_EMPTY_TRANSACTIONS,
Expand All @@ -19,7 +19,7 @@ import {
sendGetBalance,
sendRawTransaction,
sendReset,
} from "./helpers/rpc";
} from "../helpers/rpc";

describe("Transaction: serial transfer", () => {
var _tx: Transaction;
Expand Down
51 changes: 51 additions & 0 deletions e2e/test/external/e2e-multiple-tx.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { expect } from "chai";

import { TEST_ACCOUNTS, randomAccounts } from "../helpers/account";
import { send, sendGetBalance, sendRawTransactions, sendReset } from "../helpers/rpc";

describe("Multiple Transactions Per Block", () => {
it("Resets blockchain", async () => {
await sendReset();
});
it("Send multiple transactions and mine block", async () => {
const counterParty = randomAccounts(1)[0];
expect(await sendGetBalance(counterParty.address)).eq(0);

let expectedCounterPartyBalance = 0;
const signedTxs = [];
for (let i = 0; i < TEST_ACCOUNTS.length; i++) {
const amount = i + 1;
const account = TEST_ACCOUNTS[i];
signedTxs.push(await account.signWeiTransfer(counterParty.address, amount));
expectedCounterPartyBalance += amount;
}

for (const account of randomAccounts(100)) {
signedTxs.push(await account.signWeiTransfer(counterParty.address, 0));
}

const txHashes = await sendRawTransactions(signedTxs);

const latestBlockBeforeMining = await send('eth_getBlockByNumber', ['latest', true]);

// mine the block
await send("evm_mine", []);

// get the latest block after mining
const latestBlockAfterMining = await send('eth_getBlockByNumber', ['latest', true]);

// check if block was mined
expect(latestBlockAfterMining).to.exist;

// check if mined block is different from the latest block before mining
expect(latestBlockAfterMining.hash).to.not.equal(latestBlockBeforeMining.hash);

// check if all transactions are in the block
for (let txHash of txHashes) {
expect(latestBlockAfterMining.transactions.map((tx: any) => tx.hash)).to.include(txHash);
}

// check counterParty balance
expect(await sendGetBalance(counterParty.address)).eq(expectedCounterPartyBalance);
});
});
30 changes: 15 additions & 15 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ test-int name="'*'":
# ------------------------------------------------------------------------------

# E2E: Execute Hardhat tests in the specified network
e2e network="stratus" test="":
e2e network="stratus" block-mode="automine" test="":
#!/bin/bash
if [ -d e2e ]; then
cd e2e
Expand All @@ -170,76 +170,76 @@ e2e network="stratus" test="":
fi

if [ -z "{{test}}" ]; then
npx hardhat test test/*.test.ts --network {{network}}
npx hardhat test test/{{block-mode}}/*.test.ts --network {{network}}
else
npx hardhat test test/*.test.ts --network {{network}} --grep "{{test}}"
npx hardhat test test/{{block-mode}}/*.test.ts --network {{network}} --grep "{{test}}"
fi

# E2E: Starts and execute Hardhat tests in Hardhat
e2e-hardhat test="":
e2e-hardhat block-mode="automine" test="":
#!/bin/bash
if [ -d e2e ]; then
cd e2e
fi

echo "-> Starting Hardhat"
npx hardhat node &
BLOCK_MODE={{block-mode}} npx hardhat node &

echo "-> Waiting Hardhat to start"
wait-service --tcp localhost:8545 -- echo

echo "-> Running E2E tests"
just e2e hardhat {{test}}
just e2e hardhat {{block-mode}} {{test}}

echo "-> Killing Hardhat"
killport 8545

# E2E: Starts and execute Hardhat tests in Stratus
e2e-stratus test="":
e2e-stratus block-mode="automine" test="":
#!/bin/bash
if [ -d e2e ]; then
cd e2e
fi

echo "-> Starting Stratus"
just build || exit 1
just run -a 0.0.0.0:3000 > stratus.log &
just run -a 0.0.0.0:3000 --block-mode {{block-mode}} > stratus.log &

echo "-> Waiting Stratus to start"
wait-service --tcp 0.0.0.0:3000 -t {{ wait_service_timeout }} -- echo

echo "-> Running E2E tests"
just e2e stratus {{test}}
just e2e stratus {{block-mode}} {{test}}
result_code=$?

echo "-> Killing Stratus"
killport 3000
exit $result_code

# E2E: Starts and execute Hardhat tests in Stratus
e2e-stratus-rocks test="":
e2e-stratus-rocks block-mode="automine" test="":
#!/bin/bash
if [ -d e2e ]; then
cd e2e
fi

echo "-> Starting Stratus"
just build || exit 1
just run -a 0.0.0.0:3000 --perm-storage=rocks > stratus.log &
just run -a 0.0.0.0:3000 --block-mode {{block-mode}} --perm-storage=rocks > stratus.log &

echo "-> Waiting Stratus to start"
wait-service --tcp 0.0.0.0:3000 -t {{ wait_service_timeout }} -- echo

echo "-> Running E2E tests"
just e2e stratus {{test}}
just e2e stratus {{block-mode}} {{test}}
result_code=$?

echo "-> Killing Stratus"
killport 3000
exit $result_code

# E2E: Starts and execute Hardhat tests in Stratus
e2e-stratus-postgres test="":
e2e-stratus-postgres block-mode="automine" test="":
#!/bin/bash
if [ -d e2e ]; then
cd e2e
Expand All @@ -254,13 +254,13 @@ e2e-stratus-postgres test="":

echo "-> Starting Stratus"
just build || exit 1
just run -a 0.0.0.0:3000 --perm-storage {{ database_url }} > stratus.log &
just run -a 0.0.0.0:3000 --block-mode {{block-mode}} --perm-storage {{ database_url }} > stratus.log &

echo "-> Waiting Stratus to start"
wait-service --tcp 0.0.0.0:3000 -t {{ wait_service_timeout }} -- echo

echo "-> Running E2E tests"
just e2e stratus {{test}}
just e2e stratus {{block-mode}} {{test}}
result_code=$?

echo "-> Killing Stratus"
Expand Down

0 comments on commit acaaba7

Please sign in to comment.