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.tsdiffbeforeafterboth--- a/tests/src/eth/collectionAdmin.test.ts
+++ b/tests/src/eth/collectionAdmin.test.ts
@@ -76,9 +76,7 @@
// 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);
- });
+ adminListEth = adminListEth.map((element: IEthCrossAccountId) => helper.address.convertCrossAccountFromEthCrossAccount(element));
expect(adminListRpc).to.be.like(adminListEth);
// 3. check isOwnerOrAdminCross returns true:
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.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 {Contract} from 'web3-eth-contract';19import {itEth, usingEthPlaygrounds, expect} from './util';20import {ITokenPropertyPermission} from '../util/playgrounds/types';21import {Pallets} from '../util';22import {UniqueNFTCollection, UniqueNFToken, UniqueRFTCollection} from '../util/playgrounds/unique';23import {TokenPermissionField} from './util/playgrounds/types';2425describe('EVM token properties', () => {26 let donor: IKeyringPair;27 let alice: IKeyringPair;2829 before(async function() {30 await usingEthPlaygrounds(async (helper, privateKey) => {31 donor = await privateKey({url: import.meta.url});32 [alice] = await helper.arrange.createAccounts([1000n], donor);33 });34 });3536 [37 {mode: 'nft' as const, requiredPallets: []},38 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},39 ].map(testCase =>40 itEth.ifWithPallets(`[${testCase.mode}] Can set all possible token property permissions`, testCase.requiredPallets, async({helper}) => {41 const owner = await helper.eth.createAccountWithBalance(donor);42 const caller = await helper.ethCrossAccount.createAccountWithBalance(donor);43 for(const [mutable,collectionAdmin, tokenOwner] of cartesian([], [false, true], [false, true], [false, true])) {44 const {collectionId, collectionAddress} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');45 const collection = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);46 await collection.methods.addCollectionAdminCross(caller).send({from: owner});4748 await collection.methods.setTokenPropertyPermissions([49 ['testKey', [50 [TokenPermissionField.Mutable, mutable],51 [TokenPermissionField.TokenOwner, tokenOwner],52 [TokenPermissionField.CollectionAdmin, collectionAdmin]],53 ],54 ]).send({from: caller.eth});5556 expect(await helper[testCase.mode].getPropertyPermissions(collectionId)).to.be.deep.equal([{57 key: 'testKey',58 permission: {mutable, collectionAdmin, tokenOwner},59 }]);6061 expect(await collection.methods.tokenPropertyPermissions().call({from: caller.eth})).to.be.like([62 ['testKey', [63 [TokenPermissionField.Mutable.toString(), mutable],64 [TokenPermissionField.TokenOwner.toString(), tokenOwner],65 [TokenPermissionField.CollectionAdmin.toString(), collectionAdmin]],66 ],67 ]);68 }69 }));7071 [72 {mode: 'nft' as const, requiredPallets: []},73 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},74 ].map(testCase =>75 itEth.ifWithPallets(`[${testCase.mode}] Can set multiple token property permissions as owner`, testCase.requiredPallets, async({helper}) => {76 const owner = await helper.eth.createAccountWithBalance(donor);7778 const {collectionId, collectionAddress} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');79 const collection = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);8081 await collection.methods.setTokenPropertyPermissions([82 ['testKey_0', [83 [TokenPermissionField.Mutable, true],84 [TokenPermissionField.TokenOwner, true],85 [TokenPermissionField.CollectionAdmin, true]],86 ],87 ['testKey_1', [88 [TokenPermissionField.Mutable, true],89 [TokenPermissionField.TokenOwner, false],90 [TokenPermissionField.CollectionAdmin, true]],91 ],92 ['testKey_2', [93 [TokenPermissionField.Mutable, false],94 [TokenPermissionField.TokenOwner, true],95 [TokenPermissionField.CollectionAdmin, false]],96 ],97 ]).send({from: owner});9899 expect(await helper[testCase.mode].getPropertyPermissions(collectionId)).to.be.deep.equal([100 {101 key: 'testKey_0',102 permission: {mutable: true, tokenOwner: true, collectionAdmin: true},103 },104 {105 key: 'testKey_1',106 permission: {mutable: true, tokenOwner: false, collectionAdmin: true},107 },108 {109 key: 'testKey_2',110 permission: {mutable: false, tokenOwner: true, collectionAdmin: false},111 },112 ]);113114 expect(await collection.methods.tokenPropertyPermissions().call({from: owner})).to.be.like([115 ['testKey_0', [116 [TokenPermissionField.Mutable.toString(), true],117 [TokenPermissionField.TokenOwner.toString(), true],118 [TokenPermissionField.CollectionAdmin.toString(), true]],119 ],120 ['testKey_1', [121 [TokenPermissionField.Mutable.toString(), true],122 [TokenPermissionField.TokenOwner.toString(), false],123 [TokenPermissionField.CollectionAdmin.toString(), true]],124 ],125 ['testKey_2', [126 [TokenPermissionField.Mutable.toString(), false],127 [TokenPermissionField.TokenOwner.toString(), true],128 [TokenPermissionField.CollectionAdmin.toString(), false]],129 ],130 ]);131 }));132133 [134 {mode: 'nft' as const, requiredPallets: []},135 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},136 ].map(testCase =>137 itEth.ifWithPallets(`[${testCase.mode}] Can set multiple token property permissions as admin`, testCase.requiredPallets, async({helper}) => {138 const owner = await helper.eth.createAccountWithBalance(donor);139 const caller = await helper.ethCrossAccount.createAccountWithBalance(donor);140141 const {collectionId, collectionAddress} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');142 const collection = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);143 await collection.methods.addCollectionAdminCross(caller).send({from: owner});144145 await collection.methods.setTokenPropertyPermissions([146 ['testKey_0', [147 [TokenPermissionField.Mutable, true],148 [TokenPermissionField.TokenOwner, true],149 [TokenPermissionField.CollectionAdmin, true]],150 ],151 ['testKey_1', [152 [TokenPermissionField.Mutable, true],153 [TokenPermissionField.TokenOwner, false],154 [TokenPermissionField.CollectionAdmin, true]],155 ],156 ['testKey_2', [157 [TokenPermissionField.Mutable, false],158 [TokenPermissionField.TokenOwner, true],159 [TokenPermissionField.CollectionAdmin, false]],160 ],161 ]).send({from: caller.eth});162163 expect(await helper[testCase.mode].getPropertyPermissions(collectionId)).to.be.deep.equal([164 {165 key: 'testKey_0',166 permission: {mutable: true, tokenOwner: true, collectionAdmin: true},167 },168 {169 key: 'testKey_1',170 permission: {mutable: true, tokenOwner: false, collectionAdmin: true},171 },172 {173 key: 'testKey_2',174 permission: {mutable: false, tokenOwner: true, collectionAdmin: false},175 },176 ]);177178 expect(await collection.methods.tokenPropertyPermissions().call({from: caller.eth})).to.be.like([179 ['testKey_0', [180 [TokenPermissionField.Mutable.toString(), true],181 [TokenPermissionField.TokenOwner.toString(), true],182 [TokenPermissionField.CollectionAdmin.toString(), true]],183 ],184 ['testKey_1', [185 [TokenPermissionField.Mutable.toString(), true],186 [TokenPermissionField.TokenOwner.toString(), false],187 [TokenPermissionField.CollectionAdmin.toString(), true]],188 ],189 ['testKey_2', [190 [TokenPermissionField.Mutable.toString(), false],191 [TokenPermissionField.TokenOwner.toString(), true],192 [TokenPermissionField.CollectionAdmin.toString(), false]],193 ],194 ]);195196 }));197198 [199 {200 method: 'setProperties',201 methodParams: [[{key: 'testKey1', value: Buffer.from('testValue1')}, {key: 'testKey2', value: Buffer.from('testValue2')}]],202 expectedProps: [{key: 'testKey1', value: 'testValue1'}, {key: 'testKey2', value: 'testValue2'}],203 },204 {205 method: 'setProperty' /*Soft-deprecated*/,206 methodParams: ['testKey1', Buffer.from('testValue1')],207 expectedProps: [{key: 'testKey1', value: 'testValue1'}],208 },209 ].map(testCase =>210 itEth(`[${testCase.method}] Can be set`, async({helper}) => {211 const caller = await helper.eth.createAccountWithBalance(donor);212 const collection = await helper.nft.mintCollection(alice, {213 tokenPropertyPermissions: [{214 key: 'testKey1',215 permission: {216 collectionAdmin: true,217 },218 }, {219 key: 'testKey2',220 permission: {221 collectionAdmin: true,222 },223 }],224 });225226 await collection.addAdmin(alice, {Ethereum: caller});227 const token = await collection.mintToken(alice);228229 const collectionEvm = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller, testCase.method === 'setProperty');230231 await collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).send({from: caller});232233 const properties = await token.getProperties();234 expect(properties).to.deep.equal(testCase.expectedProps);235 }));236237 [238 {mode: 'nft' as const, requiredPallets: []},239 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},240 ].map(testCase =>241 itEth.ifWithPallets(`Can be multiple set/read for ${testCase.mode}`, testCase.requiredPallets, async({helper}) => {242 const caller = await helper.eth.createAccountWithBalance(donor);243244 const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });245 const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.key, permission: {tokenOwner: true,246 collectionAdmin: true,247 mutable: true}}; });248249 const collection = await helper[testCase.mode].mintCollection(alice, {250 tokenPrefix: 'ethp',251 tokenPropertyPermissions: permissions,252 }) as UniqueNFTCollection | UniqueRFTCollection;253254 const token = await collection.mintToken(alice);255256 const valuesBefore = await token.getProperties(properties.map(p => p.key));257 expect(valuesBefore).to.be.deep.equal([]);258259260 await collection.addAdmin(alice, {Ethereum: caller});261262 const address = helper.ethAddress.fromCollectionId(collection.collectionId);263 const contract = await helper.ethNativeContract.collection(address, testCase.mode, caller);264265 expect(await contract.methods.properties(token.tokenId, []).call()).to.be.deep.equal([]);266267 await contract.methods.setProperties(token.tokenId, properties).send({from: caller});268269 const values = await token.getProperties(properties.map(p => p.key));270 expect(values).to.be.deep.equal(properties.map(p => { return {key: p.key, value: p.value.toString()}; }));271272 expect(await contract.methods.properties(token.tokenId, []).call()).to.be.like(properties273 .map(p => { return helper.ethProperty.property(p.key, p.value.toString()); }));274275 expect(await contract.methods.properties(token.tokenId, [properties[0].key]).call())276 .to.be.like([helper.ethProperty.property(properties[0].key, properties[0].value.toString())]);277 }));278279 [280 {mode: 'nft' as const, requiredPallets: []},281 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},282 ].map(testCase =>283 itEth.ifWithPallets(`Can be deleted for ${testCase.mode}`, testCase.requiredPallets, async({helper}) => {284 const caller = await helper.eth.createAccountWithBalance(donor);285 const collection = await helper[testCase.mode].mintCollection(alice, {286 tokenPropertyPermissions: [{287 key: 'testKey',288 permission: {289 mutable: true,290 collectionAdmin: true,291 },292 },293 {294 key: 'testKey_1',295 permission: {296 mutable: true,297 collectionAdmin: true,298 },299 }],300 });301302 const token = await collection.mintToken(alice);303 await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}, {key: 'testKey_1', value: 'testValue_1'}]);304 expect(await token.getProperties()).to.has.length(2);305306 await collection.addAdmin(alice, {Ethereum: caller});307308 const address = helper.ethAddress.fromCollectionId(collection.collectionId);309 const contract = await helper.ethNativeContract.collection(address, testCase.mode, caller);310311 await contract.methods.deleteProperties(token.tokenId, ['testKey', 'testKey_1']).send({from: caller});312313 const result = await token.getProperties(['testKey', 'testKey_1']);314 expect(result.length).to.equal(0);315 }));316317 itEth('Can be read', async({helper}) => {318 // FIXME: User with no balance should be able to call319 const caller = await helper.eth.createAccountWithBalance(alice);320 const collection = await helper.nft.mintCollection(alice, {321 tokenPropertyPermissions: [{322 key: 'testKey',323 permission: {324 collectionAdmin: true,325 },326 }],327 });328329 const token = await collection.mintToken(alice);330 await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}]);331332 const address = helper.ethAddress.fromCollectionId(collection.collectionId);333 const contract = await helper.ethNativeContract.collection(address, 'nft', caller);334335 const value = await contract.methods.property(token.tokenId, 'testKey').call();336 expect(value).to.equal(helper.getWeb3().utils.toHex('testValue'));337 });338});339340describe('EVM token properties negative', () => {341 let donor: IKeyringPair;342 let alice: IKeyringPair;343 let caller: string;344 let aliceCollection: UniqueNFTCollection;345 let token: UniqueNFToken;346 const tokenProps = [{key: 'testKey_1', value: 'testValue_1'}, {key: 'testKey_2', value: 'testValue_2'}];347 let collectionEvm: Contract;348349 before(async function() {350 await usingEthPlaygrounds(async (helper, privateKey) => {351 donor = await privateKey({url: import.meta.url});352 [alice] = await helper.arrange.createAccounts([100n], donor);353 });354 });355356 beforeEach(async () => {357 // 1. create collection with props: testKey_1, testKey_2358 // 2. create token and set props testKey_1, testKey_2359 await usingEthPlaygrounds(async (helper) => {360 aliceCollection = await helper.nft.mintCollection(alice, {361 tokenPropertyPermissions: [{362 key: 'testKey_1',363 permission: {364 mutable: true,365 collectionAdmin: true,366 },367 },368 {369 key: 'testKey_2',370 permission: {371 mutable: true,372 collectionAdmin: true,373 },374 }],375 });376 token = await aliceCollection.mintToken(alice);377 await token.setProperties(alice, tokenProps);378 collectionEvm = await helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(aliceCollection.collectionId), 'nft', caller, true);379 });380 });381382 [383 {method: 'setProperty', methodParams: [tokenProps[1].key, Buffer.from('newValue')]},384 {method: 'setProperties', methodParams: [[{key: tokenProps[1].key, value: Buffer.from('newValue')}]]},385 ].map(testCase =>386 itEth(`[${testCase.method}] Cannot set properties of non-owned collection`, async ({helper}) => {387 caller = await helper.eth.createAccountWithBalance(donor);388 collectionEvm = await helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(aliceCollection.collectionId), 'nft', caller, true);389 // Caller not an owner and not an admin, so he cannot set properties:390 await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).call({from: caller})).to.be.rejectedWith('NoPermission');391 await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).send({from: caller})).to.be.rejected;392393 // Props have not changed:394 const expectedProps = tokenProps.map(p => helper.ethProperty.property(p.key, p.value.toString()));395 const actualProps = await collectionEvm.methods.properties(token.tokenId, []).call();396 expect(actualProps).to.deep.eq(expectedProps);397 }));398399 [400 {method: 'setProperty', methodParams: ['testKey_3', Buffer.from('testValue3')]},401 {method: 'setProperties', methodParams: [[{key: 'testKey_3', value: Buffer.from('testValue3')}]]},402 ].map(testCase =>403 itEth(`[${testCase.method}] Cannot set non-existing properties`, async ({helper}) => {404 caller = await helper.eth.createAccountWithBalance(donor);405 collectionEvm = await helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(aliceCollection.collectionId), 'nft', caller, true);406 await helper.collection.addAdmin(alice, aliceCollection.collectionId, {Ethereum: caller});407408 await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).call({from: caller})).to.be.rejectedWith('NoPermission');409 await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).send({from: caller})).to.be.rejected;410411 // Props have not changed:412 const expectedProps = tokenProps.map(p => helper.ethProperty.property(p.key, p.value.toString()));413 const actualProps = await collectionEvm.methods.properties(token.tokenId, []).call();414 expect(actualProps).to.deep.eq(expectedProps);415 }));416417 [418 {method: 'deleteProperty', methodParams: ['testKey_2']},419 {method: 'deleteProperties', methodParams: [['testKey_2']]},420 ].map(testCase =>421 itEth(`[${testCase.method}] Cannot delete properties of non-owned collection`, async ({helper}) => {422 caller = await helper.eth.createAccountWithBalance(donor);423 collectionEvm = await helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(aliceCollection.collectionId), 'nft', caller, testCase.method == 'deleteProperty');424 // Caller not an owner and not an admin, so he cannot set properties:425 await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).call({from: caller})).to.be.rejectedWith('NoPermission');426 await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).send({from: caller})).to.be.rejected;427428 // Props have not changed:429 const expectedProps = tokenProps.map(p => helper.ethProperty.property(p.key, p.value.toString()));430 const actualProps = await collectionEvm.methods.properties(token.tokenId, []).call();431 expect(actualProps).to.deep.eq(expectedProps);432 }));433434 [435 {method: 'deleteProperty', methodParams: ['testKey_3']},436 {method: 'deleteProperties', methodParams: [['testKey_3']]},437 ].map(testCase =>438 itEth(`[${testCase.method}] Cannot delete non-existing properties`, async ({helper}) => {439 caller = await helper.eth.createAccountWithBalance(donor);440 collectionEvm = await helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(aliceCollection.collectionId), 'nft', caller, testCase.method == 'deleteProperty');441 await helper.collection.addAdmin(alice, aliceCollection.collectionId, {Ethereum: caller});442 // Caller cannot delete non-existing properties:443 await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).call({from: caller})).to.be.rejectedWith('NoPermission');444 await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).send({from: caller})).to.be.rejected;445 // Props have not changed:446 const expectedProps = tokenProps.map(p => helper.ethProperty.property(p.key, p.value.toString()));447 const actualProps = await collectionEvm.methods.properties(token.tokenId, []).call();448 expect(actualProps).to.deep.eq(expectedProps);449 }));450451 [452 {mode: 'nft' as const, requiredPallets: []},453 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},454 ].map(testCase =>455 itEth.ifWithPallets(`[${testCase.mode}] Cannot set token property permissions as non owner or admin`, testCase.requiredPallets, async({helper}) => {456 const owner = await helper.eth.createAccountWithBalance(donor);457 const caller = await helper.eth.createAccountWithBalance(donor);458459 const {collectionAddress} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');460 const collection = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);461462 await expect(collection.methods.setTokenPropertyPermissions([463 ['testKey_0', [464 [TokenPermissionField.Mutable, true],465 [TokenPermissionField.TokenOwner, true],466 [TokenPermissionField.CollectionAdmin, true]],467 ],468 ]).call({from: caller})).to.be.rejectedWith('NoPermission');469 }));470471 [472 {mode: 'nft' as const, requiredPallets: []},473 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},474 ].map(testCase =>475 itEth.ifWithPallets(`[${testCase.mode}] Cannot set token property permissions with invalid character`, testCase.requiredPallets, async({helper}) => {476 const owner = await helper.eth.createAccountWithBalance(donor);477478 const {collectionAddress} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');479 const collection = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);480481 await expect(collection.methods.setTokenPropertyPermissions([482 // "Space" is invalid character483 ['testKey 0', [484 [TokenPermissionField.Mutable, true],485 [TokenPermissionField.TokenOwner, true],486 [TokenPermissionField.CollectionAdmin, true]],487 ],488 ]).call({from: owner})).to.be.rejectedWith('InvalidCharacterInPropertyKey');489 }));490491 [492 {mode: 'nft' as const, requiredPallets: []},493 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},494 ].map(testCase =>495 itEth.ifWithPallets(`[${testCase.mode}] Can reconfigure token property permissions to stricter ones`, testCase.requiredPallets, async({helper}) => {496 const owner = await helper.eth.createAccountWithBalance(donor);497498 const {collectionAddress, collectionId} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');499 const collection = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);500501 // 1. Owner sets strict property-permissions:502 await collection.methods.setTokenPropertyPermissions([503 ['testKey', [504 [TokenPermissionField.Mutable, true],505 [TokenPermissionField.TokenOwner, true],506 [TokenPermissionField.CollectionAdmin, true]],507 ],508 ]).send({from: owner});509510 // 2. Owner can set stricter property-permissions:511 for(const values of [[true, true, false], [true, false, false], [false, false, false]]) {512 await collection.methods.setTokenPropertyPermissions([513 ['testKey', [514 [TokenPermissionField.Mutable, values[0]],515 [TokenPermissionField.TokenOwner, values[1]],516 [TokenPermissionField.CollectionAdmin, values[2]]],517 ],518 ]).send({from: owner});519 }520521 expect(await helper[testCase.mode].getPropertyPermissions(collectionId)).to.be.deep.equal([{522 key: 'testKey',523 permission: {mutable: false, collectionAdmin: false, tokenOwner: false},524 }]);525 }));526527 [528 {mode: 'nft' as const, requiredPallets: []},529 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},530 ].map(testCase =>531 itEth.ifWithPallets(`[${testCase.mode}] Cannot reconfigure token property permissions to less strict ones`, testCase.requiredPallets, async({helper}) => {532 const owner = await helper.eth.createAccountWithBalance(donor);533534 const {collectionAddress} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');535 const collection = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);536537 // 1. Owner sets strict property-permissions:538 await collection.methods.setTokenPropertyPermissions([539 ['testKey', [540 [TokenPermissionField.Mutable, false],541 [TokenPermissionField.TokenOwner, false],542 [TokenPermissionField.CollectionAdmin, false]],543 ],544 ]).send({from: owner});545546 // 2. Owner cannot set less strict property-permissions:547 for(const values of [[true, false, false], [false, true, false], [false, false, true]]) {548 await expect(collection.methods.setTokenPropertyPermissions([549 ['testKey', [550 [TokenPermissionField.Mutable, values[0]],551 [TokenPermissionField.TokenOwner, values[1]],552 [TokenPermissionField.CollectionAdmin, values[2]]],553 ],554 ]).call({from: owner})).to.be.rejectedWith('NoPermission');555 }556 }));557});558559560type ElementOf<A> = A extends readonly (infer T)[] ? T : never;561function* cartesian<T extends Array<Array<any>>, R extends Array<any>>(internalRest: [...R], ...args: [...T]): Generator<[...R, ...{[K in keyof T]: ElementOf<T[K]>}]> {562 if(args.length === 0) {563 yield internalRest as any;564 return;565 }566 for(const value of args[0]) {567 yield* cartesian([...internalRest, value], ...args.slice(1)) as any;568 }569}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 {Contract} from 'web3-eth-contract';19import {itEth, usingEthPlaygrounds, expect} from './util';20import {ITokenPropertyPermission} from '../util/playgrounds/types';21import {Pallets} from '../util';22import {UniqueNFTCollection, UniqueNFToken, UniqueRFTCollection} from '../util/playgrounds/unique';23import {TokenPermissionField} from './util/playgrounds/types';2425describe('EVM token properties', () => {26 let donor: IKeyringPair;27 let alice: IKeyringPair;2829 before(async function() {30 await usingEthPlaygrounds(async (helper, privateKey) => {31 donor = await privateKey({url: import.meta.url});32 [alice] = await helper.arrange.createAccounts([1000n], donor);33 });34 });3536 [37 {mode: 'nft' as const, requiredPallets: []},38 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},39 ].map(testCase =>40 itEth.ifWithPallets(`[${testCase.mode}] Can set all possible token property permissions`, testCase.requiredPallets, async({helper}) => {41 const owner = await helper.eth.createAccountWithBalance(donor);42 const caller = await helper.ethCrossAccount.createAccountWithBalance(donor);43 for(const [mutable,collectionAdmin, tokenOwner] of cartesian([], [false, true], [false, true], [false, true])) {44 const {collectionId, collectionAddress} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');45 const collection = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);46 await collection.methods.addCollectionAdminCross(caller).send({from: owner});4748 await collection.methods.setTokenPropertyPermissions([49 ['testKey', [50 [TokenPermissionField.Mutable, mutable],51 [TokenPermissionField.TokenOwner, tokenOwner],52 [TokenPermissionField.CollectionAdmin, collectionAdmin]],53 ],54 ]).send({from: caller.eth});5556 expect(await helper[testCase.mode].getPropertyPermissions(collectionId)).to.be.deep.equal([{57 key: 'testKey',58 permission: {mutable, collectionAdmin, tokenOwner},59 }]);6061 expect(await collection.methods.tokenPropertyPermissions().call({from: caller.eth})).to.be.like([62 ['testKey', [63 [TokenPermissionField.Mutable.toString(), mutable],64 [TokenPermissionField.TokenOwner.toString(), tokenOwner],65 [TokenPermissionField.CollectionAdmin.toString(), collectionAdmin]],66 ],67 ]);68 }69 }));7071 [72 {mode: 'nft' as const, requiredPallets: []},73 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},74 ].map(testCase =>75 itEth.ifWithPallets(`[${testCase.mode}] Can set multiple token property permissions as owner`, testCase.requiredPallets, async({helper}) => {76 const owner = await helper.eth.createAccountWithBalance(donor);7778 const {collectionId, collectionAddress} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');79 const collection = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);8081 await collection.methods.setTokenPropertyPermissions([82 ['testKey_0', [83 [TokenPermissionField.Mutable, true],84 [TokenPermissionField.TokenOwner, true],85 [TokenPermissionField.CollectionAdmin, true]],86 ],87 ['testKey_1', [88 [TokenPermissionField.Mutable, true],89 [TokenPermissionField.TokenOwner, false],90 [TokenPermissionField.CollectionAdmin, true]],91 ],92 ['testKey_2', [93 [TokenPermissionField.Mutable, false],94 [TokenPermissionField.TokenOwner, true],95 [TokenPermissionField.CollectionAdmin, false]],96 ],97 ]).send({from: owner});9899 expect(await helper[testCase.mode].getPropertyPermissions(collectionId)).to.be.deep.equal([100 {101 key: 'testKey_0',102 permission: {mutable: true, tokenOwner: true, collectionAdmin: true},103 },104 {105 key: 'testKey_1',106 permission: {mutable: true, tokenOwner: false, collectionAdmin: true},107 },108 {109 key: 'testKey_2',110 permission: {mutable: false, tokenOwner: true, collectionAdmin: false},111 },112 ]);113114 expect(await collection.methods.tokenPropertyPermissions().call({from: owner})).to.be.like([115 ['testKey_0', [116 [TokenPermissionField.Mutable.toString(), true],117 [TokenPermissionField.TokenOwner.toString(), true],118 [TokenPermissionField.CollectionAdmin.toString(), true]],119 ],120 ['testKey_1', [121 [TokenPermissionField.Mutable.toString(), true],122 [TokenPermissionField.TokenOwner.toString(), false],123 [TokenPermissionField.CollectionAdmin.toString(), true]],124 ],125 ['testKey_2', [126 [TokenPermissionField.Mutable.toString(), false],127 [TokenPermissionField.TokenOwner.toString(), true],128 [TokenPermissionField.CollectionAdmin.toString(), false]],129 ],130 ]);131 }));132133 [134 {mode: 'nft' as const, requiredPallets: []},135 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},136 ].map(testCase =>137 itEth.ifWithPallets(`[${testCase.mode}] Can set multiple token property permissions as admin`, testCase.requiredPallets, async({helper}) => {138 const owner = await helper.eth.createAccountWithBalance(donor);139 const caller = await helper.ethCrossAccount.createAccountWithBalance(donor);140141 const {collectionId, collectionAddress} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');142 const collection = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);143 await collection.methods.addCollectionAdminCross(caller).send({from: owner});144145 await collection.methods.setTokenPropertyPermissions([146 ['testKey_0', [147 [TokenPermissionField.Mutable, true],148 [TokenPermissionField.TokenOwner, true],149 [TokenPermissionField.CollectionAdmin, true]],150 ],151 ['testKey_1', [152 [TokenPermissionField.Mutable, true],153 [TokenPermissionField.TokenOwner, false],154 [TokenPermissionField.CollectionAdmin, true]],155 ],156 ['testKey_2', [157 [TokenPermissionField.Mutable, false],158 [TokenPermissionField.TokenOwner, true],159 [TokenPermissionField.CollectionAdmin, false]],160 ],161 ]).send({from: caller.eth});162163 expect(await helper[testCase.mode].getPropertyPermissions(collectionId)).to.be.deep.equal([164 {165 key: 'testKey_0',166 permission: {mutable: true, tokenOwner: true, collectionAdmin: true},167 },168 {169 key: 'testKey_1',170 permission: {mutable: true, tokenOwner: false, collectionAdmin: true},171 },172 {173 key: 'testKey_2',174 permission: {mutable: false, tokenOwner: true, collectionAdmin: false},175 },176 ]);177178 expect(await collection.methods.tokenPropertyPermissions().call({from: caller.eth})).to.be.like([179 ['testKey_0', [180 [TokenPermissionField.Mutable.toString(), true],181 [TokenPermissionField.TokenOwner.toString(), true],182 [TokenPermissionField.CollectionAdmin.toString(), true]],183 ],184 ['testKey_1', [185 [TokenPermissionField.Mutable.toString(), true],186 [TokenPermissionField.TokenOwner.toString(), false],187 [TokenPermissionField.CollectionAdmin.toString(), true]],188 ],189 ['testKey_2', [190 [TokenPermissionField.Mutable.toString(), false],191 [TokenPermissionField.TokenOwner.toString(), true],192 [TokenPermissionField.CollectionAdmin.toString(), false]],193 ],194 ]);195196 }));197198 [199 {200 method: 'setProperties',201 methodParams: [[{key: 'testKey1', value: Buffer.from('testValue1')}, {key: 'testKey2', value: Buffer.from('testValue2')}]],202 expectedProps: [{key: 'testKey1', value: 'testValue1'}, {key: 'testKey2', value: 'testValue2'}],203 },204 {205 method: 'setProperty' /*Soft-deprecated*/,206 methodParams: ['testKey1', Buffer.from('testValue1')],207 expectedProps: [{key: 'testKey1', value: 'testValue1'}],208 },209 ].map(testCase =>210 itEth(`[${testCase.method}] Can be set`, async({helper}) => {211 const caller = await helper.eth.createAccountWithBalance(donor);212 const collection = await helper.nft.mintCollection(alice, {213 tokenPropertyPermissions: [{214 key: 'testKey1',215 permission: {216 collectionAdmin: true,217 },218 }, {219 key: 'testKey2',220 permission: {221 collectionAdmin: true,222 },223 }],224 });225226 await collection.addAdmin(alice, {Ethereum: caller});227 const token = await collection.mintToken(alice);228229 const collectionEvm = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller, testCase.method === 'setProperty');230231 await collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).send({from: caller});232233 const properties = await token.getProperties();234 expect(properties).to.deep.equal(testCase.expectedProps);235 }));236237 [238 {mode: 'nft' as const, requiredPallets: []},239 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},240 ].map(testCase =>241 itEth.ifWithPallets(`Can be multiple set/read for ${testCase.mode}`, testCase.requiredPallets, async({helper}) => {242 const caller = await helper.eth.createAccountWithBalance(donor);243244 const properties = Array(5).fill(0).map((_, i) => ({key: `key_${i}`, value: Buffer.from(`value_${i}`)}));245 const permissions: ITokenPropertyPermission[] = properties.map(p => ({key: p.key, permission: {tokenOwner: true,246 collectionAdmin: true,247 mutable: true}}));248249 const collection = await helper[testCase.mode].mintCollection(alice, {250 tokenPrefix: 'ethp',251 tokenPropertyPermissions: permissions,252 }) as UniqueNFTCollection | UniqueRFTCollection;253254 const token = await collection.mintToken(alice);255256 const valuesBefore = await token.getProperties(properties.map(p => p.key));257 expect(valuesBefore).to.be.deep.equal([]);258259260 await collection.addAdmin(alice, {Ethereum: caller});261262 const address = helper.ethAddress.fromCollectionId(collection.collectionId);263 const contract = await helper.ethNativeContract.collection(address, testCase.mode, caller);264265 expect(await contract.methods.properties(token.tokenId, []).call()).to.be.deep.equal([]);266267 await contract.methods.setProperties(token.tokenId, properties).send({from: caller});268269 const values = await token.getProperties(properties.map(p => p.key));270 expect(values).to.be.deep.equal(properties.map(p => ({key: p.key, value: p.value.toString()})));271272 expect(await contract.methods.properties(token.tokenId, []).call()).to.be.like(properties273 .map(p => helper.ethProperty.property(p.key, p.value.toString())));274275 expect(await contract.methods.properties(token.tokenId, [properties[0].key]).call())276 .to.be.like([helper.ethProperty.property(properties[0].key, properties[0].value.toString())]);277 }));278279 [280 {mode: 'nft' as const, requiredPallets: []},281 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},282 ].map(testCase =>283 itEth.ifWithPallets(`Can be deleted for ${testCase.mode}`, testCase.requiredPallets, async({helper}) => {284 const caller = await helper.eth.createAccountWithBalance(donor);285 const collection = await helper[testCase.mode].mintCollection(alice, {286 tokenPropertyPermissions: [{287 key: 'testKey',288 permission: {289 mutable: true,290 collectionAdmin: true,291 },292 },293 {294 key: 'testKey_1',295 permission: {296 mutable: true,297 collectionAdmin: true,298 },299 }],300 });301302 const token = await collection.mintToken(alice);303 await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}, {key: 'testKey_1', value: 'testValue_1'}]);304 expect(await token.getProperties()).to.has.length(2);305306 await collection.addAdmin(alice, {Ethereum: caller});307308 const address = helper.ethAddress.fromCollectionId(collection.collectionId);309 const contract = await helper.ethNativeContract.collection(address, testCase.mode, caller);310311 await contract.methods.deleteProperties(token.tokenId, ['testKey', 'testKey_1']).send({from: caller});312313 const result = await token.getProperties(['testKey', 'testKey_1']);314 expect(result.length).to.equal(0);315 }));316317 itEth('Can be read', async({helper}) => {318 // FIXME: User with no balance should be able to call319 const caller = await helper.eth.createAccountWithBalance(alice);320 const collection = await helper.nft.mintCollection(alice, {321 tokenPropertyPermissions: [{322 key: 'testKey',323 permission: {324 collectionAdmin: true,325 },326 }],327 });328329 const token = await collection.mintToken(alice);330 await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}]);331332 const address = helper.ethAddress.fromCollectionId(collection.collectionId);333 const contract = await helper.ethNativeContract.collection(address, 'nft', caller);334335 const value = await contract.methods.property(token.tokenId, 'testKey').call();336 expect(value).to.equal(helper.getWeb3().utils.toHex('testValue'));337 });338});339340describe('EVM token properties negative', () => {341 let donor: IKeyringPair;342 let alice: IKeyringPair;343 let caller: string;344 let aliceCollection: UniqueNFTCollection;345 let token: UniqueNFToken;346 const tokenProps = [{key: 'testKey_1', value: 'testValue_1'}, {key: 'testKey_2', value: 'testValue_2'}];347 let collectionEvm: Contract;348349 before(async function() {350 await usingEthPlaygrounds(async (helper, privateKey) => {351 donor = await privateKey({url: import.meta.url});352 [alice] = await helper.arrange.createAccounts([100n], donor);353 });354 });355356 beforeEach(async () => {357 // 1. create collection with props: testKey_1, testKey_2358 // 2. create token and set props testKey_1, testKey_2359 await usingEthPlaygrounds(async (helper) => {360 aliceCollection = await helper.nft.mintCollection(alice, {361 tokenPropertyPermissions: [{362 key: 'testKey_1',363 permission: {364 mutable: true,365 collectionAdmin: true,366 },367 },368 {369 key: 'testKey_2',370 permission: {371 mutable: true,372 collectionAdmin: true,373 },374 }],375 });376 token = await aliceCollection.mintToken(alice);377 await token.setProperties(alice, tokenProps);378 collectionEvm = await helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(aliceCollection.collectionId), 'nft', caller, true);379 });380 });381382 [383 {method: 'setProperty', methodParams: [tokenProps[1].key, Buffer.from('newValue')]},384 {method: 'setProperties', methodParams: [[{key: tokenProps[1].key, value: Buffer.from('newValue')}]]},385 ].map(testCase =>386 itEth(`[${testCase.method}] Cannot set properties of non-owned collection`, async ({helper}) => {387 caller = await helper.eth.createAccountWithBalance(donor);388 collectionEvm = await helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(aliceCollection.collectionId), 'nft', caller, true);389 // Caller not an owner and not an admin, so he cannot set properties:390 await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).call({from: caller})).to.be.rejectedWith('NoPermission');391 await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).send({from: caller})).to.be.rejected;392393 // Props have not changed:394 const expectedProps = tokenProps.map(p => helper.ethProperty.property(p.key, p.value.toString()));395 const actualProps = await collectionEvm.methods.properties(token.tokenId, []).call();396 expect(actualProps).to.deep.eq(expectedProps);397 }));398399 [400 {method: 'setProperty', methodParams: ['testKey_3', Buffer.from('testValue3')]},401 {method: 'setProperties', methodParams: [[{key: 'testKey_3', value: Buffer.from('testValue3')}]]},402 ].map(testCase =>403 itEth(`[${testCase.method}] Cannot set non-existing properties`, async ({helper}) => {404 caller = await helper.eth.createAccountWithBalance(donor);405 collectionEvm = await helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(aliceCollection.collectionId), 'nft', caller, true);406 await helper.collection.addAdmin(alice, aliceCollection.collectionId, {Ethereum: caller});407408 await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).call({from: caller})).to.be.rejectedWith('NoPermission');409 await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).send({from: caller})).to.be.rejected;410411 // Props have not changed:412 const expectedProps = tokenProps.map(p => helper.ethProperty.property(p.key, p.value.toString()));413 const actualProps = await collectionEvm.methods.properties(token.tokenId, []).call();414 expect(actualProps).to.deep.eq(expectedProps);415 }));416417 [418 {method: 'deleteProperty', methodParams: ['testKey_2']},419 {method: 'deleteProperties', methodParams: [['testKey_2']]},420 ].map(testCase =>421 itEth(`[${testCase.method}] Cannot delete properties of non-owned collection`, async ({helper}) => {422 caller = await helper.eth.createAccountWithBalance(donor);423 collectionEvm = await helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(aliceCollection.collectionId), 'nft', caller, testCase.method == 'deleteProperty');424 // Caller not an owner and not an admin, so he cannot set properties:425 await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).call({from: caller})).to.be.rejectedWith('NoPermission');426 await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).send({from: caller})).to.be.rejected;427428 // Props have not changed:429 const expectedProps = tokenProps.map(p => helper.ethProperty.property(p.key, p.value.toString()));430 const actualProps = await collectionEvm.methods.properties(token.tokenId, []).call();431 expect(actualProps).to.deep.eq(expectedProps);432 }));433434 [435 {method: 'deleteProperty', methodParams: ['testKey_3']},436 {method: 'deleteProperties', methodParams: [['testKey_3']]},437 ].map(testCase =>438 itEth(`[${testCase.method}] Cannot delete non-existing properties`, async ({helper}) => {439 caller = await helper.eth.createAccountWithBalance(donor);440 collectionEvm = await helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(aliceCollection.collectionId), 'nft', caller, testCase.method == 'deleteProperty');441 await helper.collection.addAdmin(alice, aliceCollection.collectionId, {Ethereum: caller});442 // Caller cannot delete non-existing properties:443 await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).call({from: caller})).to.be.rejectedWith('NoPermission');444 await expect(collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).send({from: caller})).to.be.rejected;445 // Props have not changed:446 const expectedProps = tokenProps.map(p => helper.ethProperty.property(p.key, p.value.toString()));447 const actualProps = await collectionEvm.methods.properties(token.tokenId, []).call();448 expect(actualProps).to.deep.eq(expectedProps);449 }));450451 [452 {mode: 'nft' as const, requiredPallets: []},453 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},454 ].map(testCase =>455 itEth.ifWithPallets(`[${testCase.mode}] Cannot set token property permissions as non owner or admin`, testCase.requiredPallets, async({helper}) => {456 const owner = await helper.eth.createAccountWithBalance(donor);457 const caller = await helper.eth.createAccountWithBalance(donor);458459 const {collectionAddress} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');460 const collection = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);461462 await expect(collection.methods.setTokenPropertyPermissions([463 ['testKey_0', [464 [TokenPermissionField.Mutable, true],465 [TokenPermissionField.TokenOwner, true],466 [TokenPermissionField.CollectionAdmin, true]],467 ],468 ]).call({from: caller})).to.be.rejectedWith('NoPermission');469 }));470471 [472 {mode: 'nft' as const, requiredPallets: []},473 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},474 ].map(testCase =>475 itEth.ifWithPallets(`[${testCase.mode}] Cannot set token property permissions with invalid character`, testCase.requiredPallets, async({helper}) => {476 const owner = await helper.eth.createAccountWithBalance(donor);477478 const {collectionAddress} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');479 const collection = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);480481 await expect(collection.methods.setTokenPropertyPermissions([482 // "Space" is invalid character483 ['testKey 0', [484 [TokenPermissionField.Mutable, true],485 [TokenPermissionField.TokenOwner, true],486 [TokenPermissionField.CollectionAdmin, true]],487 ],488 ]).call({from: owner})).to.be.rejectedWith('InvalidCharacterInPropertyKey');489 }));490491 [492 {mode: 'nft' as const, requiredPallets: []},493 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},494 ].map(testCase =>495 itEth.ifWithPallets(`[${testCase.mode}] Can reconfigure token property permissions to stricter ones`, testCase.requiredPallets, async({helper}) => {496 const owner = await helper.eth.createAccountWithBalance(donor);497498 const {collectionAddress, collectionId} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');499 const collection = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);500501 // 1. Owner sets strict property-permissions:502 await collection.methods.setTokenPropertyPermissions([503 ['testKey', [504 [TokenPermissionField.Mutable, true],505 [TokenPermissionField.TokenOwner, true],506 [TokenPermissionField.CollectionAdmin, true]],507 ],508 ]).send({from: owner});509510 // 2. Owner can set stricter property-permissions:511 for(const values of [[true, true, false], [true, false, false], [false, false, false]]) {512 await collection.methods.setTokenPropertyPermissions([513 ['testKey', [514 [TokenPermissionField.Mutable, values[0]],515 [TokenPermissionField.TokenOwner, values[1]],516 [TokenPermissionField.CollectionAdmin, values[2]]],517 ],518 ]).send({from: owner});519 }520521 expect(await helper[testCase.mode].getPropertyPermissions(collectionId)).to.be.deep.equal([{522 key: 'testKey',523 permission: {mutable: false, collectionAdmin: false, tokenOwner: false},524 }]);525 }));526527 [528 {mode: 'nft' as const, requiredPallets: []},529 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},530 ].map(testCase =>531 itEth.ifWithPallets(`[${testCase.mode}] Cannot reconfigure token property permissions to less strict ones`, testCase.requiredPallets, async({helper}) => {532 const owner = await helper.eth.createAccountWithBalance(donor);533534 const {collectionAddress} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');535 const collection = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);536537 // 1. Owner sets strict property-permissions:538 await collection.methods.setTokenPropertyPermissions([539 ['testKey', [540 [TokenPermissionField.Mutable, false],541 [TokenPermissionField.TokenOwner, false],542 [TokenPermissionField.CollectionAdmin, false]],543 ],544 ]).send({from: owner});545546 // 2. Owner cannot set less strict property-permissions:547 for(const values of [[true, false, false], [false, true, false], [false, false, true]]) {548 await expect(collection.methods.setTokenPropertyPermissions([549 ['testKey', [550 [TokenPermissionField.Mutable, values[0]],551 [TokenPermissionField.TokenOwner, values[1]],552 [TokenPermissionField.CollectionAdmin, values[2]]],553 ],554 ]).call({from: owner})).to.be.rejectedWith('NoPermission');555 }556 }));557});558559560type ElementOf<A> = A extends readonly (infer T)[] ? T : never;561function* cartesian<T extends Array<Array<any>>, R extends Array<any>>(internalRest: [...R], ...args: [...T]): Generator<[...R, ...{[K in keyof T]: ElementOf<T[K]>}]> {562 if(args.length === 0) {563 yield internalRest as any;564 return;565 }566 for(const value of args[0]) {567 yield* cartesian([...internalRest, value], ...args.slice(1)) as any;568 }569}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);