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

Support SendToIbc event in smart contract #65

Merged
merged 11 commits into from
Sep 13, 2021

Conversation

thomas-nguy
Copy link
Collaborator

support ibc log event handler

PR Checklist:

  • Have you read the CONTRIBUTING.md?
  • Does your PR follow the C4 patch requirements?
  • Have you rebased your work on top of the latest master?
  • Have you checked your code compiles? (make)
  • Have you included tests for any non-trivial functionality?
  • Have you checked your code passes the unit tests? (make test)
  • Have you checked your code formatting is correct? (go fmt)
  • Have you checked your basic code style is fine? (golangci-lint run)
  • If you added any dependencies, have you checked they do not contain any known vulnerabilities? (go list -json -m all | nancy sleuth)
  • If your changes affect the client infrastructure, have you run the integration test?
  • If your changes affect public APIs, does your PR follow the C4 evolution of public contracts?
  • If your code changes public APIs, have you incremented the crate version numbers and documented your changes in the CHANGELOG.md?
  • If you are contributing for the first time, please read the agreement in CONTRIBUTING.md now and add a comment to this pull request stating that your PR is in accordance with the Developer's Certificate of Origin.

Thank you for your code, it's appreciated! :)

@thomas-nguy thomas-nguy requested a review from a team as a code owner September 9, 2021 09:27
@thomas-nguy thomas-nguy requested review from yihuang and calvinaco and removed request for a team September 9, 2021 09:27
@thomas-nguy thomas-nguy changed the title support transferToIbc log event in smart contract support sendToIbc log event in smart contract Sep 9, 2021
@@ -30,11 +32,16 @@ var (
// EthereumTransferEvent represent the signature of
// `event __CronosSendToEthereum(address recipient, uint256 amount, uint256 bridge_fee)`
EthereumTransferEvent abi.Event

// IbcTransferEvent represent the signature of
// `event __CronosSendToIbc(address sender, string recipient, uint256 amount)`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// `event __CronosSendToIbc(address sender, string recipient, uint256 amount)`
// `event __CronosSendToIbc(string recipient, uint256 amount)`

It don't have the sender parameter in the definition.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@@ -136,7 +157,7 @@ func (h EthereumTransferHandler) Handle(ctx sdk.Context, contract common.Address
}

denom, found := h.cronosKeeper.GetDenomByContract(ctx, contract)
if !found {
if !found && !types.IsValidGravityDenom(denom) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if !found && !types.IsValidGravityDenom(denom) {
if !found || !types.IsValidGravityDenom(denom) {

I guess it should be a || here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

}

denom, found := h.cronosKeeper.GetDenomByContract(ctx, contract)
if !found && !types.IsValidIBCDenom(denom) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if !found && !types.IsValidIBCDenom(denom) {
if !found || !types.IsValidIBCDenom(denom) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@thomas-nguy thomas-nguy linked an issue Sep 9, 2021 that may be closed by this pull request
@thomas-nguy thomas-nguy changed the title support sendToIbc log event in smart contract support SendToIbc event in smart contract Sep 9, 2021
@thomas-nguy thomas-nguy changed the title support SendToIbc event in smart contract Support SendToIbc event in smart contract Sep 9, 2021
@thomas-nguy thomas-nguy changed the base branch from thomas/support-ibc-to-crc20 to main September 9, 2021 12:02
Comment on lines 233 to 234
func() {
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func() {
},
func() {},

x/cronos/keeper/evm_log_handlers.go Show resolved Hide resolved
Comment on lines 205 to 207
if !found || !types.IsValidIBCDenom(denom) {
return fmt.Errorf("contract %s is not connected to native token", contract)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we distinguish the two cases?

  • !found => No mapping found
  • !types.IsValidIBCDenom(denom) => Mapping found, but the contract is not mapped to an IBC asset

@@ -136,7 +157,7 @@ func (h EthereumTransferHandler) Handle(ctx sdk.Context, contract common.Address
}

denom, found := h.cronosKeeper.GetDenomByContract(ctx, contract)
if !found {
if !found || !types.IsValidGravityDenom(denom) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we distinguish the two cases?

  • !found => No mapping found
  • !types.IsValidGravityDenom(denom)=> Mapping found, but the contract is not mapped to an gravity asset


// IbcTransferEvent represent the signature of
// `event __CronosSendToIbc(string recipient, uint256 amount)`
IbcTransferEvent abi.Event
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we rename these variables based on the event name? i.e. SendToIbcEvent

I sometimes find it confusing when I look at IbcTransferEvent in the code

@@ -159,6 +163,47 @@ func (suite *KeeperTestSuite) TestEvmHooks() {
suite.Require().Equal(1, len(rsp.SendToEthereums))
},
},
{
"failed ibc transfer, invalid denom",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"failed ibc transfer, invalid denom",
"failed ibc transfer, non-IBC denom",

invalid is not self-explanatory here

error error
}{
{
"invalid denom, expect fail",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"invalid denom, expect fail",
"non-IBC denom, expect fail",

error error
}{
{
"invalid denom, expect fail",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"invalid denom, expect fail",
"non-Gravity denom, expect fail",

@@ -0,0 +1,14 @@
pragma solidity ^0.6.11;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we remove this if it's not used?
if it's for integration testing, we could also move it to integration_tests/contracts/.

Copy link
Collaborator

@yihuang yihuang left a comment

Choose a reason for hiding this comment

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

LGTM overall, only minor suggestions.

@codecov
Copy link

codecov bot commented Sep 10, 2021

Codecov Report

Merging #65 (fc9e5a2) into main (3ea70c5) will increase coverage by 3.61%.
The diff coverage is 38.27%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #65      +/-   ##
==========================================
+ Coverage   21.51%   25.12%   +3.61%     
==========================================
  Files          27       32       +5     
  Lines        1729     2145     +416     
==========================================
+ Hits          372      539     +167     
- Misses       1324     1570     +246     
- Partials       33       36       +3     
Impacted Files Coverage Δ
app/app.go 3.89% <0.00%> (-0.06%) ⬇️
x/cronos/keeper/grpc_query.go 0.00% <0.00%> (ø)
x/cronos/keeper/hooks.go 0.00% <0.00%> (ø)
x/cronos/keeper/msg_server.go 6.45% <0.00%> (ø)
x/cronos/types/query.pb.gw.go 0.00% <0.00%> (ø)
x/cronos/types/tracer.go 0.00% <0.00%> (ø)
x/cronos/keeper/evm.go 57.62% <66.66%> (+5.90%) ⬆️
x/cronos/keeper/evmhooks.go 80.00% <80.00%> (ø)
x/cronos/keeper/evm_log_handlers.go 86.52% <86.52%> (ø)
x/cronos/keeper/ibc.go 83.06% <100.00%> (+4.88%) ⬆️
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 66d9e40...fc9e5a2. Read the comment docs.

@thomas-nguy thomas-nguy merged commit 0cfaaf9 into main Sep 13, 2021
@yihuang yihuang deleted the thomas/support-ibc-log-handler branch September 13, 2021 03:32
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.

Support SendToIBC in evm_log_handlers
3 participants