git.delta.rocks / unique-network / refs/commits / 41d3859e3263

difftreelog

CORE-36. Integration tests

str-mv2021-07-16parent: #a042d1f.patch.diff
in: master

2 files changed

addedtests/src/enableDisableTransfer.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/enableDisableTransfer.test.ts
@@ -0,0 +1,50 @@
+//
+// 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,
+  transferExpectSuccess,
+  transferExpectFailure,
+  setTransferFlagExpectSuccess
+} from './util/helpers';
+
+chai.use(chaiAsPromised);
+
+describe('Enable/Disable Transfers', () => {
+  it.only('User can transfer token with enabled transfer flag', async () => {
+    await usingApi(async () => {
+      const Alice = privateKey('//Alice');
+      const Bob = privateKey('//Bob');
+      // nft
+      const nftCollectionId = await createCollectionExpectSuccess();
+      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
+
+      // explicitely set transfer flag
+      await setTransferFlagExpectSuccess(Alice, nftCollectionId, true);
+
+      await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1);
+    });
+  });
+
+  it.only('User can\'n transfer token with disabled transfer flag', async () => {
+    await usingApi(async () => {
+      const Alice = privateKey('//Alice');
+      const Bob = privateKey('//Bob');
+      // nft
+      const nftCollectionId = await createCollectionExpectSuccess();
+      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
+
+      // explicitely set transfer flag
+      await setTransferFlagExpectSuccess(Alice, nftCollectionId, false);
+
+      await transferExpectFailure(nftCollectionId, newNftTokenId, Alice, Bob, 1);
+    });
+  });
+});
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
523 });523 });
524}524}
525
526export async function setTransferFlagExpectSuccess(sender: IKeyringPair, collectionId: number, enabled: boolean) {
527
528 await usingApi(async (api) => {
529
530 const tx = api.tx.nft.setTransfersEnabledFlag (collectionId, enabled);
531 const events = await submitTransactionAsync(sender, tx);
532 const result = getGenericResult(events);
533
534 expect(result.success).to.be.true;
535 });
536}
525537
526export async function setContractSponsoringRateLimitExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, rateLimit: number) {538export async function setContractSponsoringRateLimitExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, rateLimit: number) {
527 await usingApi(async (api) => {539 await usingApi(async (api) => {