Skip to content

Commit

Permalink
fix: test after merging branch feat/roles
Browse files Browse the repository at this point in the history
  • Loading branch information
blockchainguyy committed Oct 31, 2023
1 parent 479606e commit 7b5482b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
9 changes: 6 additions & 3 deletions contracts/test/utils/FlowLimitTestLiveNetwork.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) {
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions test/UtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7b5482b

Please sign in to comment.