git.delta.rocks / unique-network / refs/commits / 2e2d3bf50283

difftreelog

Merge branch 'develop' into feature/transferfromtests

Greg Zaitsev2021-02-09parents: #0954b32 #337b8d4.patch.diff
in: master

4 files changed

modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
185185
186 // Timeouts for item types in passed blocks186 // Timeouts for item types in passed blocks
187 pub sponsor_transfer_timeout: u32,187 pub sponsor_transfer_timeout: u32,
188 pub owner_can_transfer: bool,
189 pub owner_can_destroy: bool,
188}190}
189191
190impl Default for CollectionLimits {192impl Default for CollectionLimits {
193 account_token_ownership_limit: 10_000_000, 195 account_token_ownership_limit: 10_000_000,
194 token_limit: u32::max_value(),196 token_limit: u32::max_value(),
195 sponsored_data_size: u32::max_value(), 197 sponsored_data_size: u32::max_value(),
196 sponsor_transfer_timeout: 14400 }198 sponsor_transfer_timeout: 14400,
199 owner_can_transfer: true,
200 owner_can_destroy: true
201 }
197 }202 }
198}203}
modifiedruntime_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
addedtests/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);
+        });
+    });
+});
modifiedtests/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'));