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

difftreelog

test add tests

Grigoriy Simonov2023-09-22parent: #17ea847.patch.diff
in: master

2 files changed

modifiedtests/src/eth/nonFungible.test.tsdiffbeforeafterboth
18import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
19import {Contract} from 'web3-eth-contract';19import {Contract} from 'web3-eth-contract';
20import {ITokenPropertyPermission} from '../util/playgrounds/types';20import {ITokenPropertyPermission} from '../util/playgrounds/types';
21import { CREATE_COLLECTION_DATA_DEFAULTS, CollectionMode, CreateCollectionData, TokenPermissionField } from './util/playgrounds/types';
2122
22describe('Check ERC721 token URI for NFT', () => {23describe('Check ERC721 token URI for NFT', () => {
23 let donor: IKeyringPair;24 let donor: IKeyringPair;
197 }198 }
198 });199 });
200
201 itEth('Can perform mintBulkCross()', async ({helper}) => {
202 const caller = await helper.eth.createAccountWithBalance(donor);
203 const callerCross = helper.ethCrossAccount.fromAddress(caller);
204 const receiver = helper.eth.createAccount();
205 const receiverCross = helper.ethCrossAccount.fromAddress(receiver);
206
207 const permissions = [
208 {code: TokenPermissionField.Mutable, value: true},
209 {code: TokenPermissionField.TokenOwner, value: true},
210 {code: TokenPermissionField.CollectionAdmin, value: true},
211 ];
212 const {collectionAddress} = await helper.eth.createCollection(
213 caller,
214 {
215 ...CREATE_COLLECTION_DATA_DEFAULTS,
216 name: 'A',
217 description: 'B',
218 tokenPrefix: 'C',
219 collectionMode: 'rft',
220 adminList: [callerCross],
221 tokenPropertyPermissions: [
222 {key: 'key_0_0', permissions},
223 {key: 'key_1_0', permissions},
224 {key: 'key_1_1', permissions},
225 {key: 'key_2_0', permissions},
226 {key: 'key_2_1', permissions},
227 {key: 'key_2_2', permissions},
228 ],
229 },
230 ).send();
231
232 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', caller);
233 {
234 const nextTokenId = await contract.methods.nextTokenId().call();
235 expect(nextTokenId).to.be.equal('1');
236 const result = await contract.methods.mintBulkCross([
237 {
238 owner: receiverCross,
239 properties: [
240 {key: 'key_0_0', value: Buffer.from('value_0_0')},
241 ],
242 },
243 {
244 owner: receiverCross,
245 properties: [
246 {key: 'key_1_0', value: Buffer.from('value_1_0')},
247 {key: 'key_1_1', value: Buffer.from('value_1_1')},
248 ],
249 },
250 {
251 owner: receiverCross,
252 properties: [
253 {key: 'key_2_0', value: Buffer.from('value_2_0')},
254 {key: 'key_2_1', value: Buffer.from('value_2_1')},
255 {key: 'key_2_2', value: Buffer.from('value_2_2')},
256 ],
257 },
258 ]).send({from: caller});
259 const events = result.events.Transfer.sort((a: any, b: any) => +a.returnValues.tokenId - b.returnValues.tokenId);
260 const bulkSize = 3;
261 for(let i = 0; i < bulkSize; i++) {
262 const event = events[i];
263 expect(event.address).to.equal(collectionAddress);
264 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
265 expect(event.returnValues.to).to.equal(receiver);
266 expect(event.returnValues.tokenId).to.equal(`${+nextTokenId + i}`);
267 }
268
269 const properties = [
270 await contract.methods.properties(+nextTokenId, []).call(),
271 await contract.methods.properties(+nextTokenId + 1, []).call(),
272 await contract.methods.properties(+nextTokenId + 2, []).call(),
273 ];
274 expect(properties).to.be.deep.equal([
275 [
276 ['key_0_0', helper.getWeb3().utils.toHex('value_0_0')],
277 ],
278 [
279 ['key_1_0', helper.getWeb3().utils.toHex('value_1_0')],
280 ['key_1_1', helper.getWeb3().utils.toHex('value_1_1')],
281 ],
282 [
283 ['key_2_0', helper.getWeb3().utils.toHex('value_2_0')],
284 ['key_2_1', helper.getWeb3().utils.toHex('value_2_1')],
285 ['key_2_2', helper.getWeb3().utils.toHex('value_2_2')],
286 ],
287 ]);
288 }
289 });
199290
200 itEth('Can perform burn()', async ({helper}) => {291 itEth('Can perform burn()', async ({helper}) => {
201 const caller = await helper.eth.createAccountWithBalance(donor);292 const caller = await helper.eth.createAccountWithBalance(donor);
modifiedtests/src/eth/reFungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -18,6 +18,7 @@
 import {expect, itEth, usingEthPlaygrounds} from './util';
 import {IKeyringPair} from '@polkadot/types/types';
 import {ITokenPropertyPermission} from '../util/playgrounds/types';
+import { CREATE_COLLECTION_DATA_DEFAULTS, TokenPermissionField } from './util/playgrounds/types';
 
 describe('Refungible: Plain calls', () => {
   let donor: IKeyringPair;
@@ -125,6 +126,96 @@
     }
   });
 
+  itEth('Can perform mintBulkCross()', async ({helper}) => {
+    const caller = await helper.eth.createAccountWithBalance(donor);
+    const callerCross = helper.ethCrossAccount.fromAddress(caller);
+    const receiver = helper.eth.createAccount();
+    const receiverCross = helper.ethCrossAccount.fromAddress(receiver);
+
+    const permissions = [
+      {code: TokenPermissionField.Mutable, value: true},
+      {code: TokenPermissionField.TokenOwner, value: true},
+      {code: TokenPermissionField.CollectionAdmin, value: true},
+    ];
+    const {collectionAddress} = await helper.eth.createCollection(
+      caller,
+      {
+        ...CREATE_COLLECTION_DATA_DEFAULTS,
+        name: 'A',
+        description: 'B',
+        tokenPrefix: 'C',
+        collectionMode: 'rft',
+        adminList: [callerCross],
+        tokenPropertyPermissions: [
+          {key: 'key_0_0', permissions},
+          {key: 'key_1_0', permissions},
+          {key: 'key_1_1', permissions},
+          {key: 'key_2_0', permissions},
+          {key: 'key_2_1', permissions},
+          {key: 'key_2_2', permissions},
+        ],
+      },
+    ).send();
+
+    const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', caller);
+    {
+      const nextTokenId = await contract.methods.nextTokenId().call();
+      expect(nextTokenId).to.be.equal('1');
+      const result = await contract.methods.mintBulkCross([
+        {
+          owner: receiverCross,
+          properties: [
+            {key: 'key_0_0', value: Buffer.from('value_0_0')},
+          ],
+        },
+        {
+          owner: receiverCross,
+          properties: [
+            {key: 'key_1_0', value: Buffer.from('value_1_0')},
+            {key: 'key_1_1', value: Buffer.from('value_1_1')},
+          ],
+        },
+        {
+          owner: receiverCross,
+          properties: [
+            {key: 'key_2_0', value: Buffer.from('value_2_0')},
+            {key: 'key_2_1', value: Buffer.from('value_2_1')},
+            {key: 'key_2_2', value: Buffer.from('value_2_2')},
+          ],
+        },
+      ]).send({from: caller});
+      const events = result.events.Transfer.sort((a: any, b: any) => +a.returnValues.tokenId - b.returnValues.tokenId);
+      const bulkSize = 3;
+      for(let i = 0; i < bulkSize; i++) {
+        const event = events[i];
+        expect(event.address).to.equal(collectionAddress);
+        expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
+        expect(event.returnValues.to).to.equal(receiver);
+        expect(event.returnValues.tokenId).to.equal(`${+nextTokenId + i}`);
+      }
+
+      const properties = [
+        await contract.methods.properties(+nextTokenId, []).call(),
+        await contract.methods.properties(+nextTokenId + 1, []).call(),
+        await contract.methods.properties(+nextTokenId + 2, []).call(),
+      ];
+      expect(properties).to.be.deep.equal([
+        [
+          ['key_0_0', helper.getWeb3().utils.toHex('value_0_0')],
+        ],
+        [
+          ['key_1_0', helper.getWeb3().utils.toHex('value_1_0')],
+          ['key_1_1', helper.getWeb3().utils.toHex('value_1_1')],
+        ],
+        [
+          ['key_2_0', helper.getWeb3().utils.toHex('value_2_0')],
+          ['key_2_1', helper.getWeb3().utils.toHex('value_2_1')],
+          ['key_2_2', helper.getWeb3().utils.toHex('value_2_2')],
+        ],
+      ]);
+    }
+  });
+
   itEth('Can perform setApprovalForAll()', async ({helper}) => {
     const owner = await helper.eth.createAccountWithBalance(donor);
     const operator = helper.eth.createAccount();