Skip to content
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
5 changes: 3 additions & 2 deletions pkg/cosmos/adapters/injective/types/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ const (

func init() {
gov.RegisterProposalType(ProposalTypeOcrSetConfig)
amino.RegisterConcrete(&SetConfigProposal{}, "injective/OcrSetConfigProposal", nil)
amino.RegisterConcrete(&SetBatchConfigProposal{}, "injective/OcrSetBatchConfigProposal", nil)
// Keep Amino concrete registration out of this init. The package-level
// LegacyAmino in codec.go is sealed during init, and registering here can
// trigger "panic: codec sealed" depending on init order.
}

// Implements Proposal Interface
Expand Down
51 changes: 51 additions & 0 deletions pkg/cosmos/adapters/injective/types/proposal_regression_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package types

import (
"fmt"
"strings"
"testing"

gov "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)

func TestProposalTypeRegistered(t *testing.T) {
t.Parallel()

if !gov.IsValidProposalType(ProposalTypeOcrSetConfig) {
t.Fatalf("proposal type %q is not registered", ProposalTypeOcrSetConfig)
}
}

func TestSetConfigProposalAminoRegistration(t *testing.T) {
t.Parallel()

var content gov.Content = &SetConfigProposal{
Title: "title",
Description: "description",
}

bz, err := amino.MarshalJSON(content)
if err != nil {
t.Fatalf("marshal gov.Content via amino: %v", err)
}

if !strings.Contains(string(bz), "ocr/SetConfigProposal") {
t.Fatalf("expected amino type tag to include ocr/SetConfigProposal, got: %s", string(bz))
}
}

func TestLegacyAminoRegistrationPanicsAfterSeal(t *testing.T) {
t.Parallel()

defer func() {
r := recover()
if r == nil {
t.Fatal("expected panic when registering on sealed legacy amino codec")
}
if !strings.Contains(fmt.Sprint(r), "codec sealed") {
t.Fatalf("expected panic to contain %q, got: %v", "codec sealed", r)
}
}()

amino.RegisterConcrete(&SetConfigProposal{}, "injective/OcrSetConfigProposal", nil)
}
Loading