difftreelog
fix after rebase
in: master
3 files changed
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 {IEthCrossAccountId} from '../util/playgrounds/types';18import {usingEthPlaygrounds, itEth, expect, EthUniqueHelper} from './util';1920async function recordEthFee(helper: EthUniqueHelper, userAddress: string, call: () => Promise<any>) {21 const before = await helper.balance.getSubstrate(helper.address.ethToSubstrate(userAddress));22 await call();23 await helper.wait.newBlocks(1);24 const after = await helper.balance.getSubstrate(helper.address.ethToSubstrate(userAddress));2526 expect(after < before).to.be.true;2728 return before - after;29}3031describe('Add collection admins', () => {32 let donor: IKeyringPair;3334 before(async function() {35 await usingEthPlaygrounds(async (_helper, privateKey) => {36 donor = await privateKey({filename: __filename});37 });38 });3940 itEth('Add admin by owner', async ({helper}) => {41 const owner = await helper.eth.createAccountWithBalance(donor);42 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');43 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);4445 const newAdmin = helper.eth.createAccount();4647 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();48 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);49 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())50 .to.be.eq(newAdmin.toLocaleLowerCase());51 });5253 itEth('Add cross account admin by owner', async ({helper, privateKey}) => {54 const owner = await helper.eth.createAccountWithBalance(donor);55 56 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');57 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);58 59 const newAdmin = await privateKey('//Bob');60 const newAdminCross = helper.ethCrossAccount.fromKeyringPair(newAdmin);61 await collectionEvm.methods.addCollectionAdminCross(newAdminCross).send();6263 const adminList = await helper.collection.getAdmins(collectionId);64 expect(adminList).to.be.like([{Substrate: newAdmin.address}]);65 });6667 itEth('Verify owner or admin', async ({helper}) => {68 const owner = await helper.eth.createAccountWithBalance(donor);69 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');7071 const newAdmin = helper.eth.createAccount();72 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);73 74 expect(await collectionEvm.methods.isOwnerOrAdmin(newAdmin).call()).to.be.false;75 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();76 expect(await collectionEvm.methods.isOwnerOrAdmin(newAdmin).call()).to.be.true;77 });7879 itEth.skip('Check adminlist', async ({helper, privateKey}) => {80 const owner = await helper.eth.createAccountWithBalance(donor);81 82 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');83 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);8485 const admin1 = helper.eth.createAccount();86 const admin2 = await privateKey('admin');87 await collectionEvm.methods.addCollectionAdmin(admin1).send();88 await collectionEvm.methods.addCollectionAdminSubstrate(admin2.addressRaw).send();8990 const adminListRpc = await helper.collection.getAdmins(collectionId);91 let adminListEth = await collectionEvm.methods.collectionAdmins().call();92 adminListEth = adminListEth.map((element: IEthCrossAccountId) => {93 return helper.address.convertCrossAccountFromEthCrossAcoount(element);94 });95 expect(adminListRpc).to.be.like(adminListEth);96 });97 98 itEth('(!negative tests!) Add admin by ADMIN is not allowed', async ({helper}) => {99 const owner = await helper.eth.createAccountWithBalance(donor);100 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');101102 const admin = await helper.eth.createAccountWithBalance(donor);103 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);104 await collectionEvm.methods.addCollectionAdmin(admin).send();105106 const user = helper.eth.createAccount();107 await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: admin}))108 .to.be.rejectedWith('NoPermission');109110 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);111 expect(adminList.length).to.be.eq(1);112 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())113 .to.be.eq(admin.toLocaleLowerCase());114 });115116 itEth('(!negative tests!) Add admin by USER is not allowed', async ({helper}) => {117 const owner = await helper.eth.createAccountWithBalance(donor);118 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');119120 const notAdmin = await helper.eth.createAccountWithBalance(donor);121 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);122123 const user = helper.eth.createAccount();124 await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: notAdmin}))125 .to.be.rejectedWith('NoPermission');126127 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);128 expect(adminList.length).to.be.eq(0);129 });130131 itEth.skip('(!negative tests!) Add substrate admin by ADMIN is not allowed', async ({helper}) => {132 const owner = await helper.eth.createAccountWithBalance(donor);133 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');134135 const admin = await helper.eth.createAccountWithBalance(donor);136 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);137 await collectionEvm.methods.addCollectionAdmin(admin).send();138139 const [notAdmin] = await helper.arrange.createAccounts([10n], donor);140 await expect(collectionEvm.methods.addCollectionAdminSubstrate(notAdmin.addressRaw).call({from: admin}))141 .to.be.rejectedWith('NoPermission');142143 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);144 expect(adminList.length).to.be.eq(1);145 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())146 .to.be.eq(admin.toLocaleLowerCase());147 });148149 itEth.skip('(!negative tests!) Add substrate admin by USER is not allowed', async ({helper}) => {150 const owner = await helper.eth.createAccountWithBalance(donor);151 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');152153 const notAdmin0 = await helper.eth.createAccountWithBalance(donor);154 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);155 const [notAdmin1] = await helper.arrange.createAccounts([10n], donor);156 await expect(collectionEvm.methods.addCollectionAdminSubstrate(notAdmin1.addressRaw).call({from: notAdmin0}))157 .to.be.rejectedWith('NoPermission');158159 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);160 expect(adminList.length).to.be.eq(0);161 });162});163164describe('Remove collection admins', () => {165 let donor: IKeyringPair;166167 before(async function() {168 await usingEthPlaygrounds(async (_helper, privateKey) => {169 donor = await privateKey({filename: __filename});170 });171 });172173 itEth('Remove admin by owner', async ({helper}) => {174 const owner = await helper.eth.createAccountWithBalance(donor);175 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');176177 const newAdmin = helper.eth.createAccount();178 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);179 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();180181 {182 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);183 expect(adminList.length).to.be.eq(1);184 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())185 .to.be.eq(newAdmin.toLocaleLowerCase());186 }187188 await collectionEvm.methods.removeCollectionAdmin(newAdmin).send();189 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);190 expect(adminList.length).to.be.eq(0);191 });192193 itEth.skip('Remove substrate admin by owner', async ({helper}) => {194 const owner = await helper.eth.createAccountWithBalance(donor);195 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');196197 const [newAdmin] = await helper.arrange.createAccounts([10n], donor);198 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);199 await collectionEvm.methods.addCollectionAdminSubstrate(newAdmin.addressRaw).send();200 {201 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);202 expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())203 .to.be.eq(newAdmin.address.toLocaleLowerCase());204 }205206 await collectionEvm.methods.removeCollectionAdminSubstrate(newAdmin.addressRaw).send();207 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);208 expect(adminList.length).to.be.eq(0);209 });210211 itEth('(!negative tests!) Remove admin by ADMIN is not allowed', async ({helper}) => {212 const owner = await helper.eth.createAccountWithBalance(donor);213 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');214215 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);216217 const admin0 = await helper.eth.createAccountWithBalance(donor);218 await collectionEvm.methods.addCollectionAdmin(admin0).send();219 const admin1 = await helper.eth.createAccountWithBalance(donor);220 await collectionEvm.methods.addCollectionAdmin(admin1).send();221222 await expect(collectionEvm.methods.removeCollectionAdmin(admin1).call({from: admin0}))223 .to.be.rejectedWith('NoPermission');224 {225 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);226 expect(adminList.length).to.be.eq(2);227 expect(adminList.toString().toLocaleLowerCase())228 .to.be.deep.contains(admin0.toLocaleLowerCase())229 .to.be.deep.contains(admin1.toLocaleLowerCase());230 }231 });232233 itEth('(!negative tests!) Remove admin by USER is not allowed', async ({helper}) => {234 const owner = await helper.eth.createAccountWithBalance(donor);235 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');236237 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);238239 const admin = await helper.eth.createAccountWithBalance(donor);240 await collectionEvm.methods.addCollectionAdmin(admin).send();241 const notAdmin = helper.eth.createAccount();242243 await expect(collectionEvm.methods.removeCollectionAdmin(admin).call({from: notAdmin}))244 .to.be.rejectedWith('NoPermission');245 {246 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);247 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())248 .to.be.eq(admin.toLocaleLowerCase());249 expect(adminList.length).to.be.eq(1);250 }251 });252253 itEth.skip('(!negative tests!) Remove substrate admin by ADMIN is not allowed', async ({helper}) => {254 const owner = await helper.eth.createAccountWithBalance(donor);255 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');256257 const [adminSub] = await helper.arrange.createAccounts([10n], donor);258 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);259 await collectionEvm.methods.addCollectionAdminSubstrate(adminSub.addressRaw).send();260 const adminEth = await helper.eth.createAccountWithBalance(donor);261 await collectionEvm.methods.addCollectionAdmin(adminEth).send();262263 await expect(collectionEvm.methods.removeCollectionAdminSubstrate(adminSub.addressRaw).call({from: adminEth}))264 .to.be.rejectedWith('NoPermission');265266 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);267 expect(adminList.length).to.be.eq(2);268 expect(adminList.toString().toLocaleLowerCase())269 .to.be.deep.contains(adminSub.address.toLocaleLowerCase())270 .to.be.deep.contains(adminEth.toLocaleLowerCase());271 });272273 itEth.skip('(!negative tests!) Remove substrate admin by USER is not allowed', async ({helper}) => {274 const owner = await helper.eth.createAccountWithBalance(donor);275 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');276277 const [adminSub] = await helper.arrange.createAccounts([10n], donor);278 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);279 await collectionEvm.methods.addCollectionAdminSubstrate(adminSub.addressRaw).send();280 const notAdminEth = await helper.eth.createAccountWithBalance(donor);281282 await expect(collectionEvm.methods.removeCollectionAdminSubstrate(adminSub.addressRaw).call({from: notAdminEth}))283 .to.be.rejectedWith('NoPermission');284285 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);286 expect(adminList.length).to.be.eq(1);287 expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())288 .to.be.eq(adminSub.address.toLocaleLowerCase());289 });290});291292describe('Change owner tests', () => {293 let donor: IKeyringPair;294295 before(async function() {296 await usingEthPlaygrounds(async (_helper, privateKey) => {297 donor = await privateKey({filename: __filename});298 });299 });300301 itEth('Change owner', async ({helper}) => {302 const owner = await helper.eth.createAccountWithBalance(donor);303 const newOwner = await helper.eth.createAccountWithBalance(donor);304 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');305 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);306307 await collectionEvm.methods.changeCollectionOwner(newOwner).send();308309 expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.false;310 expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.true;311 });312313 itEth('change owner call fee', async ({helper}) => {314 const owner = await helper.eth.createAccountWithBalance(donor);315 const newOwner = await helper.eth.createAccountWithBalance(donor);316 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');317 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);318 const cost = await recordEthFee(helper, owner, () => collectionEvm.methods.changeCollectionOwner(newOwner).send());319 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));320 expect(cost > 0);321 });322323 itEth('(!negative tests!) call setOwner by non owner', async ({helper}) => {324 const owner = await helper.eth.createAccountWithBalance(donor);325 const newOwner = await helper.eth.createAccountWithBalance(donor);326 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');327 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);328329 await expect(collectionEvm.methods.changeCollectionOwner(newOwner).send({from: newOwner})).to.be.rejected;330 expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.false;331 });332});333334describe('Change substrate owner tests', () => {335 let donor: IKeyringPair;336337 before(async function() {338 await usingEthPlaygrounds(async (_helper, privateKey) => {339 donor = await privateKey({filename: __filename});340 });341 });342343 itEth.skip('Change owner', async ({helper}) => {344 const owner = await helper.eth.createAccountWithBalance(donor);345 const [newOwner] = await helper.arrange.createAccounts([10n], donor);346 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');347 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);348349 expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.true;350 expect(await collectionEvm.methods.isOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.false;351352 await collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send();353354 expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.false;355 expect(await collectionEvm.methods.isOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.true;356 });357358 itEth.skip('change owner call fee', async ({helper}) => {359 const owner = await helper.eth.createAccountWithBalance(donor);360 const [newOwner] = await helper.arrange.createAccounts([10n], donor);361 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');362 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);363364 const cost = await recordEthFee(helper, owner, () => collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send());365 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));366 expect(cost > 0);367 });368369 itEth.skip('(!negative tests!) call setOwner by non owner', async ({helper}) => {370 const owner = await helper.eth.createAccountWithBalance(donor);371 const otherReceiver = await helper.eth.createAccountWithBalance(donor);372 const [newOwner] = await helper.arrange.createAccounts([10n], donor);373 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');374 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);375376 await expect(collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send({from: otherReceiver})).to.be.rejected;377 expect(await collectionEvm.methods.isOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.false;378 });379});tests/src/eth/collectionProperties.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionProperties.test.ts
+++ b/tests/src/eth/collectionProperties.test.ts
@@ -14,10 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util';
+import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper, EthUniqueHelper} from './util';
import {Pallets} from '../util';
import {IProperty, ITokenPropertyPermission, TCollectionMode} from '../util/playgrounds/types';
import {IKeyringPair} from '@polkadot/types/types';
+import {TCollectionMode} from '../util/playgrounds/types';
describe('EVM collection properties', () => {
let donor: IKeyringPair;
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -2341,73 +2341,6 @@
return siblingPrefix + encodedParaId + suffix;
}
-
- /**
- * Encode key to substrate address
- * @param key key for encoding address
- * @param ss58Format prefix for encoding to the address of the corresponding network
- * @returns encoded substrate address
- */
- encodeSubstrateAddress (key: Uint8Array | string | bigint, ss58Format = 42): string {
- const u8a :Uint8Array = typeof key === 'string'
- ? hexToU8a(key)
- : typeof key === 'bigint'
- ? hexToU8a(key.toString(16))
- : key;
-
- if (ss58Format < 0 || ss58Format > 16383 || [46, 47].includes(ss58Format)) {
- throw new Error(`ss58Format is not valid, received ${typeof ss58Format} "${ss58Format}"`);
- }
-
- const allowedDecodedLengths = [1, 2, 4, 8, 32, 33];
- if (!allowedDecodedLengths.includes(u8a.length)) {
- throw new Error(`key length is not valid, received ${u8a.length}, valid values are ${allowedDecodedLengths.join(', ')}`);
- }
-
- const u8aPrefix = ss58Format < 64
- ? new Uint8Array([ss58Format])
- : new Uint8Array([
- ((ss58Format & 0xfc) >> 2) | 0x40,
- (ss58Format >> 8) | ((ss58Format & 0x03) << 6),
- ]);
-
- const input = u8aConcat(u8aPrefix, u8a);
-
- return base58Encode(u8aConcat(
- input,
- blake2AsU8a(input).subarray(0, [32, 33].includes(u8a.length) ? 2 : 1),
- ));
- }
-
- /**
- * Restore substrate address from bigint representation
- * @param number decimal representation of substrate address
- * @returns substrate address
- */
- restoreCrossAccountFromBigInt(number: bigint): TSubstrateAccount {
- if (this.helper.api === null) {
- throw 'Not connected';
- }
- const res = this.helper.api.registry.createType('AccountId', '0x' + number.toString(16).padStart(64, '0')).toJSON();
- if (res === undefined || res === null) {
- throw 'Restore address error';
- }
- return res.toString();
- }
-
- /**
- * Convert etherium cross account id to substrate cross account id
- * @param ethCrossAccount etherium cross account
- * @returns substrate cross account id
- */
- convertCrossAccountFromEthCrossAcoount(ethCrossAccount: IEthCrossAccountId): ICrossAccountId {
- if (ethCrossAccount.field_1 === '0') {
- return {Ethereum: ethCrossAccount.field_0.toLocaleLowerCase()};
- }
-
- const ss58 = this.restoreCrossAccountFromBigInt(BigInt(ethCrossAccount.field_1));
- return {Substrate: ss58};
- }
}
class StakingGroup extends HelperGroup<UniqueHelper> {