difftreelog
test(ss58Format) fix format address, remove accounts constants
in: master
6 files changed
tests/src/accounts.tsdiffbeforeafterbothno changes
tests/src/creditFeesToTreasury.test.tsdiffbeforeafterboth18import 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 });727173 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);777678 const totalBefore = (await api.query.balances.totalIssuance()).toBigInt();77 const totalBefore = (await api.query.balances.totalIssuance()).toBigInt();797880 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);838184 const result = getGenericResult(await submitTransactionAsync(alicePrivateKey, transfer));82 const result = getGenericResult(await submitTransactionAsync(alice, transfer));858386 const totalAfter = (await api.query.balances.totalIssuance()).toBigInt();84 const totalAfter = (await api.query.balances.totalIssuance()).toBigInt();878591 });89 });929093 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);979598 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();10198102 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));105102106 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;110107114 });111 });115112116 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);120117121 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();124120125 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;127123128 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;132128140 await waitNewBlocks(api, 1);136 await waitNewBlocks(api, 1);141137142 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();144140145 await createCollectionExpectSuccess();141 await createCollectionExpectSuccess();146142147 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;151147158 await skipInflationBlock(api);154 await skipInflationBlock(api);159 await waitNewBlocks(api, 1);155 await waitNewBlocks(api, 1);160156161 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();162158163 await createCollectionExpectSuccess();159 await createCollectionExpectSuccess();164160165 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;167163168 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');180176181 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();184180185 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;tests/src/substrate/substrate-api.tsdiffbeforeafterboth88 await promisifySubstrate(api, async () => {88 await promisifySubstrate(api, async () => {89 if (api) {89 if (api) {90 await api.isReadyOrError;90 await api.isReadyOrError;91 const ss58Format = (api.registry.getChainProperties())!.toHuman().ss58Format;91 const ss58Format = (api.registry.getChainProperties())!.toJSON().ss58Format;92 const privateKeyWrapper = (account: string) => privateKey(account, Number(ss58Format));92 const privateKeyWrapper = (account: string) => privateKey(account, Number(ss58Format));93 result = await action(api, privateKeyWrapper);93 result = await action(api, privateKeyWrapper);94 }94 }tests/src/transfer.test.tsdiffbeforeafterboth17import {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;484749describe('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]);5354 const alicePrivateKey = privateKeyWrapper('//Alice');555956 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-expression60 expect(result.success).to.be.true;64 expect(result.success).to.be.true;616562 const [alicesBalanceAfter, bobsBalanceAfter] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);66 const [alicesBalanceAfter, bobsBalanceAfter] = await getBalance(api, [alice.address, bob.address]);636764 // tslint:disable-next-line:no-unused-expression68 // tslint:disable-next-line:no-unused-expression65 expect(alicesBalanceAfter < alicesBalanceBefore).to.be.true;69 expect(alicesBalanceAfter < alicesBalanceBefore).to.be.true;73 // Find unused address77 // Find unused address74 const pk = await findUnusedAddress(api);78 const pk = await findUnusedAddress(api);757976 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);879188 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 // nft93 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');114116115 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 // nft120 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');328327329 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);340338341 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');351348352 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);tests/src/util/helpers.tsdiffbeforeafterboth23import BN from 'bn.js';23import BN from 'bn.js';24import chai from 'chai';24import chai from 'chai';25import chaiAsPromised from 'chai-as-promised';25import chaiAsPromised from 'chai-as-promised';26import {alicesPublicKey} from '../accounts';27import {default as usingApi, executeTransaction, submitTransactionAsync, submitTransactionExpectFailAsync} from '../substrate/substrate-api';26import {default as usingApi, executeTransaction, submitTransactionAsync, submitTransactionExpectFailAsync} from '../substrate/substrate-api';28import {hexToStr, strToUTF16, utf16ToStr} from './util';27import {hexToStr, strToUTF16, utf16ToStr} from './util';29import {UpDataStructsRpcCollection, UpDataStructsCreateItemData, UpDataStructsProperty} from '@polkadot/types/lookup';28import {UpDataStructsRpcCollection, UpDataStructsCreateItemData, UpDataStructsProperty} from '@polkadot/types/lookup';403941export function normalizeAccountId(input: string | AccountId | CrossAccountId | IKeyringPair): CrossAccountId {40export function normalizeAccountId(input: string | AccountId | CrossAccountId | IKeyringPair): CrossAccountId {42 if (typeof input === 'string') {41 if (typeof input === 'string') {43 if (input.length === 48 || input.length === 47) {42 if (input.length >= 47) {44 return {Substrate: input};43 return {Substrate: input};45 } else if (input.length === 42 && input.startsWith('0x')) {44 } else if (input.length === 42 && input.startsWith('0x')) {46 return {Ethereum: input.toLowerCase()};45 return {Ethereum: input.toLowerCase()};363 // tslint:disable-next-line:no-unused-expression362 // tslint:disable-next-line:no-unused-expression364 expect(collection).to.be.not.null;363 expect(collection).to.be.not.null;365 expect(collectionCountAfter).to.be.equal(collectionCountBefore + 1, 'Error: NFT collection NOT created.');364 expect(collectionCountAfter).to.be.equal(collectionCountBefore + 1, 'Error: NFT collection NOT created.');366 expect(collection.owner.toString()).to.be.equal(toSubstrateAddress(alicesPublicKey));365 expect(collection.owner.toString()).to.be.equal(toSubstrateAddress(alicePrivateKey));367 expect(utf16ToStr(collection.name.toJSON() as any)).to.be.equal(name);366 expect(utf16ToStr(collection.name.toJSON() as any)).to.be.equal(name);368 expect(utf16ToStr(collection.description.toJSON() as any)).to.be.equal(description);367 expect(utf16ToStr(collection.description.toJSON() as any)).to.be.equal(description);369 expect(hexToStr(collection.tokenPrefix.toJSON())).to.be.equal(tokenPrefix);368 expect(hexToStr(collection.tokenPrefix.toJSON())).to.be.equal(tokenPrefix);411 // tslint:disable-next-line:no-unused-expression410 // tslint:disable-next-line:no-unused-expression412 expect(collection).to.be.not.null;411 expect(collection).to.be.not.null;413 expect(collectionCountAfter).to.be.equal(collectionCountBefore + 1, 'Error: NFT collection NOT created.');412 expect(collectionCountAfter).to.be.equal(collectionCountBefore + 1, 'Error: NFT collection NOT created.');414 expect(collection.owner.toString()).to.be.equal(toSubstrateAddress(alicesPublicKey));413 expect(collection.owner.toString()).to.be.equal(toSubstrateAddress(alicePrivateKey));415 expect(utf16ToStr(collection.name.toJSON() as any)).to.be.equal(name);414 expect(utf16ToStr(collection.name.toJSON() as any)).to.be.equal(name);416 expect(utf16ToStr(collection.description.toJSON() as any)).to.be.equal(description);415 expect(utf16ToStr(collection.description.toJSON() as any)).to.be.equal(description);417 expect(hexToStr(collection.tokenPrefix.toJSON())).to.be.equal(tokenPrefix);416 expect(hexToStr(collection.tokenPrefix.toJSON())).to.be.equal(tokenPrefix);tests/src/xcmTransfer.test.tsdiffbeforeafterboth24import {getGenericResult} from './util/helpers';24import {getGenericResult} from './util/helpers';25import waitNewBlocks from './substrate/wait-new-blocks';25import waitNewBlocks from './substrate/wait-new-blocks';26import getBalance from './substrate/get-balance';26import getBalance from './substrate/get-balance';27import {alicesPublicKey} from './accounts';282729chai.use(chaiAsPromised);28chai.use(chaiAsPromised);30const expect = chai.expect;29const expect = chai.expect;144 let balanceBefore: bigint;143 let balanceBefore: bigint;145 144 146 await usingApi(async (api) => {145 await usingApi(async (api) => {147 [balanceBefore] = await getBalance(api, [alicesPublicKey]);146 [balanceBefore] = await getBalance(api, [alice.address]);148 });147 });149148150 await usingApi(async (api) => {149 await usingApi(async (api) => {181 await usingApi(async (api) => {180 await usingApi(async (api) => {182 // todo do something about instant sealing, where there might not be any new blocks181 // todo do something about instant sealing, where there might not be any new blocks183 await waitNewBlocks(api, 3);182 await waitNewBlocks(api, 3);184 const [balanceAfter] = await getBalance(api, [alicesPublicKey]);183 const [balanceAfter] = await getBalance(api, [alice.address]);185 expect(balanceAfter > balanceBefore).to.be.true;184 expect(balanceAfter > balanceBefore).to.be.true;186 });185 });187 });186 });