Skip to content

Commit

Permalink
feat: add typechain types generation to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Grigoriy Simonov committed Oct 1, 2022
1 parent 239c99e commit 6c2a904
Show file tree
Hide file tree
Showing 15 changed files with 1,268 additions and 52 deletions.
4 changes: 3 additions & 1 deletion tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"eslint": "^8.16.0",
"mocha": "^10.0.0",
"ts-node": "^10.8.0",
"typescript": "^4.7.2"
"typescript": "^4.7.2",
"@typechain/web3-v1": "workspace:^6.0.1",
"typechain": "workspace:^8.1.0"
},
"mocha": {
"timeout": 9999999,
Expand Down
19 changes: 7 additions & 12 deletions tests/src/eth/allowlist.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,10 @@

import {IKeyringPair} from '@polkadot/types/types';
import {expect} from 'chai';
import {isAllowlisted, normalizeAccountId} from '../util/helpers';
import {
contractHelpers,
createEthAccount,
createEthAccountWithBalance,
deployFlipper,
evmCollection,
evmCollectionHelpers,
getCollectionAddressFromResult,
itWeb3,
} from './util/helpers';
import {itEth, usingEthPlaygrounds} from './util/playgrounds';
Expand Down Expand Up @@ -85,7 +80,7 @@ describe('EVM collection allowlist', () => {
const user = helper.eth.createAccount();

const {collectionAddress} = await helper.eth.createNonfungibleCollection(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 @@ -104,10 +99,10 @@ describe('EVM collection allowlist', () => {
// const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);

// expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.false;
// await collectionEvm.methods.addToCollectionAllowListSubstrate(user.addressRaw).send({from: owner});
// await collectionEvm.methods.addToCollectionAllowListSubstrate(new BN(user.addressRaw)).send({from: owner});
// expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.true;

// await collectionEvm.methods.removeFromCollectionAllowListSubstrate(user.addressRaw).send({from: owner});
// await collectionEvm.methods.removeFromCollectionAllowListSubstrate(new BN(user.addressRaw)).send({from: owner});
// expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.false;
// });

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

const {collectionAddress} = await helper.eth.createNonfungibleCollection(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 @@ -139,12 +134,12 @@ describe('EVM collection allowlist', () => {
// const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);

// expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.false;
// await expect(collectionEvm.methods.addToCollectionAllowListSubstrate(user.addressRaw).call({from: notOwner})).to.be.rejectedWith('NoPermission');
// await expect(collectionEvm.methods.addToCollectionAllowListSubstrate(new BN(user.addressRaw)).call({from: notOwner})).to.be.rejectedWith('NoPermission');
// expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.false;
// await collectionEvm.methods.addToCollectionAllowListSubstrate(user.addressRaw).send({from: owner});
// await collectionEvm.methods.addToCollectionAllowListSubstrate(new BN(user.addressRaw)).send({from: owner});

// expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.true;
// await expect(collectionEvm.methods.removeFromCollectionAllowListSubstrate(user.addressRaw).call({from: notOwner})).to.be.rejectedWith('NoPermission');
// await expect(collectionEvm.methods.removeFromCollectionAllowListSubstrate(new BN(user.addressRaw)).call({from: notOwner})).to.be.rejectedWith('NoPermission');
// expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.true;
// });
});
28 changes: 14 additions & 14 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/playgrounds';

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.createNonfungibleCollection(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 @@ -37,7 +37,7 @@ describe('EVM nesting tests group', () => {
targetNFTTokenId,
).send({from: owner});

const targetNftTokenAddress = helper.ethAddress.fromTokenId(collectionId, targetNFTTokenId);
const targetNftTokenAddress = helper.ethAddress.fromTokenId(collectionId, Number(targetNFTTokenId));

// Create a nested token
const firstTokenId = await contract.methods.nextTokenId().call();
Expand Down Expand Up @@ -69,10 +69,10 @@ 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 targetNftTokenId = await contractA.methods.nextTokenId().call();
const targetNftTokenId = Number(await contractA.methods.nextTokenId().call());
await contractA.methods.mint(
owner,
targetNftTokenId,
Expand Down Expand Up @@ -107,10 +107,10 @@ 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 targetNftTokenId = await contract.methods.nextTokenId().call();
const targetNftTokenId = Number(await contract.methods.nextTokenId().call());
await contract.methods.mint(
owner,
targetNftTokenId,
Expand Down Expand Up @@ -138,7 +138,7 @@ describe('EVM nesting tests group', () => {
const {collectionId, contract} = await createNestingCollection(helper, owner);

// Mint a token
const targetTokenId = await contract.methods.nextTokenId().call();
const targetTokenId = Number(await contract.methods.nextTokenId().call());
await contract.methods.mint(
owner,
targetTokenId,
Expand All @@ -165,10 +165,10 @@ 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 nftTokenIdA = await contractA.methods.nextTokenId().call();
const nftTokenIdA = Number(await contractA.methods.nextTokenId().call());
await contractA.methods.mint(
owner,
nftTokenIdA,
Expand All @@ -194,10 +194,10 @@ 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 nftTokenIdA = await contractA.methods.nextTokenId().call();
const nftTokenIdA = Number(await contractA.methods.nextTokenId().call());
await contractA.methods.mint(
owner,
nftTokenIdA,
Expand Down
4 changes: 2 additions & 2 deletions tests/src/eth/nonFungible.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('Check ERC721 token URI for NFT', () => {

const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
let result = await collectionHelper.methods.createERC721MetadataCompatibleCollection('Mint collection', 'a', 'b', tokenPrefix).send({value: Number(2n * UNIQUE)});
const collectionAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
const collectionAddress = helper.ethAddress.normalizeAddress(result.events!.CollectionCreated.returnValues.collectionId);
const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);

const nextTokenId = await contract.methods.nextTokenId().call();
Expand All @@ -100,7 +100,7 @@ describe('Check ERC721 token URI for NFT', () => {
await contract.methods.setProperty(nextTokenId, 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
2 changes: 1 addition & 1 deletion tests/src/eth/reFungible.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ describe('Refungible: Plain calls', () => {

{
const tokenEvents: any = [];
tokenContract.events.allEvents((_: any, event: any) => {
tokenContract.events.allEvents(undefined, (_: any, event: any) => {
tokenEvents.push(event);
});
const result = await contract.methods.transferFrom(caller, receiver, tokenId).send();
Expand Down
22 changes: 11 additions & 11 deletions tests/src/eth/reFungibleToken.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('Check ERC721 token URI for ReFungible', () => {

const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
let result = await collectionHelper.methods.createERC721MetadataCompatibleCollection('Mint collection', 'a', 'b', tokenPrefix).send({value: Number(2n * UNIQUE)});
const collectionAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
const collectionAddress = helper.ethAddress.normalizeAddress(result.events!.CollectionCreated.returnValues.collectionId);
const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);

const nextTokenId = await contract.methods.nextTokenId().call();
Expand All @@ -97,7 +97,7 @@ describe('Check ERC721 token URI for ReFungible', () => {
await contract.methods.setProperty(nextTokenId, 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 Expand Up @@ -152,7 +152,7 @@ describe('Refungible: Plain calls', () => {

{
const result = await contract.methods.approve(spender, 100).send({from: owner});
const event = result.events.Approval;
const event = result.events!.Approval;
expect(event.address).to.be.equal(tokenAddress);
expect(event.returnValues.owner).to.be.equal(owner);
expect(event.returnValues.spender).to.be.equal(spender);
Expand All @@ -179,13 +179,13 @@ describe('Refungible: Plain calls', () => {

{
const result = await contract.methods.transferFrom(owner, receiver, 49).send({from: spender});
let event = result.events.Transfer;
let event = result.events!.Transfer;
expect(event.address).to.be.equal(tokenAddress);
expect(event.returnValues.from).to.be.equal(owner);
expect(event.returnValues.to).to.be.equal(receiver);
expect(event.returnValues.value).to.be.equal('49');

event = result.events.Approval;
event = result.events!.Approval;
expect(event.address).to.be.equal(tokenAddress);
expect(event.returnValues.owner).to.be.equal(owner);
expect(event.returnValues.spender).to.be.equal(spender);
Expand Down Expand Up @@ -214,7 +214,7 @@ describe('Refungible: Plain calls', () => {

{
const result = await contract.methods.transfer(receiver, 50).send({from: owner});
const event = result.events.Transfer;
const event = result.events!.Transfer;
expect(event.address).to.be.equal(tokenAddress);
expect(event.returnValues.from).to.be.equal(owner);
expect(event.returnValues.to).to.be.equal(receiver);
Expand Down Expand Up @@ -268,7 +268,7 @@ describe('Refungible: Plain calls', () => {

const result = await contract.methods.repartition(200).send();

const event = result.events.Transfer;
const event = result.events!.Transfer;
expect(event.address).to.be.equal(tokenAddress);
expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
expect(event.returnValues.to).to.be.equal(owner);
Expand All @@ -284,7 +284,7 @@ describe('Refungible: Plain calls', () => {
const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);

const result = await contract.methods.repartition(50).send();
const event = result.events.Transfer;
const event = result.events!.Transfer;
expect(event.address).to.be.equal(tokenAddress);
expect(event.returnValues.from).to.be.equal(owner);
expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');
Expand Down Expand Up @@ -396,7 +396,7 @@ describe('Refungible: Substrate calls', () => {
const contract = helper.ethNativeContract.rftToken(tokenAddress);

const events: any = [];
contract.events.allEvents((_: any, event: any) => {
contract.events.allEvents(undefined, (_: any, event: any) => {
events.push(event);
});
expect(await token.approve(alice, {Ethereum: receiver}, 100n)).to.be.true;
Expand All @@ -420,7 +420,7 @@ describe('Refungible: Substrate calls', () => {
const contract = helper.ethNativeContract.rftToken(tokenAddress);

const events: any = [];
contract.events.allEvents((_: any, event: any) => {
contract.events.allEvents(undefined, (_: any, event: any) => {
events.push(event);
});

Expand Down Expand Up @@ -450,7 +450,7 @@ describe('Refungible: Substrate calls', () => {
const contract = helper.ethNativeContract.rftToken(tokenAddress);

const events: any = [];
contract.events.allEvents((_: any, event: any) => {
contract.events.allEvents(undefined, (_: any, event: any) => {
events.push(event);
});

Expand Down
91 changes: 91 additions & 0 deletions tests/src/eth/types/CollectionHelpersAbi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* Autogenerated file. Do not edit manually. */
/* tslint:disable */
/* eslint-disable */

import type BN from "bn.js";
import type { ContractOptions } from "web3-eth-contract";
import type { EventLog } from "web3-core";
import type { EventEmitter } from "events";
import type {
Callback,
PayableTransactionObject,
NonPayableTransactionObject,
BlockType,
ContractEventLog,
BaseContract,
} from "./types";

export interface EventOptions {
filter?: object;
fromBlock?: BlockType;
topics?: string[];
}

export type CollectionCreated = ContractEventLog<{
owner: string;
collectionId: string;
0: string;
1: string;
}>;

export interface CollectionHelpersAbi extends BaseContract {
constructor(
jsonInterface: any[],
address?: string,
options?: ContractOptions
): CollectionHelpersAbi;
clone(): CollectionHelpersAbi;
methods: {
collectionCreationFee(): NonPayableTransactionObject<string>;

createERC721MetadataCompatibleCollection(
name: string,
description: string,
tokenPrefix: string,
baseUri: string
): PayableTransactionObject<string>;

createERC721MetadataCompatibleRFTCollection(
name: string,
description: string,
tokenPrefix: string,
baseUri: string
): PayableTransactionObject<string>;

createNonfungibleCollection(
name: string,
description: string,
tokenPrefix: string
): PayableTransactionObject<string>;

createRFTCollection(
name: string,
description: string,
tokenPrefix: string
): PayableTransactionObject<string>;

isCollectionExist(
collectionAddress: string
): NonPayableTransactionObject<boolean>;

supportsInterface(
interfaceID: string | number[]
): NonPayableTransactionObject<boolean>;
};
events: {
CollectionCreated(cb?: Callback<CollectionCreated>): EventEmitter;
CollectionCreated(
options?: EventOptions,
cb?: Callback<CollectionCreated>
): EventEmitter;

allEvents(options?: EventOptions, cb?: Callback<EventLog>): EventEmitter;
};

once(event: "CollectionCreated", cb: Callback<CollectionCreated>): void;
once(
event: "CollectionCreated",
options: EventOptions,
cb: Callback<CollectionCreated>
): void;
}
Loading

0 comments on commit 6c2a904

Please sign in to comment.