Skip to content

Commit

Permalink
feat: minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
iavl committed Mar 27, 2024
1 parent cc0633e commit cf637cb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/ProxyAdminMultiSig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contract ProxyAdminMultiSig is IErrors {
string status;
}

uint256 internal constant MAX_UINT256 = type(uint256).max;
uint256 public constant MAX_UINT256 = type(uint256).max;

// multi-sig wallet
mapping(address => address) internal _owners;
Expand Down Expand Up @@ -190,13 +190,7 @@ contract ProxyAdminMultiSig is IErrors {

function _deletePendingProposalId(uint256 proposalId) internal {
// find index to be deleted
uint256 index = MAX_UINT256;
for (uint256 i = 0; i < _pendingProposalIds.length; i++) {
if (proposalId == _pendingProposalIds[i]) {
index = i;
break;
}
}
uint256 index = _getPendingProposalIndex(proposalId);

// if index not equal to MAX_UINT256, it means the proposalId is found
if (index != MAX_UINT256) {
Expand Down Expand Up @@ -225,9 +219,9 @@ contract ProxyAdminMultiSig is IErrors {

function _hasApproved(address owner, uint256 proposalId) internal view returns (bool) {
uint256 index = MAX_UINT256;
Proposal memory proposal = _proposals[proposalId];
for (uint256 i = 0; i < proposal.approvals.length; i++) {
if (owner == proposal.approvals[i]) {
address[] memory approvals = _proposals[proposalId].approvals;
for (uint256 i = 0; i < approvals.length; i++) {
if (owner == approvals[i]) {
index = i;
break;
}
Expand All @@ -237,17 +231,19 @@ contract ProxyAdminMultiSig is IErrors {
}

function _isPendingProposal(uint256 proposalId) internal view returns (bool) {
uint256 index = MAX_UINT256;
uint256 index = _getPendingProposalIndex(proposalId);
return index != MAX_UINT256;
}

/// @dev get the index of a pending proposal, return MAX_UINT256 if not found,
function _getPendingProposalIndex(uint256 proposalId) internal view returns (uint256 index) {
index = MAX_UINT256;
for (uint256 i = 0; i < _pendingProposalIds.length; i++) {
if (proposalId == _pendingProposalIds[i]) {
// plus 1 because index 0
// means a value is not in the array.
index = i + 1;
index = i;
break;
}
}

return index != MAX_UINT256;
}

/**
Expand Down
11 changes: 11 additions & 0 deletions test/ProxyAdminMultiSig.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ contract MultiSigTest is IErrors, Test, Utils {
proxy = address(transparentProxy);
}

function testSetupStatus() public view {
assertEq(_getImplementation(proxy), address(implementationV1));
assertEq(_getAdmin(proxy), address(multiSig));

_checkWalletDetail(2, 3, ownersArr3);

for (uint256 i = 0; i < ownersArr3.length; i++) {
assertEq(multiSig.isOwner(ownersArr3[i]), true);
}
}

function testConstruct() public {
multiSig = new ProxyAdminMultiSig(ownersArr3, 2);
_checkWalletDetail(2, 3, ownersArr3);
Expand Down

0 comments on commit cf637cb

Please sign in to comment.