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

difftreelog

test(ss58Format) fix format address, remove accounts constants

h3lpkey2022-06-08parent: #2074c93.patch.diff
in: master

6 files changed

deletedtests/src/accounts.tsdiffbeforeafterboth
--- a/tests/src/accounts.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// This file is part of Unique Network.
-
-// Unique Network is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Unique Network is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-
-export const bobsPublicKey = '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty';
-export const alicesPublicKey = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
-export const ferdiesPublicKey = '5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL';
-export const nullPublicKey = '5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM';
\ No newline at end of file
modifiedtests/src/creditFeesToTreasury.test.tsdiffbeforeafterboth
--- a/tests/src/creditFeesToTreasury.test.ts
+++ b/tests/src/creditFeesToTreasury.test.ts
@@ -18,7 +18,6 @@
 import chai from 'chai';
 import chaiAsPromised from 'chai-as-promised';
 import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
-import {alicesPublicKey, bobsPublicKey} from './accounts';
 import {IKeyringPair} from '@polkadot/types/types';
 import {
   createCollectionExpectSuccess,
@@ -71,17 +70,16 @@
   });
 
   it('Total issuance does not change', async () => {
-    await usingApi(async (api, privateKeyWrapper) => {
+    await usingApi(async (api) => {
       await skipInflationBlock(api);
       await waitNewBlocks(api, 1);
 
       const totalBefore = (await api.query.balances.totalIssuance()).toBigInt();
 
-      const alicePrivateKey = privateKeyWrapper('//Alice');
       const amount = 1n;
-      const transfer = api.tx.balances.transfer(bobsPublicKey, amount);
+      const transfer = api.tx.balances.transfer(bob.address, amount);
 
-      const result = getGenericResult(await submitTransactionAsync(alicePrivateKey, transfer));
+      const result = getGenericResult(await submitTransactionAsync(alice, transfer));
 
       const totalAfter = (await api.query.balances.totalIssuance()).toBigInt();
 
@@ -91,20 +89,19 @@
   });
 
   it('Sender balance decreased by fee+sent amount, Treasury balance increased by fee', async () => {
-    await usingApi(async (api, privateKeyWrapper) => {
+    await usingApi(async (api) => {
       await skipInflationBlock(api);
       await waitNewBlocks(api, 1);
 
-      const alicePrivateKey = privateKeyWrapper('//Alice');
       const treasuryBalanceBefore: bigint = (await api.query.system.account(TREASURY)).data.free.toBigInt();
-      const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
+      const aliceBalanceBefore: bigint = (await api.query.system.account(alice.address)).data.free.toBigInt();
 
       const amount = 1n;
-      const transfer = api.tx.balances.transfer(bobsPublicKey, amount);
-      const result = getGenericResult(await submitTransactionAsync(alicePrivateKey, transfer));
+      const transfer = api.tx.balances.transfer(bob.address, amount);
+      const result = getGenericResult(await submitTransactionAsync(alice, transfer));
 
       const treasuryBalanceAfter: bigint = (await api.query.system.account(TREASURY)).data.free.toBigInt();
-      const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
+      const aliceBalanceAfter: bigint = (await api.query.system.account(alice.address)).data.free.toBigInt();
       const fee = aliceBalanceBefore - aliceBalanceAfter - amount;
       const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;
 
@@ -114,19 +111,18 @@
   });
 
   it('Treasury balance increased by failed tx fee', async () => {
-    await usingApi(async (api, privateKeyWrapper) => {
+    await usingApi(async (api) => {
       //await skipInflationBlock(api);
       await waitNewBlocks(api, 1);
 
-      const bobPrivateKey = privateKeyWrapper('//Bob');
       const treasuryBalanceBefore = (await api.query.system.account(TREASURY)).data.free.toBigInt();
-      const bobBalanceBefore = (await api.query.system.account(bobsPublicKey)).data.free.toBigInt();
+      const bobBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
 
-      const badTx = api.tx.balances.setBalance(alicesPublicKey, 0, 0);
-      await expect(submitTransactionExpectFailAsync(bobPrivateKey, badTx)).to.be.rejected;
+      const badTx = api.tx.balances.setBalance(alice.address, 0, 0);
+      await expect(submitTransactionExpectFailAsync(bob, badTx)).to.be.rejected;
 
       const treasuryBalanceAfter = (await api.query.system.account(TREASURY)).data.free.toBigInt();
-      const bobBalanceAfter = (await api.query.system.account(bobsPublicKey)).data.free.toBigInt();
+      const bobBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();
       const fee = bobBalanceBefore - bobBalanceAfter;
       const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;
 
@@ -140,12 +136,12 @@
       await waitNewBlocks(api, 1);
 
       const treasuryBalanceBefore = (await api.query.system.account(TREASURY)).data.free.toBigInt();
-      const aliceBalanceBefore = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
+      const aliceBalanceBefore = (await api.query.system.account(alice.address)).data.free.toBigInt();
 
       await createCollectionExpectSuccess();
 
       const treasuryBalanceAfter = (await api.query.system.account(TREASURY)).data.free.toBigInt();
-      const aliceBalanceAfter = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
+      const aliceBalanceAfter = (await api.query.system.account(alice.address)).data.free.toBigInt();
       const fee = aliceBalanceBefore - aliceBalanceAfter;
       const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;
 
@@ -158,11 +154,11 @@
       await skipInflationBlock(api);
       await waitNewBlocks(api, 1);
 
-      const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
+      const aliceBalanceBefore: bigint = (await api.query.system.account(alice.address)).data.free.toBigInt();
 
       await createCollectionExpectSuccess();
 
-      const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
+      const aliceBalanceAfter: bigint = (await api.query.system.account(alice.address)).data.free.toBigInt();
       const fee = aliceBalanceBefore - aliceBalanceAfter;
 
       expect(fee / UNIQUE < BigInt(Math.ceil(saneMaximumFee + createCollectionDeposit))).to.be.true;
@@ -178,9 +174,9 @@
       const collectionId = await createCollectionExpectSuccess();
       const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');
 
-      const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
+      const aliceBalanceBefore: bigint = (await api.query.system.account(alice.address)).data.free.toBigInt();
       await transferExpectSuccess(collectionId, tokenId, alice, bob, 1, 'NFT');
-      const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
+      const aliceBalanceAfter: bigint = (await api.query.system.account(alice.address)).data.free.toBigInt();
 
       const fee = Number(aliceBalanceBefore - aliceBalanceAfter) / Number(UNIQUE);
       const expectedTransferFee = 0.1;
modifiedtests/src/substrate/substrate-api.tsdiffbeforeafterboth
--- a/tests/src/substrate/substrate-api.ts
+++ b/tests/src/substrate/substrate-api.ts
@@ -88,7 +88,7 @@
     await promisifySubstrate(api, async () => {
       if (api) {
         await api.isReadyOrError;
-        const ss58Format = (api.registry.getChainProperties())!.toHuman().ss58Format;
+        const ss58Format = (api.registry.getChainProperties())!.toJSON().ss58Format;
         const privateKeyWrapper = (account: string) => privateKey(account, Number(ss58Format));
         result = await action(api, privateKeyWrapper);
       }
modifiedtests/src/transfer.test.tsdiffbeforeafterboth
17import {ApiPromise} from '@polkadot/api';17import {ApiPromise} from '@polkadot/api';
18import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
19import {expect} from 'chai';19import {expect} from 'chai';
20import {alicesPublicKey, bobsPublicKey} from './accounts';
21import getBalance from './substrate/get-balance';20import getBalance from './substrate/get-balance';
22import {default as usingApi, submitTransactionAsync} from './substrate/substrate-api';21import {default as usingApi, submitTransactionAsync} from './substrate/substrate-api';
23import {22import {
47let charlie: IKeyringPair;46let charlie: IKeyringPair;
4847
49describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {48describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {
49 before(async () => {
50 await usingApi(async (api, privateKeyWrapper) => {
51 alice = privateKeyWrapper('//Alice');
52 bob = privateKeyWrapper('//Bob');
53 });
54 });
55
50 it('Balance transfers and check balance', async () => {56 it('Balance transfers and check balance', async () => {
51 await usingApi(async (api, privateKeyWrapper) => {57 await usingApi(async (api, privateKeyWrapper) => {
52 const [alicesBalanceBefore, bobsBalanceBefore] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);58 const [alicesBalanceBefore, bobsBalanceBefore] = await getBalance(api, [alice.address, bob.address]);
53
54 const alicePrivateKey = privateKeyWrapper('//Alice');
5559
56 const transfer = api.tx.balances.transfer(bobsPublicKey, 1n);60 const transfer = api.tx.balances.transfer(bob.address, 1n);
57 const events = await submitTransactionAsync(alicePrivateKey, transfer);61 const events = await submitTransactionAsync(alice, transfer);
58 const result = getCreateItemResult(events);62 const result = getCreateItemResult(events);
59 // tslint:disable-next-line:no-unused-expression63 // tslint:disable-next-line:no-unused-expression
60 expect(result.success).to.be.true;64 expect(result.success).to.be.true;
6165
62 const [alicesBalanceAfter, bobsBalanceAfter] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);66 const [alicesBalanceAfter, bobsBalanceAfter] = await getBalance(api, [alice.address, bob.address]);
6367
64 // tslint:disable-next-line:no-unused-expression68 // tslint:disable-next-line:no-unused-expression
65 expect(alicesBalanceAfter < alicesBalanceBefore).to.be.true;69 expect(alicesBalanceAfter < alicesBalanceBefore).to.be.true;
73 // Find unused address77 // Find unused address
74 const pk = await findUnusedAddress(api);78 const pk = await findUnusedAddress(api);
7579
76 const badTransfer = api.tx.balances.transfer(bobsPublicKey, 1n);80 const badTransfer = api.tx.balances.transfer(bob.address, 1n);
77 // const events = await submitTransactionAsync(pk, badTransfer);81 // const events = await submitTransactionAsync(pk, badTransfer);
78 const badTransaction = async () => {82 const badTransaction = async () => {
79 const events = await submitTransactionAsync(pk, badTransfer);83 const events = await submitTransactionAsync(pk, badTransfer);
8791
88 it('User can transfer owned token', async () => {92 it('User can transfer owned token', async () => {
89 await usingApi(async (api, privateKeyWrapper) => {93 await usingApi(async (api, privateKeyWrapper) => {
90 const alice = privateKeyWrapper('//Alice');
91 const bob = privateKeyWrapper('//Bob');
92 // nft94 // nft
93 const nftCollectionId = await createCollectionExpectSuccess();95 const nftCollectionId = await createCollectionExpectSuccess();
94 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');96 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
114116
115 it('Collection admin can transfer owned token', async () => {117 it('Collection admin can transfer owned token', async () => {
116 await usingApi(async (api, privateKeyWrapper) => {118 await usingApi(async (api, privateKeyWrapper) => {
117 const alice = privateKeyWrapper('//Alice');
118 const bob = privateKeyWrapper('//Bob');
119 // nft119 // nft
120 const nftCollectionId = await createCollectionExpectSuccess();120 const nftCollectionId = await createCollectionExpectSuccess();
121 await addCollectionAdminExpectSuccess(alice, nftCollectionId, bob.address);121 await addCollectionAdminExpectSuccess(alice, nftCollectionId, bob.address);
316describe('Transfers to self (potentially over substrate-evm boundary)', () => {316describe('Transfers to self (potentially over substrate-evm boundary)', () => {
317 itWeb3('Transfers to self. In case of same frontend', async ({api, privateKeyWrapper}) => {317 itWeb3('Transfers to self. In case of same frontend', async ({api, privateKeyWrapper}) => {
318 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});318 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
319 const alice = privateKeyWrapper('//Alice');
320 const aliceProxy = subToEth(alice.address);319 const aliceProxy = subToEth(alice.address);
321 const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address});320 const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address});
322 await transferExpectSuccess(collectionId, tokenId, alice, {Ethereum: aliceProxy}, 10, 'Fungible');321 await transferExpectSuccess(collectionId, tokenId, alice, {Ethereum: aliceProxy}, 10, 'Fungible');
328327
329 itWeb3('Transfers to self. In case of substrate-evm boundary', async ({api, privateKeyWrapper}) => {328 itWeb3('Transfers to self. In case of substrate-evm boundary', async ({api, privateKeyWrapper}) => {
330 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});329 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
331 const alice = privateKeyWrapper('//Alice');
332 const aliceProxy = subToEth(alice.address);330 const aliceProxy = subToEth(alice.address);
333 const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address});331 const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address});
334 const balanceAliceBefore = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId);332 const balanceAliceBefore = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId);
340338
341 itWeb3('Transfers to self. In case of inside substrate-evm', async ({api, privateKeyWrapper}) => {339 itWeb3('Transfers to self. In case of inside substrate-evm', async ({api, privateKeyWrapper}) => {
342 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});340 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
343 const alice = privateKeyWrapper('//Alice');
344 const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address});341 const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address});
345 const balanceAliceBefore = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId);342 const balanceAliceBefore = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId);
346 await transferExpectSuccess(collectionId, tokenId, alice, alice , 10, 'Fungible');343 await transferExpectSuccess(collectionId, tokenId, alice, alice , 10, 'Fungible');
351348
352 itWeb3('Transfers to self. In case of inside substrate-evm when not enought "Fungibles"', async ({api, privateKeyWrapper}) => {349 itWeb3('Transfers to self. In case of inside substrate-evm when not enought "Fungibles"', async ({api, privateKeyWrapper}) => {
353 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});350 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
354 const alice = privateKeyWrapper('//Alice');
355 const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address});351 const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address});
356 const balanceAliceBefore = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId);352 const balanceAliceBefore = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId);
357 await transferExpectFailure(collectionId, tokenId, alice, alice , 11);353 await transferExpectFailure(collectionId, tokenId, alice, alice , 11);
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -23,7 +23,6 @@
 import BN from 'bn.js';
 import chai from 'chai';
 import chaiAsPromised from 'chai-as-promised';
-import {alicesPublicKey} from '../accounts';
 import {default as usingApi, executeTransaction, submitTransactionAsync, submitTransactionExpectFailAsync} from '../substrate/substrate-api';
 import {hexToStr, strToUTF16, utf16ToStr} from './util';
 import {UpDataStructsRpcCollection, UpDataStructsCreateItemData, UpDataStructsProperty} from '@polkadot/types/lookup';
@@ -40,7 +39,7 @@
 
 export function normalizeAccountId(input: string | AccountId | CrossAccountId | IKeyringPair): CrossAccountId {
   if (typeof input === 'string') {
-    if (input.length === 48 || input.length === 47) {
+    if (input.length >= 47) {
       return {Substrate: input};
     } else if (input.length === 42 && input.startsWith('0x')) {
       return {Ethereum: input.toLowerCase()};
@@ -363,7 +362,7 @@
     // tslint:disable-next-line:no-unused-expression
     expect(collection).to.be.not.null;
     expect(collectionCountAfter).to.be.equal(collectionCountBefore + 1, 'Error: NFT collection NOT created.');
-    expect(collection.owner.toString()).to.be.equal(toSubstrateAddress(alicesPublicKey));
+    expect(collection.owner.toString()).to.be.equal(toSubstrateAddress(alicePrivateKey));
     expect(utf16ToStr(collection.name.toJSON() as any)).to.be.equal(name);
     expect(utf16ToStr(collection.description.toJSON() as any)).to.be.equal(description);
     expect(hexToStr(collection.tokenPrefix.toJSON())).to.be.equal(tokenPrefix);
@@ -411,7 +410,7 @@
     // tslint:disable-next-line:no-unused-expression
     expect(collection).to.be.not.null;
     expect(collectionCountAfter).to.be.equal(collectionCountBefore + 1, 'Error: NFT collection NOT created.');
-    expect(collection.owner.toString()).to.be.equal(toSubstrateAddress(alicesPublicKey));
+    expect(collection.owner.toString()).to.be.equal(toSubstrateAddress(alicePrivateKey));
     expect(utf16ToStr(collection.name.toJSON() as any)).to.be.equal(name);
     expect(utf16ToStr(collection.description.toJSON() as any)).to.be.equal(description);
     expect(hexToStr(collection.tokenPrefix.toJSON())).to.be.equal(tokenPrefix);
modifiedtests/src/xcmTransfer.test.tsdiffbeforeafterboth
--- a/tests/src/xcmTransfer.test.ts
+++ b/tests/src/xcmTransfer.test.ts
@@ -24,7 +24,6 @@
 import {getGenericResult} from './util/helpers';
 import waitNewBlocks from './substrate/wait-new-blocks';
 import getBalance from './substrate/get-balance';
-import {alicesPublicKey} from './accounts';
 
 chai.use(chaiAsPromised);
 const expect = chai.expect;
@@ -144,7 +143,7 @@
     let balanceBefore: bigint;
     
     await usingApi(async (api) => {
-      [balanceBefore] = await getBalance(api, [alicesPublicKey]);
+      [balanceBefore] = await getBalance(api, [alice.address]);
     });
 
     await usingApi(async (api) => {
@@ -181,7 +180,7 @@
     await usingApi(async (api) => {
       // todo do something about instant sealing, where there might not be any new blocks
       await waitNewBlocks(api, 3);
-      const [balanceAfter] = await getBalance(api, [alicesPublicKey]);
+      const [balanceAfter] = await getBalance(api, [alice.address]);
       expect(balanceAfter > balanceBefore).to.be.true;
     });
   });