difftreelog
Merge branch 'develop' into feature/core-202
in: master
15 files changed
pallets/nonfungible/src/lib.rsdiffbeforeafterboth328 .checked_add(data.len() as u32)328 .checked_add(data.len() as u32)329 .ok_or(ArithmeticError::Overflow)?;329 .ok_or(ArithmeticError::Overflow)?;330 ensure!(330 ensure!(331 tokens_minted < collection.limits.token_limit(),331 tokens_minted <= collection.limits.token_limit(),332 <CommonError<T>>::CollectionTokenLimitExceeded332 <CommonError<T>>::CollectionTokenLimitExceeded333 );333 );334 collection.consume_sstore()?;334 collection.consume_sstore()?;tests/src/eth/marketplace/MarketPlace.abidiffbeforeafterbothno changes
tests/src/eth/marketplace/MarketPlace.bindiffbeforeafterbothno changes
tests/src/eth/marketplace/MarketPlace.soldiffbeforeafterbothno changes
tests/src/eth/marketplace/MarketPlaceKSM.abidiffbeforeafterbothno changes
tests/src/eth/marketplace/MarketPlaceKSM.bindiffbeforeafterbothno changes
tests/src/eth/marketplace/MarketPlaceKSM.soldiffbeforeafterbothno changes
tests/src/eth/marketplace/MarketPlaceUNQ.abidiffbeforeafterbothno changes
tests/src/eth/marketplace/MarketPlaceUNQ.bindiffbeforeafterbothno changes
tests/src/eth/marketplace/MarketPlaceUNQ.soldiffbeforeafterbothno changes
tests/src/eth/marketplace/marketplace.test.tsdiffbeforeafterboth1import {readFile} from 'fs/promises';1import {readFile} from 'fs/promises';2import {getBalanceSingle, transferBalanceExpectSuccess} from '../../substrate/get-balance';2import {getBalanceSingle, transferBalanceExpectSuccess} from '../../substrate/get-balance';3import privateKey from '../../substrate/privateKey';3import privateKey from '../../substrate/privateKey';4import {createCollectionExpectSuccess, createFungibleItemExpectSuccess, createItemExpectSuccess, getTokenOwner, transferExpectSuccess, transferFromExpectSuccess} from '../../util/helpers';4import {addToWhiteListExpectSuccess, confirmSponsorshipExpectSuccess, createCollectionExpectSuccess, createFungibleItemExpectSuccess, createItemExpectSuccess, getTokenOwner, setCollectionSponsorExpectSuccess, transferExpectSuccess, transferFromExpectSuccess} from '../../util/helpers';5import {collectionIdToAddress, createEthAccountWithBalance, executeEthTxOnSub, GAS_ARGS, itWeb3, subToEth, subToEthLowercase} from '../util/helpers';5import {collectionIdToAddress, contractHelpers, createEthAccountWithBalance, executeEthTxOnSub, GAS_ARGS, itWeb3, subToEth, subToEthLowercase} from '../util/helpers';6import {evmToAddress} from '@polkadot/util-crypto';6import {evmToAddress} from '@polkadot/util-crypto';7import nonFungibleAbi from '../nonFungibleAbi.json';7import nonFungibleAbi from '../nonFungibleAbi.json';8import fungibleAbi from '../fungibleAbi.json';8import fungibleAbi from '../fungibleAbi.json';9import {expect} from 'chai';9import {expect} from 'chai';101011const PRICE = 2000n;11const PRICE = 2000n;121213describe('Matcher contract usage', () => {13describe.only('Matcher contract usage', () => {14 itWeb3('With UNQ', async ({api, web3}) => {14 itWeb3('With UNQ', async ({api, web3}) => {15 const matcherOwner = await createEthAccountWithBalance(api, web3);15 const matcherOwner = await createEthAccountWithBalance(api, web3);16 const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlaceUNQ.abi`)).toString()), undefined, {16 const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlace.abi`)).toString()), undefined, {17 from: matcherOwner,17 from: matcherOwner,18 ...GAS_ARGS,18 ...GAS_ARGS,19 });19 });20 const matcher = await matcherContract.deploy({data: (await readFile(`${__dirname}/MarketPlaceUNQ.bin`)).toString()}).send({from: matcherOwner});20 const matcher = await matcherContract.deploy({data: (await readFile(`${__dirname}/MarketPlace.bin`)).toString(), arguments:[matcherOwner]}).send({from: matcherOwner});21 const helpers = contractHelpers(web3, matcherOwner);22 await helpers.methods.toggleSponsoring(matcher.options.address, true).send({from: matcherOwner});23 await helpers.methods.setSponsoringRateLimit(matcher.options.address, 1).send({from: matcherOwner});212422 const alice = privateKey('//Alice');25 const alice = privateKey('//Alice');23 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});26 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});24 const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collectionId), {from: matcherOwner});27 const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collectionId), {from: matcherOwner});28 await setCollectionSponsorExpectSuccess(collectionId, alice.address);29 await confirmSponsorshipExpectSuccess(collectionId);3031 await helpers.methods.toggleAllowed(matcher.options.address, subToEth(alice.address), true).send({from: matcherOwner});32 await addToWhiteListExpectSuccess(alice, collectionId, evmToAddress(subToEth(alice.address)));253326 const seller = privateKey('//Bob');34 const seller = privateKey('//Bob');2728 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', seller.address);35 await helpers.methods.toggleAllowed(matcher.options.address, subToEth(seller.address), true).send({from: matcherOwner});2930 // To transfer item to matcher it first needs to be transfered to EVM account of bob31 await transferExpectSuccess(collectionId, tokenId, seller, {Ethereum: subToEth(seller.address)});36 await addToWhiteListExpectSuccess(alice, collectionId, evmToAddress(subToEth(seller.address)));32 // Fees will be paid from EVM account, so we should have some balance here3733 await transferBalanceExpectSuccess(api, seller, evmToAddress(subToEth(seller.address)), 10n ** 18n);38 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', seller.address);3940 // To transfer item to matcher it first needs to be transfered to EVM account of bob34 await transferBalanceExpectSuccess(api, alice, evmToAddress(subToEth(alice.address)), 10n ** 18n);41 await transferExpectSuccess(collectionId, tokenId, seller, {Ethereum: subToEth(seller.address)});354236 // Token is owned by seller initially43 // Token is owned by seller initially37 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: subToEthLowercase(seller.address)});44 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: subToEthLowercase(seller.address)});384539 // Ask46 // Ask40 {47 {41 await executeEthTxOnSub(api, seller, evmCollection, m => m.approve(matcher.options.address, tokenId));48 await executeEthTxOnSub(api, seller, evmCollection, m => m.approve(matcher.options.address, tokenId));42 await executeEthTxOnSub(api, seller, matcher, m => m.setAsk(PRICE, '0x0000000000000000000000000000000000000000', evmCollection.options.address, tokenId, 1));49 await executeEthTxOnSub(api, seller, matcher, m => m.addAsk(PRICE, '0x0000000000000000000000000000000000000001', evmCollection.options.address, tokenId));43 }50 }445145 // Token is transferred to matcher52 // Token is transferred to matcher64 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Substrate: alice.address});71 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Substrate: alice.address});65 });72 });667374 // selling for custom tokens excluded from release67 itWeb3('With custom ERC20', async ({api, web3}) => {75 itWeb3.skip('With custom ERC20', async ({api, web3}) => {68 const matcherOwner = await createEthAccountWithBalance(api, web3);76 const matcherOwner = await createEthAccountWithBalance(api, web3);69 const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlaceUNQ.abi`)).toString()), undefined, {77 const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlace.abi`)).toString()), undefined, {70 from: matcherOwner,78 from: matcherOwner,71 ...GAS_ARGS,79 ...GAS_ARGS,72 });80 });73 const matcher = await matcherContract.deploy({data: (await readFile(`${__dirname}/MarketPlaceUNQ.bin`)).toString()}).send({from: matcherOwner});81 const matcher = await matcherContract.deploy({data: (await readFile(`${__dirname}/MarketPlace.bin`)).toString(), arguments: [matcherOwner]}).send({from: matcherOwner});748275 const alice = privateKey('//Alice');83 const alice = privateKey('//Alice');76 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});84 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});131 itWeb3('With escrow', async ({api, web3}) => {139 itWeb3('With escrow', async ({api, web3}) => {132 const matcherOwner = await createEthAccountWithBalance(api, web3);140 const matcherOwner = await createEthAccountWithBalance(api, web3);133 const escrow = await createEthAccountWithBalance(api, web3);141 const escrow = await createEthAccountWithBalance(api, web3);134 const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlaceKSM.abi`)).toString()), undefined, {142 const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlace.abi`)).toString()), undefined, {135 from: matcherOwner,143 from: matcherOwner,136 ...GAS_ARGS,144 ...GAS_ARGS,137 });145 });138 const matcher = await matcherContract.deploy({data: (await readFile(`${__dirname}/MarketPlaceKSM.bin`)).toString(), arguments: [escrow]}).send({from: matcherOwner});146 const matcher = await matcherContract.deploy({data: (await readFile(`${__dirname}/MarketPlace.bin`)).toString(), arguments: [matcherOwner]}).send({from: matcherOwner});139147 await matcher.methods.setEscrow(escrow).send({from: matcherOwner});140 const ksmToken = 11;148 const helpers = contractHelpers(web3, matcherOwner);149 await helpers.methods.toggleSponsoring(matcher.options.address, true).send({from: matcherOwner});150 await helpers.methods.setSponsoringRateLimit(matcher.options.address, 1).send({from: matcherOwner});141151142 const alice = privateKey('//Alice');152 const alice = privateKey('//Alice');143 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});153 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});144 const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collectionId), {from: matcherOwner});154 const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collectionId), {from: matcherOwner});155 await setCollectionSponsorExpectSuccess(collectionId, alice.address);156 await confirmSponsorshipExpectSuccess(collectionId);157158 await helpers.methods.toggleAllowed(matcher.options.address, subToEth(alice.address), true).send({from: matcherOwner});159 await addToWhiteListExpectSuccess(alice, collectionId, evmToAddress(subToEth(alice.address)));145160146 const seller = privateKey('//Bob');161 const seller = privateKey('//Bob');147148 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', seller.address);162 await helpers.methods.toggleAllowed(matcher.options.address, subToEth(seller.address), true).send({from: matcherOwner});149150 // To transfer item to matcher it first needs to be transfered to EVM account of bob151 await transferExpectSuccess(collectionId, tokenId, seller, {Ethereum: subToEth(seller.address)});163 await addToWhiteListExpectSuccess(alice, collectionId, evmToAddress(subToEth(seller.address)));152 // Fees will be paid from EVM account, so we should have some balance here164153 await transferBalanceExpectSuccess(api, seller, evmToAddress(subToEth(seller.address)), 10n ** 18n);165 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', seller.address);166167 // To transfer item to matcher it first needs to be transfered to EVM account of bob154 await transferBalanceExpectSuccess(api, alice, evmToAddress(subToEth(alice.address)), 10n ** 18n);168 await transferExpectSuccess(collectionId, tokenId, seller, {Ethereum: subToEth(seller.address)});155169156 // Token is owned by seller initially170 // Token is owned by seller initially157 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: subToEthLowercase(seller.address)});171 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: subToEthLowercase(seller.address)});158172159 // Ask173 // Ask160 {174 {161 await executeEthTxOnSub(api, seller, evmCollection, m => m.approve(matcher.options.address, tokenId));175 await executeEthTxOnSub(api, seller, evmCollection, m => m.approve(matcher.options.address, tokenId));162 await executeEthTxOnSub(api, seller, matcher, m => m.setAsk(PRICE, ksmToken, evmCollection.options.address, tokenId, 1));176 await executeEthTxOnSub(api, seller, matcher, m => m.addAsk(PRICE, '0x0000000000000000000000000000000000000001', evmCollection.options.address, tokenId));163 }177 }164178165 // Token is transferred to matcher179 // Token is transferred to matcher166 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: matcher.options.address.toLowerCase()});180 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: matcher.options.address.toLowerCase()});167181168 // Give buyer KSM182 // Give buyer KSM169 await matcher.methods.deposit(PRICE, ksmToken, subToEth(alice.address)).send({from: escrow});183 await matcher.methods.depositKSM(PRICE, subToEth(alice.address)).send({from: escrow});170184171 // Buy185 // Buy172 {186 {173 expect(await matcher.methods.escrowBalance(ksmToken, subToEth(seller.address)).call()).to.be.equal('0');187 expect(await matcher.methods.balanceKSM(subToEth(seller.address)).call()).to.be.equal('0');174 expect(await matcher.methods.escrowBalance(ksmToken, subToEth(alice.address)).call()).to.be.equal(PRICE.toString());188 expect(await matcher.methods.balanceKSM(subToEth(alice.address)).call()).to.be.equal(PRICE.toString());175189176 await executeEthTxOnSub(api, alice, matcher, m => m.buy(evmCollection.options.address, tokenId));190 await executeEthTxOnSub(api, alice, matcher, m => m.buyKSM(evmCollection.options.address, tokenId, subToEth(alice.address), subToEth(alice.address)));177191178 // Price is removed from buyer balance, and added to seller192 // Price is removed from buyer balance, and added to seller179 expect(await matcher.methods.escrowBalance(ksmToken, subToEth(alice.address)).call()).to.be.equal('0');193 expect(await matcher.methods.balanceKSM(subToEth(alice.address)).call()).to.be.equal('0');180 expect(await matcher.methods.escrowBalance(ksmToken, subToEth(seller.address)).call()).to.be.equal(PRICE.toString());194 expect(await matcher.methods.balanceKSM(subToEth(seller.address)).call()).to.be.equal(PRICE.toString());181 }195 }182196183 // Token is transferred to evm account of alice197 // Token is transferred to evm account of alicetests/src/limits.test.tsdiffbeforeafterboth78 });78 });79});79});808081describe('Sponsor timeout (NFT)', () => {81describe.skip('Sponsor timeout (NFT) (only for special chain limits test)', () => {82 let alice: IKeyringPair;82 let alice: IKeyringPair;83 let bob: IKeyringPair;83 let bob: IKeyringPair;84 let charlie: IKeyringPair;84 let charlie: IKeyringPair;91 });91 });92 });92 });939394 it('Collection limits have greater timeout value than chain limits, collection limits are enforced', async () => {94 it.skip('Collection limits have greater timeout value than chain limits, collection limits are enforced', async () => {95 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});95 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});96 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 7});96 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorTransferTimeout: 7});97 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');97 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');141 });141 });142});142});143143144describe('Sponsor timeout (Fungible)', () => {144describe.skip('Sponsor timeout (Fungible) (only for special chain limits test)', () => {145 let alice: IKeyringPair;145 let alice: IKeyringPair;146 let bob: IKeyringPair;146 let bob: IKeyringPair;147 let charlie: IKeyringPair;147 let charlie: IKeyringPair;208 });208 });209});209});210210211describe('Sponsor timeout (ReFungible)', () => {211describe.skip('Sponsor timeout (ReFungible) (only for special chain limits test)', () => {212 let alice: IKeyringPair;212 let alice: IKeyringPair;213 let bob: IKeyringPair;213 let bob: IKeyringPair;214 let charlie: IKeyringPair;214 let charlie: IKeyringPair;tests/src/overflow.test.tsdiffbeforeafterboth13chai.use(chaiAsPromised);13chai.use(chaiAsPromised);14const expect = chai.expect;14const expect = chai.expect;151516describe('Integration Test fungible overflows', () => {16describe.skip('Integration Test fungible overflows', () => {17 let alice: IKeyringPair;17 let alice: IKeyringPair;18 let bob: IKeyringPair;18 let bob: IKeyringPair;19 let charlie: IKeyringPair;19 let charlie: IKeyringPair;tests/src/setOffchainSchema.test.tsdiffbeforeafterboth40 await setOffchainSchemaExpectSuccess(alice, collectionId, DATA);40 await setOffchainSchemaExpectSuccess(alice, collectionId, DATA);41 const collection = await queryCollectionExpectSuccess(api, collectionId);41 const collection = await queryCollectionExpectSuccess(api, collectionId);424243 expect(collection.offchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));43 expect('0x' + Buffer.from(collection.offchainSchema).toString('hex')).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));44 });44 });45 });45 });464651 await setOffchainSchemaExpectSuccess(bob, collectionId, DATA);51 await setOffchainSchemaExpectSuccess(bob, collectionId, DATA);52 const collection = await queryCollectionExpectSuccess(api, collectionId);52 const collection = await queryCollectionExpectSuccess(api, collectionId);535354 expect(collection.offchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));54 expect('0x' + Buffer.from(collection.offchainSchema).toString('hex')).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));55 });55 });56 });56 });57});57});tests/src/util/helpers.tsdiffbeforeafterboth905 await usingApi(async (api: ApiPromise) => {905 await usingApi(async (api: ApiPromise) => {906 const transferTx = api.tx.nft.transfer(normalizeAccountId(recipient.address), collectionId, tokenId, value);906 const transferTx = api.tx.nft.transfer(normalizeAccountId(recipient.address), collectionId, tokenId, value);907 const events = await expect(submitTransactionExpectFailAsync(sender, transferTx)).to.be.rejected;907 const events = await expect(submitTransactionExpectFailAsync(sender, transferTx)).to.be.rejected;908 if (events && Array.isArray(events)) {909 const result = getCreateCollectionResult(events);908 const result = getGenericResult(events);909 // if (events && Array.isArray(events)) {910 // const result = getCreateCollectionResult(events);910 // tslint:disable-next-line:no-unused-expression911 // tslint:disable-next-line:no-unused-expression911 expect(result.success).to.be.false;912 expect(result.success).to.be.false;912 }913 //}913 });914 });914}915}915916