difftreelog
test run eslint --fix
in: master
20 files changed
tests/src/benchmarks/mintFee/index.tsdiffbeforeafterboth--- a/tests/src/benchmarks/mintFee/index.ts
+++ b/tests/src/benchmarks/mintFee/index.ts
@@ -222,9 +222,7 @@
await collection.mintToken(
donor,
{Substrate: susbstrateReceiver.address},
- PROPERTIES.slice(0, setup.propertiesNumber).map((p) => {
- return {key: p.key, value: Buffer.from(p.value).toString()};
- }),
+ PROPERTIES.slice(0, setup.propertiesNumber).map((p) => ({key: p.key, value: Buffer.from(p.value).toString()})),
);
},
);
tests/src/benchmarks/opsFee/index.tsdiffbeforeafterboth--- a/tests/src/benchmarks/opsFee/index.ts
+++ b/tests/src/benchmarks/opsFee/index.ts
@@ -379,7 +379,7 @@
res['setCollectionProperties'].substrate = convertToTokens((await helper.arrange.calculcateFee(
{Substrate: donor.address},
() => collection.setProperties(donor, PROPERTIES.slice(0, 1)
- .map(p => { return {key: p.key, value: p.value.toString()}; })),
+ .map(p => ({key: p.key, value: p.value.toString()}))),
)));
res['deleteCollectionProperties'].substrate = convertToTokens((await helper.arrange.calculcateFee(
@@ -755,7 +755,7 @@
res['setCollectionProperties'].substrate = convertToTokens((await helper.arrange.calculcateFee(
{Substrate: donor.address},
() => collection.setProperties(donor, PROPERTIES.slice(0, 1)
- .map(p => { return {key: p.key, value: p.value.toString()}; })),
+ .map(p => ({key: p.key, value: p.value.toString()}))),
)));
res['deleteCollectionProperties'].substrate = convertToTokens((await helper.arrange.calculcateFee(
tests/src/benchmarks/utils/common.tsdiffbeforeafterboth--- a/tests/src/benchmarks/utils/common.ts
+++ b/tests/src/benchmarks/utils/common.ts
@@ -5,32 +5,26 @@
export const PROPERTIES = Array(40)
.fill(0)
- .map((_, i) => {
- return {
- key: `key_${i}`,
- value: Uint8Array.from(Buffer.from(`value_${i}`)),
- };
- });
+ .map((_, i) => ({
+ key: `key_${i}`,
+ value: Uint8Array.from(Buffer.from(`value_${i}`)),
+ }));
export const SUBS_PROPERTIES = Array(40)
.fill(0)
- .map((_, i) => {
- return {
- key: `key_${i}`,
- value: `value_${i}`,
- };
- });
+ .map((_, i) => ({
+ key: `key_${i}`,
+ value: `value_${i}`,
+ }));
-export const PERMISSIONS: ITokenPropertyPermission[] = PROPERTIES.map((p) => {
- return {
- key: p.key,
- permission: {
- tokenOwner: true,
- collectionAdmin: true,
- mutable: true,
- },
- };
-});
+export const PERMISSIONS: ITokenPropertyPermission[] = PROPERTIES.map((p) => ({
+ key: p.key,
+ permission: {
+ tokenOwner: true,
+ collectionAdmin: true,
+ mutable: true,
+ },
+}));
export function convertToTokens(value: bigint, nominal = 1000_000_000_000_000_000n): number {
return Number((value * 1000n) / nominal) / 1000;
tests/src/eth/collectionAdmin.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.3// Unique Network is free software: you can redistribute it and/or modify4// it under the terms of the GNU General Public License as published by5// the Free Software Foundation, either version 3 of the License, or6// (at your option) any later version.7//8// Unique Network is distributed in the hope that it will be useful,9// but WITHOUT ANY WARRANTY; without even the implied warranty of10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11// GNU General Public License for more details.1213// You should have received a copy of the GNU General Public License14// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1516import {IKeyringPair} from '@polkadot/types/types';17import {expect} from 'chai';18import {Pallets} from '../util';19import {IEthCrossAccountId} from '../util/playgrounds/types';20import {usingEthPlaygrounds, itEth} from './util';21import {EthUniqueHelper} from './util/playgrounds/unique.dev';2223async function recordEthFee(helper: EthUniqueHelper, userAddress: string, call: () => Promise<any>) {24 const before = await helper.balance.getSubstrate(helper.address.ethToSubstrate(userAddress));25 await call();26 await helper.wait.newBlocks(1);27 const after = await helper.balance.getSubstrate(helper.address.ethToSubstrate(userAddress));2829 expect(after < before).to.be.true;3031 return before - after;32}3334describe('Add collection admins', () => {35 let donor: IKeyringPair;3637 before(async function() {38 await usingEthPlaygrounds(async (_helper, privateKey) => {39 donor = await privateKey({url: import.meta.url});40 });41 });4243 [44 {mode: 'nft' as const, requiredPallets: []},45 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},46 {mode: 'ft' as const, requiredPallets: []},47 ].map(testCase => {48 itEth.ifWithPallets(`can add account admin by owner for ${testCase.mode}`, testCase.requiredPallets, async ({helper, privateKey}) => {49 // arrange50 const owner = await helper.eth.createAccountWithBalance(donor);51 const adminSub = await privateKey('//admin2');52 const adminEth = helper.eth.createAccount().toLowerCase();5354 const adminDeprecated = helper.eth.createAccount().toLowerCase();55 const adminCrossSub = helper.ethCrossAccount.fromKeyringPair(adminSub);56 const adminCrossEth = helper.ethCrossAccount.fromAddress(adminEth);5758 const {collectionAddress, collectionId} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');59 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner, true);6061 // Check isOwnerOrAdminCross returns false:62 expect(await collectionEvm.methods.isOwnerOrAdminCross(adminCrossSub).call()).to.be.false;63 expect(await collectionEvm.methods.isOwnerOrAdminCross(adminCrossEth).call()).to.be.false;64 expect(await collectionEvm.methods.isOwnerOrAdminCross(helper.ethCrossAccount.fromAddress(adminDeprecated)).call()).to.be.false;6566 // Soft-deprecated: can addCollectionAdmin67 await collectionEvm.methods.addCollectionAdmin(adminDeprecated).send();68 // Can addCollectionAdminCross for substrate and ethereum address69 await collectionEvm.methods.addCollectionAdminCross(adminCrossSub).send();70 await collectionEvm.methods.addCollectionAdminCross(adminCrossEth).send();7172 // 1. Expect api.rpc.unique.adminlist returns admins:73 const adminListRpc = await helper.collection.getAdmins(collectionId);74 expect(adminListRpc).to.has.length(3);75 expect(adminListRpc).to.be.deep.contain.members([{Substrate: adminSub.address}, {Ethereum: adminEth}, {Ethereum: adminDeprecated}]);7677 // 2. Expect methods.collectionAdmins == api.rpc.unique.adminlist78 let adminListEth = await collectionEvm.methods.collectionAdmins().call();79 adminListEth = adminListEth.map((element: IEthCrossAccountId) => {80 return helper.address.convertCrossAccountFromEthCrossAccount(element);81 });82 expect(adminListRpc).to.be.like(adminListEth);8384 // 3. check isOwnerOrAdminCross returns true:85 expect(await collectionEvm.methods.isOwnerOrAdminCross(adminCrossSub).call()).to.be.true;86 expect(await collectionEvm.methods.isOwnerOrAdminCross(adminCrossEth).call()).to.be.true;87 expect(await collectionEvm.methods.isOwnerOrAdminCross(helper.ethCrossAccount.fromAddress(adminDeprecated)).call()).to.be.true;88 });89 });9091 itEth('cross account admin can mint', async ({helper}) => {92 // arrange: create collection and accounts93 const owner = await helper.eth.createAccountWithBalance(donor);94 const {collectionAddress, collectionId} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', 'a', 'b', 'uri');95 const adminEth = (await helper.eth.createAccountWithBalance(donor)).toLowerCase();96 const adminCrossEth = helper.ethCrossAccount.fromAddress(adminEth);97 const [adminSub] = await helper.arrange.createAccounts([100n], donor);98 const adminCrossSub = helper.ethCrossAccount.fromKeyringPair(adminSub);99 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);100101 // cannot mint while not admin102 await expect(collectionEvm.methods.mint(owner).send({from: adminEth})).to.be.rejected;103 await expect(helper.nft.mintToken(adminSub, {collectionId, owner: {Ethereum: owner}})).to.be.rejectedWith(/common.PublicMintingNotAllowed/);104105 // admin (sub and eth) can mint token:106 await collectionEvm.methods.addCollectionAdminCross(adminCrossEth).send();107 await collectionEvm.methods.addCollectionAdminCross(adminCrossSub).send();108 await collectionEvm.methods.mint(owner).send({from: adminEth});109 await helper.nft.mintToken(adminSub, {collectionId, owner: {Ethereum: owner}});110111 expect(await helper.collection.getLastTokenId(collectionId)).to.eq(2);112 });113114 itEth('cannot add invalid cross account admin', async ({helper}) => {115 const owner = await helper.eth.createAccountWithBalance(donor);116 const [admin] = await helper.arrange.createAccounts([100n, 100n], donor);117118 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');119 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);120121 const adminCross = {122 eth: helper.address.substrateToEth(admin.address),123 sub: admin.addressRaw,124 };125 await expect(collectionEvm.methods.addCollectionAdminCross(adminCross).send()).to.be.rejected;126 });127128 itEth('can verify owner with methods.isOwnerOrAdmin[Cross]', async ({helper, privateKey}) => {129 const owner = await helper.eth.createAccountWithBalance(donor);130 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');131132 const adminDeprecated = helper.eth.createAccount();133 const admin1Cross = helper.ethCrossAccount.fromKeyringPair(await privateKey('admin'));134 const admin2Cross = helper.ethCrossAccount.fromAddress(helper.address.substrateToEth((await privateKey('admin3')).address));135 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);136137 // Soft-deprecated:138 expect(await collectionEvm.methods.isOwnerOrAdmin(adminDeprecated).call()).to.be.false;139 expect(await collectionEvm.methods.isOwnerOrAdminCross(admin1Cross).call()).to.be.false;140 expect(await collectionEvm.methods.isOwnerOrAdminCross(admin2Cross).call()).to.be.false;141142 await collectionEvm.methods.addCollectionAdmin(adminDeprecated).send();143 await collectionEvm.methods.addCollectionAdminCross(admin1Cross).send();144 await collectionEvm.methods.addCollectionAdminCross(admin2Cross).send();145146 // Soft-deprecated: isOwnerOrAdmin returns true147 expect(await collectionEvm.methods.isOwnerOrAdmin(adminDeprecated).call()).to.be.true;148 // Expect isOwnerOrAdminCross return true149 expect(await collectionEvm.methods.isOwnerOrAdminCross(admin1Cross).call()).to.be.true;150 expect(await collectionEvm.methods.isOwnerOrAdminCross(admin2Cross).call()).to.be.true;151 });152153 // Soft-deprecated154 itEth('(!negative tests!) Add admin by ADMIN is not allowed', async ({helper}) => {155 const owner = await helper.eth.createAccountWithBalance(donor);156 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');157158 const admin = await helper.eth.createAccountWithBalance(donor);159 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);160 await collectionEvm.methods.addCollectionAdmin(admin).send();161162 const user = helper.eth.createAccount();163 await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: admin}))164 .to.be.rejectedWith('NoPermission');165166 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);167 expect(adminList.length).to.be.eq(1);168 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())169 .to.be.eq(admin.toLocaleLowerCase());170 });171172 // Soft-deprecated173 itEth('(!negative tests!) Add admin by USER is not allowed', async ({helper}) => {174 const owner = await helper.eth.createAccountWithBalance(donor);175 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');176177 const notAdmin = await helper.eth.createAccountWithBalance(donor);178 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);179180 const user = helper.eth.createAccount();181 await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: notAdmin}))182 .to.be.rejectedWith('NoPermission');183184 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);185 expect(adminList.length).to.be.eq(0);186 });187188 itEth('(!negative tests!) Add [cross] admin by ADMIN is not allowed', async ({helper}) => {189 const owner = await helper.eth.createAccountWithBalance(donor);190 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');191192 const [admin, notAdmin] = await helper.arrange.createAccounts([10n, 10n], donor);193 const adminCross = helper.ethCrossAccount.fromKeyringPair(admin);194 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);195 await collectionEvm.methods.addCollectionAdminCross(adminCross).send();196197 const notAdminCross = helper.ethCrossAccount.fromKeyringPair(notAdmin);198 await expect(collectionEvm.methods.addCollectionAdminCross(notAdminCross).call({from: adminCross.eth}))199 .to.be.rejectedWith('NoPermission');200201 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);202 expect(adminList.length).to.be.eq(1);203204 const admin0Cross = helper.ethCrossAccount.fromKeyringPair(adminList[0]);205 expect(admin0Cross.eth.toLocaleLowerCase())206 .to.be.eq(adminCross.eth.toLocaleLowerCase());207 });208209 itEth('(!negative tests!) Add [cross] admin by USER is not allowed', async ({helper}) => {210 const owner = await helper.eth.createAccountWithBalance(donor);211 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');212213 const notAdmin0 = await helper.eth.createAccountWithBalance(donor);214 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);215 const [notAdmin1] = await helper.arrange.createAccounts([10n], donor);216 const notAdmin1Cross = helper.ethCrossAccount.fromKeyringPair(notAdmin1);217 await expect(collectionEvm.methods.addCollectionAdminCross(notAdmin1Cross).call({from: notAdmin0}))218 .to.be.rejectedWith('NoPermission');219220 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);221 expect(adminList.length).to.be.eq(0);222 });223});224225describe('Remove collection admins', () => {226 let donor: IKeyringPair;227228 before(async function() {229 await usingEthPlaygrounds(async (_helper, privateKey) => {230 donor = await privateKey({url: import.meta.url});231 });232 });233234 // Soft-deprecated235 itEth('Remove admin by owner', async ({helper}) => {236 const owner = await helper.eth.createAccountWithBalance(donor);237 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');238239 const newAdmin = helper.eth.createAccount();240 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);241 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();242243 {244 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);245 expect(adminList.length).to.be.eq(1);246 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())247 .to.be.eq(newAdmin.toLocaleLowerCase());248 }249250 await collectionEvm.methods.removeCollectionAdmin(newAdmin).send();251 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);252 expect(adminList.length).to.be.eq(0);253 });254255 itEth('Remove [cross] admin by owner', async ({helper}) => {256 const owner = await helper.eth.createAccountWithBalance(donor);257 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');258259 const [adminSub] = await helper.arrange.createAccounts([10n], donor);260 const adminEth = (await helper.eth.createAccountWithBalance(donor)).toLowerCase();261 const adminCrossSub = helper.ethCrossAccount.fromKeyringPair(adminSub);262 const adminCrossEth = helper.ethCrossAccount.fromAddress(adminEth);263264 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);265 await collectionEvm.methods.addCollectionAdminCross(adminCrossSub).send();266 await collectionEvm.methods.addCollectionAdminCross(adminCrossEth).send();267268 {269 const adminList = await helper.collection.getAdmins(collectionId);270 expect(adminList).to.deep.include({Substrate: adminSub.address});271 expect(adminList).to.deep.include({Ethereum: adminEth});272 }273274 await collectionEvm.methods.removeCollectionAdminCross(adminCrossSub).send();275 await collectionEvm.methods.removeCollectionAdminCross(adminCrossEth).send();276 const adminList = await helper.collection.getAdmins(collectionId);277 expect(adminList.length).to.be.eq(0);278279 // Non admin cannot mint:280 await expect(helper.nft.mintToken(adminSub, {collectionId, owner: {Substrate: adminSub.address}})).to.be.rejectedWith(/common.PublicMintingNotAllowed/);281 await expect(collectionEvm.methods.mint(adminEth).send({from: adminEth})).to.be.rejected;282 });283284 // Soft-deprecated285 itEth('(!negative tests!) Remove admin by ADMIN is not allowed', async ({helper}) => {286 const owner = await helper.eth.createAccountWithBalance(donor);287 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');288289 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);290291 const admin0 = await helper.eth.createAccountWithBalance(donor);292 await collectionEvm.methods.addCollectionAdmin(admin0).send();293 const admin1 = await helper.eth.createAccountWithBalance(donor);294 await collectionEvm.methods.addCollectionAdmin(admin1).send();295296 await expect(collectionEvm.methods.removeCollectionAdmin(admin1).call({from: admin0}))297 .to.be.rejectedWith('NoPermission');298 {299 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);300 expect(adminList.length).to.be.eq(2);301 expect(adminList.toString().toLocaleLowerCase())302 .to.be.deep.contains(admin0.toLocaleLowerCase())303 .to.be.deep.contains(admin1.toLocaleLowerCase());304 }305 });306307 // Soft-deprecated308 itEth('(!negative tests!) Remove admin by USER is not allowed', async ({helper}) => {309 const owner = await helper.eth.createAccountWithBalance(donor);310 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');311312 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);313314 const admin = await helper.eth.createAccountWithBalance(donor);315 await collectionEvm.methods.addCollectionAdmin(admin).send();316 const notAdmin = helper.eth.createAccount();317318 await expect(collectionEvm.methods.removeCollectionAdmin(admin).call({from: notAdmin}))319 .to.be.rejectedWith('NoPermission');320 {321 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);322 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())323 .to.be.eq(admin.toLocaleLowerCase());324 expect(adminList.length).to.be.eq(1);325 }326 });327328 itEth('(!negative tests!) Remove [cross] admin by ADMIN is not allowed', async ({helper}) => {329 const owner = await helper.eth.createAccountWithBalance(donor);330 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');331332 const [admin1] = await helper.arrange.createAccounts([10n], donor);333 const admin1Cross = helper.ethCrossAccount.fromKeyringPair(admin1);334 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);335 await collectionEvm.methods.addCollectionAdminCross(admin1Cross).send();336337 const [admin2] = await helper.arrange.createAccounts([10n], donor);338 const admin2Cross = helper.ethCrossAccount.fromKeyringPair(admin2);339 await collectionEvm.methods.addCollectionAdminCross(admin2Cross).send();340341 await expect(collectionEvm.methods.removeCollectionAdminCross(admin1Cross).call({from: admin2Cross.eth}))342 .to.be.rejectedWith('NoPermission');343344 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);345 expect(adminList.length).to.be.eq(2);346 expect(adminList.toString().toLocaleLowerCase())347 .to.be.deep.contains(admin1.address.toLocaleLowerCase())348 .to.be.deep.contains(admin2.address.toLocaleLowerCase());349 });350351 itEth('(!negative tests!) Remove [cross] admin by USER is not allowed', async ({helper}) => {352 const owner = await helper.eth.createAccountWithBalance(donor);353 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');354355 const [adminSub] = await helper.arrange.createAccounts([10n], donor);356 const adminSubCross = helper.ethCrossAccount.fromKeyringPair(adminSub);357 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);358 await collectionEvm.methods.addCollectionAdminCross(adminSubCross).send();359 const notAdminEth = await helper.eth.createAccountWithBalance(donor);360361 await expect(collectionEvm.methods.removeCollectionAdminCross(adminSubCross).call({from: notAdminEth}))362 .to.be.rejectedWith('NoPermission');363364 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);365 expect(adminList.length).to.be.eq(1);366 expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())367 .to.be.eq(adminSub.address.toLocaleLowerCase());368 });369});370371// Soft-deprecated372describe('Change owner tests', () => {373 let donor: IKeyringPair;374375 before(async function() {376 await usingEthPlaygrounds(async (_helper, privateKey) => {377 donor = await privateKey({url: import.meta.url});378 });379 });380381 itEth('Change owner', async ({helper}) => {382 const owner = await helper.eth.createAccountWithBalance(donor);383 const newOwner = await helper.eth.createAccountWithBalance(donor);384 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');385 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);386387 await collectionEvm.methods.changeCollectionOwner(newOwner).send();388389 expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.false;390 expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.true;391 });392393 itEth('change owner call fee', async ({helper}) => {394 const owner = await helper.eth.createAccountWithBalance(donor);395 const newOwner = await helper.eth.createAccountWithBalance(donor);396 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');397 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);398 const cost = await recordEthFee(helper, owner, () => collectionEvm.methods.changeCollectionOwner(newOwner).send());399 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));400 expect(cost > 0);401 });402403 itEth('(!negative tests!) call setOwner by non owner', async ({helper}) => {404 const owner = await helper.eth.createAccountWithBalance(donor);405 const newOwner = await helper.eth.createAccountWithBalance(donor);406 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');407 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);408409 await expect(collectionEvm.methods.changeCollectionOwner(newOwner).send({from: newOwner})).to.be.rejected;410 expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.false;411 });412});413414describe('Change substrate owner tests', () => {415 let donor: IKeyringPair;416417 before(async function() {418 await usingEthPlaygrounds(async (_helper, privateKey) => {419 donor = await privateKey({url: import.meta.url});420 });421 });422423 itEth('Change owner [cross]', async ({helper}) => {424 const owner = await helper.eth.createAccountWithBalance(donor);425 const ownerEth = await helper.eth.createAccountWithBalance(donor);426 const ownerCrossEth = helper.ethCrossAccount.fromAddress(ownerEth);427 const [ownerSub] = await helper.arrange.createAccounts([10n], donor);428 const ownerCrossSub = helper.ethCrossAccount.fromKeyringPair(ownerSub);429430 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');431 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);432433 expect(await collectionEvm.methods.isOwnerOrAdminCross(ownerCrossSub).call()).to.be.false;434435 // Can set ethereum owner:436 await collectionEvm.methods.changeCollectionOwnerCross(ownerCrossEth).send({from: owner});437 expect(await collectionEvm.methods.isOwnerOrAdminCross(ownerCrossEth).call()).to.be.true;438 expect(await helper.collection.getData(collectionId))439 .to.have.property('normalizedOwner').that.is.eq(helper.address.ethToSubstrate(ownerEth));440441 // Can set Substrate owner:442 await collectionEvm.methods.changeCollectionOwnerCross(ownerCrossSub).send({from: ownerEth});443 expect(await collectionEvm.methods.isOwnerOrAdminCross(ownerCrossSub).call()).to.be.true;444 expect(await helper.collection.getData(collectionId))445 .to.have.property('normalizedOwner').that.is.eq(helper.address.normalizeSubstrate(ownerSub.address));446 });447448 itEth.skip('change owner call fee', async ({helper}) => {449 const owner = await helper.eth.createAccountWithBalance(donor);450 const [newOwner] = await helper.arrange.createAccounts([10n], donor);451 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');452 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);453454 const cost = await recordEthFee(helper, owner, () => collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send());455 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));456 expect(cost > 0);457 });458459 itEth('(!negative tests!) call setOwner by non owner [cross]', async ({helper}) => {460 const owner = await helper.eth.createAccountWithBalance(donor);461 const otherReceiver = await helper.eth.createAccountWithBalance(donor);462 const [newOwner] = await helper.arrange.createAccounts([10n], donor);463 const newOwnerCross = helper.ethCrossAccount.fromKeyringPair(newOwner);464 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');465 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);466467 await expect(collectionEvm.methods.changeCollectionOwnerCross(newOwnerCross).send({from: otherReceiver})).to.be.rejected;468 expect(await collectionEvm.methods.isOwnerOrAdminCross(newOwnerCross).call()).to.be.false;469 });470});tests/src/eth/collectionProperties.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionProperties.test.ts
+++ b/tests/src/eth/collectionProperties.test.ts
@@ -181,17 +181,11 @@
const propertyPermissions = data2?.raw.tokenPropertyPermissions;
expect(propertyPermissions?.length).to.equal(2);
- expect(propertyPermissions.find((tpp: ITokenPropertyPermission) => {
- return tpp.key === 'URI' && tpp.permission.mutable && tpp.permission.collectionAdmin && !tpp.permission.tokenOwner;
- })).to.be.not.null;
+ expect(propertyPermissions.find((tpp: ITokenPropertyPermission) => tpp.key === 'URI' && tpp.permission.mutable && tpp.permission.collectionAdmin && !tpp.permission.tokenOwner)).to.be.not.null;
- expect(propertyPermissions.find((tpp: ITokenPropertyPermission) => {
- return tpp.key === 'URISuffix' && tpp.permission.mutable && tpp.permission.collectionAdmin && !tpp.permission.tokenOwner;
- })).to.be.not.null;
+ expect(propertyPermissions.find((tpp: ITokenPropertyPermission) => tpp.key === 'URISuffix' && tpp.permission.mutable && tpp.permission.collectionAdmin && !tpp.permission.tokenOwner)).to.be.not.null;
- expect(data2?.raw.properties?.find((property: IProperty) => {
- return property.key === 'baseURI' && property.value === BASE_URI;
- })).to.be.not.null;
+ expect(data2?.raw.properties?.find((property: IProperty) => property.key === 'baseURI' && property.value === BASE_URI)).to.be.not.null;
const token1Result = await contract.methods.mint(bruh).send();
const tokenId1 = token1Result.events.Transfer.returnValues.tokenId;
tests/src/eth/evmCoder.test.tsdiffbeforeafterboth--- a/tests/src/eth/evmCoder.test.ts
+++ b/tests/src/eth/evmCoder.test.ts
@@ -17,8 +17,7 @@
import {IKeyringPair} from '@polkadot/types/types';
import {itEth, expect, usingEthPlaygrounds} from './util';
-const getContractSource = (collectionAddress: string, contractAddress: string): string => {
- return `
+const getContractSource = (collectionAddress: string, contractAddress: string): string => `
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface ITest {
@@ -51,7 +50,6 @@
}
}
`;
-};
describe('Evm Coder tests', () => {
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -102,17 +102,15 @@
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 properties = Array(5).fill(0).map((_, i) => ({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,
- },
- };
- });
+ .map(p => ({
+ key: p.key, permission: {
+ tokenOwner: false,
+ collectionAdmin: true,
+ mutable: false,
+ },
+ }));
const collection = await helper.nft.mintCollection(minter, {
tokenPrefix: 'ethp',
@@ -146,7 +144,7 @@
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()); }));
+ .map(p => 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});
tests/src/eth/reFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -46,12 +46,11 @@
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: {
+ const properties = Array(5).fill(0).map((_, i) => ({key: `key_${i}`, value: Buffer.from(`value_${i}`)}));
+ const permissions: ITokenPropertyPermission[] = properties.map(p => ({key: p.key, permission: {
tokenOwner: false,
collectionAdmin: true,
- mutable: false}};
- });
+ mutable: false}}));
const collection = await helper.rft.mintCollection(minter, {
@@ -86,7 +85,7 @@
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()); }));
+ .map(p => 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});
tests/src/eth/tokenProperties.test.tsdiffbeforeafterboth--- a/tests/src/eth/tokenProperties.test.ts
+++ b/tests/src/eth/tokenProperties.test.ts
@@ -241,10 +241,10 @@
itEth.ifWithPallets(`Can be multiple set/read for ${testCase.mode}`, testCase.requiredPallets, async({helper}) => {
const caller = await helper.eth.createAccountWithBalance(donor);
- 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,
+ const properties = Array(5).fill(0).map((_, i) => ({key: `key_${i}`, value: Buffer.from(`value_${i}`)}));
+ const permissions: ITokenPropertyPermission[] = properties.map(p => ({key: p.key, permission: {tokenOwner: true,
collectionAdmin: true,
- mutable: true}}; });
+ mutable: true}}));
const collection = await helper[testCase.mode].mintCollection(alice, {
tokenPrefix: 'ethp',
@@ -267,10 +267,10 @@
await contract.methods.setProperties(token.tokenId, properties).send({from: caller});
const values = await token.getProperties(properties.map(p => p.key));
- expect(values).to.be.deep.equal(properties.map(p => { return {key: p.key, value: p.value.toString()}; }));
+ expect(values).to.be.deep.equal(properties.map(p => ({key: p.key, value: p.value.toString()})));
expect(await contract.methods.properties(token.tokenId, []).call()).to.be.like(properties
- .map(p => { return helper.ethProperty.property(p.key, p.value.toString()); }));
+ .map(p => helper.ethProperty.property(p.key, p.value.toString())));
expect(await contract.methods.properties(token.tokenId, [properties[0].key]).call())
.to.be.like([helper.ethProperty.property(properties[0].key, properties[0].value.toString())]);
tests/src/fungible.test.tsdiffbeforeafterboth--- a/tests/src/fungible.test.ts
+++ b/tests/src/fungible.test.ts
@@ -46,7 +46,7 @@
itSub('RPC method tokenOnewrs for fungible collection and token', async ({helper}) => {
const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};
- const facelessCrowd = (await helper.arrange.createAccounts(Array(7).fill(0n), donor)).map(keyring => {return {Substrate: keyring.address};});
+ const facelessCrowd = (await helper.arrange.createAccounts(Array(7).fill(0n), donor)).map(keyring => ({Substrate: keyring.address}));
const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
tests/src/getPropertiesRpc.test.tsdiffbeforeafterboth--- a/tests/src/getPropertiesRpc.test.ts
+++ b/tests/src/getPropertiesRpc.test.ts
@@ -48,17 +48,13 @@
describe('query properties RPC', () => {
let alice: IKeyringPair;
- const mintCollection = async (helper: UniqueHelper) => {
- return await helper.nft.mintCollection(alice, {
- tokenPrefix: 'prps',
- properties: collectionProps,
- tokenPropertyPermissions: tokenPropPermissions,
- });
- };
+ const mintCollection = async (helper: UniqueHelper) => await helper.nft.mintCollection(alice, {
+ tokenPrefix: 'prps',
+ properties: collectionProps,
+ tokenPropertyPermissions: tokenPropPermissions,
+ });
- const mintToken = async (collection: UniqueNFTCollection) => {
- return await collection.mintToken(alice, {Substrate: alice.address}, tokenProps);
- };
+ const mintToken = async (collection: UniqueNFTCollection) => await collection.mintToken(alice, {Substrate: alice.address}, tokenProps);
before(async () => {
tests/src/nesting/tokenProperties.test.tsdiffbeforeafterboth--- a/tests/src/nesting/tokenProperties.test.ts
+++ b/tests/src/nesting/tokenProperties.test.ts
@@ -44,7 +44,7 @@
async function mintCollectionWithAllPermissionsAndToken(helper: UniqueHelper, mode: 'NFT' | 'RFT'): Promise<[UniqueNFToken | UniqueRFToken, bigint]> {
const collection = await (mode == 'NFT' ? helper.nft : helper.rft).mintCollection(alice, {
tokenPropertyPermissions: permissions.flatMap(({permission, signers}, i) =>
- signers.map(signer => {return {key: `${i+1}_${signer.address}`, permission};})),
+ signers.map(signer => ({key: `${i+1}_${signer.address}`, permission}))),
});
return mode == 'NFT' ? [await collection.mintToken(alice), 1n] : [await collection.mintToken(alice, 100n as any), 100n];
}
@@ -201,7 +201,7 @@
const collectionA = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});
const collectionB = await helper.nft.mintCollection(alice, {
tokenPropertyPermissions: permissions.flatMap(({permission, signers}, i) =>
- signers.map(signer => {return {key: `${i+1}_${signer.address}`, permission};})),
+ signers.map(signer => ({key: `${i+1}_${signer.address}`, permission}))),
});
const targetToken = await collectionA.mintToken(alice);
const nestedToken = await collectionB.mintToken(alice, targetToken.nestingAccount());
@@ -239,7 +239,7 @@
const collectionA = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});
const collectionB = await helper.nft.mintCollection(alice, {
tokenPropertyPermissions: permissions.flatMap(({permission, signers}, i) =>
- signers.map(signer => {return {key: `${i+1}_${signer.address}`, permission};})),
+ signers.map(signer => ({key: `${i+1}_${signer.address}`, permission}))),
});
const targetToken = await collectionA.mintToken(alice);
const nestedToken = await collectionB.mintToken(alice, targetToken.nestingAccount());
@@ -284,7 +284,7 @@
const collectionA = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});
const collectionB = await helper.nft.mintCollection(alice, {
tokenPropertyPermissions: permissions.flatMap(({permission, signers}, i) =>
- signers.map(signer => {return {key: `${i+1}_${signer.address}`, permission};})),
+ signers.map(signer => ({key: `${i+1}_${signer.address}`, permission}))),
});
const targetToken = await collectionA.mintToken(alice);
const nestedToken = await collectionB.mintToken(alice, targetToken.nestingAccount());
@@ -477,7 +477,7 @@
async function mintCollectionWithAllPermissionsAndToken(helper: UniqueHelper, mode: 'NFT' | 'RFT'): Promise<[UniqueNFToken | UniqueRFToken, bigint]> {
const collection = await (mode == 'NFT' ? helper.nft : helper.rft).mintCollection(alice, {
- tokenPropertyPermissions: constitution.map(({permission}, i) => {return {key: `${i+1}`, permission};}),
+ tokenPropertyPermissions: constitution.map(({permission}, i) => ({key: `${i+1}`, permission})),
});
return mode == 'NFT' ? [await collection.mintToken(alice), 1n] : [await collection.mintToken(alice, 100n as any), 100n];
}
tests/src/refungible.test.tsdiffbeforeafterboth--- a/tests/src/refungible.test.ts
+++ b/tests/src/refungible.test.ts
@@ -64,7 +64,7 @@
itSub('RPC method tokenOwners for refungible collection and token', async ({helper}) => {
const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};
- const facelessCrowd = (await helper.arrange.createAccounts(Array(7).fill(0n), donor)).map(keyring => {return {Substrate: keyring.address};});
+ const facelessCrowd = (await helper.arrange.createAccounts(Array(7).fill(0n), donor)).map(keyring => ({Substrate: keyring.address}));
const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
tests/src/rpc.test.tsdiffbeforeafterboth--- a/tests/src/rpc.test.ts
+++ b/tests/src/rpc.test.ts
@@ -40,7 +40,7 @@
// Set-up a few token owners of all stripes
const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};
const facelessCrowd = (await helper.arrange.createAccounts([0n, 0n, 0n, 0n, 0n, 0n, 0n], donor))
- .map(i => {return {Substrate: i.address};});
+ .map(i => ({Substrate: i.address}));
const collection = await helper.ft.mintCollection(alice, {name: 'RPC-2', tokenPrefix: 'RPC'});
// mint some maximum (u128) amounts of tokens possible
tests/src/sub/appPromotion/appPromotion.test.tsdiffbeforeafterboth--- a/tests/src/sub/appPromotion/appPromotion.test.ts
+++ b/tests/src/sub/appPromotion/appPromotion.test.ts
@@ -357,11 +357,9 @@
const stakers = await getAccounts(3);
await Promise.all(stakers.map(staker => helper.staking.stake(staker, 100n * nominal)));
- await Promise.all(stakers.map(staker => {
- return testCase.method === 'unstakeAll'
- ? helper.staking.unstakeAll(staker)
- : helper.staking.unstakePartial(staker, 100n * nominal);
- }));
+ await Promise.all(stakers.map(staker => testCase.method === 'unstakeAll'
+ ? helper.staking.unstakeAll(staker)
+ : helper.staking.unstakePartial(staker, 100n * nominal)));
await Promise.all(stakers.map(async (staker) => {
expect(await helper.staking.getPendingUnstake({Substrate: staker.address})).to.be.equal(100n * nominal);
@@ -375,11 +373,9 @@
const stakers = await getAccounts(10);
await Promise.all(stakers.map(staker => helper.staking.stake(staker, 100n * nominal)));
- const unstakingResults = await Promise.allSettled(stakers.map((staker, i) => {
- return i % 2 === 0
- ? helper.staking.unstakeAll(staker)
- : helper.staking.unstakePartial(staker, 100n * nominal);
- }));
+ const unstakingResults = await Promise.allSettled(stakers.map((staker, i) => i % 2 === 0
+ ? helper.staking.unstakeAll(staker)
+ : helper.staking.unstakePartial(staker, 100n * nominal)));
const successfulUnstakes = unstakingResults.filter(result => result.status === 'fulfilled');
expect(successfulUnstakes).to.have.length(3);
tests/src/util/index.tsdiffbeforeafterboth--- a/tests/src/util/index.ts
+++ b/tests/src/util/index.ts
@@ -19,13 +19,9 @@
chai.use(chaiSubset);
export const expect = chai.expect;
-const getTestHash = (filename: string) => {
- return crypto.createHash('md5').update(filename).digest('hex');
-};
+const getTestHash = (filename: string) => crypto.createHash('md5').update(filename).digest('hex');
-export const getTestSeed = (filename: string) => {
- return `//Alice+${getTestHash(filename)}`;
-};
+export const getTestSeed = (filename: string) => `//Alice+${getTestHash(filename)}`;
async function usingPlaygroundsGeneral<T extends ChainHelperBase>(helperType: new(logger: ILogger) => T, url: string, code: (helper: T, privateKey: (seed: string | {filename?: string, url?: string, ignoreFundsPresence?: boolean}) => Promise<IKeyringPair>) => Promise<void>) {
const silentConsole = new SilentConsole();
@@ -65,49 +61,27 @@
}
}
-export const usingPlaygrounds = (code: (helper: DevUniqueHelper, privateKey: (seed: string | {filename?: string, url?: string, ignoreFundsPresence?: boolean}) => Promise<IKeyringPair>) => Promise<void>, url: string = config.substrateUrl) => {
- return usingPlaygroundsGeneral<DevUniqueHelper>(DevUniqueHelper, url, code);
-};
+export const usingPlaygrounds = (code: (helper: DevUniqueHelper, privateKey: (seed: string | {filename?: string, url?: string, ignoreFundsPresence?: boolean}) => Promise<IKeyringPair>) => Promise<void>, url: string = config.substrateUrl) => usingPlaygroundsGeneral<DevUniqueHelper>(DevUniqueHelper, url, code);
-export const usingWestmintPlaygrounds = (url: string, code: (helper: DevWestmintHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {
- return usingPlaygroundsGeneral<DevWestmintHelper>(DevWestmintHelper, url, code);
-};
+export const usingWestmintPlaygrounds = (url: string, code: (helper: DevWestmintHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevWestmintHelper>(DevWestmintHelper, url, code);
-export const usingStateminePlaygrounds = (url: string, code: (helper: DevWestmintHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {
- return usingPlaygroundsGeneral<DevStatemineHelper>(DevWestmintHelper, url, code);
-};
+export const usingStateminePlaygrounds = (url: string, code: (helper: DevWestmintHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevStatemineHelper>(DevWestmintHelper, url, code);
-export const usingStatemintPlaygrounds = (url: string, code: (helper: DevWestmintHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {
- return usingPlaygroundsGeneral<DevStatemintHelper>(DevWestmintHelper, url, code);
-};
+export const usingStatemintPlaygrounds = (url: string, code: (helper: DevWestmintHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevStatemintHelper>(DevWestmintHelper, url, code);
-export const usingRelayPlaygrounds = (url: string, code: (helper: DevRelayHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {
- return usingPlaygroundsGeneral<DevRelayHelper>(DevRelayHelper, url, code);
-};
+export const usingRelayPlaygrounds = (url: string, code: (helper: DevRelayHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevRelayHelper>(DevRelayHelper, url, code);
-export const usingAcalaPlaygrounds = (url: string, code: (helper: DevAcalaHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {
- return usingPlaygroundsGeneral<DevAcalaHelper>(DevAcalaHelper, url, code);
-};
+export const usingAcalaPlaygrounds = (url: string, code: (helper: DevAcalaHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevAcalaHelper>(DevAcalaHelper, url, code);
-export const usingKaruraPlaygrounds = (url: string, code: (helper: DevKaruraHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {
- return usingPlaygroundsGeneral<DevKaruraHelper>(DevAcalaHelper, url, code);
-};
+export const usingKaruraPlaygrounds = (url: string, code: (helper: DevKaruraHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevKaruraHelper>(DevAcalaHelper, url, code);
-export const usingMoonbeamPlaygrounds = (url: string, code: (helper: DevMoonbeamHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {
- return usingPlaygroundsGeneral<DevMoonbeamHelper>(DevMoonbeamHelper, url, code);
-};
+export const usingMoonbeamPlaygrounds = (url: string, code: (helper: DevMoonbeamHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevMoonbeamHelper>(DevMoonbeamHelper, url, code);
-export const usingMoonriverPlaygrounds = (url: string, code: (helper: DevMoonbeamHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {
- return usingPlaygroundsGeneral<DevMoonriverHelper>(DevMoonriverHelper, url, code);
-};
+export const usingMoonriverPlaygrounds = (url: string, code: (helper: DevMoonbeamHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevMoonriverHelper>(DevMoonriverHelper, url, code);
-export const usingAstarPlaygrounds = (url: string, code: (helper: DevAstarHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {
- return usingPlaygroundsGeneral<DevAstarHelper>(DevAstarHelper, url, code);
-};
+export const usingAstarPlaygrounds = (url: string, code: (helper: DevAstarHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevAstarHelper>(DevAstarHelper, url, code);
-export const usingShidenPlaygrounds = (url: string, code: (helper: DevShidenHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {
- return usingPlaygroundsGeneral<DevShidenHelper>(DevShidenHelper, url, code);
-};
+export const usingShidenPlaygrounds = (url: string, code: (helper: DevShidenHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => usingPlaygroundsGeneral<DevShidenHelper>(DevShidenHelper, url, code);
export const MINIMUM_DONOR_FUND = 100_000n;
export const DONOR_FUNDING = 2_000_000n;
tests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.dev.ts
+++ b/tests/src/util/playgrounds/unique.dev.ts
@@ -771,9 +771,7 @@
// <<< Referendum voting <<<
// Wait the proposal to pass
- await this.helper.wait.expectEvent(3, Event.Democracy.Passed, event => {
- return event.referendumIndex() == referendumIndex;
- });
+ await this.helper.wait.expectEvent(3, Event.Democracy.Passed, event => event.referendumIndex() == referendumIndex);
await this.helper.wait.newBlocks(1);
@@ -924,7 +922,7 @@
event<T extends IEventHelper>(
maxBlocksToWait: number,
eventHelperType: new () => T,
- filter: (_: T) => boolean = () => { return true; },
+ filter: (_: T) => boolean = () => true,
) {
// eslint-disable-next-line no-async-promise-executor
const promise = new Promise<T | null>(async (resolve) => {
@@ -970,7 +968,7 @@
async expectEvent<T extends IEventHelper>(
maxBlocksToWait: number,
eventHelperType: new () => T,
- filter: (e: T) => boolean = () => { return true; },
+ filter: (e: T) => boolean = () => true,
) {
const e = await this.event(maxBlocksToWait, eventHelperType, filter);
if (e == null) {
@@ -1077,9 +1075,7 @@
async startCapture() {
this.stopCapture();
this.unsubscribe = (await this.helper.getApi().query.system.events((eventRecords: FrameSystemEventRecord[]) => {
- const newEvents = eventRecords.filter(r => {
- return r.event.section == this.eventSection && r.event.method == this.eventMethod;
- });
+ const newEvents = eventRecords.filter(r => r.event.section == this.eventSection && r.event.method == this.eventMethod);
this.events.push(...newEvents);
})) as any;
@@ -1105,12 +1101,10 @@
async payoutStakers(signer: IKeyringPair, stakersToPayout: number): Promise<{staker: string, stake: bigint, payout: bigint}[]> {
const payoutResult = await this.helper.executeExtrinsic(signer, 'api.tx.appPromotion.payoutStakers', [stakersToPayout], true);
- return payoutResult.result.events.filter(e => e.event.method === 'StakingRecalculation').map(e => {
- return {
- staker: e.event.data[0].toString(),
- stake: e.event.data[1].toBigInt(),
- payout: e.event.data[2].toBigInt(),
- };
- });
+ return payoutResult.result.events.filter(e => e.event.method === 'StakingRecalculation').map(e => ({
+ staker: e.event.data[0].toString(),
+ stake: e.event.data[1].toBigInt(),
+ payout: e.event.data[2].toBigInt(),
+ }));
}
}
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -2395,7 +2395,7 @@
return total.toBigInt();
}
- async getLocked(address: TSubstrateAccount): Promise<[{ id: string, amount: bigint, reason: string }]> {
+ async getLocked(address: TSubstrateAccount): Promise<{ id: string, amount: bigint, reason: string }[]> {
const locks = (await this.helper.callRpc('api.query.balances.locks', [address])).toHuman();
return locks.map((lock: any) => ({id: lock.id, amount: BigInt(lock.amount.replace(/,/g, '')), reasons: lock.reasons}));
}
@@ -2581,14 +2581,12 @@
*/
async getVestingSchedules(address: TSubstrateAccount): Promise<{ start: bigint, period: bigint, periodCount: bigint, perPeriod: bigint }[]> {
const schedule = (await this.helper.callRpc('api.query.vesting.vestingSchedules', [address])).toJSON();
- return schedule.map((schedule: any) => {
- return {
- start: BigInt(schedule.start),
- period: BigInt(schedule.period),
- periodCount: BigInt(schedule.periodCount),
- perPeriod: BigInt(schedule.perPeriod),
- };
- });
+ return schedule.map((schedule: any) => ({
+ start: BigInt(schedule.start),
+ period: BigInt(schedule.period),
+ periodCount: BigInt(schedule.periodCount),
+ perPeriod: BigInt(schedule.perPeriod),
+ }));
}
/**
@@ -2804,12 +2802,10 @@
*/
async getTotalStakedPerBlock(address: ICrossAccountId): Promise<IStakingInfo[]> {
const rawTotalStakerdPerBlock = await this.helper.callRpc('api.rpc.appPromotion.totalStakedPerBlock', [address]);
- return rawTotalStakerdPerBlock.map(([block, amount]: any[]) => {
- return {
- block: block.toBigInt(),
- amount: amount.toBigInt(),
- };
- });
+ return rawTotalStakerdPerBlock.map(([block, amount]: any[]) => ({
+ block: block.toBigInt(),
+ amount: amount.toBigInt(),
+ }));
}
/**
@@ -2828,12 +2824,10 @@
*/
async getPendingUnstakePerBlock(address: ICrossAccountId): Promise<IStakingInfo[]> {
const rawUnstakedPerBlock = await this.helper.callRpc('api.rpc.appPromotion.pendingUnstakePerBlock', [address]);
- const result = rawUnstakedPerBlock.map(([block, amount]: any[]) => {
- return {
- block: block.toBigInt(),
- amount: amount.toBigInt(),
- };
- });
+ const result = rawUnstakedPerBlock.map(([block, amount]: any[]) => ({
+ block: block.toBigInt(),
+ amount: amount.toBigInt(),
+ }));
return result;
}
}
tests/src/xcm/xcmQuartz.test.tsdiffbeforeafterboth--- a/tests/src/xcm/xcmQuartz.test.ts
+++ b/tests/src/xcm/xcmQuartz.test.ts
@@ -682,10 +682,8 @@
maliciousXcmProgramSent = await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.XcmpMessageSent);
});
- await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => {
- return event.messageHash() == maliciousXcmProgramSent.messageHash()
- && event.outcome().isFailedToTransactAsset;
- });
+ await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash() == maliciousXcmProgramSent.messageHash()
+ && event.outcome().isFailedToTransactAsset);
targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(targetAccountBalance).to.be.equal(0n);
@@ -765,10 +763,8 @@
maliciousXcmProgramFullIdSent = await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.XcmpMessageSent);
});
- await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => {
- return event.messageHash() == maliciousXcmProgramFullIdSent.messageHash()
- && event.outcome().isUntrustedReserveLocation;
- });
+ await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash() == maliciousXcmProgramFullIdSent.messageHash()
+ && event.outcome().isUntrustedReserveLocation);
let accountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(accountBalance).to.be.equal(0n);
@@ -780,10 +776,8 @@
maliciousXcmProgramHereIdSent = await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.XcmpMessageSent);
});
- await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => {
- return event.messageHash() == maliciousXcmProgramHereIdSent.messageHash()
- && event.outcome().isUntrustedReserveLocation;
- });
+ await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash() == maliciousXcmProgramHereIdSent.messageHash()
+ && event.outcome().isUntrustedReserveLocation);
accountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(accountBalance).to.be.equal(0n);
@@ -858,10 +852,8 @@
});
const expectFailedToTransact = async (helper: DevUniqueHelper, messageSent: any) => {
- await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => {
- return event.messageHash() == messageSent.messageHash()
- && event.outcome().isFailedToTransactAsset;
- });
+ await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash() == messageSent.messageHash()
+ && event.outcome().isFailedToTransactAsset);
};
itSub('Quartz rejects KAR tokens from Karura', async ({helper}) => {
@@ -1172,10 +1164,8 @@
maliciousXcmProgramSent = await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.XcmpMessageSent);
});
- await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => {
- return event.messageHash() == maliciousXcmProgramSent.messageHash()
- && event.outcome().isFailedToTransactAsset;
- });
+ await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash() == maliciousXcmProgramSent.messageHash()
+ && event.outcome().isFailedToTransactAsset);
targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(targetAccountBalance).to.be.equal(0n);
@@ -1263,10 +1253,8 @@
maliciousXcmProgramFullIdSent = await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.XcmpMessageSent);
});
- await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => {
- return event.messageHash() == maliciousXcmProgramFullIdSent.messageHash()
- && event.outcome().isUntrustedReserveLocation;
- });
+ await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash() == maliciousXcmProgramFullIdSent.messageHash()
+ && event.outcome().isUntrustedReserveLocation);
let accountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(accountBalance).to.be.equal(0n);
@@ -1282,10 +1270,8 @@
maliciousXcmProgramHereIdSent = await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.XcmpMessageSent);
});
- await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => {
- return event.messageHash() == maliciousXcmProgramHereIdSent.messageHash()
- && event.outcome().isUntrustedReserveLocation;
- });
+ await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash() == maliciousXcmProgramHereIdSent.messageHash()
+ && event.outcome().isUntrustedReserveLocation);
accountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(accountBalance).to.be.equal(0n);
@@ -1544,10 +1530,8 @@
maliciousXcmProgramSent = await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.XcmpMessageSent);
});
- await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => {
- return event.messageHash() == maliciousXcmProgramSent.messageHash()
- && event.outcome().isFailedToTransactAsset;
- });
+ await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash() == maliciousXcmProgramSent.messageHash()
+ && event.outcome().isFailedToTransactAsset);
targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(targetAccountBalance).to.be.equal(0n);
@@ -1627,10 +1611,8 @@
maliciousXcmProgramFullIdSent = await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.XcmpMessageSent);
});
- await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => {
- return event.messageHash() == maliciousXcmProgramFullIdSent.messageHash()
- && event.outcome().isUntrustedReserveLocation;
- });
+ await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash() == maliciousXcmProgramFullIdSent.messageHash()
+ && event.outcome().isUntrustedReserveLocation);
let accountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(accountBalance).to.be.equal(0n);
@@ -1642,10 +1624,8 @@
maliciousXcmProgramHereIdSent = await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.XcmpMessageSent);
});
- await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => {
- return event.messageHash() == maliciousXcmProgramHereIdSent.messageHash()
- && event.outcome().isUntrustedReserveLocation;
- });
+ await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash() == maliciousXcmProgramHereIdSent.messageHash()
+ && event.outcome().isUntrustedReserveLocation);
accountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(accountBalance).to.be.equal(0n);
tests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth--- a/tests/src/xcm/xcmUnique.test.ts
+++ b/tests/src/xcm/xcmUnique.test.ts
@@ -684,10 +684,8 @@
maliciousXcmProgramSent = await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.XcmpMessageSent);
});
- await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => {
- return event.messageHash() == maliciousXcmProgramSent.messageHash()
- && event.outcome().isFailedToTransactAsset;
- });
+ await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash() == maliciousXcmProgramSent.messageHash()
+ && event.outcome().isFailedToTransactAsset);
targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(targetAccountBalance).to.be.equal(0n);
@@ -767,10 +765,8 @@
maliciousXcmProgramFullIdSent = await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.XcmpMessageSent);
});
- await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => {
- return event.messageHash() == maliciousXcmProgramFullIdSent.messageHash()
- && event.outcome().isUntrustedReserveLocation;
- });
+ await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash() == maliciousXcmProgramFullIdSent.messageHash()
+ && event.outcome().isUntrustedReserveLocation);
let accountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(accountBalance).to.be.equal(0n);
@@ -782,10 +778,8 @@
maliciousXcmProgramHereIdSent = await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.XcmpMessageSent);
});
- await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => {
- return event.messageHash() == maliciousXcmProgramHereIdSent.messageHash()
- && event.outcome().isUntrustedReserveLocation;
- });
+ await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash() == maliciousXcmProgramHereIdSent.messageHash()
+ && event.outcome().isUntrustedReserveLocation);
accountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(accountBalance).to.be.equal(0n);
@@ -860,10 +854,8 @@
});
const expectFailedToTransact = async (helper: DevUniqueHelper, messageSent: any) => {
- await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => {
- return event.messageHash() == messageSent.messageHash()
- && event.outcome().isFailedToTransactAsset;
- });
+ await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash() == messageSent.messageHash()
+ && event.outcome().isFailedToTransactAsset);
};
itSub('Unique rejects ACA tokens from Acala', async ({helper}) => {
@@ -1175,10 +1167,8 @@
maliciousXcmProgramSent = await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.XcmpMessageSent);
});
- await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => {
- return event.messageHash() == maliciousXcmProgramSent.messageHash()
- && event.outcome().isFailedToTransactAsset;
- });
+ await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash() == maliciousXcmProgramSent.messageHash()
+ && event.outcome().isFailedToTransactAsset);
targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(targetAccountBalance).to.be.equal(0n);
@@ -1266,10 +1256,8 @@
maliciousXcmProgramFullIdSent = await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.XcmpMessageSent);
});
- await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => {
- return event.messageHash() == maliciousXcmProgramFullIdSent.messageHash()
- && event.outcome().isUntrustedReserveLocation;
- });
+ await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash() == maliciousXcmProgramFullIdSent.messageHash()
+ && event.outcome().isUntrustedReserveLocation);
let accountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(accountBalance).to.be.equal(0n);
@@ -1285,10 +1273,8 @@
maliciousXcmProgramHereIdSent = await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.XcmpMessageSent);
});
- await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => {
- return event.messageHash() == maliciousXcmProgramHereIdSent.messageHash()
- && event.outcome().isUntrustedReserveLocation;
- });
+ await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash() == maliciousXcmProgramHereIdSent.messageHash()
+ && event.outcome().isUntrustedReserveLocation);
accountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(accountBalance).to.be.equal(0n);
@@ -1546,10 +1532,8 @@
maliciousXcmProgramSent = await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.XcmpMessageSent);
});
- await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => {
- return event.messageHash() == maliciousXcmProgramSent.messageHash()
- && event.outcome().isFailedToTransactAsset;
- });
+ await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash() == maliciousXcmProgramSent.messageHash()
+ && event.outcome().isFailedToTransactAsset);
targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(targetAccountBalance).to.be.equal(0n);
@@ -1629,10 +1613,8 @@
maliciousXcmProgramFullIdSent = await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.XcmpMessageSent);
});
- await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => {
- return event.messageHash() == maliciousXcmProgramFullIdSent.messageHash()
- && event.outcome().isUntrustedReserveLocation;
- });
+ await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash() == maliciousXcmProgramFullIdSent.messageHash()
+ && event.outcome().isUntrustedReserveLocation);
let accountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(accountBalance).to.be.equal(0n);
@@ -1644,10 +1626,8 @@
maliciousXcmProgramHereIdSent = await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.XcmpMessageSent);
});
- await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => {
- return event.messageHash() == maliciousXcmProgramHereIdSent.messageHash()
- && event.outcome().isUntrustedReserveLocation;
- });
+ await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash() == maliciousXcmProgramHereIdSent.messageHash()
+ && event.outcome().isUntrustedReserveLocation);
accountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(accountBalance).to.be.equal(0n);