diff --git a/go.mod b/go.mod index 4f485ad476..303118221f 100644 --- a/go.mod +++ b/go.mod @@ -45,6 +45,7 @@ require ( google.golang.org/grpc v1.63.2 google.golang.org/protobuf v1.34.0 gopkg.in/yaml.v2 v2.4.0 + sigs.k8s.io/yaml v1.4.0 ) require ( @@ -205,7 +206,6 @@ require ( gotest.tools/v3 v3.5.1 // indirect nhooyr.io/websocket v1.8.10 // indirect pgregory.net/rapid v1.1.0 // indirect - sigs.k8s.io/yaml v1.4.0 // indirect ) replace ( diff --git a/x/attribute/keeper/keeper.go b/x/attribute/keeper/keeper.go index 3858763a54..4808d8d77c 100644 --- a/x/attribute/keeper/keeper.go +++ b/x/attribute/keeper/keeper.go @@ -102,7 +102,7 @@ func (k Keeper) IterateRecords(ctx sdk.Context, prefix []byte, handle Handler) e record := types.Attribute{} // get proto objects for legacy prefix with legacy amino codec. if bytes.Equal(types.AttributeKeyPrefixAmino, prefix) { - if err := types.ModuleCdc.Unmarshal(iterator.Value(), &record); err != nil { + if err := k.cdc.Unmarshal(iterator.Value(), &record); err != nil { return err } } else { diff --git a/x/attribute/simulation/operations_test.go b/x/attribute/simulation/operations_test.go index f807c6948f..d180a4e57f 100644 --- a/x/attribute/simulation/operations_test.go +++ b/x/attribute/simulation/operations_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/suite" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -25,6 +26,7 @@ type SimTestSuite struct { ctx sdk.Context app *app.App + cdc codec.BinaryCodec } func TestSimTestSuite(t *testing.T) { @@ -34,6 +36,7 @@ func TestSimTestSuite(t *testing.T) { func (s *SimTestSuite) SetupTest() { s.app = app.Setup(s.T()) s.ctx = s.app.BaseApp.NewContext(false) + s.cdc = s.app.GetEncodingConfig().Marshaler } // LogOperationMsg logs all fields of the provided operationMsg. @@ -137,7 +140,7 @@ func (s *SimTestSuite) TestSimulateMsgAddAttribute() { s.LogOperationMsg(operationMsg) var msg types.MsgAddAttributeRequest - s.Require().NoError(types.ModuleCdc.Unmarshal(operationMsg.Msg, &msg), "UnmarshalJSON(operationMsg.Msg)") + s.Require().NoError(s.cdc.Unmarshal(operationMsg.Msg, &msg), "UnmarshalJSON(operationMsg.Msg)") s.Assert().True(operationMsg.OK, "operationMsg.OK") s.Assert().Equal("cosmos1tnh2q55v8wyygtt9srz5safamzdengsnqeycj3", msg.Account, "msg.Account") @@ -169,7 +172,7 @@ func (s *SimTestSuite) TestSimulateMsgUpdateAttribute() { s.LogOperationMsg(operationMsg) var msg types.MsgUpdateAttributeRequest - s.Require().NoError(types.ModuleCdc.Unmarshal(operationMsg.Msg, &msg), "UnmarshalJSON(operationMsg.Msg)") + s.Require().NoError(s.cdc.Unmarshal(operationMsg.Msg, &msg), "UnmarshalJSON(operationMsg.Msg)") s.Assert().True(operationMsg.OK, "operationMsg.OK") s.Assert().Equal(sdk.MsgTypeURL(&msg), operationMsg.Name, "operationMsg.Name") @@ -199,7 +202,7 @@ func (s *SimTestSuite) TestSimulateMsgDeleteAttribute() { s.LogOperationMsg(operationMsg) var msg types.MsgDeleteAttributeRequest - s.Require().NoError(types.ModuleCdc.Unmarshal(operationMsg.Msg, &msg), "UnmarshalJSON(operationMsg.Msg)") + s.Require().NoError(s.cdc.Unmarshal(operationMsg.Msg, &msg), "UnmarshalJSON(operationMsg.Msg)") s.Assert().True(operationMsg.OK, "operationMsg.OK") s.Assert().Equal(sdk.MsgTypeURL(&msg), operationMsg.Name, "operationMsg.Name") @@ -229,7 +232,7 @@ func (s *SimTestSuite) TestSimulateMsgDeleteDistinctAttribute() { s.LogOperationMsg(operationMsg) var msg types.MsgDeleteDistinctAttributeRequest - s.Require().NoError(types.ModuleCdc.Unmarshal(operationMsg.Msg, &msg), "UnmarshalJSON(operationMsg.Msg)") + s.Require().NoError(s.cdc.Unmarshal(operationMsg.Msg, &msg), "UnmarshalJSON(operationMsg.Msg)") s.Assert().True(operationMsg.OK, "operationMsg.OK") s.Assert().Equal(sdk.MsgTypeURL(&msg), operationMsg.Name, "operationMsg.Name") @@ -253,7 +256,7 @@ func (s *SimTestSuite) TestSimulateMsgSetAccountData() { s.LogOperationMsg(operationMsg) var msg types.MsgSetAccountDataRequest - s.Require().NoError(types.ModuleCdc.Unmarshal(operationMsg.Msg, &msg), "UnmarshalJSON(operationMsg.Msg)") + s.Require().NoError(s.cdc.Unmarshal(operationMsg.Msg, &msg), "UnmarshalJSON(operationMsg.Msg)") s.Assert().True(operationMsg.OK, "operationMsg.OK") s.Assert().Equal(sdk.MsgTypeURL(&msg), operationMsg.Name, "operationMsg.Name") diff --git a/x/attribute/types/codec.go b/x/attribute/types/codec.go index e76777ae49..11b25a620c 100644 --- a/x/attribute/types/codec.go +++ b/x/attribute/types/codec.go @@ -1,7 +1,6 @@ package types import ( - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" @@ -15,13 +14,3 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { registry.RegisterImplementations((*sdk.Msg)(nil), messages...) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } - -var ( - // ModuleCdc references the global x/attribute module codec. Note, the codec should - // ONLY be used in certain instances of tests and for JSON encoding as Amino is - // still used for that purpose. - // - // The actual codec used for serialization should be provided to x/attribute and - // defined at the application level. - ModuleCdc = codec.NewProtoCodec(types.NewInterfaceRegistry()) -) diff --git a/x/ibchooks/module.go b/x/ibchooks/module.go index 324da96a98..2aebeab425 100644 --- a/x/ibchooks/module.go +++ b/x/ibchooks/module.go @@ -45,9 +45,7 @@ func (AppModuleBasic) Name() string { } // RegisterLegacyAminoCodec registers the ibchooks module's types on the given LegacyAmino codec. -func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - types.RegisterCodec(cdc) -} +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {} // RegisterInterfaces registers the module's interface types func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { diff --git a/x/ibchooks/types/codec.go b/x/ibchooks/types/codec.go index e9c84035a8..11b25a620c 100644 --- a/x/ibchooks/types/codec.go +++ b/x/ibchooks/types/codec.go @@ -1,17 +1,12 @@ package types import ( - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" "github.com/cosmos/gogoproto/proto" ) -func RegisterCodec(cdc *codec.LegacyAmino) { - cdc.RegisterConcrete(&MsgEmitIBCAck{}, "provenance/ibchooks/v1/emit-ibc-ack", nil) -} - // RegisterInterfaces registers concrete implementations for this module. func RegisterInterfaces(registry types.InterfaceRegistry) { messages := make([]proto.Message, len(AllRequestMsgs)) @@ -19,17 +14,3 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { registry.RegisterImplementations((*sdk.Msg)(nil), messages...) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } - -var ( - amino = codec.NewLegacyAmino() - ModuleCdc = codec.NewProtoCodec(types.NewInterfaceRegistry()) -) - -func init() { - RegisterCodec(amino) - // Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be - // used to properly serialize MsgGrant and MsgExec instances - sdk.RegisterLegacyAminoCodec(amino) - - amino.Seal() -} diff --git a/x/marker/simulation/operations_test.go b/x/marker/simulation/operations_test.go index e4126fdfb5..89f274dd9c 100644 --- a/x/marker/simulation/operations_test.go +++ b/x/marker/simulation/operations_test.go @@ -31,6 +31,7 @@ type SimTestSuite struct { ctx sdk.Context app *app.App + cdc *codec.ProtoCodec } func TestSimTestSuite(t *testing.T) { @@ -41,6 +42,7 @@ func (s *SimTestSuite) SetupTest() { govtypes.DefaultMinDepositRatio = sdkmath.LegacyZeroDec() s.app = app.Setup(s.T()) s.ctx = s.app.BaseApp.NewContext(false) + s.cdc = codec.NewProtoCodec(s.app.GetEncodingConfig().InterfaceRegistry) } // LogOperationMsg logs all fields of the provided operationMsg. @@ -150,7 +152,7 @@ func (s *SimTestSuite) TestSimulateMsgAddMarker() { s.Require().NoError(err) var msg types.MsgAddMarkerRequest - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + s.cdc.UnmarshalJSON(operationMsg.Msg, &msg) s.Require().True(operationMsg.OK, operationMsg.String()) s.Require().Equal(sdk.MsgTypeURL(&msg), operationMsg.Name) @@ -172,7 +174,7 @@ func (s *SimTestSuite) TestSimulateMsgAddActivateFinalizeMarker() { s.Require().NoError(err) var msg types.MsgAddFinalizeActivateMarkerRequest - types.ModuleCdc.Unmarshal(operationMsg.Msg, &msg) + s.cdc.Unmarshal(operationMsg.Msg, &msg) s.Require().True(operationMsg.OK, operationMsg.String()) s.Require().Equal(sdk.MsgTypeURL(&msg), operationMsg.Name) diff --git a/x/marker/types/codec.go b/x/marker/types/codec.go index a18b8603f2..9233028c8b 100644 --- a/x/marker/types/codec.go +++ b/x/marker/types/codec.go @@ -1,7 +1,6 @@ package types import ( - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" @@ -60,13 +59,3 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } - -var ( - // ModuleCdc references the global x/account module codec. Note, the codec should - // ONLY be used in certain instances of tests and for JSON encoding as Amino is - // still used for that purpose. - // - // The actual codec used for serialization should be provided to x/account and - // defined at the application level. - ModuleCdc = codec.NewProtoCodec(types.NewInterfaceRegistry()) -) diff --git a/x/metadata/types/codec.go b/x/metadata/types/codec.go index dfdc9e63d8..d76d752bf5 100644 --- a/x/metadata/types/codec.go +++ b/x/metadata/types/codec.go @@ -1,7 +1,6 @@ package types import ( - "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" @@ -22,13 +21,3 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } - -var ( - // ModuleCdc references the global x/metadata module codec. Note, the codec should - // ONLY be used in certain instances of tests and for JSON encoding as Amino is - // still used for that purpose. - // - // The actual codec used for serialization should be provided to x/metadata and - // defined at the application level. - ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) -) diff --git a/x/metadata/types/msgs_test.go b/x/metadata/types/msgs_test.go index 44f689292e..2823cda6f9 100644 --- a/x/metadata/types/msgs_test.go +++ b/x/metadata/types/msgs_test.go @@ -8,12 +8,13 @@ import ( "github.com/google/uuid" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "gopkg.in/yaml.v2" + "sigs.k8s.io/yaml" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/provenance-io/provenance/app" "github.com/provenance-io/provenance/testutil" . "github.com/provenance-io/provenance/x/metadata/types" @@ -29,6 +30,19 @@ func getTypeName(thing interface{}) string { return rv[lastDot+1:] } +// cdc holds a fully built codec. +// Do not use this variable directly, instead use the GetCdc function to get it. +var cdc *codec.ProtoCodec + +// GetCdc returns the codec, creating it if needed. +func GetCdc(t *testing.T) *codec.ProtoCodec { + if cdc == nil { + encCfg := app.MakeTestEncodingConfig(t) + cdc = codec.NewProtoCodec(encCfg.InterfaceRegistry) + } + return cdc +} + func TestAllMsgsGetSigners(t *testing.T) { singleSignerMsgMakers := []testutil.MsgMaker{ func(signer string) sdk.Msg { @@ -82,29 +96,45 @@ func TestWriteScopeRoute(t *testing.T) { var msg = NewMsgWriteScopeRequest(*scope, []string{}, 0) require.Equal(t, sdk.MsgTypeURL(msg), "/provenance.metadata.v1.MsgWriteScopeRequest") + + expectedJSON := "{" + + "\"scope\":{" + + "\"scope_id\":\"scope1qzxcpvj6czy5g354dews3nlruxjsahhnsp\"," + + "\"specification_id\":\"scopespec1qs30c9axgrw5669ft0kffe6h9gysfe58v3\"," + + "\"owners\":[{\"address\":\"data_owner\",\"role\":\"PARTY_TYPE_OWNER\",\"optional\":false}]," + + "\"data_access\":[\"data_accessor\"]," + + "\"value_owner_address\":\"value_owner\"," + + "\"require_party_rollup\":false" + + "}," + + "\"signers\":[]," + + "\"scope_uuid\":\"\"," + + "\"spec_uuid\":\"\"," + + "\"usd_mills\":\"0\"" + + "}" + expectedYaml := `scope: - scope_id: scope1qzxcpvj6czy5g354dews3nlruxjsahhnsp - specification_id: scopespec1qs30c9axgrw5669ft0kffe6h9gysfe58v3 + data_access: + - data_accessor owners: - address: data_owner - role: 5 optional: false - data_access: - - data_accessor - value_owner_address: value_owner + role: PARTY_TYPE_OWNER require_party_rollup: false -signers: [] + scope_id: scope1qzxcpvj6czy5g354dews3nlruxjsahhnsp + specification_id: scopespec1qs30c9axgrw5669ft0kffe6h9gysfe58v3 + value_owner_address: value_owner scope_uuid: "" +signers: [] spec_uuid: "" -usdmills: 0 +usd_mills: "0" ` - bz, err := yaml.Marshal(msg) - require.NoError(t, err, "yaml.Marshal(msg)") - assert.Equal(t, expectedYaml, string(bz), "scope as yaml") + jsonBZ, err := GetCdc(t).MarshalJSON(msg) + require.NoError(t, err, "MarshalJSON(msg)") + assert.Equal(t, expectedJSON, string(jsonBZ), "scope as json") - bz, err = ModuleCdc.MarshalJSON(msg) - require.NoError(t, err, "ModuleCdc.MarshalJSON(msg)") - assert.Equal(t, "{\"scope\":{\"scope_id\":\"scope1qzxcpvj6czy5g354dews3nlruxjsahhnsp\",\"specification_id\":\"scopespec1qs30c9axgrw5669ft0kffe6h9gysfe58v3\",\"owners\":[{\"address\":\"data_owner\",\"role\":\"PARTY_TYPE_OWNER\",\"optional\":false}],\"data_access\":[\"data_accessor\"],\"value_owner_address\":\"value_owner\",\"require_party_rollup\":false},\"signers\":[],\"scope_uuid\":\"\",\"spec_uuid\":\"\",\"usd_mills\":\"0\"}", string(bz)) + yamlBZ, err := yaml.JSONToYAML(jsonBZ) + require.NoError(t, err, "yaml.JSONToYAML(jsonBZ)") + assert.Equal(t, expectedYaml, string(yamlBZ), "scope as yaml") } func TestWriteScopeValidation(t *testing.T) { @@ -721,7 +751,7 @@ func TestBindOSLocator(t *testing.T) { require.Equal(t, "/provenance.metadata.v1.MsgBindOSLocatorRequest", sdk.MsgTypeURL(bindRequestMsg)) - bz, _ := ModuleCdc.MarshalJSON(bindRequestMsg) + bz, _ := GetCdc(t).MarshalJSON(bindRequestMsg) require.Equal(t, "{\"locator\":{\"owner\":\"cosmos1sh49f6ze3vn7cdl2amh2gnc70z5mten3y08xck\",\"locator_uri\":\"http://foo.com\",\"encryption_key\":\"\"}}", string(bz)) } @@ -733,7 +763,7 @@ func TestModifyOSLocator(t *testing.T) { require.Equal(t, "/provenance.metadata.v1.MsgModifyOSLocatorRequest", sdk.MsgTypeURL(modifyRequest)) - bz, _ := ModuleCdc.MarshalJSON(modifyRequest) + bz, _ := GetCdc(t).MarshalJSON(modifyRequest) require.Equal(t, "{\"locator\":{\"owner\":\"cosmos1sh49f6ze3vn7cdl2amh2gnc70z5mten3y08xck\",\"locator_uri\":\"http://foo.com\",\"encryption_key\":\"\"}}", string(bz)) } @@ -745,7 +775,7 @@ func TestDeleteOSLocator(t *testing.T) { require.Equal(t, "/provenance.metadata.v1.MsgDeleteOSLocatorRequest", sdk.MsgTypeURL(deleteRequest)) - bz, _ := ModuleCdc.MarshalJSON(deleteRequest) + bz, _ := GetCdc(t).MarshalJSON(deleteRequest) require.Equal(t, "{\"locator\":{\"owner\":\"cosmos1sh49f6ze3vn7cdl2amh2gnc70z5mten3y08xck\",\"locator_uri\":\"http://foo.com\",\"encryption_key\":\"\"}}", string(bz)) } diff --git a/x/msgfees/types/codec.go b/x/msgfees/types/codec.go index 52abe94936..163b965b11 100644 --- a/x/msgfees/types/codec.go +++ b/x/msgfees/types/codec.go @@ -1,7 +1,6 @@ package types import ( - "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" govtypesv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" @@ -23,9 +22,3 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { &UpdateConversionFeeDenomProposal{}, ) } - -var ( - // moving to protoCodec since this is a new module and should not use the - // amino codec..someone to double verify - ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) -) diff --git a/x/name/simulation/operations_test.go b/x/name/simulation/operations_test.go index a189f1d3c4..46993252ba 100644 --- a/x/name/simulation/operations_test.go +++ b/x/name/simulation/operations_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/suite" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -24,6 +25,7 @@ type SimTestSuite struct { ctx sdk.Context app *app.App + cdc codec.BinaryCodec } func TestSimTestSuite(t *testing.T) { @@ -33,6 +35,7 @@ func TestSimTestSuite(t *testing.T) { func (s *SimTestSuite) SetupTest() { s.app = app.Setup(s.T()) s.ctx = s.app.BaseApp.NewContext(false) + s.cdc = s.app.GetEncodingConfig().Marshaler } // LogOperationMsg logs all fields of the provided operationMsg. @@ -134,7 +137,7 @@ func (s *SimTestSuite) TestSimulateMsgBindName() { s.LogOperationMsg(operationMsg) var msg types.MsgBindNameRequest - s.Require().NoError(types.ModuleCdc.Unmarshal(operationMsg.Msg, &msg), "UnmarshalJSON(operationMsg.Msg)") + s.Require().NoError(s.cdc.Unmarshal(operationMsg.Msg, &msg), "UnmarshalJSON(operationMsg.Msg)") s.Assert().True(operationMsg.OK, "operationMsg.OK") s.Assert().Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.Record.Address, "msg.Record.Address") @@ -165,7 +168,7 @@ func (s *SimTestSuite) TestSimulateMsgDeleteName() { s.LogOperationMsg(operationMsg) var msg types.MsgDeleteNameRequest - s.Require().NoError(types.ModuleCdc.Unmarshal(operationMsg.Msg, &msg), "UnmarshalJSON(operationMsg.Msg)") + s.Require().NoError(s.cdc.Unmarshal(operationMsg.Msg, &msg), "UnmarshalJSON(operationMsg.Msg)") s.Assert().True(operationMsg.OK, "operationMsg.OK") s.Assert().Equal("cosmos1tnh2q55v8wyygtt9srz5safamzdengsnqeycj3", msg.Record.Address, "msg.Record.Address") @@ -194,7 +197,7 @@ func (s *SimTestSuite) TestSimulateMsgModifyName() { s.LogOperationMsg(operationMsg) var msg types.MsgModifyNameRequest - s.Require().NoError(types.ModuleCdc.Unmarshal(operationMsg.Msg, &msg), "UnmarshalJSON(operationMsg.Msg)") + s.Require().NoError(s.cdc.Unmarshal(operationMsg.Msg, &msg), "UnmarshalJSON(operationMsg.Msg)") s.Assert().True(operationMsg.OK, "operationMsg.OK") s.Assert().Equal("cosmos1tnh2q55v8wyygtt9srz5safamzdengsnqeycj3", msg.Record.Address, "msg.Record.Address") diff --git a/x/name/types/codec.go b/x/name/types/codec.go index 99679964b1..4d1d7cf61f 100644 --- a/x/name/types/codec.go +++ b/x/name/types/codec.go @@ -1,7 +1,6 @@ package types import ( - "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" @@ -22,13 +21,3 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } - -var ( - // ModuleCdc references the global x/account module codec. Note, the codec should - // ONLY be used in certain instances of tests and for JSON encoding as Amino is - // still used for that purpose. - // - // The actual codec used for serialization should be provided to x/account and - // defined at the application level. - ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) -) diff --git a/x/oracle/keeper/keeper.go b/x/oracle/keeper/keeper.go index 2708d2656f..fd61891c50 100644 --- a/x/oracle/keeper/keeper.go +++ b/x/oracle/keeper/keeper.go @@ -17,7 +17,7 @@ import ( ) type Keeper struct { - cdc codec.BinaryCodec + cdc *codec.ProtoCodec storeKey storetypes.StoreKey memKey storetypes.StoreKey @@ -32,7 +32,7 @@ type Keeper struct { } func NewKeeper( - cdc codec.BinaryCodec, + cdc *codec.ProtoCodec, storeKey, memKey storetypes.StoreKey, ics4Wrapper types.ICS4Wrapper, diff --git a/x/oracle/keeper/keeper_test.go b/x/oracle/keeper/keeper_test.go index f7e99fa338..ac1623c335 100644 --- a/x/oracle/keeper/keeper_test.go +++ b/x/oracle/keeper/keeper_test.go @@ -10,6 +10,7 @@ import ( cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" @@ -25,6 +26,7 @@ type KeeperTestSuite struct { app *simapp.App ctx sdk.Context + cdc *codec.ProtoCodec queryClient types.QueryClient msgServer types.MsgServer @@ -47,6 +49,7 @@ func (s *KeeperTestSuite) CreateAccounts(number int) { func (s *KeeperTestSuite) SetupTest() { s.app = app.Setup(s.T()) + s.cdc = codec.NewProtoCodec(s.app.GetEncodingConfig().InterfaceRegistry) s.CreateAccounts(4) s.msgServer = keeper.NewMsgServerImpl(&s.app.OracleKeeper) s.ctx = s.app.BaseApp.NewContextLegacy(false, cmtproto.Header{Time: time.Now().UTC()}) diff --git a/x/oracle/keeper/relay.go b/x/oracle/keeper/relay.go index 8f9dbd213c..1d36ec22d7 100644 --- a/x/oracle/keeper/relay.go +++ b/x/oracle/keeper/relay.go @@ -93,7 +93,7 @@ func (k Keeper) OnAcknowledgementPacket( switch resp := ack.Response.(type) { case *channeltypes.Acknowledgement_Result: var ackData icqtypes.InterchainQueryPacketAck - if err := icqtypes.ModuleCdc.UnmarshalJSON(resp.Result, &ackData); err != nil { + if err := k.cdc.UnmarshalJSON(resp.Result, &ackData); err != nil { return cerrs.Wrap(err, "failed to unmarshal interchain query packet ack") } resps, err := icqtypes.DeserializeCosmosResponse(ackData.Data) diff --git a/x/oracle/keeper/relay_test.go b/x/oracle/keeper/relay_test.go index 09e45caca9..2800682502 100644 --- a/x/oracle/keeper/relay_test.go +++ b/x/oracle/keeper/relay_test.go @@ -84,7 +84,7 @@ func (s *KeeperTestSuite) TestOnAcknowledgementPacket() { }, { name: "success - success event is emitted on ack", - ack: channeltypes.NewResultAcknowledgement(createICQResponse(s.app.AppCodec(), "{}")), + ack: channeltypes.NewResultAcknowledgement(s.createICQResponse(s.app.AppCodec(), "{}")), packet: channeltypes.Packet{Sequence: 5, DestinationChannel: "oracle-channel"}, event: &types.EventOracleQuerySuccess{ SequenceId: strconv.FormatUint(5, 10), @@ -101,21 +101,21 @@ func (s *KeeperTestSuite) TestOnAcknowledgementPacket() { }, { name: "failure - invalid cosmos response in icq packet ack", - ack: channeltypes.NewResultAcknowledgement(createInvalidICQPacketAck()), + ack: channeltypes.NewResultAcknowledgement(s.createInvalidICQPacketAck()), packet: channeltypes.Packet{Sequence: 5}, event: nil, err: "could not deserialize data to cosmos response: unexpected EOF", }, { name: "failure - empty cosmos response in icq packet ack", - ack: channeltypes.NewResultAcknowledgement(createEmptyICQPacketAck()), + ack: channeltypes.NewResultAcknowledgement(s.createEmptyICQPacketAck()), packet: channeltypes.Packet{Sequence: 5}, event: nil, err: "no responses in interchain query packet ack: invalid request", }, { name: "failure - invalid query response in cosmos response", - ack: channeltypes.NewResultAcknowledgement(createInvalidCosmosResponse()), + ack: channeltypes.NewResultAcknowledgement(s.createInvalidCosmosResponse()), packet: channeltypes.Packet{Sequence: 5}, event: nil, err: "failed to unmarshal interchain query response to type *types.Acknowledgement_Result: unexpected EOF", @@ -151,7 +151,7 @@ func (s *KeeperTestSuite) TestOnTimeoutPacket() { s.Assert().Equal(event, emitted[0], "timeout event should be emitted") } -func createICQResponse(cdc codec.Codec, response string) []byte { +func (s *KeeperTestSuite) createICQResponse(cdc codec.Codec, response string) []byte { oracleResponse := types.QueryOracleResponse{ Data: []byte("{}"), } @@ -163,30 +163,30 @@ func createICQResponse(cdc codec.Codec, response string) []byte { icqPacket := icqtypes.InterchainQueryPacketAck{ Data: bytes, } - icqBytes, _ := icqtypes.ModuleCdc.MarshalJSON(&icqPacket) + icqBytes, _ := s.cdc.MarshalJSON(&icqPacket) return icqBytes } -func createInvalidICQPacketAck() []byte { +func (s *KeeperTestSuite) createInvalidICQPacketAck() []byte { icqPacket := icqtypes.InterchainQueryPacketAck{ Data: []byte("abc"), } - icqBytes, _ := icqtypes.ModuleCdc.MarshalJSON(&icqPacket) + icqBytes, _ := s.cdc.MarshalJSON(&icqPacket) return icqBytes } -func createEmptyICQPacketAck() []byte { +func (s *KeeperTestSuite) createEmptyICQPacketAck() []byte { bytes, _ := icqtypes.SerializeCosmosResponse([]abci.ResponseQuery{}) icqPacket := icqtypes.InterchainQueryPacketAck{ Data: bytes, } - icqBytes, _ := icqtypes.ModuleCdc.MarshalJSON(&icqPacket) + icqBytes, _ := s.cdc.MarshalJSON(&icqPacket) return icqBytes } -func createInvalidCosmosResponse() []byte { +func (s *KeeperTestSuite) createInvalidCosmosResponse() []byte { bytes, _ := icqtypes.SerializeCosmosResponse([]abci.ResponseQuery{{ Value: []byte("baddata"), }}) @@ -194,6 +194,6 @@ func createInvalidCosmosResponse() []byte { icqPacket := icqtypes.InterchainQueryPacketAck{ Data: bytes, } - icqBytes, _ := icqtypes.ModuleCdc.MarshalJSON(&icqPacket) + icqBytes, _ := s.cdc.MarshalJSON(&icqPacket) return icqBytes } diff --git a/x/oracle/module/module_ibc.go b/x/oracle/module/module_ibc.go index 585bc0ce88..5b4550212c 100644 --- a/x/oracle/module/module_ibc.go +++ b/x/oracle/module/module_ibc.go @@ -138,7 +138,7 @@ func (am AppModule) OnAcknowledgementPacket( _ sdk.AccAddress, ) error { var ack channeltypes.Acknowledgement - if err := types.ModuleCdc.UnmarshalJSON(acknowledgement, &ack); err != nil { + if err := am.cdc.UnmarshalJSON(acknowledgement, &ack); err != nil { return cerrs.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal packet acknowledgement: %v", err) } diff --git a/x/oracle/types/codec.go b/x/oracle/types/codec.go index 69fc31229f..cd5ac42832 100644 --- a/x/oracle/types/codec.go +++ b/x/oracle/types/codec.go @@ -1,7 +1,6 @@ package types import ( - "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/gogoproto/proto" @@ -18,7 +17,3 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { &QueryOracleResponse{}, ) } - -var ( - ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) -) diff --git a/x/trigger/types/codec.go b/x/trigger/types/codec.go index 02bbbaf68c..2964766405 100644 --- a/x/trigger/types/codec.go +++ b/x/trigger/types/codec.go @@ -1,7 +1,6 @@ package types import ( - "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/gogoproto/proto" @@ -38,7 +37,3 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { &BlockTimeEvent{}, ) } - -var ( - ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) -)