From 36c7382c275096b6ad9be11e25189d8ef36e2b66 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Wed, 01 Sep 2021 13:08:24 +0000 Subject: [PATCH] test: mintBulk/metadata api --- --- a/tests/src/eth/nonFungible.test.ts +++ b/tests/src/eth/nonFungible.test.ts @@ -4,9 +4,8 @@ // import privateKey from '../substrate/privateKey'; -import { approveExpectSuccess, burnItemExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess, UNIQUE } from '../util/helpers'; +import { approveExpectSuccess, burnItemExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, setVariableMetaDataExpectSuccess, transferExpectSuccess, transferFromExpectSuccess, UNIQUE } from '../util/helpers'; import { collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, transferBalanceToEth } from './util/helpers'; -import { evmToAddress } from '@polkadot/util-crypto'; import nonFungibleAbi from './nonFungibleAbi.json'; import { expect } from 'chai'; import waitNewBlocks from '../substrate/wait-new-blocks'; @@ -106,7 +105,70 @@ expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI'); } }); + itWeb3.only('Can perform mintBulk()', async ({ web3, api }) => { + const collection = await createCollectionExpectSuccess({ + mode: { type: 'NFT' }, + }); + const alice = privateKey('//Alice'); + + const caller = await createEthAccountWithBalance(api, web3); + const changeAdminTx = api.tx.nft.addCollectionAdmin(collection, { ethereum: caller }); + await submitTransactionAsync(alice, changeAdminTx); + const receiver = createEthAccount(web3); + const address = collectionIdToAddress(collection); + const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}); + + { + const nextTokenId = await contract.methods.nextTokenId().call(); + expect(nextTokenId).to.be.equal('1'); + const result = await contract.methods.mintBulkWithTokenURI( + receiver, + [ + [nextTokenId, 'Test URI 0'], + [+nextTokenId + 1, 'Test URI 1'], + [+nextTokenId + 2, 'Test URI 2'], + ], + ).send({ from: caller }); + const events = normalizeEvents(result.events); + + expect(events).to.be.deep.equal([ + { + address, + event: 'Transfer', + args: { + from: '0x0000000000000000000000000000000000000000', + to: receiver, + tokenId: nextTokenId, + }, + }, + { + address, + event: 'Transfer', + args: { + from: '0x0000000000000000000000000000000000000000', + to: receiver, + tokenId: String(+nextTokenId + 1), + }, + }, + { + address, + event: 'Transfer', + args: { + from: '0x0000000000000000000000000000000000000000', + to: receiver, + tokenId: String(+nextTokenId + 2), + }, + }, + ]); + + await waitNewBlocks(api, 1); + expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0'); + expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1'); + expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2'); + } + }); + itWeb3('Can perform burn()', async ({ web3, api }) => { const collection = await createCollectionExpectSuccess({ mode: {type: 'NFT'}, @@ -264,6 +326,41 @@ expect(+balance).to.equal(1); } }); + + itWeb3('Can perform getVariableMetadata', async ({ web3, api }) => { + const collection = await createCollectionExpectSuccess({ + mode: { type: 'NFT' }, + }); + const alice = privateKey('//Alice'); + + const owner = await createEthAccountWithBalance(api, web3); + + const item = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner }); + await setVariableMetaDataExpectSuccess(alice, collection, item, [1, 2, 3]); + + const address = collectionIdToAddress(collection); + const contract = new web3.eth.Contract(nonFungibleAbi as any, address, { from: owner, ...GAS_ARGS }); + + expect(await contract.methods.getVariableMetadata(item).call()).to.be.equal('0x010203'); + }); + + itWeb3('Can perform setVariableMetadata', async ({ web3, api }) => { + const collection = await createCollectionExpectSuccess({ + mode: { type: 'NFT' }, + }); + const alice = privateKey('//Alice'); + + const owner = await createEthAccountWithBalance(api, web3); + + const item = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner }); + + const address = collectionIdToAddress(collection); + const contract = new web3.eth.Contract(nonFungibleAbi as any, address, { from: owner, ...GAS_ARGS }); + + expect(await contract.methods.setVariableMetadata(item, '0x010203').send({ from: owner })); + await waitNewBlocks(api, 1); + expect(await contract.methods.getVariableMetadata(item).call()).to.be.equal('0x010203'); + }); }); describe('NFT: Fees', () => { --- a/tests/src/eth/nonFungibleAbi.json +++ b/tests/src/eth/nonFungibleAbi.json @@ -50,7 +50,7 @@ "type": "event" }, { - "anonymous": true, + "anonymous": false, "inputs": [], "name": "MintingFinished", "type": "event" @@ -165,6 +165,25 @@ { "inputs": [ { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + } + ], + "name": "getVariableMetadata", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" @@ -218,13 +237,73 @@ "type": "address" }, { + "internalType": "uint256[]", + "name": "tokenIds", + "type": "uint256[]" + } + ], + "name": "mintBulk", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "field_0", + "type": "uint256" + }, + { + "internalType": "string", + "name": "field_1", + "type": "string" + } + ], + "internalType": "struct Tuple0[]", + "name": "tokens", + "type": "tuple[]" + } + ], + "name": "mintBulkWithTokenURI", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { "internalType": "uint256", "name": "tokenId", "type": "uint256" }, { "internalType": "string", - "name": "tokenURI", + "name": "tokenUri", "type": "string" } ], @@ -369,6 +448,24 @@ { "inputs": [ { + "internalType": "uint256", + "name": "tokenId", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "setVariableMetadata", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint32", "name": "interfaceId", "type": "uint32" @@ -514,4 +611,4 @@ "stateMutability": "nonpayable", "type": "function" } -] \ No newline at end of file +] -- gitstuff