difftreelog
CORE-325 Make test to check supprot ERC721Metadata
in: master
2 files changed
tests/src/eth/metadata.test.tsdiffbeforeafterboth161617import {expect} from 'chai';17import {expect} from 'chai';18import {createCollectionExpectSuccess} from '../util/helpers';18import {createCollectionExpectSuccess} from '../util/helpers';19import {collectionIdToAddress, createEthAccountWithBalance, GAS_ARGS, itWeb3} from './util/helpers';19import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents} from './util/helpers';20import fungibleMetadataAbi from './fungibleMetadataAbi.json';20import fungibleMetadataAbi from './fungibleMetadataAbi.json';21import privateKey from '../substrate/privateKey';22import {submitTransactionAsync} from '../substrate/substrate-api';23import nonFungibleAbi from './nonFungibleAbi.json';212422describe('Common metadata', () => {25describe('Common metadata', () => {23 itWeb3('Returns collection name', async ({api, web3}) => {26 itWeb3('Returns collection name', async ({api, web3}) => {64 });67 });65});68});6970describe.only('Support ERC721Metadata', () => {71 itWeb3('Check unsupport ERC721Metadata ShemaVersion::Unique', async ({web3, api}) => {72 const collectionId = await createCollectionExpectSuccess({73 mode: {type: 'NFT'},74 shemaVersion: 'Unique',75 });76 const collection = await api.rpc.unique.collectionById(collectionId);77 expect(collection.isSome).to.be.true;78 expect(collection.unwrap().schemaVersion.toHuman()).to.be.eq('Unique');7980 const alice = privateKey('//Alice');8182 const caller = await createEthAccountWithBalance(api, web3);83 const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, {Ethereum: caller});84 await submitTransactionAsync(alice, changeAdminTx);8586 const address = collectionIdToAddress(collectionId);87 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});8889 await expect(contract.methods.name().call()).to.be.rejectedWith('Unsupported shema version! Support only ImageURL');90 await expect(contract.methods.symbol().call()).to.be.rejectedWith('Unsupported shema version! Support only ImageURL');9192 const receiver = createEthAccount(web3);93 const nextTokenId = await contract.methods.nextTokenId().call();94 expect(nextTokenId).to.be.equal('1');95 await expect(contract.methods.mintWithTokenURI(96 receiver,97 nextTokenId,98 'Test URI',99 ).send({from: caller})).to.be.rejected;100101 await expect(contract.methods.mintBulkWithTokenURI(102 receiver,103 [104 [nextTokenId, 'Test URI 0'],105 [+nextTokenId + 1, 'Test URI 1'],106 [+nextTokenId + 2, 'Test URI 2'],107 ],108 ).send({from: caller})).to.be.rejected;109 });110111 itWeb3('Check support ERC721Metadata for ShemaVersion::ImageURL', async ({web3, api}) => {112 const collectionId = await createCollectionExpectSuccess({113 mode: {type: 'NFT'},114 name: 'some_name',115 tokenPrefix: 'some_prefix',116 });117 const collection = await api.rpc.unique.collectionById(collectionId);118 expect(collection.isSome).to.be.true;119 expect(collection.unwrap().schemaVersion.toHuman()).to.be.eq('ImageURL');120121 const alice = privateKey('//Alice');122123 const caller = await createEthAccountWithBalance(api, web3);124 const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, {Ethereum: caller});125 await submitTransactionAsync(alice, changeAdminTx);126127 const address = collectionIdToAddress(collectionId);128 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});129 130 expect(await contract.methods.name().call()).to.be.eq('some_name');131 expect(await contract.methods.symbol().call()).to.be.eq('some_prefix');132133 const receiver = createEthAccount(web3);134 const nextTokenId = await contract.methods.nextTokenId().call();135 expect(nextTokenId).to.be.equal('1');136 const result = await contract.methods.mintWithTokenURI(137 receiver,138 nextTokenId,139 'Test URI',140 ).send({from: caller});141 const events = normalizeEvents(result.events);142143 expect(events).to.be.deep.equal([144 {145 address,146 event: 'Transfer',147 args: {148 from: '0x0000000000000000000000000000000000000000',149 to: receiver,150 tokenId: nextTokenId,151 },152 },153 ]);154155 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');156 });157});158159tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -268,6 +268,7 @@
name: string,
description: string,
tokenPrefix: string,
+ shemaVersion: string,
};
const defaultCreateCollectionParams: CreateCollectionParams = {
@@ -275,10 +276,11 @@
mode: {type: 'NFT'},
name: 'name',
tokenPrefix: 'prefix',
+ shemaVersion: 'ImageURL',
};
export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {
- const {name, description, mode, tokenPrefix} = {...defaultCreateCollectionParams, ...params};
+ const {name, description, mode, tokenPrefix, shemaVersion} = {...defaultCreateCollectionParams, ...params};
let collectionId = 0;
await usingApi(async (api) => {
@@ -297,7 +299,13 @@
modeprm = {refungible: null};
}
- const tx = api.tx.unique.createCollectionEx({name: strToUTF16(name), description: strToUTF16(description), tokenPrefix: strToUTF16(tokenPrefix), mode: modeprm as any});
+ const tx = api.tx.unique.createCollectionEx({
+ name: strToUTF16(name),
+ description: strToUTF16(description),
+ tokenPrefix: strToUTF16(tokenPrefix),
+ mode: modeprm as any,
+ schemaVersion: shemaVersion,
+ });
const events = await submitTransactionAsync(alicePrivateKey, tx);
const result = getCreateCollectionResult(events);