Skip to content

Commit

Permalink
using nums to convert to addr instead of placing load on fuzz testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ravinagill15 committed Aug 21, 2024
1 parent 55eb770 commit aa5ae1a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
6 changes: 3 additions & 3 deletions tests/ua-devtools-evm-foundry-test/test/ReceiveConfig.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ contract ReceiveConfigTest is Test {
receiveConfig = new ReceiveConfig();
}

function test_run_updates_receive_config(uint64 _confirmations, address[] memory _requiredDvns) public {
function test_run_updates_receive_config(uint64 _confirmations, uint8[] memory _requiredDvns) public {
vm.assume(_confirmations > 0 && _confirmations < type(uint64).max);
vm.assume(_requiredDvns.length > 0 && _requiredDvns.length <= 5 && Helpers.validateRequiredDvns(_requiredDvns));
vm.assume(_requiredDvns.length > 0 && _requiredDvns.length < 10);

UlnConfig memory ulnConfig = UlnConfig({
confirmations: _confirmations,
requiredDVNs: _requiredDvns,
requiredDVNs: Helpers.convertToAddresses(_requiredDvns),
requiredDVNCount: uint8(_requiredDvns.length),
optionalDVNCount: 0,
optionalDVNs: new address[](0),
Expand Down
6 changes: 3 additions & 3 deletions tests/ua-devtools-evm-foundry-test/test/SendConfig.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ contract SendConfigTest is Test {
sendConfig = new SendConfig();
}

function test_run_updates_send_config(uint64 _confirmations, address[] memory _requiredDvns, uint32 _maxMessageSize, address _executor) public {
function test_run_updates_send_config(uint64 _confirmations, uint8[] memory _requiredDvns, uint32 _maxMessageSize, address _executor) public {
vm.assume(_confirmations > 0 && _confirmations < type(uint64).max);
vm.assume(_requiredDvns.length > 0 && _requiredDvns.length <= 5 && Helpers.validateRequiredDvns(_requiredDvns));
vm.assume(_requiredDvns.length > 0 && _requiredDvns.length < 10);

UlnConfig memory ulnConfig = UlnConfig({
confirmations: _confirmations,
requiredDVNs: _requiredDvns,
requiredDVNs: Helpers.convertToAddresses(_requiredDvns),
requiredDVNCount: uint8(_requiredDvns.length),
optionalDVNCount: 0,
optionalDVNs: new address[](0),
Expand Down
25 changes: 14 additions & 11 deletions tests/ua-devtools-evm-foundry-test/utils/Helpers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
pragma solidity ^0.8.22;

library Helpers {
// Validate that the required DVNs are sorted in strictly ascending order, contain no duplicates, and are not address(0)
function validateRequiredDvns(address[] memory arr) internal pure returns (bool) {
if (arr.length < 2) return arr.length == 0 || arr[0] != address(0); // Handle arrays of length 0 or 1

for (uint256 i = 0; i < arr.length; i++) {
if (arr[i] == address(0)) {
return false; // Contains a zero address
}
function convertToAddresses(uint8[] memory numbers) public pure returns (address[] memory) {
address[] memory addresses = new address[](numbers.length);
uint160 cumulativeSum = 0;

if (i > 0 && arr[i] <= arr[i - 1]) {
return false; // Not sorted in strictly ascending order or contains duplicates
}
for (uint i = 0; i < numbers.length; i++) {
// Treat 0 as 1
uint8 currentNumber = numbers[i] == 0 ? 1 : numbers[i];

// Add to cumulative sum
cumulativeSum += currentNumber;

// Convert cumulative sum to address
addresses[i] = address(cumulativeSum);
}
return true;

return addresses;
}
}

0 comments on commit aa5ae1a

Please sign in to comment.