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.tsdiffbeforeafterboth--- a/tests/src/accounts.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// This file is part of Unique Network.
-
-// Unique Network is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Unique Network is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-
-export const bobsPublicKey = '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty';
-export const alicesPublicKey = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
-export const ferdiesPublicKey = '5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL';
-export const nullPublicKey = '5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM';
\ No newline at end of file
tests/src/addToContractAllowList.test.tsdiffbeforeafterboth--- a/tests/src/addToContractAllowList.test.ts
+++ b/tests/src/addToContractAllowList.test.ts
@@ -32,7 +32,7 @@
it('Add an address to a contract allow list', async () => {
await usingApi(async (api, privateKeyWrapper) => {
const bob = privateKeyWrapper('//Bob');
- const [contract, deployer] = await deployFlipper(api);
+ const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);
const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();
const addTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);
@@ -48,7 +48,7 @@
it('Adding same address to allow list repeatedly should not produce errors', async () => {
await usingApi(async (api, privateKeyWrapper) => {
const bob = privateKeyWrapper('//Bob');
- const [contract, deployer] = await deployFlipper(api);
+ const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);
const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();
const addTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);
@@ -87,7 +87,7 @@
it('Add to a contract allow list using a non-owner address', async () => {
await usingApi(async (api, privateKeyWrapper) => {
const bob = privateKeyWrapper('//Bob');
- const [contract] = await deployFlipper(api);
+ const [contract] = await deployFlipper(api, privateKeyWrapper);
const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();
const addTx = api.tx.unique.addToContractAllowList(contract.address, bob.address);
tests/src/burnItem.test.tsdiffbeforeafterboth--- a/tests/src/burnItem.test.ts
+++ b/tests/src/burnItem.test.ts
@@ -15,7 +15,6 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
-import {Keyring} from '@polkadot/api';
import {IKeyringPair} from '@polkadot/types/types';
import {
createCollectionExpectSuccess,
@@ -37,10 +36,9 @@
describe('integration test: ext. burnItem():', () => {
before(async () => {
- await usingApi(async () => {
- const keyring = new Keyring({type: 'sr25519'});
- alice = keyring.addFromUri('//Alice');
- bob = keyring.addFromUri('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper('//Alice');
+ bob = privateKeyWrapper('//Bob');
});
});
@@ -142,10 +140,9 @@
describe('integration test: ext. burnItem() with admin permissions:', () => {
before(async () => {
- await usingApi(async () => {
- const keyring = new Keyring({type: 'sr25519'});
- alice = keyring.addFromUri('//Alice');
- bob = keyring.addFromUri('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper('//Alice');
+ bob = privateKeyWrapper('//Bob');
});
});
@@ -209,10 +206,9 @@
describe('Negative integration test: ext. burnItem():', () => {
before(async () => {
- await usingApi(async () => {
- const keyring = new Keyring({type: 'sr25519'});
- alice = keyring.addFromUri('//Alice');
- bob = keyring.addFromUri('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper('//Alice');
+ bob = privateKeyWrapper('//Bob');
});
});
tests/src/confirmSponsorship.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import chai from 'chai';18import chaiAsPromised from 'chai-as-promised';19import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';20import {21 createCollectionExpectSuccess,22 setCollectionSponsorExpectSuccess,23 destroyCollectionExpectSuccess,24 confirmSponsorshipExpectSuccess,25 confirmSponsorshipExpectFailure,26 createItemExpectSuccess,27 findUnusedAddress,28 getGenericResult,29 enableAllowListExpectSuccess,30 enablePublicMintingExpectSuccess,31 addToAllowListExpectSuccess,32 normalizeAccountId,33 addCollectionAdminExpectSuccess,34 getCreatedCollectionCount,35 UNIQUE,36} from './util/helpers';37import {Keyring} from '@polkadot/api';38import {IKeyringPair} from '@polkadot/types/types';3940chai.use(chaiAsPromised);41const expect = chai.expect;4243let alice: IKeyringPair;44let bob: IKeyringPair;45let charlie: IKeyringPair;4647describe('integration test: ext. confirmSponsorship():', () => {4849 before(async () => {50 await usingApi(async () => {51 const keyring = new Keyring({type: 'sr25519'});52 alice = keyring.addFromUri('//Alice');53 bob = keyring.addFromUri('//Bob');54 charlie = keyring.addFromUri('//Charlie');55 });56 });5758 it('Confirm collection sponsorship', async () => {59 const collectionId = await createCollectionExpectSuccess();60 await setCollectionSponsorExpectSuccess(collectionId, bob.address);61 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');62 });63 it('Add sponsor to a collection after the same sponsor was already added and confirmed', async () => {64 const collectionId = await createCollectionExpectSuccess();65 await setCollectionSponsorExpectSuccess(collectionId, bob.address);66 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');67 await setCollectionSponsorExpectSuccess(collectionId, bob.address);68 });69 it('Add new sponsor to a collection after another sponsor was already added and confirmed', async () => {70 const collectionId = await createCollectionExpectSuccess();71 await setCollectionSponsorExpectSuccess(collectionId, bob.address);72 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');73 await setCollectionSponsorExpectSuccess(collectionId, charlie.address);74 });7576 it('NFT: Transfer fees are paid by the sponsor after confirmation', async () => {77 const collectionId = await createCollectionExpectSuccess();78 await setCollectionSponsorExpectSuccess(collectionId, bob.address);79 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');8081 await usingApi(async (api) => {82 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();8384 // Find unused address85 const zeroBalance = await findUnusedAddress(api);8687 // Mint token for unused address88 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);8990 // Transfer this tokens from unused address to Alice91 const zeroToAlice = api.tx.unique.transfer(normalizeAccountId(zeroBalance.address), collectionId, itemId, 0);92 const events = await submitTransactionAsync(zeroBalance, zeroToAlice);93 const result = getGenericResult(events);94 expect(result.success).to.be.true;9596 const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();9798 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;99 });100101 });102103 it('Fungible: Transfer fees are paid by the sponsor after confirmation', async () => {104 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});105 await setCollectionSponsorExpectSuccess(collectionId, bob.address);106 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');107108 await usingApi(async (api) => {109 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();110111 // Find unused address112 const zeroBalance = await findUnusedAddress(api);113114 // Mint token for unused address115 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', zeroBalance.address);116117 // Transfer this tokens from unused address to Alice118 const zeroToAlice = api.tx.unique.transfer(normalizeAccountId(zeroBalance.address), collectionId, itemId, 1);119 const events1 = await submitTransactionAsync(zeroBalance, zeroToAlice);120 const result1 = getGenericResult(events1);121 expect(result1.success).to.be.true;122123 const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();124125 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;126 });127 });128129 it('ReFungible: Transfer fees are paid by the sponsor after confirmation', async () => {130 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});131 await setCollectionSponsorExpectSuccess(collectionId, bob.address);132 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');133134 await usingApi(async (api) => {135 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();136137 // Find unused address138 const zeroBalance = await findUnusedAddress(api);139140 // Mint token for unused address141 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', zeroBalance.address);142143 // Transfer this tokens from unused address to Alice144 const zeroToAlice = api.tx.unique.transfer(normalizeAccountId(zeroBalance.address), collectionId, itemId, 1);145 const events1 = await submitTransactionAsync(zeroBalance, zeroToAlice);146 const result1 = getGenericResult(events1);147148 const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();149150 expect(result1.success).to.be.true;151 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;152 });153 });154155 it('CreateItem fees are paid by the sponsor after confirmation', async () => {156 const collectionId = await createCollectionExpectSuccess();157 await setCollectionSponsorExpectSuccess(collectionId, bob.address);158 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');159160 // Enable collection allow list161 await enableAllowListExpectSuccess(alice, collectionId);162163 // Enable public minting164 await enablePublicMintingExpectSuccess(alice, collectionId);165166 // Create Item167 await usingApi(async (api) => {168 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();169170 // Find unused address171 const zeroBalance = await findUnusedAddress(api);172173 // Add zeroBalance address to allow list174 await addToAllowListExpectSuccess(alice, collectionId, zeroBalance.address);175176 // Mint token using unused address as signer177 await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);178179 const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();180181 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;182 });183 });184185 it('NFT: Sponsoring of transfers is rate limited', async () => {186 const collectionId = await createCollectionExpectSuccess();187 await setCollectionSponsorExpectSuccess(collectionId, bob.address);188 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');189190 await usingApi(async (api) => {191 // Find unused address192 const zeroBalance = await findUnusedAddress(api);193194 // Mint token for alice195 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);196197 // Transfer this token from Alice to unused address and back198 // Alice to Zero gets sponsored199 const aliceToZero = api.tx.unique.transfer(normalizeAccountId(zeroBalance.address), collectionId, itemId, 0);200 const events1 = await submitTransactionAsync(alice, aliceToZero);201 const result1 = getGenericResult(events1);202203 // Second transfer should fail204 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();205 const zeroToAlice = api.tx.unique.transfer(normalizeAccountId(alice.address), collectionId, itemId, 0);206 const badTransaction = async function () {207 await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);208 };209 await expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees');210 const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();211212 // Try again after Zero gets some balance - now it should succeed213 const balancetx = api.tx.balances.transfer(zeroBalance.address, 1n * UNIQUE);214 await submitTransactionAsync(alice, balancetx);215 const events2 = await submitTransactionAsync(zeroBalance, zeroToAlice);216 const result2 = getGenericResult(events2);217218 expect(result1.success).to.be.true;219 expect(result2.success).to.be.true;220 expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);221 });222 });223224 it('Fungible: Sponsoring is rate limited', async () => {225 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});226 await setCollectionSponsorExpectSuccess(collectionId, bob.address);227 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');228229 await usingApi(async (api) => {230 // Find unused address231 const zeroBalance = await findUnusedAddress(api);232233 // Mint token for unused address234 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', zeroBalance.address);235236 // Transfer this tokens in parts from unused address to Alice237 const zeroToAlice = api.tx.unique.transfer(normalizeAccountId(zeroBalance.address), collectionId, itemId, 1);238 const events1 = await submitTransactionAsync(zeroBalance, zeroToAlice);239 const result1 = getGenericResult(events1);240 expect(result1.success).to.be.true;241242 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();243 await expect(submitTransactionExpectFailAsync(zeroBalance, zeroToAlice)).to.be.rejected;244 const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();245246 // Try again after Zero gets some balance - now it should succeed247 const balancetx = api.tx.balances.transfer(zeroBalance.address, 1n * UNIQUE);248 await submitTransactionAsync(alice, balancetx);249 const events2 = await submitTransactionAsync(zeroBalance, zeroToAlice);250 const result2 = getGenericResult(events2);251 expect(result2.success).to.be.true;252253 expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);254 });255 });256257 it('ReFungible: Sponsoring is rate limited', async () => {258 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});259 await setCollectionSponsorExpectSuccess(collectionId, bob.address);260 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');261262 await usingApi(async (api) => {263 // Find unused address264 const zeroBalance = await findUnusedAddress(api);265266 // Mint token for alice267 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', zeroBalance.address);268269 const zeroToAlice = api.tx.unique.transfer(normalizeAccountId(alice.address), collectionId, itemId, 1);270271 // Zero to alice gets sponsored272 const events1 = await submitTransactionAsync(zeroBalance, zeroToAlice);273 const result1 = getGenericResult(events1);274 expect(result1.success).to.be.true;275276 // Second transfer should fail277 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();278 await expect(submitTransactionExpectFailAsync(zeroBalance, zeroToAlice)).to.be.rejectedWith('Inability to pay some fees');279 const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();280 expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);281282 // Try again after Zero gets some balance - now it should succeed283 const balancetx = api.tx.balances.transfer(zeroBalance.address, 1n * UNIQUE);284 await submitTransactionAsync(alice, balancetx);285 const events2 = await submitTransactionAsync(zeroBalance, zeroToAlice);286 const result2 = getGenericResult(events2);287 expect(result2.success).to.be.true;288 });289 });290291 it('NFT: Sponsoring of createItem is rate limited', async () => {292 const collectionId = await createCollectionExpectSuccess();293 await setCollectionSponsorExpectSuccess(collectionId, bob.address);294 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');295296 // Enable collection allow list297 await enableAllowListExpectSuccess(alice, collectionId);298299 // Enable public minting300 await enablePublicMintingExpectSuccess(alice, collectionId);301302 await usingApi(async (api) => {303 // Find unused address304 const zeroBalance = await findUnusedAddress(api);305306 // Add zeroBalance address to allow list307 await addToAllowListExpectSuccess(alice, collectionId, zeroBalance.address);308309 // Mint token using unused address as signer - gets sponsored310 await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);311312 // Second mint should fail313 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();314315 const badTransaction = async function () {316 await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);317 };318 await expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees');319 const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();320321 // Try again after Zero gets some balance - now it should succeed322 const balancetx = api.tx.balances.transfer(zeroBalance.address, 1n * UNIQUE);323 await submitTransactionAsync(alice, balancetx);324 await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);325326 expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);327 });328 });329330});331332describe('(!negative test!) integration test: ext. confirmSponsorship():', () => {333 before(async () => {334 await usingApi(async () => {335 const keyring = new Keyring({type: 'sr25519'});336 alice = keyring.addFromUri('//Alice');337 bob = keyring.addFromUri('//Bob');338 charlie = keyring.addFromUri('//Charlie');339 });340 });341342 it('(!negative test!) Confirm sponsorship for a collection that never existed', async () => {343 // Find the collection that never existed344 let collectionId = 0;345 await usingApi(async (api) => {346 collectionId = await getCreatedCollectionCount(api) + 1;347 });348349 await confirmSponsorshipExpectFailure(collectionId, '//Bob');350 });351352 it('(!negative test!) Confirm sponsorship using a non-sponsor address', async () => {353 const collectionId = await createCollectionExpectSuccess();354 await setCollectionSponsorExpectSuccess(collectionId, bob.address);355356 await usingApi(async (api) => {357 const transfer = api.tx.balances.transfer(charlie.address, 1e15);358 await submitTransactionAsync(alice, transfer);359 });360361 await confirmSponsorshipExpectFailure(collectionId, '//Charlie');362 });363364 it('(!negative test!) Confirm sponsorship using owner address', async () => {365 const collectionId = await createCollectionExpectSuccess();366 await setCollectionSponsorExpectSuccess(collectionId, bob.address);367 await confirmSponsorshipExpectFailure(collectionId, '//Alice');368 });369370 it('(!negative test!) Confirm sponsorship by collection admin', async () => {371 const collectionId = await createCollectionExpectSuccess();372 await setCollectionSponsorExpectSuccess(collectionId, bob.address);373 await addCollectionAdminExpectSuccess(alice, collectionId, charlie.address);374 await confirmSponsorshipExpectFailure(collectionId, '//Charlie');375 });376377 it('(!negative test!) Confirm sponsorship without sponsor being set with setCollectionSponsor', async () => {378 const collectionId = await createCollectionExpectSuccess();379 await confirmSponsorshipExpectFailure(collectionId, '//Bob');380 });381382 it('(!negative test!) Confirm sponsorship in a collection that was destroyed', async () => {383 const collectionId = await createCollectionExpectSuccess();384 await destroyCollectionExpectSuccess(collectionId);385 await confirmSponsorshipExpectFailure(collectionId, '//Bob');386 });387388 it('(!negative test!) Transfer fees are not paid by the sponsor if the transfer failed', async () => {389 const collectionId = await createCollectionExpectSuccess();390 await setCollectionSponsorExpectSuccess(collectionId, bob.address);391 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');392393 await usingApi(async (api) => {394 // Find unused address395 const ownerZeroBalance = await findUnusedAddress(api);396397 // Find another unused address398 const senderZeroBalance = await findUnusedAddress(api);399400 // Mint token for an unused address401 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', ownerZeroBalance.address);402403 const sponsorBalanceBeforeTx = (await api.query.system.account(bob.address)).data.free.toBigInt();404405 // Try to transfer this token from an unsponsored unused adress to Alice406 const zeroToAlice = api.tx.unique.transfer(normalizeAccountId(alice.address), collectionId, itemId, 0);407 await expect(submitTransactionExpectFailAsync(senderZeroBalance, zeroToAlice)).to.be.rejected;408409 const sponsorBalanceAfterTx = (await api.query.system.account(bob.address)).data.free.toBigInt();410411 expect(sponsorBalanceAfterTx).to.equal(sponsorBalanceBeforeTx);412 });413 });414});1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import chai from 'chai';18import chaiAsPromised from 'chai-as-promised';19import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';20import {21 createCollectionExpectSuccess,22 setCollectionSponsorExpectSuccess,23 destroyCollectionExpectSuccess,24 confirmSponsorshipExpectSuccess,25 confirmSponsorshipExpectFailure,26 createItemExpectSuccess,27 findUnusedAddress,28 getGenericResult,29 enableAllowListExpectSuccess,30 enablePublicMintingExpectSuccess,31 addToAllowListExpectSuccess,32 normalizeAccountId,33 addCollectionAdminExpectSuccess,34 getCreatedCollectionCount,35 UNIQUE,36} from './util/helpers';37import {IKeyringPair} from '@polkadot/types/types';3839chai.use(chaiAsPromised);40const expect = chai.expect;4142let alice: IKeyringPair;43let bob: IKeyringPair;44let charlie: IKeyringPair;4546describe('integration test: ext. confirmSponsorship():', () => {4748 before(async () => {49 await usingApi(async (api, privateKeyWrapper) => {50 alice = privateKeyWrapper('//Alice');51 bob = privateKeyWrapper('//Bob');52 charlie = privateKeyWrapper('//Charlie');53 });54 });5556 it('Confirm collection sponsorship', async () => {57 const collectionId = await createCollectionExpectSuccess();58 await setCollectionSponsorExpectSuccess(collectionId, bob.address);59 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');60 });61 it('Add sponsor to a collection after the same sponsor was already added and confirmed', async () => {62 const collectionId = await createCollectionExpectSuccess();63 await setCollectionSponsorExpectSuccess(collectionId, bob.address);64 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');65 await setCollectionSponsorExpectSuccess(collectionId, bob.address);66 });67 it('Add new sponsor to a collection after another sponsor was already added and confirmed', async () => {68 const collectionId = await createCollectionExpectSuccess();69 await setCollectionSponsorExpectSuccess(collectionId, bob.address);70 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');71 await setCollectionSponsorExpectSuccess(collectionId, charlie.address);72 });7374 it('NFT: Transfer fees are paid by the sponsor after confirmation', async () => {75 const collectionId = await createCollectionExpectSuccess();76 await setCollectionSponsorExpectSuccess(collectionId, bob.address);77 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');7879 await usingApi(async (api, privateKeyWrapper) => {80 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();8182 // Find unused address83 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);8485 // Mint token for unused address86 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);8788 // Transfer this tokens from unused address to Alice89 const zeroToAlice = api.tx.unique.transfer(normalizeAccountId(zeroBalance.address), collectionId, itemId, 0);90 const events = await submitTransactionAsync(zeroBalance, zeroToAlice);91 const result = getGenericResult(events);92 expect(result.success).to.be.true;9394 const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();9596 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;97 });9899 });100101 it('Fungible: Transfer fees are paid by the sponsor after confirmation', async () => {102 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});103 await setCollectionSponsorExpectSuccess(collectionId, bob.address);104 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');105106 await usingApi(async (api, privateKeyWrapper) => {107 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();108109 // Find unused address110 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);111112 // Mint token for unused address113 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', zeroBalance.address);114115 // Transfer this tokens from unused address to Alice116 const zeroToAlice = api.tx.unique.transfer(normalizeAccountId(zeroBalance.address), collectionId, itemId, 1);117 const events1 = await submitTransactionAsync(zeroBalance, zeroToAlice);118 const result1 = getGenericResult(events1);119 expect(result1.success).to.be.true;120121 const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();122123 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;124 });125 });126127 it('ReFungible: Transfer fees are paid by the sponsor after confirmation', async () => {128 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});129 await setCollectionSponsorExpectSuccess(collectionId, bob.address);130 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');131132 await usingApi(async (api, privateKeyWrapper) => {133 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();134135 // Find unused address136 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);137138 // Mint token for unused address139 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', zeroBalance.address);140141 // Transfer this tokens from unused address to Alice142 const zeroToAlice = api.tx.unique.transfer(normalizeAccountId(zeroBalance.address), collectionId, itemId, 1);143 const events1 = await submitTransactionAsync(zeroBalance, zeroToAlice);144 const result1 = getGenericResult(events1);145146 const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();147148 expect(result1.success).to.be.true;149 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;150 });151 });152153 it('CreateItem fees are paid by the sponsor after confirmation', async () => {154 const collectionId = await createCollectionExpectSuccess();155 await setCollectionSponsorExpectSuccess(collectionId, bob.address);156 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');157158 // Enable collection allow list159 await enableAllowListExpectSuccess(alice, collectionId);160161 // Enable public minting162 await enablePublicMintingExpectSuccess(alice, collectionId);163164 // Create Item165 await usingApi(async (api, privateKeyWrapper) => {166 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();167168 // Find unused address169 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);170171 // Add zeroBalance address to allow list172 await addToAllowListExpectSuccess(alice, collectionId, zeroBalance.address);173174 // Mint token using unused address as signer175 await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);176177 const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();178179 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;180 });181 });182183 it('NFT: Sponsoring of transfers is rate limited', async () => {184 const collectionId = await createCollectionExpectSuccess();185 await setCollectionSponsorExpectSuccess(collectionId, bob.address);186 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');187188 await usingApi(async (api, privateKeyWrapper) => {189 // Find unused address190 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);191192 // Mint token for alice193 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);194195 // Transfer this token from Alice to unused address and back196 // Alice to Zero gets sponsored197 const aliceToZero = api.tx.unique.transfer(normalizeAccountId(zeroBalance.address), collectionId, itemId, 0);198 const events1 = await submitTransactionAsync(alice, aliceToZero);199 const result1 = getGenericResult(events1);200201 // Second transfer should fail202 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();203 const zeroToAlice = api.tx.unique.transfer(normalizeAccountId(alice.address), collectionId, itemId, 0);204 const badTransaction = async function () {205 await submitTransactionExpectFailAsync(zeroBalance, zeroToAlice);206 };207 await expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees');208 const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();209210 // Try again after Zero gets some balance - now it should succeed211 const balancetx = api.tx.balances.transfer(zeroBalance.address, 1n * UNIQUE);212 await submitTransactionAsync(alice, balancetx);213 const events2 = await submitTransactionAsync(zeroBalance, zeroToAlice);214 const result2 = getGenericResult(events2);215216 expect(result1.success).to.be.true;217 expect(result2.success).to.be.true;218 expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);219 });220 });221222 it('Fungible: Sponsoring is rate limited', async () => {223 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});224 await setCollectionSponsorExpectSuccess(collectionId, bob.address);225 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');226227 await usingApi(async (api, privateKeyWrapper) => {228 // Find unused address229 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);230231 // Mint token for unused address232 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', zeroBalance.address);233234 // Transfer this tokens in parts from unused address to Alice235 const zeroToAlice = api.tx.unique.transfer(normalizeAccountId(zeroBalance.address), collectionId, itemId, 1);236 const events1 = await submitTransactionAsync(zeroBalance, zeroToAlice);237 const result1 = getGenericResult(events1);238 expect(result1.success).to.be.true;239240 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();241 await expect(submitTransactionExpectFailAsync(zeroBalance, zeroToAlice)).to.be.rejected;242 const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();243244 // Try again after Zero gets some balance - now it should succeed245 const balancetx = api.tx.balances.transfer(zeroBalance.address, 1n * UNIQUE);246 await submitTransactionAsync(alice, balancetx);247 const events2 = await submitTransactionAsync(zeroBalance, zeroToAlice);248 const result2 = getGenericResult(events2);249 expect(result2.success).to.be.true;250251 expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);252 });253 });254255 it('ReFungible: Sponsoring is rate limited', async () => {256 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});257 await setCollectionSponsorExpectSuccess(collectionId, bob.address);258 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');259260 await usingApi(async (api, privateKeyWrapper) => {261 // Find unused address262 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);263264 // Mint token for alice265 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', zeroBalance.address);266267 const zeroToAlice = api.tx.unique.transfer(normalizeAccountId(alice.address), collectionId, itemId, 1);268269 // Zero to alice gets sponsored270 const events1 = await submitTransactionAsync(zeroBalance, zeroToAlice);271 const result1 = getGenericResult(events1);272 expect(result1.success).to.be.true;273274 // Second transfer should fail275 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();276 await expect(submitTransactionExpectFailAsync(zeroBalance, zeroToAlice)).to.be.rejectedWith('Inability to pay some fees');277 const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();278 expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);279280 // Try again after Zero gets some balance - now it should succeed281 const balancetx = api.tx.balances.transfer(zeroBalance.address, 1n * UNIQUE);282 await submitTransactionAsync(alice, balancetx);283 const events2 = await submitTransactionAsync(zeroBalance, zeroToAlice);284 const result2 = getGenericResult(events2);285 expect(result2.success).to.be.true;286 });287 });288289 it('NFT: Sponsoring of createItem is rate limited', async () => {290 const collectionId = await createCollectionExpectSuccess();291 await setCollectionSponsorExpectSuccess(collectionId, bob.address);292 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');293294 // Enable collection allow list295 await enableAllowListExpectSuccess(alice, collectionId);296297 // Enable public minting298 await enablePublicMintingExpectSuccess(alice, collectionId);299300 await usingApi(async (api, privateKeyWrapper) => {301 // Find unused address302 const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);303304 // Add zeroBalance address to allow list305 await addToAllowListExpectSuccess(alice, collectionId, zeroBalance.address);306307 // Mint token using unused address as signer - gets sponsored308 await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);309310 // Second mint should fail311 const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();312313 const badTransaction = async function () {314 await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);315 };316 await expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees');317 const sponsorBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();318319 // Try again after Zero gets some balance - now it should succeed320 const balancetx = api.tx.balances.transfer(zeroBalance.address, 1n * UNIQUE);321 await submitTransactionAsync(alice, balancetx);322 await createItemExpectSuccess(zeroBalance, collectionId, 'NFT', zeroBalance.address);323324 expect(sponsorBalanceAfter).to.be.equal(sponsorBalanceBefore);325 });326 });327328});329330describe('(!negative test!) integration test: ext. confirmSponsorship():', () => {331 before(async () => {332 await usingApi(async (api, privateKeyWrapper) => {333 alice = privateKeyWrapper('//Alice');334 bob = privateKeyWrapper('//Bob');335 charlie = privateKeyWrapper('//Charlie');336 });337 });338339 it('(!negative test!) Confirm sponsorship for a collection that never existed', async () => {340 // Find the collection that never existed341 let collectionId = 0;342 await usingApi(async (api) => {343 collectionId = await getCreatedCollectionCount(api) + 1;344 });345346 await confirmSponsorshipExpectFailure(collectionId, '//Bob');347 });348349 it('(!negative test!) Confirm sponsorship using a non-sponsor address', async () => {350 const collectionId = await createCollectionExpectSuccess();351 await setCollectionSponsorExpectSuccess(collectionId, bob.address);352353 await usingApi(async (api) => {354 const transfer = api.tx.balances.transfer(charlie.address, 1e15);355 await submitTransactionAsync(alice, transfer);356 });357358 await confirmSponsorshipExpectFailure(collectionId, '//Charlie');359 });360361 it('(!negative test!) Confirm sponsorship using owner address', async () => {362 const collectionId = await createCollectionExpectSuccess();363 await setCollectionSponsorExpectSuccess(collectionId, bob.address);364 await confirmSponsorshipExpectFailure(collectionId, '//Alice');365 });366367 it('(!negative test!) Confirm sponsorship by collection admin', async () => {368 const collectionId = await createCollectionExpectSuccess();369 await setCollectionSponsorExpectSuccess(collectionId, bob.address);370 await addCollectionAdminExpectSuccess(alice, collectionId, charlie.address);371 await confirmSponsorshipExpectFailure(collectionId, '//Charlie');372 });373374 it('(!negative test!) Confirm sponsorship without sponsor being set with setCollectionSponsor', async () => {375 const collectionId = await createCollectionExpectSuccess();376 await confirmSponsorshipExpectFailure(collectionId, '//Bob');377 });378379 it('(!negative test!) Confirm sponsorship in a collection that was destroyed', async () => {380 const collectionId = await createCollectionExpectSuccess();381 await destroyCollectionExpectSuccess(collectionId);382 await confirmSponsorshipExpectFailure(collectionId, '//Bob');383 });384385 it('(!negative test!) Transfer fees are not paid by the sponsor if the transfer failed', async () => {386 const collectionId = await createCollectionExpectSuccess();387 await setCollectionSponsorExpectSuccess(collectionId, bob.address);388 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');389390 await usingApi(async (api, privateKeyWrapper) => {391 // Find unused address392 const ownerZeroBalance = await findUnusedAddress(api, privateKeyWrapper);393394 // Find another unused address395 const senderZeroBalance = await findUnusedAddress(api, privateKeyWrapper);396397 // Mint token for an unused address398 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', ownerZeroBalance.address);399400 const sponsorBalanceBeforeTx = (await api.query.system.account(bob.address)).data.free.toBigInt();401402 // Try to transfer this token from an unsponsored unused adress to Alice403 const zeroToAlice = api.tx.unique.transfer(normalizeAccountId(alice.address), collectionId, itemId, 0);404 await expect(submitTransactionExpectFailAsync(senderZeroBalance, zeroToAlice)).to.be.rejected;405406 const sponsorBalanceAfterTx = (await api.query.system.account(bob.address)).data.free.toBigInt();407408 expect(sponsorBalanceAfterTx).to.equal(sponsorBalanceBeforeTx);409 });410 });411});tests/src/contracts.test.tsdiffbeforeafterboth--- a/tests/src/contracts.test.ts
+++ b/tests/src/contracts.test.ts
@@ -50,7 +50,7 @@
describe.skip('Contracts', () => {
it('Can deploy smart contract Flipper, instantiate it and call it\'s get and flip messages.', async () => {
await usingApi(async (api, privateKeyWrapper) => {
- const [contract, deployer] = await deployFlipper(api);
+ const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);
const initialGetResponse = await getFlipValue(contract, deployer);
const bob = privateKeyWrapper('//Bob');
@@ -82,7 +82,7 @@
// Prep work
const collectionId = await createCollectionExpectSuccess();
const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');
- const [contract] = await deployTransferContract(api);
+ const [contract] = await deployTransferContract(api, privateKeyWrapper);
const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, contract.address);
await submitTransactionAsync(alice, changeAdminTx);
@@ -104,7 +104,7 @@
const bob = privateKeyWrapper('//Bob');
const collectionId = await createCollectionExpectSuccess();
- const [contract] = await deployTransferContract(api);
+ const [contract] = await deployTransferContract(api, privateKeyWrapper);
await enablePublicMintingExpectSuccess(alice, collectionId);
await enableAllowListExpectSuccess(alice, collectionId);
await addToAllowListExpectSuccess(alice, collectionId, contract.address);
@@ -131,7 +131,7 @@
const bob = privateKeyWrapper('//Bob');
const collectionId = await createCollectionExpectSuccess();
- const [contract] = await deployTransferContract(api);
+ const [contract] = await deployTransferContract(api, privateKeyWrapper);
await enablePublicMintingExpectSuccess(alice, collectionId);
await enableAllowListExpectSuccess(alice, collectionId);
await addToAllowListExpectSuccess(alice, collectionId, contract.address);
@@ -173,7 +173,7 @@
const charlie = privateKeyWrapper('//Charlie');
const collectionId = await createCollectionExpectSuccess();
- const [contract] = await deployTransferContract(api);
+ const [contract] = await deployTransferContract(api, privateKeyWrapper);
const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', contract.address.toString());
const transferTx = contract.tx.approve(value, gasLimit, bob.address, collectionId, tokenId, 1);
@@ -192,7 +192,7 @@
const charlie = privateKeyWrapper('//Charlie');
const collectionId = await createCollectionExpectSuccess();
- const [contract] = await deployTransferContract(api);
+ const [contract] = await deployTransferContract(api, privateKeyWrapper);
const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);
await approveExpectSuccess(collectionId, tokenId, bob, contract.address.toString(), 1);
@@ -212,7 +212,7 @@
const bob = privateKeyWrapper('//Bob');
const collectionId = await createCollectionExpectSuccess();
- const [contract] = await deployTransferContract(api);
+ const [contract] = await deployTransferContract(api, privateKeyWrapper);
const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, contract.address);
await submitTransactionAsync(alice, changeAdminTx);
tests/src/createItem.test.tsdiffbeforeafterboth--- a/tests/src/createItem.test.ts
+++ b/tests/src/createItem.test.ts
@@ -16,7 +16,6 @@
import {default as usingApi} from './substrate/substrate-api';
import chai from 'chai';
-import {Keyring} from '@polkadot/api';
import {IKeyringPair} from '@polkadot/types/types';
import {
createCollectionExpectSuccess,
@@ -33,10 +32,9 @@
describe('integration test: ext. ():', () => {
before(async () => {
- await usingApi(async () => {
- const keyring = new Keyring({type: 'sr25519'});
- alice = keyring.addFromUri('//Alice');
- bob = keyring.addFromUri('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper('//Alice');
+ bob = privateKeyWrapper('//Bob');
});
});
@@ -101,10 +99,9 @@
describe('Negative integration test: ext. createItem():', () => {
before(async () => {
- await usingApi(async () => {
- const keyring = new Keyring({type: 'sr25519'});
- alice = keyring.addFromUri('//Alice');
- bob = keyring.addFromUri('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper('//Alice');
+ bob = privateKeyWrapper('//Bob');
});
});
tests/src/creditFeesToTreasury.test.tsdiffbeforeafterboth--- a/tests/src/creditFeesToTreasury.test.ts
+++ b/tests/src/creditFeesToTreasury.test.ts
@@ -18,7 +18,6 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
-import {alicesPublicKey, bobsPublicKey} from './accounts';
import {IKeyringPair} from '@polkadot/types/types';
import {
createCollectionExpectSuccess,
@@ -71,17 +70,16 @@
});
it('Total issuance does not change', async () => {
- await usingApi(async (api, privateKeyWrapper) => {
+ await usingApi(async (api) => {
await skipInflationBlock(api);
await waitNewBlocks(api, 1);
const totalBefore = (await api.query.balances.totalIssuance()).toBigInt();
- const alicePrivateKey = privateKeyWrapper('//Alice');
const amount = 1n;
- const transfer = api.tx.balances.transfer(bobsPublicKey, amount);
+ const transfer = api.tx.balances.transfer(bob.address, amount);
- const result = getGenericResult(await submitTransactionAsync(alicePrivateKey, transfer));
+ const result = getGenericResult(await submitTransactionAsync(alice, transfer));
const totalAfter = (await api.query.balances.totalIssuance()).toBigInt();
@@ -91,20 +89,19 @@
});
it('Sender balance decreased by fee+sent amount, Treasury balance increased by fee', async () => {
- await usingApi(async (api, privateKeyWrapper) => {
+ await usingApi(async (api) => {
await skipInflationBlock(api);
await waitNewBlocks(api, 1);
- const alicePrivateKey = privateKeyWrapper('//Alice');
const treasuryBalanceBefore: bigint = (await api.query.system.account(TREASURY)).data.free.toBigInt();
- const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
+ const aliceBalanceBefore: bigint = (await api.query.system.account(alice.address)).data.free.toBigInt();
const amount = 1n;
- const transfer = api.tx.balances.transfer(bobsPublicKey, amount);
- const result = getGenericResult(await submitTransactionAsync(alicePrivateKey, transfer));
+ const transfer = api.tx.balances.transfer(bob.address, amount);
+ const result = getGenericResult(await submitTransactionAsync(alice, transfer));
const treasuryBalanceAfter: bigint = (await api.query.system.account(TREASURY)).data.free.toBigInt();
- const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
+ const aliceBalanceAfter: bigint = (await api.query.system.account(alice.address)).data.free.toBigInt();
const fee = aliceBalanceBefore - aliceBalanceAfter - amount;
const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;
@@ -114,19 +111,18 @@
});
it('Treasury balance increased by failed tx fee', async () => {
- await usingApi(async (api, privateKeyWrapper) => {
+ await usingApi(async (api) => {
//await skipInflationBlock(api);
await waitNewBlocks(api, 1);
- const bobPrivateKey = privateKeyWrapper('//Bob');
const treasuryBalanceBefore = (await api.query.system.account(TREASURY)).data.free.toBigInt();
- const bobBalanceBefore = (await api.query.system.account(bobsPublicKey)).data.free.toBigInt();
+ const bobBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
- const badTx = api.tx.balances.setBalance(alicesPublicKey, 0, 0);
- await expect(submitTransactionExpectFailAsync(bobPrivateKey, badTx)).to.be.rejected;
+ const badTx = api.tx.balances.setBalance(alice.address, 0, 0);
+ await expect(submitTransactionExpectFailAsync(bob, badTx)).to.be.rejected;
const treasuryBalanceAfter = (await api.query.system.account(TREASURY)).data.free.toBigInt();
- const bobBalanceAfter = (await api.query.system.account(bobsPublicKey)).data.free.toBigInt();
+ const bobBalanceAfter = (await api.query.system.account(bob.address)).data.free.toBigInt();
const fee = bobBalanceBefore - bobBalanceAfter;
const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;
@@ -140,12 +136,12 @@
await waitNewBlocks(api, 1);
const treasuryBalanceBefore = (await api.query.system.account(TREASURY)).data.free.toBigInt();
- const aliceBalanceBefore = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
+ const aliceBalanceBefore = (await api.query.system.account(alice.address)).data.free.toBigInt();
await createCollectionExpectSuccess();
const treasuryBalanceAfter = (await api.query.system.account(TREASURY)).data.free.toBigInt();
- const aliceBalanceAfter = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
+ const aliceBalanceAfter = (await api.query.system.account(alice.address)).data.free.toBigInt();
const fee = aliceBalanceBefore - aliceBalanceAfter;
const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;
@@ -158,11 +154,11 @@
await skipInflationBlock(api);
await waitNewBlocks(api, 1);
- const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
+ const aliceBalanceBefore: bigint = (await api.query.system.account(alice.address)).data.free.toBigInt();
await createCollectionExpectSuccess();
- const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
+ const aliceBalanceAfter: bigint = (await api.query.system.account(alice.address)).data.free.toBigInt();
const fee = aliceBalanceBefore - aliceBalanceAfter;
expect(fee / UNIQUE < BigInt(Math.ceil(saneMaximumFee + createCollectionDeposit))).to.be.true;
@@ -178,9 +174,9 @@
const collectionId = await createCollectionExpectSuccess();
const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');
- const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
+ const aliceBalanceBefore: bigint = (await api.query.system.account(alice.address)).data.free.toBigInt();
await transferExpectSuccess(collectionId, tokenId, alice, bob, 1, 'NFT');
- const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
+ const aliceBalanceAfter: bigint = (await api.query.system.account(alice.address)).data.free.toBigInt();
const fee = Number(aliceBalanceBefore - aliceBalanceAfter) / Number(UNIQUE);
const expectedTransferFee = 0.1;
tests/src/enableContractSponsoring.test.tsdiffbeforeafterboth--- a/tests/src/enableContractSponsoring.test.ts
+++ b/tests/src/enableContractSponsoring.test.ts
@@ -31,10 +31,10 @@
describe.skip('Integration Test enableContractSponsoring', () => {
it('ensure tx fee is paid from endowment', async () => {
- await usingApi(async (api) => {
- const user = await findUnusedAddress(api);
+ await usingApi(async (api, privateKeyWrapper) => {
+ const user = await findUnusedAddress(api, privateKeyWrapper);
- const [flipper, deployer] = await deployFlipper(api);
+ const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);
await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);
await setContractSponsoringRateLimitExpectSuccess(deployer, flipper.address, 1);
await toggleFlipValueExpectSuccess(user, flipper);
@@ -44,8 +44,8 @@
});
it('ensure it can be enabled twice', async () => {
- await usingApi(async (api) => {
- const [flipper, deployer] = await deployFlipper(api);
+ await usingApi(async (api, privateKeyWrapper) => {
+ const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);
await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);
await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);
@@ -53,8 +53,8 @@
});
it('ensure it can be disabled twice', async () => {
- await usingApi(async (api) => {
- const [flipper, deployer] = await deployFlipper(api);
+ await usingApi(async (api, privateKeyWrapper) => {
+ const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);
await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);
await enableContractSponsoringExpectSuccess(deployer, flipper.address, false);
@@ -63,8 +63,8 @@
});
it('ensure it can be re-enabled', async () => {
- await usingApi(async (api) => {
- const [flipper, deployer] = await deployFlipper(api);
+ await usingApi(async (api, privateKeyWrapper) => {
+ const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);
await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);
await enableContractSponsoringExpectSuccess(deployer, flipper.address, false);
@@ -84,16 +84,16 @@
});
it('fails when called for non-contract address', async () => {
- await usingApi(async (api) => {
- const user = await findUnusedAddress(api);
+ await usingApi(async (api, privateKeyWrapper) => {
+ const user = await findUnusedAddress(api, privateKeyWrapper);
await enableContractSponsoringExpectFailure(alice, user.address, true);
});
});
it('fails when called by non-owning user', async () => {
- await usingApi(async (api) => {
- const [flipper] = await deployFlipper(api);
+ await usingApi(async (api, privateKeyWrapper) => {
+ const [flipper] = await deployFlipper(api, privateKeyWrapper);
await enableContractSponsoringExpectFailure(alice, flipper.address, true);
});
tests/src/removeCollectionSponsor.test.tsdiffbeforeafterboth--- a/tests/src/removeCollectionSponsor.test.ts
+++ b/tests/src/removeCollectionSponsor.test.ts
@@ -31,7 +31,6 @@
addCollectionAdminExpectSuccess,
getCreatedCollectionCount,
} from './util/helpers';
-import {Keyring} from '@polkadot/api';
import {IKeyringPair} from '@polkadot/types/types';
chai.use(chaiAsPromised);
@@ -43,10 +42,9 @@
describe('integration test: ext. removeCollectionSponsor():', () => {
before(async () => {
- await usingApi(async () => {
- const keyring = new Keyring({type: 'sr25519'});
- alice = keyring.addFromUri('//Alice');
- bob = keyring.addFromUri('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper('//Alice');
+ bob = privateKeyWrapper('//Bob');
});
});
@@ -56,9 +54,9 @@
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
await removeCollectionSponsorExpectSuccess(collectionId);
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
// Find unused address
- const zeroBalance = await findUnusedAddress(api);
+ const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);
// Mint token for unused address
const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', zeroBalance.address);
@@ -99,10 +97,9 @@
describe('(!negative test!) integration test: ext. removeCollectionSponsor():', () => {
before(async () => {
- await usingApi(async () => {
- const keyring = new Keyring({type: 'sr25519'});
- alice = keyring.addFromUri('//Alice');
- bob = keyring.addFromUri('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper('//Alice');
+ bob = privateKeyWrapper('//Bob');
});
});
tests/src/removeFromContractAllowList.test.tsdiffbeforeafterboth--- a/tests/src/removeFromContractAllowList.test.ts
+++ b/tests/src/removeFromContractAllowList.test.ts
@@ -30,8 +30,8 @@
});
it('user is no longer allowlisted after removal', async () => {
- await usingApi(async (api) => {
- const [flipper, deployer] = await deployFlipper(api);
+ await usingApi(async (api, privateKeyWrapper) => {
+ const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);
await addToContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);
await removeFromContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);
@@ -41,8 +41,8 @@
});
it('user can\'t execute contract after removal', async () => {
- await usingApi(async (api) => {
- const [flipper, deployer] = await deployFlipper(api);
+ await usingApi(async (api, privateKeyWrapper) => {
+ const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);
await toggleContractAllowlistExpectSuccess(deployer, flipper.address.toString(), true);
await addToContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);
@@ -54,8 +54,8 @@
});
it('can be called twice', async () => {
- await usingApi(async (api) => {
- const [flipper, deployer] = await deployFlipper(api);
+ await usingApi(async (api, privateKeyWrapper) => {
+ const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);
await addToContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);
await removeFromContractAllowListExpectSuccess(deployer, flipper.address.toString(), bob.address);
@@ -82,8 +82,8 @@
});
it('fails when executed by non owner', async () => {
- await usingApi(async (api) => {
- const [flipper] = await deployFlipper(api);
+ await usingApi(async (api, privateKeyWrapper) => {
+ const [flipper] = await deployFlipper(api, privateKeyWrapper);
await removeFromContractAllowListExpectFailure(alice, flipper.address.toString(), bob.address);
});
tests/src/rpc.load.tsdiffbeforeafterboth--- a/tests/src/rpc.load.ts
+++ b/tests/src/rpc.load.ts
@@ -54,9 +54,9 @@
});
}
-async function prepareDeployer(api: ApiPromise) {
+async function prepareDeployer(api: ApiPromise, privateKeyWrapper: ((account: string) => IKeyringPair)) {
// Find unused address
- const deployer = await findUnusedAddress(api);
+ const deployer = await findUnusedAddress(api, privateKeyWrapper);
// Transfer balance to it
const keyring = new Keyring({type: 'sr25519'});
@@ -68,11 +68,11 @@
return deployer;
}
-async function deployLoadTester(api: ApiPromise): Promise<[Contract, IKeyringPair]> {
+async function deployLoadTester(api: ApiPromise, privateKeyWrapper: ((account: string) => IKeyringPair)): Promise<[Contract, IKeyringPair]> {
const metadata = JSON.parse(fs.readFileSync('./src/load_test_sc/metadata.json').toString('utf-8'));
const abi = new Abi(metadata);
- const deployer = await prepareDeployer(api);
+ const deployer = await prepareDeployer(api, privateKeyWrapper);
const wasm = fs.readFileSync('./src/load_test_sc/loadtester.wasm');
@@ -123,7 +123,7 @@
await usingApi(async (api, privateKeyWrapper) => {
// Deploy smart contract
- const [contract, deployer] = await deployLoadTester(api);
+ const [contract, deployer] = await deployLoadTester(api, privateKeyWrapper);
// Fill smart contract up with data
const bob = privateKeyWrapper('//Bob');
tests/src/scheduler.test.tsdiffbeforeafterboth--- a/tests/src/scheduler.test.ts
+++ b/tests/src/scheduler.test.ts
@@ -116,9 +116,9 @@
});
it('Schedules and dispatches a transaction even if the caller has no funds at the time of the dispatch', async () => {
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
// Find an empty, unused account
- const zeroBalance = await findUnusedAddress(api);
+ const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);
const collectionId = await createCollectionExpectSuccess();
@@ -156,8 +156,8 @@
it('Sponsor going bankrupt does not impact a scheduled transaction', async () => {
const collectionId = await createCollectionExpectSuccess();
- await usingApi(async (api) => {
- const zeroBalance = await findUnusedAddress(api);
+ await usingApi(async (api, privateKeyWrapper) => {
+ const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);
const balanceTx = api.tx.balances.transfer(zeroBalance.address, 1n * UNIQUE);
await submitTransactionAsync(alice, balanceTx);
@@ -186,8 +186,8 @@
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
- await usingApi(async (api) => {
- const zeroBalance = await findUnusedAddress(api);
+ await usingApi(async (api, privateKeyWrapper) => {
+ const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);
await enablePublicMintingExpectSuccess(alice, collectionId);
await addToAllowListExpectSuccess(alice, collectionId, zeroBalance.address);
tests/src/setCollectionLimits.test.tsdiffbeforeafterboth--- a/tests/src/setCollectionLimits.test.ts
+++ b/tests/src/setCollectionLimits.test.ts
@@ -15,7 +15,7 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits
-import {ApiPromise, Keyring} from '@polkadot/api';
+import {ApiPromise} from '@polkadot/api';
import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
@@ -44,9 +44,8 @@
describe('setCollectionLimits positive', () => {
let tx;
before(async () => {
- await usingApi(async () => {
- const keyring = new Keyring({type: 'sr25519'});
- alice = keyring.addFromUri('//Alice');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper('//Alice');
collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
});
});
@@ -121,10 +120,9 @@
describe('setCollectionLimits negative', () => {
let tx;
before(async () => {
- await usingApi(async () => {
- const keyring = new Keyring({type: 'sr25519'});
- alice = keyring.addFromUri('//Alice');
- bob = keyring.addFromUri('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper('//Alice');
+ bob = privateKeyWrapper('//Bob');
collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
});
});
tests/src/setCollectionSponsor.test.tsdiffbeforeafterboth--- a/tests/src/setCollectionSponsor.test.ts
+++ b/tests/src/setCollectionSponsor.test.ts
@@ -24,7 +24,6 @@
addCollectionAdminExpectSuccess,
getCreatedCollectionCount,
} from './util/helpers';
-import {Keyring} from '@polkadot/api';
import {IKeyringPair} from '@polkadot/types/types';
chai.use(chaiAsPromised);
@@ -36,10 +35,10 @@
describe('integration test: ext. setCollectionSponsor():', () => {
before(async () => {
- await usingApi(async () => {
- const keyring = new Keyring({type: 'sr25519'});
- alice = keyring.addFromUri('//Alice');
- bob = keyring.addFromUri('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper('//Alice');
+ bob = privateKeyWrapper('//Bob');
+ charlie = privateKeyWrapper('//Charlie');
});
});
@@ -63,9 +62,6 @@
});
it('Replace collection sponsor', async () => {
const collectionId = await createCollectionExpectSuccess();
-
- const keyring = new Keyring({type: 'sr25519'});
- const charlie = keyring.addFromUri('//Charlie');
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await setCollectionSponsorExpectSuccess(collectionId, charlie.address);
});
@@ -73,11 +69,10 @@
describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {
before(async () => {
- await usingApi(async () => {
- const keyring = new Keyring({type: 'sr25519'});
- alice = keyring.addFromUri('//Alice');
- bob = keyring.addFromUri('//Bob');
- charlie = keyring.addFromUri('//Charlie');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper('//Alice');
+ bob = privateKeyWrapper('//Bob');
+ charlie = privateKeyWrapper('//Charlie');
});
});
tests/src/setContractSponsoringRateLimit.test.tsdiffbeforeafterboth--- a/tests/src/setContractSponsoringRateLimit.test.ts
+++ b/tests/src/setContractSponsoringRateLimit.test.ts
@@ -27,10 +27,10 @@
describe.skip('Integration Test setContractSponsoringRateLimit', () => {
it('ensure sponsored contract can\'t be called twice without pause for free', async () => {
- await usingApi(async (api) => {
- const user = await findUnusedAddress(api);
+ await usingApi(async (api, privateKeyWrapper) => {
+ const user = await findUnusedAddress(api, privateKeyWrapper);
- const [flipper, deployer] = await deployFlipper(api);
+ const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);
await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);
await setContractSponsoringRateLimitExpectSuccess(deployer, flipper.address, 10);
await toggleFlipValueExpectSuccess(user, flipper);
@@ -39,10 +39,10 @@
});
it('ensure sponsored contract can be called twice with pause for free', async () => {
- await usingApi(async (api) => {
- const user = await findUnusedAddress(api);
+ await usingApi(async (api, privateKeyWrapper) => {
+ const user = await findUnusedAddress(api, privateKeyWrapper);
- const [flipper, deployer] = await deployFlipper(api);
+ const [flipper, deployer] = await deployFlipper(api, privateKeyWrapper);
await enableContractSponsoringExpectSuccess(deployer, flipper.address, true);
await setContractSponsoringRateLimitExpectSuccess(deployer, flipper.address, 1);
await toggleFlipValueExpectSuccess(user, flipper);
@@ -62,16 +62,16 @@
});
it('fails when called for non-contract address', async () => {
- await usingApi(async (api) => {
- const user = await findUnusedAddress(api);
+ await usingApi(async (api, privateKeyWrapper) => {
+ const user = await findUnusedAddress(api, privateKeyWrapper);
await setContractSponsoringRateLimitExpectFailure(alice, user.address, 1);
});
});
it('fails when called by non-owning user', async () => {
- await usingApi(async (api) => {
- const [flipper] = await deployFlipper(api);
+ await usingApi(async (api, privateKeyWrapper) => {
+ const [flipper] = await deployFlipper(api, privateKeyWrapper);
await setContractSponsoringRateLimitExpectFailure(alice, flipper.address, 1);
});
tests/src/substrate/substrate-api.tsdiffbeforeafterboth--- a/tests/src/substrate/substrate-api.ts
+++ b/tests/src/substrate/substrate-api.ts
@@ -88,7 +88,7 @@
await promisifySubstrate(api, async () => {
if (api) {
await api.isReadyOrError;
- const ss58Format = (api.registry.getChainProperties())!.toHuman().ss58Format;
+ const ss58Format = (api.registry.getChainProperties())!.toJSON().ss58Format;
const privateKeyWrapper = (account: string) => privateKey(account, Number(ss58Format));
result = await action(api, privateKeyWrapper);
}
tests/src/toggleContractAllowList.test.tsdiffbeforeafterboth--- a/tests/src/toggleContractAllowList.test.ts
+++ b/tests/src/toggleContractAllowList.test.ts
@@ -34,8 +34,8 @@
describe.skip('Integration Test toggleContractAllowList', () => {
it('Enable allow list contract mode', async () => {
- await usingApi(async api => {
- const [contract, deployer] = await deployFlipper(api);
+ await usingApi(async (api, privateKeyWrapper) => {
+ const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);
const enabledBefore = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();
const enableAllowListTx = api.tx.unique.toggleContractAllowList(contract.address, true);
@@ -52,7 +52,7 @@
await usingApi(async (api, privateKeyWrapper) => {
const bob = privateKeyWrapper('//Bob');
- const [contract, deployer] = await deployFlipper(api);
+ const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);
let flipValueBefore = await getFlipValue(contract, deployer);
const flip = contract.tx.flip(value, gasLimit);
@@ -111,8 +111,8 @@
});
it('Enabling allow list repeatedly should not produce errors', async () => {
- await usingApi(async api => {
- const [contract, deployer] = await deployFlipper(api);
+ await usingApi(async (api, privateKeyWrapper) => {
+ const [contract, deployer] = await deployFlipper(api, privateKeyWrapper);
const enabledBefore = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();
const enableAllowListTx = api.tx.unique.toggleContractAllowList(contract.address, true);
@@ -151,7 +151,7 @@
it('Enable allow list using a non-owner address', async () => {
await usingApi(async (api, privateKeyWrapper) => {
const bob = privateKeyWrapper('//Bob');
- const [contract] = await deployFlipper(api);
+ const [contract] = await deployFlipper(api, privateKeyWrapper);
const enabledBefore = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();
const enableAllowListTx = api.tx.unique.toggleContractAllowList(contract.address, true);
tests/src/transfer.test.tsdiffbeforeafterboth--- a/tests/src/transfer.test.ts
+++ b/tests/src/transfer.test.ts
@@ -17,7 +17,6 @@
import {ApiPromise} from '@polkadot/api';
import {IKeyringPair} from '@polkadot/types/types';
import {expect} from 'chai';
-import {alicesPublicKey, bobsPublicKey} from './accounts';
import getBalance from './substrate/get-balance';
import {default as usingApi, submitTransactionAsync} from './substrate/substrate-api';
import {
@@ -47,19 +46,24 @@
let charlie: IKeyringPair;
describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {
+ before(async () => {
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper('//Alice');
+ bob = privateKeyWrapper('//Bob');
+ });
+ });
+
it('Balance transfers and check balance', async () => {
await usingApi(async (api, privateKeyWrapper) => {
- const [alicesBalanceBefore, bobsBalanceBefore] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);
+ const [alicesBalanceBefore, bobsBalanceBefore] = await getBalance(api, [alice.address, bob.address]);
- const alicePrivateKey = privateKeyWrapper('//Alice');
-
- const transfer = api.tx.balances.transfer(bobsPublicKey, 1n);
- const events = await submitTransactionAsync(alicePrivateKey, transfer);
+ const transfer = api.tx.balances.transfer(bob.address, 1n);
+ const events = await submitTransactionAsync(alice, transfer);
const result = getCreateItemResult(events);
// tslint:disable-next-line:no-unused-expression
expect(result.success).to.be.true;
- const [alicesBalanceAfter, bobsBalanceAfter] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);
+ const [alicesBalanceAfter, bobsBalanceAfter] = await getBalance(api, [alice.address, bob.address]);
// tslint:disable-next-line:no-unused-expression
expect(alicesBalanceAfter < alicesBalanceBefore).to.be.true;
@@ -69,11 +73,11 @@
});
it('Inability to pay fees error message is correct', async () => {
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
// Find unused address
- const pk = await findUnusedAddress(api);
+ const pk = await findUnusedAddress(api, privateKeyWrapper);
- const badTransfer = api.tx.balances.transfer(bobsPublicKey, 1n);
+ const badTransfer = api.tx.balances.transfer(bob.address, 1n);
// const events = await submitTransactionAsync(pk, badTransfer);
const badTransaction = async () => {
const events = await submitTransactionAsync(pk, badTransfer);
@@ -87,8 +91,6 @@
it('User can transfer owned token', async () => {
await usingApi(async (api, privateKeyWrapper) => {
- const alice = privateKeyWrapper('//Alice');
- const bob = privateKeyWrapper('//Bob');
// nft
const nftCollectionId = await createCollectionExpectSuccess();
const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
@@ -114,8 +116,6 @@
it('Collection admin can transfer owned token', async () => {
await usingApi(async (api, privateKeyWrapper) => {
- const alice = privateKeyWrapper('//Alice');
- const bob = privateKeyWrapper('//Bob');
// nft
const nftCollectionId = await createCollectionExpectSuccess();
await addCollectionAdminExpectSuccess(alice, nftCollectionId, bob.address);
@@ -316,7 +316,6 @@
describe('Transfers to self (potentially over substrate-evm boundary)', () => {
itWeb3('Transfers to self. In case of same frontend', async ({api, privateKeyWrapper}) => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const alice = privateKeyWrapper('//Alice');
const aliceProxy = subToEth(alice.address);
const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address});
await transferExpectSuccess(collectionId, tokenId, alice, {Ethereum: aliceProxy}, 10, 'Fungible');
@@ -328,7 +327,6 @@
itWeb3('Transfers to self. In case of substrate-evm boundary', async ({api, privateKeyWrapper}) => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const alice = privateKeyWrapper('//Alice');
const aliceProxy = subToEth(alice.address);
const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address});
const balanceAliceBefore = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId);
@@ -340,7 +338,6 @@
itWeb3('Transfers to self. In case of inside substrate-evm', async ({api, privateKeyWrapper}) => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const alice = privateKeyWrapper('//Alice');
const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address});
const balanceAliceBefore = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId);
await transferExpectSuccess(collectionId, tokenId, alice, alice , 10, 'Fungible');
@@ -351,7 +348,6 @@
itWeb3('Transfers to self. In case of inside substrate-evm when not enought "Fungibles"', async ({api, privateKeyWrapper}) => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const alice = privateKeyWrapper('//Alice');
const tokenId = await createItemExpectSuccess(alice, collectionId, 'Fungible', {Substrate: alice.address});
const balanceAliceBefore = await getTokenBalance(api, collectionId, normalizeAccountId(alice), tokenId);
await transferExpectFailure(collectionId, tokenId, alice, alice , 11);
tests/src/util/contracthelpers.tsdiffbeforeafterboth--- a/tests/src/util/contracthelpers.ts
+++ b/tests/src/util/contracthelpers.ts
@@ -20,7 +20,7 @@
import fs from 'fs';
import {Abi, CodePromise, ContractPromise as Contract} from '@polkadot/api-contract';
import {IKeyringPair} from '@polkadot/types/types';
-import {ApiPromise, Keyring} from '@polkadot/api';
+import {ApiPromise} from '@polkadot/api';
chai.use(chaiAsPromised);
const expect = chai.expect;
@@ -45,13 +45,12 @@
});
}
-async function prepareDeployer(api: ApiPromise) {
+async function prepareDeployer(api: ApiPromise, privateKeyWrapper: (account: string) => IKeyringPair) {
// Find unused address
- const deployer = await findUnusedAddress(api);
+ const deployer = await findUnusedAddress(api, privateKeyWrapper);
// Transfer balance to it
- const keyring = new Keyring({type: 'sr25519'});
- const alice = keyring.addFromUri('//Alice');
+ const alice = privateKeyWrapper('//Alice');
const amount = BigInt(endowment) + 10n**15n;
const tx = api.tx.balances.transfer(deployer.address, amount);
await submitTransactionAsync(alice, tx);
@@ -59,11 +58,11 @@
return deployer;
}
-export async function deployFlipper(api: ApiPromise): Promise<[Contract, IKeyringPair]> {
+export async function deployFlipper(api: ApiPromise, privateKeyWrapper: (account: string) => IKeyringPair): Promise<[Contract, IKeyringPair]> {
const metadata = JSON.parse(fs.readFileSync('./src/flipper/metadata.json').toString('utf-8'));
const abi = new Abi(metadata);
- const deployer = await prepareDeployer(api);
+ const deployer = await prepareDeployer(api, privateKeyWrapper);
const wasm = fs.readFileSync('./src/flipper/flipper.wasm');
@@ -99,11 +98,11 @@
await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
}
-export async function deployTransferContract(api: ApiPromise): Promise<[Contract, IKeyringPair]> {
+export async function deployTransferContract(api: ApiPromise, privateKeyWrapper: (account: string) => IKeyringPair): Promise<[Contract, IKeyringPair]> {
const metadata = JSON.parse(fs.readFileSync('./src/transfer_contract/metadata.json').toString('utf-8'));
const abi = new Abi(metadata);
- const deployer = await prepareDeployer(api);
+ const deployer = await prepareDeployer(api, privateKeyWrapper);
const wasm = fs.readFileSync('./src/transfer_contract/nft_transfer.wasm');
tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -16,14 +16,13 @@
import '../interfaces/augment-api-rpc';
import '../interfaces/augment-api-query';
-import {ApiPromise, Keyring} from '@polkadot/api';
+import {ApiPromise} from '@polkadot/api';
import type {AccountId, EventRecord, Event} from '@polkadot/types/interfaces';
import {AnyTuple, IEvent, IKeyringPair} from '@polkadot/types/types';
import {evmToAddress} from '@polkadot/util-crypto';
import BN from 'bn.js';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import {alicesPublicKey} from '../accounts';
import {default as usingApi, executeTransaction, submitTransactionAsync, submitTransactionExpectFailAsync} from '../substrate/substrate-api';
import {hexToStr, strToUTF16, utf16ToStr} from './util';
import {UpDataStructsRpcCollection, UpDataStructsCreateItemData, UpDataStructsProperty} from '@polkadot/types/lookup';
@@ -40,7 +39,7 @@
export function normalizeAccountId(input: string | AccountId | CrossAccountId | IKeyringPair): CrossAccountId {
if (typeof input === 'string') {
- if (input.length === 48 || input.length === 47) {
+ if (input.length >= 47) {
return {Substrate: input};
} else if (input.length === 42 && input.startsWith('0x')) {
return {Ethereum: input.toLowerCase()};
@@ -363,7 +362,7 @@
// tslint:disable-next-line:no-unused-expression
expect(collection).to.be.not.null;
expect(collectionCountAfter).to.be.equal(collectionCountBefore + 1, 'Error: NFT collection NOT created.');
- expect(collection.owner.toString()).to.be.equal(toSubstrateAddress(alicesPublicKey));
+ expect(collection.owner.toString()).to.be.equal(toSubstrateAddress(alicePrivateKey));
expect(utf16ToStr(collection.name.toJSON() as any)).to.be.equal(name);
expect(utf16ToStr(collection.description.toJSON() as any)).to.be.equal(description);
expect(hexToStr(collection.tokenPrefix.toJSON())).to.be.equal(tokenPrefix);
@@ -411,7 +410,7 @@
// tslint:disable-next-line:no-unused-expression
expect(collection).to.be.not.null;
expect(collectionCountAfter).to.be.equal(collectionCountBefore + 1, 'Error: NFT collection NOT created.');
- expect(collection.owner.toString()).to.be.equal(toSubstrateAddress(alicesPublicKey));
+ expect(collection.owner.toString()).to.be.equal(toSubstrateAddress(alicePrivateKey));
expect(utf16ToStr(collection.name.toJSON() as any)).to.be.equal(name);
expect(utf16ToStr(collection.description.toJSON() as any)).to.be.equal(description);
expect(hexToStr(collection.tokenPrefix.toJSON())).to.be.equal(tokenPrefix);
@@ -482,13 +481,12 @@
});
}
-export async function findUnusedAddress(api: ApiPromise, seedAddition = ''): Promise<IKeyringPair> {
+export async function findUnusedAddress(api: ApiPromise, privateKeyWrapper: (account: string) => IKeyringPair, seedAddition = ''): Promise<IKeyringPair> {
let bal = 0n;
let unused;
do {
const randomSeed = 'seed' + Math.floor(Math.random() * Math.floor(10000)) + seedAddition;
- const keyring = new Keyring({type: 'sr25519'});
- unused = keyring.addFromUri(`//${randomSeed}`);
+ unused = privateKeyWrapper(`//${randomSeed}`);
bal = (await api.query.system.account(unused.address)).data.free.toBigInt();
} while (bal !== 0n);
return unused;
@@ -498,8 +496,8 @@
return (await api.rpc.unique.allowance(collectionId, normalizeAccountId(owner), normalizeAccountId(approved), tokenId)).toBigInt();
}
-export function findUnusedAddresses(api: ApiPromise, amount: number): Promise<IKeyringPair[]> {
- return Promise.all(new Array(amount).fill(null).map(() => findUnusedAddress(api, '_' + Date.now())));
+export function findUnusedAddresses(api: ApiPromise, privateKeyWrapper: (account: string) => IKeyringPair, amount: number): Promise<IKeyringPair[]> {
+ return Promise.all(new Array(amount).fill(null).map(() => findUnusedAddress(api, privateKeyWrapper, '_' + Date.now())));
}
export async function findNotExistingCollection(api: ApiPromise): Promise<number> {
tests/src/xcmTransfer.test.tsdiffbeforeafterboth--- a/tests/src/xcmTransfer.test.ts
+++ b/tests/src/xcmTransfer.test.ts
@@ -24,7 +24,6 @@
import {getGenericResult} from './util/helpers';
import waitNewBlocks from './substrate/wait-new-blocks';
import getBalance from './substrate/get-balance';
-import {alicesPublicKey} from './accounts';
chai.use(chaiAsPromised);
const expect = chai.expect;
@@ -144,7 +143,7 @@
let balanceBefore: bigint;
await usingApi(async (api) => {
- [balanceBefore] = await getBalance(api, [alicesPublicKey]);
+ [balanceBefore] = await getBalance(api, [alice.address]);
});
await usingApi(async (api) => {
@@ -181,7 +180,7 @@
await usingApi(async (api) => {
// todo do something about instant sealing, where there might not be any new blocks
await waitNewBlocks(api, 3);
- const [balanceAfter] = await getBalance(api, [alicesPublicKey]);
+ const [balanceAfter] = await getBalance(api, [alice.address]);
expect(balanceAfter > balanceBefore).to.be.true;
});
});