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
18import chai from 'chai';18import chai from 'chai';
19import chaiAsPromised from 'chai-as-promised';19import chaiAsPromised from 'chai-as-promised';
20import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';20import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
21import {alicesPublicKey, bobsPublicKey} from './accounts';
22import {IKeyringPair} from '@polkadot/types/types';21import {IKeyringPair} from '@polkadot/types/types';
23import {22import {
24 createCollectionExpectSuccess,23 createCollectionExpectSuccess,
71 });70 });
7271
73 it('Total issuance does not change', async () => {72 it('Total issuance does not change', async () => {
74 await usingApi(async (api, privateKeyWrapper) => {73 await usingApi(async (api) => {
75 await skipInflationBlock(api);74 await skipInflationBlock(api);
76 await waitNewBlocks(api, 1);75 await waitNewBlocks(api, 1);
7776
78 const totalBefore = (await api.query.balances.totalIssuance()).toBigInt();77 const totalBefore = (await api.query.balances.totalIssuance()).toBigInt();
7978
80 const alicePrivateKey = privateKeyWrapper('//Alice');
81 const amount = 1n;79 const amount = 1n;
82 const transfer = api.tx.balances.transfer(bobsPublicKey, amount);80 const transfer = api.tx.balances.transfer(bob.address, amount);
8381
84 const result = getGenericResult(await submitTransactionAsync(alicePrivateKey, transfer));82 const result = getGenericResult(await submitTransactionAsync(alice, transfer));
8583
86 const totalAfter = (await api.query.balances.totalIssuance()).toBigInt();84 const totalAfter = (await api.query.balances.totalIssuance()).toBigInt();
8785
91 });89 });
9290
93 it('Sender balance decreased by fee+sent amount, Treasury balance increased by fee', async () => {91 it('Sender balance decreased by fee+sent amount, Treasury balance increased by fee', async () => {
94 await usingApi(async (api, privateKeyWrapper) => {92 await usingApi(async (api) => {
95 await skipInflationBlock(api);93 await skipInflationBlock(api);
96 await waitNewBlocks(api, 1);94 await waitNewBlocks(api, 1);
9795
98 const alicePrivateKey = privateKeyWrapper('//Alice');
99 const treasuryBalanceBefore: bigint = (await api.query.system.account(TREASURY)).data.free.toBigInt();96 const treasuryBalanceBefore: bigint = (await api.query.system.account(TREASURY)).data.free.toBigInt();
100 const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();97 const aliceBalanceBefore: bigint = (await api.query.system.account(alice.address)).data.free.toBigInt();
10198
102 const amount = 1n;99 const amount = 1n;
103 const transfer = api.tx.balances.transfer(bobsPublicKey, amount);100 const transfer = api.tx.balances.transfer(bob.address, amount);
104 const result = getGenericResult(await submitTransactionAsync(alicePrivateKey, transfer));101 const result = getGenericResult(await submitTransactionAsync(alice, transfer));
105102
106 const treasuryBalanceAfter: bigint = (await api.query.system.account(TREASURY)).data.free.toBigInt();103 const treasuryBalanceAfter: bigint = (await api.query.system.account(TREASURY)).data.free.toBigInt();
107 const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();104 const aliceBalanceAfter: bigint = (await api.query.system.account(alice.address)).data.free.toBigInt();
108 const fee = aliceBalanceBefore - aliceBalanceAfter - amount;105 const fee = aliceBalanceBefore - aliceBalanceAfter - amount;
109 const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;106 const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;
110107
114 });111 });
115112
116 it('Treasury balance increased by failed tx fee', async () => {113 it('Treasury balance increased by failed tx fee', async () => {
117 await usingApi(async (api, privateKeyWrapper) => {114 await usingApi(async (api) => {
118 //await skipInflationBlock(api);115 //await skipInflationBlock(api);
119 await waitNewBlocks(api, 1);116 await waitNewBlocks(api, 1);
120117
121 const bobPrivateKey = privateKeyWrapper('//Bob');
122 const treasuryBalanceBefore = (await api.query.system.account(TREASURY)).data.free.toBigInt();118 const treasuryBalanceBefore = (await api.query.system.account(TREASURY)).data.free.toBigInt();
123 const bobBalanceBefore = (await api.query.system.account(bobsPublicKey)).data.free.toBigInt();119 const bobBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
124120
125 const badTx = api.tx.balances.setBalance(alicesPublicKey, 0, 0);121 const badTx = api.tx.balances.setBalance(alice.address, 0, 0);
126 await expect(submitTransactionExpectFailAsync(bobPrivateKey, badTx)).to.be.rejected;122 await expect(submitTransactionExpectFailAsync(bob, badTx)).to.be.rejected;
127123
128 const treasuryBalanceAfter = (await api.query.system.account(TREASURY)).data.free.toBigInt();124 const treasuryBalanceAfter = (await api.query.system.account(TREASURY)).data.free.toBigInt();
129 const bobBalanceAfter = (await api.query.system.account(bobsPublicKey)).data.free.toBigInt();125 const bobBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();
130 const fee = bobBalanceBefore - bobBalanceAfter;126 const fee = bobBalanceBefore - bobBalanceAfter;
131 const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;127 const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;
132128
140 await waitNewBlocks(api, 1);136 await waitNewBlocks(api, 1);
141137
142 const treasuryBalanceBefore = (await api.query.system.account(TREASURY)).data.free.toBigInt();138 const treasuryBalanceBefore = (await api.query.system.account(TREASURY)).data.free.toBigInt();
143 const aliceBalanceBefore = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();139 const aliceBalanceBefore = (await api.query.system.account(alice.address)).data.free.toBigInt();
144140
145 await createCollectionExpectSuccess();141 await createCollectionExpectSuccess();
146142
147 const treasuryBalanceAfter = (await api.query.system.account(TREASURY)).data.free.toBigInt();143 const treasuryBalanceAfter = (await api.query.system.account(TREASURY)).data.free.toBigInt();
148 const aliceBalanceAfter = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();144 const aliceBalanceAfter = (await api.query.system.account(alice.address)).data.free.toBigInt();
149 const fee = aliceBalanceBefore - aliceBalanceAfter;145 const fee = aliceBalanceBefore - aliceBalanceAfter;
150 const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;146 const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;
151147
158 await skipInflationBlock(api);154 await skipInflationBlock(api);
159 await waitNewBlocks(api, 1);155 await waitNewBlocks(api, 1);
160156
161 const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();157 const aliceBalanceBefore: bigint = (await api.query.system.account(alice.address)).data.free.toBigInt();
162158
163 await createCollectionExpectSuccess();159 await createCollectionExpectSuccess();
164160
165 const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();161 const aliceBalanceAfter: bigint = (await api.query.system.account(alice.address)).data.free.toBigInt();
166 const fee = aliceBalanceBefore - aliceBalanceAfter;162 const fee = aliceBalanceBefore - aliceBalanceAfter;
167163
168 expect(fee / UNIQUE < BigInt(Math.ceil(saneMaximumFee + createCollectionDeposit))).to.be.true;164 expect(fee / UNIQUE < BigInt(Math.ceil(saneMaximumFee + createCollectionDeposit))).to.be.true;
178 const collectionId = await createCollectionExpectSuccess();174 const collectionId = await createCollectionExpectSuccess();
179 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');175 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');
180176
181 const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();177 const aliceBalanceBefore: bigint = (await api.query.system.account(alice.address)).data.free.toBigInt();
182 await transferExpectSuccess(collectionId, tokenId, alice, bob, 1, 'NFT');178 await transferExpectSuccess(collectionId, tokenId, alice, bob, 1, 'NFT');
183 const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();179 const aliceBalanceAfter: bigint = (await api.query.system.account(alice.address)).data.free.toBigInt();
184180
185 const fee = Number(aliceBalanceBefore - aliceBalanceAfter) / Number(UNIQUE);181 const fee = Number(aliceBalanceBefore - aliceBalanceAfter) / Number(UNIQUE);
186 const expectedTransferFee = 0.1;182 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
--- a/tests/src/transfer.test.ts
+++ b/tests/src/transfer.test.ts
@@ -17,7 +17,6 @@
 import {ApiPromise} from '@polkadot/api';
 import {IKeyringPair} from '@polkadot/types/types';
 import {expect} from 'chai';
-import {alicesPublicKey, bobsPublicKey} from './accounts';
 import getBalance from './substrate/get-balance';
 import {default as usingApi, submitTransactionAsync} from './substrate/substrate-api';
 import {
@@ -47,19 +46,24 @@
 let charlie: IKeyringPair;
 
 describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {
+  before(async () => {
+    await usingApi(async (api, privateKeyWrapper) => {
+      alice = privateKeyWrapper('//Alice');
+      bob = privateKeyWrapper('//Bob');
+    });
+  });
+  
   it('Balance transfers and check balance', async () => {
     await usingApi(async (api, privateKeyWrapper) => {
-      const [alicesBalanceBefore, bobsBalanceBefore] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);
-
-      const alicePrivateKey = privateKeyWrapper('//Alice');
+      const [alicesBalanceBefore, bobsBalanceBefore] = await getBalance(api, [alice.address, bob.address]);
 
-      const transfer = api.tx.balances.transfer(bobsPublicKey, 1n);
-      const events = await submitTransactionAsync(alicePrivateKey, transfer);
+      const transfer = api.tx.balances.transfer(bob.address, 1n);
+      const events = await submitTransactionAsync(alice, transfer);
       const result = getCreateItemResult(events);
       // tslint:disable-next-line:no-unused-expression
       expect(result.success).to.be.true;
 
-      const [alicesBalanceAfter, bobsBalanceAfter] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);
+      const [alicesBalanceAfter, bobsBalanceAfter] = await getBalance(api, [alice.address, bob.address]);
 
       // tslint:disable-next-line:no-unused-expression
       expect(alicesBalanceAfter < alicesBalanceBefore).to.be.true;
@@ -73,7 +77,7 @@
       // Find unused address
       const pk = await findUnusedAddress(api);
 
-      const badTransfer = api.tx.balances.transfer(bobsPublicKey, 1n);
+      const badTransfer = api.tx.balances.transfer(bob.address, 1n);
       // const events = await submitTransactionAsync(pk, badTransfer);
       const badTransaction = async () => {
         const events = await submitTransactionAsync(pk, badTransfer);
@@ -87,8 +91,6 @@
 
   it('User can transfer owned token', async () => {
     await usingApi(async (api, privateKeyWrapper) => {
-      const alice = privateKeyWrapper('//Alice');
-      const bob = privateKeyWrapper('//Bob');
       // nft
       const nftCollectionId = await createCollectionExpectSuccess();
       const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
@@ -114,8 +116,6 @@
 
   it('Collection admin can transfer owned token', async () => {
     await usingApi(async (api, privateKeyWrapper) => {
-      const alice = privateKeyWrapper('//Alice');
-      const bob = privateKeyWrapper('//Bob');
       // nft
       const nftCollectionId = await createCollectionExpectSuccess();
       await addCollectionAdminExpectSuccess(alice, nftCollectionId, bob.address);
@@ -316,7 +316,6 @@
 describe('Transfers to self (potentially over substrate-evm boundary)', () => {
   itWeb3('Transfers to self. In case of same frontend', async ({api, privateKeyWrapper}) => {
     const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
-    const alice = privateKeyWrapper('//Alice');
     const aliceProxy = subToEth(alice.address);
     const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address});
     await transferExpectSuccess(collectionId, tokenId, alice, {Ethereum: aliceProxy}, 10, 'Fungible');
@@ -328,7 +327,6 @@
 
   itWeb3('Transfers to self. In case of substrate-evm boundary', async ({api, privateKeyWrapper}) => {
     const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
-    const alice = privateKeyWrapper('//Alice');
     const aliceProxy = subToEth(alice.address);
     const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address});
     const balanceAliceBefore = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId);
@@ -340,7 +338,6 @@
 
   itWeb3('Transfers to self. In case of inside substrate-evm', async ({api, privateKeyWrapper}) => {
     const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
-    const alice = privateKeyWrapper('//Alice');
     const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address});
     const balanceAliceBefore = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId);
     await transferExpectSuccess(collectionId, tokenId, alice, alice , 10, 'Fungible');
@@ -351,7 +348,6 @@
 
   itWeb3('Transfers to self. In case of inside substrate-evm when not enought "Fungibles"', async ({api, privateKeyWrapper}) => {
     const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
-    const alice = privateKeyWrapper('//Alice');
     const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address});
     const balanceAliceBefore = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId);
     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;
     });
   });