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
1616
17import {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';
2124
22describe('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});
69
70describe.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');
79
80 const alice = privateKey('//Alice');
81
82 const caller = await createEthAccountWithBalance(api, web3);
83 const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, {Ethereum: caller});
84 await submitTransactionAsync(alice, changeAdminTx);
85
86 const address = collectionIdToAddress(collectionId);
87 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
88
89 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');
91
92 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;
100
101 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 });
110
111 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');
120
121 const alice = privateKey('//Alice');
122
123 const caller = await createEthAccountWithBalance(api, web3);
124 const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, {Ethereum: caller});
125 await submitTransactionAsync(alice, changeAdminTx);
126
127 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');
132
133 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);
142
143 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 ]);
154
155 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
156 });
157});
158
159
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);