mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 00:05:18 +00:00
feat(evmutil)!: emit events on MsgConvertCosmosCoinToERC20 (#1604)
* better error message for mismatched events * rename evm asset conversion event types * emit message event for MsgConvertCosmosCoinToERC20 * emit convert_cosmos_coin_to_erc20 event
This commit is contained in:
parent
741f1e42ee
commit
fd83da7a05
@ -41,9 +41,13 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
|||||||
- (evmutil) [#1591] & [#1596] Configure module to support deploying ERC20KavaWrappedCosmosCoin contracts
|
- (evmutil) [#1591] & [#1596] Configure module to support deploying ERC20KavaWrappedCosmosCoin contracts
|
||||||
- (evmutil) [#1598] Track deployed ERC20 contract addresses for representing cosmos coins in module state
|
- (evmutil) [#1598] Track deployed ERC20 contract addresses for representing cosmos coins in module state
|
||||||
- (evmutil) [#1603] Add MsgConvertCosmosCoinToERC20 for converting an sdk.Coin to an ERC20 in the EVM
|
- (evmutil) [#1603] Add MsgConvertCosmosCoinToERC20 for converting an sdk.Coin to an ERC20 in the EVM
|
||||||
|
- (evmutil) [#1604] Emit events for MsgConvertCosmosCoinToERC20: `message` & `convert_cosmos_coin_to_erc20`
|
||||||
|
|
||||||
### Client Breaking
|
### Client Breaking
|
||||||
- (evmutil) [#1603] Renamed error `ErrConversionNotEnabled` to `ErrEVMConversionNotEnabled`
|
- (evmutil) [#1603] Renamed error `ErrConversionNotEnabled` to `ErrEVMConversionNotEnabled`
|
||||||
|
- (evmutil) [#1604] Renamed event types
|
||||||
|
- `convert_erc20_to_coin` -> `convert_evm_erc20_to_coin`
|
||||||
|
- `convert_coin_to_erc20` -> `convert_evm_erc20_from_coin`
|
||||||
|
|
||||||
## [v0.23.0]
|
## [v0.23.0]
|
||||||
|
|
||||||
@ -246,6 +250,7 @@ the [changelog](https://github.com/cosmos/cosmos-sdk/blob/v0.38.4/CHANGELOG.md).
|
|||||||
- [#257](https://github.com/Kava-Labs/kava/pulls/257) Include scripts to run
|
- [#257](https://github.com/Kava-Labs/kava/pulls/257) Include scripts to run
|
||||||
large-scale simulations remotely using aws-batch
|
large-scale simulations remotely using aws-batch
|
||||||
|
|
||||||
|
[#1604]: https://github.com/Kava-Labs/kava/pull/1604
|
||||||
[#1603]: https://github.com/Kava-Labs/kava/pull/1603
|
[#1603]: https://github.com/Kava-Labs/kava/pull/1603
|
||||||
[#1598]: https://github.com/Kava-Labs/kava/pull/1598
|
[#1598]: https://github.com/Kava-Labs/kava/pull/1598
|
||||||
[#1596]: https://github.com/Kava-Labs/kava/pull/1596
|
[#1596]: https://github.com/Kava-Labs/kava/pull/1596
|
||||||
|
@ -44,7 +44,13 @@ func (k *Keeper) ConvertCosmosCoinToERC20(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO emit conversion event
|
ctx.EventManager().EmitEvent(sdk.NewEvent(
|
||||||
|
types.EventTypeConvertCosmosCoinToERC20,
|
||||||
|
sdk.NewAttribute(types.AttributeKeyInitiator, initiator.String()),
|
||||||
|
sdk.NewAttribute(types.AttributeKeyReceiver, receiver.String()),
|
||||||
|
sdk.NewAttribute(types.AttributeKeyERC20Address, contractAddress.Hex()),
|
||||||
|
sdk.NewAttribute(types.AttributeKeyAmount, amount.String()),
|
||||||
|
))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -119,6 +119,17 @@ func (suite *ConversionCosmosNativeSuite) TestConvertCosmosCoinToERC20() {
|
|||||||
checkBalanceOf(receiver1, amount.Amount)
|
checkBalanceOf(receiver1, amount.Amount)
|
||||||
// total supply of erc20 should have increased
|
// total supply of erc20 should have increased
|
||||||
checkTotalSupply(amount.Amount)
|
checkTotalSupply(amount.Amount)
|
||||||
|
|
||||||
|
// event should be emitted
|
||||||
|
suite.EventsContains(suite.GetEvents(),
|
||||||
|
sdk.NewEvent(
|
||||||
|
types.EventTypeConvertCosmosCoinToERC20,
|
||||||
|
sdk.NewAttribute(types.AttributeKeyInitiator, initiator.String()),
|
||||||
|
sdk.NewAttribute(types.AttributeKeyReceiver, receiver1.String()),
|
||||||
|
sdk.NewAttribute(types.AttributeKeyERC20Address, contractAddress.Hex()),
|
||||||
|
sdk.NewAttribute(types.AttributeKeyAmount, amount.String()),
|
||||||
|
),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
suite.Run("2nd deploy uses same contract", func() {
|
suite.Run("2nd deploy uses same contract", func() {
|
||||||
@ -147,5 +158,16 @@ func (suite *ConversionCosmosNativeSuite) TestConvertCosmosCoinToERC20() {
|
|||||||
checkBalanceOf(receiver2, amount.Amount)
|
checkBalanceOf(receiver2, amount.Amount)
|
||||||
// total supply of erc20 should have increased
|
// total supply of erc20 should have increased
|
||||||
checkTotalSupply(amount.Amount.MulRaw(2))
|
checkTotalSupply(amount.Amount.MulRaw(2))
|
||||||
|
|
||||||
|
// event should be emitted
|
||||||
|
suite.EventsContains(suite.GetEvents(),
|
||||||
|
sdk.NewEvent(
|
||||||
|
types.EventTypeConvertCosmosCoinToERC20,
|
||||||
|
sdk.NewAttribute(types.AttributeKeyInitiator, initiator.String()),
|
||||||
|
sdk.NewAttribute(types.AttributeKeyReceiver, receiver2.String()),
|
||||||
|
sdk.NewAttribute(types.AttributeKeyERC20Address, contractAddress.Hex()),
|
||||||
|
sdk.NewAttribute(types.AttributeKeyAmount, amount.String()),
|
||||||
|
),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,13 @@ func (s msgServer) ConvertCosmosCoinToERC20(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: emit message event
|
ctx.EventManager().EmitEvent(
|
||||||
|
sdk.NewEvent(
|
||||||
|
sdk.EventTypeMessage,
|
||||||
|
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
|
||||||
|
sdk.NewAttribute(sdk.AttributeKeySender, msg.Initiator),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
return &types.MsgConvertCosmosCoinToERC20Response{}, nil
|
return &types.MsgConvertCosmosCoinToERC20Response{}, nil
|
||||||
}
|
}
|
||||||
|
@ -388,7 +388,6 @@ func (suite *MsgServerSuite) TestConvertCosmosCoinToERC20_InitialContractDeploy(
|
|||||||
|
|
||||||
// verify success
|
// verify success
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
suite.Commit()
|
|
||||||
|
|
||||||
initiator := sdk.MustAccAddressFromBech32(tc.msg.Initiator)
|
initiator := sdk.MustAccAddressFromBech32(tc.msg.Initiator)
|
||||||
receiver := testutil.MustNewInternalEVMAddressFromString(tc.msg.Receiver)
|
receiver := testutil.MustNewInternalEVMAddressFromString(tc.msg.Receiver)
|
||||||
@ -417,6 +416,24 @@ func (suite *MsgServerSuite) TestConvertCosmosCoinToERC20_InitialContractDeploy(
|
|||||||
erc20Balance, err := suite.Keeper.QueryERC20BalanceOf(suite.Ctx, contractAddress, receiver)
|
erc20Balance, err := suite.Keeper.QueryERC20BalanceOf(suite.Ctx, contractAddress, receiver)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
suite.Equal(tc.amountConverted.BigInt(), erc20Balance, "unexpected erc20 balance for receiver")
|
suite.Equal(tc.amountConverted.BigInt(), erc20Balance, "unexpected erc20 balance for receiver")
|
||||||
|
|
||||||
|
// msg server event
|
||||||
|
suite.EventsContains(suite.GetEvents(),
|
||||||
|
sdk.NewEvent(
|
||||||
|
sdk.EventTypeMessage,
|
||||||
|
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
|
||||||
|
sdk.NewAttribute(sdk.AttributeKeySender, initiator.String()),
|
||||||
|
))
|
||||||
|
|
||||||
|
// keeper event
|
||||||
|
suite.EventsContains(suite.GetEvents(),
|
||||||
|
sdk.NewEvent(
|
||||||
|
types.EventTypeConvertCosmosCoinToERC20,
|
||||||
|
sdk.NewAttribute(types.AttributeKeyInitiator, initiator.String()),
|
||||||
|
sdk.NewAttribute(types.AttributeKeyReceiver, receiver.String()),
|
||||||
|
sdk.NewAttribute(types.AttributeKeyERC20Address, contractAddress.Hex()),
|
||||||
|
sdk.NewAttribute(types.AttributeKeyAmount, tc.msg.Amount.String()),
|
||||||
|
))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,22 +10,33 @@ The evmutil module emits the following events:
|
|||||||
|
|
||||||
### MsgConvertERC20ToCoin
|
### MsgConvertERC20ToCoin
|
||||||
|
|
||||||
| Type | Attribute Key | Attribute Value |
|
| Type | Attribute Key | Attribute Value |
|
||||||
| --------------------- | ------------- | ------------------ |
|
| ------------------------- | ------------- | ------------------ |
|
||||||
| convert_erc20_to_coin | erc20_address | `{erc20 address}` |
|
| convert_evm_erc20_to_coin | initiator | `{initiator}` |
|
||||||
| convert_erc20_to_coin | initiator | `{initiator}` |
|
| convert_evm_erc20_to_coin | receiver | `{receiver}` |
|
||||||
| convert_erc20_to_coin | receiver | `{receiver}` |
|
| convert_evm_erc20_to_coin | erc20_address | `{erc20_address}` |
|
||||||
| convert_erc20_to_coin | amount | `{amount}` |
|
| convert_evm_erc20_to_coin | amount | `{amount}` |
|
||||||
| message | module | evmutil |
|
| message | module | evmutil |
|
||||||
| message | sender | {'sender address}' |
|
| message | sender | {'sender address'} |
|
||||||
|
|
||||||
### MsgConvertCoinToERC20
|
### MsgConvertCoinToERC20
|
||||||
|
|
||||||
| Type | Attribute Key | Attribute Value |
|
| Type | Attribute Key | Attribute Value |
|
||||||
| --------------------- | ------------- | ------------------ |
|
| --------------------------- | ------------- | ------------------ |
|
||||||
| convert_coin_to_erc20 | initiator | `{initiator}` |
|
| convert_evm_erc20_from_coin | initiator | `{initiator}` |
|
||||||
| convert_coin_to_erc20 | receiver | `{receiver}` |
|
| convert_evm_erc20_from_coin | receiver | `{receiver}` |
|
||||||
| convert_coin_to_erc20 | erc20_address | `{erc20_address}` |
|
| convert_evm_erc20_from_coin | erc20_address | `{erc20_address}` |
|
||||||
| convert_coin_to_erc20 | amount | `{amount}` |
|
| convert_evm_erc20_from_coin | amount | `{amount}` |
|
||||||
| message | module | evmutil |
|
| message | module | evmutil |
|
||||||
| message | sender | {'sender address}' |
|
| message | sender | {'sender address'} |
|
||||||
|
|
||||||
|
### MsgConvertCosmosCoinToERC20
|
||||||
|
|
||||||
|
| Type | Attribute Key | Attribute Value |
|
||||||
|
| ---------------------------- | ------------- | ------------------ |
|
||||||
|
| convert_cosmos_coin_to_erc20 | initiator | `{initiator}` |
|
||||||
|
| convert_cosmos_coin_to_erc20 | receiver | `{receiver}` |
|
||||||
|
| convert_cosmos_coin_to_erc20 | erc20_address | `{erc20_address}` |
|
||||||
|
| convert_cosmos_coin_to_erc20 | amount | `{amount}` |
|
||||||
|
| message | module | evmutil |
|
||||||
|
| message | sender | {'sender address'} |
|
||||||
|
@ -363,15 +363,25 @@ func (suite *Suite) GetEvents() sdk.Events {
|
|||||||
// EventsContains asserts that the expected event is in the provided events
|
// EventsContains asserts that the expected event is in the provided events
|
||||||
func (suite *Suite) EventsContains(events sdk.Events, expectedEvent sdk.Event) {
|
func (suite *Suite) EventsContains(events sdk.Events, expectedEvent sdk.Event) {
|
||||||
foundMatch := false
|
foundMatch := false
|
||||||
|
var possibleFailedMatch []sdk.Attribute
|
||||||
|
expectedAttrs := attrsToMap(expectedEvent.Attributes)
|
||||||
|
|
||||||
for _, event := range events {
|
for _, event := range events {
|
||||||
if event.Type == expectedEvent.Type {
|
if event.Type == expectedEvent.Type {
|
||||||
if reflect.DeepEqual(attrsToMap(expectedEvent.Attributes), attrsToMap(event.Attributes)) {
|
attrs := attrsToMap(event.Attributes)
|
||||||
|
if reflect.DeepEqual(expectedAttrs, attrs) {
|
||||||
foundMatch = true
|
foundMatch = true
|
||||||
|
} else {
|
||||||
|
possibleFailedMatch = attrs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suite.Truef(foundMatch, "event of type %s not found or did not match", expectedEvent.Type)
|
if !foundMatch && possibleFailedMatch != nil {
|
||||||
|
suite.ElementsMatch(expectedAttrs, possibleFailedMatch, "unmatched attributes on event of type %s", expectedEvent.Type)
|
||||||
|
} else {
|
||||||
|
suite.Truef(foundMatch, "event of type %s not found", expectedEvent.Type)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// EventsDoNotContain asserts that the event is **not** is in the provided events
|
// EventsDoNotContain asserts that the event is **not** is in the provided events
|
||||||
|
@ -5,8 +5,10 @@ const (
|
|||||||
AttributeValueCategory = ModuleName
|
AttributeValueCategory = ModuleName
|
||||||
|
|
||||||
// Event Types
|
// Event Types
|
||||||
EventTypeConvertERC20ToCoin = "convert_erc20_to_coin"
|
EventTypeConvertERC20ToCoin = "convert_evm_erc20_to_coin"
|
||||||
EventTypeConvertCoinToERC20 = "convert_coin_to_erc20"
|
EventTypeConvertCoinToERC20 = "convert_evm_erc20_from_coin"
|
||||||
|
|
||||||
|
EventTypeConvertCosmosCoinToERC20 = "convert_cosmos_coin_to_erc20"
|
||||||
|
|
||||||
// Event Attributes - Common
|
// Event Attributes - Common
|
||||||
AttributeKeyReceiver = "receiver"
|
AttributeKeyReceiver = "receiver"
|
||||||
|
Loading…
Reference in New Issue
Block a user