difftreelog
NFTPAR-231 Smart Contract White List. Anyone can call contract with disabled white list.
in: master
2 files changed
pallets/nft/src/lib.rsdiffbeforeafterboth2514 let owned_contract = <ContractOwner<T>>::contains_key(called_contract.clone())2514 let owned_contract = <ContractOwner<T>>::contains_key(called_contract.clone())2515 && <ContractOwner<T>>::get(called_contract.clone()) == *who;2515 && <ContractOwner<T>>::get(called_contract.clone()) == *who;2516 2517 if !owned_contract {2518 let white_list_enabled = <ContractWhiteListEnabled<T>>::contains_key(called_contract.clone()) && <ContractWhiteListEnabled<T>>::get(called_contract.clone());2516 let white_list_enabled = <ContractWhiteListEnabled<T>>::contains_key(called_contract.clone()) && <ContractWhiteListEnabled<T>>::get(called_contract.clone());2517 2519 if !white_list_enabled || !<ContractWhiteList<T>>::contains_key(called_contract.clone(), who) {2518 if !owned_contract && white_list_enabled {2519 if !<ContractWhiteList<T>>::contains_key(called_contract.clone(), who) {2520 return Err(InvalidTransaction::Call.into());2520 return Err(InvalidTransaction::Call.into());2521 }2521 }2522 }2522 }252325232524 let mut sponsor_transfer = false;2524 let mut sponsor_transfer = false;2525 if <ContractSponsoringRateLimit<T>>::contains_key(called_contract.clone()) {2525 if <ContractSponsoringRateLimit<T>>::contains_key(called_contract.clone()) {tests/src/contracts.test.tsdiffbeforeafterboth--- a/tests/src/contracts.test.ts
+++ b/tests/src/contracts.test.ts
@@ -115,9 +115,10 @@
let expectedFlipValue = await getFlipValue(contract, deployer);
const flip = contract.exec('flip', value, gasLimit);
- await expect(submitTransactionExpectFailAsync(bob, flip)).to.be.rejected;
- const firstFailResponse = await getFlipValue(contract, deployer);
- expect(firstFailResponse).to.be.eq(expectedFlipValue, `Only account who deployed contract can flip value.`);
+ await submitTransactionAsync(bob, flip);
+ expectedFlipValue = !expectedFlipValue;
+ const afterFlip = await getFlipValue(contract,deployer);
+ expect(afterFlip).to.be.eq(expectedFlipValue, `Anyone can call new contract.`);
const deployerCanFlip = async () => {
expectedFlipValue = !expectedFlipValue;
@@ -144,34 +145,25 @@
expectedFlipValue = !expectedFlipValue;
const flipAfterWhiteListed = await getFlipValue(contract,deployer);
expect(flipAfterWhiteListed).to.be.eq(expectedFlipValue, `Bob was whitelisted, now he can flip.`);
-
- await deployerCanFlip();
-
- const disableWhiteListTx = api.tx.nft.toggleContractWhiteList(contract.address, false);
- const disableeResult = await submitTransactionAsync(deployer, disableWhiteListTx);
- const flipWithDisabledWhitelist = contract.exec('flip', value, gasLimit);
- await expect(submitTransactionExpectFailAsync(bob, flipWithDisabledWhitelist)).to.be.rejected;
- const flipWithDisabledWhiteList = await getFlipValue(contract, deployer);
- expect(flipWithDisabledWhiteList).to.be.eq(expectedFlipValue, `Bob can't flip when whitelist is disabled, even tho he is in whitelist.`);
await deployerCanFlip();
- const enableWhiteListOneMoreTimeTx = api.tx.nft.toggleContractWhiteList(contract.address, true);
- const enableOneMoreTimeResult = await submitTransactionAsync(deployer, enableWhiteListOneMoreTimeTx);
-
- await deployerCanFlip();
-
const removeBobFromWhiteListTx = api.tx.nft.removeFromContractWhiteList(contract.address, bob.address);
const removeBobResult = await submitTransactionAsync(deployer, removeBobFromWhiteListTx);
const bobRemoved = contract.exec('flip', value, gasLimit);
await expect(submitTransactionExpectFailAsync(bob, bobRemoved)).to.be.rejected;
const afterBobRemoved = await getFlipValue(contract, deployer);
- expect(afterBobRemoved).to.be.eq(expectedFlipValue, `Enabling whitelist doesn't make it possible to call contract for everyone.`);
+ expect(afterBobRemoved).to.be.eq(expectedFlipValue, `Bob can't call contract, now when he is removeed from white list.`);
await deployerCanFlip();
- const cleanupTx = api.tx.nft.toggleContractWhiteList(contract.address, false);
- const cleanupResult = await submitTransactionAsync(deployer, cleanupTx);
+ const disableWhiteListTx = api.tx.nft.toggleContractWhiteList(contract.address, false);
+ const disableWhiteListResult = await submitTransactionAsync(deployer, disableWhiteListTx);
+ const whiteListDisabledFlip = contract.exec('flip', value, gasLimit);
+ await submitTransactionAsync(bob, whiteListDisabledFlip);
+ expectedFlipValue = !expectedFlipValue;
+ const afterWhiteListDisabled = await getFlipValue(contract,deployer);
+ expect(afterWhiteListDisabled).to.be.eq(expectedFlipValue, `Anyone can call contract with disabled whitelist.`);
console.error = consoleError;
});