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
--- 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
modifiedruntime_types.jsondiffbeforeafterboth
before · runtime_types.json
1{2    "AccessMode": {3      "_enum": [4        "Normal",5        "WhiteList"6      ]7    },8    "DecimalPoints": "u8",9    "CollectionMode": {10      "_enum": {11        "Invalid": null,12        "NFT": null,13        "Fungible": "DecimalPoints",14        "ReFungible": null15      }16    },17    "Ownership": {18      "Owner": "AccountId",19      "Fraction": "u128"20    },21    "FungibleItemType": {22      "Value": "u128"23    },24    "NftItemType": {25      "Owner": "AccountId",26      "ConstData": "Vec<u8>",27      "VariableData": "Vec<u8>"28    },29    "ReFungibleItemType": {30      "Owner": "Vec<Ownership<AccountId>>",31      "ConstData": "Vec<u8>",32      "VariableData": "Vec<u8>"33    },34    "CollectionType": {35      "Owner": "AccountId",36      "Mode": "CollectionMode",37      "Access": "AccessMode",38      "DecimalPoints": "DecimalPoints",39      "Name": "Vec<u16>",40      "Description": "Vec<u16>",41      "TokenPrefix": "Vec<u8>",42      "MintMode": "bool",43      "OffchainSchema": "Vec<u8>",44      "SchemaVersion": "SchemaVersion",45      "Sponsor": "AccountId",46      "SponsorConfirmed": "bool",47      "Limits": "CollectionLimits",48      "VariableOnChainSchema": "Vec<u8>",49      "ConstOnChainSchema": "Vec<u8>"50    },51    "RawData": "Vec<u8>",52    "Address": "AccountId",53    "LookupSource": "AccountId",54    "Weight": "u64",55    "CreateNftData": {56      "const_data": "Vec<u8>",57      "variable_data": "Vec<u8>" 58    },59    "CreateFungibleData": {60      "value": "u128"61    },62    "CreateReFungibleData": {63      "const_data": "Vec<u8>",64      "variable_data": "Vec<u8>",65      "pieces": "u128"66    },67    "CreateItemData": {68      "_enum": {69        "NFT": "CreateNftData",70        "Fungible": "CreateFungibleData",71        "ReFungible": "CreateReFungibleData"72      }73    },74    "SchemaVersion": {75      "_enum": [76        "ImageURL",77        "Unique"78      ]79    },80    "CollectionId": "u32",81    "TokenId": "u32",82    "ChainLimits": {83      "CollectionNumbersLimit": "u32",84      "AccountTokenOwnershipLimit": "u32",85      "CollectionAdminsLimit": "u64",86      "CustomDataLimit": "u32",87      "NftSponsorTimeout": "u32",88      "FungibleSponsorTimeout": "u32",89      "RefungibleSponsorTimeout": "u32",90      "OffchainSchemaLimit": "u32",91      "VariableOnChainSchemaLimit": "u32",92      "ConstOnChainSchemaLimit": "u32"93    },94    "CollectionLimits": {95      "AccountTokenOwnershipLimit": "u32",96      "SponsoredMintSize": "u32",97      "TokenLimit": "u32",98      "SponsorTimeout": "u32"99    }100}
after · runtime_types.json
1{2    "AccessMode": {3      "_enum": [4        "Normal",5        "WhiteList"6      ]7    },8    "DecimalPoints": "u8",9    "CollectionMode": {10      "_enum": {11        "Invalid": null,12        "NFT": null,13        "Fungible": "DecimalPoints",14        "ReFungible": null15      }16    },17    "Ownership": {18      "Owner": "AccountId",19      "Fraction": "u128"20    },21    "FungibleItemType": {22      "Value": "u128"23    },24    "NftItemType": {25      "Owner": "AccountId",26      "ConstData": "Vec<u8>",27      "VariableData": "Vec<u8>"28    },29    "ReFungibleItemType": {30      "Owner": "Vec<Ownership<AccountId>>",31      "ConstData": "Vec<u8>",32      "VariableData": "Vec<u8>"33    },34    "CollectionType": {35      "Owner": "AccountId",36      "Mode": "CollectionMode",37      "Access": "AccessMode",38      "DecimalPoints": "DecimalPoints",39      "Name": "Vec<u16>",40      "Description": "Vec<u16>",41      "TokenPrefix": "Vec<u8>",42      "MintMode": "bool",43      "OffchainSchema": "Vec<u8>",44      "SchemaVersion": "SchemaVersion",45      "Sponsor": "AccountId",46      "SponsorConfirmed": "bool",47      "Limits": "CollectionLimits",48      "VariableOnChainSchema": "Vec<u8>",49      "ConstOnChainSchema": "Vec<u8>"50    },51    "RawData": "Vec<u8>",52    "Address": "AccountId",53    "LookupSource": "AccountId",54    "Weight": "u64",55    "CreateNftData": {56      "const_data": "Vec<u8>",57      "variable_data": "Vec<u8>" 58    },59    "CreateFungibleData": {60      "value": "u128"61    },62    "CreateReFungibleData": {63      "const_data": "Vec<u8>",64      "variable_data": "Vec<u8>",65      "pieces": "u128"66    },67    "CreateItemData": {68      "_enum": {69        "NFT": "CreateNftData",70        "Fungible": "CreateFungibleData",71        "ReFungible": "CreateReFungibleData"72      }73    },74    "SchemaVersion": {75      "_enum": [76        "ImageURL",77        "Unique"78      ]79    },80    "CollectionId": "u32",81    "TokenId": "u32",82    "ChainLimits": {83      "CollectionNumbersLimit": "u32",84      "AccountTokenOwnershipLimit": "u32",85      "CollectionAdminsLimit": "u64",86      "CustomDataLimit": "u32",87      "NftSponsorTimeout": "u32",88      "FungibleSponsorTimeout": "u32",89      "RefungibleSponsorTimeout": "u32",90      "OffchainSchemaLimit": "u32",91      "VariableOnChainSchemaLimit": "u32",92      "ConstOnChainSchemaLimit": "u32"93    },94    "CollectionLimits": {95      "AccountTokenOwnershipLimit": "u32",96      "SponsoredMintSize": "u32",97      "TokenLimit": "u32",98      "SponsorTimeout": "u32",99      "OwnerCanTransfer": "bool",100      "OwnerCanDestroy": "bool"101    }102}
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'));