Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: cleanup for ICS20 and its tests #253

Merged
merged 8 commits into from
Feb 5, 2025

Conversation

gjermundgaraba
Copy link
Contributor

Description

closes: #XXXX


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Linked to GitHub issue with discussion and accepted design, OR link to spec that describes this work.
  • Wrote unit and integration tests.
  • Added relevant natspec and godoc comments.
  • Provide a conventional commit message to follow the repository standards.
  • Re-reviewed Files changed in the GitHub PR explorer.
  • Review SonarCloud Report in the comment section below once CI passes.

Copy link

codecov bot commented Feb 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.46%. Comparing base (a6ee62a) to head (91347ec).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #253      +/-   ##
==========================================
- Coverage   99.47%   99.46%   -0.02%     
==========================================
  Files          12       12              
  Lines         572      560      -12     
==========================================
- Hits          569      557      -12     
  Misses          3        3              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@srdtrk srdtrk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm, left some comments. Will approve after changes

Comment on lines 154 to 160
/// @notice removeHop removes the first hop from the denom trace.
/// @param denom Denom to remove the hop from
/// @param hop Hop to remove (it must be the first hop)
/// @return The new denom with the first hop removed
function removeHop(bytes memory denom, bytes memory hop) internal pure returns (bytes memory) {
return Bytes.slice(denom, hop.length);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder what the efficiency changes would be if you inlined this code instead. We may wanna consider it if it has substantial efficiency. Since function code is also easy to read, you could simply inline this and add a comment inline.

Comment on lines 162 to 168
/// @notice addHop adds a hop to the denom trace as the first hop.
/// @param denom Denom to add the hop to
/// @param hop Hop to add
/// @return The new denom with the hop added
function addHop(bytes memory denom, bytes memory hop) internal pure returns (bytes memory) {
return abi.encodePacked(hop, denom);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto about efficiency and the need for this function. The internal logic is easy to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed them, but I think maybe the compiler inlines them anyway, because there was 0 gas difference in any tests.

/// @param ics26Router The ICS26Router contract
/// @custom:storage-location erc7201:ibc.storage.ICS20Transfer
struct ICS20TransferStorage {
IEscrow escrow;
mapping(string => IBCERC20) ibcDenomContracts;
mapping(bytes32 => IBCERC20) ibcDenomContracts;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mapping(bytes32 => IBCERC20) ibcDenomContracts;
mapping(bytes32 => IBCERC20) denomIDContracts;

You forgot to change the name? (Since natspec is changed) but also I don't really like the name too much.


if (packetData.amount == 0) {
return ICS20Lib.errorAck("invalid amount: 0");
}

(address receiver, bool receiverConvertSuccess) = ICS20Lib.hexStringToAddress(packetData.receiver);
(bool receiverConvertSuccess, address receiver) = Strings.tryParseAddress(packetData.receiver);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(bool receiverConvertSuccess, address receiver) = Strings.tryParseAddress(packetData.receiver);
(bool isAddress, address receiver) = Strings.tryParseAddress(packetData.receiver);

Cleaner name

IBCERC20(erc20Address).mint(packetData.amount);
}

// transfer the tokens to the receiver
// solhint-disable-next-line multiple-sends
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// solhint-disable-next-line multiple-sends

Why is this needed?

IBCERC20(erc20Address).mint(packetData.amount);
}

// solhint-disable-next-line multiple-sends
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// solhint-disable-next-line multiple-sends

Plz remove

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm. Might be worth looking into that 0.01% cov.

@srdtrk srdtrk changed the title test: refactor unit and integration tests for solidity refactor: cleanup for ICS20 and its tests Feb 5, 2025
@gjermundgaraba gjermundgaraba merged commit 305da82 into main Feb 5, 2025
60 of 61 checks passed
@gjermundgaraba gjermundgaraba deleted the gjermund/testing-improvements branch February 5, 2025 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants