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.tsdiffbeforeafterboth--- a/tests/src/eth/createRFTCollection.test.ts
+++ b/tests/src/eth/createRFTCollection.test.ts
@@ -18,6 +18,7 @@
import {IKeyringPair} from '@polkadot/types/types';
import {Pallets, requirePalletsOrSkip} from '../util/playgrounds';
import {expect, itEth, usingEthPlaygrounds} from './util/playgrounds';
+import {UNIQUE} from '../util/helpers';
describe('Create RFT collection from EVM', () => {
let donor: IKeyringPair;
@@ -65,7 +66,7 @@
await collectionHelpers.methods
.createRFTCollection('A', 'A', 'A')
- .send();
+ .send({value: Number(2n * UNIQUE)});
expect(await collectionHelpers.methods
.isCollectionExist(expectedCollectionAddress)
@@ -166,7 +167,7 @@
await expect(collectionHelper.methods
.createRFTCollection(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);
}
{
const MAX_DESCRIPTION_LENGTH = 256;
@@ -175,7 +176,7 @@
const tokenPrefix = 'A';
await expect(collectionHelper.methods
.createRFTCollection(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;
@@ -184,16 +185,16 @@
const tokenPrefix = 'A'.repeat(MAX_TOKEN_PREFIX_LENGTH + 1);
await expect(collectionHelper.methods
.createRFTCollection(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
.createRFTCollection('Peasantry', 'absolutely anything', 'TWIW')
- .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/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.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.89// 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/>.161718import Web3 from 'web3';19import {ApiPromise} from '@polkadot/api';20import {evmToAddress} from '@polkadot/util-crypto';21import {readFile} from 'fs/promises';22import {executeTransaction, submitTransactionAsync} from '../../substrate/substrate-api';23import {getCreateCollectionResult, getCreateItemResult, UNIQUE, requirePallets, Pallets} from '../../util/helpers';24import {collectionIdToAddress, CompiledContract, createEthAccountWithBalance, createNonfungibleCollection, createRFTCollection, GAS_ARGS, itWeb3, tokenIdFromAddress, uniqueNFT, uniqueRefungible, uniqueRefungibleToken} from '../util/helpers';25import {Contract} from 'web3-eth-contract';26import * as solc from 'solc';2728import chai from 'chai';29import chaiLike from 'chai-like';30import {IKeyringPair} from '@polkadot/types/types';31chai.use(chaiLike);32const expect = chai.expect;33let fractionalizer: CompiledContract;3435async function compileFractionalizer() {36 if (!fractionalizer) {37 const input = {38 language: 'Solidity',39 sources: {40 ['Fractionalizer.sol']: {41 content: (await readFile(`${__dirname}/Fractionalizer.sol`)).toString(),42 },43 },44 settings: {45 outputSelection: {46 '*': {47 '*': ['*'],48 },49 },50 },51 };52 const json = JSON.parse(solc.compile(JSON.stringify(input), {import: await findImports()}));53 const out = json.contracts['Fractionalizer.sol']['Fractionalizer'];5455 fractionalizer = {56 abi: out.abi,57 object: '0x' + out.evm.bytecode.object,58 };59 }60 return fractionalizer;61}6263async function findImports() {64 const collectionHelpers = (await readFile(`${__dirname}/../api/CollectionHelpers.sol`)).toString();65 const contractHelpers = (await readFile(`${__dirname}/../api/ContractHelpers.sol`)).toString();66 const uniqueRefungibleToken = (await readFile(`${__dirname}/../api/UniqueRefungibleToken.sol`)).toString();67 const uniqueRefungible = (await readFile(`${__dirname}/../api/UniqueRefungible.sol`)).toString();68 const uniqueNFT = (await readFile(`${__dirname}/../api/UniqueNFT.sol`)).toString();6970 return function(path: string) {71 switch (path) {72 case 'api/CollectionHelpers.sol': return {contents: `${collectionHelpers}`};73 case 'api/ContractHelpers.sol': return {contents: `${contractHelpers}`};74 case 'api/UniqueRefungibleToken.sol': return {contents: `${uniqueRefungibleToken}`};75 case 'api/UniqueRefungible.sol': return {contents: `${uniqueRefungible}`};76 case 'api/UniqueNFT.sol': return {contents: `${uniqueNFT}`};77 default: return {error: 'File not found'};78 }79 };80}8182async function deployFractionalizer(web3: Web3, owner: string) {83 const compiled = await compileFractionalizer();84 const fractionalizerContract = new web3.eth.Contract(compiled.abi, undefined, {85 data: compiled.object,86 from: owner,87 ...GAS_ARGS,88 });89 return await fractionalizerContract.deploy({data: compiled.object}).send({from: owner});90}9192async function initFractionalizer(api: ApiPromise, web3: Web3, privateKeyWrapper: (account: string) => IKeyringPair, owner: string) {93 const fractionalizer = await deployFractionalizer(web3, owner);94 const amount = 10n * UNIQUE;95 await web3.eth.sendTransaction({from: owner, to: fractionalizer.options.address, value: `${amount}`, ...GAS_ARGS});96 const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send();97 const rftCollectionAddress = result.events.RFTCollectionSet.returnValues._collection;98 return {fractionalizer, rftCollectionAddress};99}100101async function createRFTToken(api: ApiPromise, web3: Web3, owner: string, fractionalizer: Contract, amount: bigint) {102 const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);103 const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);104 const nftTokenId = await nftContract.methods.nextTokenId().call();105 await nftContract.methods.mint(owner, nftTokenId).send();106107 await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send();108 await nftContract.methods.approve(fractionalizer.options.address, nftTokenId).send();109 const result = await fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, amount).send();110 const {_collection, _tokenId, _rftToken} = result.events.Fractionalized.returnValues;111 return {112 nftCollectionAddress: _collection,113 nftTokenId: _tokenId,114 rftTokenAddress: _rftToken,115 };116}117118describe('Fractionalizer contract usage', () => {119 before(async function() {120 await requirePallets(this, [Pallets.ReFungible]);121 });122123 itWeb3('Set RFT collection', async ({api, web3, privateKeyWrapper}) => {124 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);125 const fractionalizer = await deployFractionalizer(web3, owner);126 const {collectionIdAddress} = await createRFTCollection(api, web3, owner);127 const refungibleContract = uniqueRefungible(web3, collectionIdAddress, owner);128 await refungibleContract.methods.addCollectionAdmin(fractionalizer.options.address).send();129 const result = await fractionalizer.methods.setRFTCollection(collectionIdAddress).send();130 expect(result.events).to.be.like({131 RFTCollectionSet: {132 returnValues: {133 _collection: collectionIdAddress,134 },135 },136 });137 });138139 itWeb3('Mint RFT collection', async ({api, web3, privateKeyWrapper}) => {140 const alice = privateKeyWrapper('//Alice');141 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);142 const fractionalizer = await deployFractionalizer(web3, owner);143 const tx = api.tx.balances.transfer(evmToAddress(fractionalizer.options.address), 10n * UNIQUE);144 await submitTransactionAsync(alice, tx);145146 const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send({from: owner});147 expect(result.events).to.be.like({148 RFTCollectionSet: {},149 });150 expect(result.events.RFTCollectionSet.returnValues._collection).to.be.ok;151 });152153 itWeb3('Set Allowlist', async ({api, web3, privateKeyWrapper}) => {154 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);155 const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);156 const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);157 const result1 = await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send({from: owner});158 expect(result1.events).to.be.like({159 AllowListSet: {160 returnValues: {161 _collection: nftCollectionAddress,162 _status: true,163 },164 },165 });166 const result2 = await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, false).send({from: owner});167 expect(result2.events).to.be.like({168 AllowListSet: {169 returnValues: {170 _collection: nftCollectionAddress,171 _status: false,172 },173 },174 });175 });176177 itWeb3('NFT to RFT', async ({api, web3, privateKeyWrapper}) => {178 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);179180 const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);181 const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);182 const nftTokenId = await nftContract.methods.nextTokenId().call();183 await nftContract.methods.mint(owner, nftTokenId).send();184185 const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);186187 await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send();188 await nftContract.methods.approve(fractionalizer.options.address, nftTokenId).send();189 const result = await fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).send();190 expect(result.events).to.be.like({191 Fractionalized: {192 returnValues: {193 _collection: nftCollectionAddress,194 _tokenId: nftTokenId,195 _amount: '100',196 },197 },198 });199 const rftTokenAddress = result.events.Fractionalized.returnValues._rftToken;200 const rftTokenContract = uniqueRefungibleToken(web3, rftTokenAddress, owner);201 expect(await rftTokenContract.methods.balanceOf(owner).call()).to.equal('100');202 });203204 itWeb3('RFT to NFT', async ({api, web3, privateKeyWrapper}) => {205 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);206207 const {fractionalizer, rftCollectionAddress} = await initFractionalizer(api, web3, privateKeyWrapper, owner);208 const {rftTokenAddress, nftCollectionAddress, nftTokenId} = await createRFTToken(api, web3, owner, fractionalizer, 100n);209210 const {collectionId, tokenId} = tokenIdFromAddress(rftTokenAddress);211 const refungibleAddress = collectionIdToAddress(collectionId);212 expect(rftCollectionAddress).to.be.equal(refungibleAddress);213 const refungibleTokenContract = uniqueRefungibleToken(web3, rftTokenAddress, owner);214 await refungibleTokenContract.methods.approve(fractionalizer.options.address, 100).send();215 const result = await fractionalizer.methods.rft2nft(refungibleAddress, tokenId).send();216 expect(result.events).to.be.like({217 Defractionalized: {218 returnValues: {219 _rftToken: rftTokenAddress,220 _nftCollection: nftCollectionAddress,221 _nftTokenId: nftTokenId,222 },223 },224 });225 });226227 itWeb3('Test fractionalizer NFT <-> RFT mapping ', async ({api, web3, privateKeyWrapper}) => {228 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);229230 const {fractionalizer, rftCollectionAddress} = await initFractionalizer(api, web3, privateKeyWrapper, owner);231 const {rftTokenAddress, nftCollectionAddress, nftTokenId} = await createRFTToken(api, web3, owner, fractionalizer, 100n);232233 const {collectionId, tokenId} = tokenIdFromAddress(rftTokenAddress);234 const refungibleAddress = collectionIdToAddress(collectionId);235 expect(rftCollectionAddress).to.be.equal(refungibleAddress);236 const refungibleTokenContract = uniqueRefungibleToken(web3, rftTokenAddress, owner);237 await refungibleTokenContract.methods.approve(fractionalizer.options.address, 100).send();238239 const rft2nft = await fractionalizer.methods.rft2nftMapping(rftTokenAddress).call();240 expect(rft2nft).to.be.like({241 _collection: nftCollectionAddress,242 _tokenId: nftTokenId,243 });244245 const nft2rft = await fractionalizer.methods.nft2rftMapping(nftCollectionAddress, nftTokenId).call();246 expect(nft2rft).to.be.eq(tokenId.toString());247 });248});249250251252describe('Negative Integration Tests for fractionalizer', () => {253 before(async function() {254 await requirePallets(this, [Pallets.ReFungible]);255 });256257 itWeb3('call setRFTCollection twice', async ({api, web3, privateKeyWrapper}) => {258 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);259 const {collectionIdAddress} = await createRFTCollection(api, web3, owner);260 const refungibleContract = uniqueRefungible(web3, collectionIdAddress, owner);261262 const fractionalizer = await deployFractionalizer(web3, owner);263 await refungibleContract.methods.addCollectionAdmin(fractionalizer.options.address).send();264 await fractionalizer.methods.setRFTCollection(collectionIdAddress).send();265266 await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).call())267 .to.be.rejectedWith(/RFT collection is already set$/g);268 });269270 itWeb3('call setRFTCollection with NFT collection', async ({api, web3, privateKeyWrapper}) => {271 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);272 const {collectionIdAddress} = await createNonfungibleCollection(api, web3, owner);273 const nftContract = uniqueNFT(web3, collectionIdAddress, owner);274275 const fractionalizer = await deployFractionalizer(web3, owner);276 await nftContract.methods.addCollectionAdmin(fractionalizer.options.address).send();277278 await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).call())279 .to.be.rejectedWith(/Wrong collection type. Collection is not refungible.$/g);280 });281282 itWeb3('call setRFTCollection while not collection admin', async ({api, web3, privateKeyWrapper}) => {283 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);284 const fractionalizer = await deployFractionalizer(web3, owner);285 const {collectionIdAddress} = await createRFTCollection(api, web3, owner);286287 await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).call())288 .to.be.rejectedWith(/Fractionalizer contract should be an admin of the collection$/g);289 });290291 itWeb3('call setRFTCollection after createAndSetRFTCollection', async ({api, web3, privateKeyWrapper}) => {292 const alice = privateKeyWrapper('//Alice');293 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);294 const fractionalizer = await deployFractionalizer(web3, owner);295 const tx = api.tx.balances.transfer(evmToAddress(fractionalizer.options.address), 10n * UNIQUE);296 await submitTransactionAsync(alice, tx);297298 const result = await fractionalizer.methods.createAndSetRFTCollection('A', 'B', 'C').send({from: owner});299 const collectionIdAddress = result.events.RFTCollectionSet.returnValues._collection;300301 await expect(fractionalizer.methods.setRFTCollection(collectionIdAddress).call())302 .to.be.rejectedWith(/RFT collection is already set$/g);303 });304305 itWeb3('call nft2rft without setting RFT collection for contract', async ({api, web3, privateKeyWrapper}) => {306 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);307308 const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);309 const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);310 const nftTokenId = await nftContract.methods.nextTokenId().call();311 await nftContract.methods.mint(owner, nftTokenId).send();312313 const fractionalizer = await deployFractionalizer(web3, owner);314315 await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).call())316 .to.be.rejectedWith(/RFT collection is not set$/g);317 });318319 itWeb3('call nft2rft while not owner of NFT token', async ({api, web3, privateKeyWrapper}) => {320 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);321 const nftOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);322323 const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);324 const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);325 const nftTokenId = await nftContract.methods.nextTokenId().call();326 await nftContract.methods.mint(owner, nftTokenId).send();327 await nftContract.methods.transfer(nftOwner, 1).send();328329330 const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);331 await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send();332333 await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).call())334 .to.be.rejectedWith(/Only token owner could fractionalize it$/g);335 });336337 itWeb3('call nft2rft while not in list of allowed accounts', async ({api, web3, privateKeyWrapper}) => {338 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);339340 const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);341 const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);342 const nftTokenId = await nftContract.methods.nextTokenId().call();343 await nftContract.methods.mint(owner, nftTokenId).send();344345 const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);346347 await nftContract.methods.approve(fractionalizer.options.address, nftTokenId).send();348 await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).call())349 .to.be.rejectedWith(/Fractionalization of this collection is not allowed by admin$/g);350 });351352 itWeb3('call nft2rft while fractionalizer doesnt have approval for nft token', async ({api, web3, privateKeyWrapper}) => {353 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);354355 const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);356 const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);357 const nftTokenId = await nftContract.methods.nextTokenId().call();358 await nftContract.methods.mint(owner, nftTokenId).send();359360 const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);361362 await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send();363 await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).call())364 .to.be.rejectedWith(/ApprovedValueTooLow$/g);365 });366367 itWeb3('call rft2nft without setting RFT collection for contract', async ({api, web3, privateKeyWrapper}) => {368 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);369370 const fractionalizer = await deployFractionalizer(web3, owner);371 const {collectionIdAddress: rftCollectionAddress} = await createRFTCollection(api, web3, owner);372 const refungibleContract = uniqueRefungible(web3, rftCollectionAddress, owner);373 const rftTokenId = await refungibleContract.methods.nextTokenId().call();374 await refungibleContract.methods.mint(owner, rftTokenId).send();375 376 await expect(fractionalizer.methods.rft2nft(rftCollectionAddress, rftTokenId).call())377 .to.be.rejectedWith(/RFT collection is not set$/g);378 });379380 itWeb3('call rft2nft for RFT token that is not from configured RFT collection', async ({api, web3, privateKeyWrapper}) => {381 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);382383 const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);384 const {collectionIdAddress: rftCollectionAddress} = await createRFTCollection(api, web3, owner);385 const refungibleContract = uniqueRefungible(web3, rftCollectionAddress, owner);386 const rftTokenId = await refungibleContract.methods.nextTokenId().call();387 await refungibleContract.methods.mint(owner, rftTokenId).send();388 389 await expect(fractionalizer.methods.rft2nft(rftCollectionAddress, rftTokenId).call())390 .to.be.rejectedWith(/Wrong RFT collection$/g);391 });392393 itWeb3('call rft2nft for RFT token that was not minted by fractionalizer contract', async ({api, web3, privateKeyWrapper}) => {394 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);395 const {collectionIdAddress: rftCollectionAddress} = await createRFTCollection(api, web3, owner);396397 const fractionalizer = await deployFractionalizer(web3, owner);398 const refungibleContract = uniqueRefungible(web3, rftCollectionAddress, owner);399400 await refungibleContract.methods.addCollectionAdmin(fractionalizer.options.address).send();401 await fractionalizer.methods.setRFTCollection(rftCollectionAddress).send();402403 const rftTokenId = await refungibleContract.methods.nextTokenId().call();404 await refungibleContract.methods.mint(owner, rftTokenId).send();405 406 await expect(fractionalizer.methods.rft2nft(rftCollectionAddress, rftTokenId).call())407 .to.be.rejectedWith(/No corresponding NFT token found$/g);408 });409410 itWeb3('call rft2nft without owning all RFT pieces', async ({api, web3, privateKeyWrapper}) => {411 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);412 const receiver = await createEthAccountWithBalance(api, web3, privateKeyWrapper);413414 const {fractionalizer, rftCollectionAddress} = await initFractionalizer(api, web3, privateKeyWrapper, owner);415 const {rftTokenAddress} = await createRFTToken(api, web3, owner, fractionalizer, 100n);416 417 const {tokenId} = tokenIdFromAddress(rftTokenAddress);418 const refungibleTokenContract = uniqueRefungibleToken(web3, rftTokenAddress, owner);419 await refungibleTokenContract.methods.transfer(receiver, 50).send();420 await refungibleTokenContract.methods.approve(fractionalizer.options.address, 50).send();421 await expect(fractionalizer.methods.rft2nft(rftCollectionAddress, tokenId).call())422 .to.be.rejectedWith(/Not all pieces are owned by the caller$/g);423 });424425 itWeb3('send QTZ/UNQ to contract from non owner', async ({api, web3, privateKeyWrapper}) => {426 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);427 const payer = await createEthAccountWithBalance(api, web3, privateKeyWrapper);428429 const fractionalizer = await deployFractionalizer(web3, owner);430 const amount = 10n * UNIQUE;431 await expect(web3.eth.sendTransaction({from: payer, to: fractionalizer.options.address, value: `${amount}`, ...GAS_ARGS})).to.be.rejected;432 });433434 itWeb3('fractionalize NFT with NFT transfers disallowed', async ({api, web3, privateKeyWrapper}) => {435 const alice = privateKeyWrapper('//Alice');436 let collectionId;437 {438 const tx = api.tx.unique.createCollectionEx({name: 'A', description: 'B', tokenPrefix: 'C', mode: 'NFT'});439 const events = await submitTransactionAsync(alice, tx);440 const result = getCreateCollectionResult(events);441 collectionId = result.collectionId;442 }443 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);444 let nftTokenId;445 {446 const createData = {nft: {}};447 const tx = api.tx.unique.createItem(collectionId, {Ethereum: owner}, createData as any);448 const events = await executeTransaction(api, alice, tx);449 const result = getCreateItemResult(events);450 nftTokenId = result.itemId;451 }452 {453 const tx = api.tx.unique.setTransfersEnabledFlag(collectionId, false);454 await executeTransaction(api, alice, tx);455 }456 const nftCollectionAddress = collectionIdToAddress(collectionId);457 const {fractionalizer} = await initFractionalizer(api, web3, privateKeyWrapper, owner);458 await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send();459460 const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);461 await nftContract.methods.approve(fractionalizer.options.address, nftTokenId).send();462 await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100).call())463 .to.be.rejectedWith(/TransferNotAllowed$/g);464 });465 466 itWeb3('fractionalize NFT with RFT transfers disallowed', async ({api, web3, privateKeyWrapper}) => {467 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);468 const alice = privateKeyWrapper('//Alice');469470 let collectionId;471 {472 const tx = api.tx.unique.createCollectionEx({name: 'A', description: 'B', tokenPrefix: 'C', mode: 'ReFungible'});473 const events = await submitTransactionAsync(alice, tx);474 const result = getCreateCollectionResult(events);475 collectionId = result.collectionId;476 }477 const rftCollectionAddress = collectionIdToAddress(collectionId);478 const fractionalizer = await deployFractionalizer(web3, owner);479 {480 const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, {Ethereum: fractionalizer.options.address});481 await submitTransactionAsync(alice, changeAdminTx);482 }483 await fractionalizer.methods.setRFTCollection(rftCollectionAddress).send();484 {485 const tx = api.tx.unique.setTransfersEnabledFlag(collectionId, false);486 await executeTransaction(api, alice, tx);487 }488489 const {collectionIdAddress: nftCollectionAddress} = await createNonfungibleCollection(api, web3, owner);490 const nftContract = uniqueNFT(web3, nftCollectionAddress, owner);491 const nftTokenId = await nftContract.methods.nextTokenId().call();492 await nftContract.methods.mint(owner, nftTokenId).send();493494 await fractionalizer.methods.setNftCollectionIsAllowed(nftCollectionAddress, true).send();495 await nftContract.methods.approve(fractionalizer.options.address, nftTokenId).send();496497 await expect(fractionalizer.methods.nft2rft(nftCollectionAddress, nftTokenId, 100n).call())498 .to.be.rejectedWith(/TransferNotAllowed$/g);499 });500});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()