difftreelog
CORE-37. Integration tests
in: master
2 files changed
tests/src/metadataUpdate.test.tsdiffbeforeafterboth12//3// This file is subject to the terms and conditions defined in4// file 'LICENSE', which is part of this source code package.5//67import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import privateKey from './substrate/privateKey';10import usingApi from './substrate/substrate-api';11import {12 createItemExpectSuccess,13 createCollectionExpectSuccess,14 setMetadataUpdatePermissionFlagExpectSuccess,15 setVariableMetaDataExpectSuccess,16 setMintPermissionExpectSuccess,17 addToWhiteListExpectSuccess,18 addCollectionAdminExpectSuccess,19 setVariableMetaDataExpectFailure,20 setMetadataUpdatePermissionFlagExpectFailure21} from './util/helpers';2223chai.use(chaiAsPromised);2425describe('Metadata update permissions ', () => {26 it('Set variable metadata with ItemOwner permission flag', async () => {27 await usingApi(async () => {28 const Alice = privateKey('//Alice');29 const Bob = privateKey('//Bob');3031 const data = [1, 2, 254, 255];3233 // nft34 const nftCollectionId = await createCollectionExpectSuccess();35 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');36 await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, "ItemOwner");3738 await setVariableMetaDataExpectSuccess(Alice, nftCollectionId, newNftTokenId, data);39 });40 });4142 it('User can\'n set variable metadata with ItemOwner permission flag', async () => {43 await usingApi(async () => {44 const Alice = privateKey('//Alice');45 const Bob = privateKey('//Bob');46 47 const data = [1, 2, 254, 255];48 49 // nft50 const nftCollectionId = await createCollectionExpectSuccess();51 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');52 await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, "ItemOwner");5354 await setMintPermissionExpectSuccess(Alice, nftCollectionId, true);55 await addToWhiteListExpectSuccess(Alice, nftCollectionId, Bob.address);56 await addCollectionAdminExpectSuccess(Alice, nftCollectionId, Bob);57 58 await setVariableMetaDataExpectFailure(Bob, nftCollectionId, newNftTokenId, data);59 });60 });6162 it('Admin can set variable metadata with Admin permission flag', async () => {63 await usingApi(async () => {64 const Alice = privateKey('//Alice');65 const Bob = privateKey('//Bob');66 67 const data = [1, 2, 254, 255];68 69 // nft70 const nftCollectionId = await createCollectionExpectSuccess();71 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');72 await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, "Admin");7374 await setMintPermissionExpectSuccess(Alice, nftCollectionId, true);75 await addToWhiteListExpectSuccess(Alice, nftCollectionId, Bob.address);76 await addCollectionAdminExpectSuccess(Alice, nftCollectionId, Bob);77 78 await setVariableMetaDataExpectSuccess(Bob, nftCollectionId, newNftTokenId, data);79 });80 });8182 it('Nobody can set variable metadata with None flag', async () => {83 await usingApi(async () => {84 const Alice = privateKey('//Alice');85 const Bob = privateKey('//Bob');86 87 const data = [1, 2, 254, 255];88 89 // nft90 const nftCollectionId = await createCollectionExpectSuccess();91 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');92 await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, "None");93 94 await setVariableMetaDataExpectFailure(Alice, nftCollectionId, newNftTokenId, data);95 });96 });9798 it('Nobody can set variable metadata flag after freeze', async () => {99 await usingApi(async () => {100 const Alice = privateKey('//Alice');101 const Bob = privateKey('//Bob');102 103 const data = [1, 2, 254, 255];104 105 // nft106 const nftCollectionId = await createCollectionExpectSuccess();107 await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, "None");108 await setMetadataUpdatePermissionFlagExpectFailure(Alice, nftCollectionId, "Admin");109 110 });111 });112});tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -503,6 +503,28 @@
});
}
+export async function setMetadataUpdatePermissionFlagExpectSuccess(sender: IKeyringPair, collectionId: number, flag: string) {
+
+ await usingApi(async (api) => {
+ const tx = api.tx.nft.setMetaUpdatePermissionFlag(collectionId, flag);
+ const events = await submitTransactionAsync(sender, tx);
+ const result = getGenericResult(events);
+
+ expect(result.success).to.be.true;
+ });
+}
+
+export async function setMetadataUpdatePermissionFlagExpectFailure(sender: IKeyringPair, collectionId: number, flag: string) {
+
+ await usingApi(async (api) => {
+ const tx = api.tx.nft.setMetaUpdatePermissionFlag(collectionId, flag);
+ const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
+ const result = getGenericResult(events);
+
+ expect(result.success).to.be.false;
+ });
+}
+
export async function enableContractSponsoringExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, enable: boolean) {
await usingApi(async (api) => {
const tx = api.tx.nft.enableContractSponsoring(contractAddress, enable);
@@ -986,6 +1008,15 @@
await setMintPermissionExpectSuccess(sender, collectionId, true);
}
+export async function addCollectionAdminExpectSuccess(sender: IKeyringPair, collectionId: number, address: IKeyringPair) {
+ await usingApi(async (api) => {
+ const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(address.address));
+ const events = await submitTransactionAsync(sender, changeAdminTx);
+ const result = getCreateCollectionResult(events);
+ expect(result.success).to.be.true;
+ });
+}
+
export async function setMintPermissionExpectFailure(sender: IKeyringPair, collectionId: number, enabled: boolean) {
await usingApi(async (api) => {
// Run the transaction