-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |