git.delta.rocks / unique-network / refs/commits / 79ed02e181a1

difftreelog

CORE-346 Some changes for broken tests

Trubnikov Sergey2022-05-27parent: #4f3a569.patch.diff
in: master

5 files changed

modifiedtests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth
29 normalizeEvents,29 normalizeEvents,
30 subToEth,30 subToEth,
31 executeEthTxOnSub,31 executeEthTxOnSub,
32 evmCollectionHelper,
33 getCollectionAddressFromResult,
34 evmCollection,
32} from './util/helpers';35} from './util/helpers';
33import {36import {
34 addCollectionAdminExpectSuccess,37 addCollectionAdminExpectSuccess,
35 createCollectionExpectSuccess,38 createCollectionExpectSuccess,
36 getCreateCollectionResult,39 getCreateCollectionResult,
40 getDetailedCollectionInfo,
37 transferBalanceTo,41 transferBalanceTo,
38} from '../util/helpers';42} from '../util/helpers';
39import nonFungibleAbi from './nonFungibleAbi.json';43import nonFungibleAbi from './nonFungibleAbi.json';
42} from '../substrate/substrate-api';46} from '../substrate/substrate-api';
43import getBalance from '../substrate/get-balance';47import getBalance from '../substrate/get-balance';
44import {alicesPublicKey} from '../accounts';48import {alicesPublicKey} from '../accounts';
49import { evmToAddress } from '@polkadot/util-crypto';
4550
46describe('Sponsoring EVM contracts', () => {51describe('Sponsoring EVM contracts', () => {
47 itWeb3('Sponsoring can be set by the address that has deployed the contract', async ({api, web3}) => {52 itWeb3('Sponsoring can be set by the address that has deployed the contract', async ({api, web3}) => {
222 });227 });
223228
224 itWeb3('Sponsoring evm address from substrate collection', async ({api, web3}) => {229 itWeb3('Sponsoring evm address from substrate collection', async ({api, web3}) => {
225 const owner = privateKey('//Alice');230 const owner = await createEthAccountWithBalance(api, web3);
226 const userEth = createEthAccount(web3);231 const collectionHelper = evmCollectionHelper(web3, owner);
227 const collectionId = await createCollectionExpectSuccess();232 let result = await collectionHelper.methods.create721Collection('Sponsor collection', '1', '1').send();
228
229 {
230 const tx = api.tx.unique.setCollectionSponsor(collectionId, owner.address);233 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
231 const events = await submitTransactionAsync(owner, tx);234 const sponsor = await createEthAccountWithBalance(api, web3);
232 const result = getCreateCollectionResult(events);235 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
233 expect(result.success).to.be.true;
234 }
235 {
236 const tx = api.tx.unique.confirmSponsorship(collectionId);236 result = await collectionEvm.methods.ethSetSponsor(sponsor).send();
237 const events = await submitTransactionAsync(owner, tx);237 let collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;
238 const result = getCreateCollectionResult(events);
239 expect(result.success).to.be.true;238 expect(collectionSub.sponsorship.isUnconfirmed).to.be.true;
240 }
241
242 const address = collectionIdToAddress(collectionId);
243 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: userEth, ...GAS_ARGS});
244
245 { // This part should fail, because user not in access list and user have no money
246 const nextTokenId = await contract.methods.nextTokenId().call();
247 expect(nextTokenId).to.be.equal('1');239 expect(collectionSub.sponsorship.asUnconfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));
248 await expect(contract.methods.mintWithTokenURI(240 await expect(collectionEvm.methods.ethConfirmSponsorship().call()).to.be.rejectedWith('Caller is not set as sponsor');
249 userEth,241
250 nextTokenId,
251 'Test URI',
252 ).call({from: userEth})).to.be.rejectedWith(/PublicMintingNotAllowed/);
253 }
254
255 {
256 const tx = api.tx.unique.setPublicAccessMode(collectionId, 'AllowList');242 const sponsorCollection = evmCollection(web3, sponsor, collectionIdAddress);
257 const events = await submitTransactionAsync(owner, tx);243 await sponsorCollection.methods.ethConfirmSponsorship().send();
258 const result = getCreateCollectionResult(events);244 collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;
259 expect(result.success).to.be.true;245 expect(collectionSub.sponsorship.isConfirmed).to.be.true;
260 }
261 {
262 const tx = api.tx.unique.addToAllowList(collectionId, {Ethereum: userEth});
263 const events = await submitTransactionAsync(owner, tx);
264 const result = getCreateCollectionResult(events);
265 expect(result.success).to.be.true;246 expect(collectionSub.sponsorship.asConfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));
266 }247
267 {
268 const tx = api.tx.unique.setMintPermission(collectionId, true);248 const user = createEthAccount(web3);
269 const events = await submitTransactionAsync(owner, tx);249 const userContract = evmCollection(web3, user, collectionIdAddress);
270 const result = getCreateCollectionResult(events);250 const nextTokenId = await userContract.methods.nextTokenId().call();
251
271 expect(result.success).to.be.true;252 expect(nextTokenId).to.be.equal('1');
272 }
273
274 const [alicesBalanceBefore] = await getBalance(api, [alicesPublicKey]);253 await expect(userContract.methods.mintWithTokenURI(
254 user,
255 nextTokenId,
256 'Test URI',
257 ).call()).to.be.rejectedWith('PublicMintingNotAllowed');
258
259 // TODO: add this methods to eth
260 // {
261 // const tx = api.tx.unique.setPublicAccessMode(collectionId, 'AllowList');
262 // const events = await submitTransactionAsync(owner, tx);
263 // const result = getCreateCollectionResult(events);
264 // expect(result.success).to.be.true;
265 // }
266 // {
267 // const tx = api.tx.unique.addToAllowList(collectionId, {Ethereum: userEth});
268 // const events = await submitTransactionAsync(owner, tx);
269 // const result = getCreateCollectionResult(events);
270 // expect(result.success).to.be.true;
271 // }
272 // {
273 // const tx = api.tx.unique.setMintPermission(collectionId, true);
274 // const events = await submitTransactionAsync(owner, tx);
275 // const result = getCreateCollectionResult(events);
276 // expect(result.success).to.be.true;
277 // }
278
279 // const [alicesBalanceBefore] = await getBalance(api, [alicesPublicKey]);
275280
276 {281 {
277 const nextTokenId = await contract.methods.nextTokenId().call();282 const nextTokenId = await userContract.methods.nextTokenId().call();
278 expect(nextTokenId).to.be.equal('1');283 expect(nextTokenId).to.be.equal('1');
279 const result = await contract.methods.mintWithTokenURI(284 const result = await userContract.methods.mintWithTokenURI(
280 userEth,285 user,
281 nextTokenId,286 nextTokenId,
282 'Test URI',287 'Test URI',
283 ).send({from: userEth});288 ).send();
284 const events = normalizeEvents(result.events);289 const events = normalizeEvents(result.events);
285290
286 expect(events).to.be.deep.equal([291 expect(events).to.be.deep.equal([
287 {292 {
288 address,293 collectionIdAddress,
289 event: 'Transfer',294 event: 'Transfer',
290 args: {295 args: {
291 from: '0x0000000000000000000000000000000000000000',296 from: '0x0000000000000000000000000000000000000000',
292 to: userEth,297 to: user,
293 tokenId: nextTokenId,298 tokenId: nextTokenId,
294 },299 },
295 },300 },
296 ]);301 ]);
297302
298 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');303 expect(await userContract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
299 }304 }
300
301 const [alicesBalanceAfter] = await getBalance(api, [alicesPublicKey]);
302 expect(alicesBalanceAfter < alicesBalanceBefore).to.be.true;
303 });305 });
304306
305307
modifiedtests/src/eth/createCollection.test.tsdiffbeforeafterboth
--- a/tests/src/eth/createCollection.test.ts
+++ b/tests/src/eth/createCollection.test.ts
@@ -14,30 +14,18 @@
 // You should have received a copy of the GNU General Public License
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
-import nonFungibleAbi from './nonFungibleAbi.json';
-import {ApiPromise} from '@polkadot/api';
 import {evmToAddress} from '@polkadot/util-crypto';
 import {expect} from 'chai';
 import {getCreatedCollectionCount, getDetailedCollectionInfo} from '../util/helpers';
 import {
   evmCollectionHelper,
-  collectionIdFromAddress,
   collectionIdToAddress,
   createEthAccount,
   createEthAccountWithBalance,
   evmCollection,
-  GAS_ARGS,
   itWeb3,
-  normalizeAddress,
-  normalizeEvents,
+  getCollectionAddressFromResult,
 } from './util/helpers';
-
-async function getCollectionAddressFromResult(api: ApiPromise, result: any) {
-  const collectionIdAddress = normalizeAddress(result.events[0].raw.topics[2]);
-  const collectionId = collectionIdFromAddress(collectionIdAddress);  
-  const collection = (await getDetailedCollectionInfo(api, collectionId))!;
-  return {collectionIdAddress, collectionId, collection};
-}
 
 describe('Create collection from EVM', () => {
   itWeb3('Create collection', async ({api, web3}) => {
@@ -138,45 +126,6 @@
     expect(collectionSub.limits.ownerCanTransfer.toHuman()).to.be.eq(limits.ownerCanTransfer);
     expect(collectionSub.limits.ownerCanDestroy.toHuman()).to.be.eq(limits.ownerCanDestroy);
     expect(collectionSub.limits.transfersEnabled.toHuman()).to.be.eq(limits.transfersEnabled);
-  });
-
-  itWeb3('Check tokenURI', async ({web3, api}) => {
-    const owner = await createEthAccountWithBalance(api, web3);
-    const helper = evmCollectionHelper(web3, owner);
-    let result = await helper.methods.create721Collection('Mint collection', '6', '6').send();
-    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
-    const receiver = createEthAccount(web3);
-    const contract = new web3.eth.Contract(nonFungibleAbi as any, collectionIdAddress, {from: owner, ...GAS_ARGS});
-    const nextTokenId = await contract.methods.nextTokenId().call();
-
-    expect(nextTokenId).to.be.equal('1');
-    result = await contract.methods.mintWithTokenURI(
-      receiver,
-      nextTokenId,
-      'Test URI',
-    ).send();
-
-    const events = normalizeEvents(result.events);
-    const address = collectionIdToAddress(collectionId);
-
-    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');
-
-    // TODO: this wont work right now, need release 919000 first
-    // await helper.methods.setOffchainSchema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();
-    // const tokenUri = await contract.methods.tokenURI(nextTokenId).call();
-    // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);
   });
 
   itWeb3('Collection address exist', async ({api, web3}) => {
modifiedtests/src/eth/nonFungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -16,7 +16,7 @@
 
 import privateKey from '../substrate/privateKey';
 import {approveExpectSuccess, burnItemExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess, UNIQUE} from '../util/helpers';
-import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, transferBalanceToEth} from './util/helpers';
+import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, evmCollection, evmCollectionHelper, GAS_ARGS, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, transferBalanceToEth} from './util/helpers';
 import nonFungibleAbi from './nonFungibleAbi.json';
 import {expect} from 'chai';
 import {submitTransactionAsync} from '../substrate/substrate-api';
@@ -75,43 +75,42 @@
 
 describe('NFT: Plain calls', () => {
   itWeb3('Can perform mint()', async ({web3, api}) => {
-    const collection = await createCollectionExpectSuccess({
-      mode: {type: 'NFT'},
-    });
-    const alice = privateKey('//Alice');
-
-    const caller = await createEthAccountWithBalance(api, web3);
-    const changeAdminTx = api.tx.unique.addCollectionAdmin(collection, {Ethereum: caller});
-    await submitTransactionAsync(alice, changeAdminTx);
+    const owner = await createEthAccountWithBalance(api, web3);
+    const helper = evmCollectionHelper(web3, owner);
+    let result = await helper.methods.create721Collection('Mint collection', '6', '6').send();
+    const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
     const receiver = createEthAccount(web3);
+    const contract = evmCollection(web3, owner, collectionIdAddress);
+    const nextTokenId = await contract.methods.nextTokenId().call();
 
-    const address = collectionIdToAddress(collection);
-    const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
+    expect(nextTokenId).to.be.equal('1');
+    result = await contract.methods.mintWithTokenURI(
+      receiver,
+      nextTokenId,
+      'Test URI',
+    ).send();
 
-    {
-      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);
+    const events = normalizeEvents(result.events);
+    const address = collectionIdToAddress(collectionId);
 
-      expect(events).to.be.deep.equal([
-        {
-          address,
-          event: 'Transfer',
-          args: {
-            from: '0x0000000000000000000000000000000000000000',
-            to: receiver,
-            tokenId: nextTokenId,
-          },
+    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');
 
-      expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
-    }
+    // TODO: this wont work right now, need release 919000 first
+    // await helper.methods.setOffchainSchema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();
+    // const tokenUri = await contract.methods.tokenURI(nextTokenId).call();
+    // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);
   });
   itWeb3('Can perform mintBulk()', async ({web3, api}) => {
     const collection = await createCollectionExpectSuccess({
modifiedtests/src/eth/proxy/nonFungibleProxy.test.tsdiffbeforeafterboth
--- a/tests/src/eth/proxy/nonFungibleProxy.test.ts
+++ b/tests/src/eth/proxy/nonFungibleProxy.test.ts
@@ -127,6 +127,7 @@
       expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
     }
   });
+  
   itWeb3('Can perform mintBulk()', async ({web3, api}) => {
     const collection = await createCollectionExpectSuccess({
       mode: {type: 'NFT'},
modifiedtests/src/eth/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/eth/util/helpers.ts
+++ b/tests/src/eth/util/helpers.ts
@@ -23,12 +23,12 @@
 import usingApi, {submitTransactionAsync} from '../../substrate/substrate-api';
 import {IKeyringPair} from '@polkadot/types/types';
 import {expect} from 'chai';
-import {CrossAccountId, getGenericResult, UNIQUE} from '../../util/helpers';
+import {CrossAccountId, getDetailedCollectionInfo, getGenericResult, UNIQUE} from '../../util/helpers';
 import * as solc from 'solc';
 import config from '../../config';
 import privateKey from '../../substrate/privateKey';
 import contractHelpersAbi from './contractHelpersAbi.json';
-import collectionAbi from '../nonFungibleAbi.json';
+import nonFungibleAbi from '../nonFungibleAbi.json';
 import collectionHelperAbi from '../collectionHelperAbi.json';
 import getBalance from '../../substrate/get-balance';
 import waitNewBlocks from '../../substrate/wait-new-blocks';
@@ -68,6 +68,13 @@
   ];
 }
 
+export async function getCollectionAddressFromResult(api: ApiPromise, result: any) {
+  const collectionIdAddress = normalizeAddress(result.events[0].raw.topics[2]);
+  const collectionId = collectionIdFromAddress(collectionIdAddress);  
+  const collection = (await getDetailedCollectionInfo(api, collectionId))!;
+  return {collectionIdAddress, collectionId, collection};
+}
+
 export function collectionIdToAddress(collection: number): string {
   const buf = Buffer.from([0x17, 0xc4, 0xe6, 0x45, 0x3c, 0xc4, 0x9a, 0xaa, 0xae, 0xac, 0xa8, 0x94, 0xe6, 0xd9, 0x68, 0x3e,
     ...encodeIntBE(collection),
@@ -301,7 +308,7 @@
  * @returns 
  */
 export function evmCollection(web3: Web3, caller: string, collection: string) {
-  return new web3.eth.Contract(collectionAbi as any, collection, {from: caller, ...GAS_ARGS});
+  return new web3.eth.Contract(nonFungibleAbi as any, collection, {from: caller, ...GAS_ARGS});
 }
 
 /**