--- a/tests/src/eth/metadata.test.ts +++ b/tests/src/eth/metadata.test.ts @@ -16,8 +16,11 @@ import {expect} from 'chai'; import {createCollectionExpectSuccess} from '../util/helpers'; -import {collectionIdToAddress, createEthAccountWithBalance, GAS_ARGS, itWeb3} from './util/helpers'; +import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents} from './util/helpers'; import fungibleMetadataAbi from './fungibleMetadataAbi.json'; +import privateKey from '../substrate/privateKey'; +import {submitTransactionAsync} from '../substrate/substrate-api'; +import nonFungibleAbi from './nonFungibleAbi.json'; describe('Common metadata', () => { itWeb3('Returns collection name', async ({api, web3}) => { @@ -62,4 +65,94 @@ expect(+decimals).to.equal(6); }); -}); \ No newline at end of file +}); + +describe.only('Support ERC721Metadata', () => { + itWeb3('Check unsupport ERC721Metadata ShemaVersion::Unique', async ({web3, api}) => { + const collectionId = await createCollectionExpectSuccess({ + mode: {type: 'NFT'}, + shemaVersion: 'Unique', + }); + const collection = await api.rpc.unique.collectionById(collectionId); + expect(collection.isSome).to.be.true; + expect(collection.unwrap().schemaVersion.toHuman()).to.be.eq('Unique'); + + const alice = privateKey('//Alice'); + + const caller = await createEthAccountWithBalance(api, web3); + const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, {Ethereum: caller}); + await submitTransactionAsync(alice, changeAdminTx); + + const address = collectionIdToAddress(collectionId); + const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}); + + await expect(contract.methods.name().call()).to.be.rejectedWith('Unsupported shema version! Support only ImageURL'); + await expect(contract.methods.symbol().call()).to.be.rejectedWith('Unsupported shema version! Support only ImageURL'); + + const receiver = createEthAccount(web3); + const nextTokenId = await contract.methods.nextTokenId().call(); + expect(nextTokenId).to.be.equal('1'); + await expect(contract.methods.mintWithTokenURI( + receiver, + nextTokenId, + 'Test URI', + ).send({from: caller})).to.be.rejected; + + await expect(contract.methods.mintBulkWithTokenURI( + receiver, + [ + [nextTokenId, 'Test URI 0'], + [+nextTokenId + 1, 'Test URI 1'], + [+nextTokenId + 2, 'Test URI 2'], + ], + ).send({from: caller})).to.be.rejected; + }); + + itWeb3('Check support ERC721Metadata for ShemaVersion::ImageURL', async ({web3, api}) => { + const collectionId = await createCollectionExpectSuccess({ + mode: {type: 'NFT'}, + name: 'some_name', + tokenPrefix: 'some_prefix', + }); + const collection = await api.rpc.unique.collectionById(collectionId); + expect(collection.isSome).to.be.true; + expect(collection.unwrap().schemaVersion.toHuman()).to.be.eq('ImageURL'); + + const alice = privateKey('//Alice'); + + const caller = await createEthAccountWithBalance(api, web3); + const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, {Ethereum: caller}); + await submitTransactionAsync(alice, changeAdminTx); + + const address = collectionIdToAddress(collectionId); + const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}); + + expect(await contract.methods.name().call()).to.be.eq('some_name'); + expect(await contract.methods.symbol().call()).to.be.eq('some_prefix'); + + const receiver = createEthAccount(web3); + const nextTokenId = await contract.methods.nextTokenId().call(); + expect(nextTokenId).to.be.equal('1'); + const result = await contract.methods.mintWithTokenURI( + receiver, + nextTokenId, + 'Test URI', + ).send({from: caller}); + const events = normalizeEvents(result.events); + + expect(events).to.be.deep.equal([ + { + address, + event: 'Transfer', + args: { + from: '0x0000000000000000000000000000000000000000', + to: receiver, + tokenId: nextTokenId, + }, + }, + ]); + + expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI'); + }); +}); + --- 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 = {}): Promise { - 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);