Skip to content
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
834 changes: 604 additions & 230 deletions tests/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
"author": "",
"license": "ISC",
"dependencies": {
"@polkadot/api": "^6.8.1",
"@polkadot/types": "^6.8.1",
"@polkadot/api": "^6.10.3",
"@polkadot/types": "^6.10.3",
"@substrate/txwrapper-core": "^1.2.17",
"@substrate/txwrapper-registry": "^1.2.17",
"@substrate/txwrapper-substrate": "^1.2.17",
Expand Down
6 changes: 3 additions & 3 deletions tests/tests/test-balance/test-balance-extrinsics.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { expect } from "chai";

import { describeDevMoonbeam } from "../../util/setup-dev-tests";
import { describeDevMoonbeam, describeDevMoonbeamAllEthTxTypes } from "../../util/setup-dev-tests";
import { createTransfer } from "../../util/transactions";

describeDevMoonbeam("Balance extrinsics", (context) => {
describeDevMoonbeamAllEthTxTypes("Balance extrinsics", (context) => {
it("should appear after transfer", async function () {
const testAddress = "0x1111111111111111111111111111111111111111";
await context.createBlock({
transactions: [await createTransfer(context.web3, testAddress, 512)],
transactions: [await createTransfer(context, testAddress, 512)],
});

const blockHash = await context.polkadotApi.rpc.chain.getBlockHash(1);
Expand Down
10 changes: 5 additions & 5 deletions tests/tests/test-balance/test-balance-transfer.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { expect } from "chai";
import { GENESIS_ACCOUNT, GENESIS_ACCOUNT_BALANCE } from "../../util/constants";

import { describeDevMoonbeam } from "../../util/setup-dev-tests";
import { describeDevMoonbeam, describeDevMoonbeamAllEthTxTypes } from "../../util/setup-dev-tests";
import { createTransfer } from "../../util/transactions";

describeDevMoonbeam("Balance transfer cost", (context) => {
describeDevMoonbeamAllEthTxTypes("Balance transfer cost", (context) => {
it("should cost 21000 * 1_000_000_000", async function () {
const testAccount = "0x1111111111111111111111111111111111111111";
await context.createBlock({
transactions: [await createTransfer(context.web3, testAccount, 0)],
transactions: [await createTransfer(context, testAccount, 0)],
});

expect(await context.web3.eth.getBalance(GENESIS_ACCOUNT, 1)).to.equal(
Expand All @@ -17,11 +17,11 @@ describeDevMoonbeam("Balance transfer cost", (context) => {
});
});

describeDevMoonbeam("Balance transfer", (context) => {
describeDevMoonbeamAllEthTxTypes("Balance transfer", (context) => {
const TEST_ACCOUNT = "0x1111111111111111111111111111111111111111";
before("Create block with transfer to test account of 512", async () => {
await context.createBlock({
transactions: [await createTransfer(context.web3, TEST_ACCOUNT, 512)],
transactions: [await createTransfer(context, TEST_ACCOUNT, 512)],
});
});

Expand Down
12 changes: 6 additions & 6 deletions tests/tests/test-block/test-block-gas.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { expect } from "chai";
import { describeDevMoonbeam } from "../../util/setup-dev-tests";
import { describeDevMoonbeam, describeDevMoonbeamAllEthTxTypes } from "../../util/setup-dev-tests";

import { EXTRINSIC_GAS_LIMIT } from "../../util/constants";
import { createContract } from "../../util/transactions";
import { customWeb3Request } from "../../util/providers";

describeDevMoonbeam("Block Gas - Limit", (context) => {
describeDevMoonbeamAllEthTxTypes("Block Gas - Limit", (context) => {
it("should be allowed to the max block gas", async function () {
const { rawTx } = await createContract(context.web3, "TestContract", {
const { rawTx } = await createContract(context, "TestContract", {
gas: EXTRINSIC_GAS_LIMIT,
});
const { txResults } = await context.createBlock({ transactions: [rawTx] });
Expand All @@ -18,9 +18,9 @@ describeDevMoonbeam("Block Gas - Limit", (context) => {
});
});

describeDevMoonbeam("Block Gas - Limit", (context) => {
describeDevMoonbeamAllEthTxTypes("Block Gas - Limit", (context) => {
it("should fail setting it over the max block gas", async function () {
const { rawTx } = await createContract(context.web3, "TestContract", {
const { rawTx } = await createContract(context, "TestContract", {
gas: EXTRINSIC_GAS_LIMIT + 1,
});

Expand All @@ -34,7 +34,7 @@ describeDevMoonbeam("Block Gas - Limit", (context) => {
describeDevMoonbeam("Block Gas - Limit", (context) => {
// TODO: Joshy to fix block gas access in smart contract
it.skip("should be accessible within a contract", async function () {
const { contract, rawTx } = await createContract(context.web3, "CheckBlockVariables");
const { contract, rawTx } = await createContract(context, "CheckBlockVariables");
await context.createBlock({ transactions: [rawTx] });

expect((await contract.methods.gaslimit().call()) !== "0").to.eq(true);
Expand Down
14 changes: 7 additions & 7 deletions tests/tests/test-contract/test-contract-creation.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { expect } from "chai";
import { describeDevMoonbeam } from "../../util/setup-dev-tests";
import { describeDevMoonbeam, describeDevMoonbeamAllEthTxTypes } from "../../util/setup-dev-tests";
import { createContract } from "../../util/transactions";

describeDevMoonbeam("Contract creation", (context) => {
describeDevMoonbeamAllEthTxTypes("Contract creation", (context) => {
it("should return the transaction hash", async () => {
const { rawTx } = await createContract(context.web3, "TestContract");
const { rawTx } = await createContract(context, "TestContract");
const { txResults } = await context.createBlock({ transactions: [rawTx] });

expect(
Expand All @@ -14,15 +14,15 @@ describeDevMoonbeam("Contract creation", (context) => {
});
});

describeDevMoonbeam("Contract creation", (context) => {
describeDevMoonbeamAllEthTxTypes("Contract creation", (context) => {
it("should not contain contract at genesis", async function () {
const { contract, rawTx } = await createContract(context.web3, "TestContract");
const { contract } = await createContract(context, "TestContract");
expect(await context.web3.eth.getCode(contract.options.address)).to.deep.equal("0x");
});

it("should store the code on chain", async function () {
const { contract, rawTx } = await createContract(context.web3, "TestContract");
const { txResults } = await context.createBlock({ transactions: [rawTx] });
const { contract, rawTx } = await createContract(context, "TestContract");
await context.createBlock({ transactions: [rawTx] });

expect(await context.web3.eth.getCode(contract.options.address)).to.deep.equal(
"0x608060405234801561001057600080fd5b506004361061002b5760003560e01c8063c6888fa114610030575b" +
Expand Down
12 changes: 6 additions & 6 deletions tests/tests/test-contract/test-contract-error.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { expect } from "chai";

import { TransactionReceipt } from "web3-core";
import { describeDevMoonbeam } from "../../util/setup-dev-tests";
import { describeDevMoonbeam, describeDevMoonbeamAllEthTxTypes } from "../../util/setup-dev-tests";

import { createContract, createContractExecution } from "../../util/transactions";

describeDevMoonbeam("Contract loop error", (context) => {
describeDevMoonbeamAllEthTxTypes("Contract loop error", (context) => {
it("should return OutOfGas on inifinite loop call", async function () {
const { contract, rawTx } = await createContract(context.web3, "InfiniteContract");
const { contract, rawTx } = await createContract(context, "InfiniteContract");
await context.createBlock({ transactions: [rawTx] });

await contract.methods
Expand All @@ -20,11 +20,11 @@ describeDevMoonbeam("Contract loop error", (context) => {
});
});

describeDevMoonbeam("Contract loop error", (context) => {
describeDevMoonbeamAllEthTxTypes("Contract loop error", (context) => {
it("should fail with OutOfGas on infinite loop transaction", async function () {
const { contract, rawTx } = await createContract(context.web3, "InfiniteContract");
const { contract, rawTx } = await createContract(context, "InfiniteContract");
const infiniteTx = await createContractExecution(
context.web3,
context,
{
contract,
contractCall: contract.methods.infinite(),
Expand Down
13 changes: 6 additions & 7 deletions tests/tests/test-contract/test-contract-incr-loop.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import { expect } from "chai";
import { describeDevMoonbeam } from "../../util/setup-dev-tests";
import { describeDevMoonbeam, describeDevMoonbeamAllEthTxTypes } from "../../util/setup-dev-tests";
import { createContract, createContractExecution } from "../../util/transactions";

describeDevMoonbeam("Contract loop creation", (context) => {
describeDevMoonbeamAllEthTxTypes("Contract loop creation", (context) => {
it("Should be initialized at 0", async () => {
const { contract, rawTx } = await createContract(context.web3, "TestContractIncr");
const { contract, rawTx } = await createContract(context, "TestContractIncr");
await context.createBlock({ transactions: [rawTx] });

expect(await contract.methods.count().call()).to.eq("0");
});
});

describeDevMoonbeam("Contract loop increment", (context) => {
describeDevMoonbeamAllEthTxTypes("Contract loop increment", (context) => {
it("should increment contract state", async function () {
const { contract, rawTx } = await createContract(context.web3, "TestContractIncr");
const { contract, rawTx, contractAddress } = await createContract(context, "TestContractIncr");
await context.createBlock({ transactions: [rawTx] });

await context.createBlock({
transactions: [
await createContractExecution(context.web3, {
await createContractExecution(context, {
contract,
contractCall: contract.methods.incr(),
}),
Expand Down
8 changes: 4 additions & 4 deletions tests/tests/test-contract/test-contract-loop-cost.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from "chai";
import { describeDevMoonbeam } from "../../util/setup-dev-tests";
import { describeDevMoonbeam, describeDevMoonbeamAllEthTxTypes } from "../../util/setup-dev-tests";
import { createContract, createContractExecution } from "../../util/transactions";

[
Expand All @@ -16,13 +16,13 @@ import { createContract, createContractExecution } from "../../util/transactions
gas: 1269054,
},
].forEach(({ loop, gas }) => {
describeDevMoonbeam("Contract loop", (context) => {
describeDevMoonbeamAllEthTxTypes("Contract loop", (context) => {
it(`should consume ${gas} for ${loop} loop`, async function () {
const { contract, rawTx } = await createContract(context.web3, "FiniteLoopContract");
const { contract, rawTx } = await createContract(context, "FiniteLoopContract");
await context.createBlock({ transactions: [rawTx] });
await context.createBlock({
transactions: [
await createContractExecution(context.web3, {
await createContractExecution(context, {
contract,
contractCall: contract.methods.incr(loop),
}),
Expand Down
7 changes: 4 additions & 3 deletions tests/tests/test-contract/test-contract-methods.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { expect } from "chai";
import { describeDevMoonbeam } from "../../util/setup-dev-tests";
import { describeDevMoonbeam, describeDevMoonbeamAllEthTxTypes } from "../../util/setup-dev-tests";
import { createContract } from "../../util/transactions";
import { Contract } from "web3-eth-contract";

describeDevMoonbeam("Contract creation", (context) => {
describeDevMoonbeamAllEthTxTypes("Contract creation", (context) => {
let testContract: Contract;
let testContractTx: string;

before("Setup: Create the contract", async function () {
const { contract, rawTx } = await createContract(context.web3, "TestContract");
const { contract, rawTx } = await createContract(context, "TestContract");
const { txResults } = await context.createBlock({ transactions: [rawTx] });
testContract = contract;
testContractTx = txResults[0].result;
Expand All @@ -29,6 +29,7 @@ describeDevMoonbeam("Contract creation", (context) => {
expect(await testContract.methods.multiply(3).call()).to.equal("21");
});

// TODO: when web3 supports eip1559 and eip2930, this test should be adapted
it("should fail for call method with missing parameters", async function () {
// Create a fake contract based on origin deployed contract.
// It make the multiply method supposed to have 0 arguments
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/test-contract/test-contract-variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describeDevMoonbeam("Block Contract - Block variables", (context) => {
let blockContract: Contract;

before("Setup: Creating contract with block variables", async function () {
const { contract, rawTx } = await createContract(context.web3, "CheckBlockVariables");
const { contract, rawTx } = await createContract(context, "CheckBlockVariables");
await context.createBlock({ transactions: [rawTx] });
blockContract = contract;
});
Expand Down
6 changes: 3 additions & 3 deletions tests/tests/test-deal-fees.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { expect } from "chai";
import Keyring from "@polkadot/keyring";
import { TREASURY_ACCOUNT } from "../util/constants";
import { describeDevMoonbeam } from "../util/setup-dev-tests";
import { describeDevMoonbeamAllEthTxTypes } from "../util/setup-dev-tests";
import { createTransfer } from "../util/transactions";

describeDevMoonbeam("20% of the fees should go to treasury", (context) => {
describeDevMoonbeamAllEthTxTypes("20% of the fees should go to treasury", (context) => {
const TEST_ACCOUNT = "0x1111111111111111111111111111111111111111";
const keyring = new Keyring({ type: "ethereum" });

Expand All @@ -14,7 +14,7 @@ describeDevMoonbeam("20% of the fees should go to treasury", (context) => {

// We make an ethereum transaction, 20% of the fees should go to treasury.
await context.createBlock({
transactions: [await createTransfer(context.web3, TEST_ACCOUNT, 128)],
transactions: [await createTransfer(context, TEST_ACCOUNT, 128)],
});
expect(await context.web3.eth.getBalance(TREASURY_ACCOUNT, 1)).to.equal("4200000000000");
});
Expand Down
10 changes: 5 additions & 5 deletions tests/tests/test-ethpool/test-ethpool-multiple.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai";
import { customWeb3Request } from "../../util/providers";
import { describeDevMoonbeam } from "../../util/setup-dev-tests";
import { describeDevMoonbeamAllEthTxTypes } from "../../util/setup-dev-tests";
import { createContract } from "../../util/transactions";
import { Transaction } from "web3-core";

Expand All @@ -14,13 +14,13 @@ import { Transaction } from "web3-core";
- We resolve multiple promises in parallel that will read from this collection on the rpc-side
- We can get the final transaction data once it leaves the pending collection
*/
describeDevMoonbeam("EthPool - Multiple pending transactions", (context) => {
describeDevMoonbeamAllEthTxTypes("EthPool - Multiple pending transactions", (context) => {
let txHashes: string[];

before("Setup: Sending 10 transactions", async function () {
txHashes = await Promise.all(
new Array(10).map(async (_, i) => {
const { rawTx } = await createContract(context.web3, "TestContract", { nonce: i });
const { rawTx } = await createContract(context, "TestContract", { nonce: i });
return (await customWeb3Request(context.web3, "eth_sendRawTransaction", [rawTx])).result;
})
);
Expand Down Expand Up @@ -58,13 +58,13 @@ describeDevMoonbeam("EthPool - Multiple pending transactions", (context) => {
});
});

describeDevMoonbeam("EthPool - Multiple produced transactions", (context) => {
describeDevMoonbeamAllEthTxTypes("EthPool - Multiple produced transactions", (context) => {
let txHashes: string[];

before("Setup: Sending 10 transactions", async function () {
txHashes = await Promise.all(
new Array(10).map(async (_, i) => {
const { rawTx } = await createContract(context.web3, "TestContract", { nonce: i });
const { rawTx } = await createContract(context, "TestContract", { nonce: i });
return (await customWeb3Request(context.web3, "eth_sendRawTransaction", [rawTx])).result;
})
);
Expand Down
12 changes: 6 additions & 6 deletions tests/tests/test-ethpool/test-ethpool-nonce-future.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { expect } from "chai";

import { createContract, createTransfer } from "../../util/transactions";
import { describeDevMoonbeam } from "../../util/setup-dev-tests";
import { describeDevMoonbeam, describeDevMoonbeamAllEthTxTypes } from "../../util/setup-dev-tests";
import { customWeb3Request } from "../../util/providers";

describeDevMoonbeam("EthPool - Future Ethereum transaction", (context) => {
describeDevMoonbeamAllEthTxTypes("EthPool - Future Ethereum transaction", (context) => {
let txHash;
before("Setup: Create a block with transaction", async () => {
const { rawTx } = await createContract(context.web3, "TestContract", {
const { rawTx } = await createContract(context, "TestContract", {
nonce: 1,
});
const { txResults } = await context.createBlock({ transactions: [rawTx] });
Expand All @@ -27,10 +27,10 @@ describeDevMoonbeam("EthPool - Future Ethereum transaction", (context) => {
});
});

describeDevMoonbeam("EthPool - Future Ethereum transaction", (context) => {
describeDevMoonbeamAllEthTxTypes("EthPool - Future Ethereum transaction", (context) => {
let txHash;
before("Setup: Create a block with transaction", async () => {
const { rawTx } = await createContract(context.web3, "TestContract", {
const { rawTx } = await createContract(context, "TestContract", {
nonce: 1,
});
const { txResults } = await context.createBlock({ transactions: [rawTx] });
Expand All @@ -41,7 +41,7 @@ describeDevMoonbeam("EthPool - Future Ethereum transaction", (context) => {
// Create block including transaction with nonce 0
await context.createBlock({
transactions: [
await createTransfer(context.web3, "0x1111111111111111111111111111111111111111", 512, {
await createTransfer(context, "0x1111111111111111111111111111111111111111", 512, {
nonce: 0,
}),
],
Expand Down
6 changes: 3 additions & 3 deletions tests/tests/test-event.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { expect } from "chai";
import { describeDevMoonbeam } from "../util/setup-dev-tests";
import { describeDevMoonbeamAllEthTxTypes } from "../util/setup-dev-tests";
import { createContract } from "../util/transactions";
import { GENESIS_ACCOUNT } from "../util/constants";

describeDevMoonbeam("Event - Contract", (context) => {
describeDevMoonbeamAllEthTxTypes("Event - Contract", (context) => {
it("should contain event", async function () {
const { rawTx } = await createContract(context.web3, "SingleEventContract", {
const { rawTx } = await createContract(context, "SingleEventContract", {
from: GENESIS_ACCOUNT,
});
const { txResults } = await context.createBlock({ transactions: [rawTx] });
Expand Down
6 changes: 3 additions & 3 deletions tests/tests/test-existential-deposit.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { expect } from "chai";
import { describeDevMoonbeam } from "../util/setup-dev-tests";
import { describeDevMoonbeam, describeDevMoonbeamAllEthTxTypes } from "../util/setup-dev-tests";
import { createTransfer } from "../util/transactions";
import { GENESIS_ACCOUNT, GENESIS_ACCOUNT_BALANCE } from "../util/constants";

describeDevMoonbeam("Existential Deposit", (context) => {
describeDevMoonbeamAllEthTxTypes("Existential Deposit", (context) => {
it("should be disabled (no reaped account on 0 balance)", async function () {
await context.createBlock({
transactions: [
await createTransfer(
context.web3,
context,
"0x1111111111111111111111111111111111111111",
GENESIS_ACCOUNT_BALANCE - 21000n * 1_000_000_000n,
{
Expand Down
Loading