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.tsdiffbeforeafterboth--- a/tests/src/nesting/properties.test.ts
+++ b/tests/src/nesting/properties.test.ts
@@ -1,5 +1,4 @@
import {expect} from 'chai';
-import privateKey from '../substrate/privateKey';
import usingApi, {executeTransaction} from '../substrate/substrate-api';
import {
addCollectionAdminExpectSuccess,
@@ -16,9 +15,9 @@
describe('Composite Properties Test', () => {
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
});
});
@@ -63,9 +62,9 @@
describe('Integration Test: Collection Properties', () => {
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
});
});
@@ -158,9 +157,9 @@
describe('Negative Integration Test: Collection Properties', () => {
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
});
});
@@ -290,9 +289,9 @@
describe('Integration Test: Access Rights to Token Properties', () => {
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
});
});
@@ -356,9 +355,9 @@
describe('Negative Integration Test: Access Rights to Token Properties', () => {
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
});
});
@@ -474,10 +473,10 @@
let permissions: {permission: any, signers: 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');
permissions = [
{permission: {mutable: true, collectionAdmin: true}, signers: [alice, bob]},
@@ -639,11 +638,11 @@
let constitution: {permission: any, signers: IKeyringPair[], sinner: IKeyringPair}[];
before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
- const dave = privateKey('//Dave');
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper!('//Alice');
+ bob = privateKeyWrapper!('//Bob');
+ charlie = privateKeyWrapper!('//Charlie');
+ const dave = privateKeyWrapper!('//Dave');
constitution = [
{permission: {mutable: true, collectionAdmin: true}, signers: [alice, bob], sinner: charlie},
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.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import '../interfaces/augment-api-rpc';18import '../interfaces/augment-api-query';19import {ApiPromise, Keyring} from '@polkadot/api';20import type {AccountId, EventRecord, Event} from '@polkadot/types/interfaces';21import {AnyTuple, IEvent, IKeyringPair} from '@polkadot/types/types';22import {evmToAddress} from '@polkadot/util-crypto';23import BN from 'bn.js';24import chai from 'chai';25import chaiAsPromised from 'chai-as-promised';26import {alicesPublicKey} from '../accounts';27import privateKey from '../substrate/privateKey';28import {default as usingApi, executeTransaction, submitTransactionAsync, submitTransactionExpectFailAsync} from '../substrate/substrate-api';29import {hexToStr, strToUTF16, utf16ToStr} from './util';30import {UpDataStructsRpcCollection, UpDataStructsCreateItemData, UpDataStructsProperty} from '@polkadot/types/lookup';3132chai.use(chaiAsPromised);33const expect = chai.expect;3435export type CrossAccountId = {36 Substrate: string,37} | {38 Ethereum: string,39};4041export function normalizeAccountId(input: string | AccountId | CrossAccountId | IKeyringPair): CrossAccountId {42 if (typeof input === 'string') {43 if (input.length === 48 || input.length === 47) {44 return {Substrate: input};45 } else if (input.length === 42 && input.startsWith('0x')) {46 return {Ethereum: input.toLowerCase()};47 } else if (input.length === 40 && !input.startsWith('0x')) {48 return {Ethereum: '0x' + input.toLowerCase()};49 } else {50 throw new Error(`Unknown address format: "${input}"`);51 }52 }53 if ('address' in input) {54 return {Substrate: input.address};55 }56 if ('Ethereum' in input) {57 return {58 Ethereum: input.Ethereum.toLowerCase(),59 };60 } else if ('ethereum' in input) {61 return {62 Ethereum: (input as any).ethereum.toLowerCase(),63 };64 } else if ('Substrate' in input) {65 return input;66 } else if ('substrate' in input) {67 return {68 Substrate: (input as any).substrate,69 };70 }7172 // AccountId73 return {Substrate: input.toString()};74}75export function toSubstrateAddress(input: string | CrossAccountId | IKeyringPair): string {76 input = normalizeAccountId(input);77 if ('Substrate' in input) {78 return input.Substrate;79 } else {80 return evmToAddress(input.Ethereum);81 }82}8384export const U128_MAX = (1n << 128n) - 1n;8586const MICROUNIQUE = 1_000_000_000_000n;87const MILLIUNIQUE = 1_000n * MICROUNIQUE;88const CENTIUNIQUE = 10n * MILLIUNIQUE;89export const UNIQUE = 100n * CENTIUNIQUE;9091type GenericResult = {92 success: boolean,93};9495interface CreateCollectionResult {96 success: boolean;97 collectionId: number;98}99100interface CreateItemResult {101 success: boolean;102 collectionId: number;103 itemId: number;104 recipient?: CrossAccountId;105}106107interface TransferResult {108 collectionId: number;109 itemId: number;110 sender?: CrossAccountId;111 recipient?: CrossAccountId;112 value: bigint;113}114115interface IReFungibleOwner {116 fraction: BN;117 owner: number[];118}119120interface IGetMessage {121 checkMsgUnqMethod: string;122 checkMsgTrsMethod: string;123 checkMsgSysMethod: string;124}125126export interface IFungibleTokenDataType {127 value: number;128}129130export interface IChainLimits {131 collectionNumbersLimit: number;132 accountTokenOwnershipLimit: number;133 collectionsAdminsLimit: number;134 customDataLimit: number;135 nftSponsorTransferTimeout: number;136 fungibleSponsorTransferTimeout: number;137 refungibleSponsorTransferTimeout: number;138 //offchainSchemaLimit: number;139 //constOnChainSchemaLimit: number;140}141142export interface IReFungibleTokenDataType {143 owner: IReFungibleOwner[];144}145146export function uniqueEventMessage(events: EventRecord[]): IGetMessage {147 let checkMsgUnqMethod = '';148 let checkMsgTrsMethod = '';149 let checkMsgSysMethod = '';150 events.forEach(({event: {method, section}}) => {151 if (section === 'common') {152 checkMsgUnqMethod = method;153 } else if (section === 'treasury') {154 checkMsgTrsMethod = method;155 } else if (section === 'system') {156 checkMsgSysMethod = method;157 } else { return null; }158 });159 const result: IGetMessage = {160 checkMsgUnqMethod,161 checkMsgTrsMethod,162 checkMsgSysMethod,163 };164 return result;165}166167export function getEvent<T extends Event>(events: EventRecord[], check: (event: IEvent<AnyTuple>) => event is T): T | undefined {168 const event = events.find(r => check(r.event));169 if (!event) return;170 return event.event as T;171}172173export function getGenericResult(events: EventRecord[]): GenericResult {174 const result: GenericResult = {175 success: false,176 };177 events.forEach(({event: {method}}) => {178 // console.log(` ${phase}: ${section}.${method}:: ${data}`);179 if (method === 'ExtrinsicSuccess') {180 result.success = true;181 }182 });183 return result;184}185186187188export function getCreateCollectionResult(events: EventRecord[]): CreateCollectionResult {189 let success = false;190 let collectionId = 0;191 events.forEach(({event: {data, method, section}}) => {192 // console.log(` ${phase}: ${section}.${method}:: ${data}`);193 if (method == 'ExtrinsicSuccess') {194 success = true;195 } else if ((section == 'common') && (method == 'CollectionCreated')) {196 collectionId = parseInt(data[0].toString(), 10);197 }198 });199 const result: CreateCollectionResult = {200 success,201 collectionId,202 };203 return result;204}205206export function getCreateItemsResult(events: EventRecord[]): CreateItemResult[] {207 let success = false;208 let collectionId = 0;209 let itemId = 0;210 let recipient;211212 const results : CreateItemResult[] = [];213214 events.forEach(({event: {data, method, section}}) => {215 // console.log(` ${phase}: ${section}.${method}:: ${data}`);216 if (method == 'ExtrinsicSuccess') {217 success = true;218 } else if ((section == 'common') && (method == 'ItemCreated')) {219 collectionId = parseInt(data[0].toString(), 10);220 itemId = parseInt(data[1].toString(), 10);221 recipient = normalizeAccountId(data[2].toJSON() as any);222223 const itemRes: CreateItemResult = {224 success,225 collectionId,226 itemId,227 recipient,228 };229230 results.push(itemRes);231 }232 });233234 return results;235}236237export function getCreateItemResult(events: EventRecord[]): CreateItemResult {238 let success = false;239 let collectionId = 0;240 let itemId = 0;241 let recipient;242 events.forEach(({event: {data, method, section}}) => {243 // console.log(` ${phase}: ${section}.${method}:: ${data}`);244 if (method == 'ExtrinsicSuccess') {245 success = true;246 } else if ((section == 'common') && (method == 'ItemCreated')) {247 collectionId = parseInt(data[0].toString(), 10);248 itemId = parseInt(data[1].toString(), 10);249 recipient = normalizeAccountId(data[2].toJSON() as any);250 }251 });252 const result: CreateItemResult = {253 success,254 collectionId,255 itemId,256 recipient,257 };258 return result;259}260261export function getTransferResult(api: ApiPromise, events: EventRecord[]): TransferResult {262 for (const {event} of events) {263 if (api.events.common.Transfer.is(event)) {264 const [collection, token, sender, recipient, value] = event.data;265 return {266 collectionId: collection.toNumber(),267 itemId: token.toNumber(),268 sender: normalizeAccountId(sender.toJSON() as any),269 recipient: normalizeAccountId(recipient.toJSON() as any),270 value: value.toBigInt(),271 };272 }273 }274 throw new Error('no transfer event');275}276277interface Nft {278 type: 'NFT';279}280281interface Fungible {282 type: 'Fungible';283 decimalPoints: number;284}285286interface ReFungible {287 type: 'ReFungible';288}289290type CollectionMode = Nft | Fungible | ReFungible;291292export type Property = {293 key: any,294 value: any,295};296297type Permission = {298 mutable: boolean;299 collectionAdmin: boolean;300 tokenOwner: boolean;301}302303type PropertyPermission = {304 key: any;305 permission: Permission;306}307308export type CreateCollectionParams = {309 mode: CollectionMode,310 name: string,311 description: string,312 tokenPrefix: string,313 properties?: Array<Property>,314 propPerm?: Array<PropertyPermission>315};316317const defaultCreateCollectionParams: CreateCollectionParams = {318 description: 'description',319 mode: {type: 'NFT'},320 name: 'name',321 tokenPrefix: 'prefix',322};323324export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {325 const {name, description, mode, tokenPrefix} = {...defaultCreateCollectionParams, ...params};326327 let collectionId = 0;328 await usingApi(async (api) => {329 // Get number of collections before the transaction330 const collectionCountBefore = await getCreatedCollectionCount(api);331332 // Run the CreateCollection transaction333 const alicePrivateKey = privateKey('//Alice');334335 let modeprm = {};336 if (mode.type === 'NFT') {337 modeprm = {nft: null};338 } else if (mode.type === 'Fungible') {339 modeprm = {fungible: mode.decimalPoints};340 } else if (mode.type === 'ReFungible') {341 modeprm = {refungible: null};342 }343344 const tx = api.tx.unique.createCollectionEx({345 name: strToUTF16(name),346 description: strToUTF16(description),347 tokenPrefix: strToUTF16(tokenPrefix),348 mode: modeprm as any,349 });350 const events = await submitTransactionAsync(alicePrivateKey, tx);351 const result = getCreateCollectionResult(events);352353 // Get number of collections after the transaction354 const collectionCountAfter = await getCreatedCollectionCount(api);355356 // Get the collection357 const collection = await queryCollectionExpectSuccess(api, result.collectionId);358359 // What to expect360 // tslint:disable-next-line:no-unused-expression361 expect(result.success).to.be.true;362 expect(result.collectionId).to.be.equal(collectionCountAfter);363 // tslint:disable-next-line:no-unused-expression364 expect(collection).to.be.not.null;365 expect(collectionCountAfter).to.be.equal(collectionCountBefore + 1, 'Error: NFT collection NOT created.');366 expect(collection.owner.toString()).to.be.equal(toSubstrateAddress(alicesPublicKey));367 expect(utf16ToStr(collection.name.toJSON() as any)).to.be.equal(name);368 expect(utf16ToStr(collection.description.toJSON() as any)).to.be.equal(description);369 expect(hexToStr(collection.tokenPrefix.toJSON())).to.be.equal(tokenPrefix);370371 collectionId = result.collectionId;372 });373374 return collectionId;375}376377export async function createCollectionWithPropsExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {378 const {name, description, mode, tokenPrefix} = {...defaultCreateCollectionParams, ...params};379380 let collectionId = 0;381 await usingApi(async (api) => {382 // Get number of collections before the transaction383 const collectionCountBefore = await getCreatedCollectionCount(api);384385 // Run the CreateCollection transaction386 const alicePrivateKey = privateKey('//Alice');387388 let modeprm = {};389 if (mode.type === 'NFT') {390 modeprm = {nft: null};391 } else if (mode.type === 'Fungible') {392 modeprm = {fungible: mode.decimalPoints};393 } else if (mode.type === 'ReFungible') {394 modeprm = {refungible: null};395 }396397 const tx = api.tx.unique.createCollectionEx({name: strToUTF16(name), description: strToUTF16(description), tokenPrefix: strToUTF16(tokenPrefix), mode: modeprm as any, properties: params.properties, tokenPropertyPermissions: params.propPerm});398 const events = await submitTransactionAsync(alicePrivateKey, tx);399 const result = getCreateCollectionResult(events);400401 // Get number of collections after the transaction402 const collectionCountAfter = await getCreatedCollectionCount(api);403404 // Get the collection405 const collection = await queryCollectionExpectSuccess(api, result.collectionId);406407 // What to expect408 // tslint:disable-next-line:no-unused-expression409 expect(result.success).to.be.true;410 expect(result.collectionId).to.be.equal(collectionCountAfter);411 // tslint:disable-next-line:no-unused-expression412 expect(collection).to.be.not.null;413 expect(collectionCountAfter).to.be.equal(collectionCountBefore + 1, 'Error: NFT collection NOT created.');414 expect(collection.owner.toString()).to.be.equal(toSubstrateAddress(alicesPublicKey));415 expect(utf16ToStr(collection.name.toJSON() as any)).to.be.equal(name);416 expect(utf16ToStr(collection.description.toJSON() as any)).to.be.equal(description);417 expect(hexToStr(collection.tokenPrefix.toJSON())).to.be.equal(tokenPrefix);418419420 collectionId = result.collectionId;421 });422423 return collectionId;424}425426export async function createCollectionWithPropsExpectFailure(params: Partial<CreateCollectionParams> = {}) {427 const {name, description, mode, tokenPrefix} = {...defaultCreateCollectionParams, ...params};428429 await usingApi(async (api) => {430 // Get number of collections before the transaction431 const collectionCountBefore = await getCreatedCollectionCount(api);432433 // Run the CreateCollection transaction434 const alicePrivateKey = privateKey('//Alice');435436 let modeprm = {};437 if (mode.type === 'NFT') {438 modeprm = {nft: null};439 } else if (mode.type === 'Fungible') {440 modeprm = {fungible: mode.decimalPoints};441 } else if (mode.type === 'ReFungible') {442 modeprm = {refungible: null};443 }444445 const tx = api.tx.unique.createCollectionEx({name: strToUTF16(name), description: strToUTF16(description), tokenPrefix: strToUTF16(tokenPrefix), mode: modeprm as any, properties: params.properties, tokenPropertyPermissions: params.propPerm});446 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;447448449 // Get number of collections after the transaction450 const collectionCountAfter = await getCreatedCollectionCount(api);451452 expect(collectionCountAfter).to.be.equal(collectionCountBefore, 'Error: Collection with incorrect data created.');453 });454}455456export async function createCollectionExpectFailure(params: Partial<CreateCollectionParams> = {}) {457 const {name, description, mode, tokenPrefix} = {...defaultCreateCollectionParams, ...params};458459 let modeprm = {};460 if (mode.type === 'NFT') {461 modeprm = {nft: null};462 } else if (mode.type === 'Fungible') {463 modeprm = {fungible: mode.decimalPoints};464 } else if (mode.type === 'ReFungible') {465 modeprm = {refungible: null};466 }467468 await usingApi(async (api) => {469 // Get number of collections before the transaction470 const collectionCountBefore = await getCreatedCollectionCount(api);471472 // Run the CreateCollection transaction473 const alicePrivateKey = privateKey('//Alice');474 const tx = api.tx.unique.createCollectionEx({name: strToUTF16(name), description: strToUTF16(description), tokenPrefix: strToUTF16(tokenPrefix), mode: modeprm as any});475 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;476477 // Get number of collections after the transaction478 const collectionCountAfter = await getCreatedCollectionCount(api);479480 // What to expect481 expect(collectionCountAfter).to.be.equal(collectionCountBefore, 'Error: Collection with incorrect data created.');482 });483}484485export async function findUnusedAddress(api: ApiPromise, seedAddition = ''): Promise<IKeyringPair> {486 let bal = 0n;487 let unused;488 do {489 const randomSeed = 'seed' + Math.floor(Math.random() * Math.floor(10000)) + seedAddition;490 const keyring = new Keyring({type: 'sr25519'});491 unused = keyring.addFromUri(`//${randomSeed}`);492 bal = (await api.query.system.account(unused.address)).data.free.toBigInt();493 } while (bal !== 0n);494 return unused;495}496497export async function getAllowance(api: ApiPromise, collectionId: number, owner: CrossAccountId | string, approved: CrossAccountId | string, tokenId: number) {498 return (await api.rpc.unique.allowance(collectionId, normalizeAccountId(owner), normalizeAccountId(approved), tokenId)).toBigInt();499}500501export function findUnusedAddresses(api: ApiPromise, amount: number): Promise<IKeyringPair[]> {502 return Promise.all(new Array(amount).fill(null).map(() => findUnusedAddress(api, '_' + Date.now())));503}504505export async function findNotExistingCollection(api: ApiPromise): Promise<number> {506 const totalNumber = await getCreatedCollectionCount(api);507 const newCollection: number = totalNumber + 1;508 return newCollection;509}510511function getDestroyResult(events: EventRecord[]): boolean {512 let success = false;513 events.forEach(({event: {method}}) => {514 if (method == 'ExtrinsicSuccess') {515 success = true;516 }517 });518 return success;519}520521export async function destroyCollectionExpectFailure(collectionId: number, senderSeed = '//Alice') {522 await usingApi(async (api) => {523 // Run the DestroyCollection transaction524 const alicePrivateKey = privateKey(senderSeed);525 const tx = api.tx.unique.destroyCollection(collectionId);526 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;527 });528}529530export async function destroyCollectionExpectSuccess(collectionId: number, senderSeed = '//Alice') {531 await usingApi(async (api) => {532 // Run the DestroyCollection transaction533 const alicePrivateKey = privateKey(senderSeed);534 const tx = api.tx.unique.destroyCollection(collectionId);535 const events = await submitTransactionAsync(alicePrivateKey, tx);536 const result = getDestroyResult(events);537 expect(result).to.be.true;538539 // What to expect540 expect(await getDetailedCollectionInfo(api, collectionId)).to.be.null;541 });542}543544export async function setCollectionLimitsExpectSuccess(sender: IKeyringPair, collectionId: number, limits: any) {545 await usingApi(async (api) => {546 const tx = api.tx.unique.setCollectionLimits(collectionId, limits);547 const events = await submitTransactionAsync(sender, tx);548 const result = getGenericResult(events);549550 expect(result.success).to.be.true;551 });552}553554export const setCollectionPermissionsExpectSuccess = async (sender: IKeyringPair, collectionId: number, permissions: {mintMode?: boolean, access?: 'Normal' | 'AllowList', nesting?: 'Disabled' | 'Owner' | {OwnerRestricted: number[]}}) => {555 await usingApi(async(api) => {556 const tx = api.tx.unique.setCollectionPermissions(collectionId, permissions);557 const events = await submitTransactionAsync(sender, tx);558 const result = getGenericResult(events);559560 expect(result.success).to.be.true;561 });562};563564export async function setCollectionLimitsExpectFailure(sender: IKeyringPair, collectionId: number, limits: any) {565 await usingApi(async (api) => {566 const tx = api.tx.unique.setCollectionLimits(collectionId, limits);567 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;568 const result = getGenericResult(events);569570 expect(result.success).to.be.false;571 });572}573574export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string, sender = '//Alice') {575 await usingApi(async (api) => {576577 // Run the transaction578 const senderPrivateKey = privateKey(sender);579 const tx = api.tx.unique.setCollectionSponsor(collectionId, sponsor);580 const events = await submitTransactionAsync(senderPrivateKey, tx);581 const result = getGenericResult(events);582583 // Get the collection584 const collection = await queryCollectionExpectSuccess(api, collectionId);585586 // What to expect587 expect(result.success).to.be.true;588 expect(collection.sponsorship.toJSON()).to.deep.equal({589 unconfirmed: sponsor,590 });591 });592}593594export async function removeCollectionSponsorExpectSuccess(collectionId: number, sender = '//Alice') {595 await usingApi(async (api) => {596597 // Run the transaction598 const alicePrivateKey = privateKey(sender);599 const tx = api.tx.unique.removeCollectionSponsor(collectionId);600 const events = await submitTransactionAsync(alicePrivateKey, tx);601 const result = getGenericResult(events);602603 // Get the collection604 const collection = await queryCollectionExpectSuccess(api, collectionId);605606 // What to expect607 expect(result.success).to.be.true;608 expect(collection.sponsorship.toJSON()).to.be.deep.equal({disabled: null});609 });610}611612export async function removeCollectionSponsorExpectFailure(collectionId: number, senderSeed = '//Alice') {613 await usingApi(async (api) => {614615 // Run the transaction616 const alicePrivateKey = privateKey(senderSeed);617 const tx = api.tx.unique.removeCollectionSponsor(collectionId);618 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;619 });620}621622export async function setCollectionSponsorExpectFailure(collectionId: number, sponsor: string, senderSeed = '//Alice') {623 await usingApi(async (api) => {624625 // Run the transaction626 const alicePrivateKey = privateKey(senderSeed);627 const tx = api.tx.unique.setCollectionSponsor(collectionId, sponsor);628 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;629 });630}631632export async function confirmSponsorshipExpectSuccess(collectionId: number, senderSeed = '//Alice') {633 await usingApi(async (api) => {634635 // Run the transaction636 const sender = privateKey(senderSeed);637 const tx = api.tx.unique.confirmSponsorship(collectionId);638 const events = await submitTransactionAsync(sender, tx);639 const result = getGenericResult(events);640641 // Get the collection642 const collection = await queryCollectionExpectSuccess(api, collectionId);643644 // What to expect645 expect(result.success).to.be.true;646 expect(collection.sponsorship.toJSON()).to.be.deep.equal({647 confirmed: sender.address,648 });649 });650}651652653export async function confirmSponsorshipExpectFailure(collectionId: number, senderSeed = '//Alice') {654 await usingApi(async (api) => {655656 // Run the transaction657 const sender = privateKey(senderSeed);658 const tx = api.tx.unique.confirmSponsorship(collectionId);659 await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;660 });661}662663export async function enableContractSponsoringExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, enable: boolean) {664 await usingApi(async (api) => {665 const tx = api.tx.unique.enableContractSponsoring(contractAddress, enable);666 const events = await submitTransactionAsync(sender, tx);667 const result = getGenericResult(events);668669 expect(result.success).to.be.true;670 });671}672673export async function enableContractSponsoringExpectFailure(sender: IKeyringPair, contractAddress: AccountId | string, enable: boolean) {674 await usingApi(async (api) => {675 const tx = api.tx.unique.enableContractSponsoring(contractAddress, enable);676 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;677 const result = getGenericResult(events);678679 expect(result.success).to.be.false;680 });681}682683export async function setTransferFlagExpectSuccess(sender: IKeyringPair, collectionId: number, enabled: boolean) {684685 await usingApi(async (api) => {686687 const tx = api.tx.unique.setTransfersEnabledFlag(collectionId, enabled);688 const events = await submitTransactionAsync(sender, tx);689 const result = getGenericResult(events);690691 expect(result.success).to.be.true;692 });693}694695export async function setTransferFlagExpectFailure(sender: IKeyringPair, collectionId: number, enabled: boolean) {696697 await usingApi(async (api) => {698699 const tx = api.tx.unique.setTransfersEnabledFlag(collectionId, enabled);700 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;701 const result = getGenericResult(events);702703 expect(result.success).to.be.false;704 });705}706707export async function setContractSponsoringRateLimitExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, rateLimit: number) {708 await usingApi(async (api) => {709 const tx = api.tx.unique.setContractSponsoringRateLimit(contractAddress, rateLimit);710 const events = await submitTransactionAsync(sender, tx);711 const result = getGenericResult(events);712713 expect(result.success).to.be.true;714 });715}716717export async function setContractSponsoringRateLimitExpectFailure(sender: IKeyringPair, contractAddress: AccountId | string, rateLimit: number) {718 await usingApi(async (api) => {719 const tx = api.tx.unique.setContractSponsoringRateLimit(contractAddress, rateLimit);720 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;721 const result = getGenericResult(events);722723 expect(result.success).to.be.false;724 });725}726727export async function getNextSponsored(728 api: ApiPromise,729 collectionId: number,730 account: string | CrossAccountId,731 tokenId: number,732): Promise<number> {733 return Number((await api.rpc.unique.nextSponsored(collectionId, account, tokenId)).unwrapOr(-1));734}735736export async function toggleContractAllowlistExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, value = true) {737 await usingApi(async (api) => {738 const tx = api.tx.unique.toggleContractAllowList(contractAddress, value);739 const events = await submitTransactionAsync(sender, tx);740 const result = getGenericResult(events);741742 expect(result.success).to.be.true;743 });744}745746export async function isAllowlistedInContract(contractAddress: AccountId | string, user: string) {747 let allowlisted = false;748 await usingApi(async (api) => {749 allowlisted = (await api.query.unique.contractAllowList(contractAddress, user)).toJSON() as boolean;750 });751 return allowlisted;752}753754export async function addToContractAllowListExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, user: AccountId | string) {755 await usingApi(async (api) => {756 const tx = api.tx.unique.addToContractAllowList(contractAddress.toString(), user.toString());757 const events = await submitTransactionAsync(sender, tx);758 const result = getGenericResult(events);759760 expect(result.success).to.be.true;761 });762}763764export async function removeFromContractAllowListExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, user: AccountId | string) {765 await usingApi(async (api) => {766 const tx = api.tx.unique.removeFromContractAllowList(contractAddress.toString(), user.toString());767 const events = await submitTransactionAsync(sender, tx);768 const result = getGenericResult(events);769770 expect(result.success).to.be.true;771 });772}773774export async function removeFromContractAllowListExpectFailure(sender: IKeyringPair, contractAddress: AccountId | string, user: AccountId | string) {775 await usingApi(async (api) => {776 const tx = api.tx.unique.removeFromContractAllowList(contractAddress.toString(), user.toString());777 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;778 const result = getGenericResult(events);779780 expect(result.success).to.be.false;781 });782}783784export interface CreateFungibleData {785 readonly Value: bigint;786}787788export interface CreateReFungibleData { }789export interface CreateNftData { }790791export type CreateItemData = {792 NFT: CreateNftData;793} | {794 Fungible: CreateFungibleData;795} | {796 ReFungible: CreateReFungibleData;797};798799export async function burnItemExpectSuccess(sender: IKeyringPair, collectionId: number, tokenId: number, value = 1) {800 await usingApi(async (api) => {801 const balanceBefore = await getBalance(api, collectionId, normalizeAccountId(sender), tokenId);802 // if burning token by admin - use adminButnItemExpectSuccess803 expect(balanceBefore >= BigInt(value)).to.be.true;804805 const tx = api.tx.unique.burnItem(collectionId, tokenId, value);806 const events = await submitTransactionAsync(sender, tx);807 const result = getGenericResult(events);808 expect(result.success).to.be.true;809810 const balanceAfter = await getBalance(api, collectionId, normalizeAccountId(sender), tokenId);811 expect(balanceAfter + BigInt(value)).to.be.equal(balanceBefore);812 });813}814815export async function816approveExpectSuccess(817 collectionId: number,818 tokenId: number, owner: IKeyringPair, approved: CrossAccountId | string, amount: number | bigint = 1,819) {820 await usingApi(async (api: ApiPromise) => {821 const approveUniqueTx = api.tx.unique.approve(normalizeAccountId(approved), collectionId, tokenId, amount);822 const events = await submitTransactionAsync(owner, approveUniqueTx);823 const result = getGenericResult(events);824 expect(result.success).to.be.true;825826 expect(await getAllowance(api, collectionId, owner.address, approved, tokenId)).to.be.equal(BigInt(amount));827 });828}829830export async function adminApproveFromExpectSuccess(831 collectionId: number,832 tokenId: number, admin: IKeyringPair, owner: CrossAccountId | string, approved: CrossAccountId | string, amount: number | bigint = 1,833) {834 await usingApi(async (api: ApiPromise) => {835 const approveUniqueTx = api.tx.unique.approve(normalizeAccountId(approved), collectionId, tokenId, amount);836 const events = await submitTransactionAsync(admin, approveUniqueTx);837 const result = getGenericResult(events);838 expect(result.success).to.be.true;839840 expect(await getAllowance(api, collectionId, owner, approved, tokenId)).to.be.equal(BigInt(amount));841 });842}843844export async function845transferFromExpectSuccess(846 collectionId: number,847 tokenId: number,848 accountApproved: IKeyringPair,849 accountFrom: IKeyringPair | CrossAccountId,850 accountTo: IKeyringPair | CrossAccountId,851 value: number | bigint = 1,852 type = 'NFT',853) {854 await usingApi(async (api: ApiPromise) => {855 const from = normalizeAccountId(accountFrom);856 const to = normalizeAccountId(accountTo);857 let balanceBefore = 0n;858 if (type === 'Fungible' || type === 'ReFungible') {859 balanceBefore = await getBalance(api, collectionId, to, tokenId);860 }861 const transferFromTx = api.tx.unique.transferFrom(normalizeAccountId(accountFrom), to, collectionId, tokenId, value);862 const events = await submitTransactionAsync(accountApproved, transferFromTx);863 const result = getCreateItemResult(events);864 // tslint:disable-next-line:no-unused-expression865 expect(result.success).to.be.true;866 if (type === 'NFT') {867 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(to);868 }869 if (type === 'Fungible') {870 const balanceAfter = await getBalance(api, collectionId, to, tokenId);871 if (JSON.stringify(to) !== JSON.stringify(from)) {872 expect(balanceAfter - balanceBefore).to.be.equal(BigInt(value));873 } else {874 expect(balanceAfter).to.be.equal(balanceBefore);875 }876 }877 if (type === 'ReFungible') {878 expect(await getBalance(api, collectionId, to, tokenId)).to.be.equal(balanceBefore + BigInt(value));879 }880 });881}882883export async function884transferFromExpectFail(885 collectionId: number,886 tokenId: number,887 accountApproved: IKeyringPair,888 accountFrom: IKeyringPair,889 accountTo: IKeyringPair,890 value: number | bigint = 1,891) {892 await usingApi(async (api: ApiPromise) => {893 const transferFromTx = api.tx.unique.transferFrom(normalizeAccountId(accountFrom.address), normalizeAccountId(accountTo.address), collectionId, tokenId, value);894 const events = await expect(submitTransactionExpectFailAsync(accountApproved, transferFromTx)).to.be.rejected;895 const result = getCreateCollectionResult(events);896 // tslint:disable-next-line:no-unused-expression897 expect(result.success).to.be.false;898 });899}900901/* eslint no-async-promise-executor: "off" */902async function getBlockNumber(api: ApiPromise): Promise<number> {903 return new Promise<number>(async (resolve) => {904 const unsubscribe = await api.rpc.chain.subscribeNewHeads((head) => {905 unsubscribe();906 resolve(head.number.toNumber());907 });908 });909}910911export async function addCollectionAdminExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | CrossAccountId) {912 await usingApi(async (api) => {913 const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(address));914 const events = await submitTransactionAsync(sender, changeAdminTx);915 const result = getCreateCollectionResult(events);916 expect(result.success).to.be.true;917 });918}919920export async function921getFreeBalance(account: IKeyringPair): Promise<bigint> {922 let balance = 0n;923 await usingApi(async (api) => {924 balance = BigInt((await api.query.system.account(account.address)).data.free.toString());925 });926927 return balance;928}929930export async function transferBalanceTo(api: ApiPromise, source: IKeyringPair, target: string, amount = 1000n * UNIQUE) {931 const tx = api.tx.balances.transfer(target, amount);932 const events = await submitTransactionAsync(source, tx);933 const result = getGenericResult(events);934 expect(result.success).to.be.true;935}936937export async function938scheduleTransferExpectSuccess(939 collectionId: number,940 tokenId: number,941 sender: IKeyringPair,942 recipient: IKeyringPair,943 value: number | bigint = 1,944 blockSchedule: number,945) {946 await usingApi(async (api: ApiPromise) => {947 const blockNumber: number | undefined = await getBlockNumber(api);948 const expectedBlockNumber = blockNumber + blockSchedule;949950 expect(blockNumber).to.be.greaterThan(0);951 const transferTx = api.tx.unique.transfer(normalizeAccountId(recipient.address), collectionId, tokenId, value);952 const scheduleTx = api.tx.scheduler.schedule(expectedBlockNumber, null, 0, transferTx as any);953954 await submitTransactionAsync(sender, scheduleTx);955956 const recipientBalanceBefore = (await api.query.system.account(recipient.address)).data.free.toBigInt();957958 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(normalizeAccountId(sender.address));959960 // sleep for 4 blocks961 await waitNewBlocks(blockSchedule + 1);962963 const recipientBalanceAfter = (await api.query.system.account(recipient.address)).data.free.toBigInt();964965 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(normalizeAccountId(recipient.address));966 expect(recipientBalanceAfter).to.be.equal(recipientBalanceBefore);967 });968}969970971export async function972transferExpectSuccess(973 collectionId: number,974 tokenId: number,975 sender: IKeyringPair,976 recipient: IKeyringPair | CrossAccountId,977 value: number | bigint = 1,978 type = 'NFT',979) {980 await usingApi(async (api: ApiPromise) => {981 const from = normalizeAccountId(sender);982 const to = normalizeAccountId(recipient);983984 let balanceBefore = 0n;985 if (type === 'Fungible') {986 balanceBefore = await getBalance(api, collectionId, to, tokenId);987 }988 const transferTx = api.tx.unique.transfer(to, collectionId, tokenId, value);989 const events = await executeTransaction(api, sender, transferTx);990991 const result = getTransferResult(api, events);992 expect(result.collectionId).to.be.equal(collectionId);993 expect(result.itemId).to.be.equal(tokenId);994 expect(result.sender).to.be.deep.equal(normalizeAccountId(sender.address));995 expect(result.recipient).to.be.deep.equal(to);996 expect(result.value).to.be.equal(BigInt(value));997998 if (type === 'NFT') {999 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(to);1000 }1001 if (type === 'Fungible') {1002 const balanceAfter = await getBalance(api, collectionId, to, tokenId);1003 if (JSON.stringify(to) !== JSON.stringify(from)) {1004 expect(balanceAfter - balanceBefore).to.be.equal(BigInt(value));1005 } else {1006 expect(balanceAfter).to.be.equal(balanceBefore);1007 }1008 }1009 if (type === 'ReFungible') {1010 expect(await getBalance(api, collectionId, to, tokenId) >= value).to.be.true;1011 }1012 });1013}10141015export async function1016transferExpectFailure(1017 collectionId: number,1018 tokenId: number,1019 sender: IKeyringPair,1020 recipient: IKeyringPair | CrossAccountId,1021 value: number | bigint = 1,1022) {1023 await usingApi(async (api: ApiPromise) => {1024 const transferTx = api.tx.unique.transfer(normalizeAccountId(recipient), collectionId, tokenId, value);1025 const events = await expect(submitTransactionExpectFailAsync(sender, transferTx)).to.be.rejected;1026 const result = getGenericResult(events);1027 // if (events && Array.isArray(events)) {1028 // const result = getCreateCollectionResult(events);1029 // tslint:disable-next-line:no-unused-expression1030 expect(result.success).to.be.false;1031 //}1032 });1033}10341035export async function1036approveExpectFail(1037 collectionId: number,1038 tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number | bigint = 1,1039) {1040 await usingApi(async (api: ApiPromise) => {1041 const approveUniqueTx = api.tx.unique.approve(normalizeAccountId(approved.address), collectionId, tokenId, amount);1042 const events = await expect(submitTransactionExpectFailAsync(owner, approveUniqueTx)).to.be.rejected;1043 const result = getCreateCollectionResult(events);1044 // tslint:disable-next-line:no-unused-expression1045 expect(result.success).to.be.false;1046 });1047}10481049export async function getBalance(1050 api: ApiPromise,1051 collectionId: number,1052 owner: string | CrossAccountId,1053 token: number,1054): Promise<bigint> {1055 return (await api.rpc.unique.balance(collectionId, normalizeAccountId(owner), token)).toBigInt();1056}1057export async function getTokenOwner(1058 api: ApiPromise,1059 collectionId: number,1060 token: number,1061): Promise<CrossAccountId> {1062 const owner = (await api.rpc.unique.tokenOwner(collectionId, token)).toJSON() as any;1063 if (owner == null) throw new Error('owner == null');1064 return normalizeAccountId(owner);1065}1066export async function getTopmostTokenOwner(1067 api: ApiPromise,1068 collectionId: number,1069 token: number,1070): Promise<CrossAccountId> {1071 const owner = (await api.rpc.unique.topmostTokenOwner(collectionId, token)).toJSON() as any;1072 if (owner == null) throw new Error('owner == null');1073 return normalizeAccountId(owner);1074}1075export async function isTokenExists(1076 api: ApiPromise,1077 collectionId: number,1078 token: number,1079): Promise<boolean> {1080 return (await api.rpc.unique.tokenExists(collectionId, token)).toJSON();1081}1082export async function getLastTokenId(1083 api: ApiPromise,1084 collectionId: number,1085): Promise<number> {1086 return (await api.rpc.unique.lastTokenId(collectionId)).toJSON();1087}1088export async function getAdminList(1089 api: ApiPromise,1090 collectionId: number,1091): Promise<string[]> {1092 return (await api.rpc.unique.adminlist(collectionId)).toHuman() as any;1093}1094export async function getTokenProperties(1095 api: ApiPromise,1096 collectionId: number,1097 tokenId: number,1098 propertyKeys: string[],1099): Promise<UpDataStructsProperty[]> {1100 return (await api.rpc.unique.tokenProperties(collectionId, tokenId, propertyKeys)).toHuman() as any;1101}11021103export async function createFungibleItemExpectSuccess(1104 sender: IKeyringPair,1105 collectionId: number,1106 data: CreateFungibleData,1107 owner: CrossAccountId | string = sender.address,1108) {1109 return await usingApi(async (api) => {1110 const tx = api.tx.unique.createItem(collectionId, normalizeAccountId(owner), {Fungible: data});11111112 const events = await submitTransactionAsync(sender, tx);1113 const result = getCreateItemResult(events);11141115 expect(result.success).to.be.true;1116 return result.itemId;1117 });1118}11191120export async function createMultipleItemsWithPropsExpectSuccess(sender: IKeyringPair, collectionId: number, itemsData: any, owner: CrossAccountId | string = sender.address) {1121 await usingApi(async (api) => {1122 const to = normalizeAccountId(owner);1123 const tx = api.tx.unique.createMultipleItems(collectionId, to, itemsData);11241125 const events = await submitTransactionAsync(sender, tx);1126 const result = getCreateItemsResult(events);11271128 for (const res of result) {1129 expect(await api.rpc.unique.tokenProperties(collectionId, res.itemId)).not.to.be.empty;1130 }1131 });1132}11331134export async function createMultipleItemsExWithPropsExpectSuccess(sender: IKeyringPair, collectionId: number, itemsData: any) {1135 await usingApi(async (api) => {1136 const tx = api.tx.unique.createMultipleItemsEx(collectionId, itemsData);11371138 const events = await submitTransactionAsync(sender, tx);1139 const result = getCreateItemsResult(events);11401141 for (const res of result) {1142 expect(await api.rpc.unique.tokenProperties(collectionId, res.itemId)).not.to.be.empty;1143 }1144 });1145}11461147export async function createItemWithPropsExpectSuccess(sender: IKeyringPair, collectionId: number, createMode: string, props: Array<Property>, owner: CrossAccountId | string = sender.address) {1148 let newItemId = 0;1149 await usingApi(async (api) => {1150 const to = normalizeAccountId(owner);1151 const itemCountBefore = await getLastTokenId(api, collectionId);1152 const itemBalanceBefore = await getBalance(api, collectionId, to, newItemId);11531154 let tx;1155 if (createMode === 'Fungible') {1156 const createData = {fungible: {value: 10}};1157 tx = api.tx.unique.createItem(collectionId, to, createData as any);1158 } else if (createMode === 'ReFungible') {1159 const createData = {refungible: {pieces: 100}};1160 tx = api.tx.unique.createItem(collectionId, to, createData as any);1161 } else {1162 const data = api.createType('UpDataStructsCreateItemData', {NFT: {properties: props}});1163 tx = api.tx.unique.createItem(collectionId, to, data as UpDataStructsCreateItemData);1164 }11651166 const events = await submitTransactionAsync(sender, tx);1167 const result = getCreateItemResult(events);11681169 const itemCountAfter = await getLastTokenId(api, collectionId);1170 const itemBalanceAfter = await getBalance(api, collectionId, to, newItemId);11711172 if (createMode === 'NFT') {1173 expect(await api.rpc.unique.tokenProperties(collectionId, result.itemId)).not.to.be.empty;1174 }11751176 // What to expect1177 // tslint:disable-next-line:no-unused-expression1178 expect(result.success).to.be.true;1179 if (createMode === 'Fungible') {1180 expect(itemBalanceAfter - itemBalanceBefore).to.be.equal(10n);1181 } else {1182 expect(itemCountAfter).to.be.equal(itemCountBefore + 1);1183 }1184 expect(collectionId).to.be.equal(result.collectionId);1185 expect(itemCountAfter.toString()).to.be.equal(result.itemId.toString());1186 expect(to).to.be.deep.equal(result.recipient);1187 newItemId = result.itemId;1188 });1189 return newItemId;1190}11911192export async function createItemWithPropsExpectFailure(sender: IKeyringPair, collectionId: number, createMode: string, props: Array<Property>, owner: CrossAccountId | string = sender.address) {1193 await usingApi(async (api) => {11941195 let tx;1196 if (createMode === 'NFT') {1197 const data = api.createType('UpDataStructsCreateItemData', {NFT: {properties: props}});1198 tx = api.tx.unique.createItem(collectionId, normalizeAccountId(owner), data);1199 } else {1200 tx = api.tx.unique.createItem(collectionId, normalizeAccountId(owner), createMode);1201 }120212031204 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1205 if(events.message && events.message.toString().indexOf('1002: Verification Error') > -1) return;1206 const result = getCreateItemResult(events);12071208 expect(result.success).to.be.false;1209 });1210}12111212export async function createItemExpectSuccess(sender: IKeyringPair, collectionId: number, createMode: string, owner: CrossAccountId | string = sender.address) {1213 let newItemId = 0;1214 await usingApi(async (api) => {1215 const to = normalizeAccountId(owner);1216 const itemCountBefore = await getLastTokenId(api, collectionId);1217 const itemBalanceBefore = await getBalance(api, collectionId, to, newItemId);12181219 let tx;1220 if (createMode === 'Fungible') {1221 const createData = {fungible: {value: 10}};1222 tx = api.tx.unique.createItem(collectionId, to, createData as any);1223 } else if (createMode === 'ReFungible') {1224 const createData = {refungible: {pieces: 100}};1225 tx = api.tx.unique.createItem(collectionId, to, createData as any);1226 } else {1227 const createData = {nft: {}};1228 tx = api.tx.unique.createItem(collectionId, to, createData as any);1229 }12301231 const events = await submitTransactionAsync(sender, tx);1232 const result = getCreateItemResult(events);12331234 const itemCountAfter = await getLastTokenId(api, collectionId);1235 const itemBalanceAfter = await getBalance(api, collectionId, to, newItemId);12361237 // What to expect1238 // tslint:disable-next-line:no-unused-expression1239 expect(result.success).to.be.true;1240 if (createMode === 'Fungible') {1241 expect(itemBalanceAfter - itemBalanceBefore).to.be.equal(10n);1242 } else {1243 expect(itemCountAfter).to.be.equal(itemCountBefore + 1);1244 }1245 expect(collectionId).to.be.equal(result.collectionId);1246 expect(itemCountAfter.toString()).to.be.equal(result.itemId.toString());1247 expect(to).to.be.deep.equal(result.recipient);1248 newItemId = result.itemId;1249 });1250 return newItemId;1251}12521253export async function createItemExpectFailure(sender: IKeyringPair, collectionId: number, createMode: string, owner: CrossAccountId | string = sender.address) {1254 await usingApi(async (api) => {1255 const tx = api.tx.unique.createItem(collectionId, normalizeAccountId(owner), createMode);12561257 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1258 const result = getCreateItemResult(events);12591260 expect(result.success).to.be.false;1261 });1262}12631264export async function setPublicAccessModeExpectSuccess(1265 sender: IKeyringPair, collectionId: number,1266 accessMode: 'Normal' | 'AllowList',1267) {1268 await usingApi(async (api) => {12691270 // Run the transaction1271 const tx = api.tx.unique.setCollectionPermissions(collectionId, {access: accessMode});1272 const events = await submitTransactionAsync(sender, tx);1273 const result = getGenericResult(events);12741275 // Get the collection1276 const collection = await queryCollectionExpectSuccess(api, collectionId);12771278 // What to expect1279 // tslint:disable-next-line:no-unused-expression1280 expect(result.success).to.be.true;1281 expect(collection.permissions.access.toHuman()).to.be.equal(accessMode);1282 });1283}12841285export async function setPublicAccessModeExpectFail(1286 sender: IKeyringPair, collectionId: number,1287 accessMode: 'Normal' | 'AllowList',1288) {1289 await usingApi(async (api) => {12901291 // Run the transaction1292 const tx = api.tx.unique.setCollectionPermissions(collectionId, {access: accessMode});1293 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1294 const result = getGenericResult(events);12951296 // What to expect1297 // tslint:disable-next-line:no-unused-expression1298 expect(result.success).to.be.false;1299 });1300}13011302export async function enableAllowListExpectSuccess(sender: IKeyringPair, collectionId: number) {1303 await setPublicAccessModeExpectSuccess(sender, collectionId, 'AllowList');1304}13051306export async function enableAllowListExpectFail(sender: IKeyringPair, collectionId: number) {1307 await setPublicAccessModeExpectFail(sender, collectionId, 'AllowList');1308}13091310export async function disableAllowListExpectSuccess(sender: IKeyringPair, collectionId: number) {1311 await setPublicAccessModeExpectSuccess(sender, collectionId, 'Normal');1312}13131314export async function setMintPermissionExpectSuccess(sender: IKeyringPair, collectionId: number, enabled: boolean) {1315 await usingApi(async (api) => {13161317 // Run the transaction1318 const tx = api.tx.unique.setCollectionPermissions(collectionId, {mintMode: enabled});1319 const events = await submitTransactionAsync(sender, tx);1320 const result = getGenericResult(events);1321 expect(result.success).to.be.true;13221323 // Get the collection1324 const collection = await queryCollectionExpectSuccess(api, collectionId);13251326 expect(collection.permissions.mintMode.toHuman()).to.be.equal(enabled);1327 });1328}13291330export async function enablePublicMintingExpectSuccess(sender: IKeyringPair, collectionId: number) {1331 await setMintPermissionExpectSuccess(sender, collectionId, true);1332}13331334export async function setMintPermissionExpectFailure(sender: IKeyringPair, collectionId: number, enabled: boolean) {1335 await usingApi(async (api) => {1336 // Run the transaction1337 const tx = api.tx.unique.setCollectionPermissions(collectionId, {mintMode: enabled});1338 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1339 const result = getCreateCollectionResult(events);1340 // tslint:disable-next-line:no-unused-expression1341 expect(result.success).to.be.false;1342 });1343}13441345export async function setChainLimitsExpectFailure(sender: IKeyringPair, limits: IChainLimits) {1346 await usingApi(async (api) => {1347 // Run the transaction1348 const tx = api.tx.unique.setChainLimits(limits);1349 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1350 const result = getCreateCollectionResult(events);1351 // tslint:disable-next-line:no-unused-expression1352 expect(result.success).to.be.false;1353 });1354}13551356export async function isAllowlisted(api: ApiPromise, collectionId: number, address: string | CrossAccountId) {1357 return (await api.rpc.unique.allowed(collectionId, normalizeAccountId(address))).toJSON();1358}13591360export async function addToAllowListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | AccountId | CrossAccountId) {1361 await usingApi(async (api) => {1362 expect(await isAllowlisted(api, collectionId, normalizeAccountId(address))).to.be.false;13631364 // Run the transaction1365 const tx = api.tx.unique.addToAllowList(collectionId, normalizeAccountId(address));1366 const events = await submitTransactionAsync(sender, tx);1367 const result = getGenericResult(events);1368 expect(result.success).to.be.true;13691370 expect(await isAllowlisted(api, collectionId, normalizeAccountId(address))).to.be.true;1371 });1372}13731374export async function addToAllowListAgainExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | AccountId) {1375 await usingApi(async (api) => {13761377 expect(await isAllowlisted(api, collectionId, normalizeAccountId(address))).to.be.true;13781379 // Run the transaction1380 const tx = api.tx.unique.addToAllowList(collectionId, normalizeAccountId(address));1381 const events = await submitTransactionAsync(sender, tx);1382 const result = getGenericResult(events);1383 expect(result.success).to.be.true;13841385 expect(await isAllowlisted(api, collectionId, normalizeAccountId(address))).to.be.true;1386 });1387}13881389export async function addToAllowListExpectFail(sender: IKeyringPair, collectionId: number, address: string | AccountId) {1390 await usingApi(async (api) => {13911392 // Run the transaction1393 const tx = api.tx.unique.addToAllowList(collectionId, normalizeAccountId(address));1394 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1395 const result = getGenericResult(events);13961397 // What to expect1398 // tslint:disable-next-line:no-unused-expression1399 expect(result.success).to.be.false;1400 });1401}14021403export async function removeFromAllowListExpectSuccess(sender: IKeyringPair, collectionId: number, address: CrossAccountId) {1404 await usingApi(async (api) => {1405 // Run the transaction1406 const tx = api.tx.unique.removeFromAllowList(collectionId, normalizeAccountId(address));1407 const events = await submitTransactionAsync(sender, tx);1408 const result = getGenericResult(events);14091410 // What to expect1411 // tslint:disable-next-line:no-unused-expression1412 expect(result.success).to.be.true;1413 });1414}14151416export async function removeFromAllowListExpectFailure(sender: IKeyringPair, collectionId: number, address: CrossAccountId) {1417 await usingApi(async (api) => {1418 // Run the transaction1419 const tx = api.tx.unique.removeFromAllowList(collectionId, normalizeAccountId(address));1420 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1421 const result = getGenericResult(events);14221423 // What to expect1424 // tslint:disable-next-line:no-unused-expression1425 expect(result.success).to.be.false;1426 });1427}14281429export const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)1430 : Promise<UpDataStructsRpcCollection | null> => {1431 return (await api.rpc.unique.collectionById(collectionId)).unwrapOr(null);1432};14331434export const getCreatedCollectionCount = async (api: ApiPromise): Promise<number> => {1435 // set global object - collectionsCount1436 return (await api.rpc.unique.collectionStats()).created.toNumber();1437};14381439export async function queryCollectionExpectSuccess(api: ApiPromise, collectionId: number): Promise<UpDataStructsRpcCollection> {1440 return (await api.rpc.unique.collectionById(collectionId)).unwrap();1441}14421443export async function waitNewBlocks(blocksCount = 1): Promise<void> {1444 await usingApi(async (api) => {1445 const promise = new Promise<void>(async (resolve) => {1446 const unsubscribe = await api.rpc.chain.subscribeNewHeads(() => {1447 if (blocksCount > 0) {1448 blocksCount--;1449 } else {1450 unsubscribe();1451 resolve();1452 }1453 });1454 });1455 return promise;1456 });1457}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import '../interfaces/augment-api-rpc';18import '../interfaces/augment-api-query';19import {ApiPromise, Keyring} from '@polkadot/api';20import type {AccountId, EventRecord, Event} from '@polkadot/types/interfaces';21import {AnyTuple, IEvent, IKeyringPair} from '@polkadot/types/types';22import {evmToAddress} from '@polkadot/util-crypto';23import BN from 'bn.js';24import chai from 'chai';25import chaiAsPromised from 'chai-as-promised';26import {alicesPublicKey} from '../accounts';27import {default as usingApi, executeTransaction, submitTransactionAsync, submitTransactionExpectFailAsync} from '../substrate/substrate-api';28import {hexToStr, strToUTF16, utf16ToStr} from './util';29import {UpDataStructsRpcCollection, UpDataStructsCreateItemData, UpDataStructsProperty} from '@polkadot/types/lookup';3031chai.use(chaiAsPromised);32const expect = chai.expect;3334export type CrossAccountId = {35 Substrate: string,36} | {37 Ethereum: string,38};3940export function normalizeAccountId(input: string | AccountId | CrossAccountId | IKeyringPair): CrossAccountId {41 if (typeof input === 'string') {42 if (input.length === 48 || input.length === 47) {43 return {Substrate: input};44 } else if (input.length === 42 && input.startsWith('0x')) {45 return {Ethereum: input.toLowerCase()};46 } else if (input.length === 40 && !input.startsWith('0x')) {47 return {Ethereum: '0x' + input.toLowerCase()};48 } else {49 throw new Error(`Unknown address format: "${input}"`);50 }51 }52 if ('address' in input) {53 return {Substrate: input.address};54 }55 if ('Ethereum' in input) {56 return {57 Ethereum: input.Ethereum.toLowerCase(),58 };59 } else if ('ethereum' in input) {60 return {61 Ethereum: (input as any).ethereum.toLowerCase(),62 };63 } else if ('Substrate' in input) {64 return input;65 } else if ('substrate' in input) {66 return {67 Substrate: (input as any).substrate,68 };69 }7071 // AccountId72 return {Substrate: input.toString()};73}74export function toSubstrateAddress(input: string | CrossAccountId | IKeyringPair): string {75 input = normalizeAccountId(input);76 if ('Substrate' in input) {77 return input.Substrate;78 } else {79 return evmToAddress(input.Ethereum);80 }81}8283export const U128_MAX = (1n << 128n) - 1n;8485const MICROUNIQUE = 1_000_000_000_000n;86const MILLIUNIQUE = 1_000n * MICROUNIQUE;87const CENTIUNIQUE = 10n * MILLIUNIQUE;88export const UNIQUE = 100n * CENTIUNIQUE;8990type GenericResult = {91 success: boolean,92};9394interface CreateCollectionResult {95 success: boolean;96 collectionId: number;97}9899interface CreateItemResult {100 success: boolean;101 collectionId: number;102 itemId: number;103 recipient?: CrossAccountId;104}105106interface TransferResult {107 collectionId: number;108 itemId: number;109 sender?: CrossAccountId;110 recipient?: CrossAccountId;111 value: bigint;112}113114interface IReFungibleOwner {115 fraction: BN;116 owner: number[];117}118119interface IGetMessage {120 checkMsgUnqMethod: string;121 checkMsgTrsMethod: string;122 checkMsgSysMethod: string;123}124125export interface IFungibleTokenDataType {126 value: number;127}128129export interface IChainLimits {130 collectionNumbersLimit: number;131 accountTokenOwnershipLimit: number;132 collectionsAdminsLimit: number;133 customDataLimit: number;134 nftSponsorTransferTimeout: number;135 fungibleSponsorTransferTimeout: number;136 refungibleSponsorTransferTimeout: number;137 //offchainSchemaLimit: number;138 //constOnChainSchemaLimit: number;139}140141export interface IReFungibleTokenDataType {142 owner: IReFungibleOwner[];143}144145export function uniqueEventMessage(events: EventRecord[]): IGetMessage {146 let checkMsgUnqMethod = '';147 let checkMsgTrsMethod = '';148 let checkMsgSysMethod = '';149 events.forEach(({event: {method, section}}) => {150 if (section === 'common') {151 checkMsgUnqMethod = method;152 } else if (section === 'treasury') {153 checkMsgTrsMethod = method;154 } else if (section === 'system') {155 checkMsgSysMethod = method;156 } else { return null; }157 });158 const result: IGetMessage = {159 checkMsgUnqMethod,160 checkMsgTrsMethod,161 checkMsgSysMethod,162 };163 return result;164}165166export function getEvent<T extends Event>(events: EventRecord[], check: (event: IEvent<AnyTuple>) => event is T): T | undefined {167 const event = events.find(r => check(r.event));168 if (!event) return;169 return event.event as T;170}171172export function getGenericResult(events: EventRecord[]): GenericResult {173 const result: GenericResult = {174 success: false,175 };176 events.forEach(({event: {method}}) => {177 // console.log(` ${phase}: ${section}.${method}:: ${data}`);178 if (method === 'ExtrinsicSuccess') {179 result.success = true;180 }181 });182 return result;183}184185186187export function getCreateCollectionResult(events: EventRecord[]): CreateCollectionResult {188 let success = false;189 let collectionId = 0;190 events.forEach(({event: {data, method, section}}) => {191 // console.log(` ${phase}: ${section}.${method}:: ${data}`);192 if (method == 'ExtrinsicSuccess') {193 success = true;194 } else if ((section == 'common') && (method == 'CollectionCreated')) {195 collectionId = parseInt(data[0].toString(), 10);196 }197 });198 const result: CreateCollectionResult = {199 success,200 collectionId,201 };202 return result;203}204205export function getCreateItemsResult(events: EventRecord[]): CreateItemResult[] {206 let success = false;207 let collectionId = 0;208 let itemId = 0;209 let recipient;210211 const results : CreateItemResult[] = [];212213 events.forEach(({event: {data, method, section}}) => {214 // console.log(` ${phase}: ${section}.${method}:: ${data}`);215 if (method == 'ExtrinsicSuccess') {216 success = true;217 } else if ((section == 'common') && (method == 'ItemCreated')) {218 collectionId = parseInt(data[0].toString(), 10);219 itemId = parseInt(data[1].toString(), 10);220 recipient = normalizeAccountId(data[2].toJSON() as any);221222 const itemRes: CreateItemResult = {223 success,224 collectionId,225 itemId,226 recipient,227 };228229 results.push(itemRes);230 }231 });232233 return results;234}235236export function getCreateItemResult(events: EventRecord[]): CreateItemResult {237 let success = false;238 let collectionId = 0;239 let itemId = 0;240 let recipient;241 events.forEach(({event: {data, method, section}}) => {242 // console.log(` ${phase}: ${section}.${method}:: ${data}`);243 if (method == 'ExtrinsicSuccess') {244 success = true;245 } else if ((section == 'common') && (method == 'ItemCreated')) {246 collectionId = parseInt(data[0].toString(), 10);247 itemId = parseInt(data[1].toString(), 10);248 recipient = normalizeAccountId(data[2].toJSON() as any);249 }250 });251 const result: CreateItemResult = {252 success,253 collectionId,254 itemId,255 recipient,256 };257 return result;258}259260export function getTransferResult(api: ApiPromise, events: EventRecord[]): TransferResult {261 for (const {event} of events) {262 if (api.events.common.Transfer.is(event)) {263 const [collection, token, sender, recipient, value] = event.data;264 return {265 collectionId: collection.toNumber(),266 itemId: token.toNumber(),267 sender: normalizeAccountId(sender.toJSON() as any),268 recipient: normalizeAccountId(recipient.toJSON() as any),269 value: value.toBigInt(),270 };271 }272 }273 throw new Error('no transfer event');274}275276interface Nft {277 type: 'NFT';278}279280interface Fungible {281 type: 'Fungible';282 decimalPoints: number;283}284285interface ReFungible {286 type: 'ReFungible';287}288289type CollectionMode = Nft | Fungible | ReFungible;290291export type Property = {292 key: any,293 value: any,294};295296type Permission = {297 mutable: boolean;298 collectionAdmin: boolean;299 tokenOwner: boolean;300}301302type PropertyPermission = {303 key: any;304 permission: Permission;305}306307export type CreateCollectionParams = {308 mode: CollectionMode,309 name: string,310 description: string,311 tokenPrefix: string,312 properties?: Array<Property>,313 propPerm?: Array<PropertyPermission>314};315316const defaultCreateCollectionParams: CreateCollectionParams = {317 description: 'description',318 mode: {type: 'NFT'},319 name: 'name',320 tokenPrefix: 'prefix',321};322323export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {324 const {name, description, mode, tokenPrefix} = {...defaultCreateCollectionParams, ...params};325326 let collectionId = 0;327 await usingApi(async (api, privateKeyWrapper) => {328 // Get number of collections before the transaction329 const collectionCountBefore = await getCreatedCollectionCount(api);330331 // Run the CreateCollection transaction332 const alicePrivateKey = privateKeyWrapper!('//Alice');333334 let modeprm = {};335 if (mode.type === 'NFT') {336 modeprm = {nft: null};337 } else if (mode.type === 'Fungible') {338 modeprm = {fungible: mode.decimalPoints};339 } else if (mode.type === 'ReFungible') {340 modeprm = {refungible: null};341 }342343 const tx = api.tx.unique.createCollectionEx({344 name: strToUTF16(name),345 description: strToUTF16(description),346 tokenPrefix: strToUTF16(tokenPrefix),347 mode: modeprm as any,348 });349 const events = await submitTransactionAsync(alicePrivateKey, tx);350 const result = getCreateCollectionResult(events);351352 // Get number of collections after the transaction353 const collectionCountAfter = await getCreatedCollectionCount(api);354355 // Get the collection356 const collection = await queryCollectionExpectSuccess(api, result.collectionId);357358 // What to expect359 // tslint:disable-next-line:no-unused-expression360 expect(result.success).to.be.true;361 expect(result.collectionId).to.be.equal(collectionCountAfter);362 // tslint:disable-next-line:no-unused-expression363 expect(collection).to.be.not.null;364 expect(collectionCountAfter).to.be.equal(collectionCountBefore + 1, 'Error: NFT collection NOT created.');365 expect(collection.owner.toString()).to.be.equal(toSubstrateAddress(alicesPublicKey));366 expect(utf16ToStr(collection.name.toJSON() as any)).to.be.equal(name);367 expect(utf16ToStr(collection.description.toJSON() as any)).to.be.equal(description);368 expect(hexToStr(collection.tokenPrefix.toJSON())).to.be.equal(tokenPrefix);369370 collectionId = result.collectionId;371 });372373 return collectionId;374}375376export async function createCollectionWithPropsExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {377 const {name, description, mode, tokenPrefix} = {...defaultCreateCollectionParams, ...params};378379 let collectionId = 0;380 await usingApi(async (api, privateKeyWrapper) => {381 // Get number of collections before the transaction382 const collectionCountBefore = await getCreatedCollectionCount(api);383384 // Run the CreateCollection transaction385 const alicePrivateKey = privateKeyWrapper!('//Alice');386387 let modeprm = {};388 if (mode.type === 'NFT') {389 modeprm = {nft: null};390 } else if (mode.type === 'Fungible') {391 modeprm = {fungible: mode.decimalPoints};392 } else if (mode.type === 'ReFungible') {393 modeprm = {refungible: null};394 }395396 const tx = api.tx.unique.createCollectionEx({name: strToUTF16(name), description: strToUTF16(description), tokenPrefix: strToUTF16(tokenPrefix), mode: modeprm as any, properties: params.properties, tokenPropertyPermissions: params.propPerm});397 const events = await submitTransactionAsync(alicePrivateKey, tx);398 const result = getCreateCollectionResult(events);399400 // Get number of collections after the transaction401 const collectionCountAfter = await getCreatedCollectionCount(api);402403 // Get the collection404 const collection = await queryCollectionExpectSuccess(api, result.collectionId);405406 // What to expect407 // tslint:disable-next-line:no-unused-expression408 expect(result.success).to.be.true;409 expect(result.collectionId).to.be.equal(collectionCountAfter);410 // tslint:disable-next-line:no-unused-expression411 expect(collection).to.be.not.null;412 expect(collectionCountAfter).to.be.equal(collectionCountBefore + 1, 'Error: NFT collection NOT created.');413 expect(collection.owner.toString()).to.be.equal(toSubstrateAddress(alicesPublicKey));414 expect(utf16ToStr(collection.name.toJSON() as any)).to.be.equal(name);415 expect(utf16ToStr(collection.description.toJSON() as any)).to.be.equal(description);416 expect(hexToStr(collection.tokenPrefix.toJSON())).to.be.equal(tokenPrefix);417418419 collectionId = result.collectionId;420 });421422 return collectionId;423}424425export async function createCollectionWithPropsExpectFailure(params: Partial<CreateCollectionParams> = {}) {426 const {name, description, mode, tokenPrefix} = {...defaultCreateCollectionParams, ...params};427428 await usingApi(async (api, privateKeyWrapper) => {429 // Get number of collections before the transaction430 const collectionCountBefore = await getCreatedCollectionCount(api);431432 // Run the CreateCollection transaction433 const alicePrivateKey = privateKeyWrapper!('//Alice');434435 let modeprm = {};436 if (mode.type === 'NFT') {437 modeprm = {nft: null};438 } else if (mode.type === 'Fungible') {439 modeprm = {fungible: mode.decimalPoints};440 } else if (mode.type === 'ReFungible') {441 modeprm = {refungible: null};442 }443444 const tx = api.tx.unique.createCollectionEx({name: strToUTF16(name), description: strToUTF16(description), tokenPrefix: strToUTF16(tokenPrefix), mode: modeprm as any, properties: params.properties, tokenPropertyPermissions: params.propPerm});445 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;446447448 // Get number of collections after the transaction449 const collectionCountAfter = await getCreatedCollectionCount(api);450451 expect(collectionCountAfter).to.be.equal(collectionCountBefore, 'Error: Collection with incorrect data created.');452 });453}454455export async function createCollectionExpectFailure(params: Partial<CreateCollectionParams> = {}) {456 const {name, description, mode, tokenPrefix} = {...defaultCreateCollectionParams, ...params};457458 let modeprm = {};459 if (mode.type === 'NFT') {460 modeprm = {nft: null};461 } else if (mode.type === 'Fungible') {462 modeprm = {fungible: mode.decimalPoints};463 } else if (mode.type === 'ReFungible') {464 modeprm = {refungible: null};465 }466467 await usingApi(async (api, privateKeyWrapper) => {468 // Get number of collections before the transaction469 const collectionCountBefore = await getCreatedCollectionCount(api);470471 // Run the CreateCollection transaction472 const alicePrivateKey = privateKeyWrapper!('//Alice');473 const tx = api.tx.unique.createCollectionEx({name: strToUTF16(name), description: strToUTF16(description), tokenPrefix: strToUTF16(tokenPrefix), mode: modeprm as any});474 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;475476 // Get number of collections after the transaction477 const collectionCountAfter = await getCreatedCollectionCount(api);478479 // What to expect480 expect(collectionCountAfter).to.be.equal(collectionCountBefore, 'Error: Collection with incorrect data created.');481 });482}483484export async function findUnusedAddress(api: ApiPromise, seedAddition = ''): Promise<IKeyringPair> {485 let bal = 0n;486 let unused;487 do {488 const randomSeed = 'seed' + Math.floor(Math.random() * Math.floor(10000)) + seedAddition;489 const keyring = new Keyring({type: 'sr25519'});490 unused = keyring.addFromUri(`//${randomSeed}`);491 bal = (await api.query.system.account(unused.address)).data.free.toBigInt();492 } while (bal !== 0n);493 return unused;494}495496export async function getAllowance(api: ApiPromise, collectionId: number, owner: CrossAccountId | string, approved: CrossAccountId | string, tokenId: number) {497 return (await api.rpc.unique.allowance(collectionId, normalizeAccountId(owner), normalizeAccountId(approved), tokenId)).toBigInt();498}499500export function findUnusedAddresses(api: ApiPromise, amount: number): Promise<IKeyringPair[]> {501 return Promise.all(new Array(amount).fill(null).map(() => findUnusedAddress(api, '_' + Date.now())));502}503504export async function findNotExistingCollection(api: ApiPromise): Promise<number> {505 const totalNumber = await getCreatedCollectionCount(api);506 const newCollection: number = totalNumber + 1;507 return newCollection;508}509510function getDestroyResult(events: EventRecord[]): boolean {511 let success = false;512 events.forEach(({event: {method}}) => {513 if (method == 'ExtrinsicSuccess') {514 success = true;515 }516 });517 return success;518}519520export async function destroyCollectionExpectFailure(collectionId: number, senderSeed = '//Alice') {521 await usingApi(async (api, privateKeyWrapper) => {522 // Run the DestroyCollection transaction523 const alicePrivateKey = privateKeyWrapper!(senderSeed);524 const tx = api.tx.unique.destroyCollection(collectionId);525 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;526 });527}528529export async function destroyCollectionExpectSuccess(collectionId: number, senderSeed = '//Alice') {530 await usingApi(async (api, privateKeyWrapper) => {531 // Run the DestroyCollection transaction532 const alicePrivateKey = privateKeyWrapper!(senderSeed);533 const tx = api.tx.unique.destroyCollection(collectionId);534 const events = await submitTransactionAsync(alicePrivateKey, tx);535 const result = getDestroyResult(events);536 expect(result).to.be.true;537538 // What to expect539 expect(await getDetailedCollectionInfo(api, collectionId)).to.be.null;540 });541}542543export async function setCollectionLimitsExpectSuccess(sender: IKeyringPair, collectionId: number, limits: any) {544 await usingApi(async (api) => {545 const tx = api.tx.unique.setCollectionLimits(collectionId, limits);546 const events = await submitTransactionAsync(sender, tx);547 const result = getGenericResult(events);548549 expect(result.success).to.be.true;550 });551}552553export const setCollectionPermissionsExpectSuccess = async (sender: IKeyringPair, collectionId: number, permissions: {mintMode?: boolean, access?: 'Normal' | 'AllowList', nesting?: 'Disabled' | 'Owner' | {OwnerRestricted: number[]}}) => {554 await usingApi(async(api) => {555 const tx = api.tx.unique.setCollectionPermissions(collectionId, permissions);556 const events = await submitTransactionAsync(sender, tx);557 const result = getGenericResult(events);558559 expect(result.success).to.be.true;560 });561};562563export async function setCollectionLimitsExpectFailure(sender: IKeyringPair, collectionId: number, limits: any) {564 await usingApi(async (api) => {565 const tx = api.tx.unique.setCollectionLimits(collectionId, limits);566 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;567 const result = getGenericResult(events);568569 expect(result.success).to.be.false;570 });571}572573export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string, sender = '//Alice') {574 await usingApi(async (api, privateKeyWrapper) => {575576 // Run the transaction577 const senderPrivateKey = privateKeyWrapper!(sender);578 const tx = api.tx.unique.setCollectionSponsor(collectionId, sponsor);579 const events = await submitTransactionAsync(senderPrivateKey, tx);580 const result = getGenericResult(events);581582 // Get the collection583 const collection = await queryCollectionExpectSuccess(api, collectionId);584585 // What to expect586 expect(result.success).to.be.true;587 expect(collection.sponsorship.toJSON()).to.deep.equal({588 unconfirmed: sponsor,589 });590 });591}592593export async function removeCollectionSponsorExpectSuccess(collectionId: number, sender = '//Alice') {594 await usingApi(async (api, privateKeyWrapper) => {595596 // Run the transaction597 const alicePrivateKey = privateKeyWrapper!(sender);598 const tx = api.tx.unique.removeCollectionSponsor(collectionId);599 const events = await submitTransactionAsync(alicePrivateKey, tx);600 const result = getGenericResult(events);601602 // Get the collection603 const collection = await queryCollectionExpectSuccess(api, collectionId);604605 // What to expect606 expect(result.success).to.be.true;607 expect(collection.sponsorship.toJSON()).to.be.deep.equal({disabled: null});608 });609}610611export async function removeCollectionSponsorExpectFailure(collectionId: number, senderSeed = '//Alice') {612 await usingApi(async (api, privateKeyWrapper) => {613614 // Run the transaction615 const alicePrivateKey = privateKeyWrapper!(senderSeed);616 const tx = api.tx.unique.removeCollectionSponsor(collectionId);617 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;618 });619}620621export async function setCollectionSponsorExpectFailure(collectionId: number, sponsor: string, senderSeed = '//Alice') {622 await usingApi(async (api, privateKeyWrapper) => {623624 // Run the transaction625 const alicePrivateKey = privateKeyWrapper!(senderSeed);626 const tx = api.tx.unique.setCollectionSponsor(collectionId, sponsor);627 await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;628 });629}630631export async function confirmSponsorshipExpectSuccess(collectionId: number, senderSeed = '//Alice') {632 await usingApi(async (api, privateKeyWrapper) => {633634 // Run the transaction635 const sender = privateKeyWrapper!(senderSeed);636 const tx = api.tx.unique.confirmSponsorship(collectionId);637 const events = await submitTransactionAsync(sender, tx);638 const result = getGenericResult(events);639640 // Get the collection641 const collection = await queryCollectionExpectSuccess(api, collectionId);642643 // What to expect644 expect(result.success).to.be.true;645 expect(collection.sponsorship.toJSON()).to.be.deep.equal({646 confirmed: sender.address,647 });648 });649}650651652export async function confirmSponsorshipExpectFailure(collectionId: number, senderSeed = '//Alice') {653 await usingApi(async (api, privateKeyWrapper) => {654655 // Run the transaction656 const sender = privateKeyWrapper!(senderSeed);657 const tx = api.tx.unique.confirmSponsorship(collectionId);658 await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;659 });660}661662export async function enableContractSponsoringExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, enable: boolean) {663 await usingApi(async (api) => {664 const tx = api.tx.unique.enableContractSponsoring(contractAddress, enable);665 const events = await submitTransactionAsync(sender, tx);666 const result = getGenericResult(events);667668 expect(result.success).to.be.true;669 });670}671672export async function enableContractSponsoringExpectFailure(sender: IKeyringPair, contractAddress: AccountId | string, enable: boolean) {673 await usingApi(async (api) => {674 const tx = api.tx.unique.enableContractSponsoring(contractAddress, enable);675 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;676 const result = getGenericResult(events);677678 expect(result.success).to.be.false;679 });680}681682export async function setTransferFlagExpectSuccess(sender: IKeyringPair, collectionId: number, enabled: boolean) {683684 await usingApi(async (api) => {685686 const tx = api.tx.unique.setTransfersEnabledFlag(collectionId, enabled);687 const events = await submitTransactionAsync(sender, tx);688 const result = getGenericResult(events);689690 expect(result.success).to.be.true;691 });692}693694export async function setTransferFlagExpectFailure(sender: IKeyringPair, collectionId: number, enabled: boolean) {695696 await usingApi(async (api) => {697698 const tx = api.tx.unique.setTransfersEnabledFlag(collectionId, enabled);699 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;700 const result = getGenericResult(events);701702 expect(result.success).to.be.false;703 });704}705706export async function setContractSponsoringRateLimitExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, rateLimit: number) {707 await usingApi(async (api) => {708 const tx = api.tx.unique.setContractSponsoringRateLimit(contractAddress, rateLimit);709 const events = await submitTransactionAsync(sender, tx);710 const result = getGenericResult(events);711712 expect(result.success).to.be.true;713 });714}715716export async function setContractSponsoringRateLimitExpectFailure(sender: IKeyringPair, contractAddress: AccountId | string, rateLimit: number) {717 await usingApi(async (api) => {718 const tx = api.tx.unique.setContractSponsoringRateLimit(contractAddress, rateLimit);719 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;720 const result = getGenericResult(events);721722 expect(result.success).to.be.false;723 });724}725726export async function getNextSponsored(727 api: ApiPromise,728 collectionId: number,729 account: string | CrossAccountId,730 tokenId: number,731): Promise<number> {732 return Number((await api.rpc.unique.nextSponsored(collectionId, account, tokenId)).unwrapOr(-1));733}734735export async function toggleContractAllowlistExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, value = true) {736 await usingApi(async (api) => {737 const tx = api.tx.unique.toggleContractAllowList(contractAddress, value);738 const events = await submitTransactionAsync(sender, tx);739 const result = getGenericResult(events);740741 expect(result.success).to.be.true;742 });743}744745export async function isAllowlistedInContract(contractAddress: AccountId | string, user: string) {746 let allowlisted = false;747 await usingApi(async (api) => {748 allowlisted = (await api.query.unique.contractAllowList(contractAddress, user)).toJSON() as boolean;749 });750 return allowlisted;751}752753export async function addToContractAllowListExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, user: AccountId | string) {754 await usingApi(async (api) => {755 const tx = api.tx.unique.addToContractAllowList(contractAddress.toString(), user.toString());756 const events = await submitTransactionAsync(sender, tx);757 const result = getGenericResult(events);758759 expect(result.success).to.be.true;760 });761}762763export async function removeFromContractAllowListExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, user: AccountId | string) {764 await usingApi(async (api) => {765 const tx = api.tx.unique.removeFromContractAllowList(contractAddress.toString(), user.toString());766 const events = await submitTransactionAsync(sender, tx);767 const result = getGenericResult(events);768769 expect(result.success).to.be.true;770 });771}772773export async function removeFromContractAllowListExpectFailure(sender: IKeyringPair, contractAddress: AccountId | string, user: AccountId | string) {774 await usingApi(async (api) => {775 const tx = api.tx.unique.removeFromContractAllowList(contractAddress.toString(), user.toString());776 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;777 const result = getGenericResult(events);778779 expect(result.success).to.be.false;780 });781}782783export interface CreateFungibleData {784 readonly Value: bigint;785}786787export interface CreateReFungibleData { }788export interface CreateNftData { }789790export type CreateItemData = {791 NFT: CreateNftData;792} | {793 Fungible: CreateFungibleData;794} | {795 ReFungible: CreateReFungibleData;796};797798export async function burnItemExpectSuccess(sender: IKeyringPair, collectionId: number, tokenId: number, value = 1) {799 await usingApi(async (api) => {800 const balanceBefore = await getBalance(api, collectionId, normalizeAccountId(sender), tokenId);801 // if burning token by admin - use adminButnItemExpectSuccess802 expect(balanceBefore >= BigInt(value)).to.be.true;803804 const tx = api.tx.unique.burnItem(collectionId, tokenId, value);805 const events = await submitTransactionAsync(sender, tx);806 const result = getGenericResult(events);807 expect(result.success).to.be.true;808809 const balanceAfter = await getBalance(api, collectionId, normalizeAccountId(sender), tokenId);810 expect(balanceAfter + BigInt(value)).to.be.equal(balanceBefore);811 });812}813814export async function815approveExpectSuccess(816 collectionId: number,817 tokenId: number, owner: IKeyringPair, approved: CrossAccountId | string, amount: number | bigint = 1,818) {819 await usingApi(async (api: ApiPromise) => {820 const approveUniqueTx = api.tx.unique.approve(normalizeAccountId(approved), collectionId, tokenId, amount);821 const events = await submitTransactionAsync(owner, approveUniqueTx);822 const result = getGenericResult(events);823 expect(result.success).to.be.true;824825 expect(await getAllowance(api, collectionId, owner.address, approved, tokenId)).to.be.equal(BigInt(amount));826 });827}828829export async function adminApproveFromExpectSuccess(830 collectionId: number,831 tokenId: number, admin: IKeyringPair, owner: CrossAccountId | string, approved: CrossAccountId | string, amount: number | bigint = 1,832) {833 await usingApi(async (api: ApiPromise) => {834 const approveUniqueTx = api.tx.unique.approve(normalizeAccountId(approved), collectionId, tokenId, amount);835 const events = await submitTransactionAsync(admin, approveUniqueTx);836 const result = getGenericResult(events);837 expect(result.success).to.be.true;838839 expect(await getAllowance(api, collectionId, owner, approved, tokenId)).to.be.equal(BigInt(amount));840 });841}842843export async function844transferFromExpectSuccess(845 collectionId: number,846 tokenId: number,847 accountApproved: IKeyringPair,848 accountFrom: IKeyringPair | CrossAccountId,849 accountTo: IKeyringPair | CrossAccountId,850 value: number | bigint = 1,851 type = 'NFT',852) {853 await usingApi(async (api: ApiPromise) => {854 const from = normalizeAccountId(accountFrom);855 const to = normalizeAccountId(accountTo);856 let balanceBefore = 0n;857 if (type === 'Fungible' || type === 'ReFungible') {858 balanceBefore = await getBalance(api, collectionId, to, tokenId);859 }860 const transferFromTx = api.tx.unique.transferFrom(normalizeAccountId(accountFrom), to, collectionId, tokenId, value);861 const events = await submitTransactionAsync(accountApproved, transferFromTx);862 const result = getCreateItemResult(events);863 // tslint:disable-next-line:no-unused-expression864 expect(result.success).to.be.true;865 if (type === 'NFT') {866 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(to);867 }868 if (type === 'Fungible') {869 const balanceAfter = await getBalance(api, collectionId, to, tokenId);870 if (JSON.stringify(to) !== JSON.stringify(from)) {871 expect(balanceAfter - balanceBefore).to.be.equal(BigInt(value));872 } else {873 expect(balanceAfter).to.be.equal(balanceBefore);874 }875 }876 if (type === 'ReFungible') {877 expect(await getBalance(api, collectionId, to, tokenId)).to.be.equal(balanceBefore + BigInt(value));878 }879 });880}881882export async function883transferFromExpectFail(884 collectionId: number,885 tokenId: number,886 accountApproved: IKeyringPair,887 accountFrom: IKeyringPair,888 accountTo: IKeyringPair,889 value: number | bigint = 1,890) {891 await usingApi(async (api: ApiPromise) => {892 const transferFromTx = api.tx.unique.transferFrom(normalizeAccountId(accountFrom.address), normalizeAccountId(accountTo.address), collectionId, tokenId, value);893 const events = await expect(submitTransactionExpectFailAsync(accountApproved, transferFromTx)).to.be.rejected;894 const result = getCreateCollectionResult(events);895 // tslint:disable-next-line:no-unused-expression896 expect(result.success).to.be.false;897 });898}899900/* eslint no-async-promise-executor: "off" */901async function getBlockNumber(api: ApiPromise): Promise<number> {902 return new Promise<number>(async (resolve) => {903 const unsubscribe = await api.rpc.chain.subscribeNewHeads((head) => {904 unsubscribe();905 resolve(head.number.toNumber());906 });907 });908}909910export async function addCollectionAdminExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | CrossAccountId) {911 await usingApi(async (api) => {912 const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(address));913 const events = await submitTransactionAsync(sender, changeAdminTx);914 const result = getCreateCollectionResult(events);915 expect(result.success).to.be.true;916 });917}918919export async function920getFreeBalance(account: IKeyringPair): Promise<bigint> {921 let balance = 0n;922 await usingApi(async (api) => {923 balance = BigInt((await api.query.system.account(account.address)).data.free.toString());924 });925926 return balance;927}928929export async function transferBalanceTo(api: ApiPromise, source: IKeyringPair, target: string, amount = 1000n * UNIQUE) {930 const tx = api.tx.balances.transfer(target, amount);931 const events = await submitTransactionAsync(source, tx);932 const result = getGenericResult(events);933 expect(result.success).to.be.true;934}935936export async function937scheduleTransferExpectSuccess(938 collectionId: number,939 tokenId: number,940 sender: IKeyringPair,941 recipient: IKeyringPair,942 value: number | bigint = 1,943 blockSchedule: number,944) {945 await usingApi(async (api: ApiPromise) => {946 const blockNumber: number | undefined = await getBlockNumber(api);947 const expectedBlockNumber = blockNumber + blockSchedule;948949 expect(blockNumber).to.be.greaterThan(0);950 const transferTx = api.tx.unique.transfer(normalizeAccountId(recipient.address), collectionId, tokenId, value);951 const scheduleTx = api.tx.scheduler.schedule(expectedBlockNumber, null, 0, transferTx as any);952953 await submitTransactionAsync(sender, scheduleTx);954955 const recipientBalanceBefore = (await api.query.system.account(recipient.address)).data.free.toBigInt();956957 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(normalizeAccountId(sender.address));958959 // sleep for 4 blocks960 await waitNewBlocks(blockSchedule + 1);961962 const recipientBalanceAfter = (await api.query.system.account(recipient.address)).data.free.toBigInt();963964 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(normalizeAccountId(recipient.address));965 expect(recipientBalanceAfter).to.be.equal(recipientBalanceBefore);966 });967}968969970export async function971transferExpectSuccess(972 collectionId: number,973 tokenId: number,974 sender: IKeyringPair,975 recipient: IKeyringPair | CrossAccountId,976 value: number | bigint = 1,977 type = 'NFT',978) {979 await usingApi(async (api: ApiPromise) => {980 const from = normalizeAccountId(sender);981 const to = normalizeAccountId(recipient);982983 let balanceBefore = 0n;984 if (type === 'Fungible') {985 balanceBefore = await getBalance(api, collectionId, to, tokenId);986 }987 const transferTx = api.tx.unique.transfer(to, collectionId, tokenId, value);988 const events = await executeTransaction(api, sender, transferTx);989990 const result = getTransferResult(api, events);991 expect(result.collectionId).to.be.equal(collectionId);992 expect(result.itemId).to.be.equal(tokenId);993 expect(result.sender).to.be.deep.equal(normalizeAccountId(sender.address));994 expect(result.recipient).to.be.deep.equal(to);995 expect(result.value).to.be.equal(BigInt(value));996997 if (type === 'NFT') {998 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal(to);999 }1000 if (type === 'Fungible') {1001 const balanceAfter = await getBalance(api, collectionId, to, tokenId);1002 if (JSON.stringify(to) !== JSON.stringify(from)) {1003 expect(balanceAfter - balanceBefore).to.be.equal(BigInt(value));1004 } else {1005 expect(balanceAfter).to.be.equal(balanceBefore);1006 }1007 }1008 if (type === 'ReFungible') {1009 expect(await getBalance(api, collectionId, to, tokenId) >= value).to.be.true;1010 }1011 });1012}10131014export async function1015transferExpectFailure(1016 collectionId: number,1017 tokenId: number,1018 sender: IKeyringPair,1019 recipient: IKeyringPair | CrossAccountId,1020 value: number | bigint = 1,1021) {1022 await usingApi(async (api: ApiPromise) => {1023 const transferTx = api.tx.unique.transfer(normalizeAccountId(recipient), collectionId, tokenId, value);1024 const events = await expect(submitTransactionExpectFailAsync(sender, transferTx)).to.be.rejected;1025 const result = getGenericResult(events);1026 // if (events && Array.isArray(events)) {1027 // const result = getCreateCollectionResult(events);1028 // tslint:disable-next-line:no-unused-expression1029 expect(result.success).to.be.false;1030 //}1031 });1032}10331034export async function1035approveExpectFail(1036 collectionId: number,1037 tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number | bigint = 1,1038) {1039 await usingApi(async (api: ApiPromise) => {1040 const approveUniqueTx = api.tx.unique.approve(normalizeAccountId(approved.address), collectionId, tokenId, amount);1041 const events = await expect(submitTransactionExpectFailAsync(owner, approveUniqueTx)).to.be.rejected;1042 const result = getCreateCollectionResult(events);1043 // tslint:disable-next-line:no-unused-expression1044 expect(result.success).to.be.false;1045 });1046}10471048export async function getBalance(1049 api: ApiPromise,1050 collectionId: number,1051 owner: string | CrossAccountId,1052 token: number,1053): Promise<bigint> {1054 return (await api.rpc.unique.balance(collectionId, normalizeAccountId(owner), token)).toBigInt();1055}1056export async function getTokenOwner(1057 api: ApiPromise,1058 collectionId: number,1059 token: number,1060): Promise<CrossAccountId> {1061 const owner = (await api.rpc.unique.tokenOwner(collectionId, token)).toJSON() as any;1062 if (owner == null) throw new Error('owner == null');1063 return normalizeAccountId(owner);1064}1065export async function getTopmostTokenOwner(1066 api: ApiPromise,1067 collectionId: number,1068 token: number,1069): Promise<CrossAccountId> {1070 const owner = (await api.rpc.unique.topmostTokenOwner(collectionId, token)).toJSON() as any;1071 if (owner == null) throw new Error('owner == null');1072 return normalizeAccountId(owner);1073}1074export async function isTokenExists(1075 api: ApiPromise,1076 collectionId: number,1077 token: number,1078): Promise<boolean> {1079 return (await api.rpc.unique.tokenExists(collectionId, token)).toJSON();1080}1081export async function getLastTokenId(1082 api: ApiPromise,1083 collectionId: number,1084): Promise<number> {1085 return (await api.rpc.unique.lastTokenId(collectionId)).toJSON();1086}1087export async function getAdminList(1088 api: ApiPromise,1089 collectionId: number,1090): Promise<string[]> {1091 return (await api.rpc.unique.adminlist(collectionId)).toHuman() as any;1092}1093export async function getTokenProperties(1094 api: ApiPromise,1095 collectionId: number,1096 tokenId: number,1097 propertyKeys: string[],1098): Promise<UpDataStructsProperty[]> {1099 return (await api.rpc.unique.tokenProperties(collectionId, tokenId, propertyKeys)).toHuman() as any;1100}11011102export async function createFungibleItemExpectSuccess(1103 sender: IKeyringPair,1104 collectionId: number,1105 data: CreateFungibleData,1106 owner: CrossAccountId | string = sender.address,1107) {1108 return await usingApi(async (api) => {1109 const tx = api.tx.unique.createItem(collectionId, normalizeAccountId(owner), {Fungible: data});11101111 const events = await submitTransactionAsync(sender, tx);1112 const result = getCreateItemResult(events);11131114 expect(result.success).to.be.true;1115 return result.itemId;1116 });1117}11181119export async function createMultipleItemsWithPropsExpectSuccess(sender: IKeyringPair, collectionId: number, itemsData: any, owner: CrossAccountId | string = sender.address) {1120 await usingApi(async (api) => {1121 const to = normalizeAccountId(owner);1122 const tx = api.tx.unique.createMultipleItems(collectionId, to, itemsData);11231124 const events = await submitTransactionAsync(sender, tx);1125 const result = getCreateItemsResult(events);11261127 for (const res of result) {1128 expect(await api.rpc.unique.tokenProperties(collectionId, res.itemId)).not.to.be.empty;1129 }1130 });1131}11321133export async function createMultipleItemsExWithPropsExpectSuccess(sender: IKeyringPair, collectionId: number, itemsData: any) {1134 await usingApi(async (api) => {1135 const tx = api.tx.unique.createMultipleItemsEx(collectionId, itemsData);11361137 const events = await submitTransactionAsync(sender, tx);1138 const result = getCreateItemsResult(events);11391140 for (const res of result) {1141 expect(await api.rpc.unique.tokenProperties(collectionId, res.itemId)).not.to.be.empty;1142 }1143 });1144}11451146export async function createItemWithPropsExpectSuccess(sender: IKeyringPair, collectionId: number, createMode: string, props: Array<Property>, owner: CrossAccountId | string = sender.address) {1147 let newItemId = 0;1148 await usingApi(async (api) => {1149 const to = normalizeAccountId(owner);1150 const itemCountBefore = await getLastTokenId(api, collectionId);1151 const itemBalanceBefore = await getBalance(api, collectionId, to, newItemId);11521153 let tx;1154 if (createMode === 'Fungible') {1155 const createData = {fungible: {value: 10}};1156 tx = api.tx.unique.createItem(collectionId, to, createData as any);1157 } else if (createMode === 'ReFungible') {1158 const createData = {refungible: {pieces: 100}};1159 tx = api.tx.unique.createItem(collectionId, to, createData as any);1160 } else {1161 const data = api.createType('UpDataStructsCreateItemData', {NFT: {properties: props}});1162 tx = api.tx.unique.createItem(collectionId, to, data as UpDataStructsCreateItemData);1163 }11641165 const events = await submitTransactionAsync(sender, tx);1166 const result = getCreateItemResult(events);11671168 const itemCountAfter = await getLastTokenId(api, collectionId);1169 const itemBalanceAfter = await getBalance(api, collectionId, to, newItemId);11701171 if (createMode === 'NFT') {1172 expect(await api.rpc.unique.tokenProperties(collectionId, result.itemId)).not.to.be.empty;1173 }11741175 // What to expect1176 // tslint:disable-next-line:no-unused-expression1177 expect(result.success).to.be.true;1178 if (createMode === 'Fungible') {1179 expect(itemBalanceAfter - itemBalanceBefore).to.be.equal(10n);1180 } else {1181 expect(itemCountAfter).to.be.equal(itemCountBefore + 1);1182 }1183 expect(collectionId).to.be.equal(result.collectionId);1184 expect(itemCountAfter.toString()).to.be.equal(result.itemId.toString());1185 expect(to).to.be.deep.equal(result.recipient);1186 newItemId = result.itemId;1187 });1188 return newItemId;1189}11901191export async function createItemWithPropsExpectFailure(sender: IKeyringPair, collectionId: number, createMode: string, props: Array<Property>, owner: CrossAccountId | string = sender.address) {1192 await usingApi(async (api) => {11931194 let tx;1195 if (createMode === 'NFT') {1196 const data = api.createType('UpDataStructsCreateItemData', {NFT: {properties: props}});1197 tx = api.tx.unique.createItem(collectionId, normalizeAccountId(owner), data);1198 } else {1199 tx = api.tx.unique.createItem(collectionId, normalizeAccountId(owner), createMode);1200 }120112021203 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1204 if(events.message && events.message.toString().indexOf('1002: Verification Error') > -1) return;1205 const result = getCreateItemResult(events);12061207 expect(result.success).to.be.false;1208 });1209}12101211export async function createItemExpectSuccess(sender: IKeyringPair, collectionId: number, createMode: string, owner: CrossAccountId | string = sender.address) {1212 let newItemId = 0;1213 await usingApi(async (api) => {1214 const to = normalizeAccountId(owner);1215 const itemCountBefore = await getLastTokenId(api, collectionId);1216 const itemBalanceBefore = await getBalance(api, collectionId, to, newItemId);12171218 let tx;1219 if (createMode === 'Fungible') {1220 const createData = {fungible: {value: 10}};1221 tx = api.tx.unique.createItem(collectionId, to, createData as any);1222 } else if (createMode === 'ReFungible') {1223 const createData = {refungible: {pieces: 100}};1224 tx = api.tx.unique.createItem(collectionId, to, createData as any);1225 } else {1226 const createData = {nft: {}};1227 tx = api.tx.unique.createItem(collectionId, to, createData as any);1228 }12291230 const events = await submitTransactionAsync(sender, tx);1231 const result = getCreateItemResult(events);12321233 const itemCountAfter = await getLastTokenId(api, collectionId);1234 const itemBalanceAfter = await getBalance(api, collectionId, to, newItemId);12351236 // What to expect1237 // tslint:disable-next-line:no-unused-expression1238 expect(result.success).to.be.true;1239 if (createMode === 'Fungible') {1240 expect(itemBalanceAfter - itemBalanceBefore).to.be.equal(10n);1241 } else {1242 expect(itemCountAfter).to.be.equal(itemCountBefore + 1);1243 }1244 expect(collectionId).to.be.equal(result.collectionId);1245 expect(itemCountAfter.toString()).to.be.equal(result.itemId.toString());1246 expect(to).to.be.deep.equal(result.recipient);1247 newItemId = result.itemId;1248 });1249 return newItemId;1250}12511252export async function createItemExpectFailure(sender: IKeyringPair, collectionId: number, createMode: string, owner: CrossAccountId | string = sender.address) {1253 await usingApi(async (api) => {1254 const tx = api.tx.unique.createItem(collectionId, normalizeAccountId(owner), createMode);12551256 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1257 const result = getCreateItemResult(events);12581259 expect(result.success).to.be.false;1260 });1261}12621263export async function setPublicAccessModeExpectSuccess(1264 sender: IKeyringPair, collectionId: number,1265 accessMode: 'Normal' | 'AllowList',1266) {1267 await usingApi(async (api) => {12681269 // Run the transaction1270 const tx = api.tx.unique.setCollectionPermissions(collectionId, {access: accessMode});1271 const events = await submitTransactionAsync(sender, tx);1272 const result = getGenericResult(events);12731274 // Get the collection1275 const collection = await queryCollectionExpectSuccess(api, collectionId);12761277 // What to expect1278 // tslint:disable-next-line:no-unused-expression1279 expect(result.success).to.be.true;1280 expect(collection.permissions.access.toHuman()).to.be.equal(accessMode);1281 });1282}12831284export async function setPublicAccessModeExpectFail(1285 sender: IKeyringPair, collectionId: number,1286 accessMode: 'Normal' | 'AllowList',1287) {1288 await usingApi(async (api) => {12891290 // Run the transaction1291 const tx = api.tx.unique.setCollectionPermissions(collectionId, {access: accessMode});1292 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1293 const result = getGenericResult(events);12941295 // What to expect1296 // tslint:disable-next-line:no-unused-expression1297 expect(result.success).to.be.false;1298 });1299}13001301export async function enableAllowListExpectSuccess(sender: IKeyringPair, collectionId: number) {1302 await setPublicAccessModeExpectSuccess(sender, collectionId, 'AllowList');1303}13041305export async function enableAllowListExpectFail(sender: IKeyringPair, collectionId: number) {1306 await setPublicAccessModeExpectFail(sender, collectionId, 'AllowList');1307}13081309export async function disableAllowListExpectSuccess(sender: IKeyringPair, collectionId: number) {1310 await setPublicAccessModeExpectSuccess(sender, collectionId, 'Normal');1311}13121313export async function setMintPermissionExpectSuccess(sender: IKeyringPair, collectionId: number, enabled: boolean) {1314 await usingApi(async (api) => {13151316 // Run the transaction1317 const tx = api.tx.unique.setCollectionPermissions(collectionId, {mintMode: enabled});1318 const events = await submitTransactionAsync(sender, tx);1319 const result = getGenericResult(events);1320 expect(result.success).to.be.true;13211322 // Get the collection1323 const collection = await queryCollectionExpectSuccess(api, collectionId);13241325 expect(collection.permissions.mintMode.toHuman()).to.be.equal(enabled);1326 });1327}13281329export async function enablePublicMintingExpectSuccess(sender: IKeyringPair, collectionId: number) {1330 await setMintPermissionExpectSuccess(sender, collectionId, true);1331}13321333export async function setMintPermissionExpectFailure(sender: IKeyringPair, collectionId: number, enabled: boolean) {1334 await usingApi(async (api) => {1335 // Run the transaction1336 const tx = api.tx.unique.setCollectionPermissions(collectionId, {mintMode: enabled});1337 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1338 const result = getCreateCollectionResult(events);1339 // tslint:disable-next-line:no-unused-expression1340 expect(result.success).to.be.false;1341 });1342}13431344export async function setChainLimitsExpectFailure(sender: IKeyringPair, limits: IChainLimits) {1345 await usingApi(async (api) => {1346 // Run the transaction1347 const tx = api.tx.unique.setChainLimits(limits);1348 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1349 const result = getCreateCollectionResult(events);1350 // tslint:disable-next-line:no-unused-expression1351 expect(result.success).to.be.false;1352 });1353}13541355export async function isAllowlisted(api: ApiPromise, collectionId: number, address: string | CrossAccountId) {1356 return (await api.rpc.unique.allowed(collectionId, normalizeAccountId(address))).toJSON();1357}13581359export async function addToAllowListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | AccountId | CrossAccountId) {1360 await usingApi(async (api) => {1361 expect(await isAllowlisted(api, collectionId, normalizeAccountId(address))).to.be.false;13621363 // Run the transaction1364 const tx = api.tx.unique.addToAllowList(collectionId, normalizeAccountId(address));1365 const events = await submitTransactionAsync(sender, tx);1366 const result = getGenericResult(events);1367 expect(result.success).to.be.true;13681369 expect(await isAllowlisted(api, collectionId, normalizeAccountId(address))).to.be.true;1370 });1371}13721373export async function addToAllowListAgainExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | AccountId) {1374 await usingApi(async (api) => {13751376 expect(await isAllowlisted(api, collectionId, normalizeAccountId(address))).to.be.true;13771378 // Run the transaction1379 const tx = api.tx.unique.addToAllowList(collectionId, normalizeAccountId(address));1380 const events = await submitTransactionAsync(sender, tx);1381 const result = getGenericResult(events);1382 expect(result.success).to.be.true;13831384 expect(await isAllowlisted(api, collectionId, normalizeAccountId(address))).to.be.true;1385 });1386}13871388export async function addToAllowListExpectFail(sender: IKeyringPair, collectionId: number, address: string | AccountId) {1389 await usingApi(async (api) => {13901391 // Run the transaction1392 const tx = api.tx.unique.addToAllowList(collectionId, normalizeAccountId(address));1393 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1394 const result = getGenericResult(events);13951396 // What to expect1397 // tslint:disable-next-line:no-unused-expression1398 expect(result.success).to.be.false;1399 });1400}14011402export async function removeFromAllowListExpectSuccess(sender: IKeyringPair, collectionId: number, address: CrossAccountId) {1403 await usingApi(async (api) => {1404 // Run the transaction1405 const tx = api.tx.unique.removeFromAllowList(collectionId, normalizeAccountId(address));1406 const events = await submitTransactionAsync(sender, tx);1407 const result = getGenericResult(events);14081409 // What to expect1410 // tslint:disable-next-line:no-unused-expression1411 expect(result.success).to.be.true;1412 });1413}14141415export async function removeFromAllowListExpectFailure(sender: IKeyringPair, collectionId: number, address: CrossAccountId) {1416 await usingApi(async (api) => {1417 // Run the transaction1418 const tx = api.tx.unique.removeFromAllowList(collectionId, normalizeAccountId(address));1419 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;1420 const result = getGenericResult(events);14211422 // What to expect1423 // tslint:disable-next-line:no-unused-expression1424 expect(result.success).to.be.false;1425 });1426}14271428export const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)1429 : Promise<UpDataStructsRpcCollection | null> => {1430 return (await api.rpc.unique.collectionById(collectionId)).unwrapOr(null);1431};14321433export const getCreatedCollectionCount = async (api: ApiPromise): Promise<number> => {1434 // set global object - collectionsCount1435 return (await api.rpc.unique.collectionStats()).created.toNumber();1436};14371438export async function queryCollectionExpectSuccess(api: ApiPromise, collectionId: number): Promise<UpDataStructsRpcCollection> {1439 return (await api.rpc.unique.collectionById(collectionId)).unwrap();1440}14411442export async function waitNewBlocks(blocksCount = 1): Promise<void> {1443 await usingApi(async (api) => {1444 const promise = new Promise<void>(async (resolve) => {1445 const unsubscribe = await api.rpc.chain.subscribeNewHeads(() => {1446 if (blocksCount > 0) {1447 blocksCount--;1448 } else {1449 unsubscribe();1450 resolve();1451 }1452 });1453 });1454 return promise;1455 });1456}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 = {