difftreelog
Merge pull request #799 from UniqueNetwork/tests/eth-helpers
in: master
14 files changed
.envdiffbeforeafterboth--- a/.env
+++ b/.env
@@ -3,21 +3,21 @@
POLKADOT_MAINNET_BRANCH=release-v0.9.30
STATEMINT_BUILD_BRANCH=release-parachains-v9320
-ACALA_BUILD_BRANCH=2.10.1
+ACALA_BUILD_BRANCH=2.11.0
MOONBEAM_BUILD_BRANCH=runtime-1901
-UNIQUE_MAINNET_BRANCH=v930033
+UNIQUE_MAINNET_BRANCH=release-v930033
UNIQUE_REPLICA_FROM=wss://eu-ws.unique.network:443
-KUSAMA_MAINNET_BRANCH=release-v0.9.34
-STATEMINE_BUILD_BRANCH=release-parachains-v9320
-KARURA_BUILD_BRANCH=release-karura-2.10.0
-MOONRIVER_BUILD_BRANCH=runtime-1901
-QUARTZ_MAINNET_BRANCH=v930033
+KUSAMA_MAINNET_BRANCH=release-v0.9.35
+STATEMINE_BUILD_BRANCH=release-parachains-v9330
+KARURA_BUILD_BRANCH=release-karura-2.11.0
+MOONRIVER_BUILD_BRANCH=runtime-2000
+QUARTZ_MAINNET_BRANCH=release-v930034
QUARTZ_REPLICA_FROM=wss://eu-ws-quartz.unique.network:443
UNQWND_MAINNET_BRANCH=release-v0.9.30
WESTMINT_BUILD_BRANCH=parachains-v9330
-OPAL_MAINNET_BRANCH=v930032
+OPAL_MAINNET_BRANCH=release-v930034
OPAL_REPLICA_FROM=wss://eu-ws-opal.unique.network:443
POLKADOT_LAUNCH_BRANCH=unique-network
tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -8,11 +8,13 @@
"@types/chai": "^4.3.3",
"@types/chai-as-promised": "^7.1.5",
"@types/chai-like": "^1.1.1",
+ "@types/chai-subset": "^1.3.3",
"@types/mocha": "^10.0.0",
"@types/node": "^18.11.2",
"@typescript-eslint/eslint-plugin": "^5.40.1",
"@typescript-eslint/parser": "^5.40.1",
"chai": "^4.3.6",
+ "chai-subset": "^1.6.0",
"eslint": "^8.25.0",
"eslint-plugin-mocha": "^10.1.0",
"mocha": "^10.1.0",
tests/src/eth/collectionAdmin.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionAdmin.test.ts
+++ b/tests/src/eth/collectionAdmin.test.ts
@@ -15,6 +15,7 @@
import {IKeyringPair} from '@polkadot/types/types';
import {expect} from 'chai';
+import {Pallets} from '../util';
import {IEthCrossAccountId} from '../util/playgrounds/types';
import {usingEthPlaygrounds, itEth} from './util';
import {EthUniqueHelper} from './util/playgrounds/unique.dev';
@@ -39,36 +40,52 @@
});
});
- itEth('can add account admin by owner', async ({helper, privateKey}) => {
- // arrange
- const owner = await helper.eth.createAccountWithBalance(donor);
- const adminSub = await privateKey('//admin2');
- const adminEth = helper.eth.createAccount().toLowerCase();
-
- const adminDeprecated = helper.eth.createAccount().toLowerCase();
- const adminCrossSub = helper.ethCrossAccount.fromKeyringPair(adminSub);
- const adminCrossEth = helper.ethCrossAccount.fromAddress(adminEth);
-
- const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');
- const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);
-
- // Soft-deprecated: can addCollectionAdmin
- await collectionEvm.methods.addCollectionAdmin(adminDeprecated).send();
- // Can addCollectionAdminCross for substrate and ethereum address
- await collectionEvm.methods.addCollectionAdminCross(adminCrossSub).send();
- await collectionEvm.methods.addCollectionAdminCross(adminCrossEth).send();
+ [
+ {mode: 'nft' as const, requiredPallets: []},
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ {mode: 'ft' as const, requiredPallets: []},
+ ].map(testCase => {
+ itEth.ifWithPallets(`can add account admin by owner for ${testCase.mode}`, testCase.requiredPallets, async ({helper, privateKey}) => {
+ // arrange
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const adminSub = await privateKey('//admin2');
+ const adminEth = helper.eth.createAccount().toLowerCase();
+
+ const adminDeprecated = helper.eth.createAccount().toLowerCase();
+ const adminCrossSub = helper.ethCrossAccount.fromKeyringPair(adminSub);
+ const adminCrossEth = helper.ethCrossAccount.fromAddress(adminEth);
+
+ const {collectionAddress, collectionId} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner, true);
- // 1. Expect api.rpc.unique.adminlist returns admins:
- const adminListRpc = await helper.collection.getAdmins(collectionId);
- expect(adminListRpc).to.has.length(3);
- expect(adminListRpc).to.be.deep.contain.members([{Substrate: adminSub.address}, {Ethereum: adminEth}, {Ethereum: adminDeprecated}]);
+ // Check isOwnerOrAdminCross returns false:
+ expect(await collectionEvm.methods.isOwnerOrAdminCross(adminCrossSub).call()).to.be.false;
+ expect(await collectionEvm.methods.isOwnerOrAdminCross(adminCrossEth).call()).to.be.false;
+ expect(await collectionEvm.methods.isOwnerOrAdminCross(helper.ethCrossAccount.fromAddress(adminDeprecated)).call()).to.be.false;
+
+ // Soft-deprecated: can addCollectionAdmin
+ await collectionEvm.methods.addCollectionAdmin(adminDeprecated).send();
+ // Can addCollectionAdminCross for substrate and ethereum address
+ await collectionEvm.methods.addCollectionAdminCross(adminCrossSub).send();
+ await collectionEvm.methods.addCollectionAdminCross(adminCrossEth).send();
+
+ // 1. Expect api.rpc.unique.adminlist returns admins:
+ const adminListRpc = await helper.collection.getAdmins(collectionId);
+ expect(adminListRpc).to.has.length(3);
+ expect(adminListRpc).to.be.deep.contain.members([{Substrate: adminSub.address}, {Ethereum: adminEth}, {Ethereum: adminDeprecated}]);
+
+ // 2. Expect methods.collectionAdmins == api.rpc.unique.adminlist
+ let adminListEth = await collectionEvm.methods.collectionAdmins().call();
+ adminListEth = adminListEth.map((element: IEthCrossAccountId) => {
+ return helper.address.convertCrossAccountFromEthCrossAccount(element);
+ });
+ expect(adminListRpc).to.be.like(adminListEth);
- // 2. Expect methods.collectionAdmins == api.rpc.unique.adminlist
- let adminListEth = await collectionEvm.methods.collectionAdmins().call();
- adminListEth = adminListEth.map((element: IEthCrossAccountId) => {
- return helper.address.convertCrossAccountFromEthCrossAccount(element);
+ // 3. check isOwnerOrAdminCross returns true:
+ expect(await collectionEvm.methods.isOwnerOrAdminCross(adminCrossSub).call()).to.be.true;
+ expect(await collectionEvm.methods.isOwnerOrAdminCross(adminCrossEth).call()).to.be.true;
+ expect(await collectionEvm.methods.isOwnerOrAdminCross(helper.ethCrossAccount.fromAddress(adminDeprecated)).call()).to.be.true;
});
- expect(adminListRpc).to.be.like(adminListEth);
});
itEth('cross account admin can mint', async ({helper}) => {
tests/src/eth/collectionProperties.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionProperties.test.ts
+++ b/tests/src/eth/collectionProperties.test.ts
@@ -26,27 +26,36 @@
before(async function() {
await usingEthPlaygrounds(async (_helper, privateKey) => {
donor = await privateKey({filename: __filename});
- [alice] = await _helper.arrange.createAccounts([20n], donor);
+ [alice] = await _helper.arrange.createAccounts([50n], donor);
});
});
// Soft-deprecated: setCollectionProperty
[
- {method: 'setCollectionProperties', methodParams: [[{key: 'testKey1', value: Buffer.from('testValue1')}, {key: 'testKey2', value: Buffer.from('testValue2')}]], expectedProps: [{key: 'testKey1', value: 'testValue1'}, {key: 'testKey2', value: 'testValue2'}]},
- {method: 'setCollectionProperty', methodParams: ['testKey', Buffer.from('testValue')], expectedProps: [{key: 'testKey', value: 'testValue'}]},
+ {method: 'setCollectionProperties', mode: 'nft' as const, methodParams: [[{key: 'testKey1', value: Buffer.from('testValue1')}, {key: 'testKey2', value: Buffer.from('testValue2')}]], expectedProps: [{key: 'testKey1', value: 'testValue1'}, {key: 'testKey2', value: 'testValue2'}]},
+ {method: 'setCollectionProperties', mode: 'rft' as const, methodParams: [[{key: 'testKey1', value: Buffer.from('testValue1')}, {key: 'testKey2', value: Buffer.from('testValue2')}]], expectedProps: [{key: 'testKey1', value: 'testValue1'}, {key: 'testKey2', value: 'testValue2'}]},
+ {method: 'setCollectionProperties', mode: 'ft' as const, methodParams: [[{key: 'testKey1', value: Buffer.from('testValue1')}, {key: 'testKey2', value: Buffer.from('testValue2')}]], expectedProps: [{key: 'testKey1', value: 'testValue1'}, {key: 'testKey2', value: 'testValue2'}]},
+ {method: 'setCollectionProperty', mode: 'nft' as const, methodParams: ['testKey', Buffer.from('testValue')], expectedProps: [{key: 'testKey', value: 'testValue'}]},
].map(testCase =>
- itEth(`Collection properties can be set: ${testCase.method}`, async({helper}) => {
+ itEth.ifWithPallets(`Collection properties can be set: ${testCase.method}() for ${testCase.mode}`, testCase.mode === 'rft' ? [Pallets.ReFungible] : [], async({helper}) => {
const caller = await helper.eth.createAccountWithBalance(donor);
- const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: []});
+ const collection = await helper[testCase.mode].mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: []});
await collection.addAdmin(alice, {Ethereum: caller});
-
+
const address = helper.ethAddress.fromCollectionId(collection.collectionId);
- const contract = helper.ethNativeContract.collection(address, 'nft', caller, testCase.method === 'setCollectionProperty');
+ const collectionEvm = helper.ethNativeContract.collection(address, 'nft', caller, testCase.method === 'setCollectionProperty');
- await contract.methods[testCase.method](...testCase.methodParams).send({from: caller});
+ // collectionProperties returns an empty array if no properties:
+ expect(await collectionEvm.methods.collectionProperties([]).call()).to.be.like([]);
+ expect(await collectionEvm.methods.collectionProperties(['NonExistingKey']).call()).to.be.like([]);
+
+ await collectionEvm.methods[testCase.method](...testCase.methodParams).send({from: caller});
const raw = (await collection.getData())?.raw;
expect(raw.properties).to.deep.equal(testCase.expectedProps);
+
+ // collectionProperties returns properties:
+ expect(await collectionEvm.methods.collectionProperties([]).call()).to.be.like(testCase.expectedProps.map(prop => helper.ethProperty.property(prop.key, prop.value)));
}));
itEth('Cannot set invalid properties', async({helper}) => {
@@ -68,16 +77,18 @@
// Soft-deprecated: deleteCollectionProperty
[
- {method: 'deleteCollectionProperties', methodParams: [['testKey1', 'testKey2']], expectedProps: [{key: 'testKey3', value: 'testValue3'}]},
- {method: 'deleteCollectionProperty', methodParams: ['testKey1'], expectedProps: [{key: 'testKey2', value: 'testValue2'}, {key: 'testKey3', value: 'testValue3'}]},
+ {method: 'deleteCollectionProperties', mode: 'nft' as const, methodParams: [['testKey1', 'testKey2']], expectedProps: [{key: 'testKey3', value: 'testValue3'}]},
+ {method: 'deleteCollectionProperties', mode: 'rft' as const, methodParams: [['testKey1', 'testKey2']], expectedProps: [{key: 'testKey3', value: 'testValue3'}]},
+ {method: 'deleteCollectionProperties', mode: 'ft' as const, methodParams: [['testKey1', 'testKey2']], expectedProps: [{key: 'testKey3', value: 'testValue3'}]},
+ {method: 'deleteCollectionProperty', mode: 'nft' as const, methodParams: ['testKey1'], expectedProps: [{key: 'testKey2', value: 'testValue2'}, {key: 'testKey3', value: 'testValue3'}]},
].map(testCase =>
- itEth(`Collection properties can be deleted: ${testCase.method}()`, async({helper}) => {
+ itEth.ifWithPallets(`Collection properties can be deleted: ${testCase.method}() for ${testCase.mode}`, testCase.mode === 'rft' ? [Pallets.ReFungible] : [], async({helper}) => {
const properties = [
{key: 'testKey1', value: 'testValue1'},
{key: 'testKey2', value: 'testValue2'},
{key: 'testKey3', value: 'testValue3'}];
const caller = await helper.eth.createAccountWithBalance(donor);
- const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties});
+ const collection = await helper[testCase.mode].mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties});
await collection.addAdmin(alice, {Ethereum: caller});
@@ -92,7 +103,6 @@
expect(raw.properties).to.deep.equal(testCase.expectedProps);
}));
-
[
{method: 'deleteCollectionProperties', methodParams: [['testKey2']]},
{method: 'deleteCollectionProperty', methodParams: ['testKey2']},
@@ -207,82 +217,5 @@
await contract.methods.setProperties(tokenId2, [{key: 'URISuffix', value: Buffer.from(SUFFIX)}]).send();
expect(await contract.methods.tokenURI(tokenId2).call()).to.equal(BASE_URI + SUFFIX);
- }));
-});
-
-describe('EVM collection property', () => {
- let donor: IKeyringPair;
-
- before(async function() {
- await usingEthPlaygrounds(async (_helper, privateKey) => {
- donor = await privateKey({filename: __filename});
- });
- });
-
- [
- {case: 'nft' as const},
- {case: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
- {case: 'ft' as const},
- ].map(testCase =>
- itEth.ifWithPallets(`can set/read properties ${testCase.case}`, testCase.requiredPallets || [], async ({helper}) => {
- const collection = await helper[testCase.case].mintCollection(donor, {name: 'A', description: 'B', tokenPrefix: 'C'});
-
- const sender = await helper.eth.createAccountWithBalance(donor, 100n);
- await collection.addAdmin(donor, {Ethereum: sender});
-
- const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
- const contract = helper.ethNativeContract.collection(collectionAddress, testCase.case, sender);
-
- const keys = ['key0', 'key1'];
-
- const writeProperties = [
- helper.ethProperty.property(keys[0], 'value0'),
- helper.ethProperty.property(keys[1], 'value1'),
- ];
-
- await contract.methods.setCollectionProperties(writeProperties).send();
- const readProperties = await contract.methods.collectionProperties([keys[0], keys[1]]).call();
- expect(readProperties).to.be.like(writeProperties);
- }));
-
- [
- {case: 'nft' as const},
- {case: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
- {case: 'ft' as const},
- ].map(testCase =>
- itEth.ifWithPallets(`can delete properties ${testCase.case}`, testCase.requiredPallets || [], async ({helper}) => {
- const collection = await helper[testCase.case].mintCollection(donor, {name: 'A', description: 'B', tokenPrefix: 'C'});
-
- const sender = await helper.eth.createAccountWithBalance(donor, 100n);
- await collection.addAdmin(donor, {Ethereum: sender});
-
- const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
- const contract = helper.ethNativeContract.collection(collectionAddress, testCase.case, sender);
-
- const keys = ['key0', 'key1', 'key2', 'key3'];
-
- {
- const writeProperties = [
- helper.ethProperty.property(keys[0], 'value0'),
- helper.ethProperty.property(keys[1], 'value1'),
- helper.ethProperty.property(keys[2], 'value2'),
- helper.ethProperty.property(keys[3], 'value3'),
- ];
-
- await contract.methods.setCollectionProperties(writeProperties).send();
- const readProperties = await contract.methods.collectionProperties([keys[0], keys[1], keys[2], keys[3]]).call();
- expect(readProperties).to.be.like(writeProperties);
- }
-
- {
- const expectProperties = [
- helper.ethProperty.property(keys[0], 'value0'),
- helper.ethProperty.property(keys[1], 'value1'),
- ];
-
- await contract.methods.deleteCollectionProperties([keys[2], keys[3]]).send();
- const readProperties = await contract.methods.collectionProperties([]).call();
- expect(readProperties).to.be.like(expectProperties);
- }
}));
});
tests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {EthUniqueHelper} from './util/playgrounds/unique.dev';19import {itEth, expect, SponsoringMode, usingEthPlaygrounds} from './util';20import {usingPlaygrounds} from '../util';21import {CompiledContract} from './util/playgrounds/types';2223describe('Sponsoring EVM contracts', () => {24 let donor: IKeyringPair;2526 before(async () => {27 await usingPlaygrounds(async (_helper, privateKey) => {28 donor = await privateKey({filename: __filename});29 });30 });3132 itEth('Self sponsored can be set by the address that deployed the contract', async ({helper}) => {33 const owner = await helper.eth.createAccountWithBalance(donor);34 const flipper = await helper.eth.deployFlipper(owner);35 const helpers = helper.ethNativeContract.contractHelpers(owner);3637 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;38 await expect(helpers.methods.selfSponsoredEnable(flipper.options.address).send()).to.be.not.rejected;39 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;40 });4142 itEth('Set self sponsored events', async ({helper}) => {43 const owner = await helper.eth.createAccountWithBalance(donor);44 const flipper = await helper.eth.deployFlipper(owner);45 const helpers = helper.ethNativeContract.contractHelpers(owner);46 47 const result = await helpers.methods.selfSponsoredEnable(flipper.options.address).send();48 const ethEvents = helper.eth.helper.eth.normalizeEvents(result.events);49 expect(ethEvents).to.be.deep.equal([50 {51 address: flipper.options.address,52 event: 'ContractSponsorSet',53 args: {54 contractAddress: flipper.options.address,55 sponsor: flipper.options.address,56 },57 },58 {59 address: flipper.options.address,60 event: 'ContractSponsorshipConfirmed',61 args: {62 contractAddress: flipper.options.address,63 sponsor: flipper.options.address,64 },65 },66 ]);67 });6869 itEth('Self sponsored can not be set by the address that did not deployed the contract', async ({helper}) => {70 const owner = await helper.eth.createAccountWithBalance(donor);71 const notOwner = await helper.eth.createAccountWithBalance(donor);72 const helpers = helper.ethNativeContract.contractHelpers(owner);73 const flipper = await helper.eth.deployFlipper(owner);7475 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;76 await expect(helpers.methods.selfSponsoredEnable(flipper.options.address).call({from: notOwner})).to.be.rejectedWith('NoPermission');77 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;78 });7980 itEth('Sponsoring can be set by the address that has deployed the contract', async ({helper}) => {81 const owner = await helper.eth.createAccountWithBalance(donor);82 const helpers = helper.ethNativeContract.contractHelpers(owner);83 const flipper = await helper.eth.deployFlipper(owner);8485 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;86 await expect(helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner})).to.be.not.rejected;87 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;88 });8990 itEth('Sponsoring cannot be set by the address that did not deployed the contract', async ({helper}) => {91 const owner = await helper.eth.createAccountWithBalance(donor);92 const notOwner = await helper.eth.createAccountWithBalance(donor);93 const helpers = helper.ethNativeContract.contractHelpers(owner);94 const flipper = await helper.eth.deployFlipper(owner);9596 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;97 await expect(helpers.methods.setSponsoringMode(notOwner, SponsoringMode.Allowlisted).call({from: notOwner})).to.be.rejectedWith('NoPermission');98 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;99 });100 101 itEth('Sponsor can be set by the address that deployed the contract', async ({helper}) => {102 const owner = await helper.eth.createAccountWithBalance(donor);103 const sponsor = await helper.eth.createAccountWithBalance(donor);104 const helpers = helper.ethNativeContract.contractHelpers(owner);105 const flipper = await helper.eth.deployFlipper(owner);106107 expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.false;108 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;109 expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.true;110 });111 112 itEth('Set sponsor event', async ({helper}) => {113 const owner = await helper.eth.createAccountWithBalance(donor);114 const sponsor = await helper.eth.createAccountWithBalance(donor);115 const helpers = helper.ethNativeContract.contractHelpers(owner);116 const flipper = await helper.eth.deployFlipper(owner);117 118 const result = await helpers.methods.setSponsor(flipper.options.address, sponsor).send();119 const events = helper.eth.normalizeEvents(result.events);120 expect(events).to.be.deep.equal([121 {122 address: flipper.options.address,123 event: 'ContractSponsorSet',124 args: {125 contractAddress: flipper.options.address,126 sponsor: sponsor,127 },128 },129 ]);130 });131 132 itEth('Sponsor can not be set by the address that did not deployed the contract', async ({helper}) => {133 const owner = await helper.eth.createAccountWithBalance(donor);134 const sponsor = await helper.eth.createAccountWithBalance(donor);135 const notOwner = await helper.eth.createAccountWithBalance(donor);136 const helpers = helper.ethNativeContract.contractHelpers(owner);137 const flipper = await helper.eth.deployFlipper(owner);138139 expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.false;140 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).call({from: notOwner})).to.be.rejectedWith('NoPermission');141 expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.false;142 });143144 itEth('Sponsorship can be confirmed by the address that pending as sponsor', async ({helper}) => {145 const owner = await helper.eth.createAccountWithBalance(donor);146 const sponsor = await helper.eth.createAccountWithBalance(donor);147 const helpers = helper.ethNativeContract.contractHelpers(owner);148 const flipper = await helper.eth.deployFlipper(owner);149150 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;151 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;152 await expect(helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor})).to.be.not.rejected;153 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;154 });155156 itEth('Confirm sponsorship event', async ({helper}) => {157 const owner = await helper.eth.createAccountWithBalance(donor);158 const sponsor = await helper.eth.createAccountWithBalance(donor);159 const helpers = helper.ethNativeContract.contractHelpers(owner);160 const flipper = await helper.eth.deployFlipper(owner);161162 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;163 const result = await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});164 const events = helper.eth.normalizeEvents(result.events);165 expect(events).to.be.deep.equal([166 {167 address: flipper.options.address,168 event: 'ContractSponsorshipConfirmed',169 args: {170 contractAddress: flipper.options.address,171 sponsor: sponsor,172 },173 },174 ]);175 });176177 itEth('Sponsorship can not be confirmed by the address that not pending as sponsor', async ({helper}) => {178 const owner = await helper.eth.createAccountWithBalance(donor);179 const sponsor = await helper.eth.createAccountWithBalance(donor);180 const notSponsor = await helper.eth.createAccountWithBalance(donor);181 const helpers = helper.ethNativeContract.contractHelpers(owner);182 const flipper = await helper.eth.deployFlipper(owner);183184 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;185 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;186 await expect(helpers.methods.confirmSponsorship(flipper.options.address).call({from: notSponsor})).to.be.rejectedWith('NoPermission');187 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;188 });189190 itEth('Sponsorship can not be confirmed by the address that not set as sponsor', async ({helper}) => {191 const owner = await helper.eth.createAccountWithBalance(donor);192 const notSponsor = await helper.eth.createAccountWithBalance(donor);193 const helpers = helper.ethNativeContract.contractHelpers(owner);194 const flipper = await helper.eth.deployFlipper(owner);195196 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;197 await expect(helpers.methods.confirmSponsorship(flipper.options.address).call({from: notSponsor})).to.be.rejectedWith('NoPendingSponsor');198 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;199 });200201 itEth('Get self sponsored sponsor', async ({helper}) => {202 const owner = await helper.eth.createAccountWithBalance(donor);203 const helpers = helper.ethNativeContract.contractHelpers(owner);204 const flipper = await helper.eth.deployFlipper(owner);205206 await helpers.methods.selfSponsoredEnable(flipper.options.address).send();207 208 const result = await helpers.methods.sponsor(flipper.options.address).call();209210 expect(result[0]).to.be.eq(flipper.options.address);211 expect(result[1]).to.be.eq('0');212 });213214 itEth('Get confirmed sponsor', async ({helper}) => {215 const owner = await helper.eth.createAccountWithBalance(donor);216 const sponsor = await helper.eth.createAccountWithBalance(donor);217 const helpers = helper.ethNativeContract.contractHelpers(owner);218 const flipper = await helper.eth.deployFlipper(owner);219220 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();221 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});222 223 const result = await helpers.methods.sponsor(flipper.options.address).call();224225 expect(result[0]).to.be.eq(sponsor);226 expect(result[1]).to.be.eq('0');227 });228229 itEth('Sponsor can be removed by the address that deployed the contract', async ({helper}) => {230 const owner = await helper.eth.createAccountWithBalance(donor);231 const sponsor = await helper.eth.createAccountWithBalance(donor);232 const helpers = helper.ethNativeContract.contractHelpers(owner);233 const flipper = await helper.eth.deployFlipper(owner);234235 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;236 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();237 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});238 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;239 240 await helpers.methods.removeSponsor(flipper.options.address).send();241 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;242 });243244 itEth('Remove sponsor event', async ({helper}) => {245 const owner = await helper.eth.createAccountWithBalance(donor);246 const sponsor = await helper.eth.createAccountWithBalance(donor);247 const helpers = helper.ethNativeContract.contractHelpers(owner);248 const flipper = await helper.eth.deployFlipper(owner);249250 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();251 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});252 253 const result = await helpers.methods.removeSponsor(flipper.options.address).send();254 const events = helper.eth.normalizeEvents(result.events);255 expect(events).to.be.deep.equal([256 {257 address: flipper.options.address,258 event: 'ContractSponsorRemoved',259 args: {260 contractAddress: flipper.options.address,261 },262 },263 ]);264 });265266 itEth('Sponsor can not be removed by the address that did not deployed the contract', async ({helper}) => {267 const owner = await helper.eth.createAccountWithBalance(donor);268 const notOwner = await helper.eth.createAccountWithBalance(donor);269 const sponsor = await helper.eth.createAccountWithBalance(donor);270 const helpers = helper.ethNativeContract.contractHelpers(owner);271 const flipper = await helper.eth.deployFlipper(owner);272273 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;274 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();275 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});276 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;277 278 await expect(helpers.methods.removeSponsor(flipper.options.address).call({from: notOwner})).to.be.rejectedWith('NoPermission');279 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;280 });281282 itEth('In generous mode, non-allowlisted user transaction will be sponsored', async ({helper}) => {283 const owner = await helper.eth.createAccountWithBalance(donor);284 const sponsor = await helper.eth.createAccountWithBalance(donor);285 const caller = await helper.eth.createAccountWithBalance(donor);286 const helpers = helper.ethNativeContract.contractHelpers(owner);287 const flipper = await helper.eth.deployFlipper(owner);288289 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();290 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});291292 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Generous).send({from: owner});293 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});294295 const sponsorBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));296 const callerBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));297298 await flipper.methods.flip().send({from: caller});299 expect(await flipper.methods.getValue().call()).to.be.true;300301 // Balance should be taken from sponsor instead of caller302 const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));303 const callerBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));304 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;305 expect(callerBalanceAfter).to.be.eq(callerBalanceBefore);306 });307308 itEth('In generous mode, non-allowlisted user transaction will be self sponsored', async ({helper}) => {309 const owner = await helper.eth.createAccountWithBalance(donor);310 const caller = await helper.eth.createAccountWithBalance(donor);311 const helpers = helper.ethNativeContract.contractHelpers(owner);312 const flipper = await helper.eth.deployFlipper(owner);313314 await helpers.methods.selfSponsoredEnable(flipper.options.address).send();315316 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Generous).send({from: owner});317 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});318319 await helper.eth.transferBalanceFromSubstrate(donor, flipper.options.address);320321 const contractBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(flipper.options.address));322 const callerBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));323324 await flipper.methods.flip().send({from: caller});325 expect(await flipper.methods.getValue().call()).to.be.true;326327 // Balance should be taken from sponsor instead of caller328 const contractBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(flipper.options.address));329 const callerBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));330 expect(contractBalanceAfter < contractBalanceBefore).to.be.true;331 expect(callerBalanceAfter).to.be.eq(callerBalanceBefore);332 });333334 itEth('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should decrease (allowlisted)', async ({helper}) => {335 const owner = await helper.eth.createAccountWithBalance(donor);336 const sponsor = await helper.eth.createAccountWithBalance(donor);337 const caller = helper.eth.createAccount();338 const helpers = helper.ethNativeContract.contractHelpers(owner);339 const flipper = await helper.eth.deployFlipper(owner);340341 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});342 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});343344 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});345 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});346347 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();348 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});349350 const sponsorBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));351 expect(sponsorBalanceBefore).to.be.not.equal('0');352353 await flipper.methods.flip().send({from: caller});354 expect(await flipper.methods.getValue().call()).to.be.true;355356 // Balance should be taken from flipper instead of caller357 const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));358 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;359 });360361 itEth('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should not decrease (non-allowlisted)', async ({helper}) => {362 const owner = await helper.eth.createAccountWithBalance(donor);363 const caller = await helper.eth.createAccount();364 const helpers = helper.ethNativeContract.contractHelpers(owner);365 const flipper = await helper.eth.deployFlipper(owner);366367 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});368 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});369370 await helper.eth.transferBalanceFromSubstrate(donor, flipper.options.address);371372 const originalFlipperBalance = await helper.balance.getEthereum(flipper.options.address);373 expect(originalFlipperBalance).to.be.not.equal('0');374375 await expect(flipper.methods.flip().send({from: caller})).to.be.rejectedWith(/Returned error: insufficient funds for gas \* price \+ value/);376 expect(await flipper.methods.getValue().call()).to.be.false;377378 // Balance should be taken from flipper instead of caller379 // FIXME the comment is wrong! What check should be here?380 const balanceAfter = await helper.balance.getEthereum(flipper.options.address);381 expect(balanceAfter).to.be.equal(originalFlipperBalance);382 });383384 itEth('Sponsoring is set, an address that has UNQ can send a transaction and it works. User balance should not change', async ({helper}) => {385 const owner = await helper.eth.createAccountWithBalance(donor);386 const sponsor = await helper.eth.createAccountWithBalance(donor);387 const caller = await helper.eth.createAccountWithBalance(donor);388 const helpers = helper.ethNativeContract.contractHelpers(owner);389 const flipper = await helper.eth.deployFlipper(owner);390391 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});392 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});393394 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});395 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});396397 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();398 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});399400 const sponsorBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));401 const callerBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));402403 await flipper.methods.flip().send({from: caller});404 expect(await flipper.methods.getValue().call()).to.be.true;405406 const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));407 const callerBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));408 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;409 expect(callerBalanceAfter).to.be.equal(callerBalanceBefore);410 });411412 itEth('Sponsoring is limited, with setContractRateLimit. The limitation is working if transactions are sent more often, the sender pays the commission.', async ({helper}) => {413 const owner = await helper.eth.createAccountWithBalance(donor);414 const sponsor = await helper.eth.createAccountWithBalance(donor);415 const caller = await helper.eth.createAccountWithBalance(donor);416 const helpers = helper.ethNativeContract.contractHelpers(owner);417 const flipper = await helper.eth.deployFlipper(owner);418 419 const originalCallerBalance = await helper.balance.getEthereum(caller);420 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});421 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});422423 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});424 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 10).send({from: owner});425426 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();427 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});428429 const originalFlipperBalance = await helper.balance.getEthereum(sponsor);430 expect(originalFlipperBalance).to.be.not.equal('0');431432 await flipper.methods.flip().send({from: caller});433 expect(await flipper.methods.getValue().call()).to.be.true;434 expect(await helper.balance.getEthereum(caller)).to.be.equal(originalCallerBalance);435436 const newFlipperBalance = await helper.balance.getEthereum(sponsor);437 expect(newFlipperBalance).to.be.not.equal(originalFlipperBalance);438439 await flipper.methods.flip().send({from: caller});440 // todo:playgrounds fails rarely (expected 99893341659775672580n to equal 99912598679356033129n) (again, 99893341659775672580n)441 expect(await helper.balance.getEthereum(sponsor)).to.be.equal(newFlipperBalance);442 expect(await helper.balance.getEthereum(caller)).to.be.not.equal(originalCallerBalance);443 });444445 // TODO: Find a way to calculate default rate limit446 itEth('Default rate limit equal 7200', async ({helper}) => {447 const owner = await helper.eth.createAccountWithBalance(donor);448 const helpers = helper.ethNativeContract.contractHelpers(owner);449 const flipper = await helper.eth.deployFlipper(owner);450451 expect(await helpers.methods.sponsoringRateLimit(flipper.options.address).call()).to.be.equal('7200');452 });453});454455describe('Sponsoring Fee Limit', () => {456 let donor: IKeyringPair;457 let alice: IKeyringPair;458 let testContract: CompiledContract;459460 async function compileTestContract(helper: EthUniqueHelper) {461 if (!testContract) {462 testContract = await helper.ethContract.compile(463 'TestContract',464 `465 // SPDX-License-Identifier: MIT466 pragma solidity ^0.8.0;467 468 contract TestContract {469 event Result(bool);470471 function test(uint32 cycles) public {472 uint256 counter = 0;473 while(true) {474 counter ++;475 if (counter > cycles){476 break;477 }478 }479 emit Result(true);480 }481 }482 `,483 );484 }485 return testContract;486 }487 488 async function deployTestContract(helper: EthUniqueHelper, owner: string) {489 const compiled = await compileTestContract(helper);490 return await helper.ethContract.deployByAbi(owner, compiled.abi, compiled.object);491 }492493 before(async () => {494 await usingEthPlaygrounds(async (helper, privateKey) => {495 donor = await privateKey({filename: __filename});496 [alice] = await helper.arrange.createAccounts([100n], donor);497 });498 });499500 itEth('Default fee limit', async ({helper}) => {501 const owner = await helper.eth.createAccountWithBalance(donor);502 const helpers = helper.ethNativeContract.contractHelpers(owner);503 const flipper = await helper.eth.deployFlipper(owner);504505 expect(await helpers.methods.sponsoringFeeLimit(flipper.options.address).call()).to.be.equal('115792089237316195423570985008687907853269984665640564039457584007913129639935');506 });507508 itEth('Set fee limit', async ({helper}) => {509 const owner = await helper.eth.createAccountWithBalance(donor);510 const helpers = helper.ethNativeContract.contractHelpers(owner);511 const flipper = await helper.eth.deployFlipper(owner);512513 await helpers.methods.setSponsoringFeeLimit(flipper.options.address, 100).send();514 expect(await helpers.methods.sponsoringFeeLimit(flipper.options.address).call()).to.be.equal('100');515 });516517 itEth('Negative test - set fee limit by non-owner', async ({helper}) => {518 const owner = await helper.eth.createAccountWithBalance(donor);519 const stranger = await helper.eth.createAccountWithBalance(donor);520 const helpers = helper.ethNativeContract.contractHelpers(owner);521 const flipper = await helper.eth.deployFlipper(owner);522523 await expect(helpers.methods.setSponsoringFeeLimit(flipper.options.address, 100).send({from: stranger})).to.be.rejected;524 });525526 itEth('Negative test - check that eth transactions exceeding fee limit are not executed', async ({helper}) => {527 const owner = await helper.eth.createAccountWithBalance(donor);528 const sponsor = await helper.eth.createAccountWithBalance(donor);529 const user = await helper.eth.createAccountWithBalance(donor);530 const helpers = helper.ethNativeContract.contractHelpers(owner);531532 const testContract = await deployTestContract(helper, owner);533 534 await helpers.methods.setSponsoringMode(testContract.options.address, SponsoringMode.Generous).send({from: owner});535 await helpers.methods.setSponsoringRateLimit(testContract.options.address, 0).send({from: owner});536 537 await helpers.methods.setSponsor(testContract.options.address, sponsor).send();538 await helpers.methods.confirmSponsorship(testContract.options.address).send({from: sponsor});539540 const gasPrice = BigInt(await helper.getWeb3().eth.getGasPrice());541542 await helpers.methods.setSponsoringFeeLimit(testContract.options.address, 2_000_000n * gasPrice).send();543544 const originalUserBalance = await helper.balance.getEthereum(user);545 await testContract.methods.test(100).send({from: user, gas: 2_000_000});546 expect(await helper.balance.getEthereum(user)).to.be.equal(originalUserBalance);547548 await testContract.methods.test(100).send({from: user, gas: 2_100_000});549 expect(await helper.balance.getEthereum(user)).to.not.be.equal(originalUserBalance);550 });551552 itEth('Negative test - check that evm.call transactions exceeding fee limit are not executed', async ({helper}) => {553 const owner = await helper.eth.createAccountWithBalance(donor);554 const sponsor = await helper.eth.createAccountWithBalance(donor);555 const helpers = helper.ethNativeContract.contractHelpers(owner);556557 const testContract = await deployTestContract(helper, owner);558 559 await helpers.methods.setSponsoringMode(testContract.options.address, SponsoringMode.Generous).send({from: owner});560 await helpers.methods.setSponsoringRateLimit(testContract.options.address, 0).send({from: owner});561 562 await helpers.methods.setSponsor(testContract.options.address, sponsor).send();563 await helpers.methods.confirmSponsorship(testContract.options.address).send({from: sponsor});564565 const gasPrice = BigInt(await helper.getWeb3().eth.getGasPrice());566567 await helpers.methods.setSponsoringFeeLimit(testContract.options.address, 2_000_000n * gasPrice).send();568569 const originalAliceBalance = await helper.balance.getSubstrate(alice.address);570571 await helper.eth.sendEVM(572 alice,573 testContract.options.address,574 testContract.methods.test(100).encodeABI(),575 '0',576 2_000_000,577 );578 // expect((await api.query.system.account(alice.address)).data.free.toBigInt()).to.be.equal(originalAliceBalance);579 expect(await helper.balance.getSubstrate(alice.address)).to.be.equal(originalAliceBalance);580 581 await helper.eth.sendEVM(582 alice,583 testContract.options.address,584 testContract.methods.test(100).encodeABI(),585 '0',586 2_100_000,587 );588 expect(await helper.balance.getSubstrate(alice.address)).to.not.be.equal(originalAliceBalance);589 });590});1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {EthUniqueHelper} from './util/playgrounds/unique.dev';19import {itEth, expect, SponsoringMode, usingEthPlaygrounds} from './util';20import {usingPlaygrounds} from '../util';21import {CompiledContract} from './util/playgrounds/types';2223describe('Sponsoring EVM contracts', () => {24 let donor: IKeyringPair;25 let nominal: bigint;2627 before(async () => {28 await usingPlaygrounds(async (helper, privateKey) => {29 donor = await privateKey({filename: __filename});30 nominal = helper.balance.getOneTokenNominal();31 });32 });3334 itEth('Self sponsoring can be set by the address that deployed the contract', async ({helper}) => {35 const owner = await helper.eth.createAccountWithBalance(donor);36 const flipper = await helper.eth.deployFlipper(owner);37 const helpers = helper.ethNativeContract.contractHelpers(owner);3839 // 1. owner can set selfSponsoring:40 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;41 const result = await helpers.methods.selfSponsoredEnable(flipper.options.address).send({from: owner});42 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;4344 // 1.1 Can get sponsor using methods.sponsor:45 const actualSponsor = await helpers.methods.sponsor(flipper.options.address).call();46 expect(actualSponsor.eth).to.eq(flipper.options.address);47 expect(actualSponsor.sub).to.eq('0');4849 // 2. Events should be:50 const ethEvents = helper.eth.helper.eth.normalizeEvents(result.events);51 expect(ethEvents).to.be.deep.equal([52 {53 address: flipper.options.address,54 event: 'ContractSponsorSet',55 args: {56 contractAddress: flipper.options.address,57 sponsor: flipper.options.address,58 },59 },60 {61 address: flipper.options.address,62 event: 'ContractSponsorshipConfirmed',63 args: {64 contractAddress: flipper.options.address,65 sponsor: flipper.options.address,66 },67 },68 ]);69 });7071 itEth('Self sponsoring cannot be set by the address that did not deployed the contract', async ({helper}) => {72 const owner = await helper.eth.createAccountWithBalance(donor);73 const notOwner = await helper.eth.createAccountWithBalance(donor);74 const helpers = helper.ethNativeContract.contractHelpers(owner);75 const flipper = await helper.eth.deployFlipper(owner);7677 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;78 await expect(helpers.methods.selfSponsoredEnable(flipper.options.address).call({from: notOwner})).to.be.rejectedWith('NoPermission');79 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;80 });8182 itEth('Sponsoring can be set by the address that has deployed the contract', async ({helper}) => {83 const owner = await helper.eth.createAccountWithBalance(donor);84 const helpers = helper.ethNativeContract.contractHelpers(owner);85 const flipper = await helper.eth.deployFlipper(owner);8687 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;88 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});89 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;90 });9192 itEth('Sponsoring cannot be set by the address that did not deployed the contract', async ({helper}) => {93 const owner = await helper.eth.createAccountWithBalance(donor);94 const notOwner = await helper.eth.createAccountWithBalance(donor);95 const helpers = helper.ethNativeContract.contractHelpers(owner);96 const flipper = await helper.eth.deployFlipper(owner);9798 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;99 await expect(helpers.methods.setSponsoringMode(notOwner, SponsoringMode.Allowlisted).call({from: notOwner})).to.be.rejectedWith('NoPermission');100 expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;101 });102 103 itEth('Sponsor can be set by the address that deployed the contract', async ({helper}) => {104 const owner = await helper.eth.createAccountWithBalance(donor);105 const sponsor = await helper.eth.createAccountWithBalance(donor);106 const helpers = helper.ethNativeContract.contractHelpers(owner);107 const flipper = await helper.eth.deployFlipper(owner);108109 // 1. owner can set a sponsor:110 expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.false;111 const result = await helpers.methods.setSponsor(flipper.options.address, sponsor).send();112 expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.true;113114 // 2. Events should be:115 const events = helper.eth.normalizeEvents(result.events);116 expect(events).to.be.deep.equal([117 {118 address: flipper.options.address,119 event: 'ContractSponsorSet',120 args: {121 contractAddress: flipper.options.address,122 sponsor: sponsor,123 },124 },125 ]);126 });127 128 itEth('Sponsor cannot be set by the address that did not deployed the contract', async ({helper}) => {129 const owner = await helper.eth.createAccountWithBalance(donor);130 const sponsor = await helper.eth.createAccountWithBalance(donor);131 const notOwner = await helper.eth.createAccountWithBalance(donor);132 const helpers = helper.ethNativeContract.contractHelpers(owner);133 const flipper = await helper.eth.deployFlipper(owner);134135 expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.false;136 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).call({from: notOwner})).to.be.rejectedWith('NoPermission');137 expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.false;138 });139140 itEth('Sponsorship can be confirmed by the address that pending as sponsor', async ({helper}) => {141 const owner = await helper.eth.createAccountWithBalance(donor);142 const sponsor = await helper.eth.createAccountWithBalance(donor);143 const helpers = helper.ethNativeContract.contractHelpers(owner);144 const flipper = await helper.eth.deployFlipper(owner);145146 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;147 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();148149 // 1. sponsor can confirm sponsorship:150 const result = await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});151 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;152153 // 1.1 Can get sponsor using methods.sponsor:154 const actualSponsor = await helpers.methods.sponsor(flipper.options.address).call();155 expect(actualSponsor.eth).to.eq(sponsor);156 expect(actualSponsor.sub).to.eq('0');157158 // 2. Events should be:159 const events = helper.eth.normalizeEvents(result.events);160 expect(events).to.be.deep.equal([161 {162 address: flipper.options.address,163 event: 'ContractSponsorshipConfirmed',164 args: {165 contractAddress: flipper.options.address,166 sponsor: sponsor,167 },168 },169 ]);170 });171172 itEth('Sponsorship can not be confirmed by the address that not pending as sponsor', async ({helper}) => {173 const owner = await helper.eth.createAccountWithBalance(donor);174 const sponsor = await helper.eth.createAccountWithBalance(donor);175 const notSponsor = await helper.eth.createAccountWithBalance(donor);176 const helpers = helper.ethNativeContract.contractHelpers(owner);177 const flipper = await helper.eth.deployFlipper(owner);178179 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;180 await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;181 await expect(helpers.methods.confirmSponsorship(flipper.options.address).call({from: notSponsor})).to.be.rejectedWith('NoPermission');182 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;183 });184185 itEth('Sponsorship can not be confirmed by the address that not set as sponsor', async ({helper}) => {186 const owner = await helper.eth.createAccountWithBalance(donor);187 const notSponsor = await helper.eth.createAccountWithBalance(donor);188 const helpers = helper.ethNativeContract.contractHelpers(owner);189 const flipper = await helper.eth.deployFlipper(owner);190191 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;192 await expect(helpers.methods.confirmSponsorship(flipper.options.address).call({from: notSponsor})).to.be.rejectedWith('NoPendingSponsor');193 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;194 });195196 itEth('Sponsor can be removed by the address that deployed the contract', async ({helper}) => {197 const owner = await helper.eth.createAccountWithBalance(donor);198 const sponsor = await helper.eth.createAccountWithBalance(donor);199 const helpers = helper.ethNativeContract.contractHelpers(owner);200 const flipper = await helper.eth.deployFlipper(owner);201202 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;203 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();204 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});205 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;206 // 1. Can remove sponsor:207 const result = await helpers.methods.removeSponsor(flipper.options.address).send();208 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;209210 // 2. Events should be:211 const events = helper.eth.normalizeEvents(result.events);212 expect(events).to.be.deep.equal([213 {214 address: flipper.options.address,215 event: 'ContractSponsorRemoved',216 args: {217 contractAddress: flipper.options.address,218 },219 },220 ]);221222 // TODO: why call method reverts?223 // const actualSponsor = await helpers.methods.sponsor(flipper.options.address).call();224 // expect(actualSponsor.eth).to.eq(sponsor);225 // expect(actualSponsor.sub).to.eq('0');226 });227228 itEth('Sponsor can not be removed by the address that did not deployed the contract', async ({helper}) => {229 const owner = await helper.eth.createAccountWithBalance(donor);230 const notOwner = await helper.eth.createAccountWithBalance(donor);231 const sponsor = await helper.eth.createAccountWithBalance(donor);232 const helpers = helper.ethNativeContract.contractHelpers(owner);233 const flipper = await helper.eth.deployFlipper(owner);234235 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;236 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();237 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});238 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;239 240 await expect(helpers.methods.removeSponsor(flipper.options.address).call({from: notOwner})).to.be.rejectedWith('NoPermission');241 await expect(helpers.methods.removeSponsor(flipper.options.address).send({from: notOwner})).to.be.rejected;242 expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;243 });244245 itEth('In generous mode, non-allowlisted user transaction will be sponsored', async ({helper}) => {246 const owner = await helper.eth.createAccountWithBalance(donor);247 const sponsor = await helper.eth.createAccountWithBalance(donor);248 const caller = await helper.eth.createAccountWithBalance(donor);249 const helpers = helper.ethNativeContract.contractHelpers(owner);250 const flipper = await helper.eth.deployFlipper(owner);251252 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();253 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});254255 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Generous).send({from: owner});256 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});257258 const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));259 const callerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(caller));260261 await flipper.methods.flip().send({from: caller});262 expect(await flipper.methods.getValue().call()).to.be.true;263264 // Balance should be taken from sponsor instead of caller265 const sponsorBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));266 const callerBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(caller));267 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;268 expect(callerBalanceAfter).to.be.eq(callerBalanceBefore);269 });270271 itEth('In generous mode, non-allowlisted user transaction will be self sponsored', async ({helper}) => {272 const owner = await helper.eth.createAccountWithBalance(donor);273 const caller = await helper.eth.createAccountWithBalance(donor);274 const helpers = helper.ethNativeContract.contractHelpers(owner);275 const flipper = await helper.eth.deployFlipper(owner);276277 await helpers.methods.selfSponsoredEnable(flipper.options.address).send();278279 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Generous).send({from: owner});280 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});281282 await helper.eth.transferBalanceFromSubstrate(donor, flipper.options.address);283284 const contractBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(flipper.options.address));285 const callerBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));286287 await flipper.methods.flip().send({from: caller});288 expect(await flipper.methods.getValue().call()).to.be.true;289290 // Balance should be taken from sponsor instead of caller291 const contractBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(flipper.options.address));292 const callerBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));293 expect(contractBalanceAfter < contractBalanceBefore).to.be.true;294 expect(callerBalanceAfter).to.be.eq(callerBalanceBefore);295 });296297 [298 {balance: 0n, label: '0'},299 {balance: 10n, label: '10'},300 ].map(testCase => {301 itEth(`Allow-listed address that has ${testCase.label} UNQ can call a contract. Sponsor balance should decrease`, async ({helper}) => {302 const owner = await helper.eth.createAccountWithBalance(donor);303 const sponsor = await helper.eth.createAccountWithBalance(donor);304 const caller = helper.eth.createAccount();305 await helper.eth.transferBalanceFromSubstrate(donor, caller, testCase.balance);306 const helpers = helper.ethNativeContract.contractHelpers(owner);307 const flipper = await helper.eth.deployFlipper(owner);308 309 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});310 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});311 312 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});313 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});314 315 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();316 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});317 318 const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));319 expect(sponsorBalanceBefore > 0n).to.be.true;320 321 await flipper.methods.flip().send({from: caller});322 expect(await flipper.methods.getValue().call()).to.be.true;323 324 // Balance should be taken from flipper instead of caller325 const sponsorBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));326 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;327 // Caller's balance does not change:328 const callerBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(caller));329 expect(callerBalanceAfter).to.eq(testCase.balance * nominal);330 });331 });332333 itEth('Non-allow-listed address can call a contract. Sponsor balance should not decrease', async ({helper}) => {334 const owner = await helper.eth.createAccountWithBalance(donor);335 const caller = helper.eth.createAccount();336 const contractHelpers = helper.ethNativeContract.contractHelpers(owner);337338 // Deploy flipper and send some tokens:339 const flipper = await helper.eth.deployFlipper(owner);340 await helper.eth.transferBalanceFromSubstrate(donor, flipper.options.address);341 expect(await flipper.methods.getValue().call()).to.be.false;342 // flipper address has some tokens:343 const originalFlipperBalance = await helper.balance.getEthereum(flipper.options.address);344 expect(originalFlipperBalance > 0n).to.be.true;345346 // Set Allowlisted sponsoring mode. caller is not in allow list:347 await contractHelpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});348 await contractHelpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});349 await contractHelpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});350351 // 1. Caller has no UNQ and is not in allow list. So he cannot flip: 352 await expect(flipper.methods.flip().send({from: caller})).to.be.rejectedWith(/Returned error: insufficient funds for gas \* price \+ value/);353 expect(await flipper.methods.getValue().call()).to.be.false;354355 // Flipper's balance does not change:356 const balanceAfter = await helper.balance.getEthereum(flipper.options.address);357 expect(balanceAfter).to.be.equal(originalFlipperBalance);358 });359360 itEth('Sponsoring is limited, with setContractRateLimit. The limitation is working if transactions are sent more often, the sender pays the commission.', async ({helper}) => {361 const owner = await helper.eth.createAccountWithBalance(donor);362 const sponsor = await helper.eth.createAccountWithBalance(donor);363 const caller = await helper.eth.createAccountWithBalance(donor);364 const helpers = helper.ethNativeContract.contractHelpers(owner);365 const flipper = await helper.eth.deployFlipper(owner);366 367 const originalCallerBalance = await helper.balance.getEthereum(caller);368 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});369 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});370371 await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});372 await helpers.methods.setSponsoringRateLimit(flipper.options.address, 10).send({from: owner});373374 await helpers.methods.setSponsor(flipper.options.address, sponsor).send();375 await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});376377 const originalFlipperBalance = await helper.balance.getEthereum(sponsor);378 expect(originalFlipperBalance > 0n).to.be.true;379380 await flipper.methods.flip().send({from: caller});381 expect(await flipper.methods.getValue().call()).to.be.true;382 expect(await helper.balance.getEthereum(caller)).to.be.equal(originalCallerBalance);383384 const newFlipperBalance = await helper.balance.getEthereum(sponsor);385 expect(newFlipperBalance).to.be.not.equal(originalFlipperBalance);386387 await flipper.methods.flip().send({from: caller});388 // todo:playgrounds fails rarely (expected 99893341659775672580n to equal 99912598679356033129n) (again, 99893341659775672580n)389 expect(await helper.balance.getEthereum(sponsor)).to.be.equal(newFlipperBalance);390 expect(await helper.balance.getEthereum(caller)).to.be.not.equal(originalCallerBalance);391 });392393 // TODO: Find a way to calculate default rate limit394 itEth('Default rate limit equal 7200', async ({helper}) => {395 const owner = await helper.eth.createAccountWithBalance(donor);396 const helpers = helper.ethNativeContract.contractHelpers(owner);397 const flipper = await helper.eth.deployFlipper(owner);398399 expect(await helpers.methods.sponsoringRateLimit(flipper.options.address).call()).to.be.equal('7200');400 });401});402403describe('Sponsoring Fee Limit', () => {404 let donor: IKeyringPair;405 let alice: IKeyringPair;406 let testContract: CompiledContract;407408 async function compileTestContract(helper: EthUniqueHelper) {409 if (!testContract) {410 testContract = await helper.ethContract.compile(411 'TestContract',412 `413 // SPDX-License-Identifier: MIT414 pragma solidity ^0.8.0;415 416 contract TestContract {417 event Result(bool);418419 function test(uint32 cycles) public {420 uint256 counter = 0;421 while(true) {422 counter ++;423 if (counter > cycles){424 break;425 }426 }427 emit Result(true);428 }429 }430 `,431 );432 }433 return testContract;434 }435 436 async function deployTestContract(helper: EthUniqueHelper, owner: string) {437 const compiled = await compileTestContract(helper);438 return await helper.ethContract.deployByAbi(owner, compiled.abi, compiled.object);439 }440441 before(async () => {442 await usingEthPlaygrounds(async (helper, privateKey) => {443 donor = await privateKey({filename: __filename});444 [alice] = await helper.arrange.createAccounts([100n], donor);445 });446 });447448 itEth('Default fee limit', async ({helper}) => {449 const owner = await helper.eth.createAccountWithBalance(donor);450 const helpers = helper.ethNativeContract.contractHelpers(owner);451 const flipper = await helper.eth.deployFlipper(owner);452453 expect(await helpers.methods.sponsoringFeeLimit(flipper.options.address).call()).to.be.equal('115792089237316195423570985008687907853269984665640564039457584007913129639935');454 });455456 itEth('Set fee limit', async ({helper}) => {457 const owner = await helper.eth.createAccountWithBalance(donor);458 const helpers = helper.ethNativeContract.contractHelpers(owner);459 const flipper = await helper.eth.deployFlipper(owner);460461 await helpers.methods.setSponsoringFeeLimit(flipper.options.address, 100).send();462 expect(await helpers.methods.sponsoringFeeLimit(flipper.options.address).call()).to.be.equal('100');463 });464465 itEth('Negative test - set fee limit by non-owner', async ({helper}) => {466 const owner = await helper.eth.createAccountWithBalance(donor);467 const stranger = await helper.eth.createAccountWithBalance(donor);468 const helpers = helper.ethNativeContract.contractHelpers(owner);469 const flipper = await helper.eth.deployFlipper(owner);470471 await expect(helpers.methods.setSponsoringFeeLimit(flipper.options.address, 100).send({from: stranger})).to.be.rejected;472 });473474 itEth('Negative test - check that eth transactions exceeding fee limit are not executed', async ({helper}) => {475 const owner = await helper.eth.createAccountWithBalance(donor);476 const sponsor = await helper.eth.createAccountWithBalance(donor);477 const user = await helper.eth.createAccountWithBalance(donor);478 const helpers = helper.ethNativeContract.contractHelpers(owner);479480 const testContract = await deployTestContract(helper, owner);481 482 await helpers.methods.setSponsoringMode(testContract.options.address, SponsoringMode.Generous).send({from: owner});483 await helpers.methods.setSponsoringRateLimit(testContract.options.address, 0).send({from: owner});484 485 await helpers.methods.setSponsor(testContract.options.address, sponsor).send();486 await helpers.methods.confirmSponsorship(testContract.options.address).send({from: sponsor});487488 const gasPrice = BigInt(await helper.getWeb3().eth.getGasPrice());489490 await helpers.methods.setSponsoringFeeLimit(testContract.options.address, 2_000_000n * gasPrice).send();491492 const originalUserBalance = await helper.balance.getEthereum(user);493 await testContract.methods.test(100).send({from: user, gas: 2_000_000});494 expect(await helper.balance.getEthereum(user)).to.be.equal(originalUserBalance);495496 await testContract.methods.test(100).send({from: user, gas: 2_100_000});497 expect(await helper.balance.getEthereum(user)).to.not.be.equal(originalUserBalance);498 });499500 itEth('Negative test - check that evm.call transactions exceeding fee limit are not executed', async ({helper}) => {501 const owner = await helper.eth.createAccountWithBalance(donor);502 const sponsor = await helper.eth.createAccountWithBalance(donor);503 const helpers = helper.ethNativeContract.contractHelpers(owner);504505 const testContract = await deployTestContract(helper, owner);506 507 await helpers.methods.setSponsoringMode(testContract.options.address, SponsoringMode.Generous).send({from: owner});508 await helpers.methods.setSponsoringRateLimit(testContract.options.address, 0).send({from: owner});509 510 await helpers.methods.setSponsor(testContract.options.address, sponsor).send();511 await helpers.methods.confirmSponsorship(testContract.options.address).send({from: sponsor});512513 const gasPrice = BigInt(await helper.getWeb3().eth.getGasPrice());514515 await helpers.methods.setSponsoringFeeLimit(testContract.options.address, 2_000_000n * gasPrice).send();516517 const originalAliceBalance = await helper.balance.getSubstrate(alice.address);518519 await helper.eth.sendEVM(520 alice,521 testContract.options.address,522 testContract.methods.test(100).encodeABI(),523 '0',524 2_000_000,525 );526 // expect((await api.query.system.account(alice.address)).data.free.toBigInt()).to.be.equal(originalAliceBalance);527 expect(await helper.balance.getSubstrate(alice.address)).to.be.equal(originalAliceBalance);528 529 await helper.eth.sendEVM(530 alice,531 testContract.options.address,532 testContract.methods.test(100).encodeABI(),533 '0',534 2_100_000,535 );536 expect(await helper.balance.getSubstrate(alice.address)).to.not.be.equal(originalAliceBalance);537 });538});tests/src/eth/events.test.tsdiffbeforeafterboth--- a/tests/src/eth/events.test.ts
+++ b/tests/src/eth/events.test.ts
@@ -40,7 +40,7 @@
const {collectionAddress, events: ethEvents} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
await helper.wait.newBlocks(1);
{
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionCreated',
args: {
@@ -49,21 +49,21 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionCreated'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionCreated'}]);
clearEvents(ethEvents, subEvents);
}
{
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const result = await collectionHelper.methods.destroyCollection(collectionAddress).send({from:owner});
await helper.wait.newBlocks(1);
- expect(result.events).to.be.like({
+ expect(result.events).to.containSubset({
CollectionDestroyed: {
returnValues: {
collectionId: collectionAddress,
},
},
});
- expect(subEvents).to.be.like([{method: 'CollectionDestroyed'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionDestroyed'}]);
}
unsubscribe();
}
@@ -71,7 +71,7 @@
async function testCollectionPropertySetAndDeleted(helper: EthUniqueHelper, mode: TCollectionMode) {
const owner = await helper.eth.createAccountWithBalance(donor);
const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
- const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, mode, owner);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const ethEvents: any = [];
@@ -82,7 +82,7 @@
{
await collection.methods.setCollectionProperties([{key: 'A', value: [0,1,2,3]}]).send({from:owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -90,13 +90,13 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionPropertySet'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionPropertySet'}]);
clearEvents(ethEvents, subEvents);
}
{
await collection.methods.deleteCollectionProperties(['A']).send({from:owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -104,7 +104,7 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionPropertyDeleted'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionPropertyDeleted'}]);
}
unsubscribe();
}
@@ -112,7 +112,7 @@
async function testPropertyPermissionSet(helper: EthUniqueHelper, mode: TCollectionMode) {
const owner = await helper.eth.createAccountWithBalance(donor);
const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
- const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, mode, owner);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const ethEvents: any = [];
collectionHelper.events.allEvents((_: any, event: any) => {
@@ -127,7 +127,7 @@
],
]).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -135,7 +135,7 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'PropertyPermissionSet'}]);
+ expect(subEvents).to.containSubset([{method: 'PropertyPermissionSet'}]);
unsubscribe();
}
@@ -143,7 +143,7 @@
const owner = await helper.eth.createAccountWithBalance(donor);
const user = helper.ethCrossAccount.createAccount();
const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
- const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, mode, owner);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const ethEvents: any[] = [];
collectionHelper.events.allEvents((_: any, event: any) => {
@@ -154,7 +154,7 @@
{
await collection.methods.addToCollectionAllowListCross(user).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -162,14 +162,13 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'AllowListAddressAdded'}]);
+ expect(subEvents).to.containSubset([{method: 'AllowListAddressAdded'}]);
clearEvents(ethEvents, subEvents);
}
{
await collection.methods.removeFromCollectionAllowListCross(user).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents.length).to.be.eq(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -177,7 +176,7 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'AllowListAddressRemoved'}]);
+ expect(subEvents).to.containSubset([{method: 'AllowListAddressRemoved'}]);
}
unsubscribe();
}
@@ -186,7 +185,7 @@
const owner = await helper.eth.createAccountWithBalance(donor);
const user = helper.ethCrossAccount.createAccount();
const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
- const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, mode, owner);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const ethEvents: any = [];
collectionHelper.events.allEvents((_: any, event: any) => {
@@ -196,7 +195,7 @@
{
await collection.methods.addCollectionAdminCross(user).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -204,13 +203,13 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionAdminAdded'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionAdminAdded'}]);
clearEvents(ethEvents, subEvents);
}
{
await collection.methods.removeCollectionAdminCross(user).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -218,7 +217,7 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionAdminRemoved'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionAdminRemoved'}]);
}
unsubscribe();
}
@@ -226,7 +225,7 @@
async function testCollectionLimitSet(helper: EthUniqueHelper, mode: TCollectionMode) {
const owner = await helper.eth.createAccountWithBalance(donor);
const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
- const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, mode, owner);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const ethEvents: any = [];
collectionHelper.events.allEvents((_: any, event: any) => {
@@ -236,7 +235,7 @@
{
await collection.methods.setCollectionLimit(CollectionLimits.OwnerCanTransfer, true, 0).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -244,7 +243,7 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionLimitSet'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionLimitSet'}]);
}
unsubscribe();
}
@@ -253,7 +252,7 @@
const owner = await helper.eth.createAccountWithBalance(donor);
const newOwner = helper.ethCrossAccount.createAccount();
const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
- const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, mode, owner);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const ethEvents: any = [];
collectionHelper.events.allEvents((_: any, event: any) => {
@@ -263,7 +262,7 @@
{
await collection.methods.changeCollectionOwnerCross(newOwner).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -271,7 +270,7 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionOwnerChanged'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionOwnerChanged'}]);
}
unsubscribe();
}
@@ -279,7 +278,7 @@
async function testCollectionPermissionSet(helper: EthUniqueHelper, mode: TCollectionMode) {
const owner = await helper.eth.createAccountWithBalance(donor);
const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
- const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, mode, owner);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const ethEvents: any = [];
collectionHelper.events.allEvents((_: any, event: any) => {
@@ -289,7 +288,7 @@
{
await collection.methods.setCollectionMintMode(true).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -297,13 +296,13 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionPermissionSet'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionPermissionSet'}]);
clearEvents(ethEvents, subEvents);
}
{
await collection.methods.setCollectionAccess(1).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -311,7 +310,7 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionPermissionSet'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionPermissionSet'}]);
}
unsubscribe();
}
@@ -320,7 +319,7 @@
const owner = await helper.eth.createAccountWithBalance(donor);
const sponsor = await helper.ethCrossAccount.createAccountWithBalance(donor);
const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
- const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, mode, owner);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const ethEvents: any = [];
collectionHelper.events.allEvents((_: any, event: any) => {
@@ -332,21 +331,19 @@
{
await collection.methods.setCollectionSponsorCross(sponsor).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
- {
- event: 'CollectionChanged',
- returnValues: {
- collectionId: collectionAddress,
- },
+ expect(ethEvents).to.containSubset([{
+ event: 'CollectionChanged',
+ returnValues: {
+ collectionId: collectionAddress,
},
- ]);
- expect(subEvents).to.be.like([{method: 'CollectionSponsorSet'}]);
+ }]);
+ expect(subEvents).to.containSubset([{method: 'CollectionSponsorSet'}]);
clearEvents(ethEvents, subEvents);
}
{
await collection.methods.confirmCollectionSponsorship().send({from: sponsor.eth});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -354,13 +351,13 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'SponsorshipConfirmed'}]);
+ expect(subEvents).to.containSubset([{method: 'SponsorshipConfirmed'}]);
clearEvents(ethEvents, subEvents);
}
{
await collection.methods.removeCollectionSponsor().send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'CollectionChanged',
returnValues: {
@@ -368,7 +365,7 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'CollectionSponsorRemoved'}]);
+ expect(subEvents).to.containSubset([{method: 'CollectionSponsorRemoved'}]);
}
unsubscribe();
}
@@ -376,7 +373,7 @@
async function testTokenPropertySetAndDeleted(helper: EthUniqueHelper, mode: TCollectionMode) {
const owner = await helper.eth.createAccountWithBalance(donor);
const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
- const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, mode, owner);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const result = await collection.methods.mint(owner).send({from: owner});
const tokenId = result.events.Transfer.returnValues.tokenId;
@@ -397,7 +394,7 @@
{
await collection.methods.setProperties(tokenId, [{key: 'A', value: [1,2,3]}]).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'TokenChanged',
returnValues: {
@@ -405,13 +402,13 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'TokenPropertySet'}]);
+ expect(subEvents).to.containSubset([{method: 'TokenPropertySet'}]);
clearEvents(ethEvents, subEvents);
}
{
await collection.methods.deleteProperties(tokenId, ['A']).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.be.like([
+ expect(ethEvents).to.containSubset([
{
event: 'TokenChanged',
returnValues: {
@@ -419,7 +416,7 @@
},
},
]);
- expect(subEvents).to.be.like([{method: 'TokenPropertyDeleted'}]);
+ expect(subEvents).to.containSubset([{method: 'TokenPropertyDeleted'}]);
}
unsubscribe();
}
tests/src/eth/fungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/fungible.test.ts
+++ b/tests/src/eth/fungible.test.ts
@@ -79,23 +79,40 @@
expect(event.returnValues.value).to.equal('100');
});
+ [
+ 'substrate' as const,
+ 'ethereum' as const,
+ ].map(testCase => {
+ itEth(`Can perform mintCross() for ${testCase} address`, async ({helper}) => {
+ // 1. Create receiver depending on the test case:
+ const receiverEth = helper.eth.createAccount();
+ const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);
+ const receiverSub = owner;
+ const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(owner);
+
+ const ethOwner = await helper.eth.createAccountWithBalance(donor);
+ const collection = await helper.ft.mintCollection(alice);
+ await collection.addAdmin(alice, {Ethereum: ethOwner});
- itEth('Can perform mintCross()', async ({helper}) => {
- const receiverCross = helper.ethCrossAccount.fromKeyringPair(owner);
- const ethOwner = await helper.eth.createAccountWithBalance(donor);
- const collection = await helper.ft.mintCollection(alice);
- await collection.addAdmin(alice, {Ethereum: ethOwner});
-
- const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
- const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', ethOwner);
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', ethOwner);
+
+ // 2. Mint tokens:
+ const result = await collectionEvm.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, 100).send();
+
+ const event = result.events.Transfer;
+ expect(event.address).to.equal(collectionAddress);
+ expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(receiverSub.address));
+ expect(event.returnValues.value).to.equal('100');
- const result = await contract.methods.mintCross(receiverCross, 100).send();
-
- const event = result.events.Transfer;
- expect(event.address).to.equal(collectionAddress);
- expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
- expect(event.returnValues.to).to.equal(helper.address.substrateToEth(owner.address));
- expect(event.returnValues.value).to.equal('100');
+ // 3. Get balance depending on the test case:
+ let balance;
+ if (testCase === 'ethereum') balance = await collection.getBalance({Ethereum: receiverEth});
+ else if (testCase === 'substrate') balance = await collection.getBalance({Substrate: receiverSub.address});
+ // 3.1 Check balance:
+ expect(balance).to.eq(100n);
+ });
});
itEth('Can perform mintBulk()', async ({helper}) => {
@@ -169,6 +186,68 @@
}
});
+ itEth('Can perform approveCross()', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const spender = helper.eth.createAccount();
+ const spenderSub = (await helper.arrange.createAccounts([1n], donor))[0];
+ const spenderCrossEth = helper.ethCrossAccount.fromAddress(spender);
+ const spenderCrossSub = helper.ethCrossAccount.fromKeyringPair(spenderSub);
+
+
+ const collection = await helper.ft.mintCollection(alice);
+ await collection.mint(alice, 200n, {Ethereum: owner});
+
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
+
+ {
+ const result = await contract.methods.approveCross(spenderCrossEth, 100).send({from: owner});
+ const event = result.events.Approval;
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.owner).to.be.equal(owner);
+ expect(event.returnValues.spender).to.be.equal(spender);
+ expect(event.returnValues.value).to.be.equal('100');
+ }
+
+ {
+ const allowance = await contract.methods.allowance(owner, spender).call();
+ expect(+allowance).to.equal(100);
+ }
+
+
+ {
+ const result = await contract.methods.approveCross(spenderCrossSub, 100).send({from: owner});
+ const event = result.events.Approval;
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.owner).to.be.equal(owner);
+ expect(event.returnValues.spender).to.be.equal(helper.address.substrateToEth(spenderSub.address));
+ expect(event.returnValues.value).to.be.equal('100');
+ }
+
+ {
+ const allowance = await collection.getApprovedTokens({Ethereum: owner}, {Substrate: spenderSub.address});
+ expect(allowance).to.equal(100n);
+ }
+
+ {
+ //TO-DO expect with future allowanceCross(owner, spenderCrossEth).call()
+ }
+ });
+
+ itEth('Non-owner and non admin cannot approveCross', async ({helper}) => {
+ const nonOwner = await helper.eth.createAccountWithBalance(donor);
+ const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const collection = await helper.ft.mintCollection(alice, {name: 'A', description: 'B', tokenPrefix: 'C'});
+ await collection.mint(alice, 100n, {Ethereum: owner});
+
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
+
+ await expect(collectionEvm.methods.approveCross(nonOwnerCross, 20).call({from: nonOwner})).to.be.rejectedWith('CantApproveMoreThanOwned');
+ });
+
+
itEth('Can perform burnFromCross()', async ({helper}) => {
const sender = await helper.eth.createAccountWithBalance(donor, 100n);
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -175,55 +175,82 @@
// expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);
});
- itEth('Can perform mintCross()', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const receiverCross = helper.ethCrossAccount.fromKeyringPair(bob);
- const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });
- const permissions: ITokenPropertyPermission[] = properties
- .map(p => {
- return {
- key: p.key, permission: {
- tokenOwner: true,
- collectionAdmin: true,
- mutable: true,
- },
- };
- });
+ // TODO combine all minting tests in one place
+ [
+ 'substrate' as const,
+ 'ethereum' as const,
+ ].map(testCase => {
+ itEth(`Can perform mintCross() for ${testCase} address`, async ({helper}) => {
+ const collectionAdmin = await helper.eth.createAccountWithBalance(donor);
+
+ const receiverEth = helper.eth.createAccount();
+ const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);
+ const receiverSub = bob;
+ const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);
+
+ // const receiverCross = helper.ethCrossAccount.fromKeyringPair(bob);
+ const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });
+ const permissions: ITokenPropertyPermission[] = properties
+ .map(p => {
+ return {
+ key: p.key, permission: {
+ tokenOwner: false,
+ collectionAdmin: true,
+ mutable: false,
+ },
+ };
+ });
- const collection = await helper.nft.mintCollection(minter, {
- tokenPrefix: 'ethp',
- tokenPropertyPermissions: permissions,
- });
- await collection.addAdmin(minter, {Ethereum: caller});
+ const collection = await helper.nft.mintCollection(minter, {
+ tokenPrefix: 'ethp',
+ tokenPropertyPermissions: permissions,
+ });
+ await collection.addAdmin(minter, {Ethereum: collectionAdmin});
- const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
- const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', caller, true);
- let expectedTokenId = await contract.methods.nextTokenId().call();
- let result = await contract.methods.mintCross(receiverCross, []).send();
- let tokenId = result.events.Transfer.returnValues.tokenId;
- expect(tokenId).to.be.equal(expectedTokenId);
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', collectionAdmin, true);
+ let expectedTokenId = await contract.methods.nextTokenId().call();
+ let result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, []).send();
+ let tokenId = result.events.Transfer.returnValues.tokenId;
+ expect(tokenId).to.be.equal(expectedTokenId);
- let event = result.events.Transfer;
- expect(event.address).to.be.equal(collectionAddress);
- expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
- expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));
- expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);
+ let event = result.events.Transfer;
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));
+ expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);
- expectedTokenId = await contract.methods.nextTokenId().call();
- result = await contract.methods.mintCross(receiverCross, properties).send();
- event = result.events.Transfer;
- expect(event.address).to.be.equal(collectionAddress);
- expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
- expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));
- expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);
+ expectedTokenId = await contract.methods.nextTokenId().call();
+ result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, properties).send();
+ event = result.events.Transfer;
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));
+ expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);
- tokenId = result.events.Transfer.returnValues.tokenId;
+ tokenId = result.events.Transfer.returnValues.tokenId;
- expect(tokenId).to.be.equal(expectedTokenId);
+ expect(tokenId).to.be.equal(expectedTokenId);
- expect(await contract.methods.properties(tokenId, []).call()).to.be.like(properties
- .map(p => { return helper.ethProperty.property(p.key, p.value.toString()); }));
+ expect(await contract.methods.properties(tokenId, []).call()).to.be.like(properties
+ .map(p => { return helper.ethProperty.property(p.key, p.value.toString()); }));
+
+ expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId))
+ .to.deep.eq(testCase === 'ethereum' ? {Ethereum: receiverEth.toLowerCase()} : {Substrate: receiverSub.address});
+ });
+ });
+
+ itEth('Non-owner and non admin cannot mintCross', async ({helper}) => {
+ const nonOwner = await helper.eth.createAccountWithBalance(donor);
+ const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);
+
+ const collection = await helper.nft.mintCollection(minter);
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft');
+
+ await expect(collectionEvm.methods.mintCross(nonOwnerCross, []).call({from: nonOwner}))
+ .to.be.rejectedWith('PublicMintingNotAllowed');
});
//TODO: CORE-302 add eth methods
@@ -375,6 +402,8 @@
},
});
}
+
+ expect(await helper.nft.doesTokenExist(collection.collectionId, token.tokenId)).to.be.false;
});
itEth('Can perform transfer with ApprovalForAll', async ({helper}) => {
@@ -455,6 +484,7 @@
expect(await token2.doesExist()).to.be.false;
});
+ // TODO combine all approve tests in one place
itEth('Can perform approveCross()', async ({helper}) => {
// arrange: create accounts
const owner = await helper.eth.createAccountWithBalance(donor, 100n);
@@ -503,6 +533,17 @@
expect(await helper.nft.getTokenOwner(collection.collectionId, token2.tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});
});
+ itEth('Non-owner and non admin cannot approveCross', async ({helper}) => {
+ const nonOwner = await helper.eth.createAccountWithBalance(donor);
+ const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});
+ const collectionEvm = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');
+ const token = await collection.mintToken(minter, {Ethereum: owner});
+
+ await expect(collectionEvm.methods.approveCross(nonOwnerCross, token.tokenId).call({from: nonOwner})).to.be.rejectedWith('CantApproveMoreThanOwned');
+ });
+
itEth('Can reaffirm approved address', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor, 100n);
const ownerCrossEth = helper.ethCrossAccount.fromAddress(owner);
tests/src/eth/reFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -137,48 +137,63 @@
expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');
});
- itEth('Can perform mintCross()', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const receiverCross = helper.ethCrossAccount.fromKeyringPair(bob);
- const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });
- const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.key, permission: {tokenOwner: true,
- collectionAdmin: true,
- mutable: true}}; });
+ [
+ 'substrate' as const,
+ 'ethereum' as const,
+ ].map(testCase => {
+ itEth(`Can perform mintCross() for ${testCase} address`, async ({helper}) => {
+ const collectionAdmin = await helper.eth.createAccountWithBalance(donor);
+
+ const receiverEth = helper.eth.createAccount();
+ const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);
+ const receiverSub = bob;
+ const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);
+
+ const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });
+ const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.key, permission: {
+ tokenOwner: false,
+ collectionAdmin: true,
+ mutable: false}};
+ });
- const collection = await helper.rft.mintCollection(minter, {
- tokenPrefix: 'ethp',
- tokenPropertyPermissions: permissions,
- });
- await collection.addAdmin(minter, {Ethereum: caller});
+ const collection = await helper.rft.mintCollection(minter, {
+ tokenPrefix: 'ethp',
+ tokenPropertyPermissions: permissions,
+ });
+ await collection.addAdmin(minter, {Ethereum: collectionAdmin});
- const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
- const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller, true);
- let expectedTokenId = await contract.methods.nextTokenId().call();
- let result = await contract.methods.mintCross(receiverCross, []).send();
- let tokenId = result.events.Transfer.returnValues.tokenId;
- expect(tokenId).to.be.equal(expectedTokenId);
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', collectionAdmin, true);
+ let expectedTokenId = await contract.methods.nextTokenId().call();
+ let result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, []).send();
+ let tokenId = result.events.Transfer.returnValues.tokenId;
+ expect(tokenId).to.be.equal(expectedTokenId);
- let event = result.events.Transfer;
- expect(event.address).to.be.equal(collectionAddress);
- expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
- expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));
- expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);
+ let event = result.events.Transfer;
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));
+ expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);
- expectedTokenId = await contract.methods.nextTokenId().call();
- result = await contract.methods.mintCross(receiverCross, properties).send();
- event = result.events.Transfer;
- expect(event.address).to.be.equal(collectionAddress);
- expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
- expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));
- expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);
+ expectedTokenId = await contract.methods.nextTokenId().call();
+ result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, properties).send();
+ event = result.events.Transfer;
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));
+ expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);
- tokenId = result.events.Transfer.returnValues.tokenId;
+ tokenId = result.events.Transfer.returnValues.tokenId;
- expect(tokenId).to.be.equal(expectedTokenId);
+ expect(tokenId).to.be.equal(expectedTokenId);
- expect(await contract.methods.properties(tokenId, []).call()).to.be.like(properties
- .map(p => { return helper.ethProperty.property(p.key, p.value.toString()); }));
+ expect(await contract.methods.properties(tokenId, []).call()).to.be.like(properties
+ .map(p => { return helper.ethProperty.property(p.key, p.value.toString()); }));
+
+ expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId))
+ .to.deep.eq(testCase === 'ethereum' ? {Ethereum: receiverEth.toLowerCase()} : {Substrate: receiverSub.address});
+ });
});
itEth.skip('Can perform mintBulk()', async ({helper}) => {
tests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungibleToken.test.ts
+++ b/tests/src/eth/reFungibleToken.test.ts
@@ -207,7 +207,20 @@
//TO-DO expect with future allowanceCross(owner, spenderCrossEth).call()
}
});
-
+
+ itEth('Non-owner and non admin cannot approveCross', async ({helper}) => {
+ const nonOwner = await helper.eth.createAccountWithBalance(donor);
+ const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const collection = await helper.rft.mintCollection(alice, {name: 'A', description: 'B', tokenPrefix: 'C'});
+ const token = await collection.mintToken(alice, 100n, {Ethereum: owner});
+
+ const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, token.tokenId);
+ const tokenEvm = helper.ethNativeContract.rftToken(tokenAddress, owner);
+
+ await expect(tokenEvm.methods.approveCross(nonOwnerCross, 20).call({from: nonOwner})).to.be.rejectedWith('CantApproveMoreThanOwned');
+ });
+
[
'transferFrom',
'transferFromCross',
tests/src/eth/tokenProperties.test.tsdiffbeforeafterboth--- a/tests/src/eth/tokenProperties.test.ts
+++ b/tests/src/eth/tokenProperties.test.ts
@@ -37,7 +37,7 @@
{mode: 'nft' as const, requiredPallets: []},
{mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
].map(testCase =>
- itEth.ifWithPallets(`[${testCase.mode}] Set and get token property permissions`, testCase.requiredPallets, async({helper}) => {
+ itEth.ifWithPallets(`[${testCase.mode}] Can set all possible token property permissions`, testCase.requiredPallets, async({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const caller = await helper.ethCrossAccount.createAccountWithBalance(donor);
for(const [mutable,collectionAdmin, tokenOwner] of cartesian([], [false, true], [false, true], [false, true])) {
@@ -72,11 +72,11 @@
{mode: 'nft' as const, requiredPallets: []},
{mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
].map(testCase =>
- itEth.ifWithPallets(`[${testCase.mode}] Set and get multiple token property permissions as owner`, testCase.requiredPallets, async({helper}) => {
+ itEth.ifWithPallets(`[${testCase.mode}] Can set multiple token property permissions as owner`, testCase.requiredPallets, async({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const {collectionId, collectionAddress} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');
- const collection = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
await collection.methods.setTokenPropertyPermissions([
['testKey_0', [
@@ -128,19 +128,18 @@
[EthTokenPermissions.CollectionAdmin.toString(), false]],
],
]);
-
}));
[
{mode: 'nft' as const, requiredPallets: []},
{mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
].map(testCase =>
- itEth.ifWithPallets(`[${testCase.mode}] Set and get multiple token property permissions as admin`, testCase.requiredPallets, async({helper}) => {
+ itEth.ifWithPallets(`[${testCase.mode}] Can set multiple token property permissions as admin`, testCase.requiredPallets, async({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const caller = await helper.ethCrossAccount.createAccountWithBalance(donor);
const {collectionId, collectionAddress} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');
- const collection = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
await collection.methods.addCollectionAdminCross(caller).send({from: owner});
await collection.methods.setTokenPropertyPermissions([
@@ -452,12 +451,12 @@
{mode: 'nft' as const, requiredPallets: []},
{mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
].map(testCase =>
- itEth.ifWithPallets(`[${testCase.mode}] Cant set token property permissions as non owner or admin`, testCase.requiredPallets, async({helper}) => {
+ itEth.ifWithPallets(`[${testCase.mode}] Cannot set token property permissions as non owner or admin`, testCase.requiredPallets, async({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const caller = await helper.eth.createAccountWithBalance(donor);
const {collectionAddress} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');
- const collection = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
await expect(collection.methods.setTokenPropertyPermissions([
['testKey_0', [
@@ -472,11 +471,11 @@
{mode: 'nft' as const, requiredPallets: []},
{mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
].map(testCase =>
- itEth.ifWithPallets(`[${testCase.mode}] Cant set token property permissions with invalid character`, testCase.requiredPallets, async({helper}) => {
+ itEth.ifWithPallets(`[${testCase.mode}] Cannot set token property permissions with invalid character`, testCase.requiredPallets, async({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const {collectionAddress} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');
- const collection = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
await expect(collection.methods.setTokenPropertyPermissions([
// "Space" is invalid character
@@ -487,7 +486,73 @@
],
]).call({from: owner})).to.be.rejectedWith('InvalidCharacterInPropertyKey');
}));
-
+
+ [
+ {mode: 'nft' as const, requiredPallets: []},
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ ].map(testCase =>
+ itEth.ifWithPallets(`[${testCase.mode}] Can reconfigure token property permissions to stricter ones`, testCase.requiredPallets, async({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+
+ const {collectionAddress, collectionId} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');
+ const collection = helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
+
+ // 1. Owner sets strict property-permissions:
+ await collection.methods.setTokenPropertyPermissions([
+ ['testKey', [
+ [EthTokenPermissions.Mutable, true],
+ [EthTokenPermissions.TokenOwner, true],
+ [EthTokenPermissions.CollectionAdmin, true]],
+ ],
+ ]).send({from: owner});
+
+ // 2. Owner can set stricter property-permissions:
+ for(const values of [[true, true, false], [true, false, false], [false, false, false]]) {
+ await collection.methods.setTokenPropertyPermissions([
+ ['testKey', [
+ [EthTokenPermissions.Mutable, values[0]],
+ [EthTokenPermissions.TokenOwner, values[1]],
+ [EthTokenPermissions.CollectionAdmin, values[2]]],
+ ],
+ ]).send({from: owner});
+ }
+
+ expect(await helper[testCase.mode].getPropertyPermissions(collectionId)).to.be.deep.equal([{
+ key: 'testKey',
+ permission: {mutable: false, collectionAdmin: false, tokenOwner: false},
+ }]);
+ }));
+
+ [
+ {mode: 'nft' as const, requiredPallets: []},
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ ].map(testCase =>
+ itEth.ifWithPallets(`[${testCase.mode}] Cannot reconfigure token property permissions to less strict ones`, testCase.requiredPallets, async({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+
+ const {collectionAddress} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');
+ const collection = helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
+
+ // 1. Owner sets strict property-permissions:
+ await collection.methods.setTokenPropertyPermissions([
+ ['testKey', [
+ [EthTokenPermissions.Mutable, false],
+ [EthTokenPermissions.TokenOwner, false],
+ [EthTokenPermissions.CollectionAdmin, false]],
+ ],
+ ]).send({from: owner});
+
+ // 2. Owner cannot set less strict property-permissions:
+ for(const values of [[true, false, false], [false, true, false], [false, false, true]]) {
+ await expect(collection.methods.setTokenPropertyPermissions([
+ ['testKey', [
+ [EthTokenPermissions.Mutable, values[0]],
+ [EthTokenPermissions.TokenOwner, values[1]],
+ [EthTokenPermissions.CollectionAdmin, values[2]]],
+ ],
+ ]).call({from: owner})).to.be.rejectedWith('NoPermission');
+ }
+ }));
});
tests/src/util/index.tsdiffbeforeafterboth--- a/tests/src/util/index.ts
+++ b/tests/src/util/index.ts
@@ -6,6 +6,7 @@
import {IKeyringPair} from '@polkadot/types/types/interfaces';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
+import chaiSubset from 'chai-subset';
import {Context} from 'mocha';
import config from '../config';
import {ChainHelperBase} from './playgrounds/unique';
@@ -13,6 +14,7 @@
import {DevUniqueHelper, SilentLogger, SilentConsole, DevMoonbeamHelper, DevMoonriverHelper, DevAcalaHelper, DevKaruraHelper, DevRelayHelper, DevWestmintHelper} from './playgrounds/unique.dev';
chai.use(chaiAsPromised);
+chai.use(chaiSubset);
export const expect = chai.expect;
const getTestHash = (filename: string) => {
tests/src/vesting.test.tsdiffbeforeafterboth--- a/tests/src/vesting.test.ts
+++ b/tests/src/vesting.test.ts
@@ -32,8 +32,12 @@
// arrange
const [sender, recepient] = await helper.arrange.createAccounts([1000n, 1n], donor);
const currentRelayBlock = await helper.chain.getRelayBlockNumber();
- const schedule1 = {start: currentRelayBlock + 4n, period: 4n, periodCount: 2n, perPeriod: 50n * nominal};
- const schedule2 = {start: currentRelayBlock + 8n, period: 8n, periodCount: 2n, perPeriod: 100n * nominal};
+ const SCHEDULE_1_PERIOD = 4n; // 6 blocks one period
+ const SCHEDULE_1_START = currentRelayBlock + 6n; // Block when 1 schedule starts
+ const SCHEDULE_2_PERIOD = 8n; // 12 blocks one period
+ const SCHEDULE_2_START = currentRelayBlock + 12n; // Block when 2 schedule starts
+ const schedule1 = {start: SCHEDULE_1_START, period: SCHEDULE_1_PERIOD, periodCount: 2n, perPeriod: 50n * nominal};
+ const schedule2 = {start: SCHEDULE_2_START, period: SCHEDULE_2_PERIOD, periodCount: 2n, perPeriod: 100n * nominal};
// act
await helper.balance.vestedTransfer(sender, recepient.address, schedule1);
@@ -59,20 +63,22 @@
expect(schedule[0]).to.deep.eq(schedule1);
expect(schedule[1]).to.deep.eq(schedule2);
- await helper.wait.forRelayBlockNumber(currentRelayBlock + 8n);
+ // Wait first part available:
+ await helper.wait.forRelayBlockNumber(SCHEDULE_1_START + SCHEDULE_1_PERIOD);
await helper.balance.claim(recepient);
- // check recepient balance after claim (50 tokens claimed):
+ // check recepient balance after claim (50 tokens claimed, 250 left):
balanceRecepient = await helper.balance.getSubstrateFull(recepient.address);
expect(balanceRecepient.free / nominal).to.eq(300n);
expect(balanceRecepient.feeFrozen).to.eq(250n * nominal);
expect(balanceRecepient.miscFrozen).to.eq(250n * nominal);
expect(balanceRecepient.reserved).to.eq(0n);
- await helper.wait.forRelayBlockNumber(currentRelayBlock + 16n);
+ // Wait first schedule ends and first part od second schedule:
+ await helper.wait.forRelayBlockNumber(SCHEDULE_2_START + SCHEDULE_2_PERIOD);
await helper.balance.claim(recepient);
- // check recepient balance after second claim (150 tokens claimed):
+ // check recepient balance after second claim (150 tokens claimed, 100 left):
balanceRecepient = await helper.balance.getSubstrateFull(recepient.address);
expect(balanceRecepient.free / nominal).to.eq(300n);
expect(balanceRecepient.feeFrozen).to.eq(100n * nominal);
@@ -84,10 +90,11 @@
expect(schedule).to.has.length(1);
expect(schedule[0]).to.deep.eq(schedule2);
- await helper.wait.forRelayBlockNumber(currentRelayBlock + 24n);
+ // Wait 2 schedule ends:
+ await helper.wait.forRelayBlockNumber(SCHEDULE_2_START + SCHEDULE_2_PERIOD * 2n);
await helper.balance.claim(recepient);
- // check recepient balance after second claim (100 tokens claimed):
+ // check recepient balance after second claim (100 tokens claimed, 0 left):
balanceRecepient = await helper.balance.getSubstrateFull(recepient.address);
expect(balanceRecepient.free / nominal).to.eq(300n);
expect(balanceRecepient.feeFrozen).to.eq(0n);
tests/yarn.lockdiffbeforeafterboth--- a/tests/yarn.lock
+++ b/tests/yarn.lock
@@ -979,6 +979,13 @@
dependencies:
"@types/chai" "*"
+"@types/chai-subset@^1.3.3":
+ version "1.3.3"
+ resolved "https://registry.yarnpkg.com/@types/chai-subset/-/chai-subset-1.3.3.tgz#97893814e92abd2c534de422cb377e0e0bdaac94"
+ integrity sha512-frBecisrNGz+F4T6bcc+NLeolfiojh5FxW2klu669+8BARtyQv2C/GkNW6FUodVe4BroGMP/wER/YDGc7rEllw==
+ dependencies:
+ "@types/chai" "*"
+
"@types/chai@*", "@types/chai@^4.3.3":
version "4.3.4"
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.3.4.tgz#e913e8175db8307d78b4e8fa690408ba6b65dee4"
@@ -1569,6 +1576,11 @@
resolved "https://registry.yarnpkg.com/chai-like/-/chai-like-1.1.1.tgz#8c558a414c34514e814d497c772547ceb7958f64"
integrity sha512-VKa9z/SnhXhkT1zIjtPACFWSoWsqVoaz1Vg+ecrKo5DCKVlgL30F/pEyEvXPBOVwCgLZcWUleCM/C1okaKdTTA==
+chai-subset@^1.6.0:
+ version "1.6.0"
+ resolved "https://registry.yarnpkg.com/chai-subset/-/chai-subset-1.6.0.tgz#a5d0ca14e329a79596ed70058b6646bd6988cfe9"
+ integrity sha512-K3d+KmqdS5XKW5DWPd5sgNffL3uxdDe+6GdnJh3AYPhwnBGRY5urfvfcbRtWIvvpz+KxkL9FeBB6MZewLUNwug==
+
chai@^4.3.6:
version "4.3.7"
resolved "https://registry.yarnpkg.com/chai/-/chai-4.3.7.tgz#ec63f6df01829088e8bf55fca839bcd464a8ec51"