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.tsdiffbeforeafterboth1import privateKey from "./substrate/privateKey";2import usingApi from "./substrate/substrate-api";3import { deployFlipper, toggleFlipValueExpectFailure, toggleFlipValueExpectSuccess } from "./util/contracthelpers";4import { addToContractWhiteListExpectSuccess, isWhitelistedInContract, removeFromContractWhiteListExpectFailure, removeFromContractWhiteListExpectSuccess, toggleContractWhitelistExpectSuccess } from "./util/helpers";5import { IKeyringPair } from '@polkadot/types/types';6import { expect } from "chai";78describe('Integration Test removeFromContractWhiteList', () => {9 let bob: IKeyringPair;1011 before(() => {12 bob = privateKey('//Bob');13 });1415 it('user is no longer whitelisted after removal', async () => {16 await usingApi(async (api) => {17 const [flipper, deployer] = await deployFlipper(api);1819 await addToContractWhiteListExpectSuccess(deployer, flipper.address, bob.address);20 await removeFromContractWhiteListExpectSuccess(deployer, flipper.address, bob.address);2122 expect(await isWhitelistedInContract(flipper.address, bob.address)).to.be.false;23 });24 });2526 it('user can\'t execute contract after removal', async () => {27 await usingApi(async (api) => {28 const [flipper, deployer] = await deployFlipper(api);29 await toggleContractWhitelistExpectSuccess(deployer, flipper.address, true);3031 await addToContractWhiteListExpectSuccess(deployer, flipper.address, bob.address);32 await toggleFlipValueExpectSuccess(bob, flipper);3334 await removeFromContractWhiteListExpectSuccess(deployer, flipper.address, bob.address);35 await toggleFlipValueExpectFailure(bob, flipper);36 });37 });3839 it('can be called twice', async () => {40 await usingApi(async (api) => {41 const [flipper, deployer] = await deployFlipper(api);4243 await addToContractWhiteListExpectSuccess(deployer, flipper.address, bob.address);44 await removeFromContractWhiteListExpectSuccess(deployer, flipper.address, bob.address);45 await removeFromContractWhiteListExpectSuccess(deployer, flipper.address, bob.address);46 });47 });48});4950describe('Negative Integration Test removeFromContractWhiteList', () => {51 let alice: IKeyringPair;52 let bob: IKeyringPair;5354 before(() => {55 alice = privateKey('//Alice');56 bob = privateKey('//Bob');57 });5859 it('fails when called with non-contract address', async () => {60 await usingApi(async () => {61 await removeFromContractWhiteListExpectFailure(alice, alice.address, bob.address);62 });63 });6465 it('fails when executed by non owner', async () => {66 await usingApi(async (api) => {67 const [flipper, _] = await deployFlipper(api);6869 await removeFromContractWhiteListExpectFailure(alice, flipper.address, bob.address);70 });71 });72});tests/src/util/helpers.tsdiffbeforeafterboth--- 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'));