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.tsdiffbeforeafterboth--- a/tests/src/confirmSponsorship.test.ts
+++ b/tests/src/confirmSponsorship.test.ts
@@ -34,7 +34,6 @@
getCreatedCollectionCount,
UNIQUE,
} from './util/helpers';
-import {Keyring} from '@polkadot/api';
import {IKeyringPair} from '@polkadot/types/types';
chai.use(chaiAsPromised);
@@ -47,11 +46,10 @@
describe('integration test: ext. confirmSponsorship():', () => {
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');
});
});
@@ -78,11 +76,11 @@
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
// 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);
@@ -105,11 +103,11 @@
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
// 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, 'Fungible', zeroBalance.address);
@@ -131,11 +129,11 @@
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
// 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, 'ReFungible', zeroBalance.address);
@@ -164,11 +162,11 @@
await enablePublicMintingExpectSuccess(alice, collectionId);
// Create Item
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
const sponsorBalanceBefore = (await api.query.system.account(bob.address)).data.free.toBigInt();
// Find unused address
- const zeroBalance = await findUnusedAddress(api);
+ const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);
// Add zeroBalance address to allow list
await addToAllowListExpectSuccess(alice, collectionId, zeroBalance.address);
@@ -187,9 +185,9 @@
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
- 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 alice
const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
@@ -226,9 +224,9 @@
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
- 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, 'Fungible', zeroBalance.address);
@@ -259,9 +257,9 @@
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
- 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 alice
const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', zeroBalance.address);
@@ -299,9 +297,9 @@
// Enable public minting
await enablePublicMintingExpectSuccess(alice, collectionId);
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
// Find unused address
- const zeroBalance = await findUnusedAddress(api);
+ const zeroBalance = await findUnusedAddress(api, privateKeyWrapper);
// Add zeroBalance address to allow list
await addToAllowListExpectSuccess(alice, collectionId, zeroBalance.address);
@@ -331,11 +329,10 @@
describe('(!negative test!) integration test: ext. confirmSponsorship():', () => {
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');
});
});
@@ -390,12 +387,12 @@
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
// Find unused address
- const ownerZeroBalance = await findUnusedAddress(api);
+ const ownerZeroBalance = await findUnusedAddress(api, privateKeyWrapper);
// Find another unused address
- const senderZeroBalance = await findUnusedAddress(api);
+ const senderZeroBalance = await findUnusedAddress(api, privateKeyWrapper);
// Mint token for an unused address
const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', ownerZeroBalance.address);
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.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 {default as usingApi} from './substrate/substrate-api';18import chai from 'chai';19import {Keyring} from '@polkadot/api';20import {IKeyringPair} from '@polkadot/types/types';21import {22 createCollectionExpectSuccess,23 createItemExpectSuccess,24 addCollectionAdminExpectSuccess,25 createCollectionWithPropsExpectSuccess,26 createItemWithPropsExpectSuccess,27 createItemWithPropsExpectFailure,28} from './util/helpers';2930const expect = chai.expect;31let alice: IKeyringPair;32let bob: IKeyringPair;3334describe('integration test: ext. ():', () => {35 before(async () => {36 await usingApi(async () => {37 const keyring = new Keyring({type: 'sr25519'});38 alice = keyring.addFromUri('//Alice');39 bob = keyring.addFromUri('//Bob');40 });41 });4243 it('Create new item in NFT collection', async () => {44 const createMode = 'NFT';45 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});46 await createItemExpectSuccess(alice, newCollectionID, createMode);47 });48 it('Create new item in Fungible collection', async () => {49 const createMode = 'Fungible';50 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});51 await createItemExpectSuccess(alice, newCollectionID, createMode);52 });53 it('Create new item in ReFungible collection', async () => {54 const createMode = 'ReFungible';55 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});56 await createItemExpectSuccess(alice, newCollectionID, createMode);57 });58 it('Create new item in NFT collection with collection admin permissions', async () => {59 const createMode = 'NFT';60 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});61 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);62 await createItemExpectSuccess(bob, newCollectionID, createMode);63 });64 it('Create new item in Fungible collection with collection admin permissions', async () => {65 const createMode = 'Fungible';66 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});67 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);68 await createItemExpectSuccess(bob, newCollectionID, createMode);69 });70 it('Create new item in ReFungible collection with collection admin permissions', async () => {71 const createMode = 'ReFungible';72 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});73 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);74 await createItemExpectSuccess(bob, newCollectionID, createMode);75 });7677 it('Set property Admin', async () => {78 const createMode = 'NFT';79 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 80 propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});81 82 await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'k', value: 't2'}]);83 });8485 it('Set property AdminConst', async () => {86 const createMode = 'NFT';87 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 88 propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});89 90 await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'key1', value: 'val1'}]);91 });9293 it('Set property itemOwnerOrAdmin', async () => {94 const createMode = 'NFT';95 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode},96 propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]});97 98 await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'key1', value: 'val1'}]);99 });100});101102describe('Negative integration test: ext. createItem():', () => {103 before(async () => {104 await usingApi(async () => {105 const keyring = new Keyring({type: 'sr25519'});106 alice = keyring.addFromUri('//Alice');107 bob = keyring.addFromUri('//Bob');108 });109 });110111 it('Regular user cannot create new item in NFT collection', async () => {112 const createMode = 'NFT';113 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});114 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;115 });116 it('Regular user cannot create new item in Fungible collection', async () => {117 const createMode = 'Fungible';118 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});119 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;120 });121 it('Regular user cannot create new item in ReFungible collection', async () => {122 const createMode = 'ReFungible';123 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});124 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;125 });126127 it('No editing rights', async () => {128 await usingApi(async () => {129 const createMode = 'NFT';130 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 131 propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]});132 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);133134 await createItemWithPropsExpectFailure(bob, newCollectionID, 'NFT', [{key: 'key1', value: 'v'}]);135 });136 });137138 it('User doesnt have editing rights', async () => {139 await usingApi(async () => {140 const newCollectionID = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});141 await createItemWithPropsExpectFailure(bob, newCollectionID, 'NFT', [{key: 'key1', value: 'v'}]);142 });143 });144145 it('Adding property without access rights', async () => {146 await usingApi(async () => {147 const newCollectionID = await createCollectionWithPropsExpectSuccess();148 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);149150 await createItemWithPropsExpectFailure(bob, newCollectionID, 'NFT', [{key: 'k', value: 'v'}]);151 });152 });153154 it('Adding more than 64 prps', async () => {155 await usingApi(async () => {156 const prps = [];157158 for (let i = 0; i < 65; i++) {159 prps.push({key: `key${i}`, value: `value${i}`});160 }161162 const newCollectionID = await createCollectionWithPropsExpectSuccess();163 164 createItemWithPropsExpectFailure(alice, newCollectionID, 'NFT', prps);165 });166 });167168 it('Trying to add bigger property than allowed', async () => {169 await usingApi(async () => {170 const newCollectionID = await createCollectionWithPropsExpectSuccess();171 172 createItemWithPropsExpectFailure(alice, newCollectionID, 'NFT', [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]);173 });174 });175});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 {default as usingApi} from './substrate/substrate-api';18import chai from 'chai';19import {IKeyringPair} from '@polkadot/types/types';20import {21 createCollectionExpectSuccess,22 createItemExpectSuccess,23 addCollectionAdminExpectSuccess,24 createCollectionWithPropsExpectSuccess,25 createItemWithPropsExpectSuccess,26 createItemWithPropsExpectFailure,27} from './util/helpers';2829const expect = chai.expect;30let alice: IKeyringPair;31let bob: IKeyringPair;3233describe('integration test: ext. ():', () => {34 before(async () => {35 await usingApi(async (api, privateKeyWrapper) => {36 alice = privateKeyWrapper('//Alice');37 bob = privateKeyWrapper('//Bob');38 });39 });4041 it('Create new item in NFT collection', async () => {42 const createMode = 'NFT';43 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});44 await createItemExpectSuccess(alice, newCollectionID, createMode);45 });46 it('Create new item in Fungible collection', async () => {47 const createMode = 'Fungible';48 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});49 await createItemExpectSuccess(alice, newCollectionID, createMode);50 });51 it('Create new item in ReFungible collection', async () => {52 const createMode = 'ReFungible';53 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});54 await createItemExpectSuccess(alice, newCollectionID, createMode);55 });56 it('Create new item in NFT collection with collection admin permissions', async () => {57 const createMode = 'NFT';58 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});59 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);60 await createItemExpectSuccess(bob, newCollectionID, createMode);61 });62 it('Create new item in Fungible collection with collection admin permissions', async () => {63 const createMode = 'Fungible';64 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});65 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);66 await createItemExpectSuccess(bob, newCollectionID, createMode);67 });68 it('Create new item in ReFungible collection with collection admin permissions', async () => {69 const createMode = 'ReFungible';70 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});71 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);72 await createItemExpectSuccess(bob, newCollectionID, createMode);73 });7475 it('Set property Admin', async () => {76 const createMode = 'NFT';77 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 78 propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});79 80 await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'k', value: 't2'}]);81 });8283 it('Set property AdminConst', async () => {84 const createMode = 'NFT';85 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 86 propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});87 88 await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'key1', value: 'val1'}]);89 });9091 it('Set property itemOwnerOrAdmin', async () => {92 const createMode = 'NFT';93 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode},94 propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]});95 96 await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'key1', value: 'val1'}]);97 });98});99100describe('Negative integration test: ext. createItem():', () => {101 before(async () => {102 await usingApi(async (api, privateKeyWrapper) => {103 alice = privateKeyWrapper('//Alice');104 bob = privateKeyWrapper('//Bob');105 });106 });107108 it('Regular user cannot create new item in NFT collection', async () => {109 const createMode = 'NFT';110 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});111 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;112 });113 it('Regular user cannot create new item in Fungible collection', async () => {114 const createMode = 'Fungible';115 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});116 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;117 });118 it('Regular user cannot create new item in ReFungible collection', async () => {119 const createMode = 'ReFungible';120 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});121 await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;122 });123124 it('No editing rights', async () => {125 await usingApi(async () => {126 const createMode = 'NFT';127 const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 128 propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]});129 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);130131 await createItemWithPropsExpectFailure(bob, newCollectionID, 'NFT', [{key: 'key1', value: 'v'}]);132 });133 });134135 it('User doesnt have editing rights', async () => {136 await usingApi(async () => {137 const newCollectionID = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});138 await createItemWithPropsExpectFailure(bob, newCollectionID, 'NFT', [{key: 'key1', value: 'v'}]);139 });140 });141142 it('Adding property without access rights', async () => {143 await usingApi(async () => {144 const newCollectionID = await createCollectionWithPropsExpectSuccess();145 await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);146147 await createItemWithPropsExpectFailure(bob, newCollectionID, 'NFT', [{key: 'k', value: 'v'}]);148 });149 });150151 it('Adding more than 64 prps', async () => {152 await usingApi(async () => {153 const prps = [];154155 for (let i = 0; i < 65; i++) {156 prps.push({key: `key${i}`, value: `value${i}`});157 }158159 const newCollectionID = await createCollectionWithPropsExpectSuccess();160 161 createItemWithPropsExpectFailure(alice, newCollectionID, 'NFT', prps);162 });163 });164165 it('Trying to add bigger property than allowed', async () => {166 await usingApi(async () => {167 const newCollectionID = await createCollectionWithPropsExpectSuccess();168 169 createItemWithPropsExpectFailure(alice, newCollectionID, 'NFT', [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]);170 });171 });172});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;
});
});