From 7b5482ba27d456e71e5b11c743dc6d66a218284c Mon Sep 17 00:00:00 2001 From: blockchainguyy Date: Tue, 31 Oct 2023 12:05:40 +0530 Subject: [PATCH] fix: test after merging branch feat/roles --- contracts/test/utils/FlowLimitTestLiveNetwork.sol | 9 ++++++--- test/UtilsTest.js | 2 ++ test/utils.js | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/contracts/test/utils/FlowLimitTestLiveNetwork.sol b/contracts/test/utils/FlowLimitTestLiveNetwork.sol index d85fda38..2f02bc4a 100644 --- a/contracts/test/utils/FlowLimitTestLiveNetwork.sol +++ b/contracts/test/utils/FlowLimitTestLiveNetwork.sol @@ -8,6 +8,7 @@ contract FlowLimitTestLiveNetwork is IFlowLimit { uint256 internal constant FLOW_LIMIT_SLOT = 0x201b7a0b7c19aaddc4ce9579b7df8d2db123805861bc7763627f13e04d8af42f; uint256 internal constant PREFIX_FLOW_OUT_AMOUNT = uint256(keccak256('flow-out-amount')); uint256 internal constant PREFIX_FLOW_IN_AMOUNT = uint256(keccak256('flow-in-amount')); + bytes32 public constant TOKEN_ID = 0x0; uint256 internal constant EPOCH_TIME = 60; @@ -22,7 +23,7 @@ contract FlowLimitTestLiveNetwork is IFlowLimit { sstore(FLOW_LIMIT_SLOT, flowLimit) } - emit FlowLimitSet(flowLimit); + emit FlowLimitSet(TOKEN_ID, msg.sender, flowLimit); } function _getFlowOutSlot(uint256 epoch) internal pure returns (uint256 slot) { @@ -60,8 +61,10 @@ contract FlowLimitTestLiveNetwork is IFlowLimit { flowToCompare := sload(slotToCompare) } - if (flowToAdd + flowAmount > flowToCompare + flowLimit) revert FlowLimitExceeded(); - if (flowAmount > flowLimit) revert FlowLimitExceeded(); + uint256 maxFlowLimit = flowToCompare + flowLimit; + uint256 netFlowAmount = flowToAdd + flowAmount; + if (netFlowAmount > maxFlowLimit) revert FlowLimitExceeded(maxFlowLimit, netFlowAmount); + if (flowAmount > flowLimit) revert FlowLimitExceeded(flowLimit, flowAmount); assembly { sstore(slotToAdd, add(flowToAdd, flowAmount)) diff --git a/test/UtilsTest.js b/test/UtilsTest.js index 4dfdf23c..f24171dd 100644 --- a/test/UtilsTest.js +++ b/test/UtilsTest.js @@ -226,12 +226,14 @@ describe('ExpressCallHandler', () => { describe('FlowLimit', async () => { let test; + let tokenId; const flowLimit = isHardhat ? 5 : 2; before(async () => { test = isHardhat ? await deployContract(ownerWallet, 'FlowLimitTest') : await deployContract(ownerWallet, 'FlowLimitTestLiveNetwork'); + tokenId = await test.TOKEN_ID(); }); async function nextEpoch() { diff --git a/test/utils.js b/test/utils.js index fec60d74..5711be2e 100644 --- a/test/utils.js +++ b/test/utils.js @@ -10,6 +10,8 @@ const getGasOptions = () => { return network.config.blockGasLimit ? { gasLimit: network.config.blockGasLimit.toString() } : { gasLimit: 5e6 }; // defaults to 5M gas for revert tests to work correctly }; +const isHardhat = network.name === 'hardhat'; + const expectRevert = async (txFunc, contract, error, args) => { if (network.config.skipRevertTests) { await expect(txFunc(getGasOptions())).to.be.reverted;