Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace missing interfaces to x/profiles module protobuf codec into app codec #1270

Merged
merged 4 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: fix
module: x/profiles
pull_request: 1270
description: Replace missing interfaces to `x/profiles` module protobuf codec into app codec
backward_compatible: true
date: 2023-12-01T08:06:01.010353464Z
10 changes: 5 additions & 5 deletions x/profiles/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
am IBCModule, ctx sdk.Context, packet channeltypes.Packet,
) (handled bool, ack channeltypes.Acknowledgement, err error) {
var packetData types.LinkChainAccountPacketData
if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &packetData); err != nil {
if err := am.cdc.UnmarshalJSON(packet.GetData(), &packetData); err != nil {

Check warning on line 219 in x/profiles/ibc_module.go

View check run for this annotation

Codecov / codecov/patch

x/profiles/ibc_module.go#L219

Added line #L219 was not covered by tests
return false, channeltypes.Acknowledgement{}, nil
}

Expand Down Expand Up @@ -259,7 +259,7 @@
am IBCModule, ctx sdk.Context, packet channeltypes.Packet,
) (handled bool, ack channeltypes.Acknowledgement, err error) {
var data oracletypes.OracleResponsePacketData
if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil {
if err := am.cdc.UnmarshalJSON(packet.GetData(), &data); err != nil {

Check warning on line 262 in x/profiles/ibc_module.go

View check run for this annotation

Codecov / codecov/patch

x/profiles/ibc_module.go#L262

Added line #L262 was not covered by tests
return false, channeltypes.Acknowledgement{}, nil
}

Expand Down Expand Up @@ -295,14 +295,14 @@
relayer sdk.AccAddress,
) error {
var ack channeltypes.Acknowledgement
err := types.ModuleCdc.UnmarshalJSON(acknowledgement, &ack)
err := am.cdc.UnmarshalJSON(acknowledgement, &ack)

Check warning on line 298 in x/profiles/ibc_module.go

View check run for this annotation

Codecov / codecov/patch

x/profiles/ibc_module.go#L298

Added line #L298 was not covered by tests
if err != nil {
return errors.Wrapf(sdkerrors.ErrUnknownRequest,
"cannot unmarshal oracle packet acknowledgement: %v", err)
}

var data oracletypes.OracleRequestPacketData
err = types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data)
err = am.cdc.UnmarshalJSON(packet.GetData(), &data)

Check warning on line 305 in x/profiles/ibc_module.go

View check run for this annotation

Codecov / codecov/patch

x/profiles/ibc_module.go#L305

Added line #L305 was not covered by tests
if err != nil {
return errors.Wrapf(sdkerrors.ErrUnknownRequest,
"cannot unmarshal oracle request packet data: %s", err)
Expand Down Expand Up @@ -351,7 +351,7 @@
relayer sdk.AccAddress,
) error {
var data oracletypes.OracleRequestPacketData
err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data)
err := am.cdc.UnmarshalJSON(packet.GetData(), &data)

Check warning on line 354 in x/profiles/ibc_module.go

View check run for this annotation

Codecov / codecov/patch

x/profiles/ibc_module.go#L354

Added line #L354 was not covered by tests
if err != nil {
return errors.Wrapf(sdkerrors.ErrUnknownRequest,
"cannot unmarshal oracle request packet data: %s", err)
Expand Down
4 changes: 2 additions & 2 deletions x/profiles/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
// Keeper maintains the link to data storage and exposes getter/setter methods for the various parts of the state machine
type Keeper struct {
storeKey storetypes.StoreKey
cdc codec.BinaryCodec
cdc codec.Codec
legacyAmino *codec.LegacyAmino
paramSubspace paramstypes.Subspace
hooks types.ProfilesHooks
Expand All @@ -46,7 +46,7 @@ type Keeper struct {
// 2. DTag -> Address
// This is used to get the address of a user based on a DTag
func NewKeeper(
cdc codec.BinaryCodec,
cdc codec.Codec,
legacyAmino *codec.LegacyAmino,
storeKey storetypes.StoreKey,
ak authkeeper.AccountKeeper,
Expand Down
2 changes: 1 addition & 1 deletion x/profiles/keeper/relay_app_links.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (k Keeper) OnOracleRequestAcknowledgementPacket(
link.State = types.AppLinkStateVerificationStarted

var packetAck oracletypes.OracleRequestPacketAcknowledgement
err = types.ModuleCdc.UnmarshalJSON(res.Result, &packetAck)
err = k.cdc.UnmarshalJSON(res.Result, &packetAck)
if err != nil {
return fmt.Errorf("cannot unmarshal oracle request packet acknowledgment: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion x/profiles/keeper/relay_app_links_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ func (suite *KeeperTestSuite) TestKeeper_OnOracleRequestAcknowledgementPacket()
suite.Require().NoError(err)
},
data: createRequestPacketData("client_id"),
ack: channeltypes.NewResultAcknowledgement(types.ModuleCdc.MustMarshalJSON(&result)),
ack: channeltypes.NewResultAcknowledgement(suite.cdc.MustMarshalJSON(&result)),
shouldErr: false,
expLink: types.NewApplicationLink(
"cosmos10nsdxxdvy9qka3zv0lzw8z9cnu6kanld8jh773",
Expand Down
11 changes: 7 additions & 4 deletions x/profiles/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec/legacy"
"github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand Down Expand Up @@ -64,6 +65,10 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
&SingleSignature{},
&CosmosMultiSignature{},
)
registry.RegisterImplementations(
(*cryptotypes.PubKey)(nil),
&ethsecp256k1.PubKey{},
)

registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgSaveProfile{},
Expand All @@ -86,15 +91,13 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
var (
amino = codec.NewLegacyAmino()

// AminoCdc references the global x/relationships module codec. Note, the codec should
// AminoCdc references the global x/profiles 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/relationships and
// The actual codec used for serialization should be provided to x/profiles and
// defined at the application level.
AminoCdc = codec.NewAminoCodec(amino)

ModuleCdc = codec.NewProtoCodec(types.NewInterfaceRegistry())
)

func init() {
Expand Down
6 changes: 3 additions & 3 deletions x/profiles/types/models_packets.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package types
import (
"fmt"

"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand Down Expand Up @@ -61,7 +62,6 @@ func (p LinkChainAccountPacketData) Validate() error {
}

// GetBytes is a helper for serialising
func (p LinkChainAccountPacketData) GetBytes() ([]byte, error) {
var modulePacket LinkChainAccountPacketData
return sdk.SortJSON(ModuleCdc.MustMarshalJSON(&modulePacket))
func (p LinkChainAccountPacketData) GetBytes(cdc codec.Codec) ([]byte, error) {
return sdk.SortJSON(cdc.MustMarshalJSON(&p))
}
11 changes: 8 additions & 3 deletions x/profiles/types/models_packets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/stretchr/testify/require"

"github.com/desmos-labs/desmos/v6/app"
"github.com/desmos-labs/desmos/v6/testutil/profilestesting"
"github.com/desmos-labs/desmos/v6/x/profiles/types"
)
Expand Down Expand Up @@ -138,13 +139,17 @@ func TestLinkChainAccountPacketData_Validate(t *testing.T) {
}

func TestLinkChainAccountPacketData_GetBytes(t *testing.T) {
pubKey := profilestesting.PubKeyFromBech32("cosmospub1addwnpepqvryxhhqhw52c4ny5twtfzf3fsrjqhx0x5cuya0fylw0wu0eqptykeqhr4d")
packetData := types.NewLinkChainAccountPacketData(
types.NewBech32Address("cosmos1yt7rqhj0hjw92ed0948r2pqwtp9smukurqcs70", "cosmos"),
types.NewProof(secp256k1.GenPrivKey().PubKey(), profilestesting.SingleSignatureFromHex("032086ede8d4bce29fe364a94744ca71dbeaf370221ba20f9716a165c54b079561"), "plain_text"),
types.NewProof(pubKey, profilestesting.SingleSignatureFromHex("032086ede8d4bce29fe364a94744ca71dbeaf370221ba20f9716a165c54b079561"), "plain_text"),
types.NewChainConfig("cosmos"),
"cosmos1yt7rqhj0hjw92ed0948r2pqwtp9smukurqcs70",
types.NewProof(secp256k1.GenPrivKey().PubKey(), profilestesting.SingleSignatureFromHex("032086ede8d4bce29fe364a94744ca71dbeaf370221ba20f9716a165c54b079561"), "plain_text"),
types.NewProof(pubKey, profilestesting.SingleSignatureFromHex("032086ede8d4bce29fe364a94744ca71dbeaf370221ba20f9716a165c54b079561"), "plain_text"),
)
_, err := packetData.GetBytes()

cdc, _ := app.MakeCodecs()
bz, err := packetData.GetBytes(cdc)
require.NoError(t, err)
require.Equal(t, "{\"destination_address\":\"cosmos1yt7rqhj0hjw92ed0948r2pqwtp9smukurqcs70\",\"destination_proof\":{\"plain_text\":\"plain_text\",\"pub_key\":{\"@type\":\"/cosmos.crypto.secp256k1.PubKey\",\"key\":\"AwZDXuC7qKxWZKLctIkxTAcgXM81McJ16Sfc93H5AFZL\"},\"signature\":{\"@type\":\"/desmos.profiles.v3.SingleSignature\",\"signature\":\"AyCG7ejUvOKf42SpR0TKcdvq83AiG6IPlxahZcVLB5Vh\",\"value_type\":\"SIGNATURE_VALUE_TYPE_RAW\"}},\"source_address\":{\"@type\":\"/desmos.profiles.v3.Bech32Address\",\"prefix\":\"cosmos\",\"value\":\"cosmos1yt7rqhj0hjw92ed0948r2pqwtp9smukurqcs70\"},\"source_chain_config\":{\"name\":\"cosmos\"},\"source_proof\":{\"plain_text\":\"plain_text\",\"pub_key\":{\"@type\":\"/cosmos.crypto.secp256k1.PubKey\",\"key\":\"AwZDXuC7qKxWZKLctIkxTAcgXM81McJ16Sfc93H5AFZL\"},\"signature\":{\"@type\":\"/desmos.profiles.v3.SingleSignature\",\"signature\":\"AyCG7ejUvOKf42SpR0TKcdvq83AiG6IPlxahZcVLB5Vh\",\"value_type\":\"SIGNATURE_VALUE_TYPE_RAW\"}}}", string(bz))
}
Loading