git.delta.rocks / unique-network / refs/commits / d996a74e54de

difftreelog

Merge pull request #835 from UniqueNetwork/tests/generalization

Yaroslav Bolyukin2023-01-18parents: #d161923 #5954afe.patch.diff
in: master

20 files changed

modifiedtests/src/apiConsts.test.tsdiffbeforeafterboth
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17import {ApiPromise} from '@polkadot/api';17import {ApiPromise} from '@polkadot/api';
18import {usingPlaygrounds, itSub, expect} from './util';18import {usingPlaygrounds, itSub, expect, COLLECTION_HELPER, CONTRACT_HELPER} from './util';
1919
2020
21const MAX_COLLECTION_DESCRIPTION_LENGTH = 256n;21const MAX_COLLECTION_DESCRIPTION_LENGTH = 256n;
41 transfersEnabled: true,41 transfersEnabled: true,
42};42};
43
44const EVM_COLLECTION_HELPERS_ADDRESS = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f';
45const HELPERS_CONTRACT_ADDRESS = '0x842899ECF380553E8a4de75bF534cdf6fBF64049';
4643
47describe('integration test: API UNIQUE consts', () => {44describe('integration test: API UNIQUE consts', () => {
48 let api: ApiPromise;45 let api: ApiPromise;
106 });103 });
107104
108 itSub('HELPERS_CONTRACT_ADDRESS', () => {105 itSub('HELPERS_CONTRACT_ADDRESS', () => {
109 expect(api.consts.evmContractHelpers.contractAddress.toString().toLowerCase()).to.be.equal(HELPERS_CONTRACT_ADDRESS.toLowerCase());106 expect(api.consts.evmContractHelpers.contractAddress.toString().toLowerCase()).to.be.equal(CONTRACT_HELPER.toLowerCase());
110 });107 });
111108
112 itSub('EVM_COLLECTION_HELPERS_ADDRESS', () => {109 itSub('EVM_COLLECTION_HELPERS_ADDRESS', () => {
113 expect(api.consts.common.contractAddress.toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS.toLowerCase());110 expect(api.consts.common.contractAddress.toString().toLowerCase()).to.be.equal(COLLECTION_HELPER.toLowerCase());
114 });111 });
115});112});
116113
modifiedtests/src/burnItem.test.tsdiffbeforeafterboth
46 expect(await collection.getBalance({Substrate: alice.address})).to.eq(9n);46 expect(await collection.getBalance({Substrate: alice.address})).to.eq(9n);
47 });47 });
48
49 itSub.ifWithPallets('Burn item in ReFungible collection', [Pallets.ReFungible], async function({helper}) {
50 const collection = await helper.rft.mintCollection(alice);
51 const token = await collection.mintToken(alice, 100n);
52
53 await token.burn(alice, 90n);
54 expect(await token.getBalance({Substrate: alice.address})).to.eq(10n);
55
56 await token.burn(alice, 10n);
57 expect(await token.getBalance({Substrate: alice.address})).to.eq(0n);
58 });
59
60 itSub.ifWithPallets('Burn owned portion of item in ReFungible collection', [Pallets.ReFungible], async function({helper}) {
61 const collection = await helper.rft.mintCollection(alice);
62 const token = await collection.mintToken(alice, 100n);
63
64 await token.transfer(alice, {Substrate: bob.address}, 1n);
65
66 expect(await token.getBalance({Substrate: alice.address})).to.eq(99n);
67 expect(await token.getBalance({Substrate: bob.address})).to.eq(1n);
68
69 await token.burn(bob, 1n);
70
71 expect(await token.getBalance({Substrate: alice.address})).to.eq(99n);
72 expect(await token.getBalance({Substrate: bob.address})).to.eq(0n);
73 });
74});48});
7549
76describe('integration test: ext. burnItem() with admin permissions:', () => {50describe('integration test: ext. burnItem() with admin permissions:', () => {
105 expect(await collection.getBalance({Substrate: alice.address})).to.eq(9n);79 expect(await collection.getBalance({Substrate: alice.address})).to.eq(9n);
106 });80 });
107
108 itSub.ifWithPallets('Burn item in ReFungible collection', [Pallets.ReFungible], async function({helper}) {
109 const collection = await helper.rft.mintCollection(alice);
110 await collection.setLimits(alice, {ownerCanTransfer: true});
111 await collection.addAdmin(alice, {Substrate: bob.address});
112 const token = await collection.mintToken(alice, 100n);
113
114 await token.burnFrom(bob, {Substrate: alice.address}, 100n);
115 expect(await token.doesExist()).to.be.false;
116 });
117});81});
11882
119describe('Negative integration test: ext. burnItem():', () => {83describe('Negative integration test: ext. burnItem():', () => {
140 await expect(token.burn(bob)).to.be.rejectedWith('common.NoPermission');104 await expect(token.burn(bob)).to.be.rejectedWith('common.NoPermission');
141 });105 });
142
143 itSub.ifWithPallets('RFT: cannot burn non-owned token pieces', [Pallets.ReFungible], async ({helper}) => {
144 const collection = await helper.rft.mintCollection(alice);
145 const aliceToken = await collection.mintToken(alice, 10n, {Substrate: alice.address});
146 const bobToken = await collection.mintToken(alice, 10n, {Substrate: bob.address});
147
148 // 1. Cannot burn non-owned token:
149 await expect(bobToken.burn(alice, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
150 await expect(bobToken.burn(alice, 5n)).to.be.rejectedWith('common.TokenValueTooLow');
151 // 2. Cannot burn non-existing token:
152 await expect(helper.rft.burnToken(alice, 99999, 10)).to.be.rejectedWith('common.CollectionNotFound');
153 await expect(helper.rft.burnToken(alice, collection.collectionId, 99999)).to.be.rejectedWith('common.TokenValueTooLow');
154 // 3. Can burn zero amount of owned tokens (EIP-20)
155 await aliceToken.burn(alice, 0n);
156
157 // 4. Storage is not corrupted:
158 expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
159 expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
160
161 // 4.1 Tokens can be transfered:
162 await aliceToken.transfer(alice, {Substrate: bob.address}, 10n);
163 await bobToken.transfer(bob, {Substrate: alice.address}, 10n);
164 expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
165 expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
166 });
167106
168 itSub('Transfer a burned token', async ({helper}) => {107 itSub('Transfer a burned token', async ({helper}) => {
169 const collection = await helper.nft.mintCollection(alice);108 const collection = await helper.nft.mintCollection(alice);
modifiedtests/src/eth/collectionHelperAddress.test.tsdiffbeforeafterboth
1616
17import {itEth, usingEthPlaygrounds, expect} from './util';17import {itEth, usingEthPlaygrounds, expect} from './util';
18import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
19import {Pallets} from '../util';19import {COLLECTION_HELPER, Pallets} from '../util';
20
21const EVM_COLLECTION_HELPERS_ADDRESS = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f';
2220
23describe('[eth]CollectionHelperAddress test: ERC20/ERC721 ', () => {21describe('[eth]CollectionHelperAddress test: ERC20/ERC721 ', () => {
24 let donor: IKeyringPair;22 let donor: IKeyringPair;
36 const nftCollection = await helper.ethNativeContract.collection(nftCollectionAddress, 'nft', owner);34 const nftCollection = await helper.ethNativeContract.collection(nftCollectionAddress, 'nft', owner);
3735
38 expect((await nftCollection.methods.collectionHelperAddress().call())36 expect((await nftCollection.methods.collectionHelperAddress().call())
39 .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);37 .toString().toLowerCase()).to.be.equal(COLLECTION_HELPER);
40 });38 });
4139
42 itEth.ifWithPallets('RFT ', [Pallets.ReFungible], async ({helper}) => {40 itEth.ifWithPallets('RFT ', [Pallets.ReFungible], async ({helper}) => {
4644
47 const rftCollection = await helper.ethNativeContract.collection(rftCollectionAddress, 'rft', owner);45 const rftCollection = await helper.ethNativeContract.collection(rftCollectionAddress, 'rft', owner);
48 expect((await rftCollection.methods.collectionHelperAddress().call())46 expect((await rftCollection.methods.collectionHelperAddress().call())
49 .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);47 .toString().toLowerCase()).to.be.equal(COLLECTION_HELPER);
50 });48 });
5149
52 itEth('FT', async ({helper}) => {50 itEth('FT', async ({helper}) => {
56 const collection = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);54 const collection = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
5755
58 expect((await collection.methods.collectionHelperAddress().call())56 expect((await collection.methods.collectionHelperAddress().call())
59 .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);57 .toString().toLowerCase()).to.be.equal(COLLECTION_HELPER);
60 });58 });
6159
62 itEth('[collectionHelpers] convert collectionId into address', async ({helper}) => {60 itEth('[collectionHelpers] convert collectionId into address', async ({helper}) => {
modifiedtests/src/eth/createNFTCollection.test.tsdiffbeforeafterboth
18import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
19import {expect, itEth, usingEthPlaygrounds} from './util';19import {expect, itEth, usingEthPlaygrounds} from './util';
20import {CollectionLimitField} from './util/playgrounds/types';20import {CollectionLimitField} from './util/playgrounds/types';
21import {COLLECTION_HELPER} from '../util';
2122
2223
23describe('Create NFT collection from EVM', () => {24describe('Create NFT collection from EVM', () => {
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;
61 });29 });
62 });30 });
63
64 itEth('Can perform mint()', async ({helper}) => {
65 const owner = await helper.eth.createAccountWithBalance(donor);
66 const receiver = helper.eth.createAccount();
67 const collection = await helper.ft.mintCollection(alice);
68 await collection.addAdmin(alice, {Ethereum: owner});
69
70 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
71 const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
72
73 const result = await contract.methods.mint(receiver, 100).send();
74
75 const event = result.events.Transfer;
76 expect(event.address).to.equal(collectionAddress);
77 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
78 expect(event.returnValues.to).to.equal(receiver);
79 expect(event.returnValues.value).to.equal('100');
80 });
8131
82 [32 [
83 'substrate' as const,33 'substrate' as const,
addedtests/src/eth/getCode.test.tsdiffbeforeafterboth

no changes

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;
150 });88 });
151 });89 });
152
153 itEth('Can perform mint() & get crossOwner()', async ({helper}) => {
154 const owner = await helper.eth.createAccountWithBalance(donor);
155 const receiver = helper.eth.createAccount();
156
157 const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', '6', '6', '');
158 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
159
160 const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();
161 const tokenId = result.events.Transfer.returnValues.tokenId;
162 expect(tokenId).to.be.equal('1');
163
164 const event = result.events.Transfer;
165 expect(event.address).to.be.equal(collectionAddress);
166 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
167 expect(event.returnValues.to).to.be.equal(receiver);
168
169 expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');
170 expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
171 // TODO: this wont work right now, need release 919000 first
172 // await helper.methods.setOffchainSchema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();
173 // const tokenUri = await contract.methods.tokenURI(nextTokenId).call();
174 // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);
175 });
17690
177 // TODO combine all minting tests in one place91 // TODO combine all minting tests in one place
178 [92 [
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, true);
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;
118 });34 });
119 });35 });
120
121 itEth('Can perform mint() & crossOwnerOf()', async ({helper}) => {
122 const owner = await helper.eth.createAccountWithBalance(donor);
123 const receiver = helper.eth.createAccount();
124 const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, 'Minty', '6', '6', '');
125 const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
126
127 const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();
128
129 const event = result.events.Transfer;
130 expect(event.address).to.equal(collectionAddress);
131 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
132 expect(event.returnValues.to).to.equal(receiver);
133 const tokenId = event.returnValues.tokenId;
134 expect(tokenId).to.be.equal('1');
135
136 expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
137 expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');
138 });
13936
140 [37 [
141 'substrate' as const,38 'substrate' as const,
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', () => {
addedtests/src/eth/tokens/callMethodsERC20.test.tsdiffbeforeafterboth

no changes

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

no changes

addedtests/src/eth/tokens/minting.test.tsdiffbeforeafterboth

no changes

modifiedtests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth
257 }257 }
258 }258 }
259259
260 async createCollection(mode: TCollectionMode, signer: string, name: string, description: string, tokenPrefix: string, decimals = 18): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {260 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 }> {
261 const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();261 const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();
262 const collectionHelper = await this.helper.ethNativeContract.collectionHelpers(signer);262 const collectionHelper = await this.helper.ethNativeContract.collectionHelpers(signer);
263 const functionName: string = this.createCollectionMethodName(mode);263 const functionName: string = this.createCollectionMethodName(mode);
268 const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);268 const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
269 const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);269 const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);
270 const events = this.helper.eth.normalizeEvents(result.events);270 const events = this.helper.eth.normalizeEvents(result.events);
271 const collection = await this.helper.ethNativeContract.collectionById(collectionId, mode, signer, mergeDeprecated);
271272
272 return {collectionId, collectionAddress, events};273 return {collectionId, collectionAddress, events, collection};
273 }274 }
274275
275 createNFTCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {276 createNFTCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {
modifiedtests/src/nesting/nest.test.tsdiffbeforeafterboth
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';
18import {expect, itSub, Pallets, usingPlaygrounds} from '../util';18import {expect, itSub, usingPlaygrounds} from '../util';
1919
20describe('Integration Test: Composite nesting tests', () => {20describe('Integration Test: Composite nesting tests', () => {
21 let alice: IKeyringPair;21 let alice: IKeyringPair;
289 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(7n);289 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(7n);
290 });290 });
291
292 // ---------- Re-Fungible ----------
293
294 itSub.ifWithPallets('ReFungible: allows an Owner to nest/unnest their token', [Pallets.ReFungible], async ({helper}) => {
295 const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}}});
296 const collectionRFT = await helper.rft.mintCollection(alice);
297 const targetToken = await collectionNFT.mintToken(alice, {Substrate: charlie.address});
298
299 await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});
300 await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());
301
302 await collectionRFT.setPermissions(alice, {access: 'AllowList', mintMode: true});
303 await collectionRFT.addToAllowList(alice, {Substrate: charlie.address});
304 await collectionRFT.addToAllowList(alice, targetToken.nestingAccount());
305
306 // Create an immediately nested token
307 const nestedToken = await collectionRFT.mintToken(charlie, 5n, targetToken.nestingAccount());
308 expect(await nestedToken.getBalance(targetToken.nestingAccount())).to.be.equal(5n);
309
310 // Create a token to be nested and nest
311 const newToken = await collectionRFT.mintToken(charlie, 5n);
312 await newToken.transfer(charlie, targetToken.nestingAccount(), 2n);
313 expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(2n);
314 });
315
316 itSub.ifWithPallets('ReFungible: allows an Owner to nest/unnest their token (Restricted nesting)', [Pallets.ReFungible], async ({helper}) => {
317 const collectionNFT = await helper.nft.mintCollection(alice);
318 const collectionRFT = await helper.rft.mintCollection(alice);
319 const targetToken = await collectionNFT.mintToken(alice, {Substrate: charlie.address});
320
321 await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted:[collectionRFT.collectionId]}});
322 await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});
323 await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());
324
325 await collectionRFT.setPermissions(alice, {access: 'AllowList', mintMode: true});
326 await collectionRFT.addToAllowList(alice, {Substrate: charlie.address});
327 await collectionRFT.addToAllowList(alice, targetToken.nestingAccount());
328
329 // Create an immediately nested token
330 const nestedToken = await collectionRFT.mintToken(charlie, 5n, targetToken.nestingAccount());
331 expect(await nestedToken.getBalance(targetToken.nestingAccount())).to.be.equal(5n);
332
333 // Create a token to be nested and nest
334 const newToken = await collectionRFT.mintToken(charlie, 5n);
335 await newToken.transfer(charlie, targetToken.nestingAccount(), 2n);
336 expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(2n);
337 });
338});291});
339292
340describe('Negative Test: Nesting', () => {293describe('Negative Test: Nesting', () => {
581 expect(await collectionFT.getBalance({Substrate: alice.address})).to.be.equal(5n);534 expect(await collectionFT.getBalance({Substrate: alice.address})).to.be.equal(5n);
582 });535 });
583
584 // ---------- Re-Fungible ----------
585
586 itSub.ifWithPallets('ReFungible: disallows to nest token if nesting is disabled', [Pallets.ReFungible], async ({helper}) => {
587 const collectionNFT = await helper.nft.mintCollection(alice);
588 const collectionRFT = await helper.rft.mintCollection(alice);
589 const targetToken = await collectionNFT.mintToken(alice);
590
591 // Try to create an immediately nested token
592 await expect(collectionRFT.mintToken(alice, 5n, targetToken.nestingAccount()))
593 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);
594
595 // Try to create a token to be nested and nest
596 const token = await collectionRFT.mintToken(alice, 5n);
597 await expect(token.transfer(alice, targetToken.nestingAccount(), 2n))
598 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);
599 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(5n);
600 });
601
602 itSub.ifWithPallets('ReFungible: disallows a non-Owner to nest someone else\'s token', [Pallets.ReFungible], async ({helper}) => {
603 const collectionNFT = await helper.nft.mintCollection(alice);
604 const collectionRFT = await helper.rft.mintCollection(alice);
605 const targetToken = await collectionNFT.mintToken(alice);
606
607 await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}});
608 await collectionNFT.addToAllowList(alice, {Substrate: bob.address});
609 await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());
610
611 // Try to create a token to be nested and nest
612 const newToken = await collectionRFT.mintToken(alice);
613 await expect(newToken.transfer(bob, targetToken.nestingAccount())).to.be.rejectedWith(/common\.TokenValueTooLow/);
614
615 expect(await targetToken.getChildren()).to.be.length(0);
616 expect(await newToken.getBalance({Substrate: alice.address})).to.be.equal(1n);
617
618 // Nest some tokens as Alice into Bob's token
619 await newToken.transfer(alice, targetToken.nestingAccount());
620
621 // Try to pull it out
622 await expect(newToken.transferFrom(bob, targetToken.nestingAccount(), {Substrate: alice.address}, 1n))
623 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);
624 expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(1n);
625 });
626
627 itSub.ifWithPallets('ReFungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', [Pallets.ReFungible], async ({helper}) => {
628 const collectionNFT = await helper.nft.mintCollection(alice);
629 const collectionRFT = await helper.rft.mintCollection(alice);
630 const targetToken = await collectionNFT.mintToken(alice);
631
632 await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted: [collectionRFT.collectionId]}});
633 await collectionNFT.addToAllowList(alice, {Substrate: bob.address});
634 await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());
635
636 // Try to create a token to be nested and nest
637 const newToken = await collectionRFT.mintToken(alice);
638 await expect(newToken.transfer(bob, targetToken.nestingAccount())).to.be.rejectedWith(/common\.TokenValueTooLow/);
639
640 expect(await targetToken.getChildren()).to.be.length(0);
641 expect(await newToken.getBalance({Substrate: alice.address})).to.be.equal(1n);
642
643 // Nest some tokens as Alice into Bob's token
644 await newToken.transfer(alice, targetToken.nestingAccount());
645
646 // Try to pull it out
647 await expect(newToken.transferFrom(bob, targetToken.nestingAccount(), {Substrate: alice.address}, 1n))
648 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);
649 expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(1n);
650 });
651
652 itSub.ifWithPallets('ReFungible: disallows to nest token to an unlisted collection', [Pallets.ReFungible], async ({helper}) => {
653 const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true, restricted: []}}});
654 const collectionRFT = await helper.rft.mintCollection(alice);
655 const targetToken = await collectionNFT.mintToken(alice);
656
657 // Try to create an immediately nested token
658 await expect(collectionRFT.mintToken(alice, 5n, targetToken.nestingAccount()))
659 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
660
661 // Try to create a token to be nested and nest
662 const token = await collectionRFT.mintToken(alice, 5n);
663 await expect(token.transfer(alice, targetToken.nestingAccount(), 2n))
664 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
665 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(5n);
666 });
667});536});
668537
modifiedtests/src/refungible.test.tsdiffbeforeafterboth
88 expect((await token.getTop10Owners()).length).to.be.equal(10);88 expect((await token.getTop10Owners()).length).to.be.equal(10);
89 });89 });
90
91 itSub('Transfer token pieces', async ({helper}) => {
92 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
93 const token = await collection.mintToken(alice, 100n);
94
95 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
96 expect(await token.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;
97
98 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);
99 expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);
100
101 await expect(token.transfer(alice, {Substrate: bob.address}, 41n))
102 .to.eventually.be.rejectedWith(/common\.TokenValueTooLow/);
103 });
10490
105 itSub('Create multiple tokens', async ({helper}) => {91 itSub('Create multiple tokens', async ({helper}) => {
106 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});92 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
120 expect(await collection.getTokenBalance(lastTokenId, {Substrate: alice.address})).to.be.equal(100n);106 expect(await collection.getTokenBalance(lastTokenId, {Substrate: alice.address})).to.be.equal(100n);
121 });107 });
122
123 itSub('Burn some pieces', async ({helper}) => {
124 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
125 const token = await collection.mintToken(alice, 100n);
126 expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
127 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
128 expect(await token.burn(alice, 99n)).to.be.true;
129 expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
130 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(1n);
131 });
132
133 itSub('Burn all pieces', async ({helper}) => {
134 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
135 const token = await collection.mintToken(alice, 100n);
136
137 expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
138 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
139
140 expect(await token.burn(alice, 100n)).to.be.true;
141 expect(await collection.doesTokenExist(token.tokenId)).to.be.false;
142 });
143
144 itSub('Burn some pieces for multiple users', async ({helper}) => {
145 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
146 const token = await collection.mintToken(alice, 100n);
147
148 expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
149
150 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
151 expect(await token.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;
152
153 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);
154 expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);
155
156 expect(await token.burn(alice, 40n)).to.be.true;
157
158 expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
159 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);
160
161 expect(await token.burn(bob, 59n)).to.be.true;
162
163 expect(await token.getBalance({Substrate: bob.address})).to.be.equal(1n);
164 expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
165
166 expect(await token.burn(bob, 1n)).to.be.true;
167
168 expect(await collection.doesTokenExist(token.tokenId)).to.be.false;
169 });
170108
171 itSub('Set allowance for token', async ({helper}) => {109 itSub('Set allowance for token', async ({helper}) => {
172 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});110 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
183 expect(await token.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(40n);121 expect(await token.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(40n);
184 });122 });
185
186 itSub('Repartition', async ({helper}) => {
187 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
188 const token = await collection.mintToken(alice, 100n);
189
190 expect(await token.repartition(alice, 200n)).to.be.true;
191 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(200n);
192 expect(await token.getTotalPieces()).to.be.equal(200n);
193
194 expect(await token.transfer(alice, {Substrate: bob.address}, 110n)).to.be.true;
195 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(90n);
196 expect(await token.getBalance({Substrate: bob.address})).to.be.equal(110n);
197
198 await expect(token.repartition(alice, 80n))
199 .to.eventually.be.rejectedWith(/refungible\.RepartitionWhileNotOwningAllPieces/);
200
201 expect(await token.transfer(alice, {Substrate: bob.address}, 90n)).to.be.true;
202 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);
203 expect(await token.getBalance({Substrate: bob.address})).to.be.equal(200n);
204
205 expect(await token.repartition(bob, 150n)).to.be.true;
206 await expect(token.transfer(bob, {Substrate: alice.address}, 160n))
207 .to.eventually.be.rejectedWith(/common\.TokenValueTooLow/);
208 });
209
210 itSub('Repartition with increased amount', async ({helper}) => {
211 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
212 const token = await collection.mintToken(alice, 100n);
213 await token.repartition(alice, 200n);
214 const chainEvents = helper.chainLog.slice(-1)[0].events;
215 const event = chainEvents.find((event: any) => event.section === 'common' && event.method === 'ItemCreated');
216 expect(event).to.deep.include({
217 section: 'common',
218 method: 'ItemCreated',
219 index: [66, 2],
220 data: [
221 collection.collectionId,
222 token.tokenId,
223 {substrate: alice.address},
224 100n,
225 ],
226 });
227 });
228
229 itSub('Repartition with decreased amount', async ({helper}) => {
230 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
231 const token = await collection.mintToken(alice, 100n);
232 await token.repartition(alice, 50n);
233 const chainEvents = helper.chainLog.slice(-1)[0].events;
234 const event = chainEvents.find((event: any) => event.section === 'common' && event.method === 'ItemDestroyed');
235 expect(event).to.deep.include({
236 section: 'common',
237 method: 'ItemDestroyed',
238 index: [66, 3],
239 data: [
240 collection.collectionId,
241 token.tokenId,
242 {substrate: alice.address},
243 50n,
244 ],
245 });
246 });
247123
248 itSub('Create new collection with properties', async ({helper}) => {124 itSub('Create new collection with properties', async ({helper}) => {
249 const properties = [{key: 'key1', value: 'val1'}];125 const properties = [{key: 'key1', value: 'val1'}];
255 });131 });
256});132});
257
258describe('Refungible negative tests', () => {
259 let donor: IKeyringPair;
260 let alice: IKeyringPair;
261 let bob: IKeyringPair;
262 let charlie: IKeyringPair;
263
264 before(async function() {
265 await usingPlaygrounds(async (helper, privateKey) => {
266 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
267
268 donor = await privateKey({filename: __filename});
269 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
270 });
271 });
272
273 itSub('Cannot transfer incorrect amount of token pieces', async ({helper}) => {
274 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
275 const tokenAlice = await collection.mintToken(alice, 10n, {Substrate: alice.address});
276 const tokenBob = await collection.mintToken(alice, 10n, {Substrate: bob.address});
277
278 // 1. Alice cannot transfer Bob's token:
279 await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
280 await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');
281 await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 10n)).to.be.rejectedWith('common.TokenValueTooLow');
282 await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 100n)).to.be.rejectedWith('common.TokenValueTooLow');
283
284 // 2. Alice cannot transfer non-existing token:
285 await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
286 await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');
287
288 // 3. Zero transfer allowed (EIP-20):
289 await tokenAlice.transfer(alice, {Substrate: charlie.address}, 0n);
290
291 expect(await tokenAlice.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
292 expect(await tokenBob.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
293 expect(await tokenAlice.getBalance({Substrate: alice.address})).to.eq(10n);
294 expect(await tokenBob.getBalance({Substrate: bob.address})).to.eq(10n);
295 expect(await tokenBob.getBalance({Substrate: charlie.address})).to.eq(0n);
296 });
297});
298133
addedtests/src/sub/refungible/burn.test.tsdiffbeforeafterboth

no changes

addedtests/src/sub/refungible/nesting.test.tsdiffbeforeafterboth

no changes

addedtests/src/sub/refungible/repartition.test.tsdiffbeforeafterboth

no changes

addedtests/src/sub/refungible/transfer.test.tsdiffbeforeafterboth

no changes

modifiedtests/src/util/index.tsdiffbeforeafterboth
100export const LOCKING_PERIOD = 12n; // 12 blocks of relay100export const LOCKING_PERIOD = 12n; // 12 blocks of relay
101export const UNLOCKING_PERIOD = 6n; // 6 blocks of parachain101export const UNLOCKING_PERIOD = 6n; // 6 blocks of parachain
102102
103// Native contracts
104export const COLLECTION_HELPER = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f';
105export const CONTRACT_HELPER = '0x842899ECF380553E8a4de75bF534cdf6fBF64049';
103106
104export enum Pallets {107export enum Pallets {
105 Inflation = 'inflation',108 Inflation = 'inflation',