Skip to content

Commit

Permalink
test(stf/mock): Unmarshal with knowing the message type (#21178)
Browse files Browse the repository at this point in the history
  • Loading branch information
hieuvubk authored Aug 7, 2024
1 parent 641f964 commit 5b7d8b6
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions server/v2/stf/mock/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"crypto/sha256"
"encoding/json"
"errors"
"reflect"

"github.com/cosmos/gogoproto/proto"
gogoproto "github.com/cosmos/gogoproto/types"

"cosmossdk.io/core/transaction"
Expand Down Expand Up @@ -69,7 +71,12 @@ func (t *Tx) Decode(b []byte) {
if err != nil {
panic(err)
}
var msg transaction.Msg
msgName, err := gogoproto.AnyMessageName(rawTx.Msg)
msgType := proto.MessageType(msgName).Elem()
if err != nil {
panic(err)
}
msg := reflect.New(msgType).Interface().(proto.Message)
if err := gogoproto.UnmarshalAny(rawTx.Msg, msg); err != nil {
panic(err)
}
Expand All @@ -84,7 +91,12 @@ func (t *Tx) DecodeJSON(b []byte) {
if err != nil {
panic(err)
}
var msg transaction.Msg
msgName, err := gogoproto.AnyMessageName(rawTx.Msg)
msgType := proto.MessageType(msgName).Elem()
if err != nil {
panic(err)
}
msg := reflect.New(msgType).Interface().(proto.Message)
if err := gogoproto.UnmarshalAny(rawTx.Msg, msg); err != nil {
panic(err)
}
Expand Down

0 comments on commit 5b7d8b6

Please sign in to comment.