difftreelog
Update transfer disable tests
in: master
3 files changed
tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -59,7 +59,8 @@
"testSetVariableMetadataSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setVariableMetadataSponsoringRateLimit.test.ts",
"testInflation": "mocha --timeout 9999999 -r ts-node/register ./**/inflation.test.ts",
"testPalletPresence": "mocha --timeout 9999999 -r ts-node/register ./**/pallet-presence.test.ts",
- "testBlockProduction": "mocha --timeout 9999999 -r ts-node/register ./**/block-production.test.ts"
+ "testBlockProduction": "mocha --timeout 9999999 -r ts-node/register ./**/block-production.test.ts",
+ "testEnableDisableTransfers": "mocha --timeout 9999999 -r ts-node/register ./**/enableDisableTransfer.test.ts"
},
"author": "",
"license": "SEE LICENSE IN ../LICENSE",
tests/src/enableDisableTransfer.test.tsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import privateKey from './substrate/privateKey';9import usingApi from './substrate/substrate-api';10import {11 createItemExpectSuccess,12 createCollectionExpectSuccess,13 transferExpectSuccess,14 transferExpectFailure,15 setTransferFlagExpectSuccess,16} from './util/helpers';1718chai.use(chaiAsPromised);1920describe('Enable/Disable Transfers', () => {21 it('User can transfer token with enabled transfer flag', async () => {22 await usingApi(async () => {23 const Alice = privateKey('//Alice');24 const Bob = privateKey('//Bob');25 // nft26 const nftCollectionId = await createCollectionExpectSuccess();27 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');2829 // explicitely set transfer flag30 await setTransferFlagExpectSuccess(Alice, nftCollectionId, true);3132 await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1);33 });34 });3536 it('User can\'n transfer token with disabled transfer flag', async () => {37 await usingApi(async () => {38 const Alice = privateKey('//Alice');39 const Bob = privateKey('//Bob');40 // nft41 const nftCollectionId = await createCollectionExpectSuccess();42 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');4344 // explicitely set transfer flag45 await setTransferFlagExpectSuccess(Alice, nftCollectionId, false);4647 await transferExpectFailure(nftCollectionId, newNftTokenId, Alice, Bob, 1);48 });49 });50});1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import privateKey from './substrate/privateKey';9import usingApi from './substrate/substrate-api';10import {11 createItemExpectSuccess,12 createCollectionExpectSuccess,13 transferExpectSuccess,14 transferExpectFailure,15 setTransferFlagExpectSuccess,16 setTransferFlagExpectFailure,17} from './util/helpers';1819chai.use(chaiAsPromised);2021describe('Enable/Disable Transfers', () => {22 it('User can transfer token with enabled transfer flag', async () => {23 await usingApi(async () => {24 const Alice = privateKey('//Alice');25 const Bob = privateKey('//Bob');26 // nft27 const nftCollectionId = await createCollectionExpectSuccess();28 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');2930 // explicitely set transfer flag31 await setTransferFlagExpectSuccess(Alice, nftCollectionId, true);3233 await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1);34 });35 });3637 it('User can\'n transfer token with disabled transfer flag', async () => {38 await usingApi(async () => {39 const Alice = privateKey('//Alice');40 const Bob = privateKey('//Bob');41 // nft42 const nftCollectionId = await createCollectionExpectSuccess();43 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');4445 // explicitely set transfer flag46 await setTransferFlagExpectSuccess(Alice, nftCollectionId, false);4748 await transferExpectFailure(nftCollectionId, newNftTokenId, Alice, Bob, 1);49 });50 });51});5253describe('Negative Enable/Disable Transfers', () => {54 it('Non-owner cannot change transfer flag', async () => {55 await usingApi(async () => {56 const Bob = privateKey('//Bob');57 // nft58 const nftCollectionId = await createCollectionExpectSuccess();5960 // Change transfer flag61 await setTransferFlagExpectFailure(Bob, nftCollectionId, false);62 });63 });64});tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -535,6 +535,18 @@
});
}
+export async function setTransferFlagExpectFailure(sender: IKeyringPair, collectionId: number, enabled: boolean) {
+
+ await usingApi(async (api) => {
+
+ const tx = api.tx.nft.setTransfersEnabledFlag (collectionId, enabled);
+ const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
+ const result = getGenericResult(events);
+
+ expect(result.success).to.be.false;
+ });
+}
+
export async function setContractSponsoringRateLimitExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, rateLimit: number) {
await usingApi(async (api) => {
const tx = api.tx.nft.setContractSponsoringRateLimit(contractAddress, rateLimit);