Skip to content

Commit 456c588

Browse files
committed
fix: token and caps array mismatch
1 parent fb791fb commit 456c588

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

src/contracts/action-hubs/CappedTokenTransfersHub.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ contract CappedTokenTransfersHub is ActionHub, ICappedTokenTransfersHub, SafeMan
5252
EPOCH_LENGTH = _epochLength;
5353
lastEpoch = block.timestamp;
5454

55+
if (_tokens.length != _caps.length) revert TokensAndCapsLengthMismatch();
5556
if (_epochLength == 0) revert EpochLengthCannotBeZero();
5657

5758
for (uint256 i = 0; i < _tokens.length; i++) {

src/interfaces/action-hubs/ICappedTokenTransfersHub.sol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ interface ICappedTokenTransfersHub is IActionHub, ISafeManageable {
5050
*/
5151
error TokenAlreadyRegisteredInHub(address _token);
5252

53+
/**
54+
* @notice Thrown when the tokens and caps length mismatch
55+
*/
56+
error TokensAndCapsLengthMismatch();
57+
5358
// ~~~ FUNCTIONS ~~~
5459

5560
/**

test/unit/actions-hubs/CappedTokenTransfersHub.t.sol

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,21 @@ contract UnitCappedTokenTransfersHub is Test {
8080
new CappedTokenTransfersHub(safe, recipient, tokens, caps, 0);
8181
}
8282

83+
function test_Constructor_WhenTheTokensAndCapsLengthMismatch() external {
84+
tokens = new address[](2);
85+
tokens[0] = makeAddr('token1');
86+
tokens[1] = makeAddr('token2');
87+
88+
caps = new uint256[](3);
89+
caps[0] = 100;
90+
caps[1] = 200;
91+
caps[2] = 300;
92+
93+
// it reverts
94+
vm.expectRevert(ICappedTokenTransfersHub.TokensAndCapsLengthMismatch.selector);
95+
new CappedTokenTransfersHub(safe, recipient, tokens, caps, EPOCH_LENGTH);
96+
}
97+
8398
modifier whenCalledByTheSafeOwner() {
8499
vm.mockCall(address(safe), abi.encodeWithSelector(IOwnerManager.isOwner.selector), abi.encode(true));
85100
_;

test/unit/actions-hubs/CappedTokenTransfersHub.tree

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ UnitCappedTokenTransfersHub::constructor
66
│ └── it sets the tokens and caps
77
├── When tokens registered contain a duplicated token
88
│ └── it reverts
9-
└── When the epoch length is zero
9+
├── When the epoch length is zero
10+
│ └── it reverts
11+
└── When the tokens and caps length mismatch
1012
└── it reverts
1113

1214
UnitCappedTokenTransfersHub::createNewActionsBuilder

0 commit comments

Comments
 (0)