difftreelog
Merge branch 'develop' into feature/transferfromtests
in: master
4 files changed
pallets/nft/src/lib.rsdiffbeforeafterboth--- 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
runtime_types.jsondiffbeforeafterboth--- 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
tests/src/removeFromContractWhiteList.test.tsdiffbeforeafterboth--- /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);
+ });
+ });
+});
tests/src/util/helpers.tsdiffbeforeafterboth410 });410 });411}411}412413export async function toggleContractWhitelistExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, enabled: boolean) {414 await usingApi(async (api) => {415 const tx = api.tx.nft.toggleContractWhiteList(contractAddress, true);416 const events = await submitTransactionAsync(sender, tx);417 const result = getGenericResult(events);418419 expect(result.success).to.be.true;420 });421}422423export async function isWhitelistedInContract(contractAddress: AccountId | string, user: string) {424 let whitelisted: boolean = false;425 await usingApi(async (api) => {426 whitelisted = (await api.query.nft.contractWhiteList(contractAddress, user)).toJSON() as boolean;427 });428 return whitelisted;429}430431export async function addToContractWhiteListExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, user: string) {432 await usingApi(async (api) => {433 const tx = api.tx.nft.addToContractWhiteList(contractAddress, user);434 const events = await submitTransactionAsync(sender, tx);435 const result = getGenericResult(events);436437 expect(result.success).to.be.true;438 });439}440441export async function removeFromContractWhiteListExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, user: string) {442 await usingApi(async (api) => {443 const tx = api.tx.nft.removeFromContractWhiteList(contractAddress, user);444 const events = await submitTransactionAsync(sender, tx);445 const result = getGenericResult(events);446447 expect(result.success).to.be.true;448 });449}450451export async function removeFromContractWhiteListExpectFailure(sender: IKeyringPair, contractAddress: AccountId | string, user: string) {452 await usingApi(async (api) => {453 const tx = api.tx.nft.removeFromContractWhiteList(contractAddress, user);454 const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;455 const result = getGenericResult(events);456457 expect(result.success).to.be.false;458 });459}412460413export async function setVariableMetaDataExpectSuccess(sender: IKeyringPair, collectionId: number, itemId: number, data: number[]) {461export async function setVariableMetaDataExpectSuccess(sender: IKeyringPair, collectionId: number, itemId: number, data: number[]) {414 await usingApi(async (api) => {462 await usingApi(async (api) => {