Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Oct 23, 2024
1 parent f67ea48 commit 98efdc6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 33 deletions.
16 changes: 8 additions & 8 deletions integration_tests/test_ibc_rly.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ def coin_spent(spender, amt, denom):
def distribute_fee(receiver, fee):
return {
"receiver": receiver,
"fee": keccak(text=fee),
"fee": fee,
}


def fungible(dst, src, amt, denom):
return {
"receiver": dst,
"sender": src,
"denom": keccak(text=denom),
"denom": denom,
"amount": amt,
}

Expand All @@ -123,7 +123,7 @@ def burn(burner, amt, denom):

def recv_packet(seq, src, dst, amt, denom):
return {
"packetSequence": f"{seq}",
"packetSequence": seq,
"packetSrcPort": keccak(text="transfer"),
"packetSrcChannel": keccak(text=channel),
"packetSrcPortInfo": "transfer",
Expand All @@ -143,7 +143,7 @@ def recv_packet(seq, src, dst, amt, denom):

def acknowledge_packet(seq):
return {
"packetSequence": f"{seq}",
"packetSequence": seq,
"packetSrcPort": keccak(text="transfer"),
"packetSrcChannel": keccak(text=channel),
"packetSrcPortInfo": "transfer",
Expand All @@ -156,13 +156,13 @@ def acknowledge_packet(seq):

def denom_trace(denom):
return {
"denom": keccak(text=denom),
"denom": denom,
}


def write_ack(seq, src, dst, amt, denom):
return {
"packetSequence": f"{seq}",
"packetSequence": seq,
"packetSrcPort": keccak(text="transfer"),
"packetSrcChannel": keccak(text=channel),
"packetSrcPortInfo": "transfer",
Expand Down Expand Up @@ -226,7 +226,7 @@ def filter_logs_since(w3, start, name, seq):
{
"fromBlock": start,
"address": [CONTRACT],
"topics": [topic, "0x" + keccak(text=f"{seq}").hex()],
"topics": [topic, "0x{:064x}".format(seq)],
}
)

Expand All @@ -244,7 +244,7 @@ def test_ibc(ibc):
relayer = to_checksum_address(bech32_to_eth(relayer0))
cronos_addr = module_address("cronos")
transfer_addr = module_address("transfer")
seq = get_send_packet_seq(chainmain_cli)
seq = int(get_send_packet_seq(chainmain_cli))
expected = [
recv_packet(seq, relayer0, cronos_signer2, src_amount, src_denom),
denom_trace(denom),
Expand Down
5 changes: 4 additions & 1 deletion x/cronos/events/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,15 @@ func makeFilter(
func (desc *EventDescriptor) ConvertEvent(
event []abci.EventAttribute,
valueDecoders ValueDecoders,
replaceAttrs map[string]string,
) (*ethtypes.Log, error) {
attrs := make(map[string]string, len(event))
for _, attr := range event {
attrs[toUnderScore(attr.Key)] = attr.Value
}

for k, v := range replaceAttrs {
attrs[k] = attrs[v]
}

Check warning on line 73 in x/cronos/events/event.go

View check run for this annotation

Codecov / codecov/patch

x/cronos/events/event.go#L71-L73

Added lines #L71 - L73 were not covered by tests

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism
filterQuery, err := makeFilter(valueDecoders, attrs, desc.indexed, true)
if err != nil {
return nil, err
Expand Down
46 changes: 24 additions & 22 deletions x/cronos/events/events.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package events

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
ibcfeetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types"
Expand All @@ -19,24 +17,24 @@ var (
RelayerEvents map[string]*EventDescriptor
IcaEvents map[string]*EventDescriptor
RelayerValueDecoders = ValueDecoders{
channeltypes.AttributeKeyDataHex: ConvertPacketData,
transfertypes.AttributeKeyAmount: ConvertAmount,
banktypes.AttributeKeyRecipient: ConvertAccAddressFromBech32,
banktypes.AttributeKeySpender: ConvertAccAddressFromBech32,
banktypes.AttributeKeyReceiver: ConvertAccAddressFromBech32,
banktypes.AttributeKeySender: ConvertAccAddressFromBech32,
banktypes.AttributeKeyMinter: ConvertAccAddressFromBech32,
banktypes.AttributeKeyBurner: ConvertAccAddressFromBech32,
channeltypes.AttributeKeySequence: ConvertUint64,
channeltypes.AttributeKeySrcPort: ReturnStringAsIs,
fmt.Sprintf("%s_info", channeltypes.AttributeKeySrcPort): ReturnStringAsIs,
channeltypes.AttributeKeySrcChannel: ReturnStringAsIs,
fmt.Sprintf("%s_info", channeltypes.AttributeKeySrcChannel): ReturnStringAsIs,
channeltypes.AttributeKeyDstPort: ReturnStringAsIs,
channeltypes.AttributeKeyDstChannel: ReturnStringAsIs,
channeltypes.AttributeKeyConnectionID: ReturnStringAsIs,
ibcfeetypes.AttributeKeyFee: ReturnStringAsIs,
transfertypes.AttributeKeyDenom: ReturnStringAsIs,
channeltypes.AttributeKeyDataHex: ConvertPacketData,
transfertypes.AttributeKeyAmount: ConvertAmount,
banktypes.AttributeKeyRecipient: ConvertAccAddressFromBech32,
banktypes.AttributeKeySpender: ConvertAccAddressFromBech32,
banktypes.AttributeKeyReceiver: ConvertAccAddressFromBech32,
banktypes.AttributeKeySender: ConvertAccAddressFromBech32,
banktypes.AttributeKeyMinter: ConvertAccAddressFromBech32,
banktypes.AttributeKeyBurner: ConvertAccAddressFromBech32,
channeltypes.AttributeKeySequence: ConvertUint64,
channeltypes.AttributeKeySrcPort: ReturnStringAsIs,
cronoseventstypes.AttributeKeySrcPortInfo: ReturnStringAsIs,
channeltypes.AttributeKeySrcChannel: ReturnStringAsIs,
cronoseventstypes.AttributeKeySrcChannelInfo: ReturnStringAsIs,
channeltypes.AttributeKeyDstPort: ReturnStringAsIs,
channeltypes.AttributeKeyDstChannel: ReturnStringAsIs,
channeltypes.AttributeKeyConnectionID: ReturnStringAsIs,
ibcfeetypes.AttributeKeyFee: ReturnStringAsIs,
transfertypes.AttributeKeyDenom: ReturnStringAsIs,
}
IcaValueDecoders = ValueDecoders{
cronoseventstypes.AttributeKeySeq: ConvertUint64,
Expand All @@ -63,13 +61,17 @@ func RelayerConvertEvent(event sdk.Event) (*ethtypes.Log, error) {
if !ok {
return nil, nil
}
return desc.ConvertEvent(event.Attributes, RelayerValueDecoders)
replaceAttrs := map[string]string{
cronoseventstypes.AttributeKeySrcPortInfo: channeltypes.AttributeKeySrcPort,
cronoseventstypes.AttributeKeySrcChannelInfo: channeltypes.AttributeKeySrcChannel,
}
return desc.ConvertEvent(event.Attributes, RelayerValueDecoders, replaceAttrs)

Check warning on line 68 in x/cronos/events/events.go

View check run for this annotation

Codecov / codecov/patch

x/cronos/events/events.go#L64-L68

Added lines #L64 - L68 were not covered by tests
}

func IcaConvertEvent(event sdk.Event) (*ethtypes.Log, error) {
desc, ok := IcaEvents[event.Type]
if !ok {
return nil, nil
}
return desc.ConvertEvent(event.Attributes, IcaValueDecoders)
return desc.ConvertEvent(event.Attributes, IcaValueDecoders, map[string]string{})

Check warning on line 76 in x/cronos/events/events.go

View check run for this annotation

Codecov / codecov/patch

x/cronos/events/events.go#L76

Added line #L76 was not covered by tests
}
6 changes: 4 additions & 2 deletions x/cronos/events/types/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

const (
EventTypeSubmitMsgsResult = "submit_msgs_result"
AttributeKeySeq = "seq"
EventTypeSubmitMsgsResult = "submit_msgs_result"
AttributeKeySeq = "seq"
AttributeKeySrcPortInfo = "packet_src_port_info"
AttributeKeySrcChannelInfo = "packet_src_channel_info"
)

0 comments on commit 98efdc6

Please sign in to comment.