difftreelog
test(ss58Format) more test fixes
in: master
17 files changed
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/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/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.tsdiffbeforeafterboth73 });73 });747475 it('Inability to pay fees error message is correct', async () => {75 it('Inability to pay fees error message is correct', async () => {76 await usingApi(async (api) => {76 await usingApi(async (api, privateKeyWrapper) => {77 // Find unused address77 // Find unused address78 const pk = await findUnusedAddress(api);78 const pk = await findUnusedAddress(api, privateKeyWrapper);797980 const badTransfer = api.tx.balances.transfer(bob.address, 1n);80 const badTransfer = api.tx.balances.transfer(bob.address, 1n);81 // const events = await submitTransactionAsync(pk, badTransfer);81 // const events = await submitTransactionAsync(pk, badTransfer);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';481 });481 });482}482}483483484export async function findUnusedAddress(api: ApiPromise, seedAddition = ''): Promise<IKeyringPair> {484export async function findUnusedAddress(api: ApiPromise, privateKeyWrapper: (account: string) => IKeyringPair, seedAddition = ''): Promise<IKeyringPair> {485 let bal = 0n;485 let bal = 0n;486 let unused;486 let unused;487 do {487 do {488 const randomSeed = 'seed' + Math.floor(Math.random() * Math.floor(10000)) + seedAddition;488 const randomSeed = 'seed' + Math.floor(Math.random() * Math.floor(10000)) + seedAddition;489 const keyring = new Keyring({type: 'sr25519'});490 unused = keyring.addFromUri(`//${randomSeed}`);489 unused = privateKeyWrapper(`//${randomSeed}`);491 bal = (await api.query.system.account(unused.address)).data.free.toBigInt();490 bal = (await api.query.system.account(unused.address)).data.free.toBigInt();492 } while (bal !== 0n);491 } while (bal !== 0n);493 return unused;492 return unused;497 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();498}497}499498500export function findUnusedAddresses(api: ApiPromise, amount: number): Promise<IKeyringPair[]> {499export function findUnusedAddresses(api: ApiPromise, privateKeyWrapper: (account: string) => IKeyringPair, amount: number): Promise<IKeyringPair[]> {501 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())));502}501}503502504export async function findNotExistingCollection(api: ApiPromise): Promise<number> {503export async function findNotExistingCollection(api: ApiPromise): Promise<number> {