Skip to content

Commit

Permalink
Merge pull request #9 from solidity-labs-io/addresses_unit_test
Browse files Browse the repository at this point in the history
Addresses.sol unit tests
  • Loading branch information
ElliotFriedman authored Dec 20, 2023
2 parents c3dd1d5 + 71249cb commit 302d9da
Show file tree
Hide file tree
Showing 7 changed files with 483 additions and 163 deletions.
8 changes: 4 additions & 4 deletions addresses/Addresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
{
"addr": "0x3dd46846eed8D147841AE162C8425c08BD8E1b41",
"name": "DEV_MULTISIG",
"chainId": 1
"chainId": 31337
},
{
"addr": "0x7da82C7AB4771ff031b66538D2fB9b0B047f6CF9",
"name": "TEAM_MULTISIG",
"chainId": 1
"chainId": 31337
},
{
"addr": "0x1a9C8182C09F50C8318d769245beA52c32BE35BC",
"name": "PROTOCOL_TIMELOCK",
"chainId": 1
"chainId": 31337
},
{
"addr": "0x10A19e7eE7d7F8a52822f6817de8ea18204F2e4f",
"name": "DAO_MULTISIG",
"chainId": 1
"chainId": 31337
}
]
33 changes: 18 additions & 15 deletions addresses/Addresses.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ contract Addresses is IAddresses, Test {
/// @notice struct to record addresses deployed during a proposal
struct RecordedAddress {
string name;
address addr;
uint256 chainId;
}

/// @notice array of addresses deployed during a proposal
Expand All @@ -45,12 +45,7 @@ contract Addresses is IAddresses, Test {

SavedAddresses[] memory savedAddresses = abi.decode(parsedJson, (SavedAddresses[]));

for (uint256 i = 0; i < savedAddresses.length; i++) {
require(
getAddress(savedAddresses[i].name, savedAddresses[i].chainId) == address(0),
"Addresses: duplicate address in json"
);

for (uint256 i = 0; i < savedAddresses.length; i++) {
_addAddress(savedAddresses[i].name, savedAddresses[i].chainId, savedAddresses[i].addr);
}
}
Expand All @@ -61,13 +56,13 @@ contract Addresses is IAddresses, Test {

require(
currentAddress == address(0),
string(abi.encodePacked("Address: ", name, "already set on chain: ", _chainId.toString()))
string(abi.encodePacked("Address: ", name, " already set on chain: ", _chainId.toString()))
);

_addresses[name][_chainId] = addr;
vm.label(addr, name);

recordedAddresses.push(RecordedAddress({name: name, addr: addr}));
recordedAddresses.push(RecordedAddress({name: name, chainId: _chainId}));
}

function _getAddress(string memory name, uint256 _chainId) private view returns (address addr) {
Expand All @@ -77,7 +72,7 @@ contract Addresses is IAddresses, Test {

require(
addr != address(0),
string(abi.encodePacked("Address: ", name, "not set on chain: ", _chainId.toString()))
string(abi.encodePacked("Address: ", name, " not set on chain: ", _chainId.toString()))
);
}

Expand All @@ -103,16 +98,24 @@ contract Addresses is IAddresses, Test {

/// @notice remove recorded addresses
function resetRecordingAddresses() external {
for (uint256 i = 0; i < recordedAddresses.length; i++) {
delete _addresses[recordedAddresses[i].name][recordedAddresses[i].chainId];
}

delete recordedAddresses;
}

/// @notice get recorded addresses from a proposal's deployment
function getRecordedAddresses() external view returns (string[] memory names, address[] memory addresses) {
names = new string[](recordedAddresses.length);
addresses = new address[](recordedAddresses.length);
for (uint256 i = 0; i < recordedAddresses.length; i++) {
function getRecordedAddresses() external view returns (string[] memory names, uint256[] memory chainIds, address[] memory addresses) {
uint256 length = recordedAddresses.length;
names = new string[](length);
chainIds = new uint256[](length);
addresses = new address[](length);

for (uint256 i = 0; i < length; i++) {
names[i] = recordedAddresses[i].name;
addresses[i] = recordedAddresses[i].addr;
chainIds[i] = recordedAddresses[i].chainId;
addresses[i] = _addresses[recordedAddresses[i].name][recordedAddresses[i].chainId];
}
}
}
2 changes: 1 addition & 1 deletion addresses/IAddresses.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ interface IAddresses {
function resetRecordingAddresses() external;

/// @notice get recorded addresses from a proposal's deployment
function getRecordedAddresses() external view returns (string[] memory names, address[] memory addresses);
function getRecordedAddresses() external view returns (string[] memory names, uint256[] memory chainIds, address[] memory addresses);
}
Loading

0 comments on commit 302d9da

Please sign in to comment.