difftreelog
test(ss58Format) transfer all tests to the new privateKeyWrapper method
in: master
62 files changed
tests/src/addCollectionAdmin.test.tsdiffbeforeafterboth--- a/tests/src/addCollectionAdmin.test.ts
+++ b/tests/src/addCollectionAdmin.test.ts
@@ -17,7 +17,6 @@
import {ApiPromise} from '@polkadot/api';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import privateKey from './substrate/privateKey';
import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId, queryCollectionExpectSuccess} from './util/helpers';
@@ -26,10 +25,10 @@
describe('Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {
it('Add collection admin.', async () => {
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
const collectionId = await createCollectionExpectSuccess();
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
const collection = await queryCollectionExpectSuccess(api, collectionId);
expect(collection.owner.toString()).to.be.equal(alice.address);
@@ -43,11 +42,11 @@
});
it('Add admin using added collection admin.', async () => {
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
const collectionId = await createCollectionExpectSuccess();
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
- const charlie = privateKey('//CHARLIE');
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
+ const charlie = privateKeyWrapper!('//CHARLIE');
const collection = await queryCollectionExpectSuccess(api, collectionId);
expect(collection.owner.toString()).to.be.equal(alice.address);
@@ -69,10 +68,10 @@
describe('Negative Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {
it("Not owner can't add collection admin.", async () => {
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
const collectionId = await createCollectionExpectSuccess();
- const alice = privateKey('//Alice');
- const nonOwner = privateKey('//Bob_stash');
+ const alice = privateKeyWrapper!('//Alice');
+ const nonOwner = privateKeyWrapper!('//Bob_stash');
const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(alice.address));
await expect(submitTransactionExpectFailAsync(nonOwner, changeAdminTx)).to.be.rejected;
@@ -85,11 +84,11 @@
});
});
it("Can't add collection admin of not existing collection.", async () => {
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
// tslint:disable-next-line: no-bitwise
const collectionId = (1 << 32) - 1;
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
const changeOwnerTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));
await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;
@@ -100,10 +99,10 @@
});
it("Can't add an admin to a destroyed collection.", async () => {
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
const collectionId = await createCollectionExpectSuccess();
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
await destroyCollectionExpectSuccess(collectionId);
const changeOwnerTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));
await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;
@@ -114,16 +113,16 @@
});
it('Add an admin to a collection that has reached the maximum number of admins limit', async () => {
- await usingApi(async (api: ApiPromise) => {
- const alice = privateKey('//Alice');
+ await usingApi(async (api: ApiPromise, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
const accounts = [
- privateKey('//AdminTest/1').address,
- privateKey('//AdminTest/2').address,
- privateKey('//AdminTest/3').address,
- privateKey('//AdminTest/4').address,
- privateKey('//AdminTest/5').address,
- privateKey('//AdminTest/6').address,
- privateKey('//AdminTest/7').address,
+ privateKeyWrapper!('//AdminTest/1').address,
+ privateKeyWrapper!('//AdminTest/2').address,
+ privateKeyWrapper!('//AdminTest/3').address,
+ privateKeyWrapper!('//AdminTest/4').address,
+ privateKeyWrapper!('//AdminTest/5').address,
+ privateKeyWrapper!('//AdminTest/6').address,
+ privateKeyWrapper!('//AdminTest/7').address,
];
const collectionId = await createCollectionExpectSuccess();
tests/src/addToAllowList.test.tsdiffbeforeafterboth--- a/tests/src/addToAllowList.test.ts
+++ b/tests/src/addToAllowList.test.ts
@@ -17,7 +17,6 @@
import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import privateKey from './substrate/privateKey';
import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';
import {
addToAllowListExpectSuccess,
@@ -42,9 +41,9 @@
describe('Integration Test ext. addToAllowList()', () => {
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
});
});
@@ -65,10 +64,10 @@
describe('Negative Integration Test ext. addToAllowList()', () => {
it('Allow list an address in the collection that does not exist', async () => {
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
// tslint:disable-next-line: no-bitwise
const collectionId = await getCreatedCollectionCount(api) + 1;
- const bob = privateKey('//Bob');
+ const bob = privateKeyWrapper!('//Bob');
const tx = api.tx.unique.addToAllowList(collectionId, normalizeAccountId(bob.address));
await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
@@ -76,9 +75,9 @@
});
it('Allow list an address in the collection that was destroyed', async () => {
- await usingApi(async (api) => {
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
// tslint:disable-next-line: no-bitwise
const collectionId = await createCollectionExpectSuccess();
await destroyCollectionExpectSuccess(collectionId);
@@ -88,9 +87,9 @@
});
it('Allow list an address in the collection that does not have allow list access enabled', async () => {
- await usingApi(async (api) => {
- const alice = privateKey('//Alice');
- const ferdie = privateKey('//Ferdie');
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
+ const ferdie = privateKeyWrapper!('//Ferdie');
const collectionId = await createCollectionExpectSuccess();
await enableAllowListExpectSuccess(alice, collectionId);
await enablePublicMintingExpectSuccess(alice, collectionId);
@@ -104,10 +103,10 @@
describe('Integration Test ext. addToAllowList() with collection admin permissions:', () => {
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
+ charlie = privateKeyWrapper!('//Charlie');
});
});
tests/src/addToContractAllowList.test.tsdiffbeforeafterboth--- a/tests/src/addToContractAllowList.test.ts
+++ b/tests/src/addToContractAllowList.test.ts
@@ -17,7 +17,6 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
-import privateKey from './substrate/privateKey';
import {
deployFlipper,
} from './util/contracthelpers';
@@ -31,8 +30,8 @@
describe.skip('Integration Test addToContractAllowList', () => {
it('Add an address to a contract allow list', async () => {
- await usingApi(async api => {
- const bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ const bob = privateKeyWrapper!('//Bob');
const [contract, deployer] = await deployFlipper(api);
const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();
@@ -47,8 +46,8 @@
});
it('Adding same address to allow list repeatedly should not produce errors', async () => {
- await usingApi(async api => {
- const bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ const bob = privateKeyWrapper!('//Bob');
const [contract, deployer] = await deployFlipper(api);
const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();
@@ -70,10 +69,10 @@
describe.skip('Negative Integration Test addToContractAllowList', () => {
it('Add an address to a allow list of a non-contract', async () => {
- await usingApi(async api => {
- const alice = privateKey('//Bob');
- const bob = privateKey('//Bob');
- const charlieGuineaPig = privateKey('//Charlie');
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Bob');
+ const bob = privateKeyWrapper!('//Bob');
+ const charlieGuineaPig = privateKeyWrapper!('//Charlie');
const allowListedBefore = (await api.query.unique.contractAllowList(charlieGuineaPig.address, bob.address)).toJSON();
const addTx = api.tx.unique.addToContractAllowList(charlieGuineaPig.address, bob.address);
@@ -86,8 +85,8 @@
});
it('Add to a contract allow list using a non-owner address', async () => {
- await usingApi(async api => {
- const bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ const bob = privateKeyWrapper!('//Bob');
const [contract] = await deployFlipper(api);
const allowListedBefore = (await api.query.unique.contractAllowList(contract.address, bob.address)).toJSON();
tests/src/allowLists.test.tsdiffbeforeafterboth--- a/tests/src/allowLists.test.ts
+++ b/tests/src/allowLists.test.ts
@@ -17,7 +17,6 @@
import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import privateKey from './substrate/privateKey';
import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';
import {
addToAllowListExpectSuccess,
@@ -50,10 +49,10 @@
describe('Integration Test ext. Allow list tests', () => {
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
+ charlie = privateKeyWrapper!('//Charlie');
});
});
tests/src/approve.test.tsdiffbeforeafterboth--- a/tests/src/approve.test.ts
+++ b/tests/src/approve.test.ts
@@ -18,7 +18,6 @@
import {ApiPromise} from '@polkadot/api';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import privateKey from './substrate/privateKey';
import {default as usingApi} from './substrate/substrate-api';
import {
approveExpectFail,
@@ -43,10 +42,10 @@
let charlie: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
+ charlie = privateKeyWrapper!('//Charlie');
});
});
@@ -99,10 +98,10 @@
let charlie: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
+ charlie = privateKeyWrapper!('//Charlie');
});
});
@@ -131,10 +130,10 @@
let charlie: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
+ charlie = privateKeyWrapper!('//Charlie');
});
});
@@ -166,10 +165,10 @@
let charlie: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
+ charlie = privateKeyWrapper!('//Charlie');
});
});
@@ -205,11 +204,11 @@
let dave: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
- dave = privateKey('//Dave');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
+ charlie = privateKeyWrapper!('//Charlie');
+ dave = privateKeyWrapper!('//Dave');
});
});
@@ -228,10 +227,10 @@
let charlie: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
+ charlie = privateKeyWrapper!('//Charlie');
});
});
@@ -267,10 +266,10 @@
let charlie: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
+ charlie = privateKeyWrapper!('//Charlie');
});
});
@@ -300,11 +299,11 @@
let dave: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
- dave = privateKey('//Dave');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
+ charlie = privateKeyWrapper!('//Charlie');
+ dave = privateKeyWrapper!('//Dave');
});
});
@@ -340,11 +339,11 @@
let dave: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
- dave = privateKey('//Dave');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
+ charlie = privateKeyWrapper!('//Charlie');
+ dave = privateKeyWrapper!('//Dave');
});
});
@@ -391,10 +390,10 @@
let charlie: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
+ charlie = privateKeyWrapper!('//Charlie');
});
});
@@ -413,10 +412,10 @@
let charlie: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
+ charlie = privateKeyWrapper!('//Charlie');
});
});
tests/src/change-collection-owner.test.tsdiffbeforeafterboth--- a/tests/src/change-collection-owner.test.ts
+++ b/tests/src/change-collection-owner.test.ts
@@ -16,7 +16,6 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import privateKey from './substrate/privateKey';
import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
import {createCollectionExpectSuccess,
addCollectionAdminExpectSuccess,
@@ -41,10 +40,10 @@
describe('Integration Test changeCollectionOwner(collection_id, new_owner):', () => {
it('Changing owner changes owner address', async () => {
- await usingApi(async api => {
+ await usingApi(async (api, privateKeyWrapper) => {
const collectionId = await createCollectionExpectSuccess();
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
const collection =await queryCollectionExpectSuccess(api, collectionId);
expect(collection.owner.toString()).to.be.deep.eq(alice.address);
@@ -60,10 +59,10 @@
describe('Integration Test changeCollectionOwner(collection_id, new_owner) special checks for exOwner:', () => {
it('Changing the owner of the collection is not allowed for the former owner', async () => {
- await usingApi(async api => {
+ await usingApi(async (api, privateKeyWrapper) => {
const collectionId = await createCollectionExpectSuccess();
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
const collection = await queryCollectionExpectSuccess(api, collectionId);
expect(collection.owner.toString()).to.be.deep.eq(alice.address);
@@ -80,11 +79,11 @@
});
it('New collectionOwner has access to sponsorship management operations in the collection', async () => {
- await usingApi(async api => {
+ await usingApi(async (api, privateKeyWrapper) => {
const collectionId = await createCollectionExpectSuccess();
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
- const charlie = privateKey('//Charlie');
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
+ const charlie = privateKeyWrapper!('//Charlie');
const collection = await queryCollectionExpectSuccess(api, collectionId);
expect(collection.owner.toString()).to.be.deep.eq(alice.address);
@@ -124,11 +123,11 @@
});
it('New collectionOwner has access to changeCollectionOwner', async () => {
- await usingApi(async api => {
+ await usingApi(async (api, privateKeyWrapper) => {
const collectionId = await createCollectionExpectSuccess();
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
- const charlie = privateKey('//Charlie');
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
+ const charlie = privateKeyWrapper!('//Charlie');
const collection = await queryCollectionExpectSuccess(api, collectionId);
expect(collection.owner.toString()).to.be.deep.eq(alice.address);
@@ -151,10 +150,10 @@
describe('Negative Integration Test changeCollectionOwner(collection_id, new_owner):', () => {
it('Not owner can\'t change owner.', async () => {
- await usingApi(async api => {
+ await usingApi(async (api, privateKeyWrapper) => {
const collectionId = await createCollectionExpectSuccess();
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);
await expect(submitTransactionExpectFailAsync(bob, changeOwnerTx)).to.be.rejected;
@@ -168,10 +167,10 @@
});
it('Collection admin can\'t change owner.', async () => {
- await usingApi(async api => {
+ await usingApi(async (api, privateKeyWrapper) => {
const collectionId = await createCollectionExpectSuccess();
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
@@ -187,10 +186,10 @@
});
it('Can\'t change owner of a non-existing collection.', async () => {
- await usingApi(async api => {
+ await usingApi(async (api, privateKeyWrapper) => {
const collectionId = (1<<32) - 1;
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
const changeOwnerTx = api.tx.unique.changeCollectionOwner(collectionId, bob.address);
await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;
@@ -201,11 +200,11 @@
});
it('Former collectionOwner not allowed to sponsorship management operations in the collection', async () => {
- await usingApi(async api => {
+ await usingApi(async (api, privateKeyWrapper) => {
const collectionId = await createCollectionExpectSuccess();
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
- const charlie = privateKey('//Charlie');
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
+ const charlie = privateKeyWrapper!('//Charlie');
const collection = await queryCollectionExpectSuccess(api, collectionId);
expect(collection.owner.toString()).to.be.deep.eq(alice.address);
tests/src/check-event/burnItemEvent.test.tsdiffbeforeafterboth--- a/tests/src/check-event/burnItemEvent.test.ts
+++ b/tests/src/check-event/burnItemEvent.test.ts
@@ -19,7 +19,6 @@
import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import privateKey from '../substrate/privateKey';
import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
import {createCollectionExpectSuccess, createItemExpectSuccess, uniqueEventMessage} from '../util/helpers';
@@ -32,8 +31,8 @@
const checkTreasury = 'Deposit';
const checkSystem = 'ExtrinsicSuccess';
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
});
});
it('Check event from burnItem(): ', async () => {
tests/src/check-event/createCollectionEvent.test.tsdiffbeforeafterboth--- a/tests/src/check-event/createCollectionEvent.test.ts
+++ b/tests/src/check-event/createCollectionEvent.test.ts
@@ -19,7 +19,6 @@
import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import privateKey from '../substrate/privateKey';
import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
import {uniqueEventMessage} from '../util/helpers';
@@ -32,8 +31,8 @@
const checkTreasury = 'Deposit';
const checkSystem = 'ExtrinsicSuccess';
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
});
});
it('Check event from createCollection(): ', async () => {
tests/src/check-event/createItemEvent.test.tsdiffbeforeafterboth--- a/tests/src/check-event/createItemEvent.test.ts
+++ b/tests/src/check-event/createItemEvent.test.ts
@@ -19,7 +19,6 @@
import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import privateKey from '../substrate/privateKey';
import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
import {createCollectionExpectSuccess, uniqueEventMessage, normalizeAccountId} from '../util/helpers';
@@ -32,8 +31,8 @@
const checkTreasury = 'Deposit';
const checkSystem = 'ExtrinsicSuccess';
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
});
});
it('Check event from createItem(): ', async () => {
tests/src/check-event/createMultipleItemsEvent.test.tsdiffbeforeafterboth--- a/tests/src/check-event/createMultipleItemsEvent.test.ts
+++ b/tests/src/check-event/createMultipleItemsEvent.test.ts
@@ -19,7 +19,6 @@
import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import privateKey from '../substrate/privateKey';
import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
import {createCollectionExpectSuccess, uniqueEventMessage, normalizeAccountId} from '../util/helpers';
@@ -32,8 +31,8 @@
const checkTreasury = 'Deposit';
const checkSystem = 'ExtrinsicSuccess';
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
});
});
it('Check event from createMultipleItems(): ', async () => {
tests/src/check-event/destroyCollectionEvent.test.tsdiffbeforeafterboth--- a/tests/src/check-event/destroyCollectionEvent.test.ts
+++ b/tests/src/check-event/destroyCollectionEvent.test.ts
@@ -19,7 +19,6 @@
import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import privateKey from '../substrate/privateKey';
import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
import {createCollectionExpectSuccess, uniqueEventMessage} from '../util/helpers';
@@ -31,8 +30,8 @@
const checkTreasury = 'Deposit';
const checkSystem = 'ExtrinsicSuccess';
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
});
});
it('Check event from destroyCollection(): ', async () => {
tests/src/check-event/transferEvent.test.tsdiffbeforeafterboth--- a/tests/src/check-event/transferEvent.test.ts
+++ b/tests/src/check-event/transferEvent.test.ts
@@ -19,7 +19,6 @@
import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import privateKey from '../substrate/privateKey';
import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
import {createCollectionExpectSuccess, createItemExpectSuccess, uniqueEventMessage, normalizeAccountId} from '../util/helpers';
@@ -33,9 +32,9 @@
const checkTreasury = 'Deposit';
const checkSystem = 'ExtrinsicSuccess';
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
});
});
it('Check event from transfer(): ', async () => {
tests/src/check-event/transferFromEvent.test.tsdiffbeforeafterboth--- a/tests/src/check-event/transferFromEvent.test.ts
+++ b/tests/src/check-event/transferFromEvent.test.ts
@@ -19,7 +19,6 @@
import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import privateKey from '../substrate/privateKey';
import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
import {createCollectionExpectSuccess, createItemExpectSuccess, uniqueEventMessage, normalizeAccountId} from '../util/helpers';
@@ -33,9 +32,9 @@
const checkTreasury = 'Deposit';
const checkSystem = 'ExtrinsicSuccess';
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
});
});
it('Check event from transferFrom(): ', async () => {
tests/src/contracts.test.tsdiffbeforeafterboth--- a/tests/src/contracts.test.ts
+++ b/tests/src/contracts.test.ts
@@ -50,11 +50,11 @@
describe.skip('Contracts', () => {
it('Can deploy smart contract Flipper, instantiate it and call it\'s get and flip messages.', async () => {
- await usingApi(async api => {
+ await usingApi(async (api, privateKeyWrapper) => {
const [contract, deployer] = await deployFlipper(api);
const initialGetResponse = await getFlipValue(contract, deployer);
- const bob = privateKey('//Bob');
+ const bob = privateKeyWrapper!('//Bob');
const flip = contract.tx.flip(value, gasLimit);
await submitTransactionAsync(bob, flip);
@@ -76,9 +76,9 @@
describe.skip('Chain extensions', () => {
it('Transfer CE', async () => {
- await usingApi(async api => {
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
// Prep work
const collectionId = await createCollectionExpectSuccess();
@@ -100,9 +100,9 @@
});
it('Mint CE', async () => {
- await usingApi(async api => {
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
const collectionId = await createCollectionExpectSuccess();
const [contract] = await deployTransferContract(api);
@@ -127,9 +127,9 @@
});
it('Bulk mint CE', async () => {
- await usingApi(async api => {
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
const collectionId = await createCollectionExpectSuccess();
const [contract] = await deployTransferContract(api);
@@ -168,10 +168,10 @@
});
it('Approve CE', async () => {
- await usingApi(async api => {
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
- const charlie = privateKey('//Charlie');
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
+ const charlie = privateKeyWrapper!('//Charlie');
const collectionId = await createCollectionExpectSuccess();
const [contract] = await deployTransferContract(api);
@@ -187,10 +187,10 @@
});
it('TransferFrom CE', async () => {
- await usingApi(async api => {
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
- const charlie = privateKey('//Charlie');
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
+ const charlie = privateKeyWrapper!('//Charlie');
const collectionId = await createCollectionExpectSuccess();
const [contract] = await deployTransferContract(api);
@@ -208,9 +208,9 @@
});
it('ToggleAllowList CE', async () => {
- await usingApi(async api => {
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
const collectionId = await createCollectionExpectSuccess();
const [contract] = await deployTransferContract(api);
tests/src/createCollection.test.tsdiffbeforeafterboth--- a/tests/src/createCollection.test.ts
+++ b/tests/src/createCollection.test.ts
@@ -15,7 +15,6 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {expect} from 'chai';
-import privateKey from './substrate/privateKey';
import usingApi, {executeTransaction, submitTransactionAsync} from './substrate/substrate-api';
import {createCollectionWithPropsExpectFailure, createCollectionExpectFailure, createCollectionExpectSuccess, getCreateCollectionResult, getDetailedCollectionInfo, createCollectionWithPropsExpectSuccess} from './util/helpers';
@@ -58,9 +57,9 @@
});
it('Create new collection with extra fields', async () => {
- await usingApi(async api => {
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
const tx = api.tx.unique.createCollectionEx({
mode: {Fungible: 8},
permissions: {
@@ -101,8 +100,8 @@
await createCollectionExpectFailure({tokenPrefix: 'A'.repeat(17), mode: {type: 'NFT'}});
});
it('fails when bad limits are set', async () => {
- await usingApi(async api => {
- const alice = privateKey('//Alice');
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
const tx = api.tx.unique.createCollectionEx({mode: 'NFT', limits: {tokenLimit: 0}});
await expect(executeTransaction(api, alice, tx)).to.be.rejectedWith(/^common.CollectionTokenLimitExceeded$/);
});
tests/src/createMultipleItems.test.tsdiffbeforeafterboth--- a/tests/src/createMultipleItems.test.ts
+++ b/tests/src/createMultipleItems.test.ts
@@ -18,7 +18,6 @@
import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import privateKey from './substrate/privateKey';
import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync, executeTransaction} from './substrate/substrate-api';
import {
createCollectionExpectSuccess,
@@ -41,12 +40,12 @@
describe('Integration Test createMultipleItems(collection_id, owner, items_data):', () => {
it('Create 0x31, 0x32, 0x33 items in active NFT collection and verify tokens data in chain', async () => {
- await usingApi(async (api: ApiPromise) => {
+ await usingApi(async (api, privateKeyWrapper) => {
const collectionId = await createCollectionExpectSuccess();
const itemsListIndexBefore = await getLastTokenId(api, collectionId);
expect(itemsListIndexBefore).to.be.equal(0);
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
await submitTransactionAsync(
alice,
api.tx.unique.setPropertyPermissions(collectionId, [{key: 'data', permission: {tokenOwner: true}}]),
@@ -73,11 +72,11 @@
});
it('Create 0x01, 0x02, 0x03 items in active Fungible collection and verify tokens data in chain', async () => {
- await usingApi(async (api: ApiPromise) => {
+ await usingApi(async (api, privateKeyWrapper) => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
const itemsListIndexBefore = await getLastTokenId(api, collectionId);
expect(itemsListIndexBefore).to.be.equal(0);
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const args = [
{Fungible: {value: 1}},
{Fungible: {value: 2}},
@@ -93,11 +92,11 @@
});
it('Create 0x31, 0x32, 0x33 items in active ReFungible collection and verify tokens data in chain', async () => {
- await usingApi(async (api: ApiPromise) => {
+ await usingApi(async (api, privateKeyWrapper) => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
const itemsListIndexBefore = await getLastTokenId(api, collectionId);
expect(itemsListIndexBefore).to.be.equal(0);
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const args = [
{ReFungible: {pieces: 1}},
{ReFungible: {pieces: 2}},
@@ -116,8 +115,8 @@
});
it('Can mint amount of items equals to collection limits', async () => {
- await usingApi(async (api) => {
- const alice = privateKey('//Alice');
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
const collectionId = await createCollectionExpectSuccess();
await setCollectionLimitsExpectSuccess(alice, collectionId, {
@@ -135,11 +134,11 @@
});
it('Create 0x31, 0x32, 0x33 items in active NFT with property Admin', async () => {
- await usingApi(async (api: ApiPromise) => {
+ await usingApi(async (api, privateKeyWrapper) => {
const collectionId = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});
const itemsListIndexBefore = await getLastTokenId(api, collectionId);
expect(itemsListIndexBefore).to.be.equal(0);
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const args = [
{NFT: {properties: [{key: 'k', value: 'v1'}]}},
{NFT: {properties: [{key: 'k', value: 'v2'}]}},
@@ -161,12 +160,12 @@
});
it('Create 0x31, 0x32, 0x33 items in active NFT with property AdminConst', async () => {
- await usingApi(async (api: ApiPromise) => {
+ await usingApi(async (api, privateKeyWrapper) => {
const collectionId = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});
const itemsListIndexBefore = await getLastTokenId(api, collectionId);
expect(itemsListIndexBefore).to.be.equal(0);
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
const args = [
{NFT: {properties: [{key: 'k', value: 'v1'}]}},
@@ -189,11 +188,11 @@
});
it('Create 0x31, 0x32, 0x33 items in active NFT with property itemOwnerOrAdmin', async () => {
- await usingApi(async (api: ApiPromise) => {
+ await usingApi(async (api, privateKeyWrapper) => {
const collectionId = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]});
const itemsListIndexBefore = await getLastTokenId(api, collectionId);
expect(itemsListIndexBefore).to.be.equal(0);
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const args = [
{NFT: {properties: [{key: 'k', value: 'v1'}]}},
{NFT: {properties: [{key: 'k', value: 'v2'}]}},
@@ -220,9 +219,9 @@
let bob: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
});
});
@@ -302,9 +301,9 @@
let bob: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
});
});
@@ -360,12 +359,12 @@
});
it('Create NFT and Re-fungible tokens that has reached the maximum data limit', async () => {
- await usingApi(async (api: ApiPromise) => {
+ await usingApi(async (api, privateKeyWrapper) => {
// NFT
const collectionId = await createCollectionWithPropsExpectSuccess({
propPerm: [{key: 'key', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}],
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const args = [
{NFT: {properties: [{key: 'key', value: 'A'.repeat(32769)}]}},
{NFT: {properties: [{key: 'key', value: 'B'.repeat(32769)}]}},
tests/src/createMultipleItemsEx.test.tsdiffbeforeafterboth--- a/tests/src/createMultipleItemsEx.test.ts
+++ b/tests/src/createMultipleItemsEx.test.ts
@@ -15,17 +15,16 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {expect} from 'chai';
-import privateKey from './substrate/privateKey';
import usingApi, {executeTransaction} from './substrate/substrate-api';
-import {createCollectionExpectSuccess, createCollectionWithPropsExpectSuccess, addCollectionAdminExpectSuccess} from './util/helpers';
+import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess, createCollectionWithPropsExpectSuccess} from './util/helpers';
describe('createMultipleItemsEx', () => {
it('can initialize multiple NFT with different owners', async () => {
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
- const charlie = privateKey('//Charlie');
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
+ const charlie = privateKeyWrapper!('//Charlie');
const data = [
{
owner: {substrate: alice.address},
@@ -47,10 +46,10 @@
it('createMultipleItemsEx with property Admin', async () => {
const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
- const charlie = privateKey('//Charlie');
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
+ const charlie = privateKeyWrapper!('//Charlie');
const data = [
{
owner: {substrate: alice.address},
@@ -75,10 +74,10 @@
it('createMultipleItemsEx with property AdminConst', async () => {
const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
- const charlie = privateKey('//Charlie');
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
+ const charlie = privateKeyWrapper!('//Charlie');
const data = [
{
owner: {substrate: alice.address},
@@ -103,10 +102,10 @@
it('createMultipleItemsEx with property itemOwnerOrAdmin', async () => {
const collection = await createCollectionWithPropsExpectSuccess({mode: {type: 'NFT'}, propPerm: [{key: 'k', permission: {mutable: false, collectionAdmin: true, tokenOwner: true}}]});
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
- const charlie = privateKey('//Charlie');
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
+ const charlie = privateKeyWrapper!('//Charlie');
const data = [
{
owner: {substrate: alice.address},
@@ -132,11 +131,11 @@
it('No editing rights', async () => {
const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],
propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
- const charlie = privateKey('//Charlie');
- await addCollectionAdminExpectSuccess(alice, collection, bob.address);
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
+ const charlie = privateKeyWrapper!('//Charlie');
+ await addCollectionAdminExpectSuccess(alice, collection, bob.address);
const data = [
{
owner: {substrate: alice.address},
@@ -161,10 +160,10 @@
it('User doesnt have editing rights', async () => {
const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}],
propPerm: [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]});
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
- await addCollectionAdminExpectSuccess(alice, collection, bob.address);
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
+ await addCollectionAdminExpectSuccess(alice, collection, bob.address);
const data = [
{
owner: {substrate: alice.address},
@@ -188,11 +187,11 @@
it('Adding property without access rights', async () => {
const collection = await createCollectionWithPropsExpectSuccess({properties: [{key: 'key1', value: 'v'}]});
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
- const charlie = privateKey('//Charlie');
- await addCollectionAdminExpectSuccess(alice, collection, bob.address);
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
+ const charlie = privateKeyWrapper!('//Charlie');
+ await addCollectionAdminExpectSuccess(alice, collection, bob.address);
const data = [
{
owner: {substrate: alice.address},
@@ -220,20 +219,20 @@
propPerms.push({key: `key${i}`, permission: {mutable: true, collectionAdmin: true, tokenOwner: true}});
}
- const alice = privateKey('//Alice');
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
await expect(executeTransaction(api, alice, api.tx.unique.setPropertyPermissions(collection, propPerms))).to.be.rejectedWith(/common\.PropertyLimitReached/);
});
});
it('Trying to add bigger property than allowed', async () => {
const collection = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]});
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
- const charlie = privateKey('//Charlie');
- await addCollectionAdminExpectSuccess(alice, collection, bob.address);
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
+ const charlie = privateKeyWrapper!('//Charlie');
+ await addCollectionAdminExpectSuccess(alice, collection, bob.address);
const data = [
{
owner: {substrate: alice.address}, properties: [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}],
@@ -253,10 +252,10 @@
it('can initialize multiple NFT with different owners', async () => {
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
- const charlie = privateKey('//Charlie');
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
+ const charlie = privateKeyWrapper!('//Charlie');
const data = [
{
owner: {substrate: alice.address},
@@ -278,10 +277,10 @@
it('can initialize multiple NFT with different owners', async () => {
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
- const charlie = privateKey('//Charlie');
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
+ const charlie = privateKeyWrapper!('//Charlie');
const data = [
{
owner: {substrate: alice.address},
@@ -303,10 +302,10 @@
it('fails when trying to set multiple owners when creating multiple refungibles', async () => {
const collection = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
-
- await usingApi(async (api) => {
+
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
// Polkadot requires map, and yet requires keys to be JSON encoded
const users = new Map();
users.set(JSON.stringify({substrate: alice.address}), 1);
tests/src/creditFeesToTreasury.test.tsdiffbeforeafterboth--- a/tests/src/creditFeesToTreasury.test.ts
+++ b/tests/src/creditFeesToTreasury.test.ts
@@ -19,7 +19,6 @@
import chaiAsPromised from 'chai-as-promised';
import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
import {alicesPublicKey, bobsPublicKey} from './accounts';
-import privateKey from './substrate/privateKey';
import {IKeyringPair} from '@polkadot/types/types';
import {
createCollectionExpectSuccess,
@@ -65,20 +64,20 @@
describe('integration test: Fees must be credited to Treasury:', () => {
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
});
});
it('Total issuance does not change', async () => {
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
await skipInflationBlock(api);
await waitNewBlocks(api, 1);
const totalBefore = (await api.query.balances.totalIssuance()).toBigInt();
- const alicePrivateKey = privateKey('//Alice');
+ const alicePrivateKey = privateKeyWrapper!('//Alice');
const amount = 1n;
const transfer = api.tx.balances.transfer(bobsPublicKey, amount);
@@ -92,11 +91,11 @@
});
it('Sender balance decreased by fee+sent amount, Treasury balance increased by fee', async () => {
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
await skipInflationBlock(api);
await waitNewBlocks(api, 1);
- const alicePrivateKey = privateKey('//Alice');
+ 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();
@@ -115,11 +114,11 @@
});
it('Treasury balance increased by failed tx fee', async () => {
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
//await skipInflationBlock(api);
await waitNewBlocks(api, 1);
- const bobPrivateKey = privateKey('//Bob');
+ 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();
tests/src/destroyCollection.test.tsdiffbeforeafterboth--- a/tests/src/destroyCollection.test.ts
+++ b/tests/src/destroyCollection.test.ts
@@ -17,7 +17,6 @@
import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import privateKey from './substrate/privateKey';
import {default as usingApi} from './substrate/substrate-api';
import {createCollectionExpectSuccess,
destroyCollectionExpectSuccess,
@@ -50,9 +49,9 @@
let bob: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
});
});
tests/src/enableContractSponsoring.test.tsdiffbeforeafterboth--- a/tests/src/enableContractSponsoring.test.ts
+++ b/tests/src/enableContractSponsoring.test.ts
@@ -17,7 +17,6 @@
import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import privateKey from './substrate/privateKey';
import usingApi from './substrate/substrate-api';
import {deployFlipper, getFlipValue, toggleFlipValueExpectSuccess} from './util/contracthelpers';
import {
@@ -79,7 +78,9 @@
let alice: IKeyringPair;
before(async () => {
- alice = privateKey('//Alice');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ });
});
it('fails when called for non-contract address', async () => {
tests/src/enableDisableTransfer.test.tsdiffbeforeafterboth--- a/tests/src/enableDisableTransfer.test.ts
+++ b/tests/src/enableDisableTransfer.test.ts
@@ -16,7 +16,6 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import privateKey from './substrate/privateKey';
import usingApi from './substrate/substrate-api';
import {
createItemExpectSuccess,
@@ -31,9 +30,9 @@
describe('Enable/Disable Transfers', () => {
it('User can transfer token with enabled transfer flag', async () => {
- await usingApi(async () => {
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ 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');
@@ -46,9 +45,9 @@
});
it('User can\'n transfer token with disabled transfer flag', async () => {
- await usingApi(async () => {
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ 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');
@@ -63,8 +62,8 @@
describe('Negative Enable/Disable Transfers', () => {
it('Non-owner cannot change transfer flag', async () => {
- await usingApi(async () => {
- const bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ const bob = privateKeyWrapper!('//Bob');
// nft
const nftCollectionId = await createCollectionExpectSuccess();
tests/src/eth/base.test.tsdiffbeforeafterboth--- a/tests/src/eth/base.test.ts
+++ b/tests/src/eth/base.test.ts
@@ -28,7 +28,6 @@
import {expect} from 'chai';
import {createCollectionExpectSuccess, createItemExpectSuccess, UNIQUE} from '../util/helpers';
import nonFungibleAbi from './nonFungibleAbi.json';
-import privateKey from '../substrate/privateKey';
import {Contract} from 'web3-eth-contract';
import Web3 from 'web3';
@@ -50,11 +49,11 @@
expect(cost - balanceB < BigInt(0.2 * Number(UNIQUE))).to.be.true;
});
- itWeb3('NFT transfer is close to 0.15 UNQ', async ({web3, api}) => {
+ itWeb3('NFT transfer is close to 0.15 UNQ', async ({web3, api, privateKeyWrapper}) => {
const caller = await createEthAccountWithBalance(api, web3);
const receiver = createEthAccount(web3);
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const collection = await createCollectionExpectSuccess({
mode: {type: 'NFT'},
});
tests/src/eth/collectionProperties.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionProperties.test.ts
+++ b/tests/src/eth/collectionProperties.test.ts
@@ -1,4 +1,3 @@
-import privateKey from '../substrate/privateKey';
import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess} from '../util/helpers';
import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3} from './util/helpers';
import nonFungibleAbi from './nonFungibleAbi.json';
@@ -6,8 +5,8 @@
import {executeTransaction} from '../substrate/substrate-api';
describe('EVM collection properties', () => {
- itWeb3('Can be set', async({web3, api}) => {
- const alice = privateKey('//Alice');
+ itWeb3('Can be set', async({web3, api, privateKeyWrapper}) => {
+ const alice = privateKeyWrapper!('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
@@ -21,8 +20,8 @@
const [{value}] = (await api.rpc.unique.collectionProperties(collection, ['testKey'])).toHuman()! as any;
expect(value).to.equal('testValue');
});
- itWeb3('Can be deleted', async({web3, api}) => {
- const alice = privateKey('//Alice');
+ itWeb3('Can be deleted', async({web3, api, privateKeyWrapper}) => {
+ const alice = privateKeyWrapper!('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
@@ -38,8 +37,8 @@
const result = (await api.rpc.unique.collectionProperties(collection, ['testKey'])).toJSON()! as any;
expect(result.length).to.equal(0);
});
- itWeb3('Can be read', async({web3, api}) => {
- const alice = privateKey('//Alice');
+ itWeb3('Can be read', async({web3, api, privateKeyWrapper}) => {
+ const alice = privateKeyWrapper!('//Alice');
const caller = createEthAccount(web3);
const collection = await createCollectionExpectSuccess({mode: {type:'NFT'}});
tests/src/eth/collectionSponsoring.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionSponsoring.test.ts
+++ b/tests/src/eth/collectionSponsoring.test.ts
@@ -1,12 +1,11 @@
-import privateKey from '../substrate/privateKey';
import {addToAllowListExpectSuccess, confirmSponsorshipExpectSuccess, createCollectionExpectSuccess, enablePublicMintingExpectSuccess, setCollectionSponsorExpectSuccess} from '../util/helpers';
import {itWeb3, createEthAccount, collectionIdToAddress, GAS_ARGS, normalizeEvents} from './util/helpers';
import nonFungibleAbi from './nonFungibleAbi.json';
import {expect} from 'chai';
describe('evm collection sponsoring', () => {
- itWeb3('sponsors mint transactions', async ({web3}) => {
- const alice = privateKey('//Alice');
+ itWeb3('sponsors mint transactions', async ({web3, privateKeyWrapper}) => {
+ const alice = privateKeyWrapper!('//Alice');
const collection = await createCollectionExpectSuccess();
await setCollectionSponsorExpectSuccess(collection, alice.address);
tests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth--- a/tests/src/eth/contractSponsoring.test.ts
+++ b/tests/src/eth/contractSponsoring.test.ts
@@ -14,7 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-import privateKey from '../substrate/privateKey';
import {expect} from 'chai';
import {
contractHelpers,
@@ -63,8 +62,8 @@
expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;
});
- itWeb3('In generous mode, non-allowlisted user transaction will be sponsored', async ({api, web3}) => {
- const alice = privateKey('//Alice');
+ itWeb3('In generous mode, non-allowlisted user transaction will be sponsored', async ({api, web3, privateKeyWrapper}) => {
+ const alice = privateKeyWrapper!('//Alice');
const owner = await createEthAccountWithBalance(api, web3);
const caller = await createEthAccountWithBalance(api, web3);
@@ -91,8 +90,8 @@
expect(+balanceAfter).to.be.lessThan(+originalFlipperBalance);
});
- itWeb3('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should decrease (allowlisted)', async ({api, web3}) => {
- const alice = privateKey('//Alice');
+ itWeb3('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should decrease (allowlisted)', async ({api, web3, privateKeyWrapper}) => {
+ const alice = privateKeyWrapper!('//Alice');
const owner = await createEthAccountWithBalance(api, web3);
const caller = createEthAccount(web3);
@@ -121,8 +120,8 @@
expect(+balanceAfter).to.be.lessThan(+originalFlipperBalance);
});
- itWeb3('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should not decrease (non-allowlisted)', async ({api, web3}) => {
- const alice = privateKey('//Alice');
+ itWeb3('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should not decrease (non-allowlisted)', async ({api, web3, privateKeyWrapper}) => {
+ const alice = privateKeyWrapper!('//Alice');
const owner = await createEthAccountWithBalance(api, web3);
const caller = createEthAccount(web3);
@@ -149,8 +148,8 @@
expect(+balanceAfter).to.be.equals(+originalFlipperBalance);
});
- itWeb3('Sponsoring is set, an address that has UNQ can send a transaction and it works. User balance should not change', async ({api, web3}) => {
- const alice = privateKey('//Alice');
+ itWeb3('Sponsoring is set, an address that has UNQ can send a transaction and it works. User balance should not change', async ({api, web3, privateKeyWrapper}) => {
+ const alice = privateKeyWrapper!('//Alice');
const owner = await createEthAccountWithBalance(api, web3);
const caller = await createEthAccountWithBalance(api, web3);
@@ -178,8 +177,8 @@
expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);
});
- itWeb3('Sponsoring is limited, with setContractRateLimit. The limitation is working if transactions are sent more often, the sender pays the commission.', async ({api, web3}) => {
- const alice = privateKey('//Alice');
+ itWeb3('Sponsoring is limited, with setContractRateLimit. The limitation is working if transactions are sent more often, the sender pays the commission.', async ({api, web3, privateKeyWrapper}) => {
+ const alice = privateKeyWrapper!('//Alice');
const owner = await createEthAccountWithBalance(api, web3);
const caller = await createEthAccountWithBalance(api, web3);
@@ -301,9 +300,9 @@
});
//TODO: CORE-302 add eth methods
- itWeb3.skip('Check that transaction via EVM spend money from substrate address', async ({api, web3}) => {
- const owner = privateKey('//Alice');
- const user = privateKey(`//User/${Date.now()}`);
+ itWeb3.skip('Check that transaction via EVM spend money from substrate address', async ({api, web3, privateKeyWrapper}) => {
+ const owner = privateKeyWrapper!('//Alice');
+ const user = privateKeyWrapper!(`//User/${Date.now()}`);
const userEth = subToEth(user.address);
const collectionId = await createCollectionExpectSuccess();
await addCollectionAdminExpectSuccess(owner, collectionId, {Ethereum: userEth});
tests/src/eth/crossTransfer.test.tsdiffbeforeafterboth--- a/tests/src/eth/crossTransfer.test.ts
+++ b/tests/src/eth/crossTransfer.test.ts
@@ -14,7 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-import privateKey from '../substrate/privateKey';
import {createCollectionExpectSuccess,
createFungibleItemExpectSuccess,
transferExpectSuccess,
@@ -28,27 +27,27 @@
import nonFungibleAbi from './nonFungibleAbi.json';
describe('Token transfer between substrate address and EVM address. Fungible', () => {
- itWeb3('The private key X create a substrate address. Alice sends a token to the corresponding EVM address, and X can send it to Bob in the substrate', async () => {
+ itWeb3('The private key X create a substrate address. Alice sends a token to the corresponding EVM address, and X can send it to Bob in the substrate', async ({privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
mode: {type: 'Fungible', decimalPoints: 0},
});
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
- const charlie = privateKey('//Charlie');
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
+ const charlie = privateKeyWrapper!('//Charlie');
await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Substrate: alice.address});
await transferExpectSuccess(collection, 0, alice, {Ethereum: subToEth(charlie.address)} , 200, 'Fungible');
await transferFromExpectSuccess(collection, 0, alice, {Ethereum: subToEth(charlie.address)}, charlie, 50, 'Fungible');
await transferExpectSuccess(collection, 0, charlie, bob, 50, 'Fungible');
});
- itWeb3('The private key X create a EVM address. Alice sends a token to the substrate address corresponding to this EVM address, and X can send it to Bob in the EVM', async ({api, web3}) => {
+ itWeb3('The private key X create a EVM address. Alice sends a token to the substrate address corresponding to this EVM address, and X can send it to Bob in the EVM', async ({api, web3, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
mode: {type: 'Fungible', decimalPoints: 0},
});
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
const bobProxy = await createEthAccountWithBalance(api, web3);
const aliceProxy = await createEthAccountWithBalance(api, web3);
@@ -64,28 +63,28 @@
});
describe('Token transfer between substrate address and EVM address. NFT', () => {
- itWeb3('The private key X create a substrate address. Alice sends a token to the corresponding EVM address, and X can send it to Bob in the substrate', async () => {
+ itWeb3('The private key X create a substrate address. Alice sends a token to the corresponding EVM address, and X can send it to Bob in the substrate', async ({privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
mode: {type: 'NFT'},
});
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
- const charlie = privateKey('//Charlie');
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
+ const charlie = privateKeyWrapper!('//Charlie');
const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});
await transferExpectSuccess(collection, tokenId, alice, {Ethereum: subToEth(charlie.address)}, 1, 'NFT');
await transferFromExpectSuccess(collection, tokenId, alice, {Ethereum: subToEth(charlie.address)}, charlie, 1, 'NFT');
await transferExpectSuccess(collection, tokenId, charlie, bob, 1, 'NFT');
});
- itWeb3('The private key X create a EVM address. Alice sends a token to the substrate address corresponding to this EVM address, and X can send it to Bob in the EVM', async ({api, web3}) => {
+ itWeb3('The private key X create a EVM address. Alice sends a token to the substrate address corresponding to this EVM address, and X can send it to Bob in the EVM', async ({api, web3, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
mode: {type: 'NFT'},
});
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
- const charlie = privateKey('//Charlie');
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
+ const charlie = privateKeyWrapper!('//Charlie');
const bobProxy = await createEthAccountWithBalance(api, web3);
const aliceProxy = await createEthAccountWithBalance(api, web3);
const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});
tests/src/eth/fungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/fungible.test.ts
+++ b/tests/src/eth/fungible.test.ts
@@ -14,19 +14,18 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-import privateKey from '../substrate/privateKey';
import {approveExpectSuccess, createCollectionExpectSuccess, createFungibleItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess, UNIQUE} from '../util/helpers';
import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, transferBalanceToEth} from './util/helpers';
import fungibleAbi from './fungibleAbi.json';
import {expect} from 'chai';
describe('Fungible: Information getting', () => {
- itWeb3('totalSupply', async ({api, web3}) => {
+ itWeb3('totalSupply', async ({api, web3, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
mode: {type: 'Fungible', decimalPoints: 0},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
@@ -39,12 +38,12 @@
expect(totalSupply).to.equal('200');
});
- itWeb3('balanceOf', async ({api, web3}) => {
+ itWeb3('balanceOf', async ({api, web3, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
mode: {type: 'Fungible', decimalPoints: 0},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
@@ -59,12 +58,12 @@
});
describe('Fungible: Plain calls', () => {
- itWeb3('Can perform approve()', async ({web3, api}) => {
+ itWeb3('Can perform approve()', async ({web3, api, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
mode: {type: 'Fungible', decimalPoints: 0},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const owner = await createEthAccountWithBalance(api, web3);
@@ -98,12 +97,12 @@
}
});
- itWeb3('Can perform transferFrom()', async ({web3, api}) => {
+ itWeb3('Can perform transferFrom()', async ({web3, api, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
mode: {type: 'Fungible', decimalPoints: 0},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const owner = createEthAccount(web3);
await transferBalanceToEth(api, alice, owner);
@@ -156,12 +155,12 @@
}
});
- itWeb3('Can perform transfer()', async ({web3, api}) => {
+ itWeb3('Can perform transfer()', async ({web3, api, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
mode: {type: 'Fungible', decimalPoints: 0},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const owner = createEthAccount(web3);
await transferBalanceToEth(api, alice, owner);
@@ -203,11 +202,11 @@
});
describe('Fungible: Fees', () => {
- itWeb3('approve() call fee is less than 0.2UNQ', async ({web3, api}) => {
+ itWeb3('approve() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'Fungible', decimalPoints: 0},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const owner = await createEthAccountWithBalance(api, web3);
const spender = createEthAccount(web3);
@@ -221,11 +220,11 @@
expect(cost < BigInt(0.2 * Number(UNIQUE)));
});
- itWeb3('transferFrom() call fee is less than 0.2UNQ', async ({web3, api}) => {
+ itWeb3('transferFrom() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'Fungible', decimalPoints: 0},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const owner = await createEthAccountWithBalance(api, web3);
const spender = await createEthAccountWithBalance(api, web3);
@@ -241,11 +240,11 @@
expect(cost < BigInt(0.2 * Number(UNIQUE)));
});
- itWeb3('transfer() call fee is less than 0.2UNQ', async ({web3, api}) => {
+ itWeb3('transfer() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'Fungible', decimalPoints: 0},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const owner = await createEthAccountWithBalance(api, web3);
const receiver = createEthAccount(web3);
@@ -261,11 +260,11 @@
});
describe('Fungible: Substrate calls', () => {
- itWeb3('Events emitted for approve()', async ({web3}) => {
+ itWeb3('Events emitted for approve()', async ({web3, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'Fungible', decimalPoints: 0},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const receiver = createEthAccount(web3);
@@ -291,12 +290,12 @@
]);
});
- itWeb3('Events emitted for transferFrom()', async ({web3}) => {
+ itWeb3('Events emitted for transferFrom()', async ({web3, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'Fungible', decimalPoints: 0},
});
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
const receiver = createEthAccount(web3);
@@ -332,11 +331,11 @@
]);
});
- itWeb3('Events emitted for transfer()', async ({web3}) => {
+ itWeb3('Events emitted for transfer()', async ({web3, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'Fungible', decimalPoints: 0},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const receiver = createEthAccount(web3);
tests/src/eth/marketplace/marketplace.test.tsdiffbeforeafterboth--- a/tests/src/eth/marketplace/marketplace.test.ts
+++ b/tests/src/eth/marketplace/marketplace.test.ts
@@ -16,7 +16,6 @@
import {readFile} from 'fs/promises';
import {getBalanceSingle} from '../../substrate/get-balance';
-import privateKey from '../../substrate/privateKey';
import {
addToAllowListExpectSuccess,
confirmSponsorshipExpectSuccess,
@@ -38,8 +37,8 @@
const PRICE = 2000n;
describe('Matcher contract usage', () => {
- itWeb3('With UNQ', async ({api, web3}) => {
- const alice = privateKey('//Alice');
+ itWeb3('With UNQ', async ({api, web3, privateKeyWrapper}) => {
+ const alice = privateKeyWrapper!('//Alice');
const matcherOwner = await createEthAccountWithBalance(api, web3);
const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlace.abi`)).toString()), undefined, {
from: matcherOwner,
@@ -61,7 +60,7 @@
await helpers.methods.toggleAllowed(matcher.options.address, subToEth(alice.address), true).send({from: matcherOwner});
await addToAllowListExpectSuccess(alice, collectionId, evmToAddress(subToEth(alice.address)));
- const seller = privateKey(`//Seller/${Date.now()}`);
+ const seller = privateKeyWrapper!(`//Seller/${Date.now()}`);
await helpers.methods.toggleAllowed(matcher.options.address, subToEth(seller.address), true).send({from: matcherOwner});
const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', seller.address);
@@ -99,8 +98,8 @@
});
- itWeb3('With escrow', async ({api, web3}) => {
- const alice = privateKey('//Alice');
+ itWeb3('With escrow', async ({api, web3, privateKeyWrapper}) => {
+ const alice = privateKeyWrapper!('//Alice');
const matcherOwner = await createEthAccountWithBalance(api, web3);
const escrow = await createEthAccountWithBalance(api, web3);
const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlace.abi`)).toString()), undefined, {
@@ -124,7 +123,7 @@
await helpers.methods.toggleAllowed(matcher.options.address, subToEth(alice.address), true).send({from: matcherOwner});
await addToAllowListExpectSuccess(alice, collectionId, evmToAddress(subToEth(alice.address)));
- const seller = privateKey(`//Seller/${Date.now()}`);
+ const seller = privateKeyWrapper!(`//Seller/${Date.now()}`);
await helpers.methods.toggleAllowed(matcher.options.address, subToEth(seller.address), true).send({from: matcherOwner});
const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', seller.address);
@@ -170,8 +169,8 @@
});
- itWeb3('Sell tokens from substrate user via EVM contract', async ({api, web3}) => {
- const alice = privateKey('//Alice');
+ itWeb3('Sell tokens from substrate user via EVM contract', async ({api, web3, privateKeyWrapper}) => {
+ const alice = privateKeyWrapper!('//Alice');
const matcherOwner = await createEthAccountWithBalance(api, web3);
const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlace.abi`)).toString()), undefined, {
from: matcherOwner,
@@ -184,7 +183,7 @@
await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorApproveTimeout: 1});
const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collectionId), {from: matcherOwner});
- const seller = privateKey(`//Seller/${Date.now()}`);
+ const seller = privateKeyWrapper!(`//Seller/${Date.now()}`);
await transferBalanceTo(api, alice, seller.address);
const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', seller.address);
tests/src/eth/migration.test.tsdiffbeforeafterboth--- a/tests/src/eth/migration.test.ts
+++ b/tests/src/eth/migration.test.ts
@@ -15,12 +15,11 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {expect} from 'chai';
-import privateKey from '../substrate/privateKey';
import {submitTransactionAsync} from '../substrate/substrate-api';
import {createEthAccountWithBalance, GAS_ARGS, itWeb3} from './util/helpers';
describe('EVM Migrations', () => {
- itWeb3('Deploy contract saved state', async ({web3, api}) => {
+ itWeb3('Deploy contract saved state', async ({web3, api, privateKeyWrapper}) => {
/*
contract StatefulContract {
uint counter;
@@ -54,7 +53,7 @@
['0xedc95719e9a3b28dd8e80877cb5880a9be7de1a13fc8b05e7999683b6b567643', '0x0000000000000000000000000000000000000000000000000000000000000004'],
];
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
await submitTransactionAsync(alice, api.tx.sudo.sudo(api.tx.evmMigration.begin(ADDRESS) as any));
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -14,7 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-import privateKey from '../substrate/privateKey';
import {approveExpectSuccess, burnItemExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess, UNIQUE} from '../util/helpers';
import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, evmCollection, evmCollectionHelpers, GAS_ARGS, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, transferBalanceToEth} from './util/helpers';
import nonFungibleAbi from './nonFungibleAbi.json';
@@ -22,11 +21,11 @@
import {submitTransactionAsync} from '../substrate/substrate-api';
describe('NFT: Information getting', () => {
- itWeb3('totalSupply', async ({api, web3}) => {
+ itWeb3('totalSupply', async ({api, web3, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'NFT'},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});
@@ -38,11 +37,11 @@
expect(totalSupply).to.equal('1');
});
- itWeb3('balanceOf', async ({api, web3}) => {
+ itWeb3('balanceOf', async ({api, web3, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'NFT'},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum:caller});
@@ -56,11 +55,11 @@
expect(balance).to.equal('3');
});
- itWeb3('ownerOf', async ({api, web3}) => {
+ itWeb3('ownerOf', async ({api, web3, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'NFT'},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});
@@ -114,11 +113,11 @@
});
//TODO: CORE-302 add eth methods
- itWeb3.skip('Can perform mintBulk()', async ({web3, api}) => {
+ itWeb3.skip('Can perform mintBulk()', async ({web3, api, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'NFT'},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
const changeAdminTx = api.tx.unique.addCollectionAdmin(collection, {Ethereum: caller});
@@ -177,11 +176,11 @@
}
});
- itWeb3('Can perform burn()', async ({web3, api}) => {
+ itWeb3('Can perform burn()', async ({web3, api, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'NFT'},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const owner = await createEthAccountWithBalance(api, web3);
@@ -208,11 +207,11 @@
}
});
- itWeb3('Can perform approve()', async ({web3, api}) => {
+ itWeb3('Can perform approve()', async ({web3, api, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'NFT'},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const owner = createEthAccount(web3);
await transferBalanceToEth(api, alice, owner);
@@ -242,11 +241,11 @@
}
});
- itWeb3('Can perform transferFrom()', async ({web3, api}) => {
+ itWeb3('Can perform transferFrom()', async ({web3, api, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'NFT'},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const owner = createEthAccount(web3);
await transferBalanceToEth(api, alice, owner);
@@ -290,11 +289,11 @@
}
});
- itWeb3('Can perform transfer()', async ({web3, api}) => {
+ itWeb3('Can perform transfer()', async ({web3, api, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'NFT'},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const owner = createEthAccount(web3);
await transferBalanceToEth(api, alice, owner);
@@ -336,11 +335,11 @@
});
describe('NFT: Fees', () => {
- itWeb3('approve() call fee is less than 0.2UNQ', async ({web3, api}) => {
+ itWeb3('approve() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'NFT'},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const owner = await createEthAccountWithBalance(api, web3);
const spender = createEthAccount(web3);
@@ -354,11 +353,11 @@
expect(cost < BigInt(0.2 * Number(UNIQUE)));
});
- itWeb3('transferFrom() call fee is less than 0.2UNQ', async ({web3, api}) => {
+ itWeb3('transferFrom() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'NFT'},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const owner = await createEthAccountWithBalance(api, web3);
const spender = await createEthAccountWithBalance(api, web3);
@@ -374,11 +373,11 @@
expect(cost < BigInt(0.2 * Number(UNIQUE)));
});
- itWeb3('transfer() call fee is less than 0.2UNQ', async ({web3, api}) => {
+ itWeb3('transfer() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'NFT'},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const owner = await createEthAccountWithBalance(api, web3);
const receiver = createEthAccount(web3);
@@ -394,11 +393,11 @@
});
describe('NFT: Substrate calls', () => {
- itWeb3('Events emitted for mint()', async ({web3}) => {
+ itWeb3('Events emitted for mint()', async ({web3, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'NFT'},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const address = collectionIdToAddress(collection);
const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
@@ -421,11 +420,11 @@
]);
});
- itWeb3('Events emitted for burn()', async ({web3}) => {
+ itWeb3('Events emitted for burn()', async ({web3, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'NFT'},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const address = collectionIdToAddress(collection);
const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
@@ -448,11 +447,11 @@
]);
});
- itWeb3('Events emitted for approve()', async ({web3}) => {
+ itWeb3('Events emitted for approve()', async ({web3, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'NFT'},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const receiver = createEthAccount(web3);
@@ -478,12 +477,12 @@
]);
});
- itWeb3('Events emitted for transferFrom()', async ({web3}) => {
+ itWeb3('Events emitted for transferFrom()', async ({web3, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'NFT'},
});
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
const receiver = createEthAccount(web3);
@@ -510,11 +509,11 @@
]);
});
- itWeb3('Events emitted for transfer()', async ({web3}) => {
+ itWeb3('Events emitted for transfer()', async ({web3, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'NFT'},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const receiver = createEthAccount(web3);
tests/src/eth/payable.test.tsdiffbeforeafterboth--- a/tests/src/eth/payable.test.ts
+++ b/tests/src/eth/payable.test.ts
@@ -15,7 +15,6 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {expect} from 'chai';
-import privateKey from '../substrate/privateKey';
import {submitTransactionAsync} from '../substrate/substrate-api';
import {createEthAccountWithBalance, deployCollector, GAS_ARGS, itWeb3, subToEth, transferBalanceToEth} from './util/helpers';
import {evmToAddress} from '@polkadot/util-crypto';
@@ -32,10 +31,10 @@
expect(await contract.methods.getCollected().call()).to.be.equal('10000');
});
- itWeb3('Evm contract can receive wei from substrate account', async ({api, web3}) => {
+ itWeb3('Evm contract can receive wei from substrate account', async ({api, web3, privateKeyWrapper}) => {
const deployer = await createEthAccountWithBalance(api, web3);
const contract = await deployCollector(web3, deployer);
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
// Transaction fee/value will be payed from subToEth(sender) evm balance,
// which is backed by evmToAddress(subToEth(sender)) substrate balance
@@ -62,27 +61,27 @@
});
// We can't handle sending balance to backing storage of evm balance, because evmToAddress operation is irreversible
- itWeb3('Wei sent directly to backing storage of evm contract balance is unaccounted', async({api, web3}) => {
+ itWeb3('Wei sent directly to backing storage of evm contract balance is unaccounted', async({api, web3, privateKeyWrapper}) => {
const deployer = await createEthAccountWithBalance(api, web3);
const contract = await deployCollector(web3, deployer);
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
await transferBalanceExpectSuccess(api, alice, evmToAddress(contract.options.address), '10000');
expect(await contract.methods.getUnaccounted().call()).to.be.equal('10000');
});
- itWeb3('Balance can be retrieved from evm contract', async({api, web3}) => {
+ itWeb3('Balance can be retrieved from evm contract', async({api, web3, privateKeyWrapper}) => {
const FEE_BALANCE = 1000n * UNIQUE;
const CONTRACT_BALANCE = 1n * UNIQUE;
const deployer = await createEthAccountWithBalance(api, web3);
const contract = await deployCollector(web3, deployer);
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
await web3.eth.sendTransaction({from: deployer, to: contract.options.address, value: CONTRACT_BALANCE.toString(), ...GAS_ARGS});
- const receiver = privateKey(`//Receiver${Date.now()}`);
+ const receiver = privateKeyWrapper!(`//Receiver${Date.now()}`);
// First receive balance on eth balance of bob
{
tests/src/eth/proxy/fungibleProxy.test.tsdiffbeforeafterboth--- a/tests/src/eth/proxy/fungibleProxy.test.ts
+++ b/tests/src/eth/proxy/fungibleProxy.test.ts
@@ -14,7 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-import privateKey from '../../substrate/privateKey';
import {createCollectionExpectSuccess, createFungibleItemExpectSuccess} from '../../util/helpers';
import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents} from '../util/helpers';
import fungibleAbi from '../fungibleAbi.json';
@@ -35,12 +34,12 @@
}
describe('Fungible (Via EVM proxy): Information getting', () => {
- itWeb3('totalSupply', async ({api, web3}) => {
+ itWeb3('totalSupply', async ({api, web3, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
mode: {type: 'Fungible', decimalPoints: 0},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Substrate: alice.address});
@@ -52,12 +51,12 @@
expect(totalSupply).to.equal('200');
});
- itWeb3('balanceOf', async ({api, web3}) => {
+ itWeb3('balanceOf', async ({api, web3, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
mode: {type: 'Fungible', decimalPoints: 0},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: caller});
@@ -71,12 +70,12 @@
});
describe('Fungible (Via EVM proxy): Plain calls', () => {
- itWeb3('Can perform approve()', async ({web3, api}) => {
+ itWeb3('Can perform approve()', async ({web3, api, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
mode: {type: 'Fungible', decimalPoints: 0},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
const spender = createEthAccount(web3);
@@ -107,12 +106,12 @@
}
});
- itWeb3('Can perform transferFrom()', async ({web3, api}) => {
+ itWeb3('Can perform transferFrom()', async ({web3, api, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
mode: {type: 'Fungible', decimalPoints: 0},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
const owner = await createEthAccountWithBalance(api, web3);
@@ -162,12 +161,12 @@
}
});
- itWeb3('Can perform transfer()', async ({web3, api}) => {
+ itWeb3('Can perform transfer()', async ({web3, api, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
mode: {type: 'Fungible', decimalPoints: 0},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
const receiver = await createEthAccountWithBalance(api, web3);
tests/src/eth/proxy/nonFungibleProxy.test.tsdiffbeforeafterboth--- a/tests/src/eth/proxy/nonFungibleProxy.test.ts
+++ b/tests/src/eth/proxy/nonFungibleProxy.test.ts
@@ -14,7 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-import privateKey from '../../substrate/privateKey';
import {createCollectionExpectSuccess, createItemExpectSuccess} from '../../util/helpers';
import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents} from '../util/helpers';
import nonFungibleAbi from '../nonFungibleAbi.json';
@@ -36,11 +35,11 @@
}
describe('NFT (Via EVM proxy): Information getting', () => {
- itWeb3('totalSupply', async ({api, web3}) => {
+ itWeb3('totalSupply', async ({api, web3, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'NFT'},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});
@@ -52,11 +51,11 @@
expect(totalSupply).to.equal('1');
});
- itWeb3('balanceOf', async ({api, web3}) => {
+ itWeb3('balanceOf', async ({api, web3, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'NFT'},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});
@@ -70,11 +69,11 @@
expect(balance).to.equal('3');
});
- itWeb3('ownerOf', async ({api, web3}) => {
+ itWeb3('ownerOf', async ({api, web3, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'NFT'},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});
@@ -89,11 +88,11 @@
describe('NFT (Via EVM proxy): Plain calls', () => {
//TODO: CORE-302 add eth methods
- itWeb3.skip('Can perform mint()', async ({web3, api}) => {
+ itWeb3.skip('Can perform mint()', async ({web3, api, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'NFT'},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
const receiver = createEthAccount(web3);
@@ -130,11 +129,11 @@
});
//TODO: CORE-302 add eth methods
- itWeb3.skip('Can perform mintBulk()', async ({web3, api}) => {
+ itWeb3.skip('Can perform mintBulk()', async ({web3, api, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'NFT'},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
const receiver = createEthAccount(web3);
@@ -193,11 +192,11 @@
}
});
- itWeb3('Can perform burn()', async ({web3, api}) => {
+ itWeb3('Can perform burn()', async ({web3, api, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'NFT'},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
const address = collectionIdToAddress(collection);
@@ -225,11 +224,11 @@
}
});
- itWeb3('Can perform approve()', async ({web3, api}) => {
+ itWeb3('Can perform approve()', async ({web3, api, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'NFT'},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
const spender = createEthAccount(web3);
@@ -255,11 +254,11 @@
}
});
- itWeb3('Can perform transferFrom()', async ({web3, api}) => {
+ itWeb3('Can perform transferFrom()', async ({web3, api, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'NFT'},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
const owner = await createEthAccountWithBalance(api, web3);
@@ -299,11 +298,11 @@
}
});
- itWeb3('Can perform transfer()', async ({web3, api}) => {
+ itWeb3('Can perform transfer()', async ({web3, api, privateKeyWrapper}) => {
const collection = await createCollectionExpectSuccess({
mode: {type: 'NFT'},
});
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
const receiver = createEthAccount(web3);
tests/src/eth/sponsoring.test.tsdiffbeforeafterboth--- a/tests/src/eth/sponsoring.test.ts
+++ b/tests/src/eth/sponsoring.test.ts
@@ -15,12 +15,11 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {expect} from 'chai';
-import privateKey from '../substrate/privateKey';
import {contractHelpers, createEthAccount, createEthAccountWithBalance, deployCollector, deployFlipper, itWeb3, SponsoringMode, transferBalanceToEth} from './util/helpers';
describe('EVM sponsoring', () => {
- itWeb3('Fee is deducted from contract if sponsoring is enabled', async ({api, web3}) => {
- const alice = privateKey('//Alice');
+ itWeb3('Fee is deducted from contract if sponsoring is enabled', async ({api, web3, privateKeyWrapper}) => {
+ const alice = privateKeyWrapper!('//Alice');
const owner = await createEthAccountWithBalance(api, web3);
const caller = createEthAccount(web3);
@@ -50,8 +49,8 @@
expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);
expect(await web3.eth.getBalance(flipper.options.address)).to.be.not.equals(originalFlipperBalance);
});
- itWeb3('...but this doesn\'t applies to payable value', async ({api, web3}) => {
- const alice = privateKey('//Alice');
+ itWeb3('...but this doesn\'t applies to payable value', async ({api, web3, privateKeyWrapper}) => {
+ const alice = privateKeyWrapper!('//Alice');
const owner = await createEthAccountWithBalance(api, web3);
const caller = await createEthAccountWithBalance(api, web3);
tests/src/eth/tokenProperties.test.tsdiffbeforeafterboth--- a/tests/src/eth/tokenProperties.test.ts
+++ b/tests/src/eth/tokenProperties.test.ts
@@ -1,4 +1,3 @@
-import privateKey from '../substrate/privateKey';
import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess} from '../util/helpers';
import {cartesian, collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3} from './util/helpers';
import nonFungibleAbi from './nonFungibleAbi.json';
@@ -6,8 +5,8 @@
import {executeTransaction} from '../substrate/substrate-api';
describe('EVM token properties', () => {
- itWeb3('Can be reconfigured', async({web3, api}) => {
- const alice = privateKey('//Alice');
+ itWeb3('Can be reconfigured', async({web3, api, privateKeyWrapper}) => {
+ const alice = privateKeyWrapper!('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
for(const [mutable,collectionAdmin, tokenOwner] of cartesian([], [false, true], [false, true], [false, true])) {
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
@@ -24,8 +23,8 @@
});
}
});
- itWeb3('Can be set', async({web3, api}) => {
- const alice = privateKey('//Alice');
+ itWeb3('Can be set', async({web3, api, privateKeyWrapper}) => {
+ const alice = privateKeyWrapper!('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
const token = await createItemExpectSuccess(alice, collection, 'NFT');
@@ -47,8 +46,8 @@
const [{value}] = (await api.rpc.unique.tokenProperties(collection, token, ['testKey'])).toHuman()! as any;
expect(value).to.equal('testValue');
});
- itWeb3('Can be deleted', async({web3, api}) => {
- const alice = privateKey('//Alice');
+ itWeb3('Can be deleted', async({web3, api, privateKeyWrapper}) => {
+ const alice = privateKeyWrapper!('//Alice');
const caller = await createEthAccountWithBalance(api, web3);
const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
const token = await createItemExpectSuccess(alice, collection, 'NFT');
@@ -72,8 +71,8 @@
const result = (await api.rpc.unique.tokenProperties(collection, token, ['testKey'])).toJSON()! as any;
expect(result.length).to.equal(0);
});
- itWeb3('Can be read', async({web3, api}) => {
- const alice = privateKey('//Alice');
+ itWeb3('Can be read', async({web3, api, privateKeyWrapper}) => {
+ const alice = privateKeyWrapper!('//Alice');
const caller = createEthAccount(web3);
const collection = await createCollectionExpectSuccess({mode: {type:'NFT'}});
const token = await createItemExpectSuccess(alice, collection, 'NFT');
tests/src/eth/util/helpers.tsdiffbeforeafterboth--- a/tests/src/eth/util/helpers.ts
+++ b/tests/src/eth/util/helpers.ts
@@ -18,20 +18,20 @@
/// <reference path="helpers.d.ts" />
import {ApiPromise} from '@polkadot/api';
-import {addressToEvm, evmToAddress} from '@polkadot/util-crypto';
-import Web3 from 'web3';
-import usingApi, {submitTransactionAsync} from '../../substrate/substrate-api';
import {IKeyringPair} from '@polkadot/types/types';
+import {addressToEvm, evmToAddress} from '@polkadot/util-crypto';
import {expect} from 'chai';
-import {CrossAccountId, getDetailedCollectionInfo, getGenericResult, UNIQUE} from '../../util/helpers';
import * as solc from 'solc';
+import Web3 from 'web3';
import config from '../../config';
+import getBalance from '../../substrate/get-balance';
import privateKey from '../../substrate/privateKey';
-import contractHelpersAbi from './contractHelpersAbi.json';
-import nonFungibleAbi from '../nonFungibleAbi.json';
+import usingApi, {submitTransactionAsync} from '../../substrate/substrate-api';
+import waitNewBlocks from '../../substrate/wait-new-blocks';
+import {CrossAccountId, getDetailedCollectionInfo, getGenericResult, UNIQUE} from '../../util/helpers';
import collectionHelpersAbi from '../collectionHelpersAbi.json';
-import getBalance from '../../substrate/get-balance';
-import waitNewBlocks from '../../substrate/wait-new-blocks';
+import nonFungibleAbi from '../nonFungibleAbi.json';
+import contractHelpersAbi from './contractHelpersAbi.json';
export const GAS_ARGS = {gas: 2500000};
@@ -139,8 +139,8 @@
});
});
}
-itWeb3.only = (name: string, cb: (apis: { web3: Web3, api: ApiPromise }) => any) => itWeb3(name, cb, {only: true});
-itWeb3.skip = (name: string, cb: (apis: { web3: Web3, api: ApiPromise }) => any) => itWeb3(name, cb, {skip: true});
+itWeb3.only = (name: string, cb: (apis: { web3: Web3, api: ApiPromise, privateKeyWrapper?: (account: string) => IKeyringPair }) => any) => itWeb3(name, cb, {only: true});
+itWeb3.skip = (name: string, cb: (apis: { web3: Web3, api: ApiPromise, privateKeyWrapper?: (account: string) => IKeyringPair }) => any) => itWeb3(name, cb, {skip: true});
export async function generateSubstrateEthPair(web3: Web3) {
const account = web3.eth.accounts.create();
tests/src/inflation.test.tsdiffbeforeafterboth--- a/tests/src/inflation.test.ts
+++ b/tests/src/inflation.test.ts
@@ -17,22 +17,21 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
-import privateKey from './substrate/privateKey';
chai.use(chaiAsPromised);
const expect = chai.expect;
describe('integration test: Inflation', () => {
it('First year inflation is 10%', async () => {
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
// Make sure non-sudo can't start inflation
const tx = api.tx.inflation.startInflation(1);
- const bob = privateKey('//Bob');
+ const bob = privateKeyWrapper!('//Bob');
await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;
// Start inflation on relay block 1 (Alice is sudo)
- const alice = privateKey('//Alice');
+ const alice = privateKeyWrapper!('//Alice');
const sudoTx = api.tx.sudo.sudo(tx as any);
await submitTransactionAsync(alice, sudoTx);
tests/src/limits.test.tsdiffbeforeafterboth--- a/tests/src/limits.test.ts
+++ b/tests/src/limits.test.ts
@@ -15,7 +15,6 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {IKeyringPair} from '@polkadot/types/types';
-import privateKey from './substrate/privateKey';
import usingApi from './substrate/substrate-api';
import {
createCollectionExpectSuccess,
@@ -35,8 +34,8 @@
let alice: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
});
});
@@ -69,8 +68,8 @@
let alice: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
});
});
@@ -103,10 +102,10 @@
let charlie: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
+ charlie = privateKeyWrapper!('//Charlie');
});
});
@@ -166,10 +165,10 @@
let charlie: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
+ charlie = privateKeyWrapper!('//Charlie');
});
});
@@ -233,10 +232,10 @@
let charlie: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
+ charlie = privateKeyWrapper!('//Charlie');
});
});
@@ -296,10 +295,10 @@
let charlie: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
+ charlie = privateKeyWrapper!('//Charlie');
});
});
@@ -337,10 +336,10 @@
let charlie: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
+ charlie = privateKeyWrapper!('//Charlie');
});
});
@@ -369,10 +368,10 @@
let charlie: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
+ charlie = privateKeyWrapper!('//Charlie');
});
});
tests/src/mintModes.test.tsdiffbeforeafterboth--- a/tests/src/mintModes.test.ts
+++ b/tests/src/mintModes.test.ts
@@ -15,7 +15,6 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {IKeyringPair} from '@polkadot/types/types';
-import privateKey from './substrate/privateKey';
import usingApi from './substrate/substrate-api';
import {
addToAllowListExpectSuccess,
@@ -33,9 +32,9 @@
let bob: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
});
});
@@ -112,9 +111,9 @@
let bob: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
});
});
tests/src/nesting/graphs.test.tsdiffbeforeafterboth--- a/tests/src/nesting/graphs.test.ts
+++ b/tests/src/nesting/graphs.test.ts
@@ -2,7 +2,6 @@
import {IKeyringPair} from '@polkadot/types/types';
import {expect} from 'chai';
import {tokenIdToCross} from '../eth/util/helpers';
-import privateKey from '../substrate/privateKey';
import usingApi, {executeTransaction} from '../substrate/substrate-api';
import {getCreateCollectionResult, transferExpectSuccess} from '../util/helpers';
@@ -34,8 +33,8 @@
describe('Graphs', () => {
it('Ouroboros can\'t be created in a complex graph', async () => {
- await usingApi(async api => {
- const alice = privateKey('//Alice');
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
const collection = await buildComplexObjectGraph(api, alice);
// to self
tests/src/nesting/migration-check.test.tsdiffbeforeafterboth--- a/tests/src/nesting/migration-check.test.ts
+++ b/tests/src/nesting/migration-check.test.ts
@@ -1,5 +1,4 @@
import {expect} from 'chai';
-import privateKey from '../substrate/privateKey';
import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
import {getCreateCollectionResult} from '../util/helpers';
import {IKeyringPair} from '@polkadot/types/types';
@@ -13,8 +12,8 @@
let alice: IKeyringPair;
before(async() => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
});
});
tests/src/nesting/nest.test.tsdiffbeforeafterboth--- a/tests/src/nesting/nest.test.ts
+++ b/tests/src/nesting/nest.test.ts
@@ -1,6 +1,5 @@
import {expect} from 'chai';
import {tokenIdToAddress} from '../eth/util/helpers';
-import privateKey from '../substrate/privateKey';
import usingApi, {executeTransaction} from '../substrate/substrate-api';
import {
addToAllowListExpectSuccess,
@@ -23,9 +22,9 @@
describe('Integration Test: Nesting', () => {
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
});
});
@@ -226,9 +225,9 @@
describe('Negative Test: Nesting', async() => {
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
});
});
tests/src/nesting/properties.test.tsdiffbeforeafterboth1import {expect} from 'chai';2import privateKey from '../substrate/privateKey';3import usingApi, {executeTransaction} from '../substrate/substrate-api';4import {5 addCollectionAdminExpectSuccess,6 createCollectionExpectSuccess,7 createItemExpectSuccess,8 getCreateCollectionResult,9 transferExpectSuccess,10} from '../util/helpers';11import {IKeyringPair} from '@polkadot/types/types';1213let alice: IKeyringPair;14let bob: IKeyringPair;15let charlie: IKeyringPair;1617describe('Composite Properties Test', () => {18 before(async () => {19 await usingApi(async () => {20 alice = privateKey('//Alice');21 bob = privateKey('//Bob');22 });23 });2425 it('Makes sure collectionById supplies required fields', async () => {26 await usingApi(async api => {27 const collectionId = await createCollectionExpectSuccess();2829 const collectionOption = await api.rpc.unique.collectionById(collectionId);30 expect(collectionOption.isSome).to.be.true;31 let collection = collectionOption.unwrap();32 expect(collection.tokenPropertyPermissions.toHuman()).to.be.empty;33 expect(collection.properties.toHuman()).to.be.empty;3435 const propertyPermissions = [36 {key: 'mindgame', permission: {collectionAdmin: true, mutable: false, tokenOwner: true}},37 {key: 'skullduggery', permission: {collectionAdmin: false, mutable: true, tokenOwner: false}},38 ];39 await expect(executeTransaction(40 api, 41 alice, 42 api.tx.unique.setPropertyPermissions(collectionId, propertyPermissions), 43 )).to.not.be.rejected;4445 const collectionProperties = [46 {key: 'black_hole', value: 'LIGO'},47 {key: 'electron', value: 'come bond'}, 48 ];49 await expect(executeTransaction(50 api, 51 alice, 52 api.tx.unique.setCollectionProperties(collectionId, collectionProperties), 53 )).to.not.be.rejected;5455 collection = (await api.rpc.unique.collectionById(collectionId)).unwrap();56 expect(collection.tokenPropertyPermissions.toHuman()).to.be.deep.equal(propertyPermissions);57 expect(collection.properties.toHuman()).to.be.deep.equal(collectionProperties);58 });59 });60});6162// ---------- COLLECTION PROPERTIES6364describe('Integration Test: Collection Properties', () => {65 before(async () => {66 await usingApi(async () => {67 alice = privateKey('//Alice');68 bob = privateKey('//Bob');69 });70 });7172 it('Reads properties from a collection', async () => {73 await usingApi(async api => {74 const collection = await createCollectionExpectSuccess();75 const properties = (await api.query.common.collectionProperties(collection)).toJSON();76 expect(properties.map).to.be.empty;77 expect(properties.consumedSpace).to.equal(0);78 });79 });8081 it('Sets properties for a collection', async () => {82 await usingApi(async api => {83 const events = await executeTransaction(api, bob, api.tx.unique.createCollectionEx({mode: 'NFT'}));84 const {collectionId} = getCreateCollectionResult(events);8586 // As owner87 await expect(executeTransaction(88 api, 89 bob, 90 api.tx.unique.setCollectionProperties(collectionId, [{key: 'electron', value: 'come bond'}]), 91 )).to.not.be.rejected;9293 await addCollectionAdminExpectSuccess(bob, collectionId, alice.address);9495 // As administrator96 await expect(executeTransaction(97 api, 98 alice, 99 api.tx.unique.setCollectionProperties(collectionId, [{key: 'black_hole'}]), 100 )).to.not.be.rejected;101102 const properties = (await api.rpc.unique.collectionProperties(collectionId, ['electron', 'black_hole'])).toHuman();103 expect(properties).to.be.deep.equal([104 {key: 'electron', value: 'come bond'},105 {key: 'black_hole', value: ''},106 ]);107 });108 });109110 it('Changes properties of a collection', async () => {111 await usingApi(async api => {112 const collection = await createCollectionExpectSuccess();113114 await expect(executeTransaction(115 api, 116 alice, 117 api.tx.unique.setCollectionProperties(collection, [{key: 'electron', value: 'come bond'}, {key: 'black_hole'}]), 118 )).to.not.be.rejected;119120 // Mutate the properties121 await expect(executeTransaction(122 api, 123 alice, 124 api.tx.unique.setCollectionProperties(collection, [{key: 'electron', value: 'bonded'}, {key: 'black_hole', value: 'LIGO'}]), 125 )).to.not.be.rejected;126127 const properties = (await api.rpc.unique.collectionProperties(collection, ['electron', 'black_hole'])).toHuman();128 expect(properties).to.be.deep.equal([129 {key: 'electron', value: 'bonded'},130 {key: 'black_hole', value: 'LIGO'},131 ]);132 });133 });134135 it('Deletes properties of a collection', async () => {136 await usingApi(async api => {137 const collection = await createCollectionExpectSuccess();138139 await expect(executeTransaction(140 api, 141 alice, 142 api.tx.unique.setCollectionProperties(collection, [{key: 'electron', value: 'come bond'}, {key: 'black_hole', value: 'LIGO'}]), 143 )).to.not.be.rejected;144145 await expect(executeTransaction(146 api, 147 alice, 148 api.tx.unique.deleteCollectionProperties(collection, ['electron']), 149 )).to.not.be.rejected;150151 const properties = (await api.rpc.unique.collectionProperties(collection, ['electron', 'black_hole'])).toHuman();152 expect(properties).to.be.deep.equal([153 {key: 'black_hole', value: 'LIGO'},154 ]);155 });156 });157});158159describe('Negative Integration Test: Collection Properties', () => {160 before(async () => {161 await usingApi(async () => {162 alice = privateKey('//Alice');163 bob = privateKey('//Bob');164 });165 });166 167 it('Fails to set properties in a collection if not its onwer/administrator', async () => {168 await usingApi(async api => {169 const collection = await createCollectionExpectSuccess();170171 await expect(executeTransaction(172 api, 173 bob, 174 api.tx.unique.setCollectionProperties(collection, [{key: 'electron', value: 'come bond'}, {key: 'black_hole', value: 'LIGO'}]), 175 )).to.be.rejectedWith(/common\.NoPermission/);176 177 const properties = (await api.query.common.collectionProperties(collection)).toJSON();178 expect(properties.map).to.be.empty;179 expect(properties.consumedSpace).to.equal(0);180 });181 });182 183 it('Fails to set properties that exceed the limits', async () => {184 await usingApi(async api => {185 const collection = await createCollectionExpectSuccess();186 const spaceLimit = (await api.query.common.collectionProperties(collection)).toJSON().spaceLimit as number; 187188 // Mute the general tx parsing error, too many bytes to process189 {190 console.error = () => {};191 await expect(executeTransaction(192 api, 193 alice, 194 api.tx.unique.setCollectionProperties(collection, [{key: 'electron', value: 'low high '.repeat(Math.ceil(spaceLimit! / 9))}]), 195 )).to.be.rejected;196 }197198 let properties = (await api.rpc.unique.collectionProperties(collection, ['electron'])).toJSON();199 expect(properties).to.be.empty;200201 await expect(executeTransaction(202 api, 203 alice, 204 api.tx.unique.setCollectionProperties(collection, [205 {key: 'electron', value: 'low high '.repeat(Math.ceil(spaceLimit! / 18))}, 206 {key: 'black_hole', value: '0'.repeat(Math.ceil(spaceLimit! / 2))}, 207 ]), 208 )).to.be.rejectedWith(/common\.NoSpaceForProperty/);209210 properties = (await api.rpc.unique.collectionProperties(collection, ['electron', 'black hole'])).toJSON();211 expect(properties).to.be.empty;212 });213 });214 215 it('Fails to set more properties than it is allowed', async () => {216 await usingApi(async api => {217 const collection = await createCollectionExpectSuccess();218219 const propertiesToBeSet = [];220 for (let i = 0; i < 65; i++) {221 propertiesToBeSet.push({222 key: 'electron_' + i,223 value: Math.random() > 0.5 ? 'high' : 'low',224 });225 }226227 await expect(executeTransaction(228 api, 229 alice, 230 api.tx.unique.setCollectionProperties(collection, propertiesToBeSet), 231 )).to.be.rejectedWith(/common\.PropertyLimitReached/);232233 const properties = (await api.query.common.collectionProperties(collection)).toJSON();234 expect(properties.map).to.be.empty;235 expect(properties.consumedSpace).to.equal(0);236 });237 });238239 it('Fails to set properties with invalid names', async () => {240 await usingApi(async api => {241 const collection = await createCollectionExpectSuccess();242243 const invalidProperties = [244 [{key: 'electron', value: 'negative'}, {key: 'string theory', value: 'understandable'}],245 [{key: 'Mr.Sandman', value: 'Bring me a gene'}],246 [{key: 'déjà vu', value: 'hmm...'}],247 ];248249 for (let i = 0; i < invalidProperties.length; i++) {250 await expect(executeTransaction(251 api, 252 alice, 253 api.tx.unique.setCollectionProperties(collection, invalidProperties[i]), 254 ), `on rejecting the new badly-named property #${i}`).to.be.rejectedWith(/common\.InvalidCharacterInPropertyKey/);255 }256257 await expect(executeTransaction(258 api, 259 alice, 260 api.tx.unique.setCollectionProperties(collection, [{key: '', value: 'nothing must not exist'}]), 261 ), 'on rejecting an unnamed property').to.be.rejectedWith(/common\.EmptyPropertyKey/);262263 await expect(executeTransaction(264 api, 265 alice, 266 api.tx.unique.setCollectionProperties(collection, [267 {key: 'CRISPR-Cas9', value: 'rewriting nature!'},268 ]), 269 ), 'on setting the correctly-but-still-badly-named property').to.not.be.rejected;270271 const keys = invalidProperties.flatMap(propertySet => propertySet.map(property => property.key)).concat('CRISPR-Cas9').concat('');272273 const properties = (await api.rpc.unique.collectionProperties(collection, keys)).toHuman();274 expect(properties).to.be.deep.equal([275 {key: 'CRISPR-Cas9', value: 'rewriting nature!'},276 ]);277278 for (let i = 0; i < invalidProperties.length; i++) {279 await expect(executeTransaction(280 api, 281 alice, 282 api.tx.unique.deleteCollectionProperties(collection, invalidProperties[i].map(propertySet => propertySet.key)), 283 ), `on trying to delete the non-existent badly-named property #${i}`).to.be.rejectedWith(/common\.InvalidCharacterInPropertyKey/);284 }285 });286 });287});288289// ---------- ACCESS RIGHTS290291describe('Integration Test: Access Rights to Token Properties', () => {292 before(async () => {293 await usingApi(async () => {294 alice = privateKey('//Alice');295 bob = privateKey('//Bob');296 });297 });298 299 it('Reads access rights to properties of a collection', async () => {300 await usingApi(async api => {301 const collection = await createCollectionExpectSuccess();302 const propertyRights = (await api.query.common.collectionPropertyPermissions(collection)).toJSON();303 expect(propertyRights).to.be.empty;304 });305 });306 307 it('Sets access rights to properties of a collection', async () => {308 await usingApi(async api => {309 const collection = await createCollectionExpectSuccess();310311 await expect(executeTransaction(312 api, 313 alice, 314 api.tx.unique.setPropertyPermissions(collection, [{key: 'skullduggery', permission: {mutable: true}}]), 315 )).to.not.be.rejected;316317 await addCollectionAdminExpectSuccess(alice, collection, bob.address);318319 await expect(executeTransaction(320 api, 321 alice, 322 api.tx.unique.setPropertyPermissions(collection, [{key: 'mindgame', permission: {collectionAdmin: true, tokenOwner: false}}]), 323 )).to.not.be.rejected;324325 const propertyRights = (await api.rpc.unique.propertyPermissions(collection, ['skullduggery', 'mindgame'])).toHuman();326 expect(propertyRights).to.be.deep.equal([327 {key: 'skullduggery', permission: {'mutable': true, 'collectionAdmin': false, 'tokenOwner': false}},328 {key: 'mindgame', permission: {'mutable': false, 'collectionAdmin': true, 'tokenOwner': false}},329 ]);330 });331 });332 333 it('Changes access rights to properties of a collection', async () => {334 await usingApi(async api => {335 const collection = await createCollectionExpectSuccess();336337 await expect(executeTransaction(338 api, 339 alice, 340 api.tx.unique.setPropertyPermissions(collection, [{key: 'skullduggery', permission: {mutable: true, collectionAdmin: true}}]), 341 )).to.not.be.rejected;342343 await expect(executeTransaction(344 api, 345 alice, 346 api.tx.unique.setPropertyPermissions(collection, [{key: 'skullduggery', permission: {mutable: false, tokenOwner: true}}]), 347 )).to.not.be.rejected;348349 const propertyRights = (await api.rpc.unique.propertyPermissions(collection, ['skullduggery'])).toHuman();350 expect(propertyRights).to.be.deep.equal([351 {key: 'skullduggery', permission: {'mutable': false, 'collectionAdmin': false, 'tokenOwner': true}},352 ]);353 });354 });355});356357describe('Negative Integration Test: Access Rights to Token Properties', () => {358 before(async () => {359 await usingApi(async () => {360 alice = privateKey('//Alice');361 bob = privateKey('//Bob');362 });363 });364365 it('Prevents from setting access rights to properties of a collection if not an onwer/admin', async () => {366 await usingApi(async api => {367 const collection = await createCollectionExpectSuccess();368369 await expect(executeTransaction(370 api, 371 bob, 372 api.tx.unique.setPropertyPermissions(collection, [{key: 'skullduggery', permission: {mutable: true, tokenOwner: true}}]), 373 )).to.be.rejectedWith(/common\.NoPermission/);374375 const propertyRights = (await api.rpc.unique.propertyPermissions(collection, ['skullduggery'])).toJSON();376 expect(propertyRights).to.be.empty;377 });378 });379380 it('Prevents from adding too many possible properties', async () => {381 await usingApi(async api => {382 const collection = await createCollectionExpectSuccess();383384 const constitution = [];385 for (let i = 0; i < 65; i++) {386 constitution.push({387 key: 'property_' + i,388 permission: Math.random() > 0.5 ? {mutable: true, collectionAdmin: true, tokenOwner: true} : {},389 });390 }391392 await expect(executeTransaction(393 api, 394 alice, 395 api.tx.unique.setPropertyPermissions(collection, constitution), 396 )).to.be.rejectedWith(/common\.PropertyLimitReached/);397398 const propertyRights = (await api.query.common.collectionPropertyPermissions(collection)).toJSON();399 expect(propertyRights).to.be.empty;400 });401 });402403 it('Prevents access rights to be modified if constant', async () => {404 await usingApi(async api => {405 const collection = await createCollectionExpectSuccess();406407 await expect(executeTransaction(408 api, 409 alice, 410 api.tx.unique.setPropertyPermissions(collection, [{key: 'skullduggery', permission: {mutable: false, tokenOwner: true}}]), 411 )).to.not.be.rejected;412413 await expect(executeTransaction(414 api, 415 alice, 416 api.tx.unique.setPropertyPermissions(collection, [{key: 'skullduggery', permission: {}}]), 417 )).to.be.rejectedWith(/common\.NoPermission/);418419 const propertyRights = (await api.rpc.unique.propertyPermissions(collection, ['skullduggery'])).toHuman();420 expect(propertyRights).to.deep.equal([421 {key: 'skullduggery', permission: {'mutable': false, 'collectionAdmin': false, 'tokenOwner': true}},422 ]);423 });424 });425426 it('Prevents adding properties with invalid names', async () => {427 await usingApi(async api => {428 const collection = await createCollectionExpectSuccess();429430 const invalidProperties = [431 [{key: 'skullduggery', permission: {tokenOwner: true}}, {key: 'im possible', permission: {collectionAdmin: true}}],432 [{key: 'G#4', permission: {tokenOwner: true}}],433 [{key: 'HÆMILTON', permission: {mutable: false, collectionAdmin: true, tokenOwner: true}}],434 ];435436 for (let i = 0; i < invalidProperties.length; i++) {437 await expect(executeTransaction(438 api, 439 alice, 440 api.tx.unique.setPropertyPermissions(collection, invalidProperties[i]), 441 ), `on setting the new badly-named property #${i}`).to.be.rejectedWith(/common\.InvalidCharacterInPropertyKey/);442 }443444 await expect(executeTransaction(445 api, 446 alice, 447 api.tx.unique.setPropertyPermissions(collection, [{key: '', permission: {}}]), 448 ), 'on rejecting an unnamed property').to.be.rejectedWith(/common\.EmptyPropertyKey/);449450 const correctKey = '--0x03116e387820CA05'; // PolkadotJS would parse this as an already encoded hex-string451 await expect(executeTransaction(452 api, 453 alice, 454 api.tx.unique.setPropertyPermissions(collection, [455 {key: correctKey, permission: {collectionAdmin: true}},456 ]), 457 ), 'on setting the correctly-but-still-badly-named property').to.not.be.rejected;458459 const keys = invalidProperties.flatMap(propertySet => propertySet.map(property => property.key)).concat(correctKey).concat('');460461 const propertyRights = (await api.rpc.unique.propertyPermissions(collection, keys)).toHuman();462 expect(propertyRights).to.be.deep.equal([463 {key: correctKey, permission: {mutable: false, collectionAdmin: true, tokenOwner: false}},464 ]);465 });466 });467});468469// ---------- TOKEN PROPERTIES470471describe('Integration Test: Token Properties', () => {472 let collection: number;473 let token: number;474 let permissions: {permission: any, signers: IKeyringPair[]}[];475476 before(async () => {477 await usingApi(async () => {478 alice = privateKey('//Alice');479 bob = privateKey('//Bob');480 charlie = privateKey('//Charlie');481482 permissions = [483 {permission: {mutable: true, collectionAdmin: true}, signers: [alice, bob]},484 {permission: {mutable: false, collectionAdmin: true}, signers: [alice, bob]},485 {permission: {mutable: true, tokenOwner: true}, signers: [charlie]},486 {permission: {mutable: false, tokenOwner: true}, signers: [charlie]},487 {permission: {mutable: true, collectionAdmin: true, tokenOwner: true}, signers: [alice, bob, charlie]},488 {permission: {mutable: false, collectionAdmin: true, tokenOwner: true}, signers: [alice, bob, charlie]},489 ];490 });491 });492493 beforeEach(async () => {494 await usingApi(async () => {495 collection = await createCollectionExpectSuccess();496 token = await createItemExpectSuccess(alice, collection, 'NFT');497 await addCollectionAdminExpectSuccess(alice, collection, bob.address);498 await transferExpectSuccess(collection, token, alice, charlie);499 });500 });501 502 it('Reads yet empty properties of a token', async () => {503 await usingApi(async api => {504 const collection = await createCollectionExpectSuccess();505 const token = await createItemExpectSuccess(alice, collection, 'NFT');506 507 const properties = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();508 expect(properties.map).to.be.empty;509 expect(properties.consumedSpace).to.be.equal(0);510511 const tokenData = (await api.rpc.unique.tokenData(collection, token, ['anything'])).toJSON().properties;512 expect(tokenData).to.be.empty;513 });514 });515516 it('Assigns properties to a token according to permissions', async () => {517 await usingApi(async api => {518 const propertyKeys: string[] = [];519 let i = 0;520 for (const permission of permissions) {521 for (const signer of permission.signers) {522 const key = i + '_' + signer.address;523 propertyKeys.push(key);524525 await expect(executeTransaction(526 api, 527 alice, 528 api.tx.unique.setPropertyPermissions(collection, [{key: key, permission: permission.permission}]), 529 ), `on setting permission ${i} by ${signer.address}`).to.not.be.rejected;530531 await expect(executeTransaction(532 api, 533 signer, 534 api.tx.unique.setTokenProperties(collection, token, [{key: key, value: 'Serotonin increase'}]), 535 ), `on adding property ${i} by ${signer.address}`).to.not.be.rejected;536 }537538 i++;539 }540541 const properties = (await api.rpc.unique.tokenProperties(collection, token, propertyKeys)).toHuman() as any[];542 const tokensData = (await api.rpc.unique.tokenData(collection, token, propertyKeys)).toHuman().properties as any[];543 for (let i = 0; i < properties.length; i++) {544 expect(properties[i].value).to.be.equal('Serotonin increase');545 expect(tokensData[i].value).to.be.equal('Serotonin increase');546 }547 });548 });549550 it('Changes properties of a token according to permissions', async () => {551 await usingApi(async api => {552 const propertyKeys: string[] = [];553 let i = 0;554 for (const permission of permissions) {555 if (!permission.permission.mutable) continue;556 557 for (const signer of permission.signers) {558 const key = i + '_' + signer.address;559 propertyKeys.push(key);560561 await expect(executeTransaction(562 api, 563 alice, 564 api.tx.unique.setPropertyPermissions(collection, [{key: key, permission: permission.permission}]), 565 ), `on setting permission ${i} by ${signer.address}`).to.not.be.rejected;566567 await expect(executeTransaction(568 api, 569 signer, 570 api.tx.unique.setTokenProperties(collection, token, [{key: key, value: 'Serotonin increase'}]), 571 ), `on adding property ${i} by ${signer.address}`).to.not.be.rejected;572573 await expect(executeTransaction(574 api, 575 signer, 576 api.tx.unique.setTokenProperties(collection, token, [{key: key, value: 'Serotonin stable'}]), 577 ), `on changing property ${i} by ${signer.address}`).to.not.be.rejected;578 }579580 i++;581 }582583 const properties = (await api.rpc.unique.tokenProperties(collection, token, propertyKeys)).toHuman() as any[];584 const tokensData = (await api.rpc.unique.tokenData(collection, token, propertyKeys)).toHuman().properties as any[];585 for (let i = 0; i < properties.length; i++) {586 expect(properties[i].value).to.be.equal('Serotonin stable');587 expect(tokensData[i].value).to.be.equal('Serotonin stable');588 }589 });590 });591592 it('Deletes properties of a token according to permissions', async () => {593 await usingApi(async api => {594 const propertyKeys: string[] = [];595 let i = 0;596597 for (const permission of permissions) {598 if (!permission.permission.mutable) continue;599 600 for (const signer of permission.signers) {601 const key = i + '_' + signer.address;602 propertyKeys.push(key);603604 await expect(executeTransaction(605 api, 606 alice, 607 api.tx.unique.setPropertyPermissions(collection, [{key: key, permission: permission.permission}]), 608 ), `on setting permission ${i} by ${signer.address}`).to.not.be.rejected;609610 await expect(executeTransaction(611 api, 612 signer, 613 api.tx.unique.setTokenProperties(collection, token, [{key: key, value: 'Serotonin increase'}]), 614 ), `on adding property ${i} by ${signer.address}`).to.not.be.rejected;615616 await expect(executeTransaction(617 api, 618 signer, 619 api.tx.unique.deleteTokenProperties(collection, token, [key]), 620 ), `on deleting property ${i} by ${signer.address}`).to.not.be.rejected;621 }622 623 i++;624 }625626 const properties = (await api.rpc.unique.tokenProperties(collection, token, propertyKeys)).toJSON() as any[];627 expect(properties).to.be.empty;628 const tokensData = (await api.rpc.unique.tokenData(collection, token, propertyKeys)).toJSON().properties as any[];629 expect(tokensData).to.be.empty;630 expect((await api.query.nonfungible.tokenProperties(collection, token)).toJSON().consumedSpace).to.be.equal(0);631 });632 });633});634635describe('Negative Integration Test: Token Properties', () => {636 let collection: number;637 let token: number;638 let originalSpace: number;639 let constitution: {permission: any, signers: IKeyringPair[], sinner: IKeyringPair}[];640641 before(async () => {642 await usingApi(async () => {643 alice = privateKey('//Alice');644 bob = privateKey('//Bob');645 charlie = privateKey('//Charlie');646 const dave = privateKey('//Dave');647648 constitution = [649 {permission: {mutable: true, collectionAdmin: true}, signers: [alice, bob], sinner: charlie},650 {permission: {mutable: false, collectionAdmin: true}, signers: [alice, bob], sinner: charlie},651 {permission: {mutable: true, tokenOwner: true}, signers: [charlie], sinner: alice},652 {permission: {mutable: false, tokenOwner: true}, signers: [charlie], sinner: alice},653 {permission: {mutable: true, collectionAdmin: true, tokenOwner: true}, signers: [alice, bob, charlie], sinner: dave},654 {permission: {mutable: false, collectionAdmin: true, tokenOwner: true}, signers: [alice, bob, charlie], sinner: dave},655 ];656 });657 });658659 beforeEach(async () => {660 collection = await createCollectionExpectSuccess();661 token = await createItemExpectSuccess(alice, collection, 'NFT');662 await addCollectionAdminExpectSuccess(alice, collection, bob.address);663 await transferExpectSuccess(collection, token, alice, charlie);664 665 await usingApi(async api => {666 let i = 0;667 for (const passage of constitution) {668 const signer = passage.signers[0];669 670 await expect(executeTransaction(671 api, 672 alice, 673 api.tx.unique.setPropertyPermissions(collection, [{key: `${i}`, permission: passage.permission}]), 674 ), `on setting permission ${i} by ${signer.address}`).to.not.be.rejected;675676 await expect(executeTransaction(677 api, 678 signer, 679 api.tx.unique.setTokenProperties(collection, token, [{key: `${i}`, value: 'Serotonin increase'}]), 680 ), `on adding property ${i} by ${signer.address}`).to.not.be.rejected;681682 i++;683 }684685 originalSpace = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON().consumedSpace as number;686 });687 });688689 it('Forbids changing/deleting properties of a token if the user is outside of permissions', async () => {690 await usingApi(async api => {691 let i = -1;692 for (const forbiddance of constitution) {693 i++;694 if (!forbiddance.permission.mutable) continue;695696 await expect(executeTransaction(697 api, 698 forbiddance.sinner, 699 api.tx.unique.setTokenProperties(collection, token, [{key: `${i}`, value: 'Serotonin down'}]), 700 ), `on failing to change property ${i} by ${forbiddance.sinner.address}`).to.be.rejectedWith(/common\.NoPermission/);701702 await expect(executeTransaction(703 api, 704 forbiddance.sinner, 705 api.tx.unique.deleteTokenProperties(collection, token, [`${i}`]), 706 ), `on failing to delete property ${i} by ${forbiddance.sinner.address}`).to.be.rejectedWith(/common\.NoPermission/);707 }708709 const properties = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();710 expect(properties.consumedSpace).to.be.equal(originalSpace);711 });712 });713714 it('Forbids changing/deleting properties of a token if the property is permanent (immutable)', async () => {715 await usingApi(async api => {716 let i = -1;717 for (const permission of constitution) {718 i++;719 if (permission.permission.mutable) continue;720721 await expect(executeTransaction(722 api, 723 permission.signers[0], 724 api.tx.unique.setTokenProperties(collection, token, [{key: `${i}`, value: 'Serotonin down'}]), 725 ), `on failing to change property ${i} by ${permission.signers[0].address}`).to.be.rejectedWith(/common\.NoPermission/);726727 await expect(executeTransaction(728 api, 729 permission.signers[0], 730 api.tx.unique.deleteTokenProperties(collection, token, [i.toString()]), 731 ), `on failing to delete property ${i} by ${permission.signers[0].address}`).to.be.rejectedWith(/common\.NoPermission/);732 }733734 const properties = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();735 expect(properties.consumedSpace).to.be.equal(originalSpace);736 });737 });738739 it('Forbids adding properties to a token if the property is not declared / forbidden with the \'None\' permission', async () => {740 await usingApi(async api => {741 await expect(executeTransaction(742 api, 743 alice, 744 api.tx.unique.setTokenProperties(collection, token, [{key: 'non-existent', value: 'I exist!'}]), 745 ), 'on failing to add a previously non-existent property').to.be.rejectedWith(/common\.NoPermission/);746 747 await expect(executeTransaction(748 api, 749 alice, 750 api.tx.unique.setPropertyPermissions(collection, [{key: 'now-existent', permission: {}}]), 751 ), 'on setting a new non-permitted property').to.not.be.rejected;752753 await expect(executeTransaction(754 api, 755 alice, 756 api.tx.unique.setTokenProperties(collection, token, [{key: 'now-existent', value: 'I exist!'}]), 757 ), 'on failing to add a property forbidden by the \'None\' permission').to.be.rejectedWith(/common\.NoPermission/);758759 expect((await api.rpc.unique.tokenProperties(collection, token, ['non-existent', 'now-existent'])).toJSON()).to.be.empty;760 const properties = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();761 expect(properties.consumedSpace).to.be.equal(originalSpace);762 });763 });764765 it('Forbids adding too many properties to a token', async () => {766 await usingApi(async api => {767 await expect(executeTransaction(768 api, 769 alice, 770 api.tx.unique.setPropertyPermissions(collection, [771 {key: 'a_holy_book', permission: {collectionAdmin: true, tokenOwner: true}}, 772 {key: 'young_years', permission: {collectionAdmin: true, tokenOwner: true}},773 ]), 774 ), 'on setting a new non-permitted property').to.not.be.rejected;775776 // Mute the general tx parsing error777 {778 console.error = () => {};779 await expect(executeTransaction(780 api, 781 alice, 782 api.tx.unique.setCollectionProperties(collection, [{key: 'a_holy_book', value: 'word '.repeat(6554)}]), 783 )).to.be.rejected;784 }785786 await expect(executeTransaction(787 api, 788 alice, 789 api.tx.unique.setTokenProperties(collection, token, [790 {key: 'a_holy_book', value: 'word '.repeat(3277)}, 791 {key: 'young_years', value: 'neverending'.repeat(1490)},792 ]), 793 )).to.be.rejectedWith(/common\.NoSpaceForProperty/);794795 expect((await api.rpc.unique.tokenProperties(collection, token, ['a_holy_book', 'young_years'])).toJSON()).to.be.empty;796 const propertiesMap = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();797 expect(propertiesMap.consumedSpace).to.be.equal(originalSpace);798 });799 });800});1import {expect} from 'chai';2import usingApi, {executeTransaction} from '../substrate/substrate-api';3import {4 addCollectionAdminExpectSuccess,5 createCollectionExpectSuccess,6 createItemExpectSuccess,7 getCreateCollectionResult,8 transferExpectSuccess,9} from '../util/helpers';10import {IKeyringPair} from '@polkadot/types/types';1112let alice: IKeyringPair;13let bob: IKeyringPair;14let charlie: IKeyringPair;1516describe('Composite Properties Test', () => {17 before(async () => {18 await usingApi(async (api, privateKeyWrapper) => {19 alice = privateKeyWrapper!('//Alice');20 bob = privateKeyWrapper!('//Bob');21 });22 });2324 it('Makes sure collectionById supplies required fields', async () => {25 await usingApi(async api => {26 const collectionId = await createCollectionExpectSuccess();2728 const collectionOption = await api.rpc.unique.collectionById(collectionId);29 expect(collectionOption.isSome).to.be.true;30 let collection = collectionOption.unwrap();31 expect(collection.tokenPropertyPermissions.toHuman()).to.be.empty;32 expect(collection.properties.toHuman()).to.be.empty;3334 const propertyPermissions = [35 {key: 'mindgame', permission: {collectionAdmin: true, mutable: false, tokenOwner: true}},36 {key: 'skullduggery', permission: {collectionAdmin: false, mutable: true, tokenOwner: false}},37 ];38 await expect(executeTransaction(39 api, 40 alice, 41 api.tx.unique.setPropertyPermissions(collectionId, propertyPermissions), 42 )).to.not.be.rejected;4344 const collectionProperties = [45 {key: 'black_hole', value: 'LIGO'},46 {key: 'electron', value: 'come bond'}, 47 ];48 await expect(executeTransaction(49 api, 50 alice, 51 api.tx.unique.setCollectionProperties(collectionId, collectionProperties), 52 )).to.not.be.rejected;5354 collection = (await api.rpc.unique.collectionById(collectionId)).unwrap();55 expect(collection.tokenPropertyPermissions.toHuman()).to.be.deep.equal(propertyPermissions);56 expect(collection.properties.toHuman()).to.be.deep.equal(collectionProperties);57 });58 });59});6061// ---------- COLLECTION PROPERTIES6263describe('Integration Test: Collection Properties', () => {64 before(async () => {65 await usingApi(async (api, privateKeyWrapper) => {66 alice = privateKeyWrapper!('//Alice');67 bob = privateKeyWrapper!('//Bob');68 });69 });7071 it('Reads properties from a collection', async () => {72 await usingApi(async api => {73 const collection = await createCollectionExpectSuccess();74 const properties = (await api.query.common.collectionProperties(collection)).toJSON();75 expect(properties.map).to.be.empty;76 expect(properties.consumedSpace).to.equal(0);77 });78 });7980 it('Sets properties for a collection', async () => {81 await usingApi(async api => {82 const events = await executeTransaction(api, bob, api.tx.unique.createCollectionEx({mode: 'NFT'}));83 const {collectionId} = getCreateCollectionResult(events);8485 // As owner86 await expect(executeTransaction(87 api, 88 bob, 89 api.tx.unique.setCollectionProperties(collectionId, [{key: 'electron', value: 'come bond'}]), 90 )).to.not.be.rejected;9192 await addCollectionAdminExpectSuccess(bob, collectionId, alice.address);9394 // As administrator95 await expect(executeTransaction(96 api, 97 alice, 98 api.tx.unique.setCollectionProperties(collectionId, [{key: 'black_hole'}]), 99 )).to.not.be.rejected;100101 const properties = (await api.rpc.unique.collectionProperties(collectionId, ['electron', 'black_hole'])).toHuman();102 expect(properties).to.be.deep.equal([103 {key: 'electron', value: 'come bond'},104 {key: 'black_hole', value: ''},105 ]);106 });107 });108109 it('Changes properties of a collection', async () => {110 await usingApi(async api => {111 const collection = await createCollectionExpectSuccess();112113 await expect(executeTransaction(114 api, 115 alice, 116 api.tx.unique.setCollectionProperties(collection, [{key: 'electron', value: 'come bond'}, {key: 'black_hole'}]), 117 )).to.not.be.rejected;118119 // Mutate the properties120 await expect(executeTransaction(121 api, 122 alice, 123 api.tx.unique.setCollectionProperties(collection, [{key: 'electron', value: 'bonded'}, {key: 'black_hole', value: 'LIGO'}]), 124 )).to.not.be.rejected;125126 const properties = (await api.rpc.unique.collectionProperties(collection, ['electron', 'black_hole'])).toHuman();127 expect(properties).to.be.deep.equal([128 {key: 'electron', value: 'bonded'},129 {key: 'black_hole', value: 'LIGO'},130 ]);131 });132 });133134 it('Deletes properties of a collection', async () => {135 await usingApi(async api => {136 const collection = await createCollectionExpectSuccess();137138 await expect(executeTransaction(139 api, 140 alice, 141 api.tx.unique.setCollectionProperties(collection, [{key: 'electron', value: 'come bond'}, {key: 'black_hole', value: 'LIGO'}]), 142 )).to.not.be.rejected;143144 await expect(executeTransaction(145 api, 146 alice, 147 api.tx.unique.deleteCollectionProperties(collection, ['electron']), 148 )).to.not.be.rejected;149150 const properties = (await api.rpc.unique.collectionProperties(collection, ['electron', 'black_hole'])).toHuman();151 expect(properties).to.be.deep.equal([152 {key: 'black_hole', value: 'LIGO'},153 ]);154 });155 });156});157158describe('Negative Integration Test: Collection Properties', () => {159 before(async () => {160 await usingApi(async (api, privateKeyWrapper) => {161 alice = privateKeyWrapper!('//Alice');162 bob = privateKeyWrapper!('//Bob');163 });164 });165 166 it('Fails to set properties in a collection if not its onwer/administrator', async () => {167 await usingApi(async api => {168 const collection = await createCollectionExpectSuccess();169170 await expect(executeTransaction(171 api, 172 bob, 173 api.tx.unique.setCollectionProperties(collection, [{key: 'electron', value: 'come bond'}, {key: 'black_hole', value: 'LIGO'}]), 174 )).to.be.rejectedWith(/common\.NoPermission/);175 176 const properties = (await api.query.common.collectionProperties(collection)).toJSON();177 expect(properties.map).to.be.empty;178 expect(properties.consumedSpace).to.equal(0);179 });180 });181 182 it('Fails to set properties that exceed the limits', async () => {183 await usingApi(async api => {184 const collection = await createCollectionExpectSuccess();185 const spaceLimit = (await api.query.common.collectionProperties(collection)).toJSON().spaceLimit as number; 186187 // Mute the general tx parsing error, too many bytes to process188 {189 console.error = () => {};190 await expect(executeTransaction(191 api, 192 alice, 193 api.tx.unique.setCollectionProperties(collection, [{key: 'electron', value: 'low high '.repeat(Math.ceil(spaceLimit! / 9))}]), 194 )).to.be.rejected;195 }196197 let properties = (await api.rpc.unique.collectionProperties(collection, ['electron'])).toJSON();198 expect(properties).to.be.empty;199200 await expect(executeTransaction(201 api, 202 alice, 203 api.tx.unique.setCollectionProperties(collection, [204 {key: 'electron', value: 'low high '.repeat(Math.ceil(spaceLimit! / 18))}, 205 {key: 'black_hole', value: '0'.repeat(Math.ceil(spaceLimit! / 2))}, 206 ]), 207 )).to.be.rejectedWith(/common\.NoSpaceForProperty/);208209 properties = (await api.rpc.unique.collectionProperties(collection, ['electron', 'black hole'])).toJSON();210 expect(properties).to.be.empty;211 });212 });213 214 it('Fails to set more properties than it is allowed', async () => {215 await usingApi(async api => {216 const collection = await createCollectionExpectSuccess();217218 const propertiesToBeSet = [];219 for (let i = 0; i < 65; i++) {220 propertiesToBeSet.push({221 key: 'electron_' + i,222 value: Math.random() > 0.5 ? 'high' : 'low',223 });224 }225226 await expect(executeTransaction(227 api, 228 alice, 229 api.tx.unique.setCollectionProperties(collection, propertiesToBeSet), 230 )).to.be.rejectedWith(/common\.PropertyLimitReached/);231232 const properties = (await api.query.common.collectionProperties(collection)).toJSON();233 expect(properties.map).to.be.empty;234 expect(properties.consumedSpace).to.equal(0);235 });236 });237238 it('Fails to set properties with invalid names', async () => {239 await usingApi(async api => {240 const collection = await createCollectionExpectSuccess();241242 const invalidProperties = [243 [{key: 'electron', value: 'negative'}, {key: 'string theory', value: 'understandable'}],244 [{key: 'Mr.Sandman', value: 'Bring me a gene'}],245 [{key: 'déjà vu', value: 'hmm...'}],246 ];247248 for (let i = 0; i < invalidProperties.length; i++) {249 await expect(executeTransaction(250 api, 251 alice, 252 api.tx.unique.setCollectionProperties(collection, invalidProperties[i]), 253 ), `on rejecting the new badly-named property #${i}`).to.be.rejectedWith(/common\.InvalidCharacterInPropertyKey/);254 }255256 await expect(executeTransaction(257 api, 258 alice, 259 api.tx.unique.setCollectionProperties(collection, [{key: '', value: 'nothing must not exist'}]), 260 ), 'on rejecting an unnamed property').to.be.rejectedWith(/common\.EmptyPropertyKey/);261262 await expect(executeTransaction(263 api, 264 alice, 265 api.tx.unique.setCollectionProperties(collection, [266 {key: 'CRISPR-Cas9', value: 'rewriting nature!'},267 ]), 268 ), 'on setting the correctly-but-still-badly-named property').to.not.be.rejected;269270 const keys = invalidProperties.flatMap(propertySet => propertySet.map(property => property.key)).concat('CRISPR-Cas9').concat('');271272 const properties = (await api.rpc.unique.collectionProperties(collection, keys)).toHuman();273 expect(properties).to.be.deep.equal([274 {key: 'CRISPR-Cas9', value: 'rewriting nature!'},275 ]);276277 for (let i = 0; i < invalidProperties.length; i++) {278 await expect(executeTransaction(279 api, 280 alice, 281 api.tx.unique.deleteCollectionProperties(collection, invalidProperties[i].map(propertySet => propertySet.key)), 282 ), `on trying to delete the non-existent badly-named property #${i}`).to.be.rejectedWith(/common\.InvalidCharacterInPropertyKey/);283 }284 });285 });286});287288// ---------- ACCESS RIGHTS289290describe('Integration Test: Access Rights to Token Properties', () => {291 before(async () => {292 await usingApi(async (api, privateKeyWrapper) => {293 alice = privateKeyWrapper!('//Alice');294 bob = privateKeyWrapper!('//Bob');295 });296 });297 298 it('Reads access rights to properties of a collection', async () => {299 await usingApi(async api => {300 const collection = await createCollectionExpectSuccess();301 const propertyRights = (await api.query.common.collectionPropertyPermissions(collection)).toJSON();302 expect(propertyRights).to.be.empty;303 });304 });305 306 it('Sets access rights to properties of a collection', async () => {307 await usingApi(async api => {308 const collection = await createCollectionExpectSuccess();309310 await expect(executeTransaction(311 api, 312 alice, 313 api.tx.unique.setPropertyPermissions(collection, [{key: 'skullduggery', permission: {mutable: true}}]), 314 )).to.not.be.rejected;315316 await addCollectionAdminExpectSuccess(alice, collection, bob.address);317318 await expect(executeTransaction(319 api, 320 alice, 321 api.tx.unique.setPropertyPermissions(collection, [{key: 'mindgame', permission: {collectionAdmin: true, tokenOwner: false}}]), 322 )).to.not.be.rejected;323324 const propertyRights = (await api.rpc.unique.propertyPermissions(collection, ['skullduggery', 'mindgame'])).toHuman();325 expect(propertyRights).to.be.deep.equal([326 {key: 'skullduggery', permission: {'mutable': true, 'collectionAdmin': false, 'tokenOwner': false}},327 {key: 'mindgame', permission: {'mutable': false, 'collectionAdmin': true, 'tokenOwner': false}},328 ]);329 });330 });331 332 it('Changes access rights to properties of a collection', async () => {333 await usingApi(async api => {334 const collection = await createCollectionExpectSuccess();335336 await expect(executeTransaction(337 api, 338 alice, 339 api.tx.unique.setPropertyPermissions(collection, [{key: 'skullduggery', permission: {mutable: true, collectionAdmin: true}}]), 340 )).to.not.be.rejected;341342 await expect(executeTransaction(343 api, 344 alice, 345 api.tx.unique.setPropertyPermissions(collection, [{key: 'skullduggery', permission: {mutable: false, tokenOwner: true}}]), 346 )).to.not.be.rejected;347348 const propertyRights = (await api.rpc.unique.propertyPermissions(collection, ['skullduggery'])).toHuman();349 expect(propertyRights).to.be.deep.equal([350 {key: 'skullduggery', permission: {'mutable': false, 'collectionAdmin': false, 'tokenOwner': true}},351 ]);352 });353 });354});355356describe('Negative Integration Test: Access Rights to Token Properties', () => {357 before(async () => {358 await usingApi(async (api, privateKeyWrapper) => {359 alice = privateKeyWrapper!('//Alice');360 bob = privateKeyWrapper!('//Bob');361 });362 });363364 it('Prevents from setting access rights to properties of a collection if not an onwer/admin', async () => {365 await usingApi(async api => {366 const collection = await createCollectionExpectSuccess();367368 await expect(executeTransaction(369 api, 370 bob, 371 api.tx.unique.setPropertyPermissions(collection, [{key: 'skullduggery', permission: {mutable: true, tokenOwner: true}}]), 372 )).to.be.rejectedWith(/common\.NoPermission/);373374 const propertyRights = (await api.rpc.unique.propertyPermissions(collection, ['skullduggery'])).toJSON();375 expect(propertyRights).to.be.empty;376 });377 });378379 it('Prevents from adding too many possible properties', async () => {380 await usingApi(async api => {381 const collection = await createCollectionExpectSuccess();382383 const constitution = [];384 for (let i = 0; i < 65; i++) {385 constitution.push({386 key: 'property_' + i,387 permission: Math.random() > 0.5 ? {mutable: true, collectionAdmin: true, tokenOwner: true} : {},388 });389 }390391 await expect(executeTransaction(392 api, 393 alice, 394 api.tx.unique.setPropertyPermissions(collection, constitution), 395 )).to.be.rejectedWith(/common\.PropertyLimitReached/);396397 const propertyRights = (await api.query.common.collectionPropertyPermissions(collection)).toJSON();398 expect(propertyRights).to.be.empty;399 });400 });401402 it('Prevents access rights to be modified if constant', async () => {403 await usingApi(async api => {404 const collection = await createCollectionExpectSuccess();405406 await expect(executeTransaction(407 api, 408 alice, 409 api.tx.unique.setPropertyPermissions(collection, [{key: 'skullduggery', permission: {mutable: false, tokenOwner: true}}]), 410 )).to.not.be.rejected;411412 await expect(executeTransaction(413 api, 414 alice, 415 api.tx.unique.setPropertyPermissions(collection, [{key: 'skullduggery', permission: {}}]), 416 )).to.be.rejectedWith(/common\.NoPermission/);417418 const propertyRights = (await api.rpc.unique.propertyPermissions(collection, ['skullduggery'])).toHuman();419 expect(propertyRights).to.deep.equal([420 {key: 'skullduggery', permission: {'mutable': false, 'collectionAdmin': false, 'tokenOwner': true}},421 ]);422 });423 });424425 it('Prevents adding properties with invalid names', async () => {426 await usingApi(async api => {427 const collection = await createCollectionExpectSuccess();428429 const invalidProperties = [430 [{key: 'skullduggery', permission: {tokenOwner: true}}, {key: 'im possible', permission: {collectionAdmin: true}}],431 [{key: 'G#4', permission: {tokenOwner: true}}],432 [{key: 'HÆMILTON', permission: {mutable: false, collectionAdmin: true, tokenOwner: true}}],433 ];434435 for (let i = 0; i < invalidProperties.length; i++) {436 await expect(executeTransaction(437 api, 438 alice, 439 api.tx.unique.setPropertyPermissions(collection, invalidProperties[i]), 440 ), `on setting the new badly-named property #${i}`).to.be.rejectedWith(/common\.InvalidCharacterInPropertyKey/);441 }442443 await expect(executeTransaction(444 api, 445 alice, 446 api.tx.unique.setPropertyPermissions(collection, [{key: '', permission: {}}]), 447 ), 'on rejecting an unnamed property').to.be.rejectedWith(/common\.EmptyPropertyKey/);448449 const correctKey = '--0x03116e387820CA05'; // PolkadotJS would parse this as an already encoded hex-string450 await expect(executeTransaction(451 api, 452 alice, 453 api.tx.unique.setPropertyPermissions(collection, [454 {key: correctKey, permission: {collectionAdmin: true}},455 ]), 456 ), 'on setting the correctly-but-still-badly-named property').to.not.be.rejected;457458 const keys = invalidProperties.flatMap(propertySet => propertySet.map(property => property.key)).concat(correctKey).concat('');459460 const propertyRights = (await api.rpc.unique.propertyPermissions(collection, keys)).toHuman();461 expect(propertyRights).to.be.deep.equal([462 {key: correctKey, permission: {mutable: false, collectionAdmin: true, tokenOwner: false}},463 ]);464 });465 });466});467468// ---------- TOKEN PROPERTIES469470describe('Integration Test: Token Properties', () => {471 let collection: number;472 let token: number;473 let permissions: {permission: any, signers: IKeyringPair[]}[];474475 before(async () => {476 await usingApi(async (api, privateKeyWrapper) => {477 alice = privateKeyWrapper!('//Alice');478 bob = privateKeyWrapper!('//Bob');479 charlie = privateKeyWrapper!('//Charlie');480481 permissions = [482 {permission: {mutable: true, collectionAdmin: true}, signers: [alice, bob]},483 {permission: {mutable: false, collectionAdmin: true}, signers: [alice, bob]},484 {permission: {mutable: true, tokenOwner: true}, signers: [charlie]},485 {permission: {mutable: false, tokenOwner: true}, signers: [charlie]},486 {permission: {mutable: true, collectionAdmin: true, tokenOwner: true}, signers: [alice, bob, charlie]},487 {permission: {mutable: false, collectionAdmin: true, tokenOwner: true}, signers: [alice, bob, charlie]},488 ];489 });490 });491492 beforeEach(async () => {493 await usingApi(async () => {494 collection = await createCollectionExpectSuccess();495 token = await createItemExpectSuccess(alice, collection, 'NFT');496 await addCollectionAdminExpectSuccess(alice, collection, bob.address);497 await transferExpectSuccess(collection, token, alice, charlie);498 });499 });500 501 it('Reads yet empty properties of a token', async () => {502 await usingApi(async api => {503 const collection = await createCollectionExpectSuccess();504 const token = await createItemExpectSuccess(alice, collection, 'NFT');505 506 const properties = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();507 expect(properties.map).to.be.empty;508 expect(properties.consumedSpace).to.be.equal(0);509510 const tokenData = (await api.rpc.unique.tokenData(collection, token, ['anything'])).toJSON().properties;511 expect(tokenData).to.be.empty;512 });513 });514515 it('Assigns properties to a token according to permissions', async () => {516 await usingApi(async api => {517 const propertyKeys: string[] = [];518 let i = 0;519 for (const permission of permissions) {520 for (const signer of permission.signers) {521 const key = i + '_' + signer.address;522 propertyKeys.push(key);523524 await expect(executeTransaction(525 api, 526 alice, 527 api.tx.unique.setPropertyPermissions(collection, [{key: key, permission: permission.permission}]), 528 ), `on setting permission ${i} by ${signer.address}`).to.not.be.rejected;529530 await expect(executeTransaction(531 api, 532 signer, 533 api.tx.unique.setTokenProperties(collection, token, [{key: key, value: 'Serotonin increase'}]), 534 ), `on adding property ${i} by ${signer.address}`).to.not.be.rejected;535 }536537 i++;538 }539540 const properties = (await api.rpc.unique.tokenProperties(collection, token, propertyKeys)).toHuman() as any[];541 const tokensData = (await api.rpc.unique.tokenData(collection, token, propertyKeys)).toHuman().properties as any[];542 for (let i = 0; i < properties.length; i++) {543 expect(properties[i].value).to.be.equal('Serotonin increase');544 expect(tokensData[i].value).to.be.equal('Serotonin increase');545 }546 });547 });548549 it('Changes properties of a token according to permissions', async () => {550 await usingApi(async api => {551 const propertyKeys: string[] = [];552 let i = 0;553 for (const permission of permissions) {554 if (!permission.permission.mutable) continue;555 556 for (const signer of permission.signers) {557 const key = i + '_' + signer.address;558 propertyKeys.push(key);559560 await expect(executeTransaction(561 api, 562 alice, 563 api.tx.unique.setPropertyPermissions(collection, [{key: key, permission: permission.permission}]), 564 ), `on setting permission ${i} by ${signer.address}`).to.not.be.rejected;565566 await expect(executeTransaction(567 api, 568 signer, 569 api.tx.unique.setTokenProperties(collection, token, [{key: key, value: 'Serotonin increase'}]), 570 ), `on adding property ${i} by ${signer.address}`).to.not.be.rejected;571572 await expect(executeTransaction(573 api, 574 signer, 575 api.tx.unique.setTokenProperties(collection, token, [{key: key, value: 'Serotonin stable'}]), 576 ), `on changing property ${i} by ${signer.address}`).to.not.be.rejected;577 }578579 i++;580 }581582 const properties = (await api.rpc.unique.tokenProperties(collection, token, propertyKeys)).toHuman() as any[];583 const tokensData = (await api.rpc.unique.tokenData(collection, token, propertyKeys)).toHuman().properties as any[];584 for (let i = 0; i < properties.length; i++) {585 expect(properties[i].value).to.be.equal('Serotonin stable');586 expect(tokensData[i].value).to.be.equal('Serotonin stable');587 }588 });589 });590591 it('Deletes properties of a token according to permissions', async () => {592 await usingApi(async api => {593 const propertyKeys: string[] = [];594 let i = 0;595596 for (const permission of permissions) {597 if (!permission.permission.mutable) continue;598 599 for (const signer of permission.signers) {600 const key = i + '_' + signer.address;601 propertyKeys.push(key);602603 await expect(executeTransaction(604 api, 605 alice, 606 api.tx.unique.setPropertyPermissions(collection, [{key: key, permission: permission.permission}]), 607 ), `on setting permission ${i} by ${signer.address}`).to.not.be.rejected;608609 await expect(executeTransaction(610 api, 611 signer, 612 api.tx.unique.setTokenProperties(collection, token, [{key: key, value: 'Serotonin increase'}]), 613 ), `on adding property ${i} by ${signer.address}`).to.not.be.rejected;614615 await expect(executeTransaction(616 api, 617 signer, 618 api.tx.unique.deleteTokenProperties(collection, token, [key]), 619 ), `on deleting property ${i} by ${signer.address}`).to.not.be.rejected;620 }621 622 i++;623 }624625 const properties = (await api.rpc.unique.tokenProperties(collection, token, propertyKeys)).toJSON() as any[];626 expect(properties).to.be.empty;627 const tokensData = (await api.rpc.unique.tokenData(collection, token, propertyKeys)).toJSON().properties as any[];628 expect(tokensData).to.be.empty;629 expect((await api.query.nonfungible.tokenProperties(collection, token)).toJSON().consumedSpace).to.be.equal(0);630 });631 });632});633634describe('Negative Integration Test: Token Properties', () => {635 let collection: number;636 let token: number;637 let originalSpace: number;638 let constitution: {permission: any, signers: IKeyringPair[], sinner: IKeyringPair}[];639640 before(async () => {641 await usingApi(async (api, privateKeyWrapper) => {642 alice = privateKeyWrapper!('//Alice');643 bob = privateKeyWrapper!('//Bob');644 charlie = privateKeyWrapper!('//Charlie');645 const dave = privateKeyWrapper!('//Dave');646647 constitution = [648 {permission: {mutable: true, collectionAdmin: true}, signers: [alice, bob], sinner: charlie},649 {permission: {mutable: false, collectionAdmin: true}, signers: [alice, bob], sinner: charlie},650 {permission: {mutable: true, tokenOwner: true}, signers: [charlie], sinner: alice},651 {permission: {mutable: false, tokenOwner: true}, signers: [charlie], sinner: alice},652 {permission: {mutable: true, collectionAdmin: true, tokenOwner: true}, signers: [alice, bob, charlie], sinner: dave},653 {permission: {mutable: false, collectionAdmin: true, tokenOwner: true}, signers: [alice, bob, charlie], sinner: dave},654 ];655 });656 });657658 beforeEach(async () => {659 collection = await createCollectionExpectSuccess();660 token = await createItemExpectSuccess(alice, collection, 'NFT');661 await addCollectionAdminExpectSuccess(alice, collection, bob.address);662 await transferExpectSuccess(collection, token, alice, charlie);663 664 await usingApi(async api => {665 let i = 0;666 for (const passage of constitution) {667 const signer = passage.signers[0];668 669 await expect(executeTransaction(670 api, 671 alice, 672 api.tx.unique.setPropertyPermissions(collection, [{key: `${i}`, permission: passage.permission}]), 673 ), `on setting permission ${i} by ${signer.address}`).to.not.be.rejected;674675 await expect(executeTransaction(676 api, 677 signer, 678 api.tx.unique.setTokenProperties(collection, token, [{key: `${i}`, value: 'Serotonin increase'}]), 679 ), `on adding property ${i} by ${signer.address}`).to.not.be.rejected;680681 i++;682 }683684 originalSpace = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON().consumedSpace as number;685 });686 });687688 it('Forbids changing/deleting properties of a token if the user is outside of permissions', async () => {689 await usingApi(async api => {690 let i = -1;691 for (const forbiddance of constitution) {692 i++;693 if (!forbiddance.permission.mutable) continue;694695 await expect(executeTransaction(696 api, 697 forbiddance.sinner, 698 api.tx.unique.setTokenProperties(collection, token, [{key: `${i}`, value: 'Serotonin down'}]), 699 ), `on failing to change property ${i} by ${forbiddance.sinner.address}`).to.be.rejectedWith(/common\.NoPermission/);700701 await expect(executeTransaction(702 api, 703 forbiddance.sinner, 704 api.tx.unique.deleteTokenProperties(collection, token, [`${i}`]), 705 ), `on failing to delete property ${i} by ${forbiddance.sinner.address}`).to.be.rejectedWith(/common\.NoPermission/);706 }707708 const properties = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();709 expect(properties.consumedSpace).to.be.equal(originalSpace);710 });711 });712713 it('Forbids changing/deleting properties of a token if the property is permanent (immutable)', async () => {714 await usingApi(async api => {715 let i = -1;716 for (const permission of constitution) {717 i++;718 if (permission.permission.mutable) continue;719720 await expect(executeTransaction(721 api, 722 permission.signers[0], 723 api.tx.unique.setTokenProperties(collection, token, [{key: `${i}`, value: 'Serotonin down'}]), 724 ), `on failing to change property ${i} by ${permission.signers[0].address}`).to.be.rejectedWith(/common\.NoPermission/);725726 await expect(executeTransaction(727 api, 728 permission.signers[0], 729 api.tx.unique.deleteTokenProperties(collection, token, [i.toString()]), 730 ), `on failing to delete property ${i} by ${permission.signers[0].address}`).to.be.rejectedWith(/common\.NoPermission/);731 }732733 const properties = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();734 expect(properties.consumedSpace).to.be.equal(originalSpace);735 });736 });737738 it('Forbids adding properties to a token if the property is not declared / forbidden with the \'None\' permission', async () => {739 await usingApi(async api => {740 await expect(executeTransaction(741 api, 742 alice, 743 api.tx.unique.setTokenProperties(collection, token, [{key: 'non-existent', value: 'I exist!'}]), 744 ), 'on failing to add a previously non-existent property').to.be.rejectedWith(/common\.NoPermission/);745 746 await expect(executeTransaction(747 api, 748 alice, 749 api.tx.unique.setPropertyPermissions(collection, [{key: 'now-existent', permission: {}}]), 750 ), 'on setting a new non-permitted property').to.not.be.rejected;751752 await expect(executeTransaction(753 api, 754 alice, 755 api.tx.unique.setTokenProperties(collection, token, [{key: 'now-existent', value: 'I exist!'}]), 756 ), 'on failing to add a property forbidden by the \'None\' permission').to.be.rejectedWith(/common\.NoPermission/);757758 expect((await api.rpc.unique.tokenProperties(collection, token, ['non-existent', 'now-existent'])).toJSON()).to.be.empty;759 const properties = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();760 expect(properties.consumedSpace).to.be.equal(originalSpace);761 });762 });763764 it('Forbids adding too many properties to a token', async () => {765 await usingApi(async api => {766 await expect(executeTransaction(767 api, 768 alice, 769 api.tx.unique.setPropertyPermissions(collection, [770 {key: 'a_holy_book', permission: {collectionAdmin: true, tokenOwner: true}}, 771 {key: 'young_years', permission: {collectionAdmin: true, tokenOwner: true}},772 ]), 773 ), 'on setting a new non-permitted property').to.not.be.rejected;774775 // Mute the general tx parsing error776 {777 console.error = () => {};778 await expect(executeTransaction(779 api, 780 alice, 781 api.tx.unique.setCollectionProperties(collection, [{key: 'a_holy_book', value: 'word '.repeat(6554)}]), 782 )).to.be.rejected;783 }784785 await expect(executeTransaction(786 api, 787 alice, 788 api.tx.unique.setTokenProperties(collection, token, [789 {key: 'a_holy_book', value: 'word '.repeat(3277)}, 790 {key: 'young_years', value: 'neverending'.repeat(1490)},791 ]), 792 )).to.be.rejectedWith(/common\.NoSpaceForProperty/);793794 expect((await api.rpc.unique.tokenProperties(collection, token, ['a_holy_book', 'young_years'])).toJSON()).to.be.empty;795 const propertiesMap = (await api.query.nonfungible.tokenProperties(collection, token)).toJSON();796 expect(propertiesMap.consumedSpace).to.be.equal(originalSpace);797 });798 });799});tests/src/nesting/rules-smoke.test.tsdiffbeforeafterboth--- a/tests/src/nesting/rules-smoke.test.ts
+++ b/tests/src/nesting/rules-smoke.test.ts
@@ -1,6 +1,5 @@
import {expect} from 'chai';
import {tokenIdToAddress} from '../eth/util/helpers';
-import privateKey from '../substrate/privateKey';
import usingApi, {executeTransaction} from '../substrate/substrate-api';
import {createCollectionExpectSuccess, createFungibleItemExpectSuccess, createItemExpectSuccess, CrossAccountId, getCreateCollectionResult} from '../util/helpers';
import {IKeyringPair} from '@polkadot/types/types';
@@ -9,9 +8,9 @@
let alice!: IKeyringPair;
let nestTarget!: CrossAccountId;
before(async() => {
- await usingApi(async api => {
- alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
const events = await executeTransaction(api, alice, api.tx.unique.createCollectionEx({
mode: 'NFT',
permissions: {
tests/src/nesting/unnest.test.tsdiffbeforeafterboth--- a/tests/src/nesting/unnest.test.ts
+++ b/tests/src/nesting/unnest.test.ts
@@ -1,6 +1,5 @@
import {expect} from 'chai';
import {tokenIdToAddress} from '../eth/util/helpers';
-import privateKey from '../substrate/privateKey';
import usingApi, {executeTransaction} from '../substrate/substrate-api';
import {
createCollectionExpectSuccess,
@@ -19,9 +18,9 @@
describe('Integration Test: Unnesting', () => {
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
});
});
@@ -110,9 +109,9 @@
describe('Negative Test: Unnesting', () => {
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
});
});
tests/src/nextSponsoring.test.tsdiffbeforeafterboth--- a/tests/src/nextSponsoring.test.ts
+++ b/tests/src/nextSponsoring.test.ts
@@ -18,7 +18,6 @@
import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import privateKey from './substrate/privateKey';
import {default as usingApi} from './substrate/substrate-api';
import {
createCollectionExpectSuccess,
@@ -40,9 +39,9 @@
let bob: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
});
});
tests/src/overflow.test.tsdiffbeforeafterboth--- a/tests/src/overflow.test.ts
+++ b/tests/src/overflow.test.ts
@@ -17,7 +17,6 @@
import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import privateKey from './substrate/privateKey';
import usingApi from './substrate/substrate-api';
import {approveExpectSuccess, createCollectionExpectSuccess, createFungibleItemExpectSuccess, getAllowance, getBalance, transferExpectFailure, transferExpectSuccess, transferFromExpectFail, transferFromExpectSuccess, U128_MAX} from './util/helpers';
@@ -30,10 +29,10 @@
let charlie: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
+ charlie = privateKeyWrapper!('//Charlie');
});
});
tests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth--- a/tests/src/removeCollectionAdmin.test.ts
+++ b/tests/src/removeCollectionAdmin.test.ts
@@ -14,10 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-import {ApiPromise} from '@polkadot/api';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import privateKey from './substrate/privateKey';
import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
import {createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId, queryCollectionExpectSuccess} from './util/helpers';
@@ -26,10 +24,10 @@
describe('Integration Test removeCollectionAdmin(collection_id, account_id):', () => {
it('Remove collection admin.', async () => {
- await usingApi(async (api: ApiPromise) => {
+ await usingApi(async (api, privateKeyWrapper) => {
const collectionId = await createCollectionExpectSuccess();
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
const collection = await queryCollectionExpectSuccess(api, collectionId);
expect(collection.owner.toString()).to.be.deep.eq(alice.address);
// first - add collection admin Bob
@@ -49,11 +47,11 @@
});
it('Remove collection admin by admin.', async () => {
- await usingApi(async (api: ApiPromise) => {
+ await usingApi(async (api, privateKeyWrapper) => {
const collectionId = await createCollectionExpectSuccess();
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
- const charlie = privateKey('//Charlie');
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
+ const charlie = privateKeyWrapper!('//Charlie');
const collection = await queryCollectionExpectSuccess(api, collectionId);
expect(collection.owner.toString()).to.be.eq(alice.address);
// first - add collection admin Bob
@@ -76,8 +74,8 @@
});
it('Remove admin from collection that has no admins', async () => {
- await usingApi(async (api: ApiPromise) => {
- const alice = privateKey('//Alice');
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
const collectionId = await createCollectionExpectSuccess();
const adminListBeforeAddAdmin = await getAdminList(api, collectionId);
@@ -91,11 +89,11 @@
describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {
it('Can\'t remove collection admin from not existing collection', async () => {
- await usingApi(async (api: ApiPromise) => {
+ await usingApi(async (api, privateKeyWrapper) => {
// tslint:disable-next-line: no-bitwise
const collectionId = (1 << 32) - 1;
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
const changeOwnerTx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));
await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;
@@ -106,11 +104,11 @@
});
it('Can\'t remove collection admin from deleted collection', async () => {
- await usingApi(async (api: ApiPromise) => {
+ await usingApi(async (api, privateKeyWrapper) => {
// tslint:disable-next-line: no-bitwise
const collectionId = await createCollectionExpectSuccess();
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
await destroyCollectionExpectSuccess(collectionId);
@@ -123,11 +121,11 @@
});
it('Regular user Can\'t remove collection admin', async () => {
- await usingApi(async (api: ApiPromise) => {
+ await usingApi(async (api, privateKeyWrapper) => {
const collectionId = await createCollectionExpectSuccess();
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
- const charlie = privateKey('//Charlie');
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
+ const charlie = privateKeyWrapper!('//Charlie');
const addAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));
await submitTransactionAsync(alice, addAdminTx);
tests/src/removeFromAllowList.test.tsdiffbeforeafterboth--- a/tests/src/removeFromAllowList.test.ts
+++ b/tests/src/removeFromAllowList.test.ts
@@ -31,7 +31,6 @@
addCollectionAdminExpectSuccess,
} from './util/helpers';
import {IKeyringPair} from '@polkadot/types/types';
-import privateKey from './substrate/privateKey';
chai.use(chaiAsPromised);
const expect = chai.expect;
@@ -41,9 +40,9 @@
let bob: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
});
});
@@ -75,9 +74,9 @@
let bob: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
});
});
@@ -107,10 +106,10 @@
let charlie: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
+ charlie = privateKeyWrapper!('//Charlie');
});
});
tests/src/removeFromContractAllowList.test.tsdiffbeforeafterboth--- a/tests/src/removeFromContractAllowList.test.ts
+++ b/tests/src/removeFromContractAllowList.test.ts
@@ -14,7 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-import privateKey from './substrate/privateKey';
import usingApi from './substrate/substrate-api';
import {deployFlipper, toggleFlipValueExpectFailure, toggleFlipValueExpectSuccess} from './util/contracthelpers';
import {addToContractAllowListExpectSuccess, isAllowlistedInContract, removeFromContractAllowListExpectFailure, removeFromContractAllowListExpectSuccess, toggleContractAllowlistExpectSuccess} from './util/helpers';
@@ -25,8 +24,8 @@
let bob: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ bob = privateKeyWrapper!('//Bob');
});
});
@@ -70,9 +69,9 @@
let bob: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
});
});
tests/src/rpc.load.tsdiffbeforeafterboth--- a/tests/src/rpc.load.ts
+++ b/tests/src/rpc.load.ts
@@ -20,7 +20,6 @@
import {ApiPromise, Keyring} from '@polkadot/api';
import {findUnusedAddress} from './util/helpers';
import fs from 'fs';
-import privateKey from './substrate/privateKey';
const value = 0;
const gasLimit = 500000n * 1000000n;
@@ -121,13 +120,13 @@
});
it('Smart Contract RPC Load Test', async () => {
- await usingApi(async api => {
+ await usingApi(async (api, privateKeyWrapper) => {
// Deploy smart contract
const [contract, deployer] = await deployLoadTester(api);
// Fill smart contract up with data
- const bob = privateKey('//Bob');
+ const bob = privateKeyWrapper!('//Bob');
const tx = contract.tx.bloat(value, gasLimit, 200);
await submitTransactionAsync(bob, tx);
tests/src/scheduler.test.tsdiffbeforeafterboth--- a/tests/src/scheduler.test.ts
+++ b/tests/src/scheduler.test.ts
@@ -16,7 +16,6 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import privateKey from './substrate/privateKey';
import usingApi from './substrate/substrate-api';
import {
createItemExpectSuccess,
@@ -30,9 +29,9 @@
describe.skip('Integration Test scheduler base transaction', () => {
it('User can transfer owned token with delay (scheduler)', async () => {
- await usingApi(async () => {
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ 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');
tests/src/setChainLimits.test.tsdiffbeforeafterboth--- a/tests/src/setChainLimits.test.ts
+++ b/tests/src/setChainLimits.test.ts
@@ -15,7 +15,6 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {IKeyringPair} from '@polkadot/types/types';
-import privateKey from './substrate/privateKey';
import usingApi from './substrate/substrate-api';
import {
createCollectionExpectSuccess,
@@ -31,10 +30,10 @@
let limits: IChainLimits;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- dave = privateKey('//Dave');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
+ dave = privateKeyWrapper!('//Dave');
limits = {
collectionNumbersLimit : 1,
accountTokenOwnershipLimit: 1,
tests/src/setContractSponsoringRateLimit.test.tsdiffbeforeafterboth--- a/tests/src/setContractSponsoringRateLimit.test.ts
+++ b/tests/src/setContractSponsoringRateLimit.test.ts
@@ -15,7 +15,6 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {IKeyringPair} from '@polkadot/types/types';
-import privateKey from './substrate/privateKey';
import usingApi from './substrate/substrate-api';
import waitNewBlocks from './substrate/wait-new-blocks';
import {deployFlipper, toggleFlipValueExpectFailure, toggleFlipValueExpectSuccess} from './util/contracthelpers';
@@ -57,7 +56,9 @@
let alice: IKeyringPair;
before(async () => {
- alice = privateKey('//Alice');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ });
});
it('fails when called for non-contract address', async () => {
tests/src/setMintPermission.test.tsdiffbeforeafterboth--- a/tests/src/setMintPermission.test.ts
+++ b/tests/src/setMintPermission.test.ts
@@ -15,7 +15,6 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {IKeyringPair} from '@polkadot/types/types';
-import privateKey from './substrate/privateKey';
import usingApi from './substrate/substrate-api';
import {
addToAllowListExpectSuccess,
@@ -35,9 +34,9 @@
let bob: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
});
});
@@ -75,9 +74,9 @@
let bob: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
});
});
tests/src/setPublicAccessMode.test.tsdiffbeforeafterboth--- a/tests/src/setPublicAccessMode.test.ts
+++ b/tests/src/setPublicAccessMode.test.ts
@@ -19,7 +19,6 @@
import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import privateKey from './substrate/privateKey';
import usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';
import {
addToAllowListExpectSuccess,
@@ -41,9 +40,9 @@
describe('Integration Test setPublicAccessMode(): ', () => {
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
});
});
@@ -108,9 +107,9 @@
describe('Negative Integration Test ext. collection admin setPublicAccessMode(): ', () => {
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
});
});
it('setPublicAccessMode by collection admin', async () => {
tests/src/toggleContractAllowList.test.tsdiffbeforeafterboth--- a/tests/src/toggleContractAllowList.test.ts
+++ b/tests/src/toggleContractAllowList.test.ts
@@ -17,7 +17,6 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
-import privateKey from './substrate/privateKey';
import {
deployFlipper,
getFlipValue,
@@ -50,8 +49,8 @@
});
it('Only allowlisted account can call contract', async () => {
- await usingApi(async api => {
- const bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ const bob = privateKeyWrapper!('//Bob');
const [contract, deployer] = await deployFlipper(api);
@@ -135,9 +134,9 @@
describe.skip('Negative Integration Test toggleContractAllowList', () => {
it('Enable allow list for a non-contract', async () => {
- await usingApi(async api => {
- const alice = privateKey('//Alice');
- const bobGuineaPig = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
+ const bobGuineaPig = privateKeyWrapper!('//Bob');
const enabledBefore = (await api.query.unique.contractAllowListEnabled(bobGuineaPig.address)).toJSON();
const enableAllowListTx = api.tx.unique.toggleContractAllowList(bobGuineaPig.address, true);
@@ -150,8 +149,8 @@
});
it('Enable allow list using a non-owner address', async () => {
- await usingApi(async api => {
- const bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ const bob = privateKeyWrapper!('//Bob');
const [contract] = await deployFlipper(api);
const enabledBefore = (await api.query.unique.contractAllowListEnabled(contract.address)).toJSON();
tests/src/transfer.nload.tsdiffbeforeafterboth--- a/tests/src/transfer.nload.ts
+++ b/tests/src/transfer.nload.ts
@@ -16,7 +16,6 @@
import {ApiPromise} from '@polkadot/api';
import {IKeyringPair} from '@polkadot/types/types';
-import privateKey from './substrate/privateKey';
import usingApi, {submitTransactionAsync} from './substrate/substrate-api';
import waitNewBlocks from './substrate/wait-new-blocks';
import {findUnusedAddresses} from './util/helpers';
@@ -95,11 +94,11 @@
});
const waiting: Promise<void>[] = [];
console.log(`Starting ${os.cpus().length} workers`);
- usingApi(async (api) => {
- const alice = privateKey('//Alice');
+ usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
for (const id in os.cpus()) {
const WORKER_NAME = `//LoadWorker${id}_${Date.now()}`;
- const workerAccount = privateKey(WORKER_NAME);
+ const workerAccount = privateKeyWrapper!(WORKER_NAME);
const tx = api.tx.balances.transfer(workerAccount.address, 400n * 10n ** 23n);
await submitTransactionAsync(alice, tx);
@@ -119,8 +118,8 @@
});
} else {
increaseCounter('startedWorkers', 1);
- usingApi(async (api) => {
- await distributeBalance(privateKey(process.env.WORKER_NAME as string), api, 400n * 10n ** 22n, 10);
+ usingApi(async (api, privateKeyWrapper) => {
+ await distributeBalance(privateKeyWrapper!(process.env.WORKER_NAME as string), api, 400n * 10n ** 22n, 10);
});
const interval = setInterval(() => {
flushCounterToMaster();
tests/src/transfer.test.tsdiffbeforeafterboth--- a/tests/src/transfer.test.ts
+++ b/tests/src/transfer.test.ts
@@ -19,7 +19,6 @@
import {expect} from 'chai';
import {alicesPublicKey, bobsPublicKey} from './accounts';
import getBalance from './substrate/get-balance';
-import privateKey from './substrate/privateKey';
import {default as usingApi, submitTransactionAsync} from './substrate/substrate-api';
import {
burnItemExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess,
@@ -49,10 +48,10 @@
describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {
it('Balance transfers and check balance', async () => {
- await usingApi(async (api: ApiPromise) => {
+ await usingApi(async (api, privateKeyWrapper) => {
const [alicesBalanceBefore, bobsBalanceBefore] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);
- const alicePrivateKey = privateKey('//Alice');
+ const alicePrivateKey = privateKeyWrapper!('//Alice');
const transfer = api.tx.balances.transfer(bobsPublicKey, 1n);
const events = await submitTransactionAsync(alicePrivateKey, transfer);
@@ -87,9 +86,9 @@
});
it('User can transfer owned token', async () => {
- await usingApi(async () => {
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ 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,9 +113,9 @@
});
it('Collection admin can transfer owned token', async () => {
- await usingApi(async () => {
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
// nft
const nftCollectionId = await createCollectionExpectSuccess();
await addCollectionAdminExpectSuccess(alice, nftCollectionId, bob.address);
@@ -145,10 +144,10 @@
describe('Negative Integration Test Transfer(recipient, collection_id, item_id, value)', () => {
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
+ charlie = privateKeyWrapper!('//Charlie');
});
});
it('Transfer with not existed collection_id', async () => {
@@ -258,9 +257,9 @@
describe('Zero value transfer(From)', () => {
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
});
});
@@ -315,9 +314,9 @@
});
describe('Transfers to self (potentially over substrate-evm boundary)', () => {
- itWeb3('Transfers to self. In case of same frontend', async ({api}) => {
+ itWeb3('Transfers to self. In case of same frontend', async ({api, privateKeyWrapper}) => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const alice = privateKey('//Alice');
+ 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');
@@ -327,9 +326,9 @@
expect(balanceAliceBefore).to.be.eq(balanceAliceAfter);
});
- itWeb3('Transfers to self. In case of substrate-evm boundary', async ({api}) => {
+ itWeb3('Transfers to self. In case of substrate-evm boundary', async ({api, privateKeyWrapper}) => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const alice = privateKey('//Alice');
+ 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);
@@ -339,9 +338,9 @@
expect(balanceAliceBefore).to.be.eq(balanceAliceAfter);
});
- itWeb3('Transfers to self. In case of inside substrate-evm', async ({api}) => {
+ itWeb3('Transfers to self. In case of inside substrate-evm', async ({api, privateKeyWrapper}) => {
const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const alice = privateKey('//Alice');
+ 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');
@@ -350,9 +349,9 @@
expect(balanceAliceBefore).to.be.eq(balanceAliceAfter);
});
- itWeb3('Transfers to self. In case of inside substrate-evm when not enought "Fungibles"', async ({api}) => {
+ 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 = privateKey('//Alice');
+ 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/transferFrom.test.tsdiffbeforeafterboth--- a/tests/src/transferFrom.test.ts
+++ b/tests/src/transferFrom.test.ts
@@ -18,7 +18,6 @@
import {IKeyringPair} from '@polkadot/types/types';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-import privateKey from './substrate/privateKey';
import {default as usingApi} from './substrate/substrate-api';
import {
approveExpectFail,
@@ -43,10 +42,10 @@
let charlie: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
+ charlie = privateKeyWrapper!('//Charlie');
});
});
@@ -83,10 +82,10 @@
});
it('Should reduce allowance if value is big', async () => {
- await usingApi(async (api) => {
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
- const charlie = privateKey('//Charlie');
+ await usingApi(async (api, privateKeyWrapper) => {
+ const alice = privateKeyWrapper!('//Alice');
+ const bob = privateKeyWrapper!('//Bob');
+ const charlie = privateKeyWrapper!('//Charlie');
// fungible
const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
@@ -112,10 +111,10 @@
let charlie: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
+ charlie = privateKeyWrapper!('//Charlie');
});
});
@@ -216,8 +215,8 @@
});
it('execute transferFrom from account that is not owner of collection', async () => {
- await usingApi(async () => {
- const dave = privateKey('//Dave');
+ await usingApi(async (api, privateKeyWrapper) => {
+ const dave = privateKeyWrapper!('//Dave');
// nft
const nftCollectionId = await createCollectionExpectSuccess();
const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -24,7 +24,6 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import {alicesPublicKey} from '../accounts';
-import privateKey from '../substrate/privateKey';
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';
@@ -325,12 +324,12 @@
const {name, description, mode, tokenPrefix} = {...defaultCreateCollectionParams, ...params};
let collectionId = 0;
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
// Get number of collections before the transaction
const collectionCountBefore = await getCreatedCollectionCount(api);
// Run the CreateCollection transaction
- const alicePrivateKey = privateKey('//Alice');
+ const alicePrivateKey = privateKeyWrapper!('//Alice');
let modeprm = {};
if (mode.type === 'NFT') {
@@ -378,12 +377,12 @@
const {name, description, mode, tokenPrefix} = {...defaultCreateCollectionParams, ...params};
let collectionId = 0;
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
// Get number of collections before the transaction
const collectionCountBefore = await getCreatedCollectionCount(api);
// Run the CreateCollection transaction
- const alicePrivateKey = privateKey('//Alice');
+ const alicePrivateKey = privateKeyWrapper!('//Alice');
let modeprm = {};
if (mode.type === 'NFT') {
@@ -426,12 +425,12 @@
export async function createCollectionWithPropsExpectFailure(params: Partial<CreateCollectionParams> = {}) {
const {name, description, mode, tokenPrefix} = {...defaultCreateCollectionParams, ...params};
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
// Get number of collections before the transaction
const collectionCountBefore = await getCreatedCollectionCount(api);
// Run the CreateCollection transaction
- const alicePrivateKey = privateKey('//Alice');
+ const alicePrivateKey = privateKeyWrapper!('//Alice');
let modeprm = {};
if (mode.type === 'NFT') {
@@ -465,12 +464,12 @@
modeprm = {refungible: null};
}
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
// Get number of collections before the transaction
const collectionCountBefore = await getCreatedCollectionCount(api);
// Run the CreateCollection transaction
- const alicePrivateKey = privateKey('//Alice');
+ const alicePrivateKey = privateKeyWrapper!('//Alice');
const tx = api.tx.unique.createCollectionEx({name: strToUTF16(name), description: strToUTF16(description), tokenPrefix: strToUTF16(tokenPrefix), mode: modeprm as any});
await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;
@@ -519,18 +518,18 @@
}
export async function destroyCollectionExpectFailure(collectionId: number, senderSeed = '//Alice') {
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
// Run the DestroyCollection transaction
- const alicePrivateKey = privateKey(senderSeed);
+ const alicePrivateKey = privateKeyWrapper!(senderSeed);
const tx = api.tx.unique.destroyCollection(collectionId);
await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;
});
}
export async function destroyCollectionExpectSuccess(collectionId: number, senderSeed = '//Alice') {
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
// Run the DestroyCollection transaction
- const alicePrivateKey = privateKey(senderSeed);
+ const alicePrivateKey = privateKeyWrapper!(senderSeed);
const tx = api.tx.unique.destroyCollection(collectionId);
const events = await submitTransactionAsync(alicePrivateKey, tx);
const result = getDestroyResult(events);
@@ -572,10 +571,10 @@
}
export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string, sender = '//Alice') {
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
// Run the transaction
- const senderPrivateKey = privateKey(sender);
+ const senderPrivateKey = privateKeyWrapper!(sender);
const tx = api.tx.unique.setCollectionSponsor(collectionId, sponsor);
const events = await submitTransactionAsync(senderPrivateKey, tx);
const result = getGenericResult(events);
@@ -592,10 +591,10 @@
}
export async function removeCollectionSponsorExpectSuccess(collectionId: number, sender = '//Alice') {
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
// Run the transaction
- const alicePrivateKey = privateKey(sender);
+ const alicePrivateKey = privateKeyWrapper!(sender);
const tx = api.tx.unique.removeCollectionSponsor(collectionId);
const events = await submitTransactionAsync(alicePrivateKey, tx);
const result = getGenericResult(events);
@@ -610,30 +609,30 @@
}
export async function removeCollectionSponsorExpectFailure(collectionId: number, senderSeed = '//Alice') {
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
// Run the transaction
- const alicePrivateKey = privateKey(senderSeed);
+ const alicePrivateKey = privateKeyWrapper!(senderSeed);
const tx = api.tx.unique.removeCollectionSponsor(collectionId);
await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;
});
}
export async function setCollectionSponsorExpectFailure(collectionId: number, sponsor: string, senderSeed = '//Alice') {
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
// Run the transaction
- const alicePrivateKey = privateKey(senderSeed);
+ const alicePrivateKey = privateKeyWrapper!(senderSeed);
const tx = api.tx.unique.setCollectionSponsor(collectionId, sponsor);
await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;
});
}
export async function confirmSponsorshipExpectSuccess(collectionId: number, senderSeed = '//Alice') {
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
// Run the transaction
- const sender = privateKey(senderSeed);
+ const sender = privateKeyWrapper!(senderSeed);
const tx = api.tx.unique.confirmSponsorship(collectionId);
const events = await submitTransactionAsync(sender, tx);
const result = getGenericResult(events);
@@ -651,10 +650,10 @@
export async function confirmSponsorshipExpectFailure(collectionId: number, senderSeed = '//Alice') {
- await usingApi(async (api) => {
+ await usingApi(async (api, privateKeyWrapper) => {
// Run the transaction
- const sender = privateKey(senderSeed);
+ const sender = privateKeyWrapper!(senderSeed);
const tx = api.tx.unique.confirmSponsorship(collectionId);
await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
});
tests/src/xcmTransfer.test.tsdiffbeforeafterboth--- a/tests/src/xcmTransfer.test.ts
+++ b/tests/src/xcmTransfer.test.ts
@@ -20,7 +20,6 @@
import {WsProvider} from '@polkadot/api';
import {ApiOptions} from '@polkadot/api/types';
import {IKeyringPair} from '@polkadot/types/types';
-import privateKey from './substrate/privateKey';
import usingApi, {submitTransactionAsync} from './substrate/substrate-api';
import {getGenericResult} from './util/helpers';
import waitNewBlocks from './substrate/wait-new-blocks';
@@ -38,8 +37,8 @@
let alice: IKeyringPair;
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
});
const karuraApiOptions: ApiOptions = {