From aa5ae1a5591f044b6f7bd0d6687f38c3954bb975 Mon Sep 17 00:00:00 2001 From: ravinagill15 Date: Tue, 20 Aug 2024 17:17:58 -0700 Subject: [PATCH] using nums to convert to addr instead of placing load on fuzz testing --- .../test/ReceiveConfig.t.sol | 6 ++--- .../test/SendConfig.t.sol | 6 ++--- .../utils/Helpers.sol | 25 +++++++++++-------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/tests/ua-devtools-evm-foundry-test/test/ReceiveConfig.t.sol b/tests/ua-devtools-evm-foundry-test/test/ReceiveConfig.t.sol index 6fbab88ea..3342326ab 100644 --- a/tests/ua-devtools-evm-foundry-test/test/ReceiveConfig.t.sol +++ b/tests/ua-devtools-evm-foundry-test/test/ReceiveConfig.t.sol @@ -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), diff --git a/tests/ua-devtools-evm-foundry-test/test/SendConfig.t.sol b/tests/ua-devtools-evm-foundry-test/test/SendConfig.t.sol index ccb93cc10..0559901a3 100644 --- a/tests/ua-devtools-evm-foundry-test/test/SendConfig.t.sol +++ b/tests/ua-devtools-evm-foundry-test/test/SendConfig.t.sol @@ -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), diff --git a/tests/ua-devtools-evm-foundry-test/utils/Helpers.sol b/tests/ua-devtools-evm-foundry-test/utils/Helpers.sol index 93b089b18..24f6cc938 100644 --- a/tests/ua-devtools-evm-foundry-test/utils/Helpers.sol +++ b/tests/ua-devtools-evm-foundry-test/utils/Helpers.sol @@ -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; } }