difftreelog
Refactor admin tests
in: master
combine tests remove Bob add e2e test
2 files changed
tests/src/eth/collectionAdmin.test.tsdiffbeforeafterboth39 });39 });40 });40 });4142 // Soft-deprecated43 itEth('Add admin by owner', async ({helper}) => {44 const owner = await helper.eth.createAccountWithBalance(donor);45 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');46 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);4748 const newAdmin = helper.eth.createAccount();4950 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();51 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);52 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())53 .to.be.eq(newAdmin.toLocaleLowerCase());54 });554156 itEth('Add cross account admin by owner', async ({helper, privateKey}) => {42 itEth('can add account admin by owner', async ({helper, privateKey}) => {43 // arrange57 const owner = await helper.eth.createAccountWithBalance(donor);44 const owner = await helper.eth.createAccountWithBalance(donor);58 45 const adminSub = await privateKey('//admin2');46 const adminEth = helper.eth.createAccount().toLowerCase();4748 const adminDeprecated = helper.eth.createAccount().toLowerCase();49 const adminCrossSub = helper.ethCrossAccount.fromKeyringPair(adminSub);50 const adminCrossEth = helper.ethCrossAccount.fromAddress(adminEth);51 59 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');52 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');60 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);53 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);61 5455 // Soft-deprecated: can addCollectionAdmin 62 const newAdmin = await privateKey('//Bob');56 await collectionEvm.methods.addCollectionAdmin(adminDeprecated).send();57 // Can addCollectionAdminCross for substrate and ethereum address63 const newAdminCross = helper.ethCrossAccount.fromKeyringPair(newAdmin);58 await collectionEvm.methods.addCollectionAdminCross(adminCrossSub).send();64 await collectionEvm.methods.addCollectionAdminCross(newAdminCross).send();59 await collectionEvm.methods.addCollectionAdminCross(adminCrossEth).send();656061 // 1. Expect api.rpc.unique.adminlist returns admins:66 const adminList = await helper.collection.getAdmins(collectionId);62 const adminListRpc = await helper.collection.getAdmins(collectionId);63 expect(adminListRpc).to.has.length(3);67 expect(adminList).to.be.like([{Substrate: newAdmin.address}]);64 expect(adminListRpc).to.be.deep.contain.members([{Substrate: adminSub.address}, {Ethereum: adminEth}, {Ethereum: adminDeprecated}]);6566 // 2. Expect methods.collectionAdmins == api.rpc.unique.adminlist67 let adminListEth = await collectionEvm.methods.collectionAdmins().call();68 adminListEth = adminListEth.map((element: IEthCrossAccountId) => {69 return helper.address.convertCrossAccountFromEthCrossAccount(element);70 });71 expect(adminListRpc).to.be.like(adminListEth);68 });72 });697370 itEth('Check adminlist', async ({helper, privateKey}) => {74 itEth('cross account admin can mint', async ({helper}) => {75 // arrange: create collection and accounts71 const owner = await helper.eth.createAccountWithBalance(donor);76 const owner = await helper.eth.createAccountWithBalance(donor);72 73 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');77 const {collectionAddress, collectionId} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', 'a', 'b', 'uri');74 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);78 const adminEth = (await helper.eth.createAccountWithBalance(donor)).toLowerCase();7576 const admin1 = helper.eth.createAccount();79 const adminCrossEth = helper.ethCrossAccount.fromAddress(adminEth);77 const admin2 = await privateKey('admin');78 const admin2Cross = helper.ethCrossAccount.fromKeyringPair(admin2);80 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);79 81 80 // Soft-deprecated82 // cannot mint while not admin81 await collectionEvm.methods.addCollectionAdmin(admin1).send();83 await expect(collectionEvm.methods.mint(owner).call({from: adminEth})).to.be.rejectedWith('PublicMintingNotAllowed');84 85 // admin can mint token:82 await collectionEvm.methods.addCollectionAdminCross(admin2Cross).send();86 await collectionEvm.methods.addCollectionAdminCross(adminCrossEth).send();8384 const adminListRpc = await helper.collection.getAdmins(collectionId);87 const result = await collectionEvm.methods.mint(owner).call({from: adminEth});85 let adminListEth = await collectionEvm.methods.collectionAdmins().call();8886 adminListEth = adminListEth.map((element: IEthCrossAccountId) => {89 // TODO: Why fail87 return helper.address.convertCrossAccountFromEthCrossAcoount(element);90 expect(await helper.collection.getLastTokenId(collectionId)).to.eq(1);88 });89 expect(adminListRpc).to.be.like(adminListEth);90 });91 });919292 // Soft-deprecated93 itEth('Verify owner or admin', async ({helper}) => {93 itEth('cannot add invalid cross account admin', async ({helper}) => {94 const owner = await helper.eth.createAccountWithBalance(donor);94 const owner = await helper.eth.createAccountWithBalance(donor);95 const [admin] = await helper.arrange.createAccounts([100n, 100n], donor);9695 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');97 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');9697 const newAdmin = helper.eth.createAccount();98 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);98 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);99 99100 expect(await collectionEvm.methods.isOwnerOrAdmin(newAdmin).call()).to.be.false;100 const adminCross = {101 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();101 eth: helper.address.substrateToEth(admin.address),102 sub: admin.addressRaw,103 };102 expect(await collectionEvm.methods.isOwnerOrAdmin(newAdmin).call()).to.be.true;104 await expect(collectionEvm.methods.addCollectionAdminCross(adminCross).send()).to.be.rejected;103 });105 });104106105 itEth('Verify owner or admin cross', async ({helper, privateKey}) => {107 itEth('can verify owner with methods.isOwnerOrAdmin[Cross]', async ({helper, privateKey}) => {106 const owner = await helper.eth.createAccountWithBalance(donor);108 const owner = await helper.eth.createAccountWithBalance(donor);107 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');109 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');108110111 const adminDeprecated = helper.eth.createAccount();109 const newAdmin = await privateKey('admin');112 const admin1Cross = helper.ethCrossAccount.fromKeyringPair(await privateKey('admin'));110 const newAdminCross = helper.ethCrossAccount.fromKeyringPair(newAdmin);113 const admin2Cross = helper.ethCrossAccount.fromAddress(helper.address.substrateToEth((await privateKey('admin3')).address));111 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);114 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);112 115 116 // Soft-deprecated:117 expect(await collectionEvm.methods.isOwnerOrAdmin(adminDeprecated).call()).to.be.false;113 expect(await collectionEvm.methods.isOwnerOrAdminCross(newAdminCross).call()).to.be.false;118 expect(await collectionEvm.methods.isOwnerOrAdminCross(admin1Cross).call()).to.be.false;119 expect(await collectionEvm.methods.isOwnerOrAdminCross(admin2Cross).call()).to.be.false;120121 await collectionEvm.methods.addCollectionAdmin(adminDeprecated).send();114 await collectionEvm.methods.addCollectionAdminCross(newAdminCross).send();122 await collectionEvm.methods.addCollectionAdminCross(admin1Cross).send();123 await collectionEvm.methods.addCollectionAdminCross(admin2Cross).send();124125 // Soft-deprecated: isOwnerOrAdmin returns true126 expect(await collectionEvm.methods.isOwnerOrAdmin(adminDeprecated).call()).to.be.true;127 // Expect isOwnerOrAdminCross return true115 expect(await collectionEvm.methods.isOwnerOrAdminCross(newAdminCross).call()).to.be.true;128 expect(await collectionEvm.methods.isOwnerOrAdminCross(admin1Cross).call()).to.be.true;129 expect(await collectionEvm.methods.isOwnerOrAdminCross(admin2Cross).call()).to.be.true;116 });130 });117131118 // Soft-deprecated132 // Soft-deprecated154 const owner = await helper.eth.createAccountWithBalance(donor);168 const owner = await helper.eth.createAccountWithBalance(donor);155 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');169 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');156170157 const [admin] = await helper.arrange.createAccounts([10n], donor);171 const [admin, notAdmin] = await helper.arrange.createAccounts([10n, 10n], donor);158 const adminCross = helper.ethCrossAccount.fromKeyringPair(admin);172 const adminCross = helper.ethCrossAccount.fromKeyringPair(admin);159 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);173 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);160 await collectionEvm.methods.addCollectionAdminCross(adminCross).send();174 await collectionEvm.methods.addCollectionAdminCross(adminCross).send();161175162 const [notAdmin] = await helper.arrange.createAccounts([10n], donor);163 const notAdminCross = helper.ethCrossAccount.fromKeyringPair(notAdmin);176 const notAdminCross = helper.ethCrossAccount.fromKeyringPair(notAdmin);164 await expect(collectionEvm.methods.addCollectionAdminCross(notAdminCross).call({from: adminCross.eth}))177 await expect(collectionEvm.methods.addCollectionAdminCross(notAdminCross).call({from: adminCross.eth}))165 .to.be.rejectedWith('NoPermission');178 .to.be.rejectedWith('NoPermission');tests/src/util/playgrounds/unique.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -2429,7 +2429,7 @@
* @param ethCrossAccount etherium cross account
* @returns substrate cross account id
*/
- convertCrossAccountFromEthCrossAcoount(ethCrossAccount: IEthCrossAccountId): ICrossAccountId {
+ convertCrossAccountFromEthCrossAccount(ethCrossAccount: IEthCrossAccountId): ICrossAccountId {
if (ethCrossAccount.sub === '0') {
return {Ethereum: ethCrossAccount.eth.toLocaleLowerCase()};
}