-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: parse validator indexes as arrays from solidity
- Loading branch information
1 parent
025d296
commit d9c722a
Showing
2 changed files
with
151 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "forge-std/Test.sol"; | ||
import "../script/RegisterValidators.s.sol"; | ||
|
||
contract StringToUintArrayTest is Test { | ||
|
||
function setUp() public {} | ||
|
||
function testParseValidatorIndexes1() public pure { | ||
uint256[] memory indexes = StringToUintArrayLib.fromStr("1,2,3,4"); | ||
uint256[4] memory expected; | ||
expected[0] = 1; | ||
expected[1] = 2; | ||
expected[2] = 3; | ||
expected[3] = 4; | ||
|
||
assertEq(indexes.length, expected.length); | ||
for (uint256 i = 0; i < indexes.length; i++) { | ||
assertEq(indexes[i], expected[i]); | ||
} | ||
} | ||
|
||
function testParseValidatorIndexes2() public pure { | ||
uint256[] memory indexes = StringToUintArrayLib.fromStr("1..4"); | ||
uint256[4] memory expected; | ||
expected[0] = 1; | ||
expected[1] = 2; | ||
expected[2] = 3; | ||
expected[3] = 4; | ||
|
||
assertEq(indexes.length, expected.length); | ||
for (uint256 i = 0; i < indexes.length; i++) { | ||
assertEq(indexes[i], expected[i]); | ||
} | ||
} | ||
|
||
function testParseValidatorIndexes3() public pure { | ||
uint256[] memory indexes = StringToUintArrayLib.fromStr("1..4,6..8"); | ||
uint256[7] memory expected; | ||
expected[0] = 1; | ||
expected[1] = 2; | ||
expected[2] = 3; | ||
expected[3] = 4; | ||
expected[4] = 6; | ||
expected[5] = 7; | ||
expected[6] = 8; | ||
|
||
assertEq(indexes.length, expected.length); | ||
for (uint256 i = 0; i < indexes.length; i++) { | ||
assertEq(indexes[i], expected[i]); | ||
} | ||
} | ||
|
||
function testParseValidatorIndexes4() public pure { | ||
uint256[] memory indexes = StringToUintArrayLib.fromStr("1,2..4,6..8"); | ||
uint256[7] memory expected; | ||
expected[0] = 1; | ||
expected[1] = 2; | ||
expected[2] = 3; | ||
expected[3] = 4; | ||
expected[4] = 6; | ||
expected[5] = 7; | ||
expected[6] = 8; | ||
|
||
assertEq(indexes.length, expected.length); | ||
for (uint256 i = 0; i < indexes.length; i++) { | ||
assertEq(indexes[i], expected[i]); | ||
} | ||
} | ||
|
||
function testParse100Indexes() public pure { | ||
string memory input = "1..100"; | ||
|
||
uint256[] memory indexes = StringToUintArrayLib.fromStr(input); | ||
assertEq(indexes.length, 100); | ||
for (uint256 i = 0; i < indexes.length; i++) { | ||
assertEq(indexes[i], i + 1); | ||
} | ||
} | ||
} |