Skip to content

Commit

Permalink
temp test
Browse files Browse the repository at this point in the history
  • Loading branch information
Olshansk committed May 3, 2024
1 parent e5ecf61 commit 3d35b88
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions temp/temp_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package temp

import (
"fmt"
"testing"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/types/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/stretchr/testify/require"
)

func TestTxSerializationWithUpdateParams(t *testing.T) {
// Initialize the codec registry
registry := types.NewInterfaceRegistry()
authtypes.RegisterInterfaces(registry)
cdc := codec.NewProtoCodec(registry)

// Construct the message
msg := &authtypes.MsgUpdateParams{
// Assuming there are fields like Creator and Params in MsgUpdateParams,
// fill them accordingly with dummy or test values.
Authority: "cosmos1...",
Params: authtypes.Params{MaxMemoCharacters: 100},
}

// Create an Any type for the message
anyMsg, err := types.NewAnyWithValue(msg)
require.NoError(t, err)

// Construct the TxBody with the message
txBody := &tx.TxBody{
Messages: []*types.Any{anyMsg},
}

// Serialize the TxBody
bz, err := cdc.MarshalJSON(txBody)

fmt.Println(string(bz))
require.NoError(t, err)

// Deserialize to verify correctness
var deserialized tx.TxBody
err = cdc.Unmarshal(bz, &deserialized)
require.NoError(t, err)

// Check if the original message is equal to the deserialized message
require.Equal(t, txBody, &deserialized)
}

0 comments on commit 3d35b88

Please sign in to comment.