Skip to content

Commit

Permalink
slashing module
Browse files Browse the repository at this point in the history
  • Loading branch information
kocubinski committed Feb 13, 2023
1 parent e5076f5 commit 583181c
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 84 deletions.
90 changes: 47 additions & 43 deletions api/cosmos/slashing/v1beta1/slashing.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions proto/cosmos/slashing/v1beta1/slashing.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,21 @@ message Params {
bytes min_signed_per_window = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(amino.encoding) = "cosmos_dec_bytes",
(amino.dont_omitempty) = true
];
google.protobuf.Duration downtime_jail_duration = 3
[(gogoproto.nullable) = false, (amino.dont_omitempty) = true, (gogoproto.stdduration) = true];
bytes slash_fraction_double_sign = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(amino.encoding) = "cosmos_dec_bytes",
(amino.dont_omitempty) = true
];
bytes slash_fraction_downtime = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(amino.encoding) = "cosmos_dec_bytes",
(amino.dont_omitempty) = true
];
}
31 changes: 29 additions & 2 deletions tests/integration/aminojson/aminojson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
groupmodule "github.com/cosmos/cosmos-sdk/x/group/module"
"github.com/cosmos/cosmos-sdk/x/mint"
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/slashing"
"reflect"
"testing"
"time"
Expand Down Expand Up @@ -32,6 +33,7 @@ import (
groupapi "cosmossdk.io/api/cosmos/group/v1"
mintapi "cosmossdk.io/api/cosmos/mint/v1beta1"
paramsapi "cosmossdk.io/api/cosmos/params/v1beta1"
slashingapi "cosmossdk.io/api/cosmos/slashing/v1beta1"
"cosmossdk.io/x/evidence"
evidencetypes "cosmossdk.io/x/evidence/types"
feegranttypes "cosmossdk.io/x/feegrant"
Expand Down Expand Up @@ -60,6 +62,7 @@ import (
grouptypes "github.com/cosmos/cosmos-sdk/x/group"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/cosmos/cosmos-sdk/x/params/types/proposal"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
)

type generatedType struct {
Expand Down Expand Up @@ -223,14 +226,20 @@ var (

// params
genType(&proposal.ParameterChangeProposal{}, &paramsapi.ParameterChangeProposal{}, genOpts),

// slashing
genType(&slashingtypes.Params{}, &slashingapi.Params{}, genOpts.WithDisallowNil()),
genType(&slashingtypes.MsgUnjail{}, &slashingapi.MsgUnjail{}, genOpts),
genType(&slashingtypes.MsgUpdateParams{}, &slashingapi.MsgUpdateParams{}, genOpts.WithDisallowNil()),
}
)

func TestAminoJSON_Equivalence(t *testing.T) {
encCfg := testutil.MakeTestEncodingConfig(
auth.AppModuleBasic{}, authzmodule.AppModuleBasic{}, bank.AppModuleBasic{}, consensus.AppModuleBasic{},
distribution.AppModuleBasic{}, evidence.AppModuleBasic{}, feegrantmodule.AppModuleBasic{},
gov.AppModuleBasic{}, groupmodule.AppModuleBasic{}, mint.AppModuleBasic{}, params.AppModuleBasic{})
gov.AppModuleBasic{}, groupmodule.AppModuleBasic{}, mint.AppModuleBasic{}, params.AppModuleBasic{},
slashing.AppModuleBasic{})
aj := aminojson.NewAminoJSON()

for _, tt := range genTypes {
Expand Down Expand Up @@ -286,14 +295,15 @@ func newAny(t *testing.T, msg proto.Message) *anypb.Any {

func TestAminoJSON_LegacyParity(t *testing.T) {
encCfg := testutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, authzmodule.AppModuleBasic{},
bank.AppModuleBasic{}, distribution.AppModuleBasic{})
bank.AppModuleBasic{}, distribution.AppModuleBasic{}, slashing.AppModuleBasic{})

aj := aminojson.NewAminoJSON()
addr1 := types.AccAddress([]byte("addr1"))
now := time.Now()

genericAuth, _ := codectypes.NewAnyWithValue(&authztypes.GenericAuthorization{Msg: "foo"})
genericAuthPulsar := newAny(t, &authzapi.GenericAuthorization{Msg: "foo"})
dec10bz, _ := types.NewDec(10).Marshal()

cases := map[string]struct {
gogo gogoproto.Message
Expand Down Expand Up @@ -392,6 +402,23 @@ func TestAminoJSON_LegacyParity(t *testing.T) {
gogo: &banktypes.MsgMultiSend{},
pulsar: &bankapi.MsgMultiSend{},
},
"slashing/params/empty_dec": {
gogo: &slashingtypes.Params{DowntimeJailDuration: 1e9 + 7},
pulsar: &slashingapi.Params{DowntimeJailDuration: &durationpb.Duration{Seconds: 1, Nanos: 7}},
},
// !! Important !!
// This test cases demonstrates the expected contract and proper way to set a cosmos.Dec field represented
// as bytes in protobuf message, namely:
// dec10bz, _ := types.NewDec(10).Marshal()
"slashing/params/dec": {
gogo: &slashingtypes.Params{
DowntimeJailDuration: 1e9 + 7,
MinSignedPerWindow: types.NewDec(10)},
pulsar: &slashingapi.Params{
DowntimeJailDuration: &durationpb.Duration{Seconds: 1, Nanos: 7},
MinSignedPerWindow: dec10bz,
},
},
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
Expand Down
Loading

0 comments on commit 583181c

Please sign in to comment.