-
Notifications
You must be signed in to change notification settings - Fork 6
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
Addition of End-to-End Tests for Evolution Flow #138
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
96ec9bd
refactor test-create-collection
magecnion 80dfbcb
remove unnecesary await
magecnion 99b73a8
add e2e-test to evolution flow
magecnion 91df6bd
remove unnecesary file
magecnion 880ede6
update select evolved asset event
magecnion ac2424c
fix selector evolved asset event
magecnion 8c96b71
fix test
magecnion 9777280
fix test
magecnion 1070094
fix test
magecnion 18090ff
fix test
magecnion 0dc100c
Merge branch 'main' into feature/add_evolution_e2e_test
asiniscalchi b225c61
change requested
magecnion d6ef3dd
Merge branch 'main' of github.com:freeverseio/laos into feature/add_e…
magecnion e5f01cb
Merge branch 'feature/add_evolution_e2e_test' of github.com:freeverse…
magecnion 85efd1d
change requested
magecnion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,28 @@ | ||
export const NODE_BINARY_NAME = "laos-ownership"; | ||
import LaosEvolution from "../build/contracts/LaosEvolution.json"; | ||
import { AbiItem } from "web3-utils"; | ||
import BN from "bn.js"; | ||
|
||
|
||
// Node config | ||
export const RUNTIME_SPEC_NAME = "frontier-template"; | ||
export const RUNTIME_SPEC_VERSION = 7; | ||
export const RUNTIME_IMPL_VERSION = 0; | ||
export const RPC_PORT = 9999; | ||
|
||
// Chain config | ||
export const CHAIN_ID = 667; | ||
|
||
export const GENESIS_ACCOUNT = "0xC0F0f4ab324C46e55D02D0033343B4Be8A55532d"; | ||
export const GENESIS_ACCOUNT_PRIVATE_KEY = "0xb9d2ea9a615f3165812e8d44de0d24da9bbd164b65c4f0573e1ce2c8dbd9c8df"; | ||
export const GENESIS_ACCOUNT_BALANCE = "77559934324363988854052928524572160"; | ||
export const GENESIS_ACCOUNT_BALANCE = "77559934324363988853790420524572160"; | ||
export const GAS_PRICE = "0x3B9ACA00"; | ||
export const GAS = "0x10000"; | ||
|
||
// LAOS Evolution Contract | ||
export const LAOS_EVOLUTION_ABI = LaosEvolution.abi as AbiItem[] | ||
export const CONTRACT_ADDRESS = "0x0000000000000000000000000000000000000403"; | ||
export const SELECTOR_LOG_NEW_COLLECTION = "0x6eb24fd767a7bcfa417f3fe25a2cb245d2ae52293d3c4a8f8c6450a09795d289"; | ||
export const SELECTOR_LOG_MINTED_WITH_EXTERNAL_TOKEN_URI = "0x4b3b5da28a351f8bb73b960d7c80b2cef3e3570cb03448234dee173942c74786"; | ||
export const SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI = "0x95c167d04a267f10e6b3f373c7a336dc65cf459caf048854dc32a2d37ab1607c"; | ||
|
||
|
||
export const MAX_U96 = new BN('79228162514264337593543950336'); // 2^96 - 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
import { describeWithExistingNode, slotAndOwnerToTokenId } from "./util"; | ||
import { step } from "mocha-steps"; | ||
import { CONTRACT_ADDRESS, GAS, GAS_PRICE, GENESIS_ACCOUNT, GENESIS_ACCOUNT_PRIVATE_KEY, LAOS_EVOLUTION_ABI, SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI, SELECTOR_LOG_MINTED_WITH_EXTERNAL_TOKEN_URI, SELECTOR_LOG_NEW_COLLECTION } from "./config"; | ||
import { expect } from "chai"; | ||
import Contract from "web3-eth-contract"; | ||
import BN from "bn.js"; | ||
|
||
describeWithExistingNode("Frontier RPC (Mint and Evolve Assets)", (context) => { | ||
let contract: Contract; | ||
let nonce: number; | ||
let collectionId: number = 0; | ||
|
||
beforeEach(async function () { | ||
this.timeout(70000); | ||
|
||
contract = new context.web3.eth.Contract(LAOS_EVOLUTION_ABI, CONTRACT_ADDRESS, { | ||
from: GENESIS_ACCOUNT, | ||
gasPrice: GAS_PRICE, | ||
}); | ||
|
||
nonce = await context.web3.eth.getTransactionCount(GENESIS_ACCOUNT); | ||
|
||
context.web3.eth.accounts.wallet.add(GENESIS_ACCOUNT_PRIVATE_KEY); | ||
|
||
const result = await contract.methods.createCollection(GENESIS_ACCOUNT).send({ from: GENESIS_ACCOUNT, gas: GAS, nonce: nonce++ }); | ||
expect(result.status).to.be.eq(true); | ||
collectionId = result.events.NewCollection.returnValues.collectionId; | ||
}); | ||
|
||
step("when collection does not exist token uri should fail", async function () { | ||
const tokenId = "0"; | ||
|
||
try { | ||
await contract.methods.tokenURI(collectionId, tokenId).call(); | ||
expect.fail("Expected error was not thrown"); // Ensure an error is thrown | ||
} catch (error) { | ||
expect(error.message).to.be.eq( | ||
"Returned error: VM Exception while processing transaction: revert" | ||
); | ||
} | ||
}); | ||
|
||
step("when asset is minted it should return token uri", async function () { | ||
this.timeout(70000); | ||
|
||
const slot = "0"; | ||
const to = GENESIS_ACCOUNT; | ||
const tokenURI = "https://example.com"; | ||
|
||
const result = await contract.methods.mintWithExternalURI(collectionId, slot, to, tokenURI).send({ from: GENESIS_ACCOUNT, gas: GAS, nonce: nonce++ }); | ||
expect(result.status).to.be.eq(true); | ||
|
||
const tokenId = result.events.MintedWithExternalURI.returnValues.tokenId; | ||
const got = await contract.methods.tokenURI(collectionId, tokenId).call(); | ||
expect(got).to.be.eq(tokenURI); | ||
}); | ||
|
||
step("given slot and owner it should return token id", async function () { | ||
this.timeout(70000); | ||
|
||
const slot = "1"; | ||
const to = GENESIS_ACCOUNT; | ||
|
||
const tokenId = slotAndOwnerToTokenId(slot, to); | ||
expect(tokenId).to.be.eq("000000000000000000000001c0f0f4ab324c46e55d02d0033343b4be8a55532d"); | ||
const tokenIdDecimal = new BN(tokenId, 16, "be").toString(10); | ||
expect(tokenIdDecimal).to.be.eq("2563001357829637001682277476112176020532353127213"); | ||
}); | ||
|
||
step("when asset is minted it should emit an event", async function () { | ||
this.timeout(70000); | ||
|
||
const slot = "22"; | ||
const to = GENESIS_ACCOUNT; | ||
const tokenURI = "https://example.com"; | ||
|
||
const result = await contract.methods.mintWithExternalURI(collectionId, slot, to, tokenURI) | ||
.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); | ||
|
||
// data returned within the event | ||
expect(result.events.MintedWithExternalURI.returnValues.collectionId).to.be.eq(collectionId); | ||
expect(result.events.MintedWithExternalURI.returnValues.slot).to.be.eq(slot); | ||
expect(result.events.MintedWithExternalURI.returnValues.to).to.be.eq(to); | ||
expect(result.events.MintedWithExternalURI.returnValues.tokenURI).to.be.eq(tokenURI); | ||
const tokenId = slotAndOwnerToTokenId(slot, to); | ||
const tokenIdDecimal = new BN(tokenId, 16, "be").toString(10); | ||
expect(result.events.MintedWithExternalURI.returnValues.tokenId).to.be.eq(tokenIdDecimal); | ||
|
||
// event topics | ||
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(context.web3.utils.padLeft(GENESIS_ACCOUNT.toLowerCase(), 64)); | ||
|
||
// event data | ||
expect(result.events.MintedWithExternalURI.raw.data).to.be.eq( | ||
context.web3.eth.abi.encodeParameters( | ||
["uint64", "uint96", "string", "uint256"], | ||
[collectionId, slot, tokenURI, tokenIdDecimal] | ||
) | ||
); | ||
}); | ||
|
||
step("when asset is evolved it should change token uri", async function () { | ||
this.timeout(70000); | ||
|
||
const slot = "22"; | ||
const to = GENESIS_ACCOUNT; | ||
const tokenURI = "https://example.com"; | ||
const newTokenURI = "https://new_example.com"; | ||
const tokenId = slotAndOwnerToTokenId(slot, to); | ||
const tokenIdDecimal = new BN(tokenId, 16, "be").toString(10); | ||
|
||
const mintingResult = await contract.methods.mintWithExternalURI(collectionId, slot, to, tokenURI).send({ from: GENESIS_ACCOUNT, gas: GAS, nonce: nonce++ }); | ||
expect(mintingResult.status).to.be.eq(true); | ||
|
||
const evolvingResult = await contract.methods.evolveWithExternalURI(collectionId, tokenIdDecimal, newTokenURI).send({ from: GENESIS_ACCOUNT, gas: GAS, nonce: nonce++ }); | ||
expect(evolvingResult.status).to.be.eq(true); | ||
|
||
const got = await contract.methods.tokenURI(collectionId, tokenIdDecimal).call(); | ||
expect(got).to.be.eq(newTokenURI); | ||
}); | ||
|
||
step("when asset is evolved it should emit an event", async function () { | ||
this.timeout(70000); | ||
|
||
const slot = "22"; | ||
const to = GENESIS_ACCOUNT; | ||
const tokenURI = "https://example.com"; | ||
const newTokenURI = "https://new_example.com"; | ||
const tokenId = slotAndOwnerToTokenId(slot, to); | ||
const tokenIdDecimal = new BN(tokenId, 16, "be").toString(10); | ||
|
||
const mintingResult = await contract.methods.mintWithExternalURI(collectionId, slot, to, tokenURI).send({ from: GENESIS_ACCOUNT, gas: GAS, nonce: nonce++ }); | ||
expect(mintingResult.status).to.be.eq(true); | ||
|
||
const evolvingResult = await contract.methods.evolveWithExternalURI(collectionId, tokenIdDecimal, newTokenURI).send({ from: GENESIS_ACCOUNT, gas: GAS, nonce: nonce++ }); | ||
expect(evolvingResult.status).to.be.eq(true); | ||
|
||
expect(Object.keys(evolvingResult.events).length).to.be.eq(1); | ||
|
||
// data returned within the event | ||
expect(evolvingResult.events.EvolvedWithExternalURI.returnValues.collectionId).to.be.eq(collectionId); | ||
expect(evolvingResult.events.EvolvedWithExternalURI.returnValues.tokenId).to.be.eq(tokenIdDecimal); | ||
expect(evolvingResult.events.EvolvedWithExternalURI.returnValues.tokenURI).to.be.eq(newTokenURI); | ||
|
||
// event topics | ||
expect(evolvingResult.events.EvolvedWithExternalURI.raw.topics.length).to.be.eq(2); | ||
expect(evolvingResult.events.EvolvedWithExternalURI.raw.topics[0]).to.be.eq(SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI); | ||
expect(evolvingResult.events.EvolvedWithExternalURI.raw.topics[1]).to.be.eq("0x" + tokenId); | ||
|
||
// event data | ||
expect(evolvingResult.events.EvolvedWithExternalURI.raw.data).to.be.eq( | ||
context.web3.eth.abi.encodeParameters( | ||
["uint64", "string"], | ||
[collectionId, newTokenURI] | ||
) | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a generic error message, is there any way to expect more specific message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I included specific message https://github.com/freeverseio/laos/blob/feature/add_evolution_e2e_test/ownership-chain/precompile/laos-evolution/src/lib.rs#L93-L94 but still generic revert message is shown. Any idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could this be a solution? https://ethereum.stackexchange.com/a/84551