difftreelog
Merge pull request #835 from UniqueNetwork/tests/generalization
in: master
20 files changed
tests/src/apiConsts.test.tsdiffbeforeafterboth--- a/tests/src/apiConsts.test.ts
+++ b/tests/src/apiConsts.test.ts
@@ -15,7 +15,7 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {ApiPromise} from '@polkadot/api';
-import {usingPlaygrounds, itSub, expect} from './util';
+import {usingPlaygrounds, itSub, expect, COLLECTION_HELPER, CONTRACT_HELPER} from './util';
const MAX_COLLECTION_DESCRIPTION_LENGTH = 256n;
@@ -40,9 +40,6 @@
ownerCanDestroy: true,
transfersEnabled: true,
};
-
-const EVM_COLLECTION_HELPERS_ADDRESS = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f';
-const HELPERS_CONTRACT_ADDRESS = '0x842899ECF380553E8a4de75bF534cdf6fBF64049';
describe('integration test: API UNIQUE consts', () => {
let api: ApiPromise;
@@ -106,11 +103,11 @@
});
itSub('HELPERS_CONTRACT_ADDRESS', () => {
- expect(api.consts.evmContractHelpers.contractAddress.toString().toLowerCase()).to.be.equal(HELPERS_CONTRACT_ADDRESS.toLowerCase());
+ expect(api.consts.evmContractHelpers.contractAddress.toString().toLowerCase()).to.be.equal(CONTRACT_HELPER.toLowerCase());
});
itSub('EVM_COLLECTION_HELPERS_ADDRESS', () => {
- expect(api.consts.common.contractAddress.toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS.toLowerCase());
+ expect(api.consts.common.contractAddress.toString().toLowerCase()).to.be.equal(COLLECTION_HELPER.toLowerCase());
});
});
tests/src/burnItem.test.tsdiffbeforeafterboth--- a/tests/src/burnItem.test.ts
+++ b/tests/src/burnItem.test.ts
@@ -45,32 +45,6 @@
await collection.burnTokens(alice, 1n);
expect(await collection.getBalance({Substrate: alice.address})).to.eq(9n);
});
-
- itSub.ifWithPallets('Burn item in ReFungible collection', [Pallets.ReFungible], async function({helper}) {
- const collection = await helper.rft.mintCollection(alice);
- const token = await collection.mintToken(alice, 100n);
-
- await token.burn(alice, 90n);
- expect(await token.getBalance({Substrate: alice.address})).to.eq(10n);
-
- await token.burn(alice, 10n);
- expect(await token.getBalance({Substrate: alice.address})).to.eq(0n);
- });
-
- itSub.ifWithPallets('Burn owned portion of item in ReFungible collection', [Pallets.ReFungible], async function({helper}) {
- const collection = await helper.rft.mintCollection(alice);
- const token = await collection.mintToken(alice, 100n);
-
- await token.transfer(alice, {Substrate: bob.address}, 1n);
-
- expect(await token.getBalance({Substrate: alice.address})).to.eq(99n);
- expect(await token.getBalance({Substrate: bob.address})).to.eq(1n);
-
- await token.burn(bob, 1n);
-
- expect(await token.getBalance({Substrate: alice.address})).to.eq(99n);
- expect(await token.getBalance({Substrate: bob.address})).to.eq(0n);
- });
});
describe('integration test: ext. burnItem() with admin permissions:', () => {
@@ -104,16 +78,6 @@
await collection.burnTokensFrom(bob, {Substrate: alice.address}, 1n);
expect(await collection.getBalance({Substrate: alice.address})).to.eq(9n);
});
-
- itSub.ifWithPallets('Burn item in ReFungible collection', [Pallets.ReFungible], async function({helper}) {
- const collection = await helper.rft.mintCollection(alice);
- await collection.setLimits(alice, {ownerCanTransfer: true});
- await collection.addAdmin(alice, {Substrate: bob.address});
- const token = await collection.mintToken(alice, 100n);
-
- await token.burnFrom(bob, {Substrate: alice.address}, 100n);
- expect(await token.doesExist()).to.be.false;
- });
});
describe('Negative integration test: ext. burnItem():', () => {
@@ -138,31 +102,6 @@
const token = await collection.mintToken(alice);
await expect(token.burn(bob)).to.be.rejectedWith('common.NoPermission');
- });
-
- itSub.ifWithPallets('RFT: cannot burn non-owned token pieces', [Pallets.ReFungible], async ({helper}) => {
- const collection = await helper.rft.mintCollection(alice);
- const aliceToken = await collection.mintToken(alice, 10n, {Substrate: alice.address});
- const bobToken = await collection.mintToken(alice, 10n, {Substrate: bob.address});
-
- // 1. Cannot burn non-owned token:
- await expect(bobToken.burn(alice, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
- await expect(bobToken.burn(alice, 5n)).to.be.rejectedWith('common.TokenValueTooLow');
- // 2. Cannot burn non-existing token:
- await expect(helper.rft.burnToken(alice, 99999, 10)).to.be.rejectedWith('common.CollectionNotFound');
- await expect(helper.rft.burnToken(alice, collection.collectionId, 99999)).to.be.rejectedWith('common.TokenValueTooLow');
- // 3. Can burn zero amount of owned tokens (EIP-20)
- await aliceToken.burn(alice, 0n);
-
- // 4. Storage is not corrupted:
- expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
- expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
-
- // 4.1 Tokens can be transfered:
- await aliceToken.transfer(alice, {Substrate: bob.address}, 10n);
- await bobToken.transfer(bob, {Substrate: alice.address}, 10n);
- expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
- expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
});
itSub('Transfer a burned token', async ({helper}) => {
tests/src/eth/collectionHelperAddress.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionHelperAddress.test.ts
+++ b/tests/src/eth/collectionHelperAddress.test.ts
@@ -16,9 +16,7 @@
import {itEth, usingEthPlaygrounds, expect} from './util';
import {IKeyringPair} from '@polkadot/types/types';
-import {Pallets} from '../util';
-
-const EVM_COLLECTION_HELPERS_ADDRESS = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f';
+import {COLLECTION_HELPER, Pallets} from '../util';
describe('[eth]CollectionHelperAddress test: ERC20/ERC721 ', () => {
let donor: IKeyringPair;
@@ -36,7 +34,7 @@
const nftCollection = await helper.ethNativeContract.collection(nftCollectionAddress, 'nft', owner);
expect((await nftCollection.methods.collectionHelperAddress().call())
- .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);
+ .toString().toLowerCase()).to.be.equal(COLLECTION_HELPER);
});
itEth.ifWithPallets('RFT ', [Pallets.ReFungible], async ({helper}) => {
@@ -46,7 +44,7 @@
const rftCollection = await helper.ethNativeContract.collection(rftCollectionAddress, 'rft', owner);
expect((await rftCollection.methods.collectionHelperAddress().call())
- .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);
+ .toString().toLowerCase()).to.be.equal(COLLECTION_HELPER);
});
itEth('FT', async ({helper}) => {
@@ -56,7 +54,7 @@
const collection = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
expect((await collection.methods.collectionHelperAddress().call())
- .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);
+ .toString().toLowerCase()).to.be.equal(COLLECTION_HELPER);
});
itEth('[collectionHelpers] convert collectionId into address', async ({helper}) => {
tests/src/eth/createNFTCollection.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.8//9// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {evmToAddress} from '@polkadot/util-crypto';18import {IKeyringPair} from '@polkadot/types/types';19import {expect, itEth, usingEthPlaygrounds} from './util';20import {CollectionLimitField} from './util/playgrounds/types';212223describe('Create NFT collection from EVM', () => {24 let donor: IKeyringPair;2526 before(async function () {27 await usingEthPlaygrounds(async (_helper, privateKey) => {28 donor = await privateKey({filename: __filename});29 });30 });3132 itEth('Create collection with properties & get desctription', async ({helper}) => {33 const owner = await helper.eth.createAccountWithBalance(donor);3435 const name = 'CollectionEVM';36 const description = 'Some description';37 const prefix = 'token prefix';38 const baseUri = 'BaseURI';3940 const {collectionId, collectionAddress, events} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, name, description, prefix, baseUri);41 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');4243 expect(events).to.be.deep.equal([44 {45 address: '0x6C4E9fE1AE37a41E93CEE429e8E1881aBdcbb54F',46 event: 'CollectionCreated',47 args: {48 owner: owner,49 collectionId: collectionAddress,50 },51 },52 ]);5354 const collection = helper.nft.getCollectionObject(collectionId);55 const data = (await collection.getData())!;5657 expect(data.name).to.be.eq(name);58 expect(data.description).to.be.eq(description);59 expect(data.raw.tokenPrefix).to.be.eq(prefix);60 expect(data.raw.mode).to.be.eq('NFT');6162 expect(await contract.methods.description().call()).to.deep.equal(description);6364 const options = await collection.getOptions();65 expect(options.tokenPropertyPermissions).to.be.deep.equal([66 {67 key: 'URI',68 permission: {mutable: true, collectionAdmin: true, tokenOwner: false},69 },70 {71 key: 'URISuffix',72 permission: {mutable: true, collectionAdmin: true, tokenOwner: false},73 },74 ]);75 });7677 // Soft-deprecated78 itEth('[eth] Set sponsorship', async ({helper}) => {79 const owner = await helper.eth.createAccountWithBalance(donor);80 const sponsor = await helper.eth.createAccountWithBalance(donor);81 const ss58Format = helper.chain.getChainProperties().ss58Format;82 const {collectionId, collectionAddress} = await helper.eth.createNFTCollection(owner, 'Sponsor', 'absolutely anything', 'ROC');8384 const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);85 await collection.methods.setCollectionSponsor(sponsor).send();8687 let data = (await helper.nft.getData(collectionId))!;88 expect(data.raw.sponsorship.Unconfirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));8990 await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('ConfirmSponsorshipFail');9192 const sponsorCollection = await helper.ethNativeContract.collection(collectionAddress, 'nft', sponsor, true);93 await sponsorCollection.methods.confirmCollectionSponsorship().send();9495 data = (await helper.nft.getData(collectionId))!;96 expect(data.raw.sponsorship.Confirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));97 });9899 itEth('[cross] Set sponsorship & get description', async ({helper}) => {100 const owner = await helper.eth.createAccountWithBalance(donor);101 const sponsor = await helper.eth.createAccountWithBalance(donor);102 const ss58Format = helper.chain.getChainProperties().ss58Format;103 const description = 'absolutely anything';104 const {collectionId, collectionAddress} = await helper.eth.createNFTCollection(owner, 'Sponsor', description, 'ROC');105106 const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);107 const sponsorCross = helper.ethCrossAccount.fromAddress(sponsor);108 await collection.methods.setCollectionSponsorCross(sponsorCross).send();109110 let data = (await helper.nft.getData(collectionId))!;111 expect(data.raw.sponsorship.Unconfirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));112113 await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('ConfirmSponsorshipFail');114115 const sponsorCollection = await helper.ethNativeContract.collection(collectionAddress, 'nft', sponsor);116 await sponsorCollection.methods.confirmCollectionSponsorship().send();117118 data = (await helper.nft.getData(collectionId))!;119 expect(data.raw.sponsorship.Confirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));120121 expect(await sponsorCollection.methods.description().call()).to.deep.equal(description);122 });123124 itEth('Collection address exist', async ({helper}) => {125 const owner = await helper.eth.createAccountWithBalance(donor);126 const collectionAddressForNonexistentCollection = '0x17C4E6453CC49AAAAEACA894E6D9683E00112233';127 const collectionHelpers = await helper.ethNativeContract.collectionHelpers(owner);128129 expect(await collectionHelpers130 .methods.isCollectionExist(collectionAddressForNonexistentCollection).call())131 .to.be.false;132133 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'Exister', 'absolutely anything', 'EVC');134 expect(await collectionHelpers135 .methods.isCollectionExist(collectionAddress).call())136 .to.be.true;137138 // check collectionOwner:139 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner, true);140 const collectionOwner = await collectionEvm.methods.collectionOwner().call();141 expect(helper.address.restoreCrossAccountFromBigInt(BigInt(collectionOwner.sub))).to.eq(helper.address.ethToSubstrate(owner, true));142 });143});144145describe('(!negative tests!) Create NFT collection from EVM', () => {146 let donor: IKeyringPair;147 let nominal: bigint;148149 before(async function () {150 await usingEthPlaygrounds(async (helper, privateKey) => {151 donor = await privateKey({filename: __filename});152 nominal = helper.balance.getOneTokenNominal();153 });154 });155156 itEth('(!negative test!) Create collection (bad lengths)', async ({helper}) => {157 const owner = await helper.eth.createAccountWithBalance(donor);158 const collectionHelper = await helper.ethNativeContract.collectionHelpers(owner);159 {160 const MAX_NAME_LENGTH = 64;161 const collectionName = 'A'.repeat(MAX_NAME_LENGTH + 1);162 const description = 'A';163 const tokenPrefix = 'A';164165 await expect(collectionHelper.methods166 .createNFTCollection(collectionName, description, tokenPrefix)167 .call({value: Number(2n * nominal)})).to.be.rejectedWith('name is too long. Max length is ' + MAX_NAME_LENGTH);168169 }170 {171 const MAX_DESCRIPTION_LENGTH = 256;172 const collectionName = 'A';173 const description = 'A'.repeat(MAX_DESCRIPTION_LENGTH + 1);174 const tokenPrefix = 'A';175 await expect(collectionHelper.methods176 .createNFTCollection(collectionName, description, tokenPrefix)177 .call({value: Number(2n * nominal)})).to.be.rejectedWith('description is too long. Max length is ' + MAX_DESCRIPTION_LENGTH);178 }179 {180 const MAX_TOKEN_PREFIX_LENGTH = 16;181 const collectionName = 'A';182 const description = 'A';183 const tokenPrefix = 'A'.repeat(MAX_TOKEN_PREFIX_LENGTH + 1);184 await expect(collectionHelper.methods185 .createNFTCollection(collectionName, description, tokenPrefix)186 .call({value: Number(2n * nominal)})).to.be.rejectedWith('token_prefix is too long. Max length is ' + MAX_TOKEN_PREFIX_LENGTH);187 }188 });189190 itEth('(!negative test!) Create collection (no funds)', async ({helper}) => {191 const owner = await helper.eth.createAccountWithBalance(donor);192 const collectionHelper = await helper.ethNativeContract.collectionHelpers(owner);193 await expect(collectionHelper.methods194 .createNFTCollection('Peasantry', 'absolutely anything', 'CVE')195 .call({value: Number(1n * nominal)})).to.be.rejectedWith('Sent amount not equals to collection creation price (2000000000000000000)');196 });197198 // Soft-deprecated199 itEth('(!negative test!) [eth] Check owner', async ({helper}) => {200 const owner = await helper.eth.createAccountWithBalance(donor);201 const malfeasant = helper.eth.createAccount();202 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'Transgressed', 'absolutely anything', 'COR');203 const malfeasantCollection = await helper.ethNativeContract.collection(collectionAddress, 'nft', malfeasant, true);204 const EXPECTED_ERROR = 'NoPermission';205 {206 const sponsor = await helper.eth.createAccountWithBalance(donor);207 await expect(malfeasantCollection.methods208 .setCollectionSponsor(sponsor)209 .call()).to.be.rejectedWith(EXPECTED_ERROR);210211 const sponsorCollection = await helper.ethNativeContract.collection(collectionAddress, 'nft', sponsor, true);212 await expect(sponsorCollection.methods213 .confirmCollectionSponsorship()214 .call()).to.be.rejectedWith('ConfirmSponsorshipFail');215 }216 {217 await expect(malfeasantCollection.methods218 .setCollectionLimit({field: CollectionLimitField.AccountTokenOwnership, value: {status: true, value: 1000}})219 .call()).to.be.rejectedWith(EXPECTED_ERROR);220 }221 });222223 itEth('(!negative test!) [cross] Check owner', async ({helper}) => {224 const owner = await helper.eth.createAccountWithBalance(donor);225 const malfeasant = helper.eth.createAccount();226 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'Transgressed', 'absolutely anything', 'COR');227 const malfeasantCollection = await helper.ethNativeContract.collection(collectionAddress, 'nft', malfeasant);228 const EXPECTED_ERROR = 'NoPermission';229 {230 const sponsor = await helper.eth.createAccountWithBalance(donor);231 const sponsorCross = helper.ethCrossAccount.fromAddress(sponsor);232 await expect(malfeasantCollection.methods233 .setCollectionSponsorCross(sponsorCross)234 .call()).to.be.rejectedWith(EXPECTED_ERROR);235236 const sponsorCollection = await helper.ethNativeContract.collection(collectionAddress, 'nft', sponsor);237 await expect(sponsorCollection.methods238 .confirmCollectionSponsorship()239 .call()).to.be.rejectedWith('ConfirmSponsorshipFail');240 }241 {242 await expect(malfeasantCollection.methods243 .setCollectionLimit({field: CollectionLimitField.AccountTokenOwnership, value: {status: true, value: 1000}})244 .call()).to.be.rejectedWith(EXPECTED_ERROR);245 }246 });247248 itEth('destroyCollection', async ({helper}) => {249 const owner = await helper.eth.createAccountWithBalance(donor);250 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'Limits', 'absolutely anything', 'OLF');251 const collectionHelper = await helper.ethNativeContract.collectionHelpers(owner);252253254 const result = await collectionHelper.methods255 .destroyCollection(collectionAddress)256 .send({from: owner});257258 const events = helper.eth.normalizeEvents(result.events);259260 expect(events).to.be.deep.equal([261 {262 address: collectionHelper.options.address,263 event: 'CollectionDestroyed',264 args: {265 collectionId: collectionAddress,266 },267 },268 ]);269270 expect(await collectionHelper.methods271 .isCollectionExist(collectionAddress)272 .call()).to.be.false;273 expect(await helper.collection.getData(collectionId)).to.be.null;274 });275});1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.8//9// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {evmToAddress} from '@polkadot/util-crypto';18import {IKeyringPair} from '@polkadot/types/types';19import {expect, itEth, usingEthPlaygrounds} from './util';20import {CollectionLimitField} from './util/playgrounds/types';21import {COLLECTION_HELPER} from '../util';222324describe('Create NFT collection from EVM', () => {25 let donor: IKeyringPair;2627 before(async function () {28 await usingEthPlaygrounds(async (_helper, privateKey) => {29 donor = await privateKey({filename: __filename});30 });31 });3233 itEth('Create collection with properties & get desctription', async ({helper}) => {34 const owner = await helper.eth.createAccountWithBalance(donor);3536 const name = 'CollectionEVM';37 const description = 'Some description';38 const prefix = 'token prefix';39 const baseUri = 'BaseURI';4041 const {collectionId, collectionAddress, events} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, name, description, prefix, baseUri);42 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');4344 expect(events).to.be.deep.equal([45 {46 address: '0x6C4E9fE1AE37a41E93CEE429e8E1881aBdcbb54F',47 event: 'CollectionCreated',48 args: {49 owner: owner,50 collectionId: collectionAddress,51 },52 },53 ]);5455 const collection = helper.nft.getCollectionObject(collectionId);56 const data = (await collection.getData())!;5758 expect(data.name).to.be.eq(name);59 expect(data.description).to.be.eq(description);60 expect(data.raw.tokenPrefix).to.be.eq(prefix);61 expect(data.raw.mode).to.be.eq('NFT');6263 expect(await contract.methods.description().call()).to.deep.equal(description);6465 const options = await collection.getOptions();66 expect(options.tokenPropertyPermissions).to.be.deep.equal([67 {68 key: 'URI',69 permission: {mutable: true, collectionAdmin: true, tokenOwner: false},70 },71 {72 key: 'URISuffix',73 permission: {mutable: true, collectionAdmin: true, tokenOwner: false},74 },75 ]);76 });7778 // Soft-deprecated79 itEth('[eth] Set sponsorship', async ({helper}) => {80 const owner = await helper.eth.createAccountWithBalance(donor);81 const sponsor = await helper.eth.createAccountWithBalance(donor);82 const ss58Format = helper.chain.getChainProperties().ss58Format;83 const {collectionId, collectionAddress} = await helper.eth.createNFTCollection(owner, 'Sponsor', 'absolutely anything', 'ROC');8485 const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);86 await collection.methods.setCollectionSponsor(sponsor).send();8788 let data = (await helper.nft.getData(collectionId))!;89 expect(data.raw.sponsorship.Unconfirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));9091 await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('ConfirmSponsorshipFail');9293 const sponsorCollection = await helper.ethNativeContract.collection(collectionAddress, 'nft', sponsor, true);94 await sponsorCollection.methods.confirmCollectionSponsorship().send();9596 data = (await helper.nft.getData(collectionId))!;97 expect(data.raw.sponsorship.Confirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));98 });99100 itEth('[cross] Set sponsorship & get description', async ({helper}) => {101 const owner = await helper.eth.createAccountWithBalance(donor);102 const sponsor = await helper.eth.createAccountWithBalance(donor);103 const ss58Format = helper.chain.getChainProperties().ss58Format;104 const description = 'absolutely anything';105 const {collectionId, collectionAddress} = await helper.eth.createNFTCollection(owner, 'Sponsor', description, 'ROC');106107 const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);108 const sponsorCross = helper.ethCrossAccount.fromAddress(sponsor);109 await collection.methods.setCollectionSponsorCross(sponsorCross).send();110111 let data = (await helper.nft.getData(collectionId))!;112 expect(data.raw.sponsorship.Unconfirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));113114 await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('ConfirmSponsorshipFail');115116 const sponsorCollection = await helper.ethNativeContract.collection(collectionAddress, 'nft', sponsor);117 await sponsorCollection.methods.confirmCollectionSponsorship().send();118119 data = (await helper.nft.getData(collectionId))!;120 expect(data.raw.sponsorship.Confirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));121122 expect(await sponsorCollection.methods.description().call()).to.deep.equal(description);123 });124125 itEth('Collection address exist', async ({helper}) => {126 const owner = await helper.eth.createAccountWithBalance(donor);127 const collectionAddressForNonexistentCollection = '0x17C4E6453CC49AAAAEACA894E6D9683E00112233';128 const collectionHelpers = await helper.ethNativeContract.collectionHelpers(owner);129130 expect(await collectionHelpers131 .methods.isCollectionExist(collectionAddressForNonexistentCollection).call())132 .to.be.false;133134 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'Exister', 'absolutely anything', 'EVC');135 expect(await collectionHelpers136 .methods.isCollectionExist(collectionAddress).call())137 .to.be.true;138139 // check collectionOwner:140 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner, true);141 const collectionOwner = await collectionEvm.methods.collectionOwner().call();142 expect(helper.address.restoreCrossAccountFromBigInt(BigInt(collectionOwner.sub))).to.eq(helper.address.ethToSubstrate(owner, true));143 });144});145146describe('(!negative tests!) Create NFT collection from EVM', () => {147 let donor: IKeyringPair;148 let nominal: bigint;149150 before(async function () {151 await usingEthPlaygrounds(async (helper, privateKey) => {152 donor = await privateKey({filename: __filename});153 nominal = helper.balance.getOneTokenNominal();154 });155 });156157 itEth('(!negative test!) Create collection (bad lengths)', async ({helper}) => {158 const owner = await helper.eth.createAccountWithBalance(donor);159 const collectionHelper = await helper.ethNativeContract.collectionHelpers(owner);160 {161 const MAX_NAME_LENGTH = 64;162 const collectionName = 'A'.repeat(MAX_NAME_LENGTH + 1);163 const description = 'A';164 const tokenPrefix = 'A';165166 await expect(collectionHelper.methods167 .createNFTCollection(collectionName, description, tokenPrefix)168 .call({value: Number(2n * nominal)})).to.be.rejectedWith('name is too long. Max length is ' + MAX_NAME_LENGTH);169170 }171 {172 const MAX_DESCRIPTION_LENGTH = 256;173 const collectionName = 'A';174 const description = 'A'.repeat(MAX_DESCRIPTION_LENGTH + 1);175 const tokenPrefix = 'A';176 await expect(collectionHelper.methods177 .createNFTCollection(collectionName, description, tokenPrefix)178 .call({value: Number(2n * nominal)})).to.be.rejectedWith('description is too long. Max length is ' + MAX_DESCRIPTION_LENGTH);179 }180 {181 const MAX_TOKEN_PREFIX_LENGTH = 16;182 const collectionName = 'A';183 const description = 'A';184 const tokenPrefix = 'A'.repeat(MAX_TOKEN_PREFIX_LENGTH + 1);185 await expect(collectionHelper.methods186 .createNFTCollection(collectionName, description, tokenPrefix)187 .call({value: Number(2n * nominal)})).to.be.rejectedWith('token_prefix is too long. Max length is ' + MAX_TOKEN_PREFIX_LENGTH);188 }189 });190191 itEth('(!negative test!) Create collection (no funds)', async ({helper}) => {192 const owner = await helper.eth.createAccountWithBalance(donor);193 const collectionHelper = await helper.ethNativeContract.collectionHelpers(owner);194 await expect(collectionHelper.methods195 .createNFTCollection('Peasantry', 'absolutely anything', 'CVE')196 .call({value: Number(1n * nominal)})).to.be.rejectedWith('Sent amount not equals to collection creation price (2000000000000000000)');197 });198199 // Soft-deprecated200 itEth('(!negative test!) [eth] Check owner', async ({helper}) => {201 const owner = await helper.eth.createAccountWithBalance(donor);202 const malfeasant = helper.eth.createAccount();203 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'Transgressed', 'absolutely anything', 'COR');204 const malfeasantCollection = await helper.ethNativeContract.collection(collectionAddress, 'nft', malfeasant, true);205 const EXPECTED_ERROR = 'NoPermission';206 {207 const sponsor = await helper.eth.createAccountWithBalance(donor);208 await expect(malfeasantCollection.methods209 .setCollectionSponsor(sponsor)210 .call()).to.be.rejectedWith(EXPECTED_ERROR);211212 const sponsorCollection = await helper.ethNativeContract.collection(collectionAddress, 'nft', sponsor, true);213 await expect(sponsorCollection.methods214 .confirmCollectionSponsorship()215 .call()).to.be.rejectedWith('ConfirmSponsorshipFail');216 }217 {218 await expect(malfeasantCollection.methods219 .setCollectionLimit({field: CollectionLimitField.AccountTokenOwnership, value: {status: true, value: 1000}})220 .call()).to.be.rejectedWith(EXPECTED_ERROR);221 }222 });223224 itEth('(!negative test!) [cross] Check owner', async ({helper}) => {225 const owner = await helper.eth.createAccountWithBalance(donor);226 const malfeasant = helper.eth.createAccount();227 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'Transgressed', 'absolutely anything', 'COR');228 const malfeasantCollection = await helper.ethNativeContract.collection(collectionAddress, 'nft', malfeasant);229 const EXPECTED_ERROR = 'NoPermission';230 {231 const sponsor = await helper.eth.createAccountWithBalance(donor);232 const sponsorCross = helper.ethCrossAccount.fromAddress(sponsor);233 await expect(malfeasantCollection.methods234 .setCollectionSponsorCross(sponsorCross)235 .call()).to.be.rejectedWith(EXPECTED_ERROR);236237 const sponsorCollection = await helper.ethNativeContract.collection(collectionAddress, 'nft', sponsor);238 await expect(sponsorCollection.methods239 .confirmCollectionSponsorship()240 .call()).to.be.rejectedWith('ConfirmSponsorshipFail');241 }242 {243 await expect(malfeasantCollection.methods244 .setCollectionLimit({field: CollectionLimitField.AccountTokenOwnership, value: {status: true, value: 1000}})245 .call()).to.be.rejectedWith(EXPECTED_ERROR);246 }247 });248249 itEth('destroyCollection', async ({helper}) => {250 const owner = await helper.eth.createAccountWithBalance(donor);251 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'Limits', 'absolutely anything', 'OLF');252 const collectionHelper = await helper.ethNativeContract.collectionHelpers(owner);253254255 const result = await collectionHelper.methods256 .destroyCollection(collectionAddress)257 .send({from: owner});258259 const events = helper.eth.normalizeEvents(result.events);260261 expect(events).to.be.deep.equal([262 {263 address: collectionHelper.options.address,264 event: 'CollectionDestroyed',265 args: {266 collectionId: collectionAddress,267 },268 },269 ]);270271 expect(await collectionHelper.methods272 .isCollectionExist(collectionAddress)273 .call()).to.be.false;274 expect(await helper.collection.getData(collectionId)).to.be.null;275 });276});tests/src/eth/fungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/fungible.test.ts
+++ b/tests/src/eth/fungible.test.ts
@@ -17,38 +17,6 @@
import {expect, itEth, usingEthPlaygrounds} from './util';
import {IKeyringPair} from '@polkadot/types/types';
-describe('Fungible: Information getting', () => {
- let donor: IKeyringPair;
- let alice: IKeyringPair;
-
- before(async function() {
- await usingEthPlaygrounds(async (helper, privateKey) => {
- donor = await privateKey({filename: __filename});
- [alice] = await helper.arrange.createAccounts([20n], donor);
- });
- });
-
- itEth('totalSupply', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const collection = await helper.ft.mintCollection(alice);
- await collection.mint(alice, 200n);
-
- const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'ft', caller);
- const totalSupply = await contract.methods.totalSupply().call();
- expect(totalSupply).to.equal('200');
- });
-
- itEth('balanceOf', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const collection = await helper.ft.mintCollection(alice);
- await collection.mint(alice, 200n, {Ethereum: caller});
-
- const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'ft', caller);
- const balance = await contract.methods.balanceOf(caller).call();
- expect(balance).to.equal('200');
- });
-});
-
describe('Fungible: Plain calls', () => {
let donor: IKeyringPair;
let alice: IKeyringPair;
@@ -59,24 +27,6 @@
donor = await privateKey({filename: __filename});
[alice, owner] = await helper.arrange.createAccounts([30n, 20n], donor);
});
- });
-
- itEth('Can perform mint()', async ({helper}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
- const receiver = helper.eth.createAccount();
- const collection = await helper.ft.mintCollection(alice);
- await collection.addAdmin(alice, {Ethereum: owner});
-
- const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
- const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
-
- const result = await contract.methods.mint(receiver, 100).send();
-
- const event = result.events.Transfer;
- expect(event.address).to.equal(collectionAddress);
- expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
- expect(event.returnValues.to).to.equal(receiver);
- expect(event.returnValues.value).to.equal('100');
});
[
tests/src/eth/getCode.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/eth/getCode.test.ts
@@ -0,0 +1,53 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {expect, itEth, usingEthPlaygrounds} from './util';
+import {IKeyringPair} from '@polkadot/types/types';
+import {COLLECTION_HELPER, CONTRACT_HELPER} from '../util';
+
+describe('RPC eth_getCode', () => {
+ let donor: IKeyringPair;
+
+ before(async function() {
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ donor = await privateKey({filename: __filename});
+ });
+ });
+
+ [
+ {address: COLLECTION_HELPER},
+ {address: CONTRACT_HELPER},
+ ].map(testCase => {
+ itEth(`returns value for native contract: ${testCase.address}`, async ({helper}) => {
+ const contractCodeSub = (await helper.callRpc('api.rpc.eth.getCode', [testCase.address])).toJSON();
+ const contractCodeEth = (await helper.getWeb3().eth.getCode(testCase.address));
+
+ expect(contractCodeSub).to.has.length.greaterThan(4);
+ expect(contractCodeEth).to.has.length.greaterThan(4);
+ });
+ });
+
+ itEth('returns value for custom contract', async ({helper}) => {
+ const signer = await helper.eth.createAccountWithBalance(donor);
+ const flipper = await helper.eth.deployFlipper(signer);
+
+ const contractCodeSub = (await helper.callRpc('api.rpc.eth.getCode', [flipper.options.address])).toJSON();
+ const contractCodeEth = (await helper.getWeb3().eth.getCode(flipper.options.address));
+
+ expect(contractCodeSub).to.has.length.greaterThan(4);
+ expect(contractCodeEth).to.has.length.greaterThan(4);
+ });
+});
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -19,68 +19,6 @@
import {Contract} from 'web3-eth-contract';
import {ITokenPropertyPermission} from '../util/playgrounds/types';
-
-describe('NFT: Information getting', () => {
- let donor: IKeyringPair;
- let alice: IKeyringPair;
-
- before(async function() {
- await usingEthPlaygrounds(async (helper, privateKey) => {
- donor = await privateKey({filename: __filename});
- [alice] = await helper.arrange.createAccounts([10n], donor);
- });
- });
-
- itEth('totalSupply', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {});
- await collection.mintToken(alice);
-
- const caller = await helper.eth.createAccountWithBalance(donor);
-
- const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);
- const totalSupply = await contract.methods.totalSupply().call();
-
- expect(totalSupply).to.equal('1');
- });
-
- itEth('balanceOf', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {});
- const caller = await helper.eth.createAccountWithBalance(donor);
-
- await collection.mintToken(alice, {Ethereum: caller});
- await collection.mintToken(alice, {Ethereum: caller});
- await collection.mintToken(alice, {Ethereum: caller});
-
- const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);
- const balance = await contract.methods.balanceOf(caller).call();
-
- expect(balance).to.equal('3');
- });
-
- itEth('ownerOf', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {});
- const caller = await helper.eth.createAccountWithBalance(donor);
-
- const token = await collection.mintToken(alice, {Ethereum: caller});
-
- const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);
-
- const owner = await contract.methods.ownerOf(token.tokenId).call();
-
- expect(owner).to.equal(caller);
- });
-
- itEth('name/symbol is available regardless of ERC721Metadata support', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {name: 'test', tokenPrefix: 'TEST'});
- const caller = helper.eth.createAccount();
-
- const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);
-
- expect(await contract.methods.name().call()).to.equal('test');
- expect(await contract.methods.symbol().call()).to.equal('TEST');
- });
-});
-
describe('Check ERC721 token URI for NFT', () => {
let donor: IKeyringPair;
@@ -148,30 +86,6 @@
donor = await privateKey({filename: __filename});
[minter, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
});
- });
-
- itEth('Can perform mint() & get crossOwner()', async ({helper}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
- const receiver = helper.eth.createAccount();
-
- const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', '6', '6', '');
- const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
-
- const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();
- const tokenId = result.events.Transfer.returnValues.tokenId;
- expect(tokenId).to.be.equal('1');
-
- 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);
-
- expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');
- expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
- // TODO: this wont work right now, need release 919000 first
- // await helper.methods.setOffchainSchema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();
- // const tokenUri = await contract.methods.tokenURI(nextTokenId).call();
- // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);
});
// TODO combine all minting tests in one place
tests/src/eth/reFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -19,90 +19,6 @@
import {IKeyringPair} from '@polkadot/types/types';
import {ITokenPropertyPermission} from '../util/playgrounds/types';
-describe('Refungible: Information getting', () => {
- let donor: IKeyringPair;
-
- before(async function() {
- await usingEthPlaygrounds(async (helper, privateKey) => {
- requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
-
- donor = await privateKey({filename: __filename});
- });
- });
-
- itEth('totalSupply', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'TotalSupply', '6', '6');
- const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
-
- await contract.methods.mint(caller).send();
-
- const totalSupply = await contract.methods.totalSupply().call();
- expect(totalSupply).to.equal('1');
- });
-
- itEth('balanceOf', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'BalanceOf', '6', '6');
- const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
-
- await contract.methods.mint(caller).send();
- await contract.methods.mint(caller).send();
- await contract.methods.mint(caller).send();
-
- const balance = await contract.methods.balanceOf(caller).call();
- expect(balance).to.equal('3');
- });
-
- itEth('ownerOf', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'OwnerOf', '6', '6');
- const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
-
- const result = await contract.methods.mint(caller).send();
- const tokenId = result.events.Transfer.returnValues.tokenId;
-
- const owner = await contract.methods.ownerOf(tokenId).call();
- expect(owner).to.equal(caller);
- });
-
- itEth('ownerOf after burn', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const receiver = helper.eth.createAccount();
- const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'OwnerOf-AfterBurn', '6', '6');
- const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
-
- const result = await contract.methods.mint(caller).send();
- const tokenId = result.events.Transfer.returnValues.tokenId;
- const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller, true);
-
- await tokenContract.methods.repartition(2).send();
- await tokenContract.methods.transfer(receiver, 1).send();
-
- await tokenContract.methods.burnFrom(caller, 1).send();
-
- const owner = await contract.methods.ownerOf(tokenId).call();
- expect(owner).to.equal(receiver);
- });
-
- itEth('ownerOf for partial ownership', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const receiver = helper.eth.createAccount();
- const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Partial-OwnerOf', '6', '6');
- const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
-
- const result = await contract.methods.mint(caller).send();
- const tokenId = result.events.Transfer.returnValues.tokenId;
- const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);
-
- await tokenContract.methods.repartition(2).send();
- await tokenContract.methods.transfer(receiver, 1).send();
-
- const owner = await contract.methods.ownerOf(tokenId).call();
- expect(owner).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');
- });
-});
-
describe('Refungible: Plain calls', () => {
let donor: IKeyringPair;
let minter: IKeyringPair;
@@ -116,25 +32,6 @@
donor = await privateKey({filename: __filename});
[minter, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
});
- });
-
- itEth('Can perform mint() & crossOwnerOf()', async ({helper}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
- const receiver = helper.eth.createAccount();
- const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, 'Minty', '6', '6', '');
- const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
-
- const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();
-
- const event = result.events.Transfer;
- expect(event.address).to.equal(collectionAddress);
- expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
- expect(event.returnValues.to).to.equal(receiver);
- const tokenId = event.returnValues.tokenId;
- expect(tokenId).to.be.equal('1');
-
- expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
- expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');
});
[
tests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungibleToken.test.ts
+++ b/tests/src/eth/reFungibleToken.test.ts
@@ -19,51 +19,6 @@
import {IKeyringPair} from '@polkadot/types/types';
import {Contract} from 'web3-eth-contract';
-
-describe('Refungible token: Information getting', () => {
- let donor: IKeyringPair;
- let alice: IKeyringPair;
-
- before(async function() {
- await usingEthPlaygrounds(async (helper, privateKey) => {
- requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
-
- donor = await privateKey({filename: __filename});
- [alice] = await helper.arrange.createAccounts([20n], donor);
- });
- });
-
- itEth('totalSupply', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const collection = await helper.rft.mintCollection(alice, {tokenPrefix: 'MUON'});
- const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: caller});
-
- const contract = await helper.ethNativeContract.rftTokenById(collection.collectionId, tokenId, caller);
- const totalSupply = await contract.methods.totalSupply().call();
- expect(totalSupply).to.equal('200');
- });
-
- itEth('balanceOf', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const collection = await helper.rft.mintCollection(alice, {tokenPrefix: 'MUON'});
- const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: caller});
-
- const contract = await helper.ethNativeContract.rftTokenById(collection.collectionId, tokenId, caller);
- const balance = await contract.methods.balanceOf(caller).call();
- expect(balance).to.equal('200');
- });
-
- itEth('decimals', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const collection = await helper.rft.mintCollection(alice, {tokenPrefix: 'MUON'});
- const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: caller});
-
- const contract = await helper.ethNativeContract.rftTokenById(collection.collectionId, tokenId, caller);
- const decimals = await contract.methods.decimals().call();
- expect(decimals).to.equal('0');
- });
-});
-
// FIXME: Need erc721 for ReFubgible.
describe('Check ERC721 token URI for ReFungible', () => {
let donor: IKeyringPair;
tests/src/eth/tokens/callMethodsERC20.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/eth/tokens/callMethodsERC20.test.ts
@@ -0,0 +1,91 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {Pallets, requirePalletsOrSkip} from '../../util';
+import {expect, itEth, usingEthPlaygrounds} from '../util';
+import {IKeyringPair} from '@polkadot/types/types';
+
+[
+ {mode: 'ft' as const, requiredPallets: []},
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+].map(testCase => {
+ describe(`${testCase.mode.toUpperCase()}: ERC-20 call methods`, () => {
+ let donor: IKeyringPair;
+
+ before(async function() {
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, testCase.requiredPallets);
+ donor = await privateKey({filename: __filename});
+ });
+ });
+
+ itEth('totalSupply', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const mintingParams = testCase.mode === 'ft' ? [caller, 200n] : [caller];
+
+ const {collection, collectionId} = await helper.eth.createCollection(testCase.mode, caller, 'TotalSupply', '6', '6');
+ if (testCase.mode === 'rft') await collection.methods.mint(caller).send({from: caller});
+
+ // Use collection contract for FT or token contract for RFT:
+ const contract = testCase.mode === 'ft'
+ ? collection
+ : await helper.ethNativeContract.rftTokenById(collectionId, 1, caller);
+
+ // Mint tokens:
+ testCase.mode === 'ft'
+ ? await contract.methods.mint(...mintingParams).send({from: caller})
+ : await contract.methods.repartition(200).send({from: caller});
+
+ const totalSupply = await contract.methods.totalSupply().call();
+ expect(totalSupply).to.equal('200');
+ });
+
+ itEth('balanceOf', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const mintingParams = testCase.mode === 'ft' ? [caller, 200n] : [caller];
+
+ const {collection, collectionId} = await helper.eth.createCollection(testCase.mode, caller, 'BalanceOf', 'Descroption', 'Prefix');
+ if (testCase.mode === 'rft') await collection.methods.mint(caller).send({from: caller});
+
+ // Use collection contract for FT or token contract for RFT:
+ const contract = testCase.mode === 'ft'
+ ? collection
+ : await helper.ethNativeContract.rftTokenById(collectionId, 1, caller);
+
+ // Mint tokens:
+ testCase.mode === 'ft'
+ ? await contract.methods.mint(...mintingParams).send({from: caller})
+ : await contract.methods.repartition(200).send({from: caller});
+
+ const balance = await contract.methods.balanceOf(caller).call();
+ expect(balance).to.equal('200');
+ });
+
+ itEth('decimals', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const {collection, collectionId} = await helper.eth.createCollection(testCase.mode, caller, 'BalanceOf', 'Descroption', 'Prefix');
+ if (testCase.mode === 'rft') await collection.methods.mint(caller).send({from: caller});
+
+ // Use collection contract for FT or token contract for RFT:
+ const contract = testCase.mode === 'ft'
+ ? collection
+ : await helper.ethNativeContract.rftTokenById(collectionId, 1, caller);
+
+ const decimals = await contract.methods.decimals().call();
+ expect(decimals).to.equal(testCase.mode === 'rft' ? '0' : '18');
+ });
+ });
+});
\ No newline at end of file
tests/src/eth/tokens/callMethodsERC721.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/eth/tokens/callMethodsERC721.test.ts
@@ -0,0 +1,143 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {Pallets} from '../../util';
+import {expect, itEth, usingEthPlaygrounds} from '../util';
+import {IKeyringPair} from '@polkadot/types/types';
+
+
+describe('ERC-721 call methods', () => {
+ let donor: IKeyringPair;
+
+ before(async function() {
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ donor = await privateKey({filename: __filename});
+ });
+ });
+
+ [
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ {mode: 'nft' as const, requiredPallets: []},
+ ].map(testCase => {
+ itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: name/symbol/description`, testCase.requiredPallets, async ({helper}) => {
+ const callerEth = await helper.eth.createAccountWithBalance(donor);
+ const [callerSub] = await helper.arrange.createAccounts([100n], donor);
+ const [name, description, tokenPrefix] = ['Name', 'Description', 'Symbol'];
+
+ const {collection: collectionEth} = await helper.eth.createCollection(testCase.mode, callerEth, name, description, tokenPrefix);
+ await collectionEth.methods.mint(callerEth).send({from: callerEth});
+ const {collectionId} = await helper[testCase.mode].mintCollection(callerSub, {name, description, tokenPrefix});
+ const collectionSub = await helper.ethNativeContract.collectionById(collectionId, testCase.mode, callerEth);
+
+ // Can get name/symbol/description for Eth collection
+ expect(await collectionEth.methods.name().call()).to.eq(name);
+ expect(await collectionEth.methods.symbol().call()).to.eq(tokenPrefix);
+ expect(await collectionEth.methods.description().call()).to.eq(description);
+ // Can get name/symbol/description for Sub collection
+ expect(await collectionSub.methods.name().call()).to.eq(name);
+ expect(await collectionSub.methods.symbol().call()).to.eq(tokenPrefix);
+ expect(await collectionSub.methods.description().call()).to.eq(description);
+ });
+ });
+
+ [
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ {mode: 'nft' as const, requiredPallets: []},
+ ].map(testCase => {
+ itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: totalSupply`, testCase.requiredPallets, async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+
+ const {collection} = await helper.eth.createCollection(testCase.mode, caller, 'TotalSupply', '6', '6');
+ await collection.methods.mint(caller).send({from: caller});
+
+ const totalSupply = await collection.methods.totalSupply().call();
+ expect(totalSupply).to.equal('1');
+ });
+ });
+
+ [
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ {mode: 'nft' as const, requiredPallets: []},
+ ].map(testCase => {
+ itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: balanceOf`, testCase.requiredPallets, async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+
+ const {collection} = await helper.eth.createCollection(testCase.mode, caller, 'BalanceOf', 'Descroption', 'Prefix');
+ await collection.methods.mint(caller).send({from: caller});
+ await collection.methods.mint(caller).send({from: caller});
+ await collection.methods.mint(caller).send({from: caller});
+
+ const balance = await collection.methods.balanceOf(caller).call();
+ expect(balance).to.equal('3');
+ });
+ });
+
+ [
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ {mode: 'nft' as const, requiredPallets: []},
+ ].map(testCase => {
+ itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: ownerOf`, testCase.requiredPallets, async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const {collection} = await helper.eth.createCollection(testCase.mode, caller, 'OwnerOf', '6', '6');
+
+ const result = await collection.methods.mint(caller).send();
+ const tokenId = result.events.Transfer.returnValues.tokenId;
+
+ const owner = await collection.methods.ownerOf(tokenId).call();
+ expect(owner).to.equal(caller);
+ });
+ });
+
+ [
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ // TODO {mode: 'nft' as const, requiredPallets: []},
+ ].map(testCase => {
+ itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: ownerOf after burn`, testCase.requiredPallets, async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const {collection, collectionId} = await helper.eth.createCollection(testCase.mode, caller, 'OwnerOf-AfterBurn', '6', '6');
+
+ const result = await collection.methods.mint(caller).send();
+ const tokenId = result.events.Transfer.returnValues.tokenId;
+ const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller, true);
+
+ await tokenContract.methods.repartition(2).send();
+ await tokenContract.methods.transfer(receiver, 1).send();
+
+ await tokenContract.methods.burnFrom(caller, 1).send();
+
+ const owner = await collection.methods.ownerOf(tokenId).call();
+ expect(owner).to.equal(receiver);
+ });
+ });
+
+ itEth.ifWithPallets('RFT: ownerOf for partial ownership', [Pallets.ReFungible], async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Partial-OwnerOf', '6', '6');
+ const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
+
+ const result = await contract.methods.mint(caller).send();
+ const tokenId = result.events.Transfer.returnValues.tokenId;
+ const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);
+
+ await tokenContract.methods.repartition(2).send();
+ await tokenContract.methods.transfer(receiver, 1).send();
+
+ const owner = await contract.methods.ownerOf(tokenId).call();
+ expect(owner).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');
+ });
+});
tests/src/eth/tokens/minting.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/eth/tokens/minting.test.ts
@@ -0,0 +1,167 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {IKeyringPair} from '@polkadot/types/types';
+import {Pallets} from '../../util';
+import {expect, itEth, usingEthPlaygrounds} from '../util';
+
+
+describe('Minting tokens', () => {
+ let donor: IKeyringPair;
+ let alice: IKeyringPair;
+
+ before(async function() {
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ donor = await privateKey({filename: __filename});
+ [alice] = await helper.arrange.createAccounts([30n, 20n], donor);
+ });
+ });
+
+ [
+ {mode: 'nft' as const, requiredPallets: []},
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ {mode: 'ft' as const, requiredPallets: []},
+ ].map(testCase => {
+ itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: Can mint() for Substrate collection`, testCase.requiredPallets, async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const mintingParams = testCase.mode === 'ft' ? [receiver, 100] : [receiver];
+
+ const collection = await helper[testCase.mode].mintCollection(alice);
+ await collection.addAdmin(alice, {Ethereum: owner});
+
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
+
+ const result = await contract.methods.mint(...mintingParams).send({from: owner});
+
+ // Check events:
+ const event = result.events.Transfer;
+ expect(event.address).to.equal(collectionAddress);
+ expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.equal(receiver);
+ if (testCase.mode === 'ft')
+ expect(event.returnValues.value).to.equal('100');
+
+ // Check token exist:
+ if(testCase.mode === 'ft') {
+ expect(await helper.ft.getBalance(collection.collectionId, {Ethereum: receiver})).to.eq(100n);
+ } else {
+ const tokenId = event.returnValues.tokenId;
+ expect(tokenId).to.be.equal('1');
+ expect(await helper.collection.getLastTokenId(collection.collectionId)).to.eq(1);
+ expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
+ }
+ });
+ });
+
+ [
+ {mode: 'nft' as const, requiredPallets: []},
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ {mode: 'ft' as const, requiredPallets: []},
+ ].map(testCase => {
+ itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: Can mint() for Ethereum collection`, testCase.requiredPallets, async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const mintingParams = testCase.mode === 'ft' ? [receiver, 100] : [receiver];
+
+ const {collection, collectionAddress, collectionId} = await helper.eth.createCollection(testCase.mode, owner, 'Name', 'Desc', 'Prefix');
+
+ const result = await collection.methods.mint(...mintingParams).send({from: owner});
+
+ // Check events:
+ const event = result.events.Transfer;
+ expect(event.address).to.equal(collectionAddress);
+ expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.equal(receiver);
+ if (testCase.mode === 'ft')
+ expect(event.returnValues.value).to.equal('100');
+
+ // Check token exist:
+ if(testCase.mode === 'ft') {
+ expect(await helper.ft.getBalance(collectionId, {Ethereum: receiver})).to.eq(100n);
+ } else {
+ const tokenId = event.returnValues.tokenId;
+ expect(tokenId).to.be.equal('1');
+ expect(await helper.collection.getLastTokenId(collectionId)).to.eq(1);
+ expect(await collection.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
+ }
+ });
+ });
+
+ [
+ {mode: 'nft' as const, requiredPallets: []},
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ {mode: 'ft' as const, requiredPallets: []},
+ ].map(testCase => {
+ itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: Can mint() for Ethereum collection`, testCase.requiredPallets, async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const mintingParams = testCase.mode === 'ft' ? [receiver, 100] : [receiver];
+
+ const {collection, collectionAddress, collectionId} = await helper.eth.createCollection(testCase.mode, owner, 'Name', 'Desc', 'Prefix');
+
+ const result = await collection.methods.mint(...mintingParams).send({from: owner});
+
+ // Check events:
+ const event = result.events.Transfer;
+ expect(event.address).to.equal(collectionAddress);
+ expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.equal(receiver);
+ if (testCase.mode === 'ft')
+ expect(event.returnValues.value).to.equal('100');
+
+ // Check token exist:
+ if(testCase.mode === 'ft') {
+ expect(await helper.ft.getBalance(collectionId, {Ethereum: receiver})).to.eq(100n);
+ } else {
+ const tokenId = event.returnValues.tokenId;
+ expect(tokenId).to.be.equal('1');
+ expect(await helper.collection.getLastTokenId(collectionId)).to.eq(1);
+ expect(await collection.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
+ }
+ });
+ });
+
+ [
+ {mode: 'nft' as const, requiredPallets: []},
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ ].map(testCase => {
+ itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: Can mintWithTokenURI() for Ethereum collection`, testCase.requiredPallets, async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+
+ const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', '6', '6', '');
+ const contract = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
+
+ const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();
+ const tokenId = result.events.Transfer.returnValues.tokenId;
+ expect(tokenId).to.be.equal('1');
+
+ 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);
+
+ expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');
+ expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
+ // TODO: this wont work right now, need release 919000 first
+ // await helper.methods.setOffchainSchema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();
+ // const tokenUri = await contract.methods.tokenURI(nextTokenId).call();
+ // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);
+ });
+ });
+});
\ No newline at end of file
tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/tests/src/eth/util/playgrounds/unique.dev.ts
+++ b/tests/src/eth/util/playgrounds/unique.dev.ts
@@ -257,7 +257,7 @@
}
}
- async createCollection(mode: TCollectionMode, signer: string, name: string, description: string, tokenPrefix: string, decimals = 18): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {
+ 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 }> {
const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();
const collectionHelper = await this.helper.ethNativeContract.collectionHelpers(signer);
const functionName: string = this.createCollectionMethodName(mode);
@@ -268,8 +268,9 @@
const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);
const events = this.helper.eth.normalizeEvents(result.events);
+ const collection = await this.helper.ethNativeContract.collectionById(collectionId, mode, signer, mergeDeprecated);
- return {collectionId, collectionAddress, events};
+ return {collectionId, collectionAddress, events, collection};
}
createNFTCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {
tests/src/nesting/nest.test.tsdiffbeforeafterboth--- a/tests/src/nesting/nest.test.ts
+++ b/tests/src/nesting/nest.test.ts
@@ -15,7 +15,7 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {IKeyringPair} from '@polkadot/types/types';
-import {expect, itSub, Pallets, usingPlaygrounds} from '../util';
+import {expect, itSub, usingPlaygrounds} from '../util';
describe('Integration Test: Composite nesting tests', () => {
let alice: IKeyringPair;
@@ -287,54 +287,7 @@
await collectionFT.mint(charlie, 5n);
await collectionFT.transfer(charlie, targetToken.nestingAccount(), 2n);
expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(7n);
- });
-
- // ---------- Re-Fungible ----------
-
- itSub.ifWithPallets('ReFungible: allows an Owner to nest/unnest their token', [Pallets.ReFungible], async ({helper}) => {
- const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}}});
- const collectionRFT = await helper.rft.mintCollection(alice);
- const targetToken = await collectionNFT.mintToken(alice, {Substrate: charlie.address});
-
- await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});
- await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());
-
- await collectionRFT.setPermissions(alice, {access: 'AllowList', mintMode: true});
- await collectionRFT.addToAllowList(alice, {Substrate: charlie.address});
- await collectionRFT.addToAllowList(alice, targetToken.nestingAccount());
-
- // Create an immediately nested token
- const nestedToken = await collectionRFT.mintToken(charlie, 5n, targetToken.nestingAccount());
- expect(await nestedToken.getBalance(targetToken.nestingAccount())).to.be.equal(5n);
-
- // Create a token to be nested and nest
- const newToken = await collectionRFT.mintToken(charlie, 5n);
- await newToken.transfer(charlie, targetToken.nestingAccount(), 2n);
- expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(2n);
});
-
- itSub.ifWithPallets('ReFungible: allows an Owner to nest/unnest their token (Restricted nesting)', [Pallets.ReFungible], async ({helper}) => {
- const collectionNFT = await helper.nft.mintCollection(alice);
- const collectionRFT = await helper.rft.mintCollection(alice);
- const targetToken = await collectionNFT.mintToken(alice, {Substrate: charlie.address});
-
- await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted:[collectionRFT.collectionId]}});
- await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});
- await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());
-
- await collectionRFT.setPermissions(alice, {access: 'AllowList', mintMode: true});
- await collectionRFT.addToAllowList(alice, {Substrate: charlie.address});
- await collectionRFT.addToAllowList(alice, targetToken.nestingAccount());
-
- // Create an immediately nested token
- const nestedToken = await collectionRFT.mintToken(charlie, 5n, targetToken.nestingAccount());
- expect(await nestedToken.getBalance(targetToken.nestingAccount())).to.be.equal(5n);
-
- // Create a token to be nested and nest
- const newToken = await collectionRFT.mintToken(charlie, 5n);
- await newToken.transfer(charlie, targetToken.nestingAccount(), 2n);
- expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(2n);
- });
});
describe('Negative Test: Nesting', () => {
@@ -579,89 +532,5 @@
expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(0n);
expect(await collectionFT.getBalance({Substrate: alice.address})).to.be.equal(5n);
- });
-
- // ---------- Re-Fungible ----------
-
- itSub.ifWithPallets('ReFungible: disallows to nest token if nesting is disabled', [Pallets.ReFungible], async ({helper}) => {
- const collectionNFT = await helper.nft.mintCollection(alice);
- const collectionRFT = await helper.rft.mintCollection(alice);
- const targetToken = await collectionNFT.mintToken(alice);
-
- // Try to create an immediately nested token
- await expect(collectionRFT.mintToken(alice, 5n, targetToken.nestingAccount()))
- .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);
-
- // Try to create a token to be nested and nest
- const token = await collectionRFT.mintToken(alice, 5n);
- await expect(token.transfer(alice, targetToken.nestingAccount(), 2n))
- .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(5n);
- });
-
- itSub.ifWithPallets('ReFungible: disallows a non-Owner to nest someone else\'s token', [Pallets.ReFungible], async ({helper}) => {
- const collectionNFT = await helper.nft.mintCollection(alice);
- const collectionRFT = await helper.rft.mintCollection(alice);
- const targetToken = await collectionNFT.mintToken(alice);
-
- await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}});
- await collectionNFT.addToAllowList(alice, {Substrate: bob.address});
- await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());
-
- // Try to create a token to be nested and nest
- const newToken = await collectionRFT.mintToken(alice);
- await expect(newToken.transfer(bob, targetToken.nestingAccount())).to.be.rejectedWith(/common\.TokenValueTooLow/);
-
- expect(await targetToken.getChildren()).to.be.length(0);
- expect(await newToken.getBalance({Substrate: alice.address})).to.be.equal(1n);
-
- // Nest some tokens as Alice into Bob's token
- await newToken.transfer(alice, targetToken.nestingAccount());
-
- // Try to pull it out
- await expect(newToken.transferFrom(bob, targetToken.nestingAccount(), {Substrate: alice.address}, 1n))
- .to.be.rejectedWith(/common\.ApprovedValueTooLow/);
- expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(1n);
- });
-
- itSub.ifWithPallets('ReFungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', [Pallets.ReFungible], async ({helper}) => {
- const collectionNFT = await helper.nft.mintCollection(alice);
- const collectionRFT = await helper.rft.mintCollection(alice);
- const targetToken = await collectionNFT.mintToken(alice);
-
- await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted: [collectionRFT.collectionId]}});
- await collectionNFT.addToAllowList(alice, {Substrate: bob.address});
- await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());
-
- // Try to create a token to be nested and nest
- const newToken = await collectionRFT.mintToken(alice);
- await expect(newToken.transfer(bob, targetToken.nestingAccount())).to.be.rejectedWith(/common\.TokenValueTooLow/);
-
- expect(await targetToken.getChildren()).to.be.length(0);
- expect(await newToken.getBalance({Substrate: alice.address})).to.be.equal(1n);
-
- // Nest some tokens as Alice into Bob's token
- await newToken.transfer(alice, targetToken.nestingAccount());
-
- // Try to pull it out
- await expect(newToken.transferFrom(bob, targetToken.nestingAccount(), {Substrate: alice.address}, 1n))
- .to.be.rejectedWith(/common\.ApprovedValueTooLow/);
- expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(1n);
- });
-
- itSub.ifWithPallets('ReFungible: disallows to nest token to an unlisted collection', [Pallets.ReFungible], async ({helper}) => {
- const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true, restricted: []}}});
- const collectionRFT = await helper.rft.mintCollection(alice);
- const targetToken = await collectionNFT.mintToken(alice);
-
- // Try to create an immediately nested token
- await expect(collectionRFT.mintToken(alice, 5n, targetToken.nestingAccount()))
- .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
-
- // Try to create a token to be nested and nest
- const token = await collectionRFT.mintToken(alice, 5n);
- await expect(token.transfer(alice, targetToken.nestingAccount(), 2n))
- .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(5n);
});
});
tests/src/refungible.test.tsdiffbeforeafterboth--- a/tests/src/refungible.test.ts
+++ b/tests/src/refungible.test.ts
@@ -88,20 +88,6 @@
expect((await token.getTop10Owners()).length).to.be.equal(10);
});
- itSub('Transfer token pieces', async ({helper}) => {
- const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
- const token = await collection.mintToken(alice, 100n);
-
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
- expect(await token.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;
-
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);
- expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);
-
- await expect(token.transfer(alice, {Substrate: bob.address}, 41n))
- .to.eventually.be.rejectedWith(/common\.TokenValueTooLow/);
- });
-
itSub('Create multiple tokens', async ({helper}) => {
const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
// TODO: fix mintMultipleTokens
@@ -118,56 +104,8 @@
const lastTokenId = await collection.getLastTokenId();
expect(lastTokenId).to.be.equal(3);
expect(await collection.getTokenBalance(lastTokenId, {Substrate: alice.address})).to.be.equal(100n);
- });
-
- itSub('Burn some pieces', async ({helper}) => {
- const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
- const token = await collection.mintToken(alice, 100n);
- expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
- expect(await token.burn(alice, 99n)).to.be.true;
- expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(1n);
});
- itSub('Burn all pieces', async ({helper}) => {
- const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
- const token = await collection.mintToken(alice, 100n);
-
- expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
-
- expect(await token.burn(alice, 100n)).to.be.true;
- expect(await collection.doesTokenExist(token.tokenId)).to.be.false;
- });
-
- itSub('Burn some pieces for multiple users', async ({helper}) => {
- const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
- const token = await collection.mintToken(alice, 100n);
-
- expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
-
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
- expect(await token.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;
-
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);
- expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);
-
- expect(await token.burn(alice, 40n)).to.be.true;
-
- expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);
-
- expect(await token.burn(bob, 59n)).to.be.true;
-
- expect(await token.getBalance({Substrate: bob.address})).to.be.equal(1n);
- expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
-
- expect(await token.burn(bob, 1n)).to.be.true;
-
- expect(await collection.doesTokenExist(token.tokenId)).to.be.false;
- });
-
itSub('Set allowance for token', async ({helper}) => {
const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
const token = await collection.mintToken(alice, 100n);
@@ -183,68 +121,6 @@
expect(await token.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(40n);
});
- itSub('Repartition', async ({helper}) => {
- const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
- const token = await collection.mintToken(alice, 100n);
-
- expect(await token.repartition(alice, 200n)).to.be.true;
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(200n);
- expect(await token.getTotalPieces()).to.be.equal(200n);
-
- expect(await token.transfer(alice, {Substrate: bob.address}, 110n)).to.be.true;
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(90n);
- expect(await token.getBalance({Substrate: bob.address})).to.be.equal(110n);
-
- await expect(token.repartition(alice, 80n))
- .to.eventually.be.rejectedWith(/refungible\.RepartitionWhileNotOwningAllPieces/);
-
- expect(await token.transfer(alice, {Substrate: bob.address}, 90n)).to.be.true;
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);
- expect(await token.getBalance({Substrate: bob.address})).to.be.equal(200n);
-
- expect(await token.repartition(bob, 150n)).to.be.true;
- await expect(token.transfer(bob, {Substrate: alice.address}, 160n))
- .to.eventually.be.rejectedWith(/common\.TokenValueTooLow/);
- });
-
- itSub('Repartition with increased amount', async ({helper}) => {
- const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
- const token = await collection.mintToken(alice, 100n);
- await token.repartition(alice, 200n);
- const chainEvents = helper.chainLog.slice(-1)[0].events;
- const event = chainEvents.find((event: any) => event.section === 'common' && event.method === 'ItemCreated');
- expect(event).to.deep.include({
- section: 'common',
- method: 'ItemCreated',
- index: [66, 2],
- data: [
- collection.collectionId,
- token.tokenId,
- {substrate: alice.address},
- 100n,
- ],
- });
- });
-
- itSub('Repartition with decreased amount', async ({helper}) => {
- const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
- const token = await collection.mintToken(alice, 100n);
- await token.repartition(alice, 50n);
- const chainEvents = helper.chainLog.slice(-1)[0].events;
- const event = chainEvents.find((event: any) => event.section === 'common' && event.method === 'ItemDestroyed');
- expect(event).to.deep.include({
- section: 'common',
- method: 'ItemDestroyed',
- index: [66, 3],
- data: [
- collection.collectionId,
- token.tokenId,
- {substrate: alice.address},
- 50n,
- ],
- });
- });
-
itSub('Create new collection with properties', async ({helper}) => {
const properties = [{key: 'key1', value: 'val1'}];
const tokenPropertyPermissions = [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}];
@@ -252,46 +128,5 @@
const info = await collection.getData();
expect(info?.raw.properties).to.be.deep.equal(properties);
expect(info?.raw.tokenPropertyPermissions).to.be.deep.equal(tokenPropertyPermissions);
- });
-});
-
-describe('Refungible negative tests', () => {
- let donor: IKeyringPair;
- let alice: IKeyringPair;
- let bob: IKeyringPair;
- let charlie: IKeyringPair;
-
- before(async function() {
- await usingPlaygrounds(async (helper, privateKey) => {
- requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
-
- donor = await privateKey({filename: __filename});
- [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
- });
- });
-
- itSub('Cannot transfer incorrect amount of token pieces', async ({helper}) => {
- const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
- const tokenAlice = await collection.mintToken(alice, 10n, {Substrate: alice.address});
- const tokenBob = await collection.mintToken(alice, 10n, {Substrate: bob.address});
-
- // 1. Alice cannot transfer Bob's token:
- await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
- await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');
- await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 10n)).to.be.rejectedWith('common.TokenValueTooLow');
- await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 100n)).to.be.rejectedWith('common.TokenValueTooLow');
-
- // 2. Alice cannot transfer non-existing token:
- await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
- await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');
-
- // 3. Zero transfer allowed (EIP-20):
- await tokenAlice.transfer(alice, {Substrate: charlie.address}, 0n);
-
- expect(await tokenAlice.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
- expect(await tokenBob.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
- expect(await tokenAlice.getBalance({Substrate: alice.address})).to.eq(10n);
- expect(await tokenBob.getBalance({Substrate: bob.address})).to.eq(10n);
- expect(await tokenBob.getBalance({Substrate: charlie.address})).to.eq(0n);
});
});
tests/src/sub/refungible/burn.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/sub/refungible/burn.test.ts
@@ -0,0 +1,127 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {IKeyringPair} from '@polkadot/types/types';
+import {itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds, expect} from '../../util';
+
+describe('Refungible: burn', () => {
+ let donor: IKeyringPair;
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+
+ before(async function() {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+
+ donor = await privateKey({filename: __filename});
+ [alice, bob] = await helper.arrange.createAccounts([100n, 10n], donor);
+ });
+ });
+
+ itSub('can burn some pieces', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+ const token = await collection.mintToken(alice, 100n);
+ expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
+ await token.burn(alice, 99n);
+ expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(1n);
+ });
+
+ itSub('can burn all pieces', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+ const token = await collection.mintToken(alice, 100n);
+
+ expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
+
+ await token.burn(alice, 100n);
+ expect(await collection.doesTokenExist(token.tokenId)).to.be.false;
+ });
+
+ itSub('burn pieces for multiple users', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+ const token = await collection.mintToken(alice, 100n);
+
+ await token.transfer(alice, {Substrate: bob.address}, 60n);
+
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);
+ expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);
+
+ await token.burn(alice, 40n);
+
+ expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);
+
+ await token.burn(bob, 59n);
+
+ expect(await token.getBalance({Substrate: bob.address})).to.be.equal(1n);
+ expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
+
+ await token.burn(bob, 1n);
+
+ expect(await collection.doesTokenExist(token.tokenId)).to.be.false;
+ });
+
+ itSub('burn pieces by admin', async function({helper}) {
+ const collection = await helper.rft.mintCollection(alice);
+ await collection.setLimits(alice, {ownerCanTransfer: true});
+ await collection.addAdmin(alice, {Substrate: bob.address});
+ const token = await collection.mintToken(alice, 100n);
+
+ await token.burnFrom(bob, {Substrate: alice.address}, 100n);
+ expect(await token.doesExist()).to.be.false;
+ });
+});
+
+describe('Refungible: burn negative tests', () => {
+ let donor: IKeyringPair;
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+
+ before(async function() {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+ donor = await privateKey({filename: __filename});
+ [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);
+ });
+ });
+
+ itSub('cannot burn non-owned token pieces', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(alice);
+ const aliceToken = await collection.mintToken(alice, 10n, {Substrate: alice.address});
+ const bobToken = await collection.mintToken(alice, 10n, {Substrate: bob.address});
+
+ // 1. Cannot burn non-owned token:
+ await expect(bobToken.burn(alice, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
+ await expect(bobToken.burn(alice, 5n)).to.be.rejectedWith('common.TokenValueTooLow');
+ // 2. Cannot burn non-existing token:
+ await expect(helper.rft.burnToken(alice, 99999, 10)).to.be.rejectedWith('common.CollectionNotFound');
+ await expect(helper.rft.burnToken(alice, collection.collectionId, 99999)).to.be.rejectedWith('common.TokenValueTooLow');
+ // 3. Can burn zero amount of owned tokens (EIP-20)
+ await aliceToken.burn(alice, 0n);
+
+ // 4. Storage is not corrupted:
+ expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
+ expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
+
+ // 4.1 Tokens can be transfered:
+ await aliceToken.transfer(alice, {Substrate: bob.address}, 10n);
+ await bobToken.transfer(bob, {Substrate: alice.address}, 10n);
+ expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
+ expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
+ });
+});
tests/src/sub/refungible/nesting.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/sub/refungible/nesting.test.ts
@@ -0,0 +1,180 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {IKeyringPair} from '@polkadot/types/types';
+import {expect, itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds} from '../../util';
+
+describe('Refungible nesting', () => {
+ let alice: IKeyringPair;
+ let charlie: IKeyringPair;
+
+ before(async function() {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+ const donor = await privateKey({filename: __filename});
+ [alice, charlie] = await helper.arrange.createAccounts([50n, 10n], donor);
+ });
+ });
+
+ [
+ {restrictedMode: true},
+ {restrictedMode: false},
+ ].map(testCase => {
+ itSub(`Owner can nest their token${testCase.restrictedMode ? ': Restricted mode' : ''}`, async ({helper}) => {
+ const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}}});
+ const collectionRFT = await helper.rft.mintCollection(alice);
+ const targetToken = await collectionNFT.mintToken(alice, {Substrate: charlie.address});
+
+ await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted: testCase.restrictedMode ? [collectionRFT.collectionId] : null}});
+ await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});
+ await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());
+
+ await collectionRFT.setPermissions(alice, {access: 'AllowList', mintMode: true});
+ await collectionRFT.addToAllowList(alice, {Substrate: charlie.address});
+ await collectionRFT.addToAllowList(alice, targetToken.nestingAccount());
+
+ // Create an immediately nested token
+ const nestedToken = await collectionRFT.mintToken(charlie, 5n, targetToken.nestingAccount());
+ expect(await nestedToken.getBalance(targetToken.nestingAccount())).to.be.equal(5n);
+
+ // Create a token to be nested and nest
+ const newToken = await collectionRFT.mintToken(charlie, 5n);
+ await newToken.transfer(charlie, targetToken.nestingAccount(), 2n);
+ expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(2n);
+ expect(await newToken.getBalance({Substrate: charlie.address})).to.be.equal(3n);
+ });
+ });
+
+ itSub('Owner can unnest nested token', async ({helper}) => {
+ const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});
+ const targetToken = await collection.mintToken(alice);
+
+ // Owner mints nested RFT token:
+ const collectionRFT = await helper.rft.mintCollection(alice);
+ const token = await collectionRFT.mintToken(alice, 10n, targetToken.nestingAccount());
+
+ // 1.1 Owner can partially unnest token pieces with transferFrom:
+ await token.transferFrom(alice, targetToken.nestingAccount(), {Substrate: alice.address}, 9n);
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(9n);
+ expect(await token.getBalance(targetToken.nestingAccount())).to.be.equal(1n);
+
+ // 1.2 Owner can unnest all pieces:
+ await token.transferFrom(alice, targetToken.nestingAccount(), {Substrate: alice.address}, 1n);
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(10n);
+ expect(await token.getBalance(targetToken.nestingAccount())).to.be.equal(0n);
+ });
+
+ itSub('Owner can burn nested token pieces', async ({helper}) => {
+ const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});
+ const targetToken = await collection.mintToken(alice);
+
+ // Owner mints nested RFT token:
+ const collectionRFT = await helper.rft.mintCollection(alice);
+ const token = await collectionRFT.mintToken(alice, 100n, {Substrate: alice.address});
+ await token.transfer(alice, targetToken.nestingAccount(), 30n);
+
+ // 1.1 Owner can partially burnFrom nested pieces:
+ await token.burnFrom(alice, targetToken.nestingAccount(), 10n);
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(70n);
+ expect(await token.getBalance(targetToken.nestingAccount())).to.be.equal(20n);
+ expect(await targetToken.getChildren()).to.has.length(1);
+
+ // 1.1 Owner can burnFrom all nested pieces:
+ await token.burnFrom(alice, targetToken.nestingAccount(), 20n);
+ expect(await token.getBalance(targetToken.nestingAccount())).to.be.equal(0n);
+ expect(await targetToken.getChildren()).to.has.length(0);
+ expect(await token.doesExist()).to.be.true;
+
+ // 2. Target token does not contain any pieces and can be burnt:
+ await targetToken.burn(alice);
+ expect(await targetToken.doesExist()).to.be.false;
+ });
+});
+
+describe('Refungible nesting negative tests', () => {
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+
+ before(async function() {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+ const donor = await privateKey({filename: __filename});
+ [alice, bob] = await helper.arrange.createAccounts([100n, 50n], donor);
+ });
+ });
+
+ itSub('cannot nest token if nesting is disabled', async ({helper}) => {
+ const collectionNFT = await helper.nft.mintCollection(alice);
+ const collectionRFT = await helper.rft.mintCollection(alice);
+ const targetToken = await collectionNFT.mintToken(alice);
+
+ // Try to create an immediately nested token
+ await expect(collectionRFT.mintToken(alice, 5n, targetToken.nestingAccount()))
+ .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);
+
+ // Try to create a token to be nested and nest
+ const token = await collectionRFT.mintToken(alice, 5n);
+ await expect(token.transfer(alice, targetToken.nestingAccount(), 2n))
+ .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(5n);
+ });
+
+ [
+ {restrictedMode: true},
+ {restrictedMode: false},
+ ].map(testCase => {
+ itSub(`non-Owner cannot nest someone else's token${testCase.restrictedMode ? ': Restricted mode' : ''}`, async ({helper}) => {
+ const collectionNFT = await helper.nft.mintCollection(alice);
+ const collectionRFT = await helper.rft.mintCollection(alice);
+ const targetToken = await collectionNFT.mintToken(alice);
+
+ await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted: testCase.restrictedMode ? [collectionRFT.collectionId] : null}});
+ await collectionNFT.addToAllowList(alice, {Substrate: bob.address});
+ await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());
+
+ // Try to create a token to be nested and nest
+ const newToken = await collectionRFT.mintToken(alice);
+ await expect(newToken.transfer(bob, targetToken.nestingAccount())).to.be.rejectedWith(/common\.TokenValueTooLow/);
+
+ expect(await targetToken.getChildren()).to.be.length(0);
+ expect(await newToken.getBalance({Substrate: alice.address})).to.be.equal(1n);
+
+ // Nest some tokens as Alice into Bob's token
+ await newToken.transfer(alice, targetToken.nestingAccount());
+
+ // Try to pull it out
+ await expect(newToken.transferFrom(bob, targetToken.nestingAccount(), {Substrate: alice.address}, 1n))
+ .to.be.rejectedWith(/common\.ApprovedValueTooLow/);
+ expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(1n);
+ });
+ });
+
+ itSub('ReFungible: disallows to nest token to an unlisted collection', async ({helper}) => {
+ const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true, restricted: []}}});
+ const collectionRFT = await helper.rft.mintCollection(alice);
+ const targetToken = await collectionNFT.mintToken(alice);
+
+ // Try to create an immediately nested token
+ await expect(collectionRFT.mintToken(alice, 5n, targetToken.nestingAccount()))
+ .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
+
+ // Try to create a token to be nested and nest
+ const token = await collectionRFT.mintToken(alice, 5n);
+ await expect(token.transfer(alice, targetToken.nestingAccount(), 2n))
+ .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(5n);
+ });
+});
tests/src/sub/refungible/repartition.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/sub/refungible/repartition.test.ts
@@ -0,0 +1,96 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {IKeyringPair} from '@polkadot/types/types';
+import {itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds, expect} from '../../util';
+
+describe('integration test: Refungible functionality:', () => {
+ let donor: IKeyringPair;
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+
+ before(async function() {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+
+ donor = await privateKey({filename: __filename});
+ [alice, bob] = await helper.arrange.createAccounts([100n, 10n], donor);
+ });
+ });
+
+ itSub('Repartition', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+ const token = await collection.mintToken(alice, 100n);
+
+ expect(await token.repartition(alice, 200n)).to.be.true;
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(200n);
+ expect(await token.getTotalPieces()).to.be.equal(200n);
+
+ expect(await token.transfer(alice, {Substrate: bob.address}, 110n)).to.be.true;
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(90n);
+ expect(await token.getBalance({Substrate: bob.address})).to.be.equal(110n);
+
+ await expect(token.repartition(alice, 80n))
+ .to.eventually.be.rejectedWith(/refungible\.RepartitionWhileNotOwningAllPieces/);
+
+ expect(await token.transfer(alice, {Substrate: bob.address}, 90n)).to.be.true;
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);
+ expect(await token.getBalance({Substrate: bob.address})).to.be.equal(200n);
+
+ expect(await token.repartition(bob, 150n)).to.be.true;
+ await expect(token.transfer(bob, {Substrate: alice.address}, 160n))
+ .to.eventually.be.rejectedWith(/common\.TokenValueTooLow/);
+ });
+
+ itSub('Repartition with increased amount', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+ const token = await collection.mintToken(alice, 100n);
+ await token.repartition(alice, 200n);
+ const chainEvents = helper.chainLog.slice(-1)[0].events;
+ const event = chainEvents.find((event: any) => event.section === 'common' && event.method === 'ItemCreated');
+ expect(event).to.deep.include({
+ section: 'common',
+ method: 'ItemCreated',
+ index: [66, 2],
+ data: [
+ collection.collectionId,
+ token.tokenId,
+ {substrate: alice.address},
+ 100n,
+ ],
+ });
+ });
+
+ itSub('Repartition with decreased amount', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+ const token = await collection.mintToken(alice, 100n);
+ await token.repartition(alice, 50n);
+ const chainEvents = helper.chainLog.slice(-1)[0].events;
+ const event = chainEvents.find((event: any) => event.section === 'common' && event.method === 'ItemDestroyed');
+ expect(event).to.deep.include({
+ section: 'common',
+ method: 'ItemDestroyed',
+ index: [66, 3],
+ data: [
+ collection.collectionId,
+ token.tokenId,
+ {substrate: alice.address},
+ 50n,
+ ],
+ });
+ });
+});
+
tests/src/sub/refungible/transfer.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/sub/refungible/transfer.test.ts
@@ -0,0 +1,73 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {IKeyringPair} from '@polkadot/types/types';
+import {itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds, expect} from '../../util';
+
+describe('Refungible transfer tests', () => {
+ let donor: IKeyringPair;
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+ let charlie: IKeyringPair;
+
+ before(async function() {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+
+ donor = await privateKey({filename: __filename});
+ [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
+ });
+ });
+
+ itSub('Can transfer token pieces', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+ const token = await collection.mintToken(alice, 100n);
+
+ expect(await token.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;
+ // 1. Can transfer less or equal than have:
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);
+ expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);
+ });
+
+ itSub('Cannot transfer incorrect amount of token pieces', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+ const tokenAlice = await collection.mintToken(alice, 10n, {Substrate: alice.address});
+ const tokenBob = await collection.mintToken(alice, 10n, {Substrate: bob.address});
+
+ // 1. Alice cannot transfer Bob's token:
+ await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
+ await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');
+ await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 10n)).to.be.rejectedWith('common.TokenValueTooLow');
+ await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 100n)).to.be.rejectedWith('common.TokenValueTooLow');
+
+ // 2. Alice cannot transfer non-existing token:
+ await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
+ await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');
+
+ // 3. Cannot transfer more than have:
+ await expect(tokenAlice.transfer(alice, {Substrate: bob.address}, 11n))
+ .to.eventually.be.rejectedWith(/common\.TokenValueTooLow/);
+
+ // 4. Zero transfer allowed (EIP-20):
+ await tokenAlice.transfer(alice, {Substrate: charlie.address}, 0n);
+
+ expect(await tokenAlice.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
+ expect(await tokenBob.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
+ expect(await tokenAlice.getBalance({Substrate: alice.address})).to.eq(10n);
+ expect(await tokenBob.getBalance({Substrate: bob.address})).to.eq(10n);
+ expect(await tokenBob.getBalance({Substrate: charlie.address})).to.eq(0n);
+ });
+});
\ No newline at end of file
tests/src/util/index.tsdiffbeforeafterboth--- a/tests/src/util/index.ts
+++ b/tests/src/util/index.ts
@@ -100,6 +100,9 @@
export const LOCKING_PERIOD = 12n; // 12 blocks of relay
export const UNLOCKING_PERIOD = 6n; // 6 blocks of parachain
+// Native contracts
+export const COLLECTION_HELPER = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f';
+export const CONTRACT_HELPER = '0x842899ECF380553E8a4de75bF534cdf6fBF64049';
export enum Pallets {
Inflation = 'inflation',