Skip to content

Commit

Permalink
Use this.ethereumPairs instead of the plain address along tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tsenovilla committed Nov 12, 2024
1 parent e7bf14a commit d317c71
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 78 deletions.
19 changes: 8 additions & 11 deletions e2e-tests/tests/test-create-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {
EVOLUTION_COLLECTION_FACTORY_CONTRACT_ADDRESS,
EVOLUTION_COLLECTION_FACTORY_ABI,
GAS_PRICE,
FAITH,
FAITH_PRIVATE_KEY,
REVERT_BYTECODE,
SELECTOR_LOG_NEW_COLLECTION,
} from "./config";
Expand All @@ -24,25 +22,24 @@ describeWithExistingNode("Frontier RPC (Create Collection)", function () {
EVOLUTION_COLLECTION_FACTORY_ABI,
EVOLUTION_COLLECTION_FACTORY_CONTRACT_ADDRESS,
{
from: FAITH,
from: this.ethereumPairs.faith.address,
gasPrice: GAS_PRICE,
}
);
this.context.web3.eth.accounts.wallet.add(FAITH_PRIVATE_KEY);
});

step("when collection is created, it should return owner", async function () {
const collectionContract = await createCollection(this.context);
testCollectionContract = collectionContract;

const owner = await collectionContract.methods.owner().call();
expect(owner).to.be.eq(FAITH);
expect(owner).to.be.eq(this.ethereumPairs.faith.address);
});

step("when collection is created event is emitted", async function () {
const estimatedGas = await contract.methods.createCollection(FAITH).estimateGas();
const result = await contract.methods.createCollection(FAITH).send({
from: FAITH,
const estimatedGas = await contract.methods.createCollection(this.ethereumPairs.faith.address).estimateGas();
const result = await contract.methods.createCollection(this.ethereumPairs.faith.address).send({
from: this.ethereumPairs.faith.address,
gas: estimatedGas,
gasPrice: GAS_PRICE,
});
Expand All @@ -53,13 +50,13 @@ describeWithExistingNode("Frontier RPC (Create Collection)", function () {
true
);
testCollectionAddress = result.events.NewCollection.returnValues._collectionAddress;
expect(result.events.NewCollection.returnValues._owner).to.be.eq(FAITH);
expect(result.events.NewCollection.returnValues._owner).to.be.eq(this.ethereumPairs.faith.address);

// event topics
expect(result.events.NewCollection.raw.topics.length).to.be.eq(2);
expect(result.events.NewCollection.raw.topics[0]).to.be.eq(SELECTOR_LOG_NEW_COLLECTION);
expect(result.events.NewCollection.raw.topics[1]).to.be.eq(
this.context.web3.utils.padLeft(FAITH.toLowerCase(), 64)
this.context.web3.utils.padLeft(this.ethereumPairs.faith.address.toLowerCase(), 64)
);

// event data
Expand All @@ -75,6 +72,6 @@ describeWithExistingNode("Frontier RPC (Create Collection)", function () {
expect(await this.context.web3.eth.getCode(testCollectionAddress)).to.be.eq(REVERT_BYTECODE);

// non-contract address doesn't have any code
expect(await this.context.web3.eth.getCode(FAITH)).to.be.eq("0x");
expect(await this.context.web3.eth.getCode(this.ethereumPairs.faith.address)).to.be.eq("0x");
});
});
39 changes: 19 additions & 20 deletions e2e-tests/tests/test-evolution.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createCollection, describeWithExistingNode, slotAndOwnerToTokenId } from "./util";
import {
FAITH,
SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI,
SELECTOR_LOG_MINTED_WITH_EXTERNAL_TOKEN_URI,
SELECTOR_LOG_OWNERSHIP_TRANSFERRED,
Expand Down Expand Up @@ -32,14 +31,14 @@ describeWithExistingNode("Frontier RPC (Mint and Evolve Assets)", function () {

step("when asset is minted it should return token uri", async function () {
const slot = "0";
const to = FAITH;
const to = this.ethereumPairs.faith.address;
const tokenURI = "https://example.com";

let nonce = await this.context.web3.eth.getTransactionCount(FAITH);
let nonce = await this.context.web3.eth.getTransactionCount(this.ethereumPairs.faith.address);
const estimatedGas = await collectionContract.methods.mintWithExternalURI(to, slot, tokenURI).estimateGas();
const result = await collectionContract.methods
.mintWithExternalURI(to, slot, tokenURI)
.send({ from: FAITH, gas: estimatedGas, nonce: nonce++ });
.send({ from: this.ethereumPairs.faith.address, gas: estimatedGas, nonce: nonce++ });
expect(result.status).to.be.eq(true);

const tokenId = result.events.MintedWithExternalURI.returnValues._tokenId;
Expand All @@ -49,7 +48,7 @@ describeWithExistingNode("Frontier RPC (Mint and Evolve Assets)", function () {

step("given slot and owner it should return token id", async function () {
const slot = "1";
const to = FAITH;
const to = this.ethereumPairs.faith.address;

const tokenId = slotAndOwnerToTokenId(slot, to);
expect(tokenId).to.be.eq("000000000000000000000001c0f0f4ab324c46e55d02d0033343b4be8a55532d");
Expand All @@ -59,13 +58,13 @@ describeWithExistingNode("Frontier RPC (Mint and Evolve Assets)", function () {

step("when asset is minted it should emit an event", async function () {
const slot = "22";
const to = FAITH;
const to = this.ethereumPairs.faith.address;
const tokenURI = "https://example.com";

const estimatedGas = await collectionContract.methods.mintWithExternalURI(to, slot, tokenURI).estimateGas();
const result = await collectionContract.methods
.mintWithExternalURI(to, slot, tokenURI)
.send({ from: FAITH, gas: estimatedGas });
.send({ from: this.ethereumPairs.faith.address, gas: estimatedGas });
expect(result.status).to.be.eq(true);

expect(Object.keys(result.events).length).to.be.eq(1);
Expand All @@ -82,7 +81,7 @@ describeWithExistingNode("Frontier RPC (Mint and Evolve Assets)", function () {
expect(result.events.MintedWithExternalURI.raw.topics.length).to.be.eq(2);
expect(result.events.MintedWithExternalURI.raw.topics[0]).to.be.eq(SELECTOR_LOG_MINTED_WITH_EXTERNAL_TOKEN_URI);
expect(result.events.MintedWithExternalURI.raw.topics[1]).to.be.eq(
this.context.web3.utils.padLeft(FAITH.toLowerCase(), 64)
this.context.web3.utils.padLeft(this.ethereumPairs.faith.address.toLowerCase(), 64)
);

// event data
Expand All @@ -96,7 +95,7 @@ describeWithExistingNode("Frontier RPC (Mint and Evolve Assets)", function () {

step("when asset is evolved it should change token uri", async function () {
const slot = "22";
const to = FAITH;
const to = this.ethereumPairs.faith.address;
const tokenURI = "https://example.com";
const newTokenURI = "https://new_example.com";
const tokenId = slotAndOwnerToTokenId(slot, to);
Expand All @@ -105,15 +104,15 @@ describeWithExistingNode("Frontier RPC (Mint and Evolve Assets)", function () {
var estimatedGas = await collectionContract.methods.mintWithExternalURI(to, slot, tokenURI).estimateGas();
const mintingResult = await collectionContract.methods
.mintWithExternalURI(to, slot, tokenURI)
.send({ from: FAITH, gas: estimatedGas });
.send({ from: this.ethereumPairs.faith.address, gas: estimatedGas });
expect(mintingResult.status).to.be.eq(true);

estimatedGas = await collectionContract.methods
.evolveWithExternalURI(tokenIdDecimal, newTokenURI)
.estimateGas();
const evolvingResult = await collectionContract.methods
.evolveWithExternalURI(tokenIdDecimal, newTokenURI)
.send({ from: FAITH, gas: estimatedGas });
.send({ from: this.ethereumPairs.faith.address, gas: estimatedGas });
expect(evolvingResult.status).to.be.eq(true);

const got = await collectionContract.methods.tokenURI(tokenIdDecimal).call();
Expand All @@ -122,7 +121,7 @@ describeWithExistingNode("Frontier RPC (Mint and Evolve Assets)", function () {

step("when asset is evolved it should emit an event", async function () {
const slot = "22";
const to = FAITH;
const to = this.ethereumPairs.faith.address;
const tokenURI = "https://example.com";
const newTokenURI = "https://new_example.com";
const tokenId = slotAndOwnerToTokenId(slot, to);
Expand All @@ -131,15 +130,15 @@ describeWithExistingNode("Frontier RPC (Mint and Evolve Assets)", function () {
var estimatedGas = await collectionContract.methods.mintWithExternalURI(to, slot, tokenURI).estimateGas();
const mintingResult = await collectionContract.methods
.mintWithExternalURI(to, slot, tokenURI)
.send({ from: FAITH, gas: estimatedGas });
.send({ from: this.ethereumPairs.faith.address, gas: estimatedGas });
expect(mintingResult.status).to.be.eq(true);

estimatedGas = await collectionContract.methods
.evolveWithExternalURI(tokenIdDecimal, newTokenURI)
.estimateGas();
const evolvingResult = await collectionContract.methods
.evolveWithExternalURI(tokenIdDecimal, newTokenURI)
.send({ from: FAITH, gas: estimatedGas });
.send({ from: this.ethereumPairs.faith.address, gas: estimatedGas });
expect(evolvingResult.status).to.be.eq(true);

expect(Object.keys(evolvingResult.events).length).to.be.eq(1);
Expand Down Expand Up @@ -172,18 +171,18 @@ describeWithExistingNode("Frontier RPC (Transfer Ownership)", function () {
step("when is transferred owner should change and emit an event", async function () {
const newOwner = "0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac";

expect(await collectionContract.methods.owner().call()).to.be.eq(FAITH);
expect(await collectionContract.methods.owner().call()).to.be.eq(this.ethereumPairs.faith.address);
const estimatedGas = await collectionContract.methods.transferOwnership(newOwner).estimateGas();
const tranferringResult = await collectionContract.methods
.transferOwnership(newOwner)
.send({ from: FAITH, gas: estimatedGas });
.send({ from: this.ethereumPairs.faith.address, gas: estimatedGas });
expect(tranferringResult.status).to.be.eq(true);
expect(await collectionContract.methods.owner().call()).to.be.eq(newOwner);

expect(Object.keys(tranferringResult.events).length).to.be.eq(1);

// data returned within the event
expect(tranferringResult.events.OwnershipTransferred.returnValues._previousOwner).to.be.eq(FAITH);
expect(tranferringResult.events.OwnershipTransferred.returnValues._previousOwner).to.be.eq(this.ethereumPairs.faith.address);
expect(tranferringResult.events.OwnershipTransferred.returnValues._newOwner).to.be.eq(newOwner);

// event topics
Expand All @@ -192,7 +191,7 @@ describeWithExistingNode("Frontier RPC (Transfer Ownership)", function () {
SELECTOR_LOG_OWNERSHIP_TRANSFERRED
);
expect(tranferringResult.events.OwnershipTransferred.raw.topics[1]).to.be.eq(
this.context.web3.utils.padLeft(FAITH.toLowerCase(), 64)
this.context.web3.utils.padLeft(this.ethereumPairs.faith.address.toLowerCase(), 64)
);
expect(tranferringResult.events.OwnershipTransferred.raw.topics[2]).to.be.eq(
this.context.web3.utils.padLeft(newOwner.toLowerCase(), 64)
Expand All @@ -201,8 +200,8 @@ describeWithExistingNode("Frontier RPC (Transfer Ownership)", function () {
expect(tranferringResult.events.OwnershipTransferred.raw.data).to.be.eq("0x");

try {
const estimatedGas = await collectionContract.methods.transferOwnership(FAITH).estimateGas();
await collectionContract.methods.transferOwnership(FAITH).send({ from: FAITH, gas: estimatedGas });
const estimatedGas = await collectionContract.methods.transferOwnership(this.ethereumPairs.faith.address).estimateGas();
await collectionContract.methods.transferOwnership(this.ethereumPairs.faith.address).send({ from: this.ethereumPairs.faith.address, gas: estimatedGas });
expect.fail("Expected error was not thrown"); // Ensure an error is thrown
} catch (error) {
expect(error.message).to.eq(
Expand Down
30 changes: 11 additions & 19 deletions e2e-tests/tests/test-staking.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import { describeWithExistingNode } from "./util";
import {
ALITH,
STAKING_ABI,
STAKING_CONTRACT_ADDRESS,
UNIT,
FAITH_PRIVATE_KEY,
FAITH,
BALTATHAR,
BALTATHAR_PRIVATE_KEY,
} from "./config";
import { expect } from "chai";
import Contract from "web3-eth-contract";
import { step } from "mocha-steps";
import { Keyring } from "@polkadot/api";

describeWithExistingNode(
"Frontier RPC (Staking)",
Expand All @@ -21,10 +15,8 @@ describeWithExistingNode(

before(async function () {
contract = new this.context.web3.eth.Contract(STAKING_ABI, STAKING_CONTRACT_ADDRESS, {
from: ALITH,
from: this.ethereumPairs.alith.address,
});
this.context.web3.eth.accounts.wallet.add(BALTATHAR_PRIVATE_KEY);
this.context.web3.eth.accounts.wallet.add(FAITH_PRIVATE_KEY);
});

step("Faith can join as candidate", async function () {
Expand All @@ -37,7 +29,7 @@ describeWithExistingNode(
console.log("transaction failed", error);
});

expect(await contract.methods.isCandidate(FAITH).call()).to.be.eq(false);
expect(await contract.methods.isCandidate(this.ethereumPairs.faith.address).call()).to.be.eq(false);
const candidateCount = await contract.methods.candidateCount().call();
expect((await this.context.web3.eth.getBlock("latest")).baseFeePerGas.toString()).to.be.eq(
await this.context.web3.eth.getGasPrice()
Expand All @@ -46,24 +38,24 @@ describeWithExistingNode(
.joinCandidates(BigInt(20000) * UNIT, candidateCount)
.estimateGas();
const gasPrice = (await this.context.web3.eth.getGasPrice()) + 1; // if we don't add +1 tx never gets included in the block
let nonce = await this.context.web3.eth.getTransactionCount(FAITH);
let nonce = await this.context.web3.eth.getTransactionCount(this.ethereumPairs.faith.address);
const result = await contract.methods
.joinCandidates(BigInt(20000) * UNIT, candidateCount)
.send({ from: FAITH, gas: estimatedGas, gasPrice, nonce: nonce++ });
.send({ from: this.ethereumPairs.faith.address, gas: estimatedGas, gasPrice, nonce: nonce++ });
expect(result.status).to.be.eq(true);
expect(await contract.methods.isCandidate(FAITH).call()).to.be.eq(true);
expect(await contract.methods.isCandidate(this.ethereumPairs.faith.address).call()).to.be.eq(true);
});

step("Baltathar can delegate to Faith", async function () {
expect(await contract.methods.isDelegator(BALTATHAR).call()).to.be.eq(false);
let nonce = await this.context.web3.eth.getTransactionCount(BALTATHAR);
expect(await contract.methods.isDelegator(this.ethereumPairs.baltathar.address).call()).to.be.eq(false);
let nonce = await this.context.web3.eth.getTransactionCount(this.ethereumPairs.baltathar.address);
const gasPrice = (await this.context.web3.eth.getGasPrice()) + 1; // if we don't add +1 tx never gets included in the block
const estimatedGas = await contract.methods.delegate(FAITH, BigInt(1000) * UNIT, 0, 0).estimateGas();
const estimatedGas = await contract.methods.delegate(this.ethereumPairs.faith.address, BigInt(1000) * UNIT, 0, 0).estimateGas();
const result = await contract.methods
.delegate(FAITH, BigInt(1000) * UNIT, 0, 0)
.send({ from: BALTATHAR, gas: estimatedGas, gasPrice, nonce: nonce++ });
.delegate(this.ethereumPairs.faith.address, BigInt(1000) * UNIT, 0, 0)
.send({ from: this.ethereumPairs.baltathar.address, gas: estimatedGas, gasPrice, nonce: nonce++ });
expect(result.status).to.be.eq(true);
expect(await contract.methods.isDelegator(BALTATHAR).call()).to.be.eq(true);
expect(await contract.methods.isDelegator(this.ethereumPairs.baltathar.address).call()).to.be.eq(true);
});
},
true
Expand Down
Loading

0 comments on commit d317c71

Please sign in to comment.