git.delta.rocks / unique-network / refs/commits / 8a76dd7aa345

difftreelog

Combine call tests

Max Andreev2023-01-12parent: #32d4fdc.patch.diff
in: master

7 files changed

addedtests/src/eth/collections/callMethodsERC20.test.tsdiffbeforeafterboth

no changes

addedtests/src/eth/collections/callMethodsERC721.test.tsdiffbeforeafterboth

no changes

modifiedtests/src/eth/fungible.test.tsdiffbeforeafterboth
17import {expect, itEth, usingEthPlaygrounds} from './util';17import {expect, itEth, usingEthPlaygrounds} from './util';
18import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
19
20describe('Fungible: Information getting', () => {
21 let donor: IKeyringPair;
22 let alice: IKeyringPair;
23
24 before(async function() {
25 await usingEthPlaygrounds(async (helper, privateKey) => {
26 donor = await privateKey({filename: __filename});
27 [alice] = await helper.arrange.createAccounts([20n], donor);
28 });
29 });
30
31 itEth('totalSupply', async ({helper}) => {
32 const caller = await helper.eth.createAccountWithBalance(donor);
33 const collection = await helper.ft.mintCollection(alice);
34 await collection.mint(alice, 200n);
35
36 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'ft', caller);
37 const totalSupply = await contract.methods.totalSupply().call();
38 expect(totalSupply).to.equal('200');
39 });
40
41 itEth('balanceOf', async ({helper}) => {
42 const caller = await helper.eth.createAccountWithBalance(donor);
43 const collection = await helper.ft.mintCollection(alice);
44 await collection.mint(alice, 200n, {Ethereum: caller});
45
46 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'ft', caller);
47 const balance = await contract.methods.balanceOf(caller).call();
48 expect(balance).to.equal('200');
49 });
50});
5119
52describe('Fungible: Plain calls', () => {20describe('Fungible: Plain calls', () => {
53 let donor: IKeyringPair;21 let donor: IKeyringPair;
modifiedtests/src/eth/nonFungible.test.tsdiffbeforeafterboth
20import {ITokenPropertyPermission} from '../util/playgrounds/types';20import {ITokenPropertyPermission} from '../util/playgrounds/types';
21
22
23describe('NFT: Information getting', () => {
24 let donor: IKeyringPair;
25 let alice: IKeyringPair;
26
27 before(async function() {
28 await usingEthPlaygrounds(async (helper, privateKey) => {
29 donor = await privateKey({filename: __filename});
30 [alice] = await helper.arrange.createAccounts([10n], donor);
31 });
32 });
33
34 itEth('totalSupply', async ({helper}) => {
35 const collection = await helper.nft.mintCollection(alice, {});
36 await collection.mintToken(alice);
37
38 const caller = await helper.eth.createAccountWithBalance(donor);
39
40 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);
41 const totalSupply = await contract.methods.totalSupply().call();
42
43 expect(totalSupply).to.equal('1');
44 });
45
46 itEth('balanceOf', async ({helper}) => {
47 const collection = await helper.nft.mintCollection(alice, {});
48 const caller = await helper.eth.createAccountWithBalance(donor);
49
50 await collection.mintToken(alice, {Ethereum: caller});
51 await collection.mintToken(alice, {Ethereum: caller});
52 await collection.mintToken(alice, {Ethereum: caller});
53
54 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);
55 const balance = await contract.methods.balanceOf(caller).call();
56
57 expect(balance).to.equal('3');
58 });
59
60 itEth('ownerOf', async ({helper}) => {
61 const collection = await helper.nft.mintCollection(alice, {});
62 const caller = await helper.eth.createAccountWithBalance(donor);
63
64 const token = await collection.mintToken(alice, {Ethereum: caller});
65
66 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);
67
68 const owner = await contract.methods.ownerOf(token.tokenId).call();
69
70 expect(owner).to.equal(caller);
71 });
72
73 itEth('name/symbol is available regardless of ERC721Metadata support', async ({helper}) => {
74 const collection = await helper.nft.mintCollection(alice, {name: 'test', tokenPrefix: 'TEST'});
75 const caller = helper.eth.createAccount();
76
77 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);
78
79 expect(await contract.methods.name().call()).to.equal('test');
80 expect(await contract.methods.symbol().call()).to.equal('TEST');
81 });
82});
8321
84describe('Check ERC721 token URI for NFT', () => {22describe('Check ERC721 token URI for NFT', () => {
85 let donor: IKeyringPair;23 let donor: IKeyringPair;
modifiedtests/src/eth/reFungible.test.tsdiffbeforeafterboth
19import {IKeyringPair} from '@polkadot/types/types';19import {IKeyringPair} from '@polkadot/types/types';
20import {ITokenPropertyPermission} from '../util/playgrounds/types';20import {ITokenPropertyPermission} from '../util/playgrounds/types';
21
22describe('Refungible: Information getting', () => {
23 let donor: IKeyringPair;
24
25 before(async function() {
26 await usingEthPlaygrounds(async (helper, privateKey) => {
27 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
28
29 donor = await privateKey({filename: __filename});
30 });
31 });
32
33 itEth('totalSupply', async ({helper}) => {
34 const caller = await helper.eth.createAccountWithBalance(donor);
35 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'TotalSupply', '6', '6');
36 const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
37
38 await contract.methods.mint(caller).send();
39
40 const totalSupply = await contract.methods.totalSupply().call();
41 expect(totalSupply).to.equal('1');
42 });
43
44 itEth('balanceOf', async ({helper}) => {
45 const caller = await helper.eth.createAccountWithBalance(donor);
46 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'BalanceOf', '6', '6');
47 const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
48
49 await contract.methods.mint(caller).send();
50 await contract.methods.mint(caller).send();
51 await contract.methods.mint(caller).send();
52
53 const balance = await contract.methods.balanceOf(caller).call();
54 expect(balance).to.equal('3');
55 });
56
57 itEth('ownerOf', async ({helper}) => {
58 const caller = await helper.eth.createAccountWithBalance(donor);
59 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'OwnerOf', '6', '6');
60 const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
61
62 const result = await contract.methods.mint(caller).send();
63 const tokenId = result.events.Transfer.returnValues.tokenId;
64
65 const owner = await contract.methods.ownerOf(tokenId).call();
66 expect(owner).to.equal(caller);
67 });
68
69 itEth('ownerOf after burn', async ({helper}) => {
70 const caller = await helper.eth.createAccountWithBalance(donor);
71 const receiver = helper.eth.createAccount();
72 const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'OwnerOf-AfterBurn', '6', '6');
73 const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
74
75 const result = await contract.methods.mint(caller).send();
76 const tokenId = result.events.Transfer.returnValues.tokenId;
77 const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);
78
79 await tokenContract.methods.repartition(2).send();
80 await tokenContract.methods.transfer(receiver, 1).send();
81
82 await tokenContract.methods.burnFrom(caller, 1).send();
83
84 const owner = await contract.methods.ownerOf(tokenId).call();
85 expect(owner).to.equal(receiver);
86 });
87
88 itEth('ownerOf for partial ownership', async ({helper}) => {
89 const caller = await helper.eth.createAccountWithBalance(donor);
90 const receiver = helper.eth.createAccount();
91 const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Partial-OwnerOf', '6', '6');
92 const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
93
94 const result = await contract.methods.mint(caller).send();
95 const tokenId = result.events.Transfer.returnValues.tokenId;
96 const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);
97
98 await tokenContract.methods.repartition(2).send();
99 await tokenContract.methods.transfer(receiver, 1).send();
100
101 const owner = await contract.methods.ownerOf(tokenId).call();
102 expect(owner).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');
103 });
104});
10521
106describe('Refungible: Plain calls', () => {22describe('Refungible: Plain calls', () => {
107 let donor: IKeyringPair;23 let donor: IKeyringPair;
modifiedtests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth
20import {Contract} from 'web3-eth-contract';20import {Contract} from 'web3-eth-contract';
21
22
23describe('Refungible token: Information getting', () => {
24 let donor: IKeyringPair;
25 let alice: IKeyringPair;
26
27 before(async function() {
28 await usingEthPlaygrounds(async (helper, privateKey) => {
29 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
30
31 donor = await privateKey({filename: __filename});
32 [alice] = await helper.arrange.createAccounts([20n], donor);
33 });
34 });
35
36 itEth('totalSupply', async ({helper}) => {
37 const caller = await helper.eth.createAccountWithBalance(donor);
38 const collection = await helper.rft.mintCollection(alice, {tokenPrefix: 'MUON'});
39 const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: caller});
40
41 const contract = await helper.ethNativeContract.rftTokenById(collection.collectionId, tokenId, caller);
42 const totalSupply = await contract.methods.totalSupply().call();
43 expect(totalSupply).to.equal('200');
44 });
45
46 itEth('balanceOf', async ({helper}) => {
47 const caller = await helper.eth.createAccountWithBalance(donor);
48 const collection = await helper.rft.mintCollection(alice, {tokenPrefix: 'MUON'});
49 const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: caller});
50
51 const contract = await helper.ethNativeContract.rftTokenById(collection.collectionId, tokenId, caller);
52 const balance = await contract.methods.balanceOf(caller).call();
53 expect(balance).to.equal('200');
54 });
55
56 itEth('decimals', async ({helper}) => {
57 const caller = await helper.eth.createAccountWithBalance(donor);
58 const collection = await helper.rft.mintCollection(alice, {tokenPrefix: 'MUON'});
59 const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: caller});
60
61 const contract = await helper.ethNativeContract.rftTokenById(collection.collectionId, tokenId, caller);
62 const decimals = await contract.methods.decimals().call();
63 expect(decimals).to.equal('0');
64 });
65});
6621
67// FIXME: Need erc721 for ReFubgible.22// FIXME: Need erc721 for ReFubgible.
68describe('Check ERC721 token URI for ReFungible', () => {23describe('Check ERC721 token URI for ReFungible', () => {
modifiedtests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth
255 }255 }
256 }256 }
257257
258 async createCollection(mode: TCollectionMode, signer: string, name: string, description: string, tokenPrefix: string, decimals = 18): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {258 async createCollection(mode: TCollectionMode, signer: string, name: string, description: string, tokenPrefix: string, decimals = 18, mergeDeprecated = false): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[], collection: Contract }> {
259 const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();259 const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();
260 const collectionHelper = await this.helper.ethNativeContract.collectionHelpers(signer);260 const collectionHelper = await this.helper.ethNativeContract.collectionHelpers(signer);
261 const functionName: string = this.createCollectionMethodName(mode);261 const functionName: string = this.createCollectionMethodName(mode);
266 const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);266 const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
267 const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);267 const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);
268 const events = this.helper.eth.normalizeEvents(result.events);268 const events = this.helper.eth.normalizeEvents(result.events);
269 const collection = await this.helper.ethNativeContract.collectionById(collectionId, mode, signer, mergeDeprecated);
269270
270 return {collectionId, collectionAddress, events};271 return {collectionId, collectionAddress, events, collection};
271 }272 }
272273
273 createNFTCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {274 createNFTCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {