difftreelog
Merge pull request #373 from UniqueNetwork/feature/CORE-302-ss58Format
in: master
test(ss58Format): fix format address, remove accounts constants
21 files changed
tests/src/accounts.tsdiffbeforeafterbothno changes
tests/src/addToContractAllowList.test.tsdiffbeforeafterboth32 it('Add an address to a contract allow list', async () => {32 it('Add an address to a contract allow list', async () => {33 await usingApi(async (api, privateKeyWrapper) => {33 await usingApi(async (api, privateKeyWrapper) => {34 const bob = privateKeyWrapper('//Bob');34 const bob = privateKeyWrapper('//Bob');35 const [contract, deployer] = await deployFlipper(api);35 const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);363637 const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();37 const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();38 const addTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);38 const addTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);48 it('Adding same address to allow list repeatedly should not produce errors', async () => {48 it('Adding same address to allow list repeatedly should not produce errors', async () => {49 await usingApi(async (api, privateKeyWrapper) => {49 await usingApi(async (api, privateKeyWrapper) => {50 const bob = privateKeyWrapper('//Bob');50 const bob = privateKeyWrapper('//Bob');51 const [contract, deployer] = await deployFlipper(api);51 const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);525253 const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();53 const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();54 const addTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);54 const addTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);87 it('Add to a contract allow list using a non-owner address', async () => {87 it('Add to a contract allow list using a non-owner address', async () => {88 await usingApi(async (api, privateKeyWrapper) => {88 await usingApi(async (api, privateKeyWrapper) => {89 const bob = privateKeyWrapper('//Bob');89 const bob = privateKeyWrapper('//Bob');90 const [contract] = await deployFlipper(api);90 const [contract] = await deployFlipper(api, privateKeyWrapper);919192 const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();92 const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();93 const addTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);93 const addTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);tests/src/burnItem.test.tsdiffbeforeafterboth15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';17import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';18import {Keyring} from '@polkadot/api';19import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';20import {19import {21 createCollectionExpectSuccess,20 createCollectionExpectSuccess,373638describe('integration test: ext. burnItem():', () => {37describe('integration test: ext. burnItem():', () => {39 before(async () => {38 before(async () => {40 await usingApi(async () => {39 await usingApi(async (api, privateKeyWrapper) => {41 const keyring = new Keyring({type: 'sr25519'});42 alice = keyring.addFromUri('//Alice');40 alice = privateKeyWrapper('//Alice');43 bob = keyring.addFromUri('//Bob');41 bob = privateKeyWrapper('//Bob');44 });42 });45 });43 });4644142140143describe('integration test: ext. burnItem() with admin permissions:', () => {141describe('integration test: ext. burnItem() with admin permissions:', () => {144 before(async () => {142 before(async () => {145 await usingApi(async () => {143 await usingApi(async (api, privateKeyWrapper) => {146 const keyring = new Keyring({type: 'sr25519'});147 alice = keyring.addFromUri('//Alice');144 alice = privateKeyWrapper('//Alice');148 bob = keyring.addFromUri('//Bob');145 bob = privateKeyWrapper('//Bob');149 });146 });150 });147 });151148209206210describe('Negative integration test: ext. burnItem():', () => {207describe('Negative integration test: ext. burnItem():', () => {211 before(async () => {208 before(async () => {212 await usingApi(async () => {209 await usingApi(async (api, privateKeyWrapper) => {213 const keyring = new Keyring({type: 'sr25519'});214 alice = keyring.addFromUri('//Alice');210 alice = privateKeyWrapper('//Alice');215 bob = keyring.addFromUri('//Bob');211 bob = privateKeyWrapper('//Bob');216 });212 });217 });213 });218214tests/src/confirmSponsorship.test.tsdiffbeforeafterboth34 getCreatedCollectionCount,34 getCreatedCollectionCount,35 UNIQUE,35 UNIQUE,36} from './util/helpers';36} from './util/helpers';37import {Keyring} from '@polkadot/api';38import {IKeyringPair} from '@polkadot/types/types';37import {IKeyringPair} from '@polkadot/types/types';393840chai.use(chaiAsPromised);39chai.use(chaiAsPromised);47describe('integration test: ext. confirmSponsorship():', () => {46describe('integration test: ext. confirmSponsorship():', () => {484749 before(async () => {48 before(async () => {50 await usingApi(async () => {49 await usingApi(async (api, privateKeyWrapper) => {51 const keyring = new Keyring({type: 'sr25519'});52 alice = keyring.addFromUri('//Alice');50 alice = privateKeyWrapper('//Alice');53 bob = keyring.addFromUri('//Bob');51 bob = privateKeyWrapper('//Bob');54 charlie = keyring.addFromUri('//Charlie');52 charlie = privateKeyWrapper('//Charlie');55 });53 });56 });54 });575578 await setCollectionSponsorExpectSuccess(collectionId, bob.address);76 await setCollectionSponsorExpectSuccess(collectionId, bob.address);79 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');77 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');807881 await usingApi(async (api) => {79 await usingApi(async (api, privateKeyWrapper) => {82 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();80 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();838184 // Find unused address82 // Find unused address85 const zeroBalance = await findUnusedAddress(api);83 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);868487 // Mint token for unused address85 // Mint token for unused address88 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);86 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);105 await setCollectionSponsorExpectSuccess(collectionId, bob.address);103 await setCollectionSponsorExpectSuccess(collectionId, bob.address);106 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');104 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');107105108 await usingApi(async (api) => {106 await usingApi(async (api, privateKeyWrapper) => {109 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();107 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();110108111 // Find unused address109 // Find unused address112 const zeroBalance = await findUnusedAddress(api);110 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);113111114 // Mint token for unused address112 // Mint token for unused address115 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', zeroBalance.address);113 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', zeroBalance.address);131 await setCollectionSponsorExpectSuccess(collectionId, bob.address);129 await setCollectionSponsorExpectSuccess(collectionId, bob.address);132 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');130 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');133131134 await usingApi(async (api) => {132 await usingApi(async (api, privateKeyWrapper) => {135 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();133 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();136134137 // Find unused address135 // Find unused address138 const zeroBalance = await findUnusedAddress(api);136 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);139137140 // Mint token for unused address138 // Mint token for unused address141 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', zeroBalance.address);139 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', zeroBalance.address);164 await enablePublicMintingExpectSuccess(alice, collectionId);162 await enablePublicMintingExpectSuccess(alice, collectionId);165163166 // Create Item164 // Create Item167 await usingApi(async (api) => {165 await usingApi(async (api, privateKeyWrapper) => {168 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();166 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();169167170 // Find unused address168 // Find unused address171 const zeroBalance = await findUnusedAddress(api);169 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);172170173 // Add zeroBalance address to allow list171 // Add zeroBalance address to allow list174 await addToAllowListExpectSuccess(alice, collectionId, zeroBalance.address);172 await addToAllowListExpectSuccess(alice, collectionId, zeroBalance.address);187 await setCollectionSponsorExpectSuccess(collectionId, bob.address);185 await setCollectionSponsorExpectSuccess(collectionId, bob.address);188 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');186 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');189187190 await usingApi(async (api) => {188 await usingApi(async (api, privateKeyWrapper) => {191 // Find unused address189 // Find unused address192 const zeroBalance = await findUnusedAddress(api);190 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);193191194 // Mint token for alice192 // Mint token for alice195 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);193 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);226 await setCollectionSponsorExpectSuccess(collectionId, bob.address);224 await setCollectionSponsorExpectSuccess(collectionId, bob.address);227 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');225 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');228226229 await usingApi(async (api) => {227 await usingApi(async (api, privateKeyWrapper) => {230 // Find unused address228 // Find unused address231 const zeroBalance = await findUnusedAddress(api);229 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);232230233 // Mint token for unused address231 // Mint token for unused address234 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', zeroBalance.address);232 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', zeroBalance.address);259 await setCollectionSponsorExpectSuccess(collectionId, bob.address);257 await setCollectionSponsorExpectSuccess(collectionId, bob.address);260 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');258 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');261259262 await usingApi(async (api) => {260 await usingApi(async (api, privateKeyWrapper) => {263 // Find unused address261 // Find unused address264 const zeroBalance = await findUnusedAddress(api);262 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);265263266 // Mint token for alice264 // Mint token for alice267 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', zeroBalance.address);265 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', zeroBalance.address);299 // Enable public minting297 // Enable public minting300 await enablePublicMintingExpectSuccess(alice, collectionId);298 await enablePublicMintingExpectSuccess(alice, collectionId);301299302 await usingApi(async (api) => {300 await usingApi(async (api, privateKeyWrapper) => {303 // Find unused address301 // Find unused address304 const zeroBalance = await findUnusedAddress(api);302 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);305303306 // Add zeroBalance address to allow list304 // Add zeroBalance address to allow list307 await addToAllowListExpectSuccess(alice, collectionId, zeroBalance.address);305 await addToAllowListExpectSuccess(alice, collectionId, zeroBalance.address);331329332describe('(!negative test!) integration test: ext. confirmSponsorship():', () => {330describe('(!negative test!) integration test: ext. confirmSponsorship():', () => {333 before(async () => {331 before(async () => {334 await usingApi(async () => {332 await usingApi(async (api, privateKeyWrapper) => {335 const keyring = new Keyring({type: 'sr25519'});336 alice = keyring.addFromUri('//Alice');333 alice = privateKeyWrapper('//Alice');337 bob = keyring.addFromUri('//Bob');334 bob = privateKeyWrapper('//Bob');338 charlie = keyring.addFromUri('//Charlie');335 charlie = privateKeyWrapper('//Charlie');339 });336 });340 });337 });341338390 await setCollectionSponsorExpectSuccess(collectionId, bob.address);387 await setCollectionSponsorExpectSuccess(collectionId, bob.address);391 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');388 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');392389393 await usingApi(async (api) => {390 await usingApi(async (api, privateKeyWrapper) => {394 // Find unused address391 // Find unused address395 const ownerZeroBalance = await findUnusedAddress(api);392 const ownerZeroBalance = await findUnusedAddress(api, privateKeyWrapper);396393397 // Find another unused address394 // Find another unused address398 const senderZeroBalance = await findUnusedAddress(api);395 const senderZeroBalance = await findUnusedAddress(api, privateKeyWrapper);399396400 // Mint token for an unused address397 // Mint token for an unused address401 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', ownerZeroBalance.address);398 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', ownerZeroBalance.address);tests/src/contracts.test.tsdiffbeforeafterboth50describe.skip('Contracts', () => {50describe.skip('Contracts', () => {51 it('Can deploy smart contract Flipper, instantiate it and call it\'s get and flip messages.', async () => {51 it('Can deploy smart contract Flipper, instantiate it and call it\'s get and flip messages.', async () => {52 await usingApi(async (api, privateKeyWrapper) => {52 await usingApi(async (api, privateKeyWrapper) => {53 const [contract, deployer] = await deployFlipper(api);53 const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);54 const initialGetResponse = await getFlipValue(contract, deployer);54 const initialGetResponse = await getFlipValue(contract, deployer);555556 const bob = privateKeyWrapper('//Bob');56 const bob = privateKeyWrapper('//Bob');82 // Prep work82 // Prep work83 const collectionId = await createCollectionExpectSuccess();83 const collectionId = await createCollectionExpectSuccess();84 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');84 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');85 const [contract] = await deployTransferContract(api);85 const [contract] = await deployTransferContract(api, privateKeyWrapper);86 const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, contract.address);86 const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, contract.address);87 await submitTransactionAsync(alice, changeAdminTx);87 await submitTransactionAsync(alice, changeAdminTx);8888104 const bob = privateKeyWrapper('//Bob');104 const bob = privateKeyWrapper('//Bob');105105106 const collectionId = await createCollectionExpectSuccess();106 const collectionId = await createCollectionExpectSuccess();107 const [contract] = await deployTransferContract(api);107 const [contract] = await deployTransferContract(api, privateKeyWrapper);108 await enablePublicMintingExpectSuccess(alice, collectionId);108 await enablePublicMintingExpectSuccess(alice, collectionId);109 await enableAllowListExpectSuccess(alice, collectionId);109 await enableAllowListExpectSuccess(alice, collectionId);110 await addToAllowListExpectSuccess(alice, collectionId, contract.address);110 await addToAllowListExpectSuccess(alice, collectionId, contract.address);131 const bob = privateKeyWrapper('//Bob');131 const bob = privateKeyWrapper('//Bob');132132133 const collectionId = await createCollectionExpectSuccess();133 const collectionId = await createCollectionExpectSuccess();134 const [contract] = await deployTransferContract(api);134 const [contract] = await deployTransferContract(api, privateKeyWrapper);135 await enablePublicMintingExpectSuccess(alice, collectionId);135 await enablePublicMintingExpectSuccess(alice, collectionId);136 await enableAllowListExpectSuccess(alice, collectionId);136 await enableAllowListExpectSuccess(alice, collectionId);137 await addToAllowListExpectSuccess(alice, collectionId, contract.address);137 await addToAllowListExpectSuccess(alice, collectionId, contract.address);173 const charlie = privateKeyWrapper('//Charlie');173 const charlie = privateKeyWrapper('//Charlie');174174175 const collectionId = await createCollectionExpectSuccess();175 const collectionId = await createCollectionExpectSuccess();176 const [contract] = await deployTransferContract(api);176 const [contract] = await deployTransferContract(api, privateKeyWrapper);177 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', contract.address.toString());177 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', contract.address.toString());178178179 const transferTx = contract.tx.approve(value, gasLimit, bob.address, collectionId, tokenId, 1);179 const transferTx = contract.tx.approve(value, gasLimit, bob.address, collectionId, tokenId, 1);192 const charlie = privateKeyWrapper('//Charlie');192 const charlie = privateKeyWrapper('//Charlie');193193194 const collectionId = await createCollectionExpectSuccess();194 const collectionId = await createCollectionExpectSuccess();195 const [contract] = await deployTransferContract(api);195 const [contract] = await deployTransferContract(api, privateKeyWrapper);196 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);196 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);197 await approveExpectSuccess(collectionId, tokenId, bob, contract.address.toString(), 1);197 await approveExpectSuccess(collectionId, tokenId, bob, contract.address.toString(), 1);198198212 const bob = privateKeyWrapper('//Bob');212 const bob = privateKeyWrapper('//Bob');213213214 const collectionId = await createCollectionExpectSuccess();214 const collectionId = await createCollectionExpectSuccess();215 const [contract] = await deployTransferContract(api);215 const [contract] = await deployTransferContract(api, privateKeyWrapper);216 const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, contract.address);216 const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, contract.address);217 await submitTransactionAsync(alice, changeAdminTx);217 await submitTransactionAsync(alice, changeAdminTx);218218tests/src/createItem.test.tsdiffbeforeafterboth161617import {default as usingApi} from './substrate/substrate-api';17import {default as usingApi} from './substrate/substrate-api';18import chai from 'chai';18import chai from 'chai';19import {Keyring} from '@polkadot/api';20import {IKeyringPair} from '@polkadot/types/types';19import {IKeyringPair} from '@polkadot/types/types';21import {20import {22 createCollectionExpectSuccess,21 createCollectionExpectSuccess,333234describe('integration test: ext. ():', () => {33describe('integration test: ext. ():', () => {35 before(async () => {34 before(async () => {36 await usingApi(async () => {35 await usingApi(async (api, privateKeyWrapper) => {37 const keyring = new Keyring({type: 'sr25519'});38 alice = keyring.addFromUri('//Alice');36 alice = privateKeyWrapper('//Alice');39 bob = keyring.addFromUri('//Bob');37 bob = privateKeyWrapper('//Bob');40 });38 });41 });39 });424010199102describe('Negative integration test: ext. createItem():', () => {100describe('Negative integration test: ext. createItem():', () => {103 before(async () => {101 before(async () => {104 await usingApi(async () => {102 await usingApi(async (api, privateKeyWrapper) => {105 const keyring = new Keyring({type: 'sr25519'});106 alice = keyring.addFromUri('//Alice');103 alice = privateKeyWrapper('//Alice');107 bob = keyring.addFromUri('//Bob');104 bob = privateKeyWrapper('//Bob');108 });105 });109 });106 });110107tests/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/enableContractSponsoring.test.tsdiffbeforeafterboth313132describe.skip('Integration Test enableContractSponsoring', () => {32describe.skip('Integration Test enableContractSponsoring', () => {33 it('ensure tx fee is paid from endowment', async () => {33 it('ensure tx fee is paid from endowment', async () => {34 await usingApi(async (api) => {34 await usingApi(async (api, privateKeyWrapper) => {35 const user = await findUnusedAddress(api);35 const user = await findUnusedAddress(api, privateKeyWrapper);363637 const [flipper, deployer] = await deployFlipper(api);37 const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);38 await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);38 await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);39 await setContractSponsoringRateLimitExpectSuccess(deployer, flipper.address, 1);39 await setContractSponsoringRateLimitExpectSuccess(deployer, flipper.address, 1);40 await toggleFlipValueExpectSuccess(user, flipper);40 await toggleFlipValueExpectSuccess(user, flipper);44 });44 });454546 it('ensure it can be enabled twice', async () => {46 it('ensure it can be enabled twice', async () => {47 await usingApi(async (api) => {47 await usingApi(async (api, privateKeyWrapper) => {48 const [flipper, deployer] = await deployFlipper(api);48 const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);494950 await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);50 await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);51 await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);51 await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);52 });52 });53 });53 });545455 it('ensure it can be disabled twice', async () => {55 it('ensure it can be disabled twice', async () => {56 await usingApi(async (api) => {56 await usingApi(async (api, privateKeyWrapper) => {57 const [flipper, deployer] = await deployFlipper(api);57 const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);585859 await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);59 await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);60 await enableContractSponsoringExpectSuccess(deployer, flipper.address, false);60 await enableContractSponsoringExpectSuccess(deployer, flipper.address, false);63 });63 });646465 it('ensure it can be re-enabled', async () => {65 it('ensure it can be re-enabled', async () => {66 await usingApi(async (api) => {66 await usingApi(async (api, privateKeyWrapper) => {67 const [flipper, deployer] = await deployFlipper(api);67 const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);686869 await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);69 await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);70 await enableContractSponsoringExpectSuccess(deployer, flipper.address, false);70 await enableContractSponsoringExpectSuccess(deployer, flipper.address, false);84 });84 });858586 it('fails when called for non-contract address', async () => {86 it('fails when called for non-contract address', async () => {87 await usingApi(async (api) => {87 await usingApi(async (api, privateKeyWrapper) => {88 const user = await findUnusedAddress(api);88 const user = await findUnusedAddress(api, privateKeyWrapper);898990 await enableContractSponsoringExpectFailure(alice, user.address, true);90 await enableContractSponsoringExpectFailure(alice, user.address, true);91 });91 });92 });92 });939394 it('fails when called by non-owning user', async () => {94 it('fails when called by non-owning user', async () => {95 await usingApi(async (api) => {95 await usingApi(async (api, privateKeyWrapper) => {96 const [flipper] = await deployFlipper(api);96 const [flipper] = await deployFlipper(api, privateKeyWrapper);979798 await enableContractSponsoringExpectFailure(alice, flipper.address, true);98 await enableContractSponsoringExpectFailure(alice, flipper.address, true);99 });99 });tests/src/removeCollectionSponsor.test.tsdiffbeforeafterboth31 addCollectionAdminExpectSuccess,31 addCollectionAdminExpectSuccess,32 getCreatedCollectionCount,32 getCreatedCollectionCount,33} from './util/helpers';33} from './util/helpers';34import {Keyring} from '@polkadot/api';35import {IKeyringPair} from '@polkadot/types/types';34import {IKeyringPair} from '@polkadot/types/types';363537chai.use(chaiAsPromised);36chai.use(chaiAsPromised);43describe('integration test: ext. removeCollectionSponsor():', () => {42describe('integration test: ext. removeCollectionSponsor():', () => {444345 before(async () => {44 before(async () => {46 await usingApi(async () => {45 await usingApi(async (api, privateKeyWrapper) => {47 const keyring = new Keyring({type: 'sr25519'});48 alice = keyring.addFromUri('//Alice');46 alice = privateKeyWrapper('//Alice');49 bob = keyring.addFromUri('//Bob');47 bob = privateKeyWrapper('//Bob');50 });48 });51 });49 });525056 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');54 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');57 await removeCollectionSponsorExpectSuccess(collectionId);55 await removeCollectionSponsorExpectSuccess(collectionId);585659 await usingApi(async (api) => {57 await usingApi(async (api, privateKeyWrapper) => {60 // Find unused address58 // Find unused address61 const zeroBalance = await findUnusedAddress(api);59 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);626063 // Mint token for unused address61 // Mint token for unused address64 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);62 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);9997100describe('(!negative test!) integration test: ext. removeCollectionSponsor():', () => {98describe('(!negative test!) integration test: ext. removeCollectionSponsor():', () => {101 before(async () => {99 before(async () => {102 await usingApi(async () => {100 await usingApi(async (api, privateKeyWrapper) => {103 const keyring = new Keyring({type: 'sr25519'});104 alice = keyring.addFromUri('//Alice');101 alice = privateKeyWrapper('//Alice');105 bob = keyring.addFromUri('//Bob');102 bob = privateKeyWrapper('//Bob');106 });103 });107 });104 });108105tests/src/removeFromContractAllowList.test.tsdiffbeforeafterboth30 });30 });313132 it('user is no longer allowlisted after removal', async () => {32 it('user is no longer allowlisted after removal', async () => {33 await usingApi(async (api) => {33 await usingApi(async (api, privateKeyWrapper) => {34 const [flipper, deployer] = await deployFlipper(api);34 const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);353536 await addToContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);36 await addToContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);37 await removeFromContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);37 await removeFromContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);41 });41 });424243 it('user can\'t execute contract after removal', async () => {43 it('user can\'t execute contract after removal', async () => {44 await usingApi(async (api) => {44 await usingApi(async (api, privateKeyWrapper) => {45 const [flipper, deployer] = await deployFlipper(api);45 const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);46 await toggleContractAllowlistExpectSuccess(deployer, flipper.address.toString(), true);46 await toggleContractAllowlistExpectSuccess(deployer, flipper.address.toString(), true);474748 await addToContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);48 await addToContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);54 });54 });555556 it('can be called twice', async () => {56 it('can be called twice', async () => {57 await usingApi(async (api) => {57 await usingApi(async (api, privateKeyWrapper) => {58 const [flipper, deployer] = await deployFlipper(api);58 const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);595960 await addToContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);60 await addToContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);61 await removeFromContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);61 await removeFromContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);82 });82 });838384 it('fails when executed by non owner', async () => {84 it('fails when executed by non owner', async () => {85 await usingApi(async (api) => {85 await usingApi(async (api, privateKeyWrapper) => {86 const [flipper] = await deployFlipper(api);86 const [flipper] = await deployFlipper(api, privateKeyWrapper);878788 await removeFromContractAllowListExpectFailure(alice, flipper.address.toString(), bob.address);88 await removeFromContractAllowListExpectFailure(alice, flipper.address.toString(), bob.address);89 });89 });tests/src/rpc.load.tsdiffbeforeafterboth54 });54 });55}55}565657async function prepareDeployer(api: ApiPromise) {57async function prepareDeployer(api: ApiPromise, privateKeyWrapper: ((account: string) => IKeyringPair)) {58 // Find unused address58 // Find unused address59 const deployer = await findUnusedAddress(api);59 const deployer = await findUnusedAddress(api, privateKeyWrapper);606061 // Transfer balance to it61 // Transfer balance to it62 const keyring = new Keyring({type: 'sr25519'});62 const keyring = new Keyring({type: 'sr25519'});68 return deployer;68 return deployer;69}69}707071async function deployLoadTester(api: ApiPromise): Promise<[Contract, IKeyringPair]> {71async function deployLoadTester(api: ApiPromise, privateKeyWrapper: ((account: string) => IKeyringPair)): Promise<[Contract, IKeyringPair]> {72 const metadata = JSON.parse(fs.readFileSync('./src/load_test_sc/metadata.json').toString('utf-8'));72 const metadata = JSON.parse(fs.readFileSync('./src/load_test_sc/metadata.json').toString('utf-8'));73 const abi = new Abi(metadata);73 const abi = new Abi(metadata);747475 const deployer = await prepareDeployer(api);75 const deployer = await prepareDeployer(api, privateKeyWrapper);767677 const wasm = fs.readFileSync('./src/load_test_sc/loadtester.wasm');77 const wasm = fs.readFileSync('./src/load_test_sc/loadtester.wasm');7878123 await usingApi(async (api, privateKeyWrapper) => {123 await usingApi(async (api, privateKeyWrapper) => {124124125 // Deploy smart contract125 // Deploy smart contract126 const [contract, deployer] = await deployLoadTester(api);126 const [contract, deployer] = await deployLoadTester(api, privateKeyWrapper);127127128 // Fill smart contract up with data128 // Fill smart contract up with data129 const bob = privateKeyWrapper('//Bob');129 const bob = privateKeyWrapper('//Bob');tests/src/scheduler.test.tsdiffbeforeafterboth116 });116 });117117118 it('Schedules and dispatches a transaction even if the caller has no funds at the time of the dispatch', async () => {118 it('Schedules and dispatches a transaction even if the caller has no funds at the time of the dispatch', async () => {119 await usingApi(async (api) => {119 await usingApi(async (api, privateKeyWrapper) => {120 // Find an empty, unused account120 // Find an empty, unused account121 const zeroBalance = await findUnusedAddress(api);121 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);122122123 const collectionId = await createCollectionExpectSuccess();123 const collectionId = await createCollectionExpectSuccess();124124156 it('Sponsor going bankrupt does not impact a scheduled transaction', async () => {156 it('Sponsor going bankrupt does not impact a scheduled transaction', async () => {157 const collectionId = await createCollectionExpectSuccess();157 const collectionId = await createCollectionExpectSuccess();158158159 await usingApi(async (api) => {159 await usingApi(async (api, privateKeyWrapper) => {160 const zeroBalance = await findUnusedAddress(api);160 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);161 const balanceTx = api.tx.balances.transfer(zeroBalance.address, 1n * UNIQUE);161 const balanceTx = api.tx.balances.transfer(zeroBalance.address, 1n * UNIQUE);162 await submitTransactionAsync(alice, balanceTx);162 await submitTransactionAsync(alice, balanceTx);163163186 await setCollectionSponsorExpectSuccess(collectionId, bob.address);186 await setCollectionSponsorExpectSuccess(collectionId, bob.address);187 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');187 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');188188189 await usingApi(async (api) => {189 await usingApi(async (api, privateKeyWrapper) => {190 const zeroBalance = await findUnusedAddress(api);190 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);191191192 await enablePublicMintingExpectSuccess(alice, collectionId);192 await enablePublicMintingExpectSuccess(alice, collectionId);193 await addToAllowListExpectSuccess(alice, collectionId, zeroBalance.address);193 await addToAllowListExpectSuccess(alice, collectionId, zeroBalance.address);tests/src/setCollectionLimits.test.tsdiffbeforeafterboth15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits17// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits18import {ApiPromise, Keyring} from '@polkadot/api';18import {ApiPromise} from '@polkadot/api';19import {IKeyringPair} from '@polkadot/types/types';19import {IKeyringPair} from '@polkadot/types/types';20import chai from 'chai';20import chai from 'chai';21import chaiAsPromised from 'chai-as-promised';21import chaiAsPromised from 'chai-as-promised';44describe('setCollectionLimits positive', () => {44describe('setCollectionLimits positive', () => {45 let tx;45 let tx;46 before(async () => {46 before(async () => {47 await usingApi(async () => {47 await usingApi(async (api, privateKeyWrapper) => {48 const keyring = new Keyring({type: 'sr25519'});49 alice = keyring.addFromUri('//Alice');48 alice = privateKeyWrapper('//Alice');50 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});49 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});51 });50 });52 });51 });121describe('setCollectionLimits negative', () => {120describe('setCollectionLimits negative', () => {122 let tx;121 let tx;123 before(async () => {122 before(async () => {124 await usingApi(async () => {123 await usingApi(async (api, privateKeyWrapper) => {125 const keyring = new Keyring({type: 'sr25519'});126 alice = keyring.addFromUri('//Alice');124 alice = privateKeyWrapper('//Alice');127 bob = keyring.addFromUri('//Bob');125 bob = privateKeyWrapper('//Bob');128 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});126 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});129 });127 });130 });128 });tests/src/setCollectionSponsor.test.tsdiffbeforeafterboth24 addCollectionAdminExpectSuccess,24 addCollectionAdminExpectSuccess,25 getCreatedCollectionCount,25 getCreatedCollectionCount,26} from './util/helpers';26} from './util/helpers';27import {Keyring} from '@polkadot/api';28import {IKeyringPair} from '@polkadot/types/types';27import {IKeyringPair} from '@polkadot/types/types';292830chai.use(chaiAsPromised);29chai.use(chaiAsPromised);36describe('integration test: ext. setCollectionSponsor():', () => {35describe('integration test: ext. setCollectionSponsor():', () => {373638 before(async () => {37 before(async () => {39 await usingApi(async () => {38 await usingApi(async (api, privateKeyWrapper) => {40 const keyring = new Keyring({type: 'sr25519'});39 alice = privateKeyWrapper('//Alice');41 alice = keyring.addFromUri('//Alice');40 bob = privateKeyWrapper('//Bob');42 bob = keyring.addFromUri('//Bob');41 charlie = privateKeyWrapper('//Charlie');43 });42 });44 });43 });454464 it('Replace collection sponsor', async () => {63 it('Replace collection sponsor', async () => {65 const collectionId = await createCollectionExpectSuccess();64 const collectionId = await createCollectionExpectSuccess();6667 const keyring = new Keyring({type: 'sr25519'});68 const charlie = keyring.addFromUri('//Charlie');69 await setCollectionSponsorExpectSuccess(collectionId, bob.address);65 await setCollectionSponsorExpectSuccess(collectionId, bob.address);70 await setCollectionSponsorExpectSuccess(collectionId, charlie.address);66 await setCollectionSponsorExpectSuccess(collectionId, charlie.address);71 });67 });72});68});736974describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {70describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {75 before(async () => {71 before(async () => {76 await usingApi(async () => {72 await usingApi(async (api, privateKeyWrapper) => {77 const keyring = new Keyring({type: 'sr25519'});78 alice = keyring.addFromUri('//Alice');73 alice = privateKeyWrapper('//Alice');79 bob = keyring.addFromUri('//Bob');74 bob = privateKeyWrapper('//Bob');80 charlie = keyring.addFromUri('//Charlie');75 charlie = privateKeyWrapper('//Charlie');81 });76 });82 });77 });8378tests/src/setContractSponsoringRateLimit.test.tsdiffbeforeafterboth272728describe.skip('Integration Test setContractSponsoringRateLimit', () => {28describe.skip('Integration Test setContractSponsoringRateLimit', () => {29 it('ensure sponsored contract can\'t be called twice without pause for free', async () => {29 it('ensure sponsored contract can\'t be called twice without pause for free', async () => {30 await usingApi(async (api) => {30 await usingApi(async (api, privateKeyWrapper) => {31 const user = await findUnusedAddress(api);31 const user = await findUnusedAddress(api, privateKeyWrapper);323233 const [flipper, deployer] = await deployFlipper(api);33 const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);34 await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);34 await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);35 await setContractSponsoringRateLimitExpectSuccess(deployer, flipper.address, 10);35 await setContractSponsoringRateLimitExpectSuccess(deployer, flipper.address, 10);36 await toggleFlipValueExpectSuccess(user, flipper);36 await toggleFlipValueExpectSuccess(user, flipper);39 });39 });404041 it('ensure sponsored contract can be called twice with pause for free', async () => {41 it('ensure sponsored contract can be called twice with pause for free', async () => {42 await usingApi(async (api) => {42 await usingApi(async (api, privateKeyWrapper) => {43 const user = await findUnusedAddress(api);43 const user = await findUnusedAddress(api, privateKeyWrapper);444445 const [flipper, deployer] = await deployFlipper(api);45 const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);46 await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);46 await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);47 await setContractSponsoringRateLimitExpectSuccess(deployer, flipper.address, 1);47 await setContractSponsoringRateLimitExpectSuccess(deployer, flipper.address, 1);48 await toggleFlipValueExpectSuccess(user, flipper);48 await toggleFlipValueExpectSuccess(user, flipper);62 });62 });636364 it('fails when called for non-contract address', async () => {64 it('fails when called for non-contract address', async () => {65 await usingApi(async (api) => {65 await usingApi(async (api, privateKeyWrapper) => {66 const user = await findUnusedAddress(api);66 const user = await findUnusedAddress(api, privateKeyWrapper);676768 await setContractSponsoringRateLimitExpectFailure(alice, user.address, 1);68 await setContractSponsoringRateLimitExpectFailure(alice, user.address, 1);69 });69 });70 });70 });717172 it('fails when called by non-owning user', async () => {72 it('fails when called by non-owning user', async () => {73 await usingApi(async (api) => {73 await usingApi(async (api, privateKeyWrapper) => {74 const [flipper] = await deployFlipper(api);74 const [flipper] = await deployFlipper(api, privateKeyWrapper);757576 await setContractSponsoringRateLimitExpectFailure(alice, flipper.address, 1);76 await setContractSponsoringRateLimitExpectFailure(alice, flipper.address, 1);77 });77 });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/toggleContractAllowList.test.tsdiffbeforeafterboth34describe.skip('Integration Test toggleContractAllowList', () => {34describe.skip('Integration Test toggleContractAllowList', () => {353536 it('Enable allow list contract mode', async () => {36 it('Enable allow list contract mode', async () => {37 await usingApi(async api => {37 await usingApi(async (api, privateKeyWrapper) => {38 const [contract, deployer] = await deployFlipper(api);38 const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);393940 const enabledBefore = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();40 const enabledBefore = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();41 const enableAllowListTx = api.tx.unique.toggleContractAllowList(contract.address, true);41 const enableAllowListTx = api.tx.unique.toggleContractAllowList(contract.address, true);52 await usingApi(async (api, privateKeyWrapper) => {52 await usingApi(async (api, privateKeyWrapper) => {53 const bob = privateKeyWrapper('//Bob');53 const bob = privateKeyWrapper('//Bob');545455 const [contract, deployer] = await deployFlipper(api);55 const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);565657 let flipValueBefore = await getFlipValue(contract, deployer);57 let flipValueBefore = await getFlipValue(contract, deployer);58 const flip = contract.tx.flip(value, gasLimit);58 const flip = contract.tx.flip(value, gasLimit);111 });111 });112112113 it('Enabling allow list repeatedly should not produce errors', async () => {113 it('Enabling allow list repeatedly should not produce errors', async () => {114 await usingApi(async api => {114 await usingApi(async (api, privateKeyWrapper) => {115 const [contract, deployer] = await deployFlipper(api);115 const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);116116117 const enabledBefore = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();117 const enabledBefore = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();118 const enableAllowListTx = api.tx.unique.toggleContractAllowList(contract.address, true);118 const enableAllowListTx = api.tx.unique.toggleContractAllowList(contract.address, true);151 it('Enable allow list using a non-owner address', async () => {151 it('Enable allow list using a non-owner address', async () => {152 await usingApi(async (api, privateKeyWrapper) => {152 await usingApi(async (api, privateKeyWrapper) => {153 const bob = privateKeyWrapper('//Bob');153 const bob = privateKeyWrapper('//Bob');154 const [contract] = await deployFlipper(api);154 const [contract] = await deployFlipper(api, privateKeyWrapper);155155156 const enabledBefore = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();156 const enabledBefore = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();157 const enableAllowListTx = api.tx.unique.toggleContractAllowList(contract.address, true);157 const enableAllowListTx = api.tx.unique.toggleContractAllowList(contract.address, true);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;69 });73 });707471 it('Inability to pay fees error message is correct', async () => {75 it('Inability to pay fees error message is correct', async () => {72 await usingApi(async (api) => {76 await usingApi(async (api, privateKeyWrapper) => {73 // Find unused address77 // Find unused address74 const pk = await findUnusedAddress(api);78 const pk = await findUnusedAddress(api, privateKeyWrapper);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/contracthelpers.tsdiffbeforeafterboth20import fs from 'fs';20import fs from 'fs';21import {Abi, CodePromise, ContractPromise as Contract} from '@polkadot/api-contract';21import {Abi, CodePromise, ContractPromise as Contract} from '@polkadot/api-contract';22import {IKeyringPair} from '@polkadot/types/types';22import {IKeyringPair} from '@polkadot/types/types';23import {ApiPromise, Keyring} from '@polkadot/api';23import {ApiPromise} from '@polkadot/api';242425chai.use(chaiAsPromised);25chai.use(chaiAsPromised);26const expect = chai.expect;26const expect = chai.expect;45 });45 });46}46}474748async function prepareDeployer(api: ApiPromise) {48async function prepareDeployer(api: ApiPromise, privateKeyWrapper: (account: string) => IKeyringPair) {49 // Find unused address49 // Find unused address50 const deployer = await findUnusedAddress(api);50 const deployer = await findUnusedAddress(api, privateKeyWrapper);515152 // Transfer balance to it52 // Transfer balance to it53 const keyring = new Keyring({type: 'sr25519'});54 const alice = keyring.addFromUri('//Alice');53 const alice = privateKeyWrapper('//Alice');55 const amount = BigInt(endowment) + 10n**15n;54 const amount = BigInt(endowment) + 10n**15n;56 const tx = api.tx.balances.transfer(deployer.address, amount);55 const tx = api.tx.balances.transfer(deployer.address, amount);57 await submitTransactionAsync(alice, tx);56 await submitTransactionAsync(alice, tx);585759 return deployer;58 return deployer;60}59}616062export async function deployFlipper(api: ApiPromise): Promise<[Contract, IKeyringPair]> {61export async function deployFlipper(api: ApiPromise, privateKeyWrapper: (account: string) => IKeyringPair): Promise<[Contract, IKeyringPair]> {63 const metadata = JSON.parse(fs.readFileSync('./src/flipper/metadata.json').toString('utf-8'));62 const metadata = JSON.parse(fs.readFileSync('./src/flipper/metadata.json').toString('utf-8'));64 const abi = new Abi(metadata);63 const abi = new Abi(metadata);656466 const deployer = await prepareDeployer(api);65 const deployer = await prepareDeployer(api, privateKeyWrapper);676668 const wasm = fs.readFileSync('./src/flipper/flipper.wasm');67 const wasm = fs.readFileSync('./src/flipper/flipper.wasm');696899 await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;98 await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;100}99}101100102export async function deployTransferContract(api: ApiPromise): Promise<[Contract, IKeyringPair]> {101export async function deployTransferContract(api: ApiPromise, privateKeyWrapper: (account: string) => IKeyringPair): Promise<[Contract, IKeyringPair]> {103 const metadata = JSON.parse(fs.readFileSync('./src/transfer_contract/metadata.json').toString('utf-8'));102 const metadata = JSON.parse(fs.readFileSync('./src/transfer_contract/metadata.json').toString('utf-8'));104 const abi = new Abi(metadata);103 const abi = new Abi(metadata);105104106 const deployer = await prepareDeployer(api);105 const deployer = await prepareDeployer(api, privateKeyWrapper);107106108 const wasm = fs.readFileSync('./src/transfer_contract/nft_transfer.wasm');107 const wasm = fs.readFileSync('./src/transfer_contract/nft_transfer.wasm');109108tests/src/util/helpers.tsdiffbeforeafterboth161617import '../interfaces/augment-api-rpc';17import '../interfaces/augment-api-rpc';18import '../interfaces/augment-api-query';18import '../interfaces/augment-api-query';19import {ApiPromise, Keyring} from '@polkadot/api';19import {ApiPromise} from '@polkadot/api';20import type {AccountId, EventRecord, Event} from '@polkadot/types/interfaces';20import type {AccountId, EventRecord, Event} from '@polkadot/types/interfaces';21import {AnyTuple, IEvent, IKeyringPair} from '@polkadot/types/types';21import {AnyTuple, IEvent, IKeyringPair} from '@polkadot/types/types';22import {evmToAddress} from '@polkadot/util-crypto';22import {evmToAddress} from '@polkadot/util-crypto';23import 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);482 });481 });483}482}484483485export async function findUnusedAddress(api: ApiPromise, seedAddition = ''): Promise<IKeyringPair> {484export async function findUnusedAddress(api: ApiPromise, privateKeyWrapper: (account: string) => IKeyringPair, seedAddition = ''): Promise<IKeyringPair> {486 let bal = 0n;485 let bal = 0n;487 let unused;486 let unused;488 do {487 do {489 const randomSeed = 'seed' + Math.floor(Math.random() * Math.floor(10000)) + seedAddition;488 const randomSeed = 'seed' + Math.floor(Math.random() * Math.floor(10000)) + seedAddition;490 const keyring = new Keyring({type: 'sr25519'});491 unused = keyring.addFromUri(`//${randomSeed}`);489 unused = privateKeyWrapper(`//${randomSeed}`);492 bal = (await api.query.system.account(unused.address)).data.free.toBigInt();490 bal = (await api.query.system.account(unused.address)).data.free.toBigInt();493 } while (bal !== 0n);491 } while (bal !== 0n);494 return unused;492 return unused;498 return (await api.rpc.unique.allowance(collectionId, normalizeAccountId(owner), normalizeAccountId(approved), tokenId)).toBigInt();496 return (await api.rpc.unique.allowance(collectionId, normalizeAccountId(owner), normalizeAccountId(approved), tokenId)).toBigInt();499}497}500498501export function findUnusedAddresses(api: ApiPromise, amount: number): Promise<IKeyringPair[]> {499export function findUnusedAddresses(api: ApiPromise, privateKeyWrapper: (account: string) => IKeyringPair, amount: number): Promise<IKeyringPair[]> {502 return Promise.all(new Array(amount).fill(null).map(() => findUnusedAddress(api, '_' + Date.now())));500 return Promise.all(new Array(amount).fill(null).map(() => findUnusedAddress(api, privateKeyWrapper, '_' + Date.now())));503}501}504502505export async function findNotExistingCollection(api: ApiPromise): Promise<number> {503export async function findNotExistingCollection(api: ApiPromise): Promise<number> {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 });