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

Feature: Typechain for tests #611

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
4 changes: 3 additions & 1 deletion tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"eslint": "^8.25.0",
"mocha": "^10.1.0",
"ts-node": "^10.9.1",
"typescript": "^4.8.4"
"typescript": "^4.8.4",
"@typechain/web3-v1": "workspace:^6.0.1",
"typechain": "workspace:^8.1.0"
},
"mocha": {
"timeout": 9999999,
Expand Down
14 changes: 7 additions & 7 deletions tests/src/eth/allowlist.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('EVM collection allowlist', () => {
const user = helper.eth.createAccount();

const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');
const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
const collectionEvm = helper.ethNativeContract.nftCollection(collectionAddress, owner);

expect(await collectionEvm.methods.allowed(user).call({from: owner})).to.be.false;
await collectionEvm.methods.addToCollectionAllowList(user).send({from: owner});
Expand All @@ -98,10 +98,10 @@ describe('EVM collection allowlist', () => {
// const userCross = helper.ethCrossAccount.fromKeyringPair(user);
//
// expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.false;
// await collectionEvm.methods.addToCollectionAllowListCross(userCross).send({from: owner});
// await collectionEvm.methods.addToCollectionAllowListCross(new BN(userCross)).send({from: owner});
// expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.true;
//
// await collectionEvm.methods.removeFromCollectionAllowListCross(userCross).send({from: owner});
// await collectionEvm.methods.removeFromCollectionAllowListCross(new BN(userCross)).send({from: owner});
// expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.false;
//});

Expand All @@ -111,7 +111,7 @@ describe('EVM collection allowlist', () => {
const user = helper.eth.createAccount();

const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');
const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
const collectionEvm = helper.ethNativeContract.nftCollection(collectionAddress, owner);

expect(await collectionEvm.methods.allowed(user).call({from: owner})).to.be.false;
await expect(collectionEvm.methods.addToCollectionAllowList(user).call({from: notOwner})).to.be.rejectedWith('NoPermission');
Expand All @@ -132,12 +132,12 @@ describe('EVM collection allowlist', () => {
//
// expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.false;
// const userCross = helper.ethCrossAccount.fromKeyringPair(user);
// await expect(collectionEvm.methods.addToCollectionAllowListCross(userCross).call({from: notOwner})).to.be.rejectedWith('NoPermission');
// await expect(collectionEvm.methods.addToCollectionAllowListCross(new BN(userCross)).call({from: notOwner})).to.be.rejectedWith('NoPermission');
// expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.false;
// await collectionEvm.methods.addToCollectionAllowListCross(userCross).send({from: owner});
// await collectionEvm.methods.addToCollectionAllowListCross(new BN(userCross)).send({from: owner});
//
// expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.true;
// await expect(collectionEvm.methods.removeFromCollectionAllowListCross(userCross).call({from: notOwner})).to.be.rejectedWith('NoPermission');
// await expect(collectionEvm.methods.removeFromCollectionAllowListCross(new BN(userCross)).call({from: notOwner})).to.be.rejectedWith('NoPermission');
// expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.true;
//});
});
16 changes: 8 additions & 8 deletions tests/src/eth/collectionProperties.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,20 @@ describe('Supports ERC721Metadata', () => {
const caller = await helper.eth.createAccountWithBalance(donor);
const bruh = await helper.eth.createAccountWithBalance(donor);

const BASE_URI = 'base/';
const SUFFIX = 'suffix1';
const URI = 'uri1';
const BASE_URI = 'base/';;
const SUFFIX = 'suffix1';;
const URI = 'uri1';;

const collectionHelpers = helper.ethNativeContract.collectionHelpers(caller);
const creatorMethod = mode === 'rft' ? 'createRFTCollection' : 'createNFTCollection';
const creatorMethod = mode === 'rft' ? 'createRFTCollection' : 'createNFTCollection';;

const {collectionId, collectionAddress} = await helper.eth[creatorMethod](caller, 'n', 'd', 'p');
const {collectionId, collectionAddress} = await helper.eth[creatorMethod](caller, 'n', 'd', 'p');;

const contract = helper.ethNativeContract.collectionById(collectionId, mode, caller);
await contract.methods.addCollectionAdmin(bruh).send(); // to check that admin will work too

const collection1 = helper.nft.getCollectionObject(collectionId);
const data1 = await collection1.getData();
const data1 = await collection1.getData();;
expect(data1?.raw.flags.erc721metadata).to.be.false;
expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.false;

Expand All @@ -110,10 +110,10 @@ describe('Supports ERC721Metadata', () => {
expect(await contract.methods.supportsInterface('0x5b5e139f').call()).to.be.true;

const collection2 = helper.nft.getCollectionObject(collectionId);
const data2 = await collection2.getData();
const data2 = await collection2.getData();;
expect(data2?.raw.flags.erc721metadata).to.be.true;

const propertyPermissions = data2?.raw.tokenPropertyPermissions;
const propertyPermissions = data2?.raw.tokenPropertyPermissions;;
expect(propertyPermissions?.length).to.equal(2);

expect(propertyPermissions.find((tpp: ITokenPropertyPermission) => {
Expand Down
18 changes: 9 additions & 9 deletions tests/src/eth/collectionSponsoring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('evm collection sponsoring', () => {
expect(await helper.balance.getEthereum(minter)).to.equal(0n);

const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', minter);
const contract = helper.ethNativeContract.nftCollection(collectionAddress, minter);

await collection.addToAllowList(alice, {Ethereum: minter});

Expand Down Expand Up @@ -86,9 +86,9 @@ describe('evm collection sponsoring', () => {
const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);

let result = await collectionHelpers.methods.createNFTCollection('Sponsor collection', '1', '1').send({value: Number(2n * nominal)});
const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events!.CollectionCreated.returnValues.collectionId);
const sponsor = await helper.eth.createAccountWithBalance(donor);
const collectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', owner);
const collectionEvm = helper.ethNativeContract.nftCollection(collectionIdAddress, owner);

expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;
result = await collectionEvm.methods.setCollectionSponsor(sponsor).send({from: owner});
Expand All @@ -100,7 +100,7 @@ describe('evm collection sponsoring', () => {
await collectionEvm.methods.removeCollectionSponsor().send({from: owner});

const sponsorTuple = await collectionEvm.methods.collectionSponsor().call({from: owner});
expect(sponsorTuple.field_0).to.be.eq('0x0000000000000000000000000000000000000000');
expect(sponsorTuple[0]).to.be.eq('0x0000000000000000000000000000000000000000');
});

itEth('Sponsoring collection from evm address via access list', async ({helper}) => {
Expand All @@ -110,7 +110,7 @@ describe('evm collection sponsoring', () => {

const collection = helper.nft.getCollectionObject(collectionId);
const sponsor = await helper.eth.createAccountWithBalance(donor);
const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
const collectionEvm = helper.ethNativeContract.nftCollection(collectionAddress, owner);

await collectionEvm.methods.setCollectionSponsor(sponsor).send({from: owner});
let collectionData = (await collection.getData())!;
Expand Down Expand Up @@ -227,14 +227,14 @@ describe('evm collection sponsoring', () => {
const {collectionAddress, collectionId} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner,'Sponsor collection', '1', '1', '');
const collection = helper.nft.getCollectionObject(collectionId);
const sponsor = await helper.eth.createAccountWithBalance(donor);
const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
const collectionEvm = helper.ethNativeContract.nftCollection(collectionAddress, owner);

await collectionEvm.methods.setCollectionSponsor(sponsor).send();
let collectionData = (await collection.getData())!;
expect(collectionData.raw.sponsorship.Unconfirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));
await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');

const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'nft', sponsor);
const sponsorCollection = helper.ethNativeContract.nftCollection(collectionAddress, sponsor);
await sponsorCollection.methods.confirmCollectionSponsorship().send();
collectionData = (await collection.getData())!;
expect(collectionData.raw.sponsorship.Confirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));
Expand All @@ -245,10 +245,10 @@ describe('evm collection sponsoring', () => {
const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));
const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));

const userCollectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', user);
const userCollectionEvm = helper.ethNativeContract.nftCollection(collectionAddress, user);

const result = await userCollectionEvm.methods.mintWithTokenURI(user, 'Test URI').send();
const tokenId = result.events.Transfer.returnValues.tokenId;
const tokenId = result.events!.Transfer.returnValues.tokenId;

const events = helper.eth.normalizeEvents(result.events);
const address = helper.ethAddress.fromCollectionId(collectionId);
Expand Down
46 changes: 23 additions & 23 deletions tests/src/eth/nesting/nest.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import {IKeyringPair} from '@polkadot/types/types';
import {Contract} from 'web3-eth-contract';
import {NonFungibleAbi} from '../types';

import {itEth, EthUniqueHelper, usingEthPlaygrounds, expect} from '../util';

const createNestingCollection = async (
helper: EthUniqueHelper,
owner: string,
): Promise<{ collectionId: number, collectionAddress: string, contract: Contract }> => {
): Promise<{ collectionId: number, collectionAddress: string, contract: NonFungibleAbi }> => {
const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');

const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
await contract.methods.setCollectionNesting(true).send({from: owner});
const contract = helper.ethNativeContract.nftCollection(collectionAddress, owner);
await contract.methods['setCollectionNesting(bool)'](true).send({from: owner});

return {collectionId, collectionAddress, contract};
};
Expand All @@ -32,17 +32,17 @@ describe('EVM nesting tests group', () => {

// Create a token to be nested to
const mintingTargetNFTTokenIdResult = await contract.methods.mint(owner).send({from: owner});
const targetNFTTokenId = mintingTargetNFTTokenIdResult.events.Transfer.returnValues.tokenId;
const targetNftTokenAddress = helper.ethAddress.fromTokenId(collectionId, targetNFTTokenId);
const targetNFTTokenId = mintingTargetNFTTokenIdResult.events!.Transfer.returnValues.tokenId;
const targetNftTokenAddress = helper.ethAddress.fromTokenId(collectionId, Number(targetNFTTokenId));

// Create a nested token
const mintingFirstTokenIdResult = await contract.methods.mint(targetNftTokenAddress).send({from: owner});
const firstTokenId = mintingFirstTokenIdResult.events.Transfer.returnValues.tokenId;
const firstTokenId = mintingFirstTokenIdResult.events!.Transfer.returnValues.tokenId;
expect(await contract.methods.ownerOf(firstTokenId).call()).to.be.equal(targetNftTokenAddress);

// Create a token to be nested and nest
const mintingSecondTokenIdResult = await contract.methods.mint(owner).send({from: owner});
const secondTokenId = mintingSecondTokenIdResult.events.Transfer.returnValues.tokenId;
const secondTokenId = mintingSecondTokenIdResult.events!.Transfer.returnValues.tokenId;

await contract.methods.transfer(targetNftTokenAddress, secondTokenId).send({from: owner});
expect(await contract.methods.ownerOf(secondTokenId).call()).to.be.equal(targetNftTokenAddress);
Expand All @@ -57,20 +57,20 @@ describe('EVM nesting tests group', () => {

const {collectionId: collectionIdA, collectionAddress: collectionAddressA, contract: contractA} = await createNestingCollection(helper, owner);
const {collectionAddress: collectionAddressB, contract: contractB} = await createNestingCollection(helper, owner);
await contractA.methods.setCollectionNesting(true, [collectionAddressA, collectionAddressB]).send({from: owner});
await contractA.methods['setCollectionNesting(bool,address[])'](true, [collectionAddressA, collectionAddressB]).send({from: owner});

// Create a token to nest into
const mintingtargetNftTokenIdResult = await contractA.methods.mint(owner).send({from: owner});
const targetNftTokenId = mintingtargetNftTokenIdResult.events.Transfer.returnValues.tokenId;
const targetNftTokenId = mintingtargetNftTokenIdResult.events!.Transfer.returnValues.tokenId;
const nftTokenAddressA1 = helper.ethAddress.fromTokenId(collectionIdA, targetNftTokenId);

// Create a token for nesting in the same collection as the target
const mintingTokenIdAResult = await contractA.methods.mint(owner).send({from: owner});
const nftTokenIdA = mintingTokenIdAResult.events.Transfer.returnValues.tokenId;
const nftTokenIdA = mintingTokenIdAResult.events!.Transfer.returnValues.tokenId;

// Create a token for nesting in a different collection
const mintingTokenIdBResult = await contractB.methods.mint(owner).send({from: owner});
const nftTokenIdB = mintingTokenIdBResult.events.Transfer.returnValues.tokenId;
const nftTokenIdB = mintingTokenIdBResult.events!.Transfer.returnValues.tokenId;

// Nest
await contractA.methods.transfer(nftTokenAddressA1, nftTokenIdA).send({from: owner});
Expand All @@ -86,16 +86,16 @@ describe('EVM nesting tests group', () => {
const owner = await helper.eth.createAccountWithBalance(donor);

const {collectionId, contract} = await createNestingCollection(helper, owner);
await contract.methods.setCollectionNesting(false).send({from: owner});
await contract.methods['setCollectionNesting(bool)'](false).send({from: owner});

// Create a token to nest into
const mintingTargetTokenIdResult = await contract.methods.mint(owner).send({from: owner});
const targetTokenId = mintingTargetTokenIdResult.events.Transfer.returnValues.tokenId;
const targetTokenId = mintingTargetTokenIdResult.events!.Transfer.returnValues.tokenId;
const targetNftTokenAddress = helper.ethAddress.fromTokenId(collectionId, targetTokenId);

// Create a token to nest
const mintingNftTokenIdResult = await contract.methods.mint(owner).send({from: owner});
const nftTokenId = mintingNftTokenIdResult.events.Transfer.returnValues.tokenId;
const nftTokenId = mintingNftTokenIdResult.events!.Transfer.returnValues.tokenId;

// Try to nest
await expect(contract.methods
Expand All @@ -111,12 +111,12 @@ describe('EVM nesting tests group', () => {

// Mint a token
const mintingTargetTokenIdResult = await contract.methods.mint(owner).send({from: owner});
const targetTokenId = mintingTargetTokenIdResult.events.Transfer.returnValues.tokenId;
const targetTokenId = mintingTargetTokenIdResult.events!.Transfer.returnValues.tokenId;
const targetTokenAddress = helper.ethAddress.fromTokenId(collectionId, targetTokenId);

// Mint a token belonging to a different account
const mintingTokenIdResult = await contract.methods.mint(malignant).send({from: owner});
const tokenId = mintingTokenIdResult.events.Transfer.returnValues.tokenId;
const tokenId = mintingTokenIdResult.events!.Transfer.returnValues.tokenId;

// Try to nest one token in another as a non-owner account
await expect(contract.methods
Expand All @@ -131,16 +131,16 @@ describe('EVM nesting tests group', () => {
const {collectionId: collectionIdA, collectionAddress: collectionAddressA, contract: contractA} = await createNestingCollection(helper, owner);
const {collectionAddress: collectionAddressB, contract: contractB} = await createNestingCollection(helper, owner);

await contractA.methods.setCollectionNesting(true, [collectionAddressA, collectionAddressB]).send({from: owner});
await contractA.methods['setCollectionNesting(bool,address[])'](true, [collectionAddressA, collectionAddressB]).send({from: owner});

// Create a token in one collection
const mintingTokenIdAResult = await contractA.methods.mint(owner).send({from: owner});
const nftTokenIdA = mintingTokenIdAResult.events.Transfer.returnValues.tokenId;
const nftTokenIdA = mintingTokenIdAResult.events!.Transfer.returnValues.tokenId;
const nftTokenAddressA = helper.ethAddress.fromTokenId(collectionIdA, nftTokenIdA);

// Create a token in another collection
const mintingTokenIdBResult = await contractB.methods.mint(malignant).send({from: owner});
const nftTokenIdB = mintingTokenIdBResult.events.Transfer.returnValues.tokenId;
const nftTokenIdB = mintingTokenIdBResult.events!.Transfer.returnValues.tokenId;

// Try to drag someone else's token into the other collection and nest
await expect(contractB.methods
Expand All @@ -154,16 +154,16 @@ describe('EVM nesting tests group', () => {
const {collectionId: collectionIdA, collectionAddress: collectionAddressA, contract: contractA} = await createNestingCollection(helper, owner);
const {contract: contractB} = await createNestingCollection(helper, owner);

await contractA.methods.setCollectionNesting(true, [collectionAddressA]).send({from: owner});
await contractA.methods['setCollectionNesting(bool,address[])'](true, [collectionAddressA]).send({from: owner});

// Create a token in one collection
const mintingTokenIdAResult = await contractA.methods.mint(owner).send({from: owner});
const nftTokenIdA = mintingTokenIdAResult.events.Transfer.returnValues.tokenId;
const nftTokenIdA = mintingTokenIdAResult.events!.Transfer.returnValues.tokenId;
const nftTokenAddressA = helper.ethAddress.fromTokenId(collectionIdA, nftTokenIdA);

// Create a token in another collection
const mintingTokenIdBResult = await contractB.methods.mint(owner).send({from: owner});
const nftTokenIdB = mintingTokenIdBResult.events.Transfer.returnValues.tokenId;
const nftTokenIdB = mintingTokenIdBResult.events!.Transfer.returnValues.tokenId;


// Try to nest into a token in the other collection, disallowed in the first
Expand Down
2 changes: 1 addition & 1 deletion tests/src/eth/nonFungible.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('Check ERC721 token URI for NFT', () => {
await contract.methods.setProperty(tokenId, propertyKey, Buffer.from(propertyValue)).send();
}

const event = result.events.Transfer;
const event = result.events!.Transfer;
expect(event.address).to.be.equal(collectionAddress);
expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
expect(event.returnValues.to).to.be.equal(receiver);
Expand Down
Loading