difftreelog
add extension class to playgrounds
in: master
+ add creteAccounts method + move addCollectionAdmin tests to playgrounds
4 files changed
tests/src/addCollectionAdmin.test.tsdiffbeforeafterboth14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617import {ApiPromise} from '@polkadot/api';17import {IKeyringPair} from '@polkadot/types/types';18import chai from 'chai';18import chai from 'chai';19import chaiAsPromised from 'chai-as-promised';19import chaiAsPromised from 'chai-as-promised';20import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';21import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId, queryCollectionExpectSuccess} from './util/helpers';20import {usingPlaygrounds} from './util/playgrounds';222123chai.use(chaiAsPromised);22chai.use(chaiAsPromised);24const expect = chai.expect;23const expect = chai.expect;2425let donor: IKeyringPair;2627before(async () => {28 await usingPlaygrounds(async (_, privateKeyWrapper) => {29 donor = privateKeyWrapper('//Alice');30 });31});253226describe('Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {33describe('Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {27 it('Add collection admin.', async () => {34 it('Add collection admin.', async () => {28 await usingApi(async (api, privateKeyWrapper) => {35 await usingPlaygrounds(async (helper) => {29 const collectionId = await createCollectionExpectSuccess();36 const [alice, bob] = await helper.arrange.creteAccounts([10n, 10n], donor);30 const alice = privateKeyWrapper('//Alice');37 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});31 const bob = privateKeyWrapper('//Bob');323833 const collection = await queryCollectionExpectSuccess(api, collectionId);39 const collection = await helper.collection.getData(collectionId);34 expect(collection.owner.toString()).to.be.equal(alice.address);40 expect(collection?.normalizedOwner!).to.be.equal(alice.address);354136 const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));42 await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});37 await submitTransactionAsync(alice, changeAdminTx);384339 const adminListAfterAddAdmin = await getAdminList(api, collectionId);44 const adminListAfterAddAdmin = await helper.collection.getAdmins(collectionId);40 expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));45 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});41 });46 });42 });47 });43});48});444945describe('Negative Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {50describe('Negative Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {46 it("Not owner can't add collection admin.", async () => {51 it("Not owner can't add collection admin.", async () => {47 await usingApi(async (api, privateKeyWrapper) => {52 await usingPlaygrounds(async (helper) => {48 const collectionId = await createCollectionExpectSuccess();53 const [alice, bob, charlie] = await helper.arrange.creteAccounts([10n, 10n, 10n], donor);49 const alice = privateKeyWrapper('//Alice');50 const bob = privateKeyWrapper('//Bob');51 const charlie = privateKeyWrapper('//CHARLIE');54 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});525553 const collection = await queryCollectionExpectSuccess(api, collectionId);56 const collection = await helper.collection.getData(collectionId);54 expect(collection.owner.toString()).to.be.equal(alice.address);57 expect(collection?.normalizedOwner).to.be.equal(alice.address);555856 const adminListAfterAddAdmin = await getAdminList(api, collectionId);59 const changeAdminTxBob = async () => helper.collection.addAdmin(bob, collectionId, {Substrate: bob.address});57 expect(adminListAfterAddAdmin).to.be.not.deep.contains(normalizeAccountId(bob.address));5859 const changeAdminTxCharlie = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(charlie.address));60 const changeAdminTxCharlie = async () => helper.collection.addAdmin(bob, collectionId, {Substrate: charlie.address});60 await expect(submitTransactionAsync(bob, changeAdminTxCharlie)).to.be.rejected;61 await expect(changeAdminTxCharlie()).to.be.rejected;61 62 await expect(changeAdminTxBob()).to.be.rejected;6362 const adminListAfterAddNewAdmin = await getAdminList(api, collectionId);64 const adminListAfterAddAdmin = await helper.collection.getAdmins(collectionId);63 expect(adminListAfterAddNewAdmin).to.be.not.deep.contains(normalizeAccountId(bob.address));65 expect(adminListAfterAddAdmin).to.be.not.deep.contains({Substrate: charlie.address});64 expect(adminListAfterAddNewAdmin).to.be.not.deep.contains(normalizeAccountId(charlie.address));66 expect(adminListAfterAddAdmin).to.be.not.deep.contains({Substrate: bob.address});65 });67 });66 });68 });676968 it("Admin can't add collection admin.", async () => {70 it("Admin can't add collection admin.", async () => {69 await usingApi(async (api, privateKeyWrapper) => {71 await usingPlaygrounds(async (helper) => {70 const collectionId = await createCollectionExpectSuccess();72 const [alice, bob, charlie] = await helper.arrange.creteAccounts([10n, 10n, 10n], donor);71 const alice = privateKeyWrapper('//Alice');72 const bob = privateKeyWrapper('//Bob');73 const charlie = privateKeyWrapper('//CHARLIE');7475 const collection = await queryCollectionExpectSuccess(api, collectionId);73 const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});76 expect(collection.owner.toString()).to.be.equal(alice.address);777478 const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));75 await collection.addAdmin(alice, {Substrate: bob.address});79 await submitTransactionAsync(alice, changeAdminTx);807681 const adminListAfterAddAdmin = await getAdminList(api, collectionId);77 const adminListAfterAddAdmin = await collection.getAdmins();82 expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));78 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});837984 const changeAdminTxCharlie = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(charlie.address));80 const changeAdminTxCharlie = async () => collection.addAdmin(bob, {Substrate: charlie.address});85 await expect(submitTransactionAsync(bob, changeAdminTxCharlie)).to.be.rejected;81 await expect(changeAdminTxCharlie()).to.be.rejected;86 8287 const adminListAfterAddNewAdmin = await getAdminList(api, collectionId);83 const adminListAfterAddNewAdmin = await collection.getAdmins();88 expect(adminListAfterAddNewAdmin).to.be.deep.contains(normalizeAccountId(bob.address));84 expect(adminListAfterAddNewAdmin).to.be.deep.contains({Substrate: bob.address});89 expect(adminListAfterAddNewAdmin).to.be.not.deep.contains(normalizeAccountId(charlie.address));85 expect(adminListAfterAddNewAdmin).to.be.not.deep.contains({Substrate: charlie.address});90 });86 });91 });87 });928893 it("Can't add collection admin of not existing collection.", async () => {89 it("Can't add collection admin of not existing collection.", async () => {94 await usingApi(async (api, privateKeyWrapper) => {90 await usingPlaygrounds(async (helper) => {91 const [alice, bob] = await helper.arrange.creteAccounts([10n, 10n, 10n], donor);95 // tslint:disable-next-line: no-bitwise92 // tslint:disable-next-line: no-bitwise96 const collectionId = (1 << 32) - 1;93 const collectionId = (1 << 32) - 1;97 const alice = privateKeyWrapper('//Alice');98 const bob = privateKeyWrapper('//Bob');9994100 const changeOwnerTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));95 const addAdminTx = async () => helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});101 await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;96 await expect(addAdminTx()).to.be.rejected;10297103 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)98 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)104 await createCollectionExpectSuccess();99 await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});105 });100 });106 });101 });107102108 it("Can't add an admin to a destroyed collection.", async () => {103 it("Can't add an admin to a destroyed collection.", async () => {109 await usingApi(async (api, privateKeyWrapper) => {104 await usingPlaygrounds(async (helper) => {110 const collectionId = await createCollectionExpectSuccess();105 const [alice, bob] = await helper.arrange.creteAccounts([10n, 10n, 10n], donor);111 const alice = privateKeyWrapper('//Alice');106 const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});112 const bob = privateKeyWrapper('//Bob');107113 await destroyCollectionExpectSuccess(collectionId);108 await collection.burn(alice);114 const changeOwnerTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));109 const addAdminTx = async () => collection.addAdmin(alice, {Substrate: bob.address});115 await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;110 await expect(addAdminTx()).to.be.rejected;116111117 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)112 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)118 await createCollectionExpectSuccess();113 await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});119 });114 });120 });115 });121116122 it('Add an admin to a collection that has reached the maximum number of admins limit', async () => {117 it('Add an admin to a collection that has reached the maximum number of admins limit', async () => {123 await usingApi(async (api: ApiPromise, privateKeyWrapper) => {118 await usingPlaygrounds(async (helper) => {124 const alice = privateKeyWrapper('//Alice');125 const accounts = [119 const [alice, ...accounts] = await helper.arrange.creteAccounts([10n, 0n, 0n, 0n, 0n, 0n, 0n, 0n], donor);126 privateKeyWrapper('//AdminTest/1').address,127 privateKeyWrapper('//AdminTest/2').address,128 privateKeyWrapper('//AdminTest/3').address,129 privateKeyWrapper('//AdminTest/4').address,130 privateKeyWrapper('//AdminTest/5').address,131 privateKeyWrapper('//AdminTest/6').address,132 privateKeyWrapper('//AdminTest/7').address,133 ];134 const collectionId = await createCollectionExpectSuccess();120 const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});135121136 const chainAdminLimit = (api.consts.common.collectionAdminsLimit as any).toNumber();122 const chainAdminLimit = (helper.api!.consts.common.collectionAdminsLimit as any).toNumber();137 expect(chainAdminLimit).to.be.equal(5);123 expect(chainAdminLimit).to.be.equal(5);138124139 for (let i = 0; i < chainAdminLimit; i++) {125 for (let i = 0; i < chainAdminLimit; i++) {140 await addCollectionAdminExpectSuccess(alice, collectionId, accounts[i]);126 await collection.addAdmin(alice, {Substrate: accounts[i].address});141 const adminListAfterAddAdmin = await getAdminList(api, collectionId);127 const adminListAfterAddAdmin = await collection.getAdmins();142 expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(accounts[i]));128 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: accounts[i].address});143 }129 }144130145 const tx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(accounts[chainAdminLimit]));131 const addExtraAdminTx = async () => collection.addAdmin(alice, {Substrate: accounts[chainAdminLimit].address});146 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;132 await expect(addExtraAdminTx()).to.be.rejected;147 });133 });148 });134 });149});135});tests/src/util/playgrounds/index.tsdiffbeforeafterboth2// SPDX-License-Identifier: Apache-2.02// SPDX-License-Identifier: Apache-2.0334import {IKeyringPair} from '@polkadot/types/types';4import {IKeyringPair} from '@polkadot/types/types';5import {UniqueHelper} from './unique';6import config from '../../config';5import config from '../../config';7import '../../interfaces/augment-api-events';6import '../../interfaces/augment-api-events';8import * as defs from '../../interfaces/definitions';9import {ApiPromise, WsProvider} from '@polkadot/api';7import {DevUniqueHelper} from './unique.dev';1011812class SilentLogger {9class SilentLogger {19}16}202122class DevUniqueHelper extends UniqueHelper {23 async connect(wsEndpoint: string, listeners?: any): Promise<void> {24 const wsProvider = new WsProvider(wsEndpoint);25 this.api = new ApiPromise({26 provider: wsProvider, 27 signedExtensions: {28 ContractHelpers: {29 extrinsic: {},30 payload: {},31 },32 FakeTransactionFinalizer: {33 extrinsic: {},34 payload: {},35 },36 },37 rpc: {38 unique: defs.unique.rpc,39 rmrk: defs.rmrk.rpc,40 eth: {41 feeHistory: {42 description: 'Dummy',43 params: [],44 type: 'u8',45 },46 maxPriorityFeePerGas: {47 description: 'Dummy',48 params: [],49 type: 'u8',50 },51 },52 },53 });54 await this.api.isReadyOrError;55 this.network = await UniqueHelper.detectNetwork(this.api);56 }57}581759export const usingPlaygrounds = async (code: (helper: UniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {18export const usingPlaygrounds = async (code: (helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {60 // TODO: Remove, this is temporary: Filter unneeded API output19 // TODO: Remove, this is temporary: Filter unneeded API output61 // (Jaco promised it will be removed in the next version)20 // (Jaco promised it will be removed in the next version)62 const consoleErr = console.error;21 const consoleErr = console.error;tests/src/util/playgrounds/unique.dev.tsdiffbeforeafterbothno changes
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth439 return this.transactionStatus.FAIL;439 return this.transactionStatus.FAIL;440 }440 }441441442 signTransaction(sender: TSigner, transaction: any, label = 'transaction', options = null) {442 signTransaction(sender: TSigner, transaction: any, label = 'transaction', options: any = null) {443 const sign = (callback: any) => {443 const sign = (callback: any) => {444 if(options !== null) return transaction.signAndSend(sender, options, callback);444 if(options !== null) return transaction.signAndSend(sender, options, callback);445 return transaction.signAndSend(sender, callback);445 return transaction.signAndSend(sender, callback);