Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making End-to-End Tests Idempotent #142

Merged
merged 3 commits into from
Nov 6, 2023
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
15 changes: 5 additions & 10 deletions ownership-chain/e2e-tests/tests/test-create-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ describeWithExistingNode("Frontier RPC (Create Collection)", (context) => {
});

step("when collection does not exist owner of call should fail", async function () {
const collectionId = "0";
try {
await contract.methods.ownerOfCollection(collectionId).call();
await contract.methods.ownerOfCollection("1111").call();
expect.fail("Expected error was not thrown"); // Ensure an error is thrown
} catch (error) {
expect(error.message).to.be.eq(
Expand All @@ -34,25 +33,21 @@ describeWithExistingNode("Frontier RPC (Create Collection)", (context) => {
step("when collection is created, it should return owner", async function () {
this.timeout(70000);

const collectionId = "0";

const result = await contract.methods.createCollection(GENESIS_ACCOUNT).send({ from: GENESIS_ACCOUNT, gas: GAS, nonce: nonce++ });
expect(result.status).to.be.eq(true);

const owner = await contract.methods.ownerOfCollection(collectionId).call();
const owner = await contract.methods.ownerOfCollection(result.events.NewCollection.returnValues.collectionId).call();
expect(owner).to.be.eq(GENESIS_ACCOUNT);
});

step("when collection is created event is emitted", async function () {
this.timeout(70000);

const collectionId = "1";

const result = await contract.methods.createCollection(GENESIS_ACCOUNT).send({ from: GENESIS_ACCOUNT, gas: GAS, nonce: nonce++ });
expect(result.status).to.be.eq(true);

expect(Object.keys(result.events).length).to.be.eq(1);
expect(result.events.NewCollection.returnValues.collectionId).to.be.eq(collectionId);
expect(result.events.NewCollection.returnValues.collectionId).not.to.be.NaN;
expect(result.events.NewCollection.returnValues.owner).to.be.eq(GENESIS_ACCOUNT);

// event topics
Expand All @@ -61,7 +56,7 @@ describeWithExistingNode("Frontier RPC (Create Collection)", (context) => {
expect(result.events.NewCollection.raw.topics[1]).to.be.eq(context.web3.utils.padLeft(GENESIS_ACCOUNT.toLowerCase(), 64));

// event data
expect(result.events.NewCollection.raw.data).to.be.eq("0x" + context.web3.utils.padLeft(collectionId, 64));
expect(result.events.NewCollection.raw.data).to.be.eq("0x" + context.web3.utils.padLeft(result.events.NewCollection.returnValues.collectionId, 64));
});

});
2 changes: 1 addition & 1 deletion ownership-chain/e2e-tests/tests/test-evolution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import BN from "bn.js";
describeWithExistingNode("Frontier RPC (Mint and Evolve Assets)", (context) => {
let contract: Contract;
let nonce: number;
let collectionId: number = 0;
let collectionId: number;

beforeEach(async function () {
this.timeout(70000);
Expand Down
4 changes: 3 additions & 1 deletion ownership-chain/e2e-tests/tests/test-web3api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect } from "chai";
import { step } from "mocha-steps";
import BN from "bn.js";

import { RUNTIME_SPEC_NAME, RUNTIME_SPEC_VERSION, RUNTIME_IMPL_VERSION, CHAIN_ID, GENESIS_ACCOUNT, GENESIS_ACCOUNT_BALANCE } from "./config";
import { describeWithExistingNode, customRequest } from "./util";
Expand All @@ -25,6 +26,7 @@ describeWithExistingNode("Frontier RPC (Web3Api)", (context) => {
});

step("genesis balance is setup correctly", async function () {
expect(await context.web3.eth.getBalance(GENESIS_ACCOUNT)).to.equal(GENESIS_ACCOUNT_BALANCE);
const balance = new BN(await context.web3.eth.getBalance(GENESIS_ACCOUNT));
expect(balance.gt(new BN(0))).to.be.eq(true);
});
});