git.delta.rocks / unique-network / refs/commits / 2694afec2e83

difftreelog

CORE-325 Make test to check supprot ERC721Metadata

Trubnikov Sergey2022-04-07parent: #d83cc5b.patch.diff
in: master

2 files changed

modifiedtests/src/eth/metadata.test.tsdiffbeforeafterboth
--- 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');
+  });
+});
+
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
268 name: string,268 name: string,
269 description: string,269 description: string,
270 tokenPrefix: string,270 tokenPrefix: string,
271 shemaVersion: string,
271};272};
272273
273const defaultCreateCollectionParams: CreateCollectionParams = {274const defaultCreateCollectionParams: CreateCollectionParams = {
274 description: 'description',275 description: 'description',
275 mode: {type: 'NFT'},276 mode: {type: 'NFT'},
276 name: 'name',277 name: 'name',
277 tokenPrefix: 'prefix',278 tokenPrefix: 'prefix',
279 shemaVersion: 'ImageURL',
278};280};
279281
280export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {282export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {
281 const {name, description, mode, tokenPrefix} = {...defaultCreateCollectionParams, ...params};283 const {name, description, mode, tokenPrefix, shemaVersion} = {...defaultCreateCollectionParams, ...params};
282284
283 let collectionId = 0;285 let collectionId = 0;
284 await usingApi(async (api) => {286 await usingApi(async (api) => {
303 name: strToUTF16(name),
304 description: strToUTF16(description),
305 tokenPrefix: strToUTF16(tokenPrefix),
306 mode: modeprm as any,
307 schemaVersion: shemaVersion,
308 });
301 const events = await submitTransactionAsync(alicePrivateKey, tx);309 const events = await submitTransactionAsync(alicePrivateKey, tx);
302 const result = getCreateCollectionResult(events);310 const result = getCreateCollectionResult(events);