Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zjb0807 committed Dec 4, 2023
1 parent fb34109 commit 94a5f48
Show file tree
Hide file tree
Showing 10 changed files with 648 additions and 182 deletions.
4 changes: 2 additions & 2 deletions ts-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"run-test": "yarn mocha -r ts-node/register/transpile-only --timeout 50000 --no-warnings"
},
"dependencies": {
"@acala-network/api": "~6.0.0",
"@acala-network/bodhi": "~2.7.8",
"@acala-network/api": "~6.0.4",
"@acala-network/bodhi": "~2.7.15",
"@babel/runtime": "^7.21.5",
"@openzeppelin/contracts": "4.9.3",
"@polkadot/api": "^10.9.1",
Expand Down
2 changes: 1 addition & 1 deletion ts-tests/tests/test-bodhi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ describeWithAcala("Acala RPC (bodhi.js)", (context) => {

expect(data.usedGas.toNumber()).to.be.eq(22038);
expect(data.usedStorage.toNumber()).to.be.eq(0);
expect(data.gasLimit.toNumber()).to.be.eq(22409);
expect(data.gasLimit.toNumber()).to.be.eq(26445);
});
});
59 changes: 59 additions & 0 deletions ts-tests/tests/test-evm-call-fill-block.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { expect } from "chai";
import { step } from "mocha-steps";
import { describeWithAcala } from "./util";
import { BodhiSigner } from "@acala-network/bodhi";
import { submitExtrinsic } from "./util";
import { BigNumber } from "ethers";

describeWithAcala("Acala RPC (EVM call fill block)", (context) => {
let alice: BodhiSigner;
let alice_stash: BodhiSigner;

const FixedU128 = BigNumber.from('1000000000000000000');

before("init wallets", async function () {
[alice, alice_stash] = context.wallets;
});

step("evm create fill block", async function () {
/*
pragma solidity ^0.8.0;
contract Contract {}
*/

const contract = "0x6080604052348015600f57600080fd5b50603f80601d6000396000f3fe6080604052600080fdfea2646970667358221220b9cbc7f3d9528c236f2c6bdf64e25ac8ca17489f9b4e91a6d92bea793883d5d764736f6c63430008020033";

const creates = Array(300).fill(context.provider.api.tx.evm.create(
contract,
0,
2_000_000,
100_000,
[]
));

const beforeHeight = (await context.provider.api.query.system.number()).toNumber();
let nonce = (await context.provider.api.query.system.account(alice.substrateAddress)).nonce.toNumber();

for (const tx of creates) {
await tx.signAndSend(alice.substrateAddress, { nonce: nonce++ });
}

while (true) {
const currentHeight = await context.provider.api.query.system.number();

if (currentHeight.toNumber() > beforeHeight) {
break;
}

setTimeout(() => { }, 1000);
}

let currentBlockHash = await context.provider.api.rpc.chain.getBlockHash(beforeHeight + 1);

const events = await context.provider.api.derive.tx.events(currentBlockHash);

const evmCreateEvents = events.events.filter((item) => context.provider.api.events.evm.Created.is(item.event));

expect(evmCreateEvents.length).to.equal(223);
});
});
59 changes: 59 additions & 0 deletions ts-tests/tests/test-evm-create-fill-block.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { expect } from "chai";
import { step } from "mocha-steps";
import { describeWithAcala } from "./util";
import { BodhiSigner } from "@acala-network/bodhi";
import { submitExtrinsic } from "./util";
import { BigNumber } from "ethers";

describeWithAcala("Acala RPC (EVM create fill block)", (context) => {
let alice: BodhiSigner;
let alice_stash: BodhiSigner;

const FixedU128 = BigNumber.from('1000000000000000000');

before("init wallets", async function () {
[alice, alice_stash] = context.wallets;
});

step("evm create fill block", async function () {
/*
pragma solidity ^0.8.0;
contract Contract {}
*/

const contract = "0x6080604052348015600f57600080fd5b50603f80601d6000396000f3fe6080604052600080fdfea2646970667358221220b9cbc7f3d9528c236f2c6bdf64e25ac8ca17489f9b4e91a6d92bea793883d5d764736f6c63430008020033";

const creates = Array(300).fill(context.provider.api.tx.evm.create(
contract,
0,
2_000_000,
100_000,
[]
));

const beforeHeight = (await context.provider.api.query.system.number()).toNumber();
let nonce = (await context.provider.api.query.system.account(alice.substrateAddress)).nonce.toNumber();

for (const tx of creates) {
await tx.signAndSend(alice.substrateAddress, { nonce: nonce++ });
}

while (true) {
const currentHeight = await context.provider.api.query.system.number();

if (currentHeight.toNumber() > beforeHeight) {
break;
}

setTimeout(() => { }, 1000);
}

let currentBlockHash = await context.provider.api.rpc.chain.getBlockHash(beforeHeight + 1);

const events = await context.provider.api.derive.tx.events(currentBlockHash);

const evmCreateEvents = events.events.filter((item) => context.provider.api.events.evm.Created.is(item.event));

expect(evmCreateEvents.length).to.equal(223);
});
});
132 changes: 0 additions & 132 deletions ts-tests/tests/test-evm-fill-block.ts

This file was deleted.

2 changes: 1 addition & 1 deletion ts-tests/tests/test-gas-limit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describeWithAcala("Acala RPC (GasLimit)", (context) => {
const contract = await deployContract(alice, Factory);
// limited by used_storage
const result = await contract.createContractLoop(350);
expect(result.gasLimit.toNumber()).to.be.eq(28954750);
expect(result.gasLimit.toNumber()).to.be.eq(3570298622);

const result2 = await contract.incrementLoop(8480);
expect(result2.gasLimit.toNumber()).to.be.eq(29788849);
Expand Down
6 changes: 3 additions & 3 deletions ts-tests/tests/test-gas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describeWithAcala("Acala RPC (Gas)", (context) => {
from: alice.getAddress(),
data: "0x" + Block.bytecode,
});
expect(gas.toNumber()).to.be.eq(11301014);
expect(gas.toNumber()).to.be.eq(11301114);
});

it("eth_estimateResources for contract creation", async function () {
Expand All @@ -28,7 +28,7 @@ describeWithAcala("Acala RPC (Gas)", (context) => {
});

expect(data.usedGas.toNumber()).to.be.eq(251726);
expect(data.gasLimit.toNumber()).to.be.eq(273373);
expect(data.gasLimit.toNumber()).to.be.eq(302071);
expect(data.usedStorage.toNumber()).to.be.eq(10921);
});

Expand All @@ -46,7 +46,7 @@ describeWithAcala("Acala RPC (Gas)", (context) => {
);

expect(data.usedGas.toNumber()).to.be.eq(22038);
expect(data.gasLimit.toNumber()).to.be.eq(22409);
expect(data.gasLimit.toNumber()).to.be.eq(26445);
expect(data.usedStorage.toNumber()).to.be.eq(0);
});
});
4 changes: 2 additions & 2 deletions ts-tests/tests/test-precompiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ describeWithAcala("Acala RPC (Precompile)", (context) => {
from: await alice.getAddress(),
confirmations: 0,
nonce: 1,
// gasLimit: BigNumber.from("28535"),
// gasLimit: BigNumber.from("100200"),
// gasPrice: BigNumber.from("1"),
//data: "",
// value: BigNumber.from(0),
chainId: 595,
});
expect(res.gasLimit.toNumber()).to.eq(28535)
expect(res.gasLimit.toNumber()).to.eq(100200)
expect(res.gasPrice.toNumber()).to.eq(1)
expect(res.value.toNumber()).to.eq(0)

Expand Down
16 changes: 12 additions & 4 deletions ts-tests/tests/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const ACALA_BUILD = process.env.ACALA_BUILD || "debug";
export const BINARY_PATH = `../target/${ACALA_BUILD}/acala`;
export const SPAWNING_TIME = 120000;

export async function startAcalaNode(autoClaim = true): Promise<{ binary: ChildProcess; } & TestContext> {
export async function startAcalaNode(sealing = true, autoClaim = true): Promise<{ binary: ChildProcess; } & TestContext> {
const RPC_PORT = await getPort({ port: getPort.makeRange(9944, 9999) });
const P2P_PORT = await getPort({ port: getPort.makeRange(30333, 30433) });

Expand All @@ -30,7 +30,6 @@ export async function startAcalaNode(autoClaim = true): Promise<{ binary: ChildP
`--dev`,
`-lruntime=debug`,
`-levm=debug`,
`--instant-sealing`,
`--no-telemetry`,
`--no-prometheus`,
`--port=${P2P_PORT}`,
Expand All @@ -42,6 +41,11 @@ export async function startAcalaNode(autoClaim = true): Promise<{ binary: ChildP
`--keep-blocks=archive`,
`--tmp`,
];

if (sealing) {
args.push(`--instant-sealing`);
}

const binary = spawn(cmd, args);

binary.on("error", (err) => {
Expand Down Expand Up @@ -70,7 +74,7 @@ export async function startAcalaNode(autoClaim = true): Promise<{ binary: ChildP
console.log(chunk.toString());
}
binaryLogs.push(chunk);
if (chunk.toString().match(/best: #0/)) {
if (chunk.toString().match(/best: #/)) {
try {
const { provider, wallets } = await getTestUtils(`ws://127.0.0.1:${RPC_PORT}`, autoClaim);

Expand Down Expand Up @@ -103,10 +107,14 @@ export function describeWithAcala(title: string, cb: (context: TestContext) => v
console.log('starting acala node ...')
this.timeout(SPAWNING_TIME);

const sealing =
title !== 'Acala RPC (EVM create fill block)' &&
title !== 'Acala RPC (EVM call fill block)';

const autoClaim =
title !== 'Acala RPC (Claim Account Eip712)' &&
title !== 'Acala RPC (Block)';
const init = await startAcalaNode(autoClaim);
const init = await startAcalaNode(sealing, autoClaim);

context.provider = init.provider,
context.wallets = init.wallets,
Expand Down
Loading

0 comments on commit 94a5f48

Please sign in to comment.