Skip to content

Commit

Permalink
fix(auxiliary)!: unpack interfaces with pointer (#2165)
Browse files Browse the repository at this point in the history
Co-authored-by: Christian Gorenflo <[email protected]>
  • Loading branch information
haiyizxx and cgorenflo authored Jul 25, 2024
1 parent 4dcedbb commit 8d22714
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 3 additions & 3 deletions x/auxiliary/types/msg_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ func (m BatchRequest) GetSigners() []sdk.AccAddress {
}

// UnpackInterfaces implements UnpackInterfacesMessage
func (m BatchRequest) UnpackInterfaces(unpacker cdctypes.AnyUnpacker) error {
for _, msg := range m.Messages {
func (m *BatchRequest) UnpackInterfaces(unpacker cdctypes.AnyUnpacker) error {
for i := range m.Messages {
var sdkMsg sdk.Msg
if err := unpacker.UnpackAny(&msg, &sdkMsg); err != nil {
if err := unpacker.UnpackAny(&m.Messages[i], &sdkMsg); err != nil {
return err
}
}
Expand Down
19 changes: 19 additions & 0 deletions x/auxiliary/types/msg_batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/assert"

"github.com/axelarnetwork/axelar-core/app"
"github.com/axelarnetwork/axelar-core/testutils/rand"
"github.com/axelarnetwork/axelar-core/x/auxiliary/types"
evmtypes "github.com/axelarnetwork/axelar-core/x/evm/types"
"github.com/axelarnetwork/utils/funcs"
)

func TestBatchRequest_ValidateBasic(t *testing.T) {
Expand All @@ -30,4 +32,21 @@ func TestBatchRequest_ValidateBasic(t *testing.T) {

assert.ErrorContains(t, message.ValidateBasic(), "message signer mismatch")
})

t.Run("should unwrap messages", func(t *testing.T) {
cdc := app.MakeEncodingConfig().Codec

sender := rand.AccAddr()
messages := []sdk.Msg{
evmtypes.NewLinkRequest(sender, rand.NormalizedStr(5), rand.NormalizedStr(5), rand.NormalizedStr(5), rand.NormalizedStr(5)),
evmtypes.NewLinkRequest(sender, rand.NormalizedStr(5), rand.NormalizedStr(5), rand.NormalizedStr(5), rand.NormalizedStr(5)),
}
batch := types.NewBatchRequest(sender, messages)

bz := funcs.Must(batch.Marshal())
var unmarshaledBatch types.BatchRequest
funcs.MustNoErr(cdc.Unmarshal(bz, &unmarshaledBatch))

assert.Equal(t, messages, unmarshaledBatch.UnwrapMessages())
})
}

0 comments on commit 8d22714

Please sign in to comment.