From 2e2d3bf502831f4af1bab337cdc0a1b11ebf1d94 Mon Sep 17 00:00:00 2001 From: Greg Zaitsev Date: Tue, 09 Feb 2021 16:15:14 +0000 Subject: [PATCH] Merge branch 'develop' into feature/transferfromtests --- --- a/pallets/nft/src/lib.rs +++ b/pallets/nft/src/lib.rs @@ -185,6 +185,8 @@ // Timeouts for item types in passed blocks pub sponsor_transfer_timeout: u32, + pub owner_can_transfer: bool, + pub owner_can_destroy: bool, } impl Default for CollectionLimits { @@ -193,7 +195,10 @@ account_token_ownership_limit: 10_000_000, token_limit: u32::max_value(), sponsored_data_size: u32::max_value(), - sponsor_transfer_timeout: 14400 } + sponsor_transfer_timeout: 14400, + owner_can_transfer: true, + owner_can_destroy: true + } } } @@ -592,7 +597,7 @@ sponsor_confirmed: false, variable_on_chain_schema: Vec::new(), const_on_chain_schema: Vec::new(), - limits: CollectionLimits::default(), + limits: CollectionLimits::default() }; // Add new collection to map --- a/runtime_types.json +++ b/runtime_types.json @@ -95,6 +95,8 @@ "AccountTokenOwnershipLimit": "u32", "SponsoredMintSize": "u32", "TokenLimit": "u32", - "SponsorTimeout": "u32" + "SponsorTimeout": "u32", + "OwnerCanTransfer": "bool", + "OwnerCanDestroy": "bool" } } \ No newline at end of file --- /dev/null +++ b/tests/src/removeFromContractWhiteList.test.ts @@ -0,0 +1,72 @@ +import privateKey from "./substrate/privateKey"; +import usingApi from "./substrate/substrate-api"; +import { deployFlipper, toggleFlipValueExpectFailure, toggleFlipValueExpectSuccess } from "./util/contracthelpers"; +import { addToContractWhiteListExpectSuccess, isWhitelistedInContract, removeFromContractWhiteListExpectFailure, removeFromContractWhiteListExpectSuccess, toggleContractWhitelistExpectSuccess } from "./util/helpers"; +import { IKeyringPair } from '@polkadot/types/types'; +import { expect } from "chai"; + +describe('Integration Test removeFromContractWhiteList', () => { + let bob: IKeyringPair; + + before(() => { + bob = privateKey('//Bob'); + }); + + it('user is no longer whitelisted after removal', async () => { + await usingApi(async (api) => { + const [flipper, deployer] = await deployFlipper(api); + + await addToContractWhiteListExpectSuccess(deployer, flipper.address, bob.address); + await removeFromContractWhiteListExpectSuccess(deployer, flipper.address, bob.address); + + expect(await isWhitelistedInContract(flipper.address, bob.address)).to.be.false; + }); + }); + + it('user can\'t execute contract after removal', async () => { + await usingApi(async (api) => { + const [flipper, deployer] = await deployFlipper(api); + await toggleContractWhitelistExpectSuccess(deployer, flipper.address, true); + + await addToContractWhiteListExpectSuccess(deployer, flipper.address, bob.address); + await toggleFlipValueExpectSuccess(bob, flipper); + + await removeFromContractWhiteListExpectSuccess(deployer, flipper.address, bob.address); + await toggleFlipValueExpectFailure(bob, flipper); + }); + }); + + it('can be called twice', async () => { + await usingApi(async (api) => { + const [flipper, deployer] = await deployFlipper(api); + + await addToContractWhiteListExpectSuccess(deployer, flipper.address, bob.address); + await removeFromContractWhiteListExpectSuccess(deployer, flipper.address, bob.address); + await removeFromContractWhiteListExpectSuccess(deployer, flipper.address, bob.address); + }); + }); +}); + +describe('Negative Integration Test removeFromContractWhiteList', () => { + let alice: IKeyringPair; + let bob: IKeyringPair; + + before(() => { + alice = privateKey('//Alice'); + bob = privateKey('//Bob'); + }); + + it('fails when called with non-contract address', async () => { + await usingApi(async () => { + await removeFromContractWhiteListExpectFailure(alice, alice.address, bob.address); + }); + }); + + it('fails when executed by non owner', async () => { + await usingApi(async (api) => { + const [flipper, _] = await deployFlipper(api); + + await removeFromContractWhiteListExpectFailure(alice, flipper.address, bob.address); + }); + }); +}); --- a/tests/src/util/helpers.ts +++ b/tests/src/util/helpers.ts @@ -410,6 +410,54 @@ }); } +export async function toggleContractWhitelistExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, enabled: boolean) { + await usingApi(async (api) => { + const tx = api.tx.nft.toggleContractWhiteList(contractAddress, true); + const events = await submitTransactionAsync(sender, tx); + const result = getGenericResult(events); + + expect(result.success).to.be.true; + }); +} + +export async function isWhitelistedInContract(contractAddress: AccountId | string, user: string) { + let whitelisted: boolean = false; + await usingApi(async (api) => { + whitelisted = (await api.query.nft.contractWhiteList(contractAddress, user)).toJSON() as boolean; + }); + return whitelisted; +} + +export async function addToContractWhiteListExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, user: string) { + await usingApi(async (api) => { + const tx = api.tx.nft.addToContractWhiteList(contractAddress, user); + const events = await submitTransactionAsync(sender, tx); + const result = getGenericResult(events); + + expect(result.success).to.be.true; + }); +} + +export async function removeFromContractWhiteListExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, user: string) { + await usingApi(async (api) => { + const tx = api.tx.nft.removeFromContractWhiteList(contractAddress, user); + const events = await submitTransactionAsync(sender, tx); + const result = getGenericResult(events); + + expect(result.success).to.be.true; + }); +} + +export async function removeFromContractWhiteListExpectFailure(sender: IKeyringPair, contractAddress: AccountId | string, user: string) { + await usingApi(async (api) => { + const tx = api.tx.nft.removeFromContractWhiteList(contractAddress, user); + const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected; + const result = getGenericResult(events); + + expect(result.success).to.be.false; + }); +} + export async function setVariableMetaDataExpectSuccess(sender: IKeyringPair, collectionId: number, itemId: number, data: number[]) { await usingApi(async (api) => { const tx = api.tx.nft.setVariableMetaData(collectionId, itemId, '0x' + Buffer.from(data).toString('hex')); -- gitstuff