git.delta.rocks / unique-network / refs/commits / f05205069aee

difftreelog

CORE-302 Add test for tokenURI

Trubnikov Sergey2022-04-26parent: #7b3faa5.patch.diff
in: master

1 file changed

modifiedtests/src/eth/createCollection.test.tsdiffbeforeafterboth
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17import nonFungibleAbi from './nonFungibleAbi.json';
17import {ApiPromise} from '@polkadot/api';18import {ApiPromise} from '@polkadot/api';
18import {evmToAddress} from '@polkadot/util-crypto';19import {evmToAddress} from '@polkadot/util-crypto';
19import {expect} from 'chai';20import {expect} from 'chai';
20import {getCreatedCollectionCount, getDetailedCollectionInfo} from '../util/helpers';21import {getCreatedCollectionCount, getDetailedCollectionInfo} from '../util/helpers';
21import {collectionHelper, collectionIdFromAddress, createEthAccount, createEthAccountWithBalance, itWeb3, normalizeAddress} from './util/helpers';22import {
23 collectionHelper,
24 collectionIdFromAddress,
25 collectionIdToAddress,
26 createEthAccount,
27 createEthAccountWithBalance,
28 GAS_ARGS,
29 itWeb3,
30 normalizeAddress,
31 normalizeEvents,
32} from './util/helpers';
2233
23async function getCollectionAddressFromResult(api: ApiPromise, result: any) {34async function getCollectionAddressFromResult(api: ApiPromise, result: any) {
104 itWeb3('Set limits', async ({api, web3}) => {115 itWeb3('Set limits', async ({api, web3}) => {
105 const owner = await createEthAccountWithBalance(api, web3);116 const owner = await createEthAccountWithBalance(api, web3);
106 const helper = collectionHelper(web3, owner);117 const helper = collectionHelper(web3, owner);
107 const result = await helper.methods.create721Collection('Const collection', '4', '4').send();118 const result = await helper.methods.create721Collection('Const collection', '5', '5').send();
108 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);119 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
109 const limits = {120 const limits = {
110 accountTokenOwnershipLimit: 1000,121 accountTokenOwnershipLimit: 1000,
133 expect(collection.limits.transfersEnabled.toHuman()).to.be.eq(limits.transfersEnabled);144 expect(collection.limits.transfersEnabled.toHuman()).to.be.eq(limits.transfersEnabled);
134 });145 });
146
147 itWeb3('Check tokenURI', async ({web3, api}) => {
148 const owner = await createEthAccountWithBalance(api, web3);
149 const helper = collectionHelper(web3, owner);
150 let result = await helper.methods.create721Collection('Mint collection', '6', '6').send();
151 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
152 const receiver = createEthAccount(web3);
153 const contract = new web3.eth.Contract(nonFungibleAbi as any, collectionIdAddress.toLowerCase(), {from: owner, ...GAS_ARGS});
154 const nextTokenId = await contract.methods.nextTokenId().call();
155
156 expect(nextTokenId).to.be.equal('1');
157 result = await contract.methods.mintWithTokenURI(
158 receiver,
159 nextTokenId,
160 'Test URI',
161 ).send();
162
163 const events = normalizeEvents(result.events);
164 const address = collectionIdToAddress(collectionId);
165
166 expect(events).to.be.deep.equal([
167 {
168 address,
169 event: 'Transfer',
170 args: {
171 from: '0x0000000000000000000000000000000000000000',
172 to: receiver,
173 tokenId: nextTokenId,
174 },
175 },
176 ]);
177
178 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
179
180 // TODO: this wont work right now, need release 919000 first
181 // await helper.methods.setOffchainShema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();
182 // const tokenUri = await contract.methods.tokenURI(nextTokenId).call();
183 // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);
184 });
135});185});
136186
137describe('(!negative tests!) Create collection from EVM', () => {187describe('(!negative tests!) Create collection from EVM', () => {