difftreelog
CORE-37. Integration tests
in: master
2 files changed
tests/src/metadataUpdate.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/metadataUpdate.test.ts
@@ -0,0 +1,112 @@
+
+//
+// This file is subject to the terms and conditions defined in
+// file 'LICENSE', which is part of this source code package.
+//
+
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+import privateKey from './substrate/privateKey';
+import usingApi from './substrate/substrate-api';
+import {
+ createItemExpectSuccess,
+ createCollectionExpectSuccess,
+ setMetadataUpdatePermissionFlagExpectSuccess,
+ setVariableMetaDataExpectSuccess,
+ setMintPermissionExpectSuccess,
+ addToWhiteListExpectSuccess,
+ addCollectionAdminExpectSuccess,
+ setVariableMetaDataExpectFailure,
+ setMetadataUpdatePermissionFlagExpectFailure
+} from './util/helpers';
+
+chai.use(chaiAsPromised);
+
+describe('Metadata update permissions ', () => {
+ it('Set variable metadata with ItemOwner permission flag', async () => {
+ await usingApi(async () => {
+ const Alice = privateKey('//Alice');
+ const Bob = privateKey('//Bob');
+
+ const data = [1, 2, 254, 255];
+
+ // nft
+ const nftCollectionId = await createCollectionExpectSuccess();
+ const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
+ await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, "ItemOwner");
+
+ await setVariableMetaDataExpectSuccess(Alice, nftCollectionId, newNftTokenId, data);
+ });
+ });
+
+ it('User can\'n set variable metadata with ItemOwner permission flag', async () => {
+ await usingApi(async () => {
+ const Alice = privateKey('//Alice');
+ const Bob = privateKey('//Bob');
+
+ const data = [1, 2, 254, 255];
+
+ // nft
+ const nftCollectionId = await createCollectionExpectSuccess();
+ const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
+ await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, "ItemOwner");
+
+ await setMintPermissionExpectSuccess(Alice, nftCollectionId, true);
+ await addToWhiteListExpectSuccess(Alice, nftCollectionId, Bob.address);
+ await addCollectionAdminExpectSuccess(Alice, nftCollectionId, Bob);
+
+ await setVariableMetaDataExpectFailure(Bob, nftCollectionId, newNftTokenId, data);
+ });
+ });
+
+ it('Admin can set variable metadata with Admin permission flag', async () => {
+ await usingApi(async () => {
+ const Alice = privateKey('//Alice');
+ const Bob = privateKey('//Bob');
+
+ const data = [1, 2, 254, 255];
+
+ // nft
+ const nftCollectionId = await createCollectionExpectSuccess();
+ const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
+ await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, "Admin");
+
+ await setMintPermissionExpectSuccess(Alice, nftCollectionId, true);
+ await addToWhiteListExpectSuccess(Alice, nftCollectionId, Bob.address);
+ await addCollectionAdminExpectSuccess(Alice, nftCollectionId, Bob);
+
+ await setVariableMetaDataExpectSuccess(Bob, nftCollectionId, newNftTokenId, data);
+ });
+ });
+
+ it('Nobody can set variable metadata with None flag', async () => {
+ await usingApi(async () => {
+ const Alice = privateKey('//Alice');
+ const Bob = privateKey('//Bob');
+
+ const data = [1, 2, 254, 255];
+
+ // nft
+ const nftCollectionId = await createCollectionExpectSuccess();
+ const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
+ await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, "None");
+
+ await setVariableMetaDataExpectFailure(Alice, nftCollectionId, newNftTokenId, data);
+ });
+ });
+
+ it('Nobody can set variable metadata flag after freeze', async () => {
+ await usingApi(async () => {
+ const Alice = privateKey('//Alice');
+ const Bob = privateKey('//Bob');
+
+ const data = [1, 2, 254, 255];
+
+ // nft
+ const nftCollectionId = await createCollectionExpectSuccess();
+ await setMetadataUpdatePermissionFlagExpectSuccess(Alice, nftCollectionId, "None");
+ await setMetadataUpdatePermissionFlagExpectFailure(Alice, nftCollectionId, "Admin");
+
+ });
+ });
+});
tests/src/util/helpers.tsdiffbeforeafterboth503 });503 });504}504}505506export async function setMetadataUpdatePermissionFlagExpectSuccess(sender: IKeyringPair, collectionId: number, flag: string) {507508 await usingApi(async (api) => {509 const tx = api.tx.nft.setMetaUpdatePermissionFlag(collectionId, flag); 510 const events = await submitTransactionAsync(sender, tx);511 const result = getGenericResult(events);512513 expect(result.success).to.be.true;514 }); 515}516517export async function setMetadataUpdatePermissionFlagExpectFailure(sender: IKeyringPair, collectionId: number, flag: string) {518519 await usingApi(async (api) => {520 const tx = api.tx.nft.setMetaUpdatePermissionFlag(collectionId, flag); 521 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;522 const result = getGenericResult(events);523524 expect(result.success).to.be.false;525 }); 526}505527506export async function enableContractSponsoringExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, enable: boolean) {528export async function enableContractSponsoringExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, enable: boolean) {507 await usingApi(async (api) => {529 await usingApi(async (api) => {986 await setMintPermissionExpectSuccess(sender, collectionId, true);1008 await setMintPermissionExpectSuccess(sender, collectionId, true);987}1009}10101011export async function addCollectionAdminExpectSuccess(sender: IKeyringPair, collectionId: number, address: IKeyringPair) {1012 await usingApi(async (api) => {1013 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(address.address));1014 const events = await submitTransactionAsync(sender, changeAdminTx);1015 const result = getCreateCollectionResult(events);1016 expect(result.success).to.be.true;1017 });1018}9881019989export async function setMintPermissionExpectFailure(sender: IKeyringPair, collectionId: number, enabled: boolean) {1020export async function setMintPermissionExpectFailure(sender: IKeyringPair, collectionId: number, enabled: boolean) {990 await usingApi(async (api) => {1021 await usingApi(async (api) => {