difftreelog
Add requested changes for toggleContractWL tests
in: master
1 file changed
tests/src/toggleContractWhiteList.test.tsdiffbeforeafterboth33 });33 });34 });34 });353536 it(`Only whitelisted account can call contract`, async () => {36 it.only(`Only whitelisted account can call contract`, async () => {37 await usingApi(async api => {37 await usingApi(async api => {38 const bob = privateKey("//Bob");38 const bob = privateKey("//Bob");393940 const [contract, deployer] = await deployFlipper(api);40 const [contract, deployer] = await deployFlipper(api);414142 let expectedFlipValue = await getFlipValue(contract, deployer);42 let flipValueBefore = await getFlipValue(contract, deployer);4344 const flip = contract.exec('flip', value, gasLimit);43 const flip = contract.exec('flip', value, gasLimit);45 await submitTransactionAsync(bob, flip);44 await submitTransactionAsync(bob, flip);46 expectedFlipValue = !expectedFlipValue;47 const afterFlip = await getFlipValue(contract,deployer);45 const flipValueAfter = await getFlipValue(contract,deployer);48 expect(afterFlip).to.be.eq(expectedFlipValue, `Anyone can call new contract.`);46 expect(flipValueAfter).to.be.eq(!flipValueBefore, `Anyone can call new contract.`);494750 const deployerCanFlip = async () => {48 const deployerCanFlip = async () => {51 expectedFlipValue = !expectedFlipValue;49 let flipValueBefore = await getFlipValue(contract, deployer);52 const deployerFlip = contract.exec('flip', value, gasLimit);50 const deployerFlip = contract.exec('flip', value, gasLimit);53 await submitTransactionAsync(deployer, deployerFlip);51 await submitTransactionAsync(deployer, deployerFlip);54 const aliceFlip1Response = await getFlipValue(contract, deployer);52 const aliceFlip1Response = await getFlipValue(contract, deployer);55 expect(aliceFlip1Response).to.be.eq(expectedFlipValue, `Deployer always can flip.`);53 expect(aliceFlip1Response).to.be.eq(!flipValueBefore, `Deployer always can flip.`);56 };54 };57 await deployerCanFlip();55 await deployerCanFlip();585657 flipValueBefore = await getFlipValue(contract, deployer);59 const enableWhiteListTx = api.tx.nft.toggleContractWhiteList(contract.address, true);58 const enableWhiteListTx = api.tx.nft.toggleContractWhiteList(contract.address, true);60 const enableResult = await submitTransactionAsync(deployer, enableWhiteListTx);59 const enableResult = await submitTransactionAsync(deployer, enableWhiteListTx);61 const flipWithEnabledWhiteList = contract.exec('flip', value, gasLimit);60 const flipWithEnabledWhiteList = contract.exec('flip', value, gasLimit);62 await expect(submitTransactionExpectFailAsync(bob, flipWithEnabledWhiteList)).to.be.rejected;61 await expect(submitTransactionExpectFailAsync(bob, flipWithEnabledWhiteList)).to.be.rejected;63 const flipValueAfterEnableWhiteList = await getFlipValue(contract, deployer);62 const flipValueAfterEnableWhiteList = await getFlipValue(contract, deployer);64 expect(flipValueAfterEnableWhiteList).to.be.eq(expectedFlipValue, `Enabling whitelist doesn't make it possible to call contract for everyone.`);63 expect(flipValueAfterEnableWhiteList).to.be.eq(flipValueBefore, `Enabling whitelist doesn't make it possible to call contract for everyone.`);656466 await deployerCanFlip();65 await deployerCanFlip();676667 flipValueBefore = await getFlipValue(contract, deployer);68 const addBobToWhiteListTx = api.tx.nft.addToContractWhiteList(contract.address, bob.address);68 const addBobToWhiteListTx = api.tx.nft.addToContractWhiteList(contract.address, bob.address);69 const addBobResult = await submitTransactionAsync(deployer, addBobToWhiteListTx);69 const addBobResult = await submitTransactionAsync(deployer, addBobToWhiteListTx);70 const flipWithWhitelistedBob = contract.exec('flip', value, gasLimit);70 const flipWithWhitelistedBob = contract.exec('flip', value, gasLimit);71 await submitTransactionAsync(bob, flipWithWhitelistedBob);71 await submitTransactionAsync(bob, flipWithWhitelistedBob);72 expectedFlipValue = !expectedFlipValue;73 const flipAfterWhiteListed = await getFlipValue(contract,deployer);72 const flipAfterWhiteListed = await getFlipValue(contract,deployer);74 expect(flipAfterWhiteListed).to.be.eq(expectedFlipValue, `Bob was whitelisted, now he can flip.`);73 expect(flipAfterWhiteListed).to.be.eq(!flipValueBefore, `Bob was whitelisted, now he can flip.`);757476 await deployerCanFlip();75 await deployerCanFlip();777677 flipValueBefore = await getFlipValue(contract, deployer);78 const removeBobFromWhiteListTx = api.tx.nft.removeFromContractWhiteList(contract.address, bob.address);78 const removeBobFromWhiteListTx = api.tx.nft.removeFromContractWhiteList(contract.address, bob.address);79 const removeBobResult = await submitTransactionAsync(deployer, removeBobFromWhiteListTx);79 const removeBobResult = await submitTransactionAsync(deployer, removeBobFromWhiteListTx);80 const bobRemoved = contract.exec('flip', value, gasLimit);80 const bobRemoved = contract.exec('flip', value, gasLimit);81 await expect(submitTransactionExpectFailAsync(bob, bobRemoved)).to.be.rejected;81 await expect(submitTransactionExpectFailAsync(bob, bobRemoved)).to.be.rejected;82 const afterBobRemoved = await getFlipValue(contract, deployer);82 const afterBobRemoved = await getFlipValue(contract, deployer);83 expect(afterBobRemoved).to.be.eq(expectedFlipValue, `Bob can't call contract, now when he is removeed from white list.`);83 expect(afterBobRemoved).to.be.eq(flipValueBefore, `Bob can't call contract, now when he is removeed from white list.`);848485 await deployerCanFlip();85 await deployerCanFlip();868687 flipValueBefore = await getFlipValue(contract, deployer);87 const disableWhiteListTx = api.tx.nft.toggleContractWhiteList(contract.address, false);88 const disableWhiteListTx = api.tx.nft.toggleContractWhiteList(contract.address, false);88 const disableWhiteListResult = await submitTransactionAsync(deployer, disableWhiteListTx);89 const disableWhiteListResult = await submitTransactionAsync(deployer, disableWhiteListTx);89 const whiteListDisabledFlip = contract.exec('flip', value, gasLimit);90 const whiteListDisabledFlip = contract.exec('flip', value, gasLimit);90 await submitTransactionAsync(bob, whiteListDisabledFlip);91 await submitTransactionAsync(bob, whiteListDisabledFlip);91 expectedFlipValue = !expectedFlipValue;92 const afterWhiteListDisabled = await getFlipValue(contract,deployer);92 const afterWhiteListDisabled = await getFlipValue(contract,deployer);93 expect(afterWhiteListDisabled).to.be.eq(expectedFlipValue, `Anyone can call contract with disabled whitelist.`);93 expect(afterWhiteListDisabled).to.be.eq(!flipValueBefore, `Anyone can call contract with disabled whitelist.`);949495 });95 });96 });96 });