--- /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); + }); + }); +}); --- a/tests/src/util/helpers.ts +++ b/tests/src/util/helpers.ts @@ -523,6 +523,18 @@ }); } +export async function setTransferFlagExpectSuccess(sender: IKeyringPair, collectionId: number, enabled: boolean) { + + await usingApi(async (api) => { + + const tx = api.tx.nft.setTransfersEnabledFlag (collectionId, enabled); + const events = await submitTransactionAsync(sender, tx); + const result = getGenericResult(events); + + expect(result.success).to.be.true; + }); +} + export async function setContractSponsoringRateLimitExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, rateLimit: number) { await usingApi(async (api) => { const tx = api.tx.nft.setContractSponsoringRateLimit(contractAddress, rateLimit);