--- a/tests/package.json
+++ b/tests/package.json
@@ -5,11 +5,11 @@
"main": "",
"devDependencies": {
"@polkadot/ts": "0.4.22",
- "@polkadot/typegen": "9.2.2",
+ "@polkadot/typegen": "9.5.1",
"@types/chai": "^4.3.1",
"@types/chai-as-promised": "^7.1.5",
"@types/chai-like": "^1.1.1",
- "@types/mocha": "^9.1.1",
+ "@types/mocha": "^10.0.0",
"@types/node": "^17.0.35",
"@typescript-eslint/eslint-plugin": "^5.26.0",
"@typescript-eslint/parser": "^5.26.0",
@@ -21,34 +21,37 @@
},
"mocha": {
"timeout": 9999999,
- "require": "ts-node/register"
+ "require": ["ts-node/register"]
},
"scripts": {
"lint": "eslint --ext .ts,.js src/",
"fix": "eslint --ext .ts,.js src/ --fix",
- "test": "mocha --timeout 9999999 -r ts-node/register './src/**/*.test.ts'",
- "testEth": "mocha --timeout 9999999 -r ts-node/register './**/eth/**/*.test.ts'",
- "testEthMarketplace": "mocha --timeout 9999999 -r ts-node/register './**/eth/marketplace/**/*.test.ts'",
- "testEthNesting": "mocha --timeout 9999999 -r ts-node/register './**/eth/nesting/**/*.test.ts'",
- "testEthFractionalizer": "mocha --timeout 9999999 -r ts-node/register './**/eth/fractionalizer/**/*.test.ts'",
+ "setup": "ts-node ./src/util/globalSetup.ts",
+
+ "test": "yarn setup && mocha --timeout 9999999 -r ts-node/register './src/**/*.*test.ts'",
+ "testParallelFull": "yarn testParallel && yarn testSequential",
+ "testParallel": "yarn setup && mocha --parallel --timeout 9999999 -r ts-node/register './src/**/*.test.ts'",
+ "testSequential": "yarn setup && mocha --timeout 9999999 -r ts-node/register './src/**/*.seqtest.ts'",
+ "testStructure": "yarn setup && mocha --timeout 9999999 -r ts-node/register ./**/nesting/*.*test.ts",
+ "testEth": "yarn setup && mocha --timeout 9999999 -r ts-node/register './**/eth/**/*.*test.ts'",
+ "testEthNesting": "yarn setup && mocha --timeout 9999999 -r ts-node/register './**/eth/nesting/**/*.*test.ts'",
+ "testEthFractionalizer": "yarn setup && mocha --timeout 9999999 -r ts-node/register './**/eth/fractionalizer/**/*.*test.ts'",
+ "testEthMarketplace": "yarn setup && mocha --timeout 9999999 -r ts-node/register './**/eth/marketplace/**/*.*test.ts'",
+ "testEvent": "yarn setup && mocha --timeout 9999999 -r ts-node/register ./src/check-event/*.*test.ts",
+ "testRmrk": "yarn setup && mocha --timeout 9999999 -r ts-node/register ./**/rmrk/*.*test.ts",
+
"testEthPayable": "mocha --timeout 9999999 -r ts-node/register './**/eth/payable.test.ts'",
+ "testEthTokenProperties": "mocha --timeout 9999999 -r ts-node/register ./**/eth/tokenProperties.test.ts",
"testEvmCoder": "mocha --timeout 9999999 -r ts-node/register './**/eth/evmCoder.test.ts'",
- "load": "mocha --timeout 9999999 -r ts-node/register './**/*.load.ts'",
- "loadTransfer": "ts-node src/transfer.nload.ts",
- "testCollision": "mocha --timeout 9999999 -r ts-node/register ./src/collision-tests/*.test.ts",
- "testEvent": "mocha --timeout 9999999 -r ts-node/register ./src/check-event/*.test.ts",
"testNesting": "mocha --timeout 9999999 -r ts-node/register ./**/nest.test.ts",
"testUnnesting": "mocha --timeout 9999999 -r ts-node/register ./**/unnest.test.ts",
- "testStructure": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/**.test.ts",
"testProperties": "mocha --timeout 9999999 -r ts-node/register ./**/properties.test.ts ./**/getPropertiesRpc.test.ts",
"testMigration": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/migration-check.test.ts",
- "testRmrk": "mocha --timeout 9999999 -r ts-node/register ./**/rmrk/**.test.ts",
"testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",
- "testSetSchemaVersion": "mocha --timeout 9999999 -r ts-node/register ./**/setSchemaVersion.test.ts",
"testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",
"testChangeCollectionOwner": "mocha --timeout 9999999 -r ts-node/register ./**/change-collection-owner.test.ts",
"testSetCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionSponsor.test.ts",
- "testConfirmSponsorship": "mocha --timeout 9999999 -r ts-node/register ./**/confirmSponsorship.test.ts",
+ "testConfirmSponsorship": "mocha --timeout 9999999 --parallel -r ts-node/register ./**/confirmSponsorship.test.ts",
"testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",
"testRemoveCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionSponsor.test.ts",
"testAllowLists": "mocha --timeout 9999999 -r ts-node/register ./**/allowLists.test.ts",
@@ -78,12 +81,6 @@
"testInflation": "mocha --timeout 9999999 -r ts-node/register ./**/inflation.test.ts",
"testScheduler": "mocha --timeout 9999999 -r ts-node/register ./**/scheduler.test.ts",
"testSchedulingEVM": "mocha --timeout 9999999 -r ts-node/register ./**/eth/scheduling.test.ts",
- "testXcmUnique": "RUN_XCM_TESTS=1 mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmUnique.test.ts",
- "testXcmQuartz": "RUN_XCM_TESTS=1 mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmQuartz.test.ts",
- "testXcmOpal": "RUN_XCM_TESTS=1 mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmOpal.test.ts",
- "testXcmTransferAcala": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferAcala.test.ts acalaId=2000 uniqueId=5000",
- "testXcmTransferStatemine": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferStatemine.test.ts statemineId=1000 uniqueId=5000",
- "testXcmTransferMoonbeam": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferMoonbeam.test.ts",
"testPalletPresence": "mocha --timeout 9999999 -r ts-node/register ./**/pallet-presence.test.ts",
"testBlockProduction": "mocha --timeout 9999999 -r ts-node/register ./**/block-production.test.ts",
"testEnableDisableTransfers": "mocha --timeout 9999999 -r ts-node/register ./**/enableDisableTransfer.test.ts",
@@ -96,7 +93,18 @@
"testFT": "mocha --timeout 9999999 -r ts-node/register ./**/fungible.test.ts",
"testEthFT": "mocha --timeout 9999999 -r ts-node/register ./**/eth/fungible.test.ts",
"testRPC": "mocha --timeout 9999999 -r ts-node/register ./**/rpc.test.ts",
- "testPromotion": "mocha --timeout 9999999 -r ts-node/register ./**/app-promotion.test.ts",
+ "testPromotion": "yarn setup && mocha --timeout 9999999 -r ts-node/register ./**/app-promotion.test.ts",
+
+ "testXcmUnique": "RUN_XCM_TESTS=1 mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmUnique.test.ts",
+ "testXcmQuartz": "RUN_XCM_TESTS=1 mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmQuartz.test.ts",
+ "testXcmOpal": "RUN_XCM_TESTS=1 mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmOpal.test.ts",
+ "testXcmTransferAcala": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferAcala.test.ts acalaId=2000 uniqueId=5000",
+ "testXcmTransferStatemine": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferStatemine.test.ts statemineId=1000 uniqueId=5000",
+ "testXcmTransferMoonbeam": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferMoonbeam.test.ts",
+
+ "load": "mocha --timeout 9999999 -r ts-node/register './**/*.load.ts'",
+ "loadTransfer": "ts-node src/transfer.nload.ts",
+
"polkadot-types-fetch-metadata": "curl -H 'Content-Type: application/json' -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' http://localhost:9933 > src/interfaces/metadata.json",
"polkadot-types-from-defs": "ts-node ./node_modules/.bin/polkadot-types-from-defs --endpoint src/interfaces/metadata.json --input src/interfaces/ --package .",
"polkadot-types-from-chain": "ts-node ./node_modules/.bin/polkadot-types-from-chain --endpoint src/interfaces/metadata.json --output src/interfaces/ --package .",
@@ -106,14 +114,14 @@
"license": "SEE LICENSE IN ../LICENSE",
"homepage": "",
"dependencies": {
- "@polkadot/api": "9.2.2",
- "@polkadot/api-contract": "9.2.2",
- "@polkadot/util-crypto": "10.1.7",
- "bignumber.js": "^9.0.2",
+ "@polkadot/api": "9.5.1",
+ "@polkadot/api-contract": "9.5.1",
+ "@polkadot/util-crypto": "10.1.10",
+ "bignumber.js": "^9.1.0",
"chai-as-promised": "^7.1.1",
"chai-like": "^1.1.1",
"find-process": "^1.4.7",
- "solc": "0.8.14-fixed",
+ "solc": "0.8.17",
"web3": "^1.7.3"
},
"standard": {
--- a/tests/src/addCollectionAdmin.test.ts
+++ b/tests/src/addCollectionAdmin.test.ts
@@ -15,14 +15,14 @@
// along with Unique Network. If not, see .
import {IKeyringPair} from '@polkadot/types/types';
-import {itSub, usingPlaygrounds, expect} from './util/playgrounds';
+import {itSub, usingPlaygrounds, expect} from './util';
describe('Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {
let donor: IKeyringPair;
before(async () => {
- await usingPlaygrounds(async (_, privateKeyWrapper) => {
- donor = privateKeyWrapper('//Alice');
+ await usingPlaygrounds(async (_, privateKey) => {
+ donor = await privateKey({filename: __filename});
});
});
@@ -44,8 +44,8 @@
let donor: IKeyringPair;
before(async () => {
- await usingPlaygrounds(async (_, privateKeyWrapper) => {
- donor = privateKeyWrapper('//Alice');
+ await usingPlaygrounds(async (_, privateKey) => {
+ donor = await privateKey({filename: __filename});
});
});
--- a/tests/src/adminTransferAndBurn.test.ts
+++ b/tests/src/adminTransferAndBurn.test.ts
@@ -15,7 +15,7 @@
// along with Unique Network. If not, see .
import {IKeyringPair} from '@polkadot/types/types';
-import {usingPlaygrounds, expect, itSub} from './util/playgrounds';
+import {usingPlaygrounds, expect, itSub} from './util';
describe('Integration Test: ownerCanTransfer allows admins to use only transferFrom/burnFrom:', () => {
let alice: IKeyringPair;
@@ -24,7 +24,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);
});
});
--- a/tests/src/allowLists.test.ts
+++ b/tests/src/allowLists.test.ts
@@ -15,7 +15,7 @@
// along with Unique Network. If not, see .
import {IKeyringPair} from '@polkadot/types/types';
-import {usingPlaygrounds, expect, itSub} from './util/playgrounds';
+import {usingPlaygrounds, expect, itSub} from './util';
import {ICollectionPermissions} from './util/playgrounds/types';
describe('Integration Test ext. Allow list tests', () => {
@@ -25,7 +25,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob, charlie] = await helper.arrange.createAccounts([30n, 10n, 10n], donor);
});
});
@@ -87,7 +87,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob, charlie] = await helper.arrange.createAccounts([30n, 10n, 10n], donor);
});
});
@@ -163,7 +163,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob, charlie] = await helper.arrange.createAccounts([30n, 10n, 10n], donor);
});
});
@@ -291,7 +291,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);
});
});
--- /dev/null
+++ b/tests/src/app-promotion.seqtest.ts
@@ -0,0 +1,82 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see .
+
+import {IKeyringPair} from '@polkadot/types/types';
+import {itSub, usingPlaygrounds, Pallets, requirePalletsOrSkip} from './util';
+import {expect} from './eth/util';
+
+let superuser: IKeyringPair;
+let donor: IKeyringPair;
+let palletAdmin: IKeyringPair;
+
+describe('App promotion', () => {
+ before(async function () {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.AppPromotion]);
+ superuser = await privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
+ palletAdmin = await privateKey('//PromotionAdmin');
+ const api = helper.getApi();
+ await helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})));
+ });
+ });
+
+ after(async function () {
+ await usingPlaygrounds(async (helper) => {
+ if (helper.fetchMissingPalletNames([Pallets.AppPromotion]).length != 0) return;
+ const api = helper.getApi();
+ await helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})));
+ });
+ });
+
+ describe('admin adress', () => {
+ itSub('can be set by sudo only', async ({helper}) => {
+ const api = helper.getApi();
+ const [nonAdmin] = await helper.arrange.createAccounts([10n], donor);
+ // nonAdmin can not set admin not from himself nor as a sudo
+ await expect(helper.signTransaction(nonAdmin, api.tx.appPromotion.setAdminAddress({Substrate: nonAdmin.address}))).to.be.rejected;
+ await expect(helper.signTransaction(nonAdmin, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: nonAdmin.address})))).to.be.rejected;
+ });
+
+ itSub('can be any valid CrossAccountId', async ({helper}) => {
+ // We are not going to set an eth address as a sponsor,
+ // but we do want to check, it doesn't break anything;
+ const api = helper.getApi();
+ const [account] = await helper.arrange.createAccounts([10n], donor);
+ const ethAccount = helper.address.substrateToEth(account.address);
+ // Alice sets Ethereum address as a sudo. Then Substrate address back...
+ await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Ethereum: ethAccount})))).to.be.fulfilled;
+ await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})))).to.be.fulfilled;
+
+ // ...It doesn't break anything;
+ const collection = await helper.nft.mintCollection(account, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'});
+ await expect(helper.signTransaction(account, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.rejected;
+ });
+
+ itSub('can be reassigned', async ({helper}) => {
+ const api = helper.getApi();
+ const [oldAdmin, newAdmin, collectionOwner] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);
+ const collection = await helper.nft.mintCollection(collectionOwner, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'});
+
+ await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: oldAdmin.address})))).to.be.fulfilled;
+ await expect(helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: newAdmin.address})))).to.be.fulfilled;
+ await expect(helper.signTransaction(oldAdmin, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.rejected;
+
+ await expect(helper.signTransaction(newAdmin, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.fulfilled;
+ });
+ });
+});
+
--- a/tests/src/app-promotion.test.ts
+++ b/tests/src/app-promotion.test.ts
@@ -15,17 +15,15 @@
// along with Unique Network. If not, see .
import {IKeyringPair} from '@polkadot/types/types';
-import {itSub, usingPlaygrounds, Pallets, requirePalletsOrSkip} from './util/playgrounds';
-import {encodeAddress} from '@polkadot/util-crypto';
-import {stringToU8a} from '@polkadot/util';
+import {itSub, usingPlaygrounds, Pallets, requirePalletsOrSkip} from './util';
import {DevUniqueHelper} from './util/playgrounds/unique.dev';
-import {itEth, expect, SponsoringMode} from './eth/util/playgrounds';
+import {itEth, expect, SponsoringMode} from './eth/util';
-let alice: IKeyringPair;
+let donor: IKeyringPair;
let palletAdmin: IKeyringPair;
let nominal: bigint;
-const palletAddress = calculatePalleteAddress('appstake');
-let accounts: IKeyringPair[] = [];
+let palletAddress: string;
+let accounts: IKeyringPair[];
const LOCKING_PERIOD = 20n; // 20 blocks of relay
const UNLOCKING_PERIOD = 10n; // 10 blocks of parachain
const rewardAvailableInBlock = (stakedInBlock: bigint) => {
@@ -37,14 +35,11 @@
before(async function () {
await usingPlaygrounds(async (helper, privateKey) => {
requirePalletsOrSkip(this, helper, [Pallets.AppPromotion]);
- alice = privateKey('//Alice');
- palletAdmin = privateKey('//Charlie'); // TODO use custom address
- const api = helper.getApi();
- await helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})));
+ donor = await privateKey({filename: __filename});
+ palletAddress = helper.arrange.calculatePalletAddress('appstake');
+ palletAdmin = await privateKey('//PromotionAdmin');
nominal = helper.balance.getOneTokenNominal();
- await helper.balance.transferToSubstrate(alice, palletAdmin.address, 1000n * nominal);
- await helper.balance.transferToSubstrate(alice, palletAddress, 1000n * nominal);
- accounts = await helper.arrange.createCrowd(100, 1000n, alice); // create accounts-pool to speed up tests
+ accounts = await helper.arrange.createCrowd(100, 1000n, donor); // create accounts-pool to speed up tests
});
});
@@ -76,7 +71,7 @@
});
itSub('should allow to create maximum 10 stakes for account', async ({helper}) => {
- const [staker] = await helper.arrange.createAccounts([2000n], alice);
+ const [staker] = await helper.arrange.createAccounts([2000n], donor);
for (let i = 0; i < 10; i++) {
await helper.staking.stake(staker, 100n * nominal);
}
@@ -144,7 +139,7 @@
expect(await helper.balance.getSubstrate(staker.address) / nominal).to.be.equal(999n);
// staker can transfer:
- await helper.balance.transferToSubstrate(staker, alice.address, 998n * nominal);
+ await helper.balance.transferToSubstrate(staker, donor.address, 998n * nominal);
expect(await helper.balance.getSubstrate(staker.address) / nominal).to.be.equal(1n);
});
@@ -224,55 +219,7 @@
});
});
- describe('admin adress', () => {
- itSub('can be set by sudo only', async ({helper}) => {
- const api = helper.getApi();
- const nonAdmin = accounts.pop()!;
- // nonAdmin can not set admin not from himself nor as a sudo
- await expect(helper.signTransaction(nonAdmin, api.tx.appPromotion.setAdminAddress({Substrate: nonAdmin.address}))).to.be.rejected;
- await expect(helper.signTransaction(nonAdmin, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: nonAdmin.address})))).to.be.rejected;
-
- // Alice can
- await expect(helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})))).to.be.fulfilled;
- });
-
- itSub('can be any valid CrossAccountId', async ({helper}) => {
- // We are not going to set an eth address as a sponsor,
- // but we do want to check, it doesn't break anything;
- const api = helper.getApi();
- const account = accounts.pop()!;
- const ethAccount = helper.address.substrateToEth(account.address);
- // Alice sets Ethereum address as a sudo. Then Substrate address back...
- await expect(helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Ethereum: ethAccount})))).to.be.fulfilled;
- await expect(helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})))).to.be.fulfilled;
-
- // ...It doesn't break anything;
- const collection = await helper.nft.mintCollection(account, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'});
- await expect(helper.signTransaction(account, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.rejected;
- });
-
- itSub('can be reassigned', async ({helper}) => {
- const api = helper.getApi();
- const [oldAdmin, newAdmin, collectionOwner] = [accounts.pop()!, accounts.pop()!, accounts.pop()!];
- const collection = await helper.nft.mintCollection(collectionOwner, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion'});
-
- await expect(helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: oldAdmin.address})))).to.be.fulfilled;
- await expect(helper.signTransaction(alice, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: newAdmin.address})))).to.be.fulfilled;
- await expect(helper.signTransaction(oldAdmin, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.rejected;
-
- await expect(helper.signTransaction(newAdmin, api.tx.appPromotion.sponsorCollection(collection.collectionId))).to.be.fulfilled;
- });
- });
-
describe('collection sponsoring', () => {
- before(async function () {
- await usingPlaygrounds(async (helper) => {
- const api = helper.getApi();
- const tx = api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address}));
- await helper.signTransaction(alice, tx);
- });
- });
-
itSub('should actually sponsor transactions', async ({helper}) => {
const api = helper.getApi();
const [collectionOwner, tokenSender, receiver] = [accounts.pop()!, accounts.pop()!, accounts.pop()!];
@@ -343,7 +290,7 @@
itSub('should not overwrite collection limits set by the owner earlier', async ({helper}) => {
const api = helper.getApi();
const limits = {ownerCanDestroy: true, ownerCanTransfer: true, sponsorTransferTimeout: 0};
- const collectionWithLimits = await helper.nft.mintCollection(alice, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion', limits});
+ const collectionWithLimits = await helper.nft.mintCollection(accounts.pop()!, {name: 'New', description: 'New Collection', tokenPrefix: 'Promotion', limits});
await expect(helper.signTransaction(palletAdmin, api.tx.appPromotion.sponsorCollection(collectionWithLimits.collectionId))).to.be.fulfilled;
expect((await collectionWithLimits.getData())?.raw.limits).to.be.deep.contain(limits);
@@ -416,7 +363,7 @@
describe('contract sponsoring', () => {
itEth('should set palletes address as a sponsor', async ({helper}) => {
- const contractOwner = (await helper.eth.createAccountWithBalance(alice, 1000n)).toLowerCase();
+ const contractOwner = (await helper.eth.createAccountWithBalance(donor, 1000n)).toLowerCase();
const flipper = await helper.eth.deployFlipper(contractOwner); // await deployFlipper(web3, contractOwner);
const contractHelper = helper.ethNativeContract.contractHelpers(contractOwner);
@@ -432,7 +379,7 @@
});
itEth('should overwrite sponsoring mode and existed sponsor', async ({helper}) => {
- const contractOwner = (await helper.eth.createAccountWithBalance(alice, 1000n)).toLowerCase();
+ const contractOwner = (await helper.eth.createAccountWithBalance(donor, 1000n)).toLowerCase();
const flipper = await helper.eth.deployFlipper(contractOwner); // await deployFlipper(web3, contractOwner);
const contractHelper = helper.ethNativeContract.contractHelpers(contractOwner);
@@ -459,7 +406,7 @@
});
itEth('can be overwritten by contract owner', async ({helper}) => {
- const contractOwner = (await helper.eth.createAccountWithBalance(alice, 1000n)).toLowerCase();
+ const contractOwner = (await helper.eth.createAccountWithBalance(donor, 1000n)).toLowerCase();
const flipper = await helper.eth.deployFlipper(contractOwner); // await deployFlipper(web3, contractOwner);
const contractHelper = helper.ethNativeContract.contractHelpers(contractOwner);
@@ -480,7 +427,7 @@
itEth('can not be set by non admin', async ({helper}) => {
const nonAdmin = accounts.pop()!;
- const contractOwner = (await helper.eth.createAccountWithBalance(alice, 1000n)).toLowerCase();
+ const contractOwner = (await helper.eth.createAccountWithBalance(donor, 1000n)).toLowerCase();
const flipper = await helper.eth.deployFlipper(contractOwner); // await deployFlipper(web3, contractOwner);
const contractHelper = helper.ethNativeContract.contractHelpers(contractOwner);
@@ -499,18 +446,18 @@
itEth('should actually sponsor transactions', async ({helper}) => {
// Contract caller
- const caller = await helper.eth.createAccountWithBalance(alice, 1000n);
+ const caller = await helper.eth.createAccountWithBalance(donor, 1000n);
const palletBalanceBefore = await helper.balance.getSubstrate(palletAddress);
// Deploy flipper
- const contractOwner = (await helper.eth.createAccountWithBalance(alice, 1000n)).toLowerCase();
+ const contractOwner = (await helper.eth.createAccountWithBalance(donor, 1000n)).toLowerCase();
const flipper = await helper.eth.deployFlipper(contractOwner); // await deployFlipper(web3, contractOwner);
const contractHelper = helper.ethNativeContract.contractHelpers(contractOwner);
// Owner sets to sponsor every tx
await contractHelper.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: contractOwner});
await contractHelper.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Generous).send({from: contractOwner});
- await helper.eth.transferBalanceFromSubstrate(alice, flipper.options.address, 1000n); // transferBalanceToEth(api, alice, flipper.options.address, 1000n);
+ await helper.eth.transferBalanceFromSubstrate(donor, flipper.options.address, 1000n); // transferBalanceToEth(api, alice, flipper.options.address, 1000n);
// Set promotion to the Flipper
await helper.executeExtrinsic(palletAdmin, 'api.tx.appPromotion.sponsorContract', [flipper.options.address], true);
@@ -533,10 +480,10 @@
describe('stopSponsoringContract', () => {
itEth('should remove pallet address from contract sponsors', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(alice, 1000n);
- const contractOwner = (await helper.eth.createAccountWithBalance(alice, 1000n)).toLowerCase();
+ const caller = await helper.eth.createAccountWithBalance(donor, 1000n);
+ const contractOwner = (await helper.eth.createAccountWithBalance(donor, 1000n)).toLowerCase();
const flipper = await helper.eth.deployFlipper(contractOwner);
- await helper.eth.transferBalanceFromSubstrate(alice, flipper.options.address);
+ await helper.eth.transferBalanceFromSubstrate(donor, flipper.options.address);
const contractHelper = helper.ethNativeContract.contractHelpers(contractOwner);
await contractHelper.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Generous).send({from: contractOwner});
@@ -557,12 +504,12 @@
// caller payed for call
expect(1000n * nominal > callerBalance).to.be.true;
- expect(contractBalanceAfter).to.be.equal(1000n * nominal);
+ expect(contractBalanceAfter).to.be.equal(100n * nominal);
});
itEth('can not be called by non-admin', async ({helper}) => {
const nonAdmin = accounts.pop()!;
- const contractOwner = (await helper.eth.createAccountWithBalance(alice, 1000n)).toLowerCase();
+ const contractOwner = (await helper.eth.createAccountWithBalance(donor, 1000n)).toLowerCase();
const flipper = await helper.eth.deployFlipper(contractOwner);
await helper.executeExtrinsic(palletAdmin, 'api.tx.appPromotion.sponsorContract', [flipper.options.address]);
@@ -572,7 +519,7 @@
itEth('should not affect a contract which is not sponsored by pallete', async ({helper}) => {
const nonAdmin = accounts.pop()!;
- const contractOwner = (await helper.eth.createAccountWithBalance(alice, 1000n)).toLowerCase();
+ const contractOwner = (await helper.eth.createAccountWithBalance(donor, 1000n)).toLowerCase();
const flipper = await helper.eth.deployFlipper(contractOwner);
const contractHelper = helper.ethNativeContract.contractHelpers(contractOwner);
await expect(contractHelper.methods.selfSponsoredEnable(flipper.options.address).send()).to.be.fulfilled;
@@ -613,7 +560,7 @@
await helper.staking.stake(staker, 200n * nominal);
// wait rewards are available:
- const [_, stake2] = await helper.staking.getTotalStakedPerBlock({Substrate: staker.address});
+ const [_stake1, stake2] = await helper.staking.getTotalStakedPerBlock({Substrate: staker.address});
await helper.wait.forRelayBlockNumber(rewardAvailableInBlock(stake2.block));
const payoutToStaker = (await helper.admin.payoutStakers(palletAdmin, 100)).find((payout) => payout.staker === staker.address)?.payout;
@@ -678,7 +625,7 @@
itSub.skip('can be paid 1000 rewards in a time', async ({helper}) => {
// all other stakes should be unstaked
- const oneHundredStakers = await helper.arrange.createCrowd(100, 1050n, alice);
+ const oneHundredStakers = await helper.arrange.createCrowd(100, 1050n, donor);
// stakers stakes 10 times each
for (let i = 0; i < 10; i++) {
@@ -689,7 +636,6 @@
});
itSub.skip('can handle 40.000 rewards', async ({helper}) => {
- const [donor] = await helper.arrange.createAccounts([7_000_000n], alice);
const crowdStakes = async () => {
// each account in the crowd stakes 2 times
const crowd = await helper.arrange.createCrowd(500, 300n, donor);
@@ -706,11 +652,6 @@
});
});
});
-
-function calculatePalleteAddress(palletId: any) {
- const address = stringToU8a(('modl' + palletId).padEnd(32, '\0'));
- return encodeAddress(address);
-}
function calculateIncome(base: bigint, calcPeriod: bigint, iter = 0): bigint {
const DAY = 7200n;
--- a/tests/src/approve.test.ts
+++ b/tests/src/approve.test.ts
@@ -15,7 +15,7 @@
// along with Unique Network. If not, see .
import {IKeyringPair} from '@polkadot/types/types';
-import {expect, itSub, Pallets, usingPlaygrounds} from './util/playgrounds';
+import {expect, itSub, Pallets, usingPlaygrounds} from './util';
describe('Integration Test approve(spender, collection_id, item_id, amount):', () => {
@@ -25,7 +25,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
});
});
@@ -104,7 +104,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
});
});
@@ -141,7 +141,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
});
});
@@ -184,7 +184,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
});
});
@@ -227,7 +227,7 @@
});
});
-describe('Approved amount decreases by the transferred amount.:', () => {
+describe('Approved amount decreases by the transferred amount:', () => {
let alice: IKeyringPair;
let bob: IKeyringPair;
let charlie: IKeyringPair;
@@ -235,7 +235,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob, charlie, dave] = await helper.arrange.createAccounts([100n, 100n, 100n, 100n], donor);
});
});
@@ -265,7 +265,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
});
});
@@ -320,7 +320,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
});
});
@@ -357,7 +357,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob, charlie, dave] = await helper.arrange.createAccounts([100n, 100n, 100n, 100n], donor);
});
});
@@ -423,7 +423,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob, charlie, dave] = await helper.arrange.createAccounts([100n, 100n, 100n, 100n], donor);
});
});
@@ -474,7 +474,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
});
});
@@ -495,7 +495,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
});
});
--- a/tests/src/block-production.test.ts
+++ b/tests/src/block-production.test.ts
@@ -15,7 +15,7 @@
// along with Unique Network. If not, see .
import {ApiPromise} from '@polkadot/api';
-import {expect, itSub} from './util/playgrounds';
+import {expect, itSub} from './util';
const BLOCK_TIME_MS = 12000;
const TOLERANCE_MS = 3000;
--- a/tests/src/burnItem.test.ts
+++ b/tests/src/burnItem.test.ts
@@ -15,7 +15,7 @@
// along with Unique Network. If not, see .
import {IKeyringPair} from '@polkadot/types/types';
-import {expect, itSub, Pallets, usingPlaygrounds} from './util/playgrounds';
+import {expect, itSub, Pallets, usingPlaygrounds} from './util';
describe('integration test: ext. burnItem():', () => {
@@ -25,7 +25,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
[alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);
});
});
@@ -80,7 +80,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
[alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);
});
});
@@ -123,7 +123,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
[alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);
});
});
--- a/tests/src/calibrate.ts
+++ b/tests/src/calibrate.ts
@@ -1,6 +1,6 @@
import {IKeyringPair} from '@polkadot/types/types';
-import {usingEthPlaygrounds, EthUniqueHelper} from './eth/util/playgrounds';
+import {usingEthPlaygrounds, EthUniqueHelper} from './eth/util';
function linearRegression(points: { x: bigint, y: bigint }[]) {
@@ -56,9 +56,9 @@
}).reduce((a, b) => a + b, 0n) / BigInt(points.length));
}
-async function calibrateWeightToFee(helper: EthUniqueHelper, privateKey: (account: string) => IKeyringPair) {
- const alice = privateKey('//Alice');
- const bob = privateKey('//Bob');
+async function calibrateWeightToFee(helper: EthUniqueHelper, privateKey: (account: string) => Promise) {
+ const alice = await privateKey('//Alice');
+ const bob = await privateKey('//Bob');
const dataPoints = [];
{
@@ -106,8 +106,8 @@
}
}
-async function calibrateMinGasPrice(helper: EthUniqueHelper, privateKey: (account: string) => IKeyringPair) {
- const alice = privateKey('//Alice');
+async function calibrateMinGasPrice(helper: EthUniqueHelper, privateKey: (account: string) => Promise) {
+ const alice = await privateKey('//Alice');
const caller = await helper.eth.createAccountWithBalance(alice);
const receiver = helper.eth.createAccount();
const dataPoints = [];
--- a/tests/src/change-collection-owner.test.ts
+++ b/tests/src/change-collection-owner.test.ts
@@ -15,7 +15,7 @@
// along with Unique Network. If not, see .
import {IKeyringPair} from '@polkadot/types/types';
-import {usingPlaygrounds, expect, itSub} from './util/playgrounds';
+import {usingPlaygrounds, expect, itSub} from './util';
describe('Integration Test changeCollectionOwner(collection_id, new_owner):', () => {
let alice: IKeyringPair;
@@ -23,7 +23,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);
});
});
@@ -46,7 +46,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
});
});
@@ -108,7 +108,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
});
});
--- a/tests/src/check-event/burnItemEvent.test.ts
+++ b/tests/src/check-event/burnItemEvent.test.ts
@@ -16,7 +16,7 @@
// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits
import {IKeyringPair} from '@polkadot/types/types';
-import {usingPlaygrounds, expect, itSub} from '../util/playgrounds';
+import {usingPlaygrounds, expect, itSub} from '../util';
import {IEvent} from '../util/playgrounds/types';
@@ -24,7 +24,7 @@
let alice: IKeyringPair;
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice] = await helper.arrange.createAccounts([10n], donor);
});
});
--- a/tests/src/check-event/createCollectionEvent.test.ts
+++ b/tests/src/check-event/createCollectionEvent.test.ts
@@ -16,14 +16,14 @@
// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits
import {IKeyringPair} from '@polkadot/types/types';
-import {usingPlaygrounds, itSub, expect} from '../util/playgrounds';
+import {usingPlaygrounds, itSub, expect} from '../util';
import {IEvent} from '../util/playgrounds/types';
describe('Create collection event ', () => {
let alice: IKeyringPair;
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice] = await helper.arrange.createAccounts([10n], donor);
});
});
--- a/tests/src/check-event/createItemEvent.test.ts
+++ b/tests/src/check-event/createItemEvent.test.ts
@@ -16,14 +16,14 @@
// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits
import {IKeyringPair} from '@polkadot/types/types';
-import {itSub, usingPlaygrounds, expect} from '../util/playgrounds';
+import {itSub, usingPlaygrounds, expect} from '../util';
import {IEvent} from '../util/playgrounds/types';
describe('Create Item event ', () => {
let alice: IKeyringPair;
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice] = await helper.arrange.createAccounts([10n], donor);
});
});
--- a/tests/src/check-event/createMultipleItemsEvent.test.ts
+++ b/tests/src/check-event/createMultipleItemsEvent.test.ts
@@ -16,14 +16,14 @@
// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits
import {IKeyringPair} from '@polkadot/types/types';
-import {usingPlaygrounds, itSub, expect} from '../util/playgrounds';
+import {usingPlaygrounds, itSub, expect} from '../util';
import {IEvent} from '../util/playgrounds/types';
describe('Create Multiple Items Event event ', () => {
let alice: IKeyringPair;
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice] = await helper.arrange.createAccounts([10n], donor);
});
});
--- a/tests/src/check-event/destroyCollectionEvent.test.ts
+++ b/tests/src/check-event/destroyCollectionEvent.test.ts
@@ -16,14 +16,14 @@
// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits
import {IKeyringPair} from '@polkadot/types/types';
-import {itSub, usingPlaygrounds, expect} from '../util/playgrounds';
+import {itSub, usingPlaygrounds, expect} from '../util';
import {IEvent} from '../util/playgrounds/types';
describe('Destroy collection event ', () => {
let alice: IKeyringPair;
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice] = await helper.arrange.createAccounts([10n], donor);
});
});
--- a/tests/src/check-event/transferEvent.test.ts
+++ b/tests/src/check-event/transferEvent.test.ts
@@ -16,7 +16,7 @@
// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits
import {IKeyringPair} from '@polkadot/types/types';
-import {usingPlaygrounds, expect, itSub} from '../util/playgrounds';
+import {usingPlaygrounds, expect, itSub} from '../util';
import {IEvent} from '../util/playgrounds/types';
describe('Transfer event ', () => {
@@ -25,7 +25,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);
});
});
--- a/tests/src/check-event/transferFromEvent.test.ts
+++ b/tests/src/check-event/transferFromEvent.test.ts
@@ -16,7 +16,7 @@
// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits
import {IKeyringPair} from '@polkadot/types/types';
-import {usingPlaygrounds, expect, itSub} from '../util/playgrounds';
+import {usingPlaygrounds, expect, itSub} from '../util';
import {IEvent} from '../util/playgrounds/types';
describe('Transfer event ', () => {
@@ -24,7 +24,7 @@
let bob: IKeyringPair;
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);
});
});
--- a/tests/src/confirmSponsorship.test.ts
+++ b/tests/src/confirmSponsorship.test.ts
@@ -15,7 +15,7 @@
// along with Unique Network. If not, see .
import {IKeyringPair} from '@polkadot/types/types';
-import {usingPlaygrounds, expect, itSub, Pallets} from './util/playgrounds';
+import {usingPlaygrounds, expect, itSub, Pallets} from './util';
async function setSponsorHelper(collection: any, signer: IKeyringPair, sponsorAddress: string) {
await collection.setSponsor(signer, sponsorAddress);
@@ -37,7 +37,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob, charlie, zeroBalance] = await helper.arrange.createAccounts([100n, 100n, 100n, 0n], donor);
});
});
@@ -73,7 +73,7 @@
});
itSub('Fungible: Transfer fees are paid by the sponsor after confirmation', async ({helper}) => {
- const collection = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'}, 0);
+ const collection = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
await collection.setSponsor(alice, bob.address);
await collection.confirmSponsorship(bob);
const bobBalanceBefore = await helper.balance.getSubstrate(bob.address);
@@ -109,7 +109,9 @@
});
itSub('NFT: Sponsoring of transfers is rate limited', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL', limits: {
+ sponsorTransferTimeout: 1000,
+ }});
await collection.setSponsor(alice, bob.address);
await collection.confirmSponsorship(bob);
@@ -125,7 +127,9 @@
});
itSub('Fungible: Sponsoring is rate limited', async ({helper}) => {
- const collection = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const collection = await helper.ft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL', limits: {
+ sponsorTransferTimeout: 1000,
+ }});
await collection.setSponsor(alice, bob.address);
await collection.confirmSponsorship(bob);
@@ -141,7 +145,9 @@
});
itSub.ifWithPallets('ReFungible: Sponsoring is rate limited', [Pallets.ReFungible], async ({helper}) => {
- const collection = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const collection = await helper.rft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL', limits: {
+ sponsorTransferTimeout: 1000,
+ }});
await collection.setSponsor(alice, bob.address);
await collection.confirmSponsorship(bob);
@@ -157,7 +163,10 @@
});
itSub('NFT: Sponsoring of createItem is rate limited', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
+ const collection = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL', limits: {
+ sponsoredDataRateLimit: {blocks: 1000},
+ sponsorTransferTimeout: 1000,
+ }});
await collection.setSponsor(alice, bob.address);
await collection.confirmSponsorship(bob);
await collection.setPermissions(alice, {mintMode: true, access: 'AllowList'});
@@ -183,13 +192,13 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob, charlie, ownerZeroBalance, senderZeroBalance] = await helper.arrange.createAccounts([100n, 100n, 100n, 0n, 0n], donor);
});
});
itSub('(!negative test!) Confirm sponsorship for a collection that never existed', async ({helper}) => {
- const collectionId = 1_000_000;
+ const collectionId = (1 << 32) - 1;
const confirmSponsorshipTx = async () => helper.collection.confirmSponsorship(bob, collectionId);
await expect(confirmSponsorshipTx()).to.be.rejectedWith(/common\.CollectionNotFound/);
});
--- a/tests/src/connection.test.ts
+++ b/tests/src/connection.test.ts
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see .
-import {itSub, expect, usingPlaygrounds} from './util/playgrounds';
+import {itSub, expect, usingPlaygrounds} from './util';
describe('Connection smoke test', () => {
itSub('Connection can be established', async ({helper}) => {
--- a/tests/src/createCollection.test.ts
+++ b/tests/src/createCollection.test.ts
@@ -15,7 +15,7 @@
// along with Unique Network. If not, see .
import {IKeyringPair} from '@polkadot/types/types';
-import {usingPlaygrounds, expect, itSub, Pallets} from './util/playgrounds';
+import {usingPlaygrounds, expect, itSub, Pallets} from './util';
import {ICollectionCreationOptions, IProperty} from './util/playgrounds/types';
import {UniqueHelper} from './util/playgrounds/unique';
@@ -49,7 +49,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice] = await helper.arrange.createAccounts([100n], donor);
});
});
@@ -110,7 +110,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice] = await helper.arrange.createAccounts([100n], donor);
});
});
--- a/tests/src/createItem.test.ts
+++ b/tests/src/createItem.test.ts
@@ -15,7 +15,7 @@
// along with Unique Network. If not, see .
import {IKeyringPair} from '@polkadot/types/types';
-import {usingPlaygrounds, expect, itSub, Pallets} from './util/playgrounds';
+import {usingPlaygrounds, expect, itSub, Pallets} from './util';
import {IProperty, ICrossAccountId} from './util/playgrounds/types';
import {UniqueHelper} from './util/playgrounds/unique';
@@ -50,7 +50,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);
});
});
@@ -179,7 +179,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);
});
});
--- a/tests/src/createMultipleItems.test.ts
+++ b/tests/src/createMultipleItems.test.ts
@@ -15,14 +15,14 @@
// along with Unique Network. If not, see .
import {IKeyringPair} from '@polkadot/types/types';
-import {usingPlaygrounds, expect, Pallets, itSub} from './util/playgrounds';
+import {usingPlaygrounds, expect, Pallets, itSub} from './util';
describe('Integration Test createMultipleItems(collection_id, owner, items_data):', () => {
let alice: IKeyringPair;
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice] = await helper.arrange.createAccounts([100n], donor);
});
});
@@ -168,7 +168,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);
});
});
--- a/tests/src/createMultipleItemsEx.test.ts
+++ b/tests/src/createMultipleItemsEx.test.ts
@@ -15,7 +15,7 @@
// along with Unique Network. If not, see .
import {IKeyringPair} from '@polkadot/types/types';
-import {usingPlaygrounds, expect, Pallets, itSub} from './util/playgrounds';
+import {usingPlaygrounds, expect, Pallets, itSub} from './util';
import {IProperty} from './util/playgrounds/types';
describe('Integration Test: createMultipleItemsEx', () => {
@@ -25,7 +25,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
});
});
@@ -264,7 +264,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
});
});
--- /dev/null
+++ b/tests/src/creditFeesToTreasury.seqtest.ts
@@ -0,0 +1,165 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see .
+
+import './interfaces/augment-api-consts';
+import {IKeyringPair} from '@polkadot/types/types';
+import {ApiPromise} from '@polkadot/api';
+import {usingPlaygrounds, expect, itSub} from './util';
+
+const TREASURY = '5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z';
+const saneMinimumFee = 0.05;
+const saneMaximumFee = 0.5;
+const createCollectionDeposit = 100;
+
+// Skip the inflation block pauses if the block is close to inflation block
+// until the inflation happens
+/*eslint no-async-promise-executor: "off"*/
+function skipInflationBlock(api: ApiPromise): Promise {
+ const promise = new Promise(async (resolve) => {
+ const blockInterval = api.consts.inflation.inflationBlockInterval.toNumber();
+ const unsubscribe = await api.rpc.chain.subscribeNewHeads(head => {
+ const currentBlock = head.number.toNumber();
+ if (currentBlock % blockInterval < blockInterval - 10) {
+ unsubscribe();
+ resolve();
+ } else {
+ console.log(`Skipping inflation block, current block: ${currentBlock}`);
+ }
+ });
+ });
+
+ return promise;
+}
+
+describe('integration test: Fees must be credited to Treasury:', () => {
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+
+ before(async () => {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ const donor = await privateKey({filename: __filename});
+ [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);
+ });
+ });
+
+ itSub('Total issuance does not change', async ({helper}) => {
+ const api = helper.getApi();
+ await skipInflationBlock(api);
+ await helper.wait.newBlocks(1);
+
+ const totalBefore = (await helper.callRpc('api.query.balances.totalIssuance', [])).toBigInt();
+
+ await helper.balance.transferToSubstrate(alice, bob.address, 1n);
+
+ const totalAfter = (await helper.callRpc('api.query.balances.totalIssuance', [])).toBigInt();
+
+ expect(totalAfter).to.be.equal(totalBefore);
+ });
+
+ itSub('Sender balance decreased by fee+sent amount, Treasury balance increased by fee', async ({helper}) => {
+ await skipInflationBlock(helper.getApi());
+ await helper.wait.newBlocks(1);
+
+ const treasuryBalanceBefore = await helper.balance.getSubstrate(TREASURY);
+ const aliceBalanceBefore = await helper.balance.getSubstrate(alice.address);
+
+ const amount = 1n;
+ await helper.balance.transferToSubstrate(alice, bob.address, amount);
+
+ const treasuryBalanceAfter = await helper.balance.getSubstrate(TREASURY);
+ const aliceBalanceAfter = await helper.balance.getSubstrate(alice.address);
+
+ const fee = aliceBalanceBefore - aliceBalanceAfter - amount;
+ const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;
+
+ expect(treasuryIncrease).to.be.equal(fee);
+ });
+
+ itSub('Treasury balance increased by failed tx fee', async ({helper}) => {
+ const api = helper.getApi();
+ await helper.wait.newBlocks(1);
+
+ const treasuryBalanceBefore = await helper.balance.getSubstrate(TREASURY);
+ const bobBalanceBefore = await helper.balance.getSubstrate(bob.address);
+
+ await expect(helper.signTransaction(bob, api.tx.balances.setBalance(alice.address, 0, 0))).to.be.rejected;
+
+ const treasuryBalanceAfter = await helper.balance.getSubstrate(TREASURY);
+ const bobBalanceAfter = await helper.balance.getSubstrate(bob.address);
+
+ const fee = bobBalanceBefore - bobBalanceAfter;
+ const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;
+
+ expect(treasuryIncrease).to.be.equal(fee);
+ });
+
+ itSub('NFT Transactions also send fees to Treasury', async ({helper}) => {
+ await skipInflationBlock(helper.getApi());
+ await helper.wait.newBlocks(1);
+
+ const treasuryBalanceBefore = await helper.balance.getSubstrate(TREASURY);
+ const aliceBalanceBefore = await helper.balance.getSubstrate(alice.address);
+
+ await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+
+ const treasuryBalanceAfter = await helper.balance.getSubstrate(TREASURY);
+ const aliceBalanceAfter = await helper.balance.getSubstrate(alice.address);
+ const fee = aliceBalanceBefore - aliceBalanceAfter;
+ const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;
+
+ expect(treasuryIncrease).to.be.equal(fee);
+ });
+
+ itSub('Fees are sane', async ({helper}) => {
+ const unique = helper.balance.getOneTokenNominal();
+ await skipInflationBlock(helper.getApi());
+ await helper.wait.newBlocks(1);
+
+ const aliceBalanceBefore = await helper.balance.getSubstrate(alice.address);
+
+ await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+
+ const aliceBalanceAfter = await helper.balance.getSubstrate(alice.address);
+ const fee = aliceBalanceBefore - aliceBalanceAfter;
+
+ expect(fee / unique < BigInt(Math.ceil(saneMaximumFee + createCollectionDeposit))).to.be.true;
+ expect(fee / unique < BigInt(Math.ceil(saneMinimumFee + createCollectionDeposit))).to.be.true;
+ });
+
+ itSub('NFT Transfer fee is close to 0.1 Unique', async ({helper}) => {
+ await skipInflationBlock(helper.getApi());
+ await helper.wait.newBlocks(1);
+
+ const collection = await helper.nft.mintCollection(alice, {
+ name: 'test',
+ description: 'test',
+ tokenPrefix: 'test',
+ });
+ // const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');
+ const token = await collection.mintToken(alice, {Substrate: alice.address});
+
+ const aliceBalanceBefore = await helper.balance.getSubstrate(alice.address);
+ await token.transfer(alice, {Substrate: bob.address});
+ const aliceBalanceAfter = await helper.balance.getSubstrate(alice.address);
+
+ const fee = Number(aliceBalanceBefore - aliceBalanceAfter) / Number(helper.balance.getOneTokenNominal());
+ const expectedTransferFee = 0.1;
+ // fee drifts because of NextFeeMultiplier
+ const tolerance = 0.001;
+
+ expect(Math.abs(fee - expectedTransferFee)).to.be.lessThan(tolerance);
+ });
+});
--- a/tests/src/creditFeesToTreasury.test.ts
+++ /dev/null
@@ -1,165 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// This file is part of Unique Network.
-
-// Unique Network is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Unique Network is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Unique Network. If not, see .
-
-import './interfaces/augment-api-consts';
-import {IKeyringPair} from '@polkadot/types/types';
-import {ApiPromise} from '@polkadot/api';
-import {usingPlaygrounds, expect, itSub} from './util/playgrounds';
-
-const TREASURY = '5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z';
-const saneMinimumFee = 0.05;
-const saneMaximumFee = 0.5;
-const createCollectionDeposit = 100;
-
-// Skip the inflation block pauses if the block is close to inflation block
-// until the inflation happens
-/*eslint no-async-promise-executor: "off"*/
-function skipInflationBlock(api: ApiPromise): Promise {
- const promise = new Promise(async (resolve) => {
- const blockInterval = api.consts.inflation.inflationBlockInterval.toNumber();
- const unsubscribe = await api.rpc.chain.subscribeNewHeads(head => {
- const currentBlock = head.number.toNumber();
- if (currentBlock % blockInterval < blockInterval - 10) {
- unsubscribe();
- resolve();
- } else {
- console.log(`Skipping inflation block, current block: ${currentBlock}`);
- }
- });
- });
-
- return promise;
-}
-
-describe('integration test: Fees must be credited to Treasury:', () => {
- let alice: IKeyringPair;
- let bob: IKeyringPair;
-
- before(async () => {
- await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
- [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);
- });
- });
-
- itSub('Total issuance does not change', async ({helper}) => {
- const api = helper.getApi();
- await skipInflationBlock(api);
- await helper.wait.newBlocks(1);
-
- const totalBefore = (await helper.callRpc('api.query.balances.totalIssuance', [])).toBigInt();
-
- await helper.balance.transferToSubstrate(alice, bob.address, 1n);
-
- const totalAfter = (await helper.callRpc('api.query.balances.totalIssuance', [])).toBigInt();
-
- expect(totalAfter).to.be.equal(totalBefore);
- });
-
- itSub('Sender balance decreased by fee+sent amount, Treasury balance increased by fee', async ({helper}) => {
- await skipInflationBlock(helper.getApi());
- await helper.wait.newBlocks(1);
-
- const treasuryBalanceBefore = await helper.balance.getSubstrate(TREASURY);
- const aliceBalanceBefore = await helper.balance.getSubstrate(alice.address);
-
- const amount = 1n;
- await helper.balance.transferToSubstrate(alice, bob.address, amount);
-
- const treasuryBalanceAfter = await helper.balance.getSubstrate(TREASURY);
- const aliceBalanceAfter = await helper.balance.getSubstrate(alice.address);
-
- const fee = aliceBalanceBefore - aliceBalanceAfter - amount;
- const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;
-
- expect(treasuryIncrease).to.be.equal(fee);
- });
-
- itSub('Treasury balance increased by failed tx fee', async ({helper}) => {
- const api = helper.getApi();
- await helper.wait.newBlocks(1);
-
- const treasuryBalanceBefore = await helper.balance.getSubstrate(TREASURY);
- const bobBalanceBefore = await helper.balance.getSubstrate(bob.address);
-
- await expect(helper.signTransaction(bob, api.tx.balances.setBalance(alice.address, 0, 0))).to.be.rejected;
-
- const treasuryBalanceAfter = await helper.balance.getSubstrate(TREASURY);
- const bobBalanceAfter = await helper.balance.getSubstrate(bob.address);
-
- const fee = bobBalanceBefore - bobBalanceAfter;
- const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;
-
- expect(treasuryIncrease).to.be.equal(fee);
- });
-
- itSub('NFT Transactions also send fees to Treasury', async ({helper}) => {
- await skipInflationBlock(helper.getApi());
- await helper.wait.newBlocks(1);
-
- const treasuryBalanceBefore = await helper.balance.getSubstrate(TREASURY);
- const aliceBalanceBefore = await helper.balance.getSubstrate(alice.address);
-
- await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
-
- const treasuryBalanceAfter = await helper.balance.getSubstrate(TREASURY);
- const aliceBalanceAfter = await helper.balance.getSubstrate(alice.address);
- const fee = aliceBalanceBefore - aliceBalanceAfter;
- const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;
-
- expect(treasuryIncrease).to.be.equal(fee);
- });
-
- itSub('Fees are sane', async ({helper}) => {
- const unique = helper.balance.getOneTokenNominal();
- await skipInflationBlock(helper.getApi());
- await helper.wait.newBlocks(1);
-
- const aliceBalanceBefore = await helper.balance.getSubstrate(alice.address);
-
- await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
-
- const aliceBalanceAfter = await helper.balance.getSubstrate(alice.address);
- const fee = aliceBalanceBefore - aliceBalanceAfter;
-
- expect(fee / unique < BigInt(Math.ceil(saneMaximumFee + createCollectionDeposit))).to.be.true;
- expect(fee / unique < BigInt(Math.ceil(saneMinimumFee + createCollectionDeposit))).to.be.true;
- });
-
- itSub('NFT Transfer fee is close to 0.1 Unique', async ({helper}) => {
- await skipInflationBlock(helper.getApi());
- await helper.wait.newBlocks(1);
-
- const collection = await helper.nft.mintCollection(alice, {
- name: 'test',
- description: 'test',
- tokenPrefix: 'test',
- });
- // const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');
- const token = await collection.mintToken(alice, {Substrate: alice.address});
-
- const aliceBalanceBefore = await helper.balance.getSubstrate(alice.address);
- await token.transfer(alice, {Substrate: bob.address});
- const aliceBalanceAfter = await helper.balance.getSubstrate(alice.address);
-
- const fee = Number(aliceBalanceBefore - aliceBalanceAfter) / Number(helper.balance.getOneTokenNominal());
- const expectedTransferFee = 0.1;
- // fee drifts because of NextFeeMultiplier
- const tolerance = 0.001;
-
- expect(Math.abs(fee - expectedTransferFee)).to.be.lessThan(tolerance);
- });
-});
--- a/tests/src/destroyCollection.test.ts
+++ b/tests/src/destroyCollection.test.ts
@@ -15,14 +15,14 @@
// along with Unique Network. If not, see .
import {IKeyringPair} from '@polkadot/types/types';
-import {itSub, expect, usingPlaygrounds, Pallets} from './util/playgrounds';
+import {itSub, expect, usingPlaygrounds, Pallets} from './util';
describe('integration test: ext. destroyCollection():', () => {
let alice: IKeyringPair;
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice] = await helper.arrange.createAccounts([100n], donor);
});
});
@@ -62,7 +62,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);
});
});
--- a/tests/src/enableDisableTransfer.test.ts
+++ b/tests/src/enableDisableTransfer.test.ts
@@ -15,7 +15,7 @@
// along with Unique Network. If not, see .
import {IKeyringPair} from '@polkadot/types/types';
-import {itSub, usingPlaygrounds, expect} from './util/playgrounds';
+import {itSub, usingPlaygrounds, expect} from './util';
describe('Enable/Disable Transfers', () => {
let alice: IKeyringPair;
@@ -23,7 +23,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);
});
});
@@ -62,7 +62,7 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
[alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);
});
});
--- a/tests/src/eth/allowlist.test.ts
+++ b/tests/src/eth/allowlist.test.ts
@@ -15,14 +15,14 @@
// along with Unique Network. If not, see .
import {IKeyringPair} from '@polkadot/types/types';
-import {itEth, usingEthPlaygrounds, expect} from './util/playgrounds';
+import {itEth, usingEthPlaygrounds, expect} from './util';
describe('EVM contract allowlist', () => {
let donor: IKeyringPair;
before(async function() {
await usingEthPlaygrounds(async (_helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
});
});
@@ -70,7 +70,7 @@
before(async function() {
await usingEthPlaygrounds(async (_helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
});
});
--- a/tests/src/eth/base.test.ts
+++ b/tests/src/eth/base.test.ts
@@ -17,7 +17,7 @@
import {Contract} from 'web3-eth-contract';
import {IKeyringPair} from '@polkadot/types/types';
-import {EthUniqueHelper, itEth, usingEthPlaygrounds, expect} from './util/playgrounds';
+import {EthUniqueHelper, itEth, usingEthPlaygrounds, expect} from './util';
describe('Contract calls', () => {
@@ -25,7 +25,7 @@
before(async function() {
await usingEthPlaygrounds(async (_helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
});
});
@@ -78,7 +78,7 @@
before(async () => {
await usingEthPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ const donor = await privateKey({filename: __filename});
const [alice] = await helper.arrange.createAccounts([10n], donor);
({collectionId: collection} = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'}));
minter = helper.eth.createAccount();
--- a/tests/src/eth/collectionAdmin.test.ts
+++ b/tests/src/eth/collectionAdmin.test.ts
@@ -14,7 +14,7 @@
// along with Unique Network. If not, see .
import {IKeyringPair} from '@polkadot/types/types';
-import {usingEthPlaygrounds, itEth, expect, EthUniqueHelper} from './util/playgrounds';
+import {usingEthPlaygrounds, itEth, expect, EthUniqueHelper} from './util';
async function recordEthFee(helper: EthUniqueHelper, userAddress: string, call: () => Promise) {
const before = await helper.balance.getSubstrate(helper.address.ethToSubstrate(userAddress));
@@ -32,7 +32,7 @@
before(async function() {
await usingEthPlaygrounds(async (_helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
});
});
@@ -144,7 +144,7 @@
before(async function() {
await usingEthPlaygrounds(async (_helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
});
});
@@ -272,7 +272,7 @@
before(async function() {
await usingEthPlaygrounds(async (_helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
});
});
@@ -314,7 +314,7 @@
before(async function() {
await usingEthPlaygrounds(async (_helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
});
});
--- a/tests/src/eth/collectionProperties.test.ts
+++ b/tests/src/eth/collectionProperties.test.ts
@@ -1,4 +1,20 @@
-import {itEth, usingEthPlaygrounds, expect} from './util/playgrounds';
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see .
+
+import {itEth, usingEthPlaygrounds, expect} from './util';
import {IKeyringPair} from '@polkadot/types/types';
describe('EVM collection properties', () => {
@@ -7,7 +23,7 @@
before(async function() {
await usingEthPlaygrounds(async (_helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
[alice] = await _helper.arrange.createAccounts([10n], donor);
});
});
--- a/tests/src/eth/collectionSponsoring.test.ts
+++ b/tests/src/eth/collectionSponsoring.test.ts
@@ -1,6 +1,22 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see .
+
import {IKeyringPair} from '@polkadot/types/types';
-import {usingPlaygrounds} from './../util/playgrounds/index';
-import {itEth, expect} from '../eth/util/playgrounds';
+import {usingPlaygrounds} from '../util/index';
+import {itEth, expect} from './util';
describe('evm collection sponsoring', () => {
let donor: IKeyringPair;
@@ -9,17 +25,12 @@
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
+ [alice] = await helper.arrange.createAccounts([100n], donor);
nominal = helper.balance.getOneTokenNominal();
});
});
-
- beforeEach(async () => {
- await usingPlaygrounds(async (helper) => {
- [alice] = await helper.arrange.createAccounts([1000n], donor);
- });
- });
-
+
itEth('sponsors mint transactions', async ({helper}) => {
const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'spnr', permissions: {mintMode: true}});
await collection.setSponsor(alice, alice.address);
--- a/tests/src/eth/contractSponsoring.test.ts
+++ b/tests/src/eth/contractSponsoring.test.ts
@@ -16,8 +16,8 @@
import {IKeyringPair} from '@polkadot/types/types';
import {EthUniqueHelper} from './util/playgrounds/unique.dev';
-import {itEth, expect, SponsoringMode, usingEthPlaygrounds} from '../eth/util/playgrounds';
-import {usingPlaygrounds} from '../util/playgrounds';
+import {itEth, expect, SponsoringMode, usingEthPlaygrounds} from './util';
+import {usingPlaygrounds} from '../util';
import {CompiledContract} from './util/playgrounds/types';
describe('Sponsoring EVM contracts', () => {
@@ -25,11 +25,11 @@
before(async () => {
await usingPlaygrounds(async (_helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
});
});
- itEth('Self sponsored can be set by the address that deployed the contract', async ({helper, privateKey}) => {
+ itEth('Self sponsored can be set by the address that deployed the contract', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const flipper = await helper.eth.deployFlipper(owner);
const helpers = helper.ethNativeContract.contractHelpers(owner);
@@ -378,7 +378,7 @@
// Balance should be taken from flipper instead of caller
// FIXME the comment is wrong! What check should be here?
const balanceAfter = await helper.balance.getEthereum(flipper.options.address);
- expect(balanceAfter).to.be.equals(originalFlipperBalance);
+ expect(balanceAfter).to.be.equal(originalFlipperBalance);
});
itEth('Sponsoring is set, an address that has UNQ can send a transaction and it works. User balance should not change', async ({helper}) => {
@@ -406,7 +406,7 @@
const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));
const callerBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));
expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
- expect(callerBalanceAfter).to.be.equals(callerBalanceBefore);
+ expect(callerBalanceAfter).to.be.equal(callerBalanceBefore);
});
itEth('Sponsoring is limited, with setContractRateLimit. The limitation is working if transactions are sent more often, the sender pays the commission.', async ({helper}) => {
@@ -431,23 +431,24 @@
await flipper.methods.flip().send({from: caller});
expect(await flipper.methods.getValue().call()).to.be.true;
- expect(await helper.balance.getEthereum(caller)).to.be.equals(originalCallerBalance);
+ expect(await helper.balance.getEthereum(caller)).to.be.equal(originalCallerBalance);
const newFlipperBalance = await helper.balance.getEthereum(sponsor);
- expect(newFlipperBalance).to.be.not.equals(originalFlipperBalance);
+ expect(newFlipperBalance).to.be.not.equal(originalFlipperBalance);
await flipper.methods.flip().send({from: caller});
+ // todo:playgrounds fails rarely (expected 99893341659775672580n to equal 99912598679356033129n) (again, 99893341659775672580n)
expect(await helper.balance.getEthereum(sponsor)).to.be.equal(newFlipperBalance);
- expect(await helper.balance.getEthereum(caller)).to.be.not.equals(originalCallerBalance);
+ expect(await helper.balance.getEthereum(caller)).to.be.not.equal(originalCallerBalance);
});
// TODO: Find a way to calculate default rate limit
- itEth('Default rate limit equals 7200', async ({helper}) => {
+ itEth('Default rate limit equal 7200', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const helpers = helper.ethNativeContract.contractHelpers(owner);
const flipper = await helper.eth.deployFlipper(owner);
- expect(await helpers.methods.sponsoringRateLimit(flipper.options.address).call()).to.be.equals('7200');
+ expect(await helpers.methods.sponsoringRateLimit(flipper.options.address).call()).to.be.equal('7200');
});
});
@@ -490,24 +491,18 @@
}
before(async () => {
- await usingEthPlaygrounds(async (_helper, privateKey) => {
- donor = privateKey('//Alice');
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ donor = await privateKey({filename: __filename});
+ [alice] = await helper.arrange.createAccounts([100n], donor);
});
});
-
- beforeEach(async () => {
- await usingPlaygrounds(async (helper) => {
- [alice] = await helper.arrange.createAccounts([1000n], donor);
- });
- });
-
itEth('Default fee limit', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const helpers = helper.ethNativeContract.contractHelpers(owner);
const flipper = await helper.eth.deployFlipper(owner);
- expect(await helpers.methods.sponsoringFeeLimit(flipper.options.address).call()).to.be.equals('115792089237316195423570985008687907853269984665640564039457584007913129639935');
+ expect(await helpers.methods.sponsoringFeeLimit(flipper.options.address).call()).to.be.equal('115792089237316195423570985008687907853269984665640564039457584007913129639935');
});
itEth('Set fee limit', async ({helper}) => {
@@ -516,7 +511,7 @@
const flipper = await helper.eth.deployFlipper(owner);
await helpers.methods.setSponsoringFeeLimit(flipper.options.address, 100).send();
- expect(await helpers.methods.sponsoringFeeLimit(flipper.options.address).call()).to.be.equals('100');
+ expect(await helpers.methods.sponsoringFeeLimit(flipper.options.address).call()).to.be.equal('100');
});
itEth('Negative test - set fee limit by non-owner', async ({helper}) => {
@@ -554,7 +549,7 @@
expect(await helper.balance.getEthereum(user)).to.not.be.equal(originalUserBalance);
});
- itEth('Negative test - check that evm.call transactions exceeding fee limit are not executed', async ({helper, privateKey}) => {
+ itEth('Negative test - check that evm.call transactions exceeding fee limit are not executed', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const sponsor = await helper.eth.createAccountWithBalance(donor);
const helpers = helper.ethNativeContract.contractHelpers(owner);
--- a/tests/src/eth/createNFTCollection.test.ts
+++ b/tests/src/eth/createNFTCollection.test.ts
@@ -16,7 +16,7 @@
import {evmToAddress} from '@polkadot/util-crypto';
import {IKeyringPair} from '@polkadot/types/types';
-import {expect, itEth, usingEthPlaygrounds} from './util/playgrounds';
+import {expect, itEth, usingEthPlaygrounds} from './util';
describe('Create NFT collection from EVM', () => {
@@ -24,7 +24,7 @@
before(async function() {
await usingEthPlaygrounds(async (_helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
});
});
@@ -35,24 +35,17 @@
const description = 'Some description';
const prefix = 'token prefix';
- // todo:playgrounds this might fail when in async environment.
- const collectionCountBefore = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;
const {collectionId} = await helper.eth.createNonfungibleCollection(owner, name, description, prefix);
- const collectionCountAfter = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;
-
- const collection = helper.nft.getCollectionObject(collectionId);
- const data = (await collection.getData())!;
+ const data = (await helper.rft.getData(collectionId))!;
- expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);
- expect(collectionId).to.be.eq(collectionCountAfter);
expect(data.name).to.be.eq(name);
expect(data.description).to.be.eq(description);
expect(data.raw.tokenPrefix).to.be.eq(prefix);
expect(data.raw.mode).to.be.eq('NFT');
});
- // todo:playgrounds this test will fail when in async environment.
- itEth('Check collection address exist', async ({helper}) => {
+ // this test will occasionally fail when in async environment.
+ itEth.skip('Check collection address exist', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const expectedCollectionId = +(await helper.callRpc('api.rpc.unique.collectionStats')).created + 1;
@@ -151,7 +144,7 @@
before(async function() {
await usingEthPlaygrounds(async (helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
nominal = helper.balance.getOneTokenNominal();
});
});
--- a/tests/src/eth/createRFTCollection.test.ts
+++ b/tests/src/eth/createRFTCollection.test.ts
@@ -16,8 +16,8 @@
import {evmToAddress} from '@polkadot/util-crypto';
import {IKeyringPair} from '@polkadot/types/types';
-import {Pallets, requirePalletsOrSkip} from '../util/playgrounds';
-import {expect, itEth, usingEthPlaygrounds} from './util/playgrounds';
+import {Pallets, requirePalletsOrSkip} from '../util';
+import {expect, itEth, usingEthPlaygrounds} from './util';
describe('Create RFT collection from EVM', () => {
@@ -26,7 +26,7 @@
before(async function() {
await usingEthPlaygrounds(async (helper, privateKey) => {
requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
});
});
@@ -37,23 +37,17 @@
const description = 'Some description';
const prefix = 'token prefix';
- // todo:playgrounds this might fail when in async environment.
- const collectionCountBefore = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;
const {collectionId} = await helper.eth.createRefungibleCollection(owner, name, description, prefix);
- const collectionCountAfter = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;
-
const data = (await helper.rft.getData(collectionId))!;
- expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);
- expect(collectionId).to.be.eq(collectionCountAfter);
expect(data.name).to.be.eq(name);
expect(data.description).to.be.eq(description);
expect(data.raw.tokenPrefix).to.be.eq(prefix);
expect(data.raw.mode).to.be.eq('ReFungible');
});
-
- // todo:playgrounds this test will fail when in async environment.
- itEth('Check collection address exist', async ({helper}) => {
+
+ // this test will occasionally fail when in async environment.
+ itEth.skip('Check collection address exist', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const expectedCollectionId = +(await helper.callRpc('api.rpc.unique.collectionStats')).created + 1;
@@ -153,7 +147,7 @@
before(async function() {
await usingEthPlaygrounds(async (helper, privateKey) => {
requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
nominal = helper.balance.getOneTokenNominal();
});
});
--- a/tests/src/eth/crossTransfer.test.ts
+++ b/tests/src/eth/crossTransfer.test.ts
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see .
-import {itEth, usingEthPlaygrounds} from './util/playgrounds';
+import {itEth, usingEthPlaygrounds} from './util';
import {CrossAccountId} from '../util/playgrounds/unique';
import {IKeyringPair} from '@polkadot/types/types';
@@ -26,7 +26,7 @@
before(async function() {
await usingEthPlaygrounds(async (helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
[alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);
});
});
@@ -69,7 +69,7 @@
before(async function() {
await usingEthPlaygrounds(async (helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
[alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);
});
});
--- a/tests/src/eth/evmCoder.test.ts
+++ b/tests/src/eth/evmCoder.test.ts
@@ -15,7 +15,7 @@
// along with Unique Network. If not, see .
import {IKeyringPair} from '@polkadot/types/types';
-import {itEth, expect, usingEthPlaygrounds} from './util/playgrounds';
+import {itEth, expect, usingEthPlaygrounds} from './util';
const getContractSource = (collectionAddress: string, contractAddress: string): string => {
return `
@@ -59,7 +59,7 @@
before(async function() {
await usingEthPlaygrounds(async (_helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
});
});
--- a/tests/src/eth/fractionalizer/fractionalizer.test.ts
+++ b/tests/src/eth/fractionalizer/fractionalizer.test.ts
@@ -22,9 +22,9 @@
import {Contract} from 'web3-eth-contract';
-import {usingEthPlaygrounds, expect, itEth, EthUniqueHelper} from '../util/playgrounds';
+import {usingEthPlaygrounds, expect, itEth, EthUniqueHelper} from '../util';
import {CompiledContract} from '../util/playgrounds/types';
-import {requirePalletsOrSkip, Pallets} from '../../util/playgrounds';
+import {requirePalletsOrSkip, Pallets} from '../../util';
let compiledFractionalizer: CompiledContract;
@@ -85,7 +85,7 @@
before(async function() {
await usingEthPlaygrounds(async (helper: EthUniqueHelper, privateKey) => {
requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
});
});
@@ -225,7 +225,7 @@
before(async function() {
await usingEthPlaygrounds(async (helper: EthUniqueHelper, privateKey) => {
requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
});
});
--- a/tests/src/eth/fungible.test.ts
+++ b/tests/src/eth/fungible.test.ts
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see .
-import {expect, itEth, usingEthPlaygrounds} from './util/playgrounds';
+import {expect, itEth, usingEthPlaygrounds} from './util';
import {IKeyringPair} from '@polkadot/types/types';
describe('Fungible: Information getting', () => {
@@ -23,7 +23,7 @@
before(async function() {
await usingEthPlaygrounds(async (helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
[alice] = await helper.arrange.createAccounts([20n], donor);
});
});
@@ -55,7 +55,7 @@
before(async function() {
await usingEthPlaygrounds(async (helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
[alice] = await helper.arrange.createAccounts([20n], donor);
});
});
@@ -224,7 +224,7 @@
before(async function() {
await usingEthPlaygrounds(async (helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
[alice] = await helper.arrange.createAccounts([20n], donor);
});
});
@@ -277,7 +277,7 @@
before(async function() {
await usingEthPlaygrounds(async (helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
[alice] = await helper.arrange.createAccounts([20n], donor);
});
});
@@ -294,9 +294,11 @@
contract.events.allEvents((_: any, event: any) => {
events.push(event);
});
+
await collection.approveTokens(alice, {Ethereum: receiver}, 100n);
-
+ if (events.length == 0) await helper.wait.newBlocks(1);
const event = events[0];
+
expect(event.event).to.be.equal('Approval');
expect(event.address).to.be.equal(collectionAddress);
expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));
@@ -318,9 +320,11 @@
contract.events.allEvents((_: any, event: any) => {
events.push(event);
});
+
await collection.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver}, 51n);
-
+ if (events.length == 0) await helper.wait.newBlocks(1);
let event = events[0];
+
expect(event.event).to.be.equal('Transfer');
expect(event.address).to.be.equal(collectionAddress);
expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));
@@ -347,9 +351,11 @@
contract.events.allEvents((_: any, event: any) => {
events.push(event);
});
+
await collection.transfer(alice, {Ethereum:receiver}, 51n);
-
+ if (events.length == 0) await helper.wait.newBlocks(1);
const event = events[0];
+
expect(event.event).to.be.equal('Transfer');
expect(event.address).to.be.equal(collectionAddress);
expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));
--- a/tests/src/eth/helpersSmoke.test.ts
+++ b/tests/src/eth/helpersSmoke.test.ts
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see .
-import {expect, itEth, usingEthPlaygrounds} from './util/playgrounds';
+import {expect, itEth, usingEthPlaygrounds} from './util';
import {IKeyringPair} from '@polkadot/types/types';
describe('Helpers sanity check', () => {
@@ -22,7 +22,7 @@
before(async function() {
await usingEthPlaygrounds(async (_helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
});
});
--- a/tests/src/eth/marketplace/marketplace.test.ts
+++ b/tests/src/eth/marketplace/marketplace.test.ts
@@ -14,10 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see .
-import {usingPlaygrounds} from './../../util/playgrounds/index';
import {IKeyringPair} from '@polkadot/types/types';
import {readFile} from 'fs/promises';
-import {itEth, expect, SponsoringMode} from '../util/playgrounds';
+import {itEth, usingEthPlaygrounds, expect, SponsoringMode} from '../util';
describe('Matcher contract usage', () => {
const PRICE = 2000n;
@@ -29,17 +28,17 @@
let sellerMirror: string;
before(async () => {
- await usingPlaygrounds(async (_helper, privateKey) => {
- donor = privateKey('//Alice');
+ await usingEthPlaygrounds(async (_helper, privateKey) => {
+ donor = await privateKey({filename: __filename});
});
});
beforeEach(async () => {
- await usingPlaygrounds(async (helper, privateKey) => {
- [alice] = await helper.arrange.createAccounts([10000n], donor);
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ [alice] = await helper.arrange.createAccounts([1000n], donor);
aliceMirror = helper.address.substrateToEth(alice.address).toLowerCase();
aliceDoubleMirror = helper.address.ethToSubstrate(aliceMirror);
- seller = privateKey(`//Seller/${Date.now()}`);
+ seller = await privateKey(`//Seller/${Date.now()}`);
sellerMirror = helper.address.substrateToEth(seller.address).toLowerCase();
await helper.balance.transferToSubstrate(donor, aliceDoubleMirror, 10_000_000_000_000_000_000n);
--- a/tests/src/eth/migration.test.ts
+++ b/tests/src/eth/migration.test.ts
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see .
-import {expect, itEth, usingEthPlaygrounds} from './util/playgrounds';
+import {expect, itEth, usingEthPlaygrounds} from './util';
import {IKeyringPair} from '@polkadot/types/types';
describe('EVM Migrations', () => {
@@ -22,7 +22,7 @@
before(async function() {
await usingEthPlaygrounds(async (_helper, privateKey) => {
- superuser = privateKey('//Alice');
+ superuser = await privateKey('//Alice');
});
});
--- a/tests/src/eth/nesting/nest.test.ts
+++ b/tests/src/eth/nesting/nest.test.ts
@@ -1,7 +1,7 @@
import {IKeyringPair} from '@polkadot/types/types';
import {Contract} from 'web3-eth-contract';
-import {itEth, EthUniqueHelper, usingEthPlaygrounds, expect} from '../util/playgrounds';
+import {itEth, EthUniqueHelper, usingEthPlaygrounds, expect} from '../util';
const createNestingCollection = async (
helper: EthUniqueHelper,
@@ -21,7 +21,7 @@
before(async function() {
await usingEthPlaygrounds(async (_, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
});
});
--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see .
-import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util/playgrounds';
+import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util';
import {IKeyringPair} from '@polkadot/types/types';
import {Contract} from 'web3-eth-contract';
@@ -25,7 +25,7 @@
before(async function() {
await usingEthPlaygrounds(async (helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
[alice] = await helper.arrange.createAccounts([10n], donor);
});
});
@@ -75,7 +75,7 @@
before(async function() {
await usingEthPlaygrounds(async (_helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
});
});
@@ -137,7 +137,7 @@
before(async function() {
await usingEthPlaygrounds(async (helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
[alice] = await helper.arrange.createAccounts([10n], donor);
});
});
@@ -318,7 +318,7 @@
before(async function() {
await usingEthPlaygrounds(async (helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
[alice] = await helper.arrange.createAccounts([10n], donor);
});
});
@@ -371,7 +371,7 @@
before(async function() {
await usingEthPlaygrounds(async (helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
[alice] = await helper.arrange.createAccounts([20n], donor);
});
});
@@ -385,9 +385,11 @@
contract.events.allEvents((_: any, event: any) => {
events.push(event);
});
+
const {tokenId} = await collection.mintToken(alice);
+ if (events.length == 0) await helper.wait.newBlocks(1);
+ const event = events[0];
- const event = events[0];
expect(event.event).to.be.equal('Transfer');
expect(event.address).to.be.equal(collectionAddress);
expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
@@ -408,8 +410,9 @@
});
await token.burn(alice);
+ if (events.length == 0) await helper.wait.newBlocks(1);
+ const event = events[0];
- const event = events[0];
expect(event.event).to.be.equal('Transfer');
expect(event.address).to.be.equal(collectionAddress);
expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));
@@ -432,8 +435,9 @@
});
await token.approve(alice, {Ethereum: receiver});
+ if (events.length == 0) await helper.wait.newBlocks(1);
+ const event = events[0];
- const event = events[0];
expect(event.event).to.be.equal('Approval');
expect(event.address).to.be.equal(collectionAddress);
expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));
@@ -458,8 +462,9 @@
});
await token.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver});
-
+ if (events.length == 0) await helper.wait.newBlocks(1);
const event = events[0];
+
expect(event.address).to.be.equal(collectionAddress);
expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));
expect(event.returnValues.to).to.be.equal(receiver);
@@ -481,8 +486,9 @@
});
await token.transfer(alice, {Ethereum: receiver});
-
+ if (events.length == 0) await helper.wait.newBlocks(1);
const event = events[0];
+
expect(event.address).to.be.equal(collectionAddress);
expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));
expect(event.returnValues.to).to.be.equal(receiver);
@@ -496,7 +502,7 @@
before(async function() {
await usingEthPlaygrounds(async (helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
[alice] = await helper.arrange.createAccounts([20n], donor);
});
});
--- a/tests/src/eth/payable.test.ts
+++ b/tests/src/eth/payable.test.ts
@@ -16,14 +16,14 @@
import {IKeyringPair} from '@polkadot/types/types';
-import {itEth, expect, usingEthPlaygrounds, EthUniqueHelper} from './util/playgrounds';
+import {itEth, expect, usingEthPlaygrounds, EthUniqueHelper} from './util';
describe('EVM payable contracts', () => {
let donor: IKeyringPair;
before(async function() {
await usingEthPlaygrounds(async (_, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
});
});
@@ -68,7 +68,7 @@
expect(await contract.methods.getUnaccounted().call()).to.be.equal(weiCount.toString());
});
- itEth('Balance can be retrieved from evm contract', async({helper, privateKey}) => {
+ itEth('Balance can be retrieved from evm contract', async({helper}) => {
const FEE_BALANCE = 10n * helper.balance.getOneTokenNominal();
const CONTRACT_BALANCE = 1n * helper.balance.getOneTokenNominal();
@@ -80,7 +80,7 @@
await web3.eth.sendTransaction({from: deployer, to: contract.options.address, value: CONTRACT_BALANCE.toString(), gas: helper.eth.DEFAULT_GAS});
- const receiver = privateKey(`//Receiver${Date.now()}`);
+ const [receiver] = await helper.arrange.createAccounts([0n], donor);
// First receive balance on eth balance of bob
{
@@ -110,7 +110,7 @@
before(async function() {
await usingEthPlaygrounds(async (_, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
});
});
--- a/tests/src/eth/proxy/fungibleProxy.test.ts
+++ b/tests/src/eth/proxy/fungibleProxy.test.ts
@@ -17,7 +17,7 @@
import {expect} from 'chai';
import {readFile} from 'fs/promises';
import {IKeyringPair} from '@polkadot/types/types';
-import {EthUniqueHelper, itEth, usingEthPlaygrounds} from '../util/playgrounds';
+import {EthUniqueHelper, itEth, usingEthPlaygrounds} from '../util';
async function proxyWrap(helper: EthUniqueHelper, wrapped: any, donor: IKeyringPair) {
// Proxy owner has no special privilegies, we don't need to reuse them
@@ -37,7 +37,7 @@
before(async function() {
await usingEthPlaygrounds(async (helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
[alice] = await helper.arrange.createAccounts([10n], donor);
});
});
@@ -76,7 +76,7 @@
before(async function() {
await usingEthPlaygrounds(async (helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
[alice] = await helper.arrange.createAccounts([10n], donor);
});
});
--- a/tests/src/eth/proxy/nonFungibleProxy.test.ts
+++ b/tests/src/eth/proxy/nonFungibleProxy.test.ts
@@ -16,7 +16,7 @@
import {readFile} from 'fs/promises';
import {IKeyringPair} from '@polkadot/types/types';
-import {EthUniqueHelper, itEth, usingEthPlaygrounds, expect} from '../util/playgrounds';
+import {EthUniqueHelper, itEth, usingEthPlaygrounds, expect} from '../util';
async function proxyWrap(helper: EthUniqueHelper, wrapped: any, donor: IKeyringPair) {
@@ -37,7 +37,7 @@
before(async function() {
await usingEthPlaygrounds(async (helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
[alice] = await helper.arrange.createAccounts([10n], donor);
});
});
@@ -94,7 +94,7 @@
before(async function() {
await usingEthPlaygrounds(async (helper, privateKey) => {
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
[alice] = await helper.arrange.createAccounts([10n], donor);
});
});
--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -14,8 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see .
-import {Pallets, requirePalletsOrSkip} from '../util/playgrounds';
-import {expect, itEth, usingEthPlaygrounds} from './util/playgrounds';
+import {Pallets, requirePalletsOrSkip} from '../util';
+import {expect, itEth, usingEthPlaygrounds} from './util';
import {IKeyringPair} from '@polkadot/types/types';
describe('Refungible: Information getting', () => {
@@ -25,7 +25,7 @@
await usingEthPlaygrounds(async (helper, privateKey) => {
requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
});
});
@@ -117,7 +117,7 @@
await usingEthPlaygrounds(async (helper, privateKey) => {
requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
});
});
@@ -286,9 +286,11 @@
contract.events.allEvents((_: any, event: any) => {
events.push(event);
});
+
await tokenContract.methods.transfer(receiver, 1).send();
+ if (events.length == 0) await helper.wait.newBlocks(1);
+ const event = events[0];
- const event = events[0];
expect(event.address).to.equal(collectionAddress);
expect(event.returnValues.from).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');
expect(event.returnValues.to).to.equal(receiver);
@@ -312,9 +314,11 @@
contract.events.allEvents((_: any, event: any) => {
events.push(event);
});
+
await tokenContract.methods.transfer(receiver, 1).send();
+ if (events.length == 0) await helper.wait.newBlocks(1);
+ const event = events[0];
- const event = events[0];
expect(event.address).to.equal(collectionAddress);
expect(event.returnValues.from).to.equal(caller);
expect(event.returnValues.to).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');
@@ -329,7 +333,7 @@
await usingEthPlaygrounds(async (helper, privateKey) => {
requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
});
});
@@ -370,7 +374,7 @@
await usingEthPlaygrounds(async (helper, privateKey) => {
requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
[alice] = await helper.arrange.createAccounts([20n], donor);
});
});
--- a/tests/src/eth/reFungibleToken.test.ts
+++ b/tests/src/eth/reFungibleToken.test.ts
@@ -14,8 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see .
-import {Pallets, requirePalletsOrSkip} from '../util/playgrounds';
-import {EthUniqueHelper, expect, itEth, usingEthPlaygrounds} from './util/playgrounds';
+import {Pallets, requirePalletsOrSkip} from '../util';
+import {EthUniqueHelper, expect, itEth, usingEthPlaygrounds} from './util';
import {IKeyringPair} from '@polkadot/types/types';
import {Contract} from 'web3-eth-contract';
@@ -28,7 +28,7 @@
await usingEthPlaygrounds(async (helper, privateKey) => {
requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
[alice] = await helper.arrange.createAccounts([20n], donor);
});
});
@@ -72,7 +72,7 @@
await usingEthPlaygrounds(async (helper, privateKey) => {
requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
});
});
@@ -136,7 +136,7 @@
await usingEthPlaygrounds(async (helper, privateKey) => {
requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
[alice] = await helper.arrange.createAccounts([50n], donor);
});
});
@@ -311,6 +311,7 @@
});
await tokenContract.methods.burnFrom(caller, 1).send();
+ if (events.length == 0) await helper.wait.newBlocks(1);
const event = events[0];
expect(event.address).to.be.equal(collectionAddress);
expect(event.returnValues.from).to.be.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');
@@ -327,7 +328,7 @@
await usingEthPlaygrounds(async (helper, privateKey) => {
requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
[alice] = await helper.arrange.createAccounts([50n], donor);
});
});
@@ -382,7 +383,7 @@
await usingEthPlaygrounds(async (helper, privateKey) => {
requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
[alice] = await helper.arrange.createAccounts([50n], donor);
});
});
@@ -399,9 +400,11 @@
contract.events.allEvents((_: any, event: any) => {
events.push(event);
});
+
expect(await token.approve(alice, {Ethereum: receiver}, 100n)).to.be.true;
-
+ if (events.length == 0) await helper.wait.newBlocks(1);
const event = events[0];
+
expect(event.event).to.be.equal('Approval');
expect(event.address).to.be.equal(tokenAddress);
expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));
@@ -425,6 +428,7 @@
});
expect(await token.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver}, 51n)).to.be.true;
+ if (events.length == 0) await helper.wait.newBlocks(1);
let event = events[0];
expect(event.event).to.be.equal('Transfer');
@@ -455,8 +459,9 @@
});
expect(await token.transfer(alice, {Ethereum: receiver}, 51n)).to.be.true;
+ if (events.length == 0) await helper.wait.newBlocks(1);
+ const event = events[0];
- const event = events[0];
expect(event.event).to.be.equal('Transfer');
expect(event.address).to.be.equal(tokenAddress);
expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));
@@ -472,7 +477,7 @@
await usingEthPlaygrounds(async (helper, privateKey) => {
requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
- donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
});
});
--- a/tests/src/eth/sponsoring.test.ts
+++ b/tests/src/eth/sponsoring.test.ts
@@ -15,15 +15,15 @@
// along with Unique Network. If not, see .
import {IKeyringPair} from '@polkadot/types/types';
-import {itEth, expect, SponsoringMode} from '../eth/util/playgrounds';
-import {usingPlaygrounds} from './../util/playgrounds/index';
+import {itEth, expect, SponsoringMode} from './util';
+import {usingPlaygrounds} from '../util/index';
describe('EVM sponsoring', () => {
let donor: IKeyringPair;
before(async () => {
- await usingPlaygrounds(async (helper, privateKey) => {
- donor = privateKey('//Alice');
+ await usingPlaygrounds(async (_helper, privateKey) => {
+ donor = await privateKey({filename: __filename});
});
});
--- a/tests/src/eth/tokenProperties.test.ts
+++ b/tests/src/eth/tokenProperties.test.ts
@@ -1,32 +1,45 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see .
+
+import {itEth, usingEthPlaygrounds, expect} from './util';
import {IKeyringPair} from '@polkadot/types/types';
-import {usingPlaygrounds} from './../util/playgrounds/index';
-import {itEth, expect} from '../eth/util/playgrounds';
describe('EVM token properties', () => {
let donor: IKeyringPair;
let alice: IKeyringPair;
- before(async () => {
- await usingPlaygrounds(async (helper, privateKey) => {
- donor = privateKey('//Alice');
- [alice] = await helper.arrange.createAccounts([1000n], donor);
+ before(async function() {
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ donor = await privateKey({filename: __filename});
+ [alice] = await helper.arrange.createAccounts([100n], donor);
});
});
itEth('Can be reconfigured', async({helper}) => {
const caller = await helper.eth.createAccountWithBalance(donor);
-
for(const [mutable,collectionAdmin, tokenOwner] of cartesian([], [false, true], [false, true], [false, true])) {
- const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'ethp'});
+ const collection = await helper.nft.mintCollection(alice);
await collection.addAdmin(alice, {Ethereum: caller});
-
+
const address = helper.ethAddress.fromCollectionId(collection.collectionId);
const contract = helper.ethNativeContract.collection(address, 'nft', caller);
-
+
await contract.methods.setTokenPropertyPermission('testKey', mutable, collectionAdmin, tokenOwner).send({from: caller});
- const state = await collection.getPropertyPermissions();
- expect(state).to.be.deep.equal([{
+ expect(await collection.getPropertyPermissions()).to.be.deep.equal([{
key: 'testKey',
permission: {mutable, collectionAdmin, tokenOwner},
}]);
@@ -36,7 +49,6 @@
itEth('Can be set', async({helper}) => {
const caller = await helper.eth.createAccountWithBalance(donor);
const collection = await helper.nft.mintCollection(alice, {
- tokenPrefix: 'ethp',
tokenPropertyPermissions: [{
key: 'testKey',
permission: {
@@ -60,7 +72,6 @@
itEth('Can be deleted', async({helper}) => {
const caller = await helper.eth.createAccountWithBalance(donor);
const collection = await helper.nft.mintCollection(alice, {
- tokenPrefix: 'ethp',
tokenPropertyPermissions: [{
key: 'testKey',
permission: {
@@ -69,11 +80,11 @@
},
}],
});
+
+ const token = await collection.mintToken(alice);
+ await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}]);
await collection.addAdmin(alice, {Ethereum: caller});
-
- const token = await collection.mintToken(alice);
- await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}]);
const address = helper.ethAddress.fromCollectionId(collection.collectionId);
const contract = helper.ethNativeContract.collection(address, 'nft', caller);
@@ -85,9 +96,8 @@
});
itEth('Can be read', async({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
+ const caller = helper.eth.createAccount();
const collection = await helper.nft.mintCollection(alice, {
- tokenPrefix: 'ethp',
tokenPropertyPermissions: [{
key: 'testKey',
permission: {
@@ -95,6 +105,7 @@
},
}],
});
+
const token = await collection.mintToken(alice);
await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}]);
@@ -116,4 +127,4 @@
for(const value of args[0]) {
yield* cartesian([...internalRest, value], ...args.slice(1)) as any;
}
-}
\ No newline at end of file
+}
--- /dev/null
+++ b/tests/src/eth/util/index.ts
@@ -0,0 +1,83 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// SPDX-License-Identifier: Apache-2.0
+
+import * as path from 'path';
+import {IKeyringPair} from '@polkadot/types/types';
+
+import config from '../../config';
+
+import {EthUniqueHelper} from './playgrounds/unique.dev';
+import {SilentLogger, SilentConsole} from '../../util/playgrounds/unique.dev';
+
+export {EthUniqueHelper} from './playgrounds/unique.dev';
+
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import chaiLike from 'chai-like';
+import {getTestSeed, requirePalletsOrSkip} from '../../util';
+
+chai.use(chaiAsPromised);
+chai.use(chaiLike);
+export const expect = chai.expect;
+
+export enum SponsoringMode {
+ Disabled = 0,
+ Allowlisted = 1,
+ Generous = 2,
+}
+
+export const usingEthPlaygrounds = async (code: (helper: EthUniqueHelper, privateKey: (seed: string | {filename: string}) => Promise) => Promise) => {
+ const silentConsole = new SilentConsole();
+ silentConsole.enable();
+
+ const helper = new EthUniqueHelper(new SilentLogger());
+
+ try {
+ await helper.connect(config.substrateUrl);
+ await helper.connectWeb3(config.substrateUrl);
+ const ss58Format = helper.chain.getChainProperties().ss58Format;
+ const privateKey = async (seed: string | {filename: string}) => {
+ if (typeof seed === 'string') {
+ return helper.util.fromSeed(seed, ss58Format);
+ }
+ else {
+ const actualSeed = getTestSeed(seed.filename);
+ let account = helper.util.fromSeed(actualSeed, ss58Format);
+ if (await helper.balance.getSubstrate(account.address) == 0n) {
+ console.warn(`${path.basename(seed.filename)}: Not enough funds present on the filename account. Using the default one as the donor instead.`);
+ account = helper.util.fromSeed('//Alice', ss58Format);
+ }
+ return account;
+ }
+ };
+ await code(helper, privateKey);
+ }
+ finally {
+ await helper.disconnect();
+ silentConsole.disable();
+ }
+};
+
+export async function itEth(name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string | {filename: string}) => Promise }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {
+ (opts.only ? it.only :
+ opts.skip ? it.skip : it)(name, async function() {
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ if (opts.requiredPallets) {
+ requirePalletsOrSkip(this, helper, opts.requiredPallets);
+ }
+
+ await cb({helper, privateKey});
+ });
+ });
+}
+
+export async function itEthIfWithPallet(name: string, required: string[], cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string | {filename: string}) => Promise }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {
+ return itEth(name, cb, {requiredPallets: required, ...opts});
+}
+
+itEth.only = (name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string | {filename: string}) => Promise }) => any) => itEth(name, cb, {only: true});
+itEth.skip = (name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string | {filename: string}) => Promise }) => any) => itEth(name, cb, {skip: true});
+
+itEthIfWithPallet.only = (name: string, required: string[], cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string | {filename: string}) => Promise }) => any) => itEthIfWithPallet(name, required, cb, {only: true});
+itEthIfWithPallet.skip = (name: string, required: string[], cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string | {filename: string}) => Promise }) => any) => itEthIfWithPallet(name, required, cb, {skip: true});
+itEth.ifWithPallets = itEthIfWithPallet;
--- a/tests/src/eth/util/playgrounds/index.ts
+++ /dev/null
@@ -1,68 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// SPDX-License-Identifier: Apache-2.0
-
-import {IKeyringPair} from '@polkadot/types/types';
-
-import config from '../../../config';
-
-import {EthUniqueHelper} from './unique.dev';
-import {SilentLogger, SilentConsole} from '../../../util/playgrounds/unique.dev';
-
-export {EthUniqueHelper} from './unique.dev';
-
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-import chaiLike from 'chai-like';
-import {requirePalletsOrSkip} from '../../../util/playgrounds';
-chai.use(chaiAsPromised);
-chai.use(chaiLike);
-export const expect = chai.expect;
-
-export enum SponsoringMode {
- Disabled = 0,
- Allowlisted = 1,
- Generous = 2,
-}
-
-export const usingEthPlaygrounds = async (code: (helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise) => {
- const silentConsole = new SilentConsole();
- silentConsole.enable();
-
- const helper = new EthUniqueHelper(new SilentLogger());
-
- try {
- await helper.connect(config.substrateUrl);
- await helper.connectWeb3(config.substrateUrl);
- const ss58Format = helper.chain.getChainProperties().ss58Format;
- const privateKey = (seed: string) => helper.util.fromSeed(seed, ss58Format);
- await code(helper, privateKey);
- }
- finally {
- await helper.disconnect();
- silentConsole.disable();
- }
-};
-
-export async function itEth(name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {
- (opts.only ? it.only :
- opts.skip ? it.skip : it)(name, async function() {
- await usingEthPlaygrounds(async (helper, privateKey) => {
- if (opts.requiredPallets) {
- requirePalletsOrSkip(this, helper, opts.requiredPallets);
- }
-
- await cb({helper, privateKey});
- });
- });
-}
-
-export async function itEthIfWithPallet(name: string, required: string[], cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {
- return itEth(name, cb, {requiredPallets: required, ...opts});
-}
-
-itEth.only = (name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEth(name, cb, {only: true});
-itEth.skip = (name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEth(name, cb, {skip: true});
-
-itEthIfWithPallet.only = (name: string, required: string[], cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEthIfWithPallet(name, required, cb, {only: true});
-itEthIfWithPallet.skip = (name: string, required: string[], cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEthIfWithPallet(name, required, cb, {skip: true});
-itEth.ifWithPallets = itEthIfWithPallet;
--- a/tests/src/eth/util/playgrounds/unique.dev.ts
+++ b/tests/src/eth/util/playgrounds/unique.dev.ts
@@ -142,14 +142,14 @@
return account.address;
}
- async createAccountWithBalance(donor: IKeyringPair, amount=1000n) {
+ async createAccountWithBalance(donor: IKeyringPair, amount=100n) {
const account = this.createAccount();
await this.transferBalanceFromSubstrate(donor, account, amount);
return account;
}
- async transferBalanceFromSubstrate(donor: IKeyringPair, recepient: string, amount=1000n, inTokens=true) {
+ async transferBalanceFromSubstrate(donor: IKeyringPair, recepient: string, amount=100n, inTokens=true) {
return await this.helper.balance.transferToSubstrate(donor, evmToAddress(recepient), amount * (inTokens ? this.helper.balance.getOneTokenNominal() : 1n));
}
--- a/tests/src/fungible.test.ts
+++ b/tests/src/fungible.test.ts
@@ -15,17 +15,18 @@
// along with Unique Network. If not, see .
import {IKeyringPair} from '@polkadot/types/types';
-import {itSub, usingPlaygrounds, expect} from './util/playgrounds';
+import {itSub, usingPlaygrounds, expect} from './util';
const U128_MAX = (1n << 128n) - 1n;
describe('integration test: Fungible functionality:', () => {
+ let donor: IKeyringPair;
let alice: IKeyringPair;
let bob: IKeyringPair;
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
- const donor = privateKey('//Alice');
+ donor = await privateKey({filename: __filename});
[alice, bob] = await helper.arrange.createAccounts([100n, 10n], donor);
});
});
@@ -43,9 +44,9 @@
expect(aliceBalance).to.be.equal(U128_MAX);
});
- itSub('RPC method tokenOnewrs for fungible collection and token', async ({helper, privateKey}) => {
+ itSub('RPC method tokenOnewrs for fungible collection and token', async ({helper}) => {
const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};
- const facelessCrowd = Array(7).fill(0).map((_, i) => ({Substrate: privateKey(`//Alice+${i}`).address}));
+ const facelessCrowd = (await helper.arrange.createAccounts(Array(7).fill(0n), donor)).map(keyring => {return {Substrate: keyring.address};});
const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
@@ -64,7 +65,7 @@
expect(owners).to.deep.include.members([{Substrate: alice.address}, ethAcc, {Substrate: bob.address}, ...facelessCrowd]);
expect(owners.length).to.be.equal(10);
- const eleven = privateKey('//ALice+11');
+ const [eleven] = await helper.arrange.createAccounts([0n], donor);
expect(await collection.transfer(alice, {Substrate: eleven.address}, 10n)).to.be.true;
expect((await collection.getTop10Owners()).length).to.be.equal(10);
});
--- a/tests/src/getPropertiesRpc.test.ts
+++ b/tests/src/getPropertiesRpc.test.ts
@@ -15,7 +15,7 @@
// along with Unique Network. If not, see .
import {IKeyringPair} from '@polkadot/types/types';
-import {itSub, usingPlaygrounds, expect} from './util/playgrounds';
+import {itSub, usingPlaygrounds, expect} from './util';
import {UniqueHelper, UniqueNFTCollection} from './util/playgrounds/unique';
const collectionProps = [
@@ -63,7 +63,7 @@
before(async () => {
await usingPlaygrounds(async (_, privateKey) => {
- alice = privateKey('//Alice');
+ alice = await privateKey({filename: __filename});
});
});
--- a/tests/src/inflation.test.ts
+++ b/tests/src/inflation.test.ts
@@ -15,7 +15,7 @@
// along with Unique Network. If not, see .
import {IKeyringPair} from '@polkadot/types/types';
-import {expect, itSub, usingPlaygrounds} from './util/playgrounds';
+import {expect, itSub, usingPlaygrounds} from './util';
// todo:playgrounds requires sudo, look into on the later stage
describe('integration test: Inflation', () => {
@@ -23,7 +23,7 @@
before(async () => {
await usingPlaygrounds(async (_, privateKey) => {
- superuser = privateKey('//Alice');
+ superuser = await privateKey('//Alice');
});
});
--- a/tests/src/interfaces/augment-api-consts.ts
+++ b/tests/src/interfaces/augment-api-consts.ts
@@ -8,7 +8,7 @@
import type { ApiTypes, AugmentedConst } from '@polkadot/api-base/types';
import type { Option, u128, u16, u32, u64, u8 } from '@polkadot/types-codec';
import type { Codec } from '@polkadot/types-codec/types';
-import type { Perbill, Permill } from '@polkadot/types/interfaces/runtime';
+import type { Perbill, Permill, Weight } from '@polkadot/types/interfaces/runtime';
import type { FrameSupportPalletId, FrameSupportWeightsRuntimeDbWeight, FrameSystemLimitsBlockLength, FrameSystemLimitsBlockWeights, SpVersionRuntimeVersion, XcmV1MultiLocation } from '@polkadot/types/lookup';
export type __AugmentedConst = AugmentedConst;
@@ -97,7 +97,7 @@
* The maximum weight that may be scheduled per block for any dispatchables of less
* priority than `schedule::HARD_DEADLINE`.
**/
- maximumWeight: u64 & AugmentedConst;
+ maximumWeight: Weight & AugmentedConst;
/**
* The maximum number of scheduled calls in the queue for a single block.
* Not strictly enforced, but used for weight estimation.
@@ -126,7 +126,7 @@
**/
dbWeight: FrameSupportWeightsRuntimeDbWeight & AugmentedConst;
/**
- * The designated SS85 prefix of this chain.
+ * The designated SS58 prefix of this chain.
*
* This replaces the "ss58Format" property declared in the chain spec. Reason is
* that the runtime should know about the prefix in order to make use of it as
--- a/tests/src/interfaces/augment-api-events.ts
+++ b/tests/src/interfaces/augment-api-events.ts
@@ -8,7 +8,7 @@
import type { ApiTypes, AugmentedEvent } from '@polkadot/api-base/types';
import type { Bytes, Null, Option, Result, U256, U8aFixed, bool, u128, u32, u64, u8 } from '@polkadot/types-codec';
import type { ITuple } from '@polkadot/types-codec/types';
-import type { AccountId32, H160, H256 } from '@polkadot/types/interfaces/runtime';
+import type { AccountId32, H160, H256, Weight } from '@polkadot/types/interfaces/runtime';
import type { EthereumLog, EvmCoreErrorExitReason, FrameSupportScheduleLookupError, FrameSupportTokensMiscBalanceStatus, FrameSupportWeightsDispatchInfo, OrmlVestingVestingSchedule, PalletEvmAccountBasicCrossAccountIdRepr, PalletForeignAssetsAssetIds, PalletForeignAssetsModuleAssetMetadata, RmrkTraitsNftAccountIdOrCollectionNftTuple, SpRuntimeDispatchError, XcmV1MultiAsset, XcmV1MultiLocation, XcmV1MultiassetMultiAssets, XcmV2Response, XcmV2TraitsError, XcmV2TraitsOutcome, XcmV2Xcm, XcmVersionedMultiAssets, XcmVersionedMultiLocation } from '@polkadot/types/lookup';
export type __AugmentedEvent = AugmentedEvent;
@@ -184,11 +184,11 @@
/**
* Downward message is overweight and was placed in the overweight queue.
**/
- OverweightEnqueued: AugmentedEvent;
+ OverweightEnqueued: AugmentedEvent;
/**
* Downward message from the overweight queue was executed.
**/
- OverweightServiced: AugmentedEvent;
+ OverweightServiced: AugmentedEvent;
/**
* Downward message is unsupported version of XCM.
**/
@@ -196,7 +196,7 @@
/**
* The weight limit for handling downward messages was reached.
**/
- WeightExhausted: AugmentedEvent;
+ WeightExhausted: AugmentedEvent;
/**
* Generic event
**/
@@ -290,7 +290,7 @@
/**
* Downward messages were processed using the given weight.
**/
- DownwardMessagesProcessed: AugmentedEvent;
+ DownwardMessagesProcessed: AugmentedEvent;
/**
* Some downward messages have been received and will be processed.
**/
@@ -378,7 +378,7 @@
*
* \[ id, pallet index, call index, actual weight, max budgeted weight \]
**/
- NotifyOverweight: AugmentedEvent;
+ NotifyOverweight: AugmentedEvent;
/**
* A given location which had a version change subscription was dropped owing to an error
* migrating the location to our new XCM format.
@@ -769,19 +769,19 @@
/**
* Some XCM failed.
**/
- Fail: AugmentedEvent, error: XcmV2TraitsError, weight: u64], { messageHash: Option, error: XcmV2TraitsError, weight: u64 }>;
+ Fail: AugmentedEvent, error: XcmV2TraitsError, weight: Weight], { messageHash: Option, error: XcmV2TraitsError, weight: Weight }>;
/**
* An XCM exceeded the individual message weight budget.
**/
- OverweightEnqueued: AugmentedEvent;
+ OverweightEnqueued: AugmentedEvent;
/**
* An XCM from the overweight queue was executed with the given actual weight used.
**/
- OverweightServiced: AugmentedEvent;
+ OverweightServiced: AugmentedEvent;
/**
* Some XCM was executed ok.
**/
- Success: AugmentedEvent, weight: u64], { messageHash: Option, weight: u64 }>;
+ Success: AugmentedEvent, weight: Weight], { messageHash: Option, weight: Weight }>;
/**
* An upward message was sent to the relay chain.
**/
--- a/tests/src/interfaces/augment-api-query.ts
+++ b/tests/src/interfaces/augment-api-query.ts
@@ -8,8 +8,8 @@
import type { ApiTypes, AugmentedQuery, QueryableStorageEntry } from '@polkadot/api-base/types';
import type { BTreeMap, Bytes, Option, U256, U8aFixed, Vec, bool, u128, u16, u32, u64, u8 } from '@polkadot/types-codec';
import type { AnyNumber, ITuple } from '@polkadot/types-codec/types';
-import type { AccountId32, H160, H256 } from '@polkadot/types/interfaces/runtime';
-import type { CumulusPalletDmpQueueConfigData, CumulusPalletDmpQueuePageIndexData, CumulusPalletParachainSystemRelayStateSnapshotMessagingStateSnapshot, CumulusPalletXcmpQueueInboundChannelDetails, CumulusPalletXcmpQueueOutboundChannelDetails, CumulusPalletXcmpQueueQueueConfigData, EthereumBlock, EthereumLog, EthereumReceiptReceiptV3, EthereumTransactionTransactionV2, FpRpcTransactionStatus, FrameSupportWeightsPerDispatchClassU64, FrameSystemAccountInfo, FrameSystemEventRecord, FrameSystemLastRuntimeUpgradeInfo, FrameSystemPhase, OrmlTokensAccountData, OrmlTokensBalanceLock, OrmlTokensReserveData, OrmlVestingVestingSchedule, PalletBalancesAccountData, PalletBalancesBalanceLock, PalletBalancesReleases, PalletBalancesReserveData, PalletEvmAccountBasicCrossAccountIdRepr, PalletEvmContractHelpersSponsoringModeT, PalletForeignAssetsAssetIds, PalletForeignAssetsModuleAssetMetadata, PalletNonfungibleItemData, PalletRefungibleItemData, PalletTransactionPaymentReleases, PalletTreasuryProposal, PalletUniqueSchedulerScheduledV3, PhantomTypeUpDataStructs, PolkadotCorePrimitivesOutboundHrmpMessage, PolkadotPrimitivesV2AbridgedHostConfiguration, PolkadotPrimitivesV2PersistedValidationData, PolkadotPrimitivesV2UpgradeRestriction, SpRuntimeDigest, SpTrieStorageProof, UpDataStructsCollection, UpDataStructsCollectionStats, UpDataStructsProperties, UpDataStructsPropertiesMapPropertyPermission, UpDataStructsPropertyPermission, UpDataStructsPropertyScope, UpDataStructsSponsorshipStateBasicCrossAccountIdRepr, UpDataStructsTokenChild, XcmV1MultiLocation } from '@polkadot/types/lookup';
+import type { AccountId32, H160, H256, Weight } from '@polkadot/types/interfaces/runtime';
+import type { CumulusPalletDmpQueueConfigData, CumulusPalletDmpQueuePageIndexData, CumulusPalletParachainSystemRelayStateSnapshotMessagingStateSnapshot, CumulusPalletXcmpQueueInboundChannelDetails, CumulusPalletXcmpQueueOutboundChannelDetails, CumulusPalletXcmpQueueQueueConfigData, EthereumBlock, EthereumLog, EthereumReceiptReceiptV3, EthereumTransactionTransactionV2, FpRpcTransactionStatus, FrameSupportWeightsPerDispatchClassWeight, FrameSystemAccountInfo, FrameSystemEventRecord, FrameSystemLastRuntimeUpgradeInfo, FrameSystemPhase, OrmlTokensAccountData, OrmlTokensBalanceLock, OrmlTokensReserveData, OrmlVestingVestingSchedule, PalletBalancesAccountData, PalletBalancesBalanceLock, PalletBalancesReleases, PalletBalancesReserveData, PalletEvmAccountBasicCrossAccountIdRepr, PalletEvmContractHelpersSponsoringModeT, PalletForeignAssetsAssetIds, PalletForeignAssetsModuleAssetMetadata, PalletNonfungibleItemData, PalletRefungibleItemData, PalletTransactionPaymentReleases, PalletTreasuryProposal, PalletUniqueSchedulerScheduledV3, PhantomTypeUpDataStructs, PolkadotCorePrimitivesOutboundHrmpMessage, PolkadotPrimitivesV2AbridgedHostConfiguration, PolkadotPrimitivesV2PersistedValidationData, PolkadotPrimitivesV2UpgradeRestriction, SpRuntimeDigest, SpTrieStorageProof, UpDataStructsCollection, UpDataStructsCollectionStats, UpDataStructsProperties, UpDataStructsPropertiesMapPropertyPermission, UpDataStructsPropertyPermission, UpDataStructsPropertyScope, UpDataStructsSponsorshipStateBasicCrossAccountIdRepr, UpDataStructsTokenChild, XcmV1MultiLocation } from '@polkadot/types/lookup';
import type { Observable } from '@polkadot/types/types';
export type __AugmentedQuery = AugmentedQuery unknown>;
@@ -555,12 +555,12 @@
* The weight we reserve at the beginning of the block for processing DMP messages. This
* overrides the amount set in the Config trait.
**/
- reservedDmpWeightOverride: AugmentedQuery Observable