difftreelog
chore fix tests
in: master
12 files changed
tests/src/eth/collectionAdmin.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionAdmin.test.ts
+++ b/tests/src/eth/collectionAdmin.test.ts
@@ -30,10 +30,10 @@
itWeb3('Add admin by owner', async ({api, web3, privateKeyWrapper}) => {
const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
const collectionHelper = evmCollectionHelpers(web3, owner);
-
+
const result = await collectionHelper.methods
.createNonfungibleCollection('A', 'B', 'C')
- .send();
+ .send({value: Number(2n * UNIQUE)});
const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
const newAdmin = createEthAccount(web3);
@@ -69,7 +69,7 @@
const result = await collectionHelper.methods
.createNonfungibleCollection('A', 'B', 'C')
- .send();
+ .send({value: Number(2n * UNIQUE)});
const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
const newAdmin = createEthAccount(web3);
@@ -85,7 +85,7 @@
const result = await collectionHelper.methods
.createNonfungibleCollection('A', 'B', 'C')
- .send();
+ .send({value: Number(2n * UNIQUE)});
const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
const admin = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
@@ -108,7 +108,7 @@
const result = await collectionHelper.methods
.createNonfungibleCollection('A', 'B', 'C')
- .send();
+ .send({value: Number(2n * UNIQUE)});
const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
const notAdmin = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
@@ -174,7 +174,7 @@
const result = await collectionHelper.methods
.createNonfungibleCollection('A', 'B', 'C')
- .send();
+ .send({value: Number(2n * UNIQUE)});
const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
const newAdmin = createEthAccount(web3);
@@ -222,7 +222,7 @@
const result = await collectionHelper.methods
.createNonfungibleCollection('A', 'B', 'C')
- .send();
+ .send({value: Number(2n * UNIQUE)});
const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
@@ -249,7 +249,7 @@
const result = await collectionHelper.methods
.createNonfungibleCollection('A', 'B', 'C')
- .send();
+ .send({value: Number(2n * UNIQUE)});
const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
@@ -326,7 +326,7 @@
const collectionHelper = evmCollectionHelpers(web3, owner);
const result = await collectionHelper.methods
.createNonfungibleCollection('A', 'B', 'C')
- .send();
+ .send({value: Number(2n * UNIQUE)});
const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
@@ -342,7 +342,7 @@
const collectionHelper = evmCollectionHelpers(web3, owner);
const result = await collectionHelper.methods
.createNonfungibleCollection('A', 'B', 'C')
- .send();
+ .send({value: Number(2n * UNIQUE)});
const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
@@ -357,7 +357,7 @@
const collectionHelper = evmCollectionHelpers(web3, owner);
const result = await collectionHelper.methods
.createNonfungibleCollection('A', 'B', 'C')
- .send();
+ .send({value: Number(2n * UNIQUE)});
const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
tests/src/eth/collectionSponsoring.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionSponsoring.test.ts
+++ b/tests/src/eth/collectionSponsoring.test.ts
@@ -1,10 +1,8 @@
-import {addToAllowListExpectSuccess, bigIntToSub, confirmSponsorshipExpectSuccess, createCollectionExpectSuccess, enablePublicMintingExpectSuccess, getDetailedCollectionInfo, setCollectionSponsorExpectSuccess} from '../util/helpers';
+import {addToAllowListExpectSuccess, confirmSponsorshipExpectSuccess, createCollectionExpectSuccess, enablePublicMintingExpectSuccess, getDetailedCollectionInfo, setCollectionSponsorExpectSuccess, UNIQUE} from '../util/helpers';
import {itWeb3, createEthAccount, collectionIdToAddress, GAS_ARGS, normalizeEvents, createEthAccountWithBalance, evmCollectionHelpers, getCollectionAddressFromResult, evmCollection, ethBalanceViaSub} from './util/helpers';
import nonFungibleAbi from './nonFungibleAbi.json';
import {expect} from 'chai';
import {evmToAddress} from '@polkadot/util-crypto';
-import {submitTransactionAsync} from '../substrate/substrate-api';
-import getBalance from '../substrate/get-balance';
describe('evm collection sponsoring', () => {
itWeb3('sponsors mint transactions', async ({web3, privateKeyWrapper}) => {
@@ -64,7 +62,7 @@
itWeb3('Remove sponsor', async ({api, web3, privateKeyWrapper}) => {
const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
const collectionHelpers = evmCollectionHelpers(web3, owner);
- let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send();
+ let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send({value: Number(2n * UNIQUE)});
const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
@@ -85,7 +83,7 @@
itWeb3('Sponsoring collection from evm address via access list', async ({api, web3, privateKeyWrapper}) => {
const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
const collectionHelpers = evmCollectionHelpers(web3, owner);
- let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send();
+ let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send({value: Number(2n * UNIQUE)});
const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
@@ -210,7 +208,7 @@
itWeb3('Check that transaction via EVM spend money from sponsor address', async ({api, web3, privateKeyWrapper}) => {
const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
const collectionHelpers = evmCollectionHelpers(web3, owner);
- let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send();
+ let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send({value: Number(2n * UNIQUE)});
const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
tests/src/eth/createNFTCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createNFTCollection.test.ts
+++ b/tests/src/eth/createNFTCollection.test.ts
@@ -17,6 +17,7 @@
import {evmToAddress} from '@polkadot/util-crypto';
import {IKeyringPair} from '@polkadot/types/types';
import {expect, itEth, usingEthPlaygrounds} from './util/playgrounds';
+import {UNIQUE} from '../util/helpers';
describe('Create NFT collection from EVM', () => {
let donor: IKeyringPair;
@@ -64,7 +65,7 @@
await collectionHelpers.methods
.createNonfungibleCollection('A', 'A', 'A')
- .send();
+ .send({value: Number(2n * UNIQUE)});
expect(await collectionHelpers.methods
.isCollectionExist(expectedCollectionAddress)
@@ -164,7 +165,7 @@
await expect(collectionHelper.methods
.createNonfungibleCollection(collectionName, description, tokenPrefix)
- .call()).to.be.rejectedWith('name is too long. Max length is ' + MAX_NAME_LENGTH);
+ .call({value: Number(2n * UNIQUE)})).to.be.rejectedWith('name is too long. Max length is ' + MAX_NAME_LENGTH);
}
{
@@ -174,7 +175,7 @@
const tokenPrefix = 'A';
await expect(collectionHelper.methods
.createNonfungibleCollection(collectionName, description, tokenPrefix)
- .call()).to.be.rejectedWith('description is too long. Max length is ' + MAX_DESCRIPTION_LENGTH);
+ .call({value: Number(2n * UNIQUE)})).to.be.rejectedWith('description is too long. Max length is ' + MAX_DESCRIPTION_LENGTH);
}
{
const MAX_TOKEN_PREFIX_LENGTH = 16;
@@ -183,16 +184,16 @@
const tokenPrefix = 'A'.repeat(MAX_TOKEN_PREFIX_LENGTH + 1);
await expect(collectionHelper.methods
.createNonfungibleCollection(collectionName, description, tokenPrefix)
- .call()).to.be.rejectedWith('token_prefix is too long. Max length is ' + MAX_TOKEN_PREFIX_LENGTH);
+ .call({value: Number(2n * UNIQUE)})).to.be.rejectedWith('token_prefix is too long. Max length is ' + MAX_TOKEN_PREFIX_LENGTH);
}
});
itEth('(!negative test!) Create collection (no funds)', async ({helper}) => {
- const owner = helper.eth.createAccount();
+ const owner = await helper.eth.createAccountWithBalance(donor);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
await expect(collectionHelper.methods
.createNonfungibleCollection('Peasantry', 'absolutely anything', 'CVE')
- .call()).to.be.rejectedWith('NotSufficientFounds');
+ .call({value: Number(1n * UNIQUE)})).to.be.rejectedWith('Sent amount not equals to collection creation price (2000000000000000000)');
});
itEth('(!negative test!) Check owner', async ({helper}) => {
tests/src/eth/createRFTCollection.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 {Pallets, requirePalletsOrSkip} from '../util/playgrounds';20import {expect, itEth, usingEthPlaygrounds} from './util/playgrounds';2122describe('Create RFT collection from EVM', () => {23 let donor: IKeyringPair;2425 before(async function() {26 await usingEthPlaygrounds(async (helper, privateKey) => {27 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);28 donor = privateKey('//Alice');29 });30 });3132 itEth('Create collection', async ({helper}) => {33 const owner = await helper.eth.createAccountWithBalance(donor);34 35 const name = 'CollectionEVM';36 const description = 'Some description';37 const prefix = 'token prefix';38 39 // todo:playgrounds this might fail when in async environment.40 const collectionCountBefore = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;41 const {collectionId} = await helper.eth.createRefungibleCollection(owner, name, description, prefix);42 const collectionCountAfter = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;43 44 const data = (await helper.rft.getData(collectionId))!;4546 expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);47 expect(collectionId).to.be.eq(collectionCountAfter);48 expect(data.name).to.be.eq(name);49 expect(data.description).to.be.eq(description);50 expect(data.raw.tokenPrefix).to.be.eq(prefix);51 expect(data.raw.mode).to.be.eq('ReFungible');52 });5354 // todo:playgrounds this test will fail when in async environment.55 itEth('Check collection address exist', async ({helper}) => {56 const owner = await helper.eth.createAccountWithBalance(donor);5758 const expectedCollectionId = +(await helper.callRpc('api.rpc.unique.collectionStats')).created + 1;59 const expectedCollectionAddress = helper.ethAddress.fromCollectionId(expectedCollectionId);60 const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);6162 expect(await collectionHelpers.methods63 .isCollectionExist(expectedCollectionAddress)64 .call()).to.be.false;6566 await collectionHelpers.methods67 .createRFTCollection('A', 'A', 'A')68 .send();69 70 expect(await collectionHelpers.methods71 .isCollectionExist(expectedCollectionAddress)72 .call()).to.be.true;73 });74 75 itEth('Set sponsorship', async ({helper}) => {76 const owner = await helper.eth.createAccountWithBalance(donor);77 const sponsor = await helper.eth.createAccountWithBalance(donor);78 const ss58Format = helper.chain.getChainProperties().ss58Format;79 const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Sponsor', 'absolutely anything', 'ENVY');8081 const collection = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);82 await collection.methods.setCollectionSponsor(sponsor).send();8384 let data = (await helper.rft.getData(collectionId))!;85 expect(data.raw.sponsorship.Unconfirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));8687 await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');8889 const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);90 await sponsorCollection.methods.confirmCollectionSponsorship().send();9192 data = (await helper.rft.getData(collectionId))!;93 expect(data.raw.sponsorship.Confirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));94 });9596 itEth('Set limits', async ({helper}) => {97 const owner = await helper.eth.createAccountWithBalance(donor);98 const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Limits', 'absolutely anything', 'INSI');99 const limits = {100 accountTokenOwnershipLimit: 1000,101 sponsoredDataSize: 1024,102 sponsoredDataRateLimit: 30,103 tokenLimit: 1000000,104 sponsorTransferTimeout: 6,105 sponsorApproveTimeout: 6,106 ownerCanTransfer: false,107 ownerCanDestroy: false,108 transfersEnabled: false,109 };110111 const collection = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);112 await collection.methods['setCollectionLimit(string,uint32)']('accountTokenOwnershipLimit', limits.accountTokenOwnershipLimit).send();113 await collection.methods['setCollectionLimit(string,uint32)']('sponsoredDataSize', limits.sponsoredDataSize).send();114 await collection.methods['setCollectionLimit(string,uint32)']('sponsoredDataRateLimit', limits.sponsoredDataRateLimit).send();115 await collection.methods['setCollectionLimit(string,uint32)']('tokenLimit', limits.tokenLimit).send();116 await collection.methods['setCollectionLimit(string,uint32)']('sponsorTransferTimeout', limits.sponsorTransferTimeout).send();117 await collection.methods['setCollectionLimit(string,uint32)']('sponsorApproveTimeout', limits.sponsorApproveTimeout).send();118 await collection.methods['setCollectionLimit(string,bool)']('ownerCanTransfer', limits.ownerCanTransfer).send();119 await collection.methods['setCollectionLimit(string,bool)']('ownerCanDestroy', limits.ownerCanDestroy).send();120 await collection.methods['setCollectionLimit(string,bool)']('transfersEnabled', limits.transfersEnabled).send();121 122 const data = (await helper.rft.getData(collectionId))!;123 expect(data.raw.limits.accountTokenOwnershipLimit).to.be.eq(limits.accountTokenOwnershipLimit);124 expect(data.raw.limits.sponsoredDataSize).to.be.eq(limits.sponsoredDataSize);125 expect(data.raw.limits.sponsoredDataRateLimit.blocks).to.be.eq(limits.sponsoredDataRateLimit);126 expect(data.raw.limits.tokenLimit).to.be.eq(limits.tokenLimit);127 expect(data.raw.limits.sponsorTransferTimeout).to.be.eq(limits.sponsorTransferTimeout);128 expect(data.raw.limits.sponsorApproveTimeout).to.be.eq(limits.sponsorApproveTimeout);129 expect(data.raw.limits.ownerCanTransfer).to.be.eq(limits.ownerCanTransfer);130 expect(data.raw.limits.ownerCanDestroy).to.be.eq(limits.ownerCanDestroy);131 expect(data.raw.limits.transfersEnabled).to.be.eq(limits.transfersEnabled);132 });133134 itEth('Collection address exist', async ({helper}) => {135 const owner = await helper.eth.createAccountWithBalance(donor);136 const collectionAddressForNonexistentCollection = '0x17C4E6453CC49AAAAEACA894E6D9683E00112233';137 expect(await helper.ethNativeContract.collectionHelpers(collectionAddressForNonexistentCollection)138 .methods.isCollectionExist(collectionAddressForNonexistentCollection).call())139 .to.be.false;140 141 const {collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Exister', 'absolutely anything', 'WIWT');142 expect(await helper.ethNativeContract.collectionHelpers(collectionAddress)143 .methods.isCollectionExist(collectionAddress).call())144 .to.be.true;145 });146});147148describe('(!negative tests!) Create RFT collection from EVM', () => {149 let donor: IKeyringPair;150151 before(async function() {152 await usingEthPlaygrounds(async (helper, privateKey) => {153 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);154 donor = privateKey('//Alice');155 });156 });157158 itEth('(!negative test!) Create collection (bad lengths)', async ({helper}) => {159 const owner = await helper.eth.createAccountWithBalance(donor);160 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);161 {162 const MAX_NAME_LENGTH = 64;163 const collectionName = 'A'.repeat(MAX_NAME_LENGTH + 1);164 const description = 'A';165 const tokenPrefix = 'A';166167 await expect(collectionHelper.methods168 .createRFTCollection(collectionName, description, tokenPrefix)169 .call()).to.be.rejectedWith('name is too long. Max length is ' + MAX_NAME_LENGTH);170 }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 .createRFTCollection(collectionName, description, tokenPrefix)178 .call()).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 .createRFTCollection(collectionName, description, tokenPrefix)187 .call()).to.be.rejectedWith('token_prefix is too long. Max length is ' + MAX_TOKEN_PREFIX_LENGTH);188 }189 });190 191 itEth('(!negative test!) Create collection (no funds)', async ({helper}) => {192 const owner = helper.eth.createAccount();193 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);194 await expect(collectionHelper.methods195 .createRFTCollection('Peasantry', 'absolutely anything', 'TWIW')196 .call()).to.be.rejectedWith('NotSufficientFounds');197 });198199 itEth('(!negative test!) Check owner', async ({helper}) => {200 const owner = await helper.eth.createAccountWithBalance(donor);201 const peasant = helper.eth.createAccount();202 const {collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Transgressed', 'absolutely anything', 'YVNE');203 const peasantCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', peasant);204 const EXPECTED_ERROR = 'NoPermission';205 {206 const sponsor = await helper.eth.createAccountWithBalance(donor);207 await expect(peasantCollection.methods208 .setCollectionSponsor(sponsor)209 .call()).to.be.rejectedWith(EXPECTED_ERROR);210 211 const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);212 await expect(sponsorCollection.methods213 .confirmCollectionSponsorship()214 .call()).to.be.rejectedWith('caller is not set as sponsor');215 }216 {217 await expect(peasantCollection.methods218 .setCollectionLimit('account_token_ownership_limit', '1000')219 .call()).to.be.rejectedWith(EXPECTED_ERROR);220 }221 });222223 itEth('(!negative test!) Set limits', async ({helper}) => {224 const owner = await helper.eth.createAccountWithBalance(donor);225 const {collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Limits', 'absolutely anything', 'ISNI');226 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);227 await expect(collectionEvm.methods228 .setCollectionLimit('badLimit', 'true')229 .call()).to.be.rejectedWith('unknown boolean limit "badLimit"');230 });231});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 {Pallets, requirePalletsOrSkip} from '../util/playgrounds';20import {expect, itEth, usingEthPlaygrounds} from './util/playgrounds';21import {UNIQUE} from '../util/helpers';2223describe('Create RFT collection from EVM', () => {24 let donor: IKeyringPair;2526 before(async function() {27 await usingEthPlaygrounds(async (helper, privateKey) => {28 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);29 donor = privateKey('//Alice');30 });31 });3233 itEth('Create collection', async ({helper}) => {34 const owner = await helper.eth.createAccountWithBalance(donor);35 36 const name = 'CollectionEVM';37 const description = 'Some description';38 const prefix = 'token prefix';39 40 // todo:playgrounds this might fail when in async environment.41 const collectionCountBefore = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;42 const {collectionId} = await helper.eth.createRefungibleCollection(owner, name, description, prefix);43 const collectionCountAfter = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;44 45 const data = (await helper.rft.getData(collectionId))!;4647 expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);48 expect(collectionId).to.be.eq(collectionCountAfter);49 expect(data.name).to.be.eq(name);50 expect(data.description).to.be.eq(description);51 expect(data.raw.tokenPrefix).to.be.eq(prefix);52 expect(data.raw.mode).to.be.eq('ReFungible');53 });5455 // todo:playgrounds this test will fail when in async environment.56 itEth('Check collection address exist', async ({helper}) => {57 const owner = await helper.eth.createAccountWithBalance(donor);5859 const expectedCollectionId = +(await helper.callRpc('api.rpc.unique.collectionStats')).created + 1;60 const expectedCollectionAddress = helper.ethAddress.fromCollectionId(expectedCollectionId);61 const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);6263 expect(await collectionHelpers.methods64 .isCollectionExist(expectedCollectionAddress)65 .call()).to.be.false;6667 await collectionHelpers.methods68 .createRFTCollection('A', 'A', 'A')69 .send({value: Number(2n * UNIQUE)});70 71 expect(await collectionHelpers.methods72 .isCollectionExist(expectedCollectionAddress)73 .call()).to.be.true;74 });75 76 itEth('Set sponsorship', async ({helper}) => {77 const owner = await helper.eth.createAccountWithBalance(donor);78 const sponsor = await helper.eth.createAccountWithBalance(donor);79 const ss58Format = helper.chain.getChainProperties().ss58Format;80 const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Sponsor', 'absolutely anything', 'ENVY');8182 const collection = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);83 await collection.methods.setCollectionSponsor(sponsor).send();8485 let data = (await helper.rft.getData(collectionId))!;86 expect(data.raw.sponsorship.Unconfirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));8788 await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');8990 const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);91 await sponsorCollection.methods.confirmCollectionSponsorship().send();9293 data = (await helper.rft.getData(collectionId))!;94 expect(data.raw.sponsorship.Confirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));95 });9697 itEth('Set limits', async ({helper}) => {98 const owner = await helper.eth.createAccountWithBalance(donor);99 const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Limits', 'absolutely anything', 'INSI');100 const limits = {101 accountTokenOwnershipLimit: 1000,102 sponsoredDataSize: 1024,103 sponsoredDataRateLimit: 30,104 tokenLimit: 1000000,105 sponsorTransferTimeout: 6,106 sponsorApproveTimeout: 6,107 ownerCanTransfer: false,108 ownerCanDestroy: false,109 transfersEnabled: false,110 };111112 const collection = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);113 await collection.methods['setCollectionLimit(string,uint32)']('accountTokenOwnershipLimit', limits.accountTokenOwnershipLimit).send();114 await collection.methods['setCollectionLimit(string,uint32)']('sponsoredDataSize', limits.sponsoredDataSize).send();115 await collection.methods['setCollectionLimit(string,uint32)']('sponsoredDataRateLimit', limits.sponsoredDataRateLimit).send();116 await collection.methods['setCollectionLimit(string,uint32)']('tokenLimit', limits.tokenLimit).send();117 await collection.methods['setCollectionLimit(string,uint32)']('sponsorTransferTimeout', limits.sponsorTransferTimeout).send();118 await collection.methods['setCollectionLimit(string,uint32)']('sponsorApproveTimeout', limits.sponsorApproveTimeout).send();119 await collection.methods['setCollectionLimit(string,bool)']('ownerCanTransfer', limits.ownerCanTransfer).send();120 await collection.methods['setCollectionLimit(string,bool)']('ownerCanDestroy', limits.ownerCanDestroy).send();121 await collection.methods['setCollectionLimit(string,bool)']('transfersEnabled', limits.transfersEnabled).send();122 123 const data = (await helper.rft.getData(collectionId))!;124 expect(data.raw.limits.accountTokenOwnershipLimit).to.be.eq(limits.accountTokenOwnershipLimit);125 expect(data.raw.limits.sponsoredDataSize).to.be.eq(limits.sponsoredDataSize);126 expect(data.raw.limits.sponsoredDataRateLimit.blocks).to.be.eq(limits.sponsoredDataRateLimit);127 expect(data.raw.limits.tokenLimit).to.be.eq(limits.tokenLimit);128 expect(data.raw.limits.sponsorTransferTimeout).to.be.eq(limits.sponsorTransferTimeout);129 expect(data.raw.limits.sponsorApproveTimeout).to.be.eq(limits.sponsorApproveTimeout);130 expect(data.raw.limits.ownerCanTransfer).to.be.eq(limits.ownerCanTransfer);131 expect(data.raw.limits.ownerCanDestroy).to.be.eq(limits.ownerCanDestroy);132 expect(data.raw.limits.transfersEnabled).to.be.eq(limits.transfersEnabled);133 });134135 itEth('Collection address exist', async ({helper}) => {136 const owner = await helper.eth.createAccountWithBalance(donor);137 const collectionAddressForNonexistentCollection = '0x17C4E6453CC49AAAAEACA894E6D9683E00112233';138 expect(await helper.ethNativeContract.collectionHelpers(collectionAddressForNonexistentCollection)139 .methods.isCollectionExist(collectionAddressForNonexistentCollection).call())140 .to.be.false;141 142 const {collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Exister', 'absolutely anything', 'WIWT');143 expect(await helper.ethNativeContract.collectionHelpers(collectionAddress)144 .methods.isCollectionExist(collectionAddress).call())145 .to.be.true;146 });147});148149describe('(!negative tests!) Create RFT collection from EVM', () => {150 let donor: IKeyringPair;151152 before(async function() {153 await usingEthPlaygrounds(async (helper, privateKey) => {154 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);155 donor = privateKey('//Alice');156 });157 });158159 itEth('(!negative test!) Create collection (bad lengths)', async ({helper}) => {160 const owner = await helper.eth.createAccountWithBalance(donor);161 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);162 {163 const MAX_NAME_LENGTH = 64;164 const collectionName = 'A'.repeat(MAX_NAME_LENGTH + 1);165 const description = 'A';166 const tokenPrefix = 'A';167168 await expect(collectionHelper.methods169 .createRFTCollection(collectionName, description, tokenPrefix)170 .call({value: Number(2n * UNIQUE)})).to.be.rejectedWith('name is too long. Max length is ' + MAX_NAME_LENGTH);171 }172 {173 const MAX_DESCRIPTION_LENGTH = 256;174 const collectionName = 'A';175 const description = 'A'.repeat(MAX_DESCRIPTION_LENGTH + 1);176 const tokenPrefix = 'A';177 await expect(collectionHelper.methods178 .createRFTCollection(collectionName, description, tokenPrefix)179 .call({value: Number(2n * UNIQUE)})).to.be.rejectedWith('description is too long. Max length is ' + MAX_DESCRIPTION_LENGTH);180 }181 {182 const MAX_TOKEN_PREFIX_LENGTH = 16;183 const collectionName = 'A';184 const description = 'A';185 const tokenPrefix = 'A'.repeat(MAX_TOKEN_PREFIX_LENGTH + 1);186 await expect(collectionHelper.methods187 .createRFTCollection(collectionName, description, tokenPrefix)188 .call({value: Number(2n * UNIQUE)})).to.be.rejectedWith('token_prefix is too long. Max length is ' + MAX_TOKEN_PREFIX_LENGTH);189 }190 });191 192 itEth('(!negative test!) Create collection (no funds)', async ({helper}) => {193 const owner = await helper.eth.createAccountWithBalance(donor);194 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);195 await expect(collectionHelper.methods196 .createRFTCollection('Peasantry', 'absolutely anything', 'TWIW')197 .call({value: Number(1n * UNIQUE)})).to.be.rejectedWith('Sent amount not equals to collection creation price (2000000000000000000)');198 });199200 itEth('(!negative test!) Check owner', async ({helper}) => {201 const owner = await helper.eth.createAccountWithBalance(donor);202 const peasant = helper.eth.createAccount();203 const {collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Transgressed', 'absolutely anything', 'YVNE');204 const peasantCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', peasant);205 const EXPECTED_ERROR = 'NoPermission';206 {207 const sponsor = await helper.eth.createAccountWithBalance(donor);208 await expect(peasantCollection.methods209 .setCollectionSponsor(sponsor)210 .call()).to.be.rejectedWith(EXPECTED_ERROR);211 212 const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);213 await expect(sponsorCollection.methods214 .confirmCollectionSponsorship()215 .call()).to.be.rejectedWith('caller is not set as sponsor');216 }217 {218 await expect(peasantCollection.methods219 .setCollectionLimit('account_token_ownership_limit', '1000')220 .call()).to.be.rejectedWith(EXPECTED_ERROR);221 }222 });223224 itEth('(!negative test!) Set limits', async ({helper}) => {225 const owner = await helper.eth.createAccountWithBalance(donor);226 const {collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Limits', 'absolutely anything', 'ISNI');227 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);228 await expect(collectionEvm.methods229 .setCollectionLimit('badLimit', 'true')230 .call()).to.be.rejectedWith('unknown boolean limit "badLimit"');231 });232});tests/src/eth/fractionalizer/Fractionalizer.soldiffbeforeafterboth--- a/tests/src/eth/fractionalizer/Fractionalizer.sol
+++ b/tests/src/eth/fractionalizer/Fractionalizer.sol
@@ -81,10 +81,10 @@
string calldata _name,
string calldata _description,
string calldata _tokenPrefix
- ) external onlyOwner {
+ ) external payable onlyOwner {
require(rftCollection == address(0), "RFT collection is already set");
address collectionHelpers = 0x6C4E9fE1AE37a41E93CEE429e8E1881aBdcbb54F;
- rftCollection = CollectionHelpers(collectionHelpers).createRFTCollection(_name, _description, _tokenPrefix);
+ rftCollection = CollectionHelpers(collectionHelpers).createRFTCollection{value: msg.value}(_name, _description, _tokenPrefix);
emit RFTCollectionSet(rftCollection);
}
tests/src/eth/fractionalizer/fractionalizer.test.tsdiffbeforeafterboth--- a/tests/src/eth/fractionalizer/fractionalizer.test.ts
+++ b/tests/src/eth/fractionalizer/fractionalizer.test.ts
@@ -93,7 +93,7 @@
const fractionalizer = await deployFractionalizer(web3, owner);
const amount = 10n * UNIQUE;
await web3.eth.sendTransaction({from: owner, to: fractionalizer.options.address, value: `${amount}`, ...GAS_ARGS});
- const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send();
+ const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send({value: Number(2n * UNIQUE)});
const rftCollectionAddress = result.events.RFTCollectionSet.returnValues._collection;
return {fractionalizer, rftCollectionAddress};
}
@@ -141,9 +141,9 @@
const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
const fractionalizer = await deployFractionalizer(web3, owner);
const tx = api.tx.balances.transfer(evmToAddress(fractionalizer.options.address), 10n * UNIQUE);
- await submitTransactionAsync(alice, tx);
+ await executeTransaction(api, alice, tx);
- const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send({from: owner});
+ const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send({from: owner, value: Number(2n * UNIQUE)});
expect(result.events).to.be.like({
RFTCollectionSet: {},
});
@@ -295,7 +295,7 @@
const tx = api.tx.balances.transfer(evmToAddress(fractionalizer.options.address), 10n * UNIQUE);
await submitTransactionAsync(alice, tx);
- const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send({from: owner});
+ const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send({from: owner, value: Number(2n * UNIQUE)});
const collectionIdAddress = result.events.RFTCollectionSet.returnValues._collection;
await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).call())
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -17,6 +17,7 @@
import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util/playgrounds';
import {IKeyringPair} from '@polkadot/types/types';
import {Contract} from 'web3-eth-contract';
+import {UNIQUE} from '../util/helpers';
describe('NFT: Information getting', () => {
let donor: IKeyringPair;
@@ -83,7 +84,7 @@
const receiver = helper.eth.createAccount();
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
- let result = await collectionHelper.methods.createERC721MetadataCompatibleCollection('Mint collection', 'a', 'b', tokenPrefix).send();
+ let result = await collectionHelper.methods.createERC721MetadataCompatibleCollection('Mint collection', 'a', 'b', tokenPrefix).send({value: Number(2n * UNIQUE)});
const collectionAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
tests/src/eth/proxy/nonFungibleProxy.test.tsdiffbeforeafterboth--- a/tests/src/eth/proxy/nonFungibleProxy.test.ts
+++ b/tests/src/eth/proxy/nonFungibleProxy.test.ts
@@ -14,7 +14,7 @@
// 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 {createCollectionExpectSuccess, createItemExpectSuccess} from '../../util/helpers';
+import {createCollectionExpectSuccess, createItemExpectSuccess, UNIQUE} from '../../util/helpers';
import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, evmCollection, evmCollectionHelpers, GAS_ARGS, getCollectionAddressFromResult, itWeb3, normalizeEvents} from '../util/helpers';
import nonFungibleAbi from '../nonFungibleAbi.json';
import {expect} from 'chai';
@@ -93,7 +93,7 @@
const collectionHelper = evmCollectionHelpers(web3, owner);
const result = await collectionHelper.methods
.createNonfungibleCollection('A', 'A', 'A')
- .send();
+ .send({value: Number(2n * UNIQUE)});
const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
const receiver = createEthAccount(web3);
tests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungibleToken.test.ts
+++ b/tests/src/eth/reFungibleToken.test.ts
@@ -18,6 +18,7 @@
import {EthUniqueHelper, expect, itEth, usingEthPlaygrounds} from './util/playgrounds';
import {IKeyringPair} from '@polkadot/types/types';
import {Contract} from 'web3-eth-contract';
+import {UNIQUE} from '../util/helpers';
describe('Refungible token: Information getting', () => {
let donor: IKeyringPair;
@@ -80,7 +81,7 @@
const receiver = helper.eth.createAccount();
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
- let result = await collectionHelper.methods.createERC721MetadataCompatibleCollection('Mint collection', 'a', 'b', tokenPrefix).send();
+ let result = await collectionHelper.methods.createERC721MetadataCompatibleCollection('Mint collection', 'a', 'b', tokenPrefix).send({value: Number(2n * UNIQUE)});
const collectionAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
tests/src/eth/util/helpers.tsdiffbeforeafterboth--- a/tests/src/eth/util/helpers.ts
+++ b/tests/src/eth/util/helpers.ts
@@ -145,7 +145,7 @@
const collectionHelper = evmCollectionHelpers(web3, owner);
const result = await collectionHelper.methods
.createRFTCollection('A', 'B', 'C')
- .send();
+ .send({value: Number(2n * UNIQUE)});
return await getCollectionAddressFromResult(api, result);
}
@@ -154,7 +154,7 @@
const collectionHelper = evmCollectionHelpers(web3, owner);
const result = await collectionHelper.methods
.createNonfungibleCollection('A', 'B', 'C')
- .send();
+ .send({value: Number(2n * UNIQUE)});
return await getCollectionAddressFromResult(api, result);
}
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
@@ -170,9 +170,10 @@
}
async createNonfungibleCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{collectionId: number, collectionAddress: string}> {
+ const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();
const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);
-
- const result = await collectionHelper.methods.createNonfungibleCollection(name, description, tokenPrefix).send();
+
+ const result = await collectionHelper.methods.createNonfungibleCollection(name, description, tokenPrefix).send({value: Number(collectionCreationPrice)});
const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);
@@ -181,9 +182,10 @@
}
async createRefungibleCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{collectionId: number, collectionAddress: string}> {
+ const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();
const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);
-
- const result = await collectionHelper.methods.createRFTCollection(name, description, tokenPrefix).send();
+
+ const result = await collectionHelper.methods.createRFTCollection(name, description, tokenPrefix).send({value: Number(collectionCreationPrice)});
const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -2034,6 +2034,9 @@
class BalanceGroup extends HelperGroup {
+ getCollectionCreationPrice(): bigint {
+ return 2n * this.helper.balance.getOneTokenNominal();
+ }
/**
* Representation of the native token in the smallest unit - one OPAL (OPL), QUARTZ (QTZ), or UNIQUE (UNQ).
* @example getOneTokenNominal()