-
Notifications
You must be signed in to change notification settings - Fork 241
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
Conversation
x/cronos/keeper/evm_log_handlers.go
Outdated
@@ -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)` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// `event __CronosSendToIbc(address sender, string recipient, uint256 amount)` | |
// `event __CronosSendToIbc(string recipient, uint256 amount)` |
It don't have the sender parameter in the definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
x/cronos/keeper/evm_log_handlers.go
Outdated
@@ -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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if !found && !types.IsValidGravityDenom(denom) { | |
if !found || !types.IsValidGravityDenom(denom) { |
I guess it should be a ||
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
x/cronos/keeper/evm_log_handlers.go
Outdated
} | ||
|
||
denom, found := h.cronosKeeper.GetDenomByContract(ctx, contract) | ||
if !found && !types.IsValidIBCDenom(denom) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if !found && !types.IsValidIBCDenom(denom) { | |
if !found || !types.IsValidIBCDenom(denom) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
49196ea
to
3312cc6
Compare
func() { | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func() { | |
}, | |
func() {}, |
x/cronos/keeper/evm_log_handlers.go
Outdated
if !found || !types.IsValidIBCDenom(denom) { | ||
return fmt.Errorf("contract %s is not connected to native token", contract) | ||
} |
There was a problem hiding this comment.
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
x/cronos/keeper/evm_log_handlers.go
Outdated
@@ -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) { |
There was a problem hiding this comment.
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
x/cronos/keeper/evm_log_handlers.go
Outdated
|
||
// IbcTransferEvent represent the signature of | ||
// `event __CronosSendToIbc(string recipient, uint256 amount)` | ||
IbcTransferEvent abi.Event |
There was a problem hiding this comment.
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
x/cronos/keeper/evmhooks_test.go
Outdated
@@ -159,6 +163,47 @@ func (suite *KeeperTestSuite) TestEvmHooks() { | |||
suite.Require().Equal(1, len(rsp.SendToEthereums)) | |||
}, | |||
}, | |||
{ | |||
"failed ibc transfer, invalid denom", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"failed ibc transfer, invalid denom", | |
"failed ibc transfer, non-IBC denom", |
invalid
is not self-explanatory here
error error | ||
}{ | ||
{ | ||
"invalid denom, expect fail", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"invalid denom, expect fail", | |
"non-IBC denom, expect fail", |
error error | ||
}{ | ||
{ | ||
"invalid denom, expect fail", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"invalid denom, expect fail", | |
"non-Gravity denom, expect fail", |
contracts/src/CroBridge.sol
Outdated
@@ -0,0 +1,14 @@ | |||
pragma solidity ^0.6.11; |
There was a problem hiding this comment.
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/
.
There was a problem hiding this 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 Report
@@ 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
Continue to review full report at Codecov.
|
c14207e
to
0602ee4
Compare
0602ee4
to
265dd83
Compare
265dd83
to
62858c7
Compare
support ibc log event handler
PR Checklist:
make
)make test
)go fmt
)golangci-lint run
)go list -json -m all | nancy sleuth
)Thank you for your code, it's appreciated! :)