From 5276640d13c4f03d615192b25929bf493dfba715 Mon Sep 17 00:00:00 2001 From: AdriaCarrera Date: Tue, 18 Mar 2025 18:59:19 +0100 Subject: [PATCH 1/2] feat(tests): add slashing integration tests --- tests/integration/slashing_test.go | 76 ++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 tests/integration/slashing_test.go diff --git a/tests/integration/slashing_test.go b/tests/integration/slashing_test.go new file mode 100644 index 0000000..5755912 --- /dev/null +++ b/tests/integration/slashing_test.go @@ -0,0 +1,76 @@ +package integration + +import ( + "cosmossdk.io/math" + "time" + + sdktypes "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + "github.com/stretchr/testify/require" + "github.com/xrplevm/node/v6/testutil/integration/exrp/utils" +) + +// AddValidator tests + +func (s *TestSuite) TestSlashing_ChangeParams() { + tt := []struct { + name string + newParams slashingtypes.Params + expectedError string + }{ + { + name: "change slashing params - invalid slash fraction double sign", + newParams: slashingtypes.NewParams( + 200, + math.LegacyOneDec(), + time.Second, + math.LegacyZeroDec(), + math.LegacyOneDec(), + ), + expectedError: "downtime sign slash fraction must be zero: 1.000000000000000000", + }, + { + name: "change slashing params - invalid slash fraction downtime", + newParams: slashingtypes.NewParams( + 200, + math.LegacyOneDec(), + time.Second, + math.LegacyOneDec(), + math.LegacyZeroDec(), + ), + expectedError: "double sign slash fraction must be zero: 1.000000000000000000", + }, + { + name: "change slashing params - success", + newParams: slashingtypes.NewParams( + 200, + math.LegacyOneDec(), + time.Second, + math.LegacyZeroDec(), + math.LegacyZeroDec(), + ), + }, + } + + for _, tc := range tt { + s.Run(tc.name, func() { + authority := sdktypes.AccAddress(address.Module("gov")) + msg := &slashingtypes.MsgUpdateParams{ + Authority: authority.String(), + Params: tc.newParams, + } + + proposal, err := utils.SubmitAndAwaitProposalResolution(s.factory, s.Network(), s.keyring.GetKeys(), "test", msg) + require.NoError(s.T(), err) + + if tc.expectedError != "" { + require.Equal(s.T(), govv1.ProposalStatus_PROPOSAL_STATUS_FAILED, proposal.Status) + require.Equal(s.T(), proposal.FailedReason, tc.expectedError) + } else { + require.Equal(s.T(), govv1.ProposalStatus_PROPOSAL_STATUS_PASSED, proposal.Status) + } + }) + } +} From ae5b929457d4b2bdb1af36f13bffee882b972e60 Mon Sep 17 00:00:00 2001 From: AdriaCarrera Date: Tue, 18 Mar 2025 19:38:15 +0100 Subject: [PATCH 2/2] fix: lint --- tests/integration/slashing_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/slashing_test.go b/tests/integration/slashing_test.go index 5755912..53ada4b 100644 --- a/tests/integration/slashing_test.go +++ b/tests/integration/slashing_test.go @@ -1,9 +1,9 @@ package integration import ( - "cosmossdk.io/math" "time" + "cosmossdk.io/math" sdktypes "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" @@ -12,7 +12,7 @@ import ( "github.com/xrplevm/node/v6/testutil/integration/exrp/utils" ) -// AddValidator tests +// Slashing tests func (s *TestSuite) TestSlashing_ChangeParams() { tt := []struct {