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

chore: use Denom type in transfer/simulation. #6522

Merged
merged 5 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions modules/apps/transfer/simulation/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@ import (

"github.com/cosmos/cosmos-sdk/types/kv"

internaltypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/internal/types"
"github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
)

// NewDecodeStore returns a decoder function closure that unmarshals the KVPair's
// Value to the corresponding DenomTrace type.
// Value to the corresponding Denom type.
func NewDecodeStore() func(kvA, kvB kv.Pair) string {
return func(kvA, kvB kv.Pair) string {
switch {
case bytes.Equal(kvA.Key[:1], types.PortKey):
return fmt.Sprintf("Port A: %s\nPort B: %s", string(kvA.Value), string(kvB.Value))

case bytes.Equal(kvA.Key[:1], types.DenomTraceKey):
var denomTraceA, denomTraceB internaltypes.DenomTrace
types.ModuleCdc.MustUnmarshal(kvA.Value, &denomTraceA)
types.ModuleCdc.MustUnmarshal(kvB.Value, &denomTraceB)
return fmt.Sprintf("DenomTrace A: %s\nDenomTrace B: %s", denomTraceA.IBCDenom(), denomTraceB.IBCDenom())
case bytes.Equal(kvA.Key[:1], types.DenomKey):
var denomA, denomB types.Denom
types.ModuleCdc.MustUnmarshal(kvA.Value, &denomA)
types.ModuleCdc.MustUnmarshal(kvB.Value, &denomB)
return fmt.Sprintf("Denom A: %s\nDenom B: %s", denomA.IBCDenom(), denomB.IBCDenom())

default:
panic(fmt.Errorf("invalid %s key prefix %X", types.ModuleName, kvA.Key[:1]))
Expand Down
13 changes: 4 additions & 9 deletions modules/apps/transfer/simulation/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,13 @@ import (

"github.com/cosmos/cosmos-sdk/types/kv"

internaltypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/internal/types"
"github.com/cosmos/ibc-go/v8/modules/apps/transfer/simulation"
"github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
)

func TestDecodeStore(t *testing.T) {
dec := simulation.NewDecodeStore()

trace := internaltypes.DenomTrace{
BaseDenom: "uatom",
Path: "transfer/channelToA",
}
denom := types.NewDenom("uatom", types.NewTrace("transfer", "channelToA"))

kvPairs := kv.Pairs{
Pairs: []kv.Pair{
Expand All @@ -28,8 +23,8 @@ func TestDecodeStore(t *testing.T) {
Value: []byte(types.PortID),
},
{
Key: types.DenomTraceKey,
Value: types.ModuleCdc.MustMarshal(&trace),
Key: types.DenomKey,
Value: types.ModuleCdc.MustMarshal(&denom),
},
{
Key: []byte{0x99},
Expand All @@ -42,7 +37,7 @@ func TestDecodeStore(t *testing.T) {
expectedLog string
}{
{"PortID", fmt.Sprintf("Port A: %s\nPort B: %s", types.PortID, types.PortID)},
{"DenomTrace", fmt.Sprintf("DenomTrace A: %s\nDenomTrace B: %s", trace.IBCDenom(), trace.IBCDenom())},
{"Denom", fmt.Sprintf("Denom A: %s\nDenom B: %s", denom.IBCDenom(), denom.IBCDenom())},
{"other", ""},
}

Expand Down
Loading