-
Notifications
You must be signed in to change notification settings - Fork 715
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: Add upgrade handler for ics consumer infraction params (#3430)
* added upgrade handler for ics infraction params * lint fix * format error * bump ics version * get default infraction parameters from providertypes * lint fix --------- Co-authored-by: MSalopek <matija.salopek994@gmail.com>
- Loading branch information
1 parent
46b17a3
commit cf1210d
Showing
4 changed files
with
101 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package v22_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
testutil "github.com/cosmos/interchain-security/v6/testutil/keeper" | ||
providertypes "github.com/cosmos/interchain-security/v6/x/ccv/provider/types" | ||
|
||
"cosmossdk.io/math" | ||
|
||
v22 "github.com/cosmos/gaia/v22/app/upgrades/v22" | ||
) | ||
|
||
func TestSetDefaultConsumerInfractionParams(t *testing.T) { | ||
t.Helper() | ||
inMemParams := testutil.NewInMemKeeperParams(t) | ||
pk, ctx, ctrl, _ := testutil.GetProviderKeeperAndCtx(t, inMemParams) | ||
defer ctrl.Finish() | ||
|
||
// Add consumer chains | ||
initConsumerID := pk.FetchAndIncrementConsumerId(ctx) | ||
pk.SetConsumerChainId(ctx, initConsumerID, "init-1") | ||
pk.SetConsumerPhase(ctx, initConsumerID, providertypes.CONSUMER_PHASE_INITIALIZED) | ||
launchedConsumerID := pk.FetchAndIncrementConsumerId(ctx) | ||
pk.SetConsumerChainId(ctx, launchedConsumerID, "launched-1") | ||
pk.SetConsumerPhase(ctx, launchedConsumerID, providertypes.CONSUMER_PHASE_LAUNCHED) | ||
stoppedConsumerID := pk.FetchAndIncrementConsumerId(ctx) | ||
pk.SetConsumerChainId(ctx, stoppedConsumerID, "stopped-1") | ||
pk.SetConsumerPhase(ctx, stoppedConsumerID, providertypes.CONSUMER_PHASE_STOPPED) | ||
|
||
activeConsumerIDs := pk.GetAllActiveConsumerIds(ctx) | ||
require.Equal(t, 2, len(activeConsumerIDs)) | ||
|
||
for _, consumerID := range activeConsumerIDs { | ||
_, err := pk.GetInfractionParameters(ctx, consumerID) | ||
require.Error(t, err) | ||
} | ||
|
||
testParams := testInfractionParams() | ||
err := v22.SetConsumerInfractionParams(ctx, pk, testParams) | ||
require.NoError(t, err) | ||
|
||
for _, consumerID := range activeConsumerIDs { | ||
infractionParams, err := pk.GetInfractionParameters(ctx, consumerID) | ||
require.NoError(t, err) | ||
require.Equal(t, testParams, infractionParams) | ||
} | ||
} | ||
|
||
func testInfractionParams() providertypes.InfractionParameters { | ||
return providertypes.InfractionParameters{ | ||
DoubleSign: &providertypes.SlashJailParameters{ | ||
JailDuration: time.Duration(1<<63 - 1), // the largest value a time.Duration can hold 9223372036854775807 (approximately 292 years) | ||
SlashFraction: math.LegacyNewDecWithPrec(5, 2), // 0.05 | ||
}, | ||
Downtime: &providertypes.SlashJailParameters{ | ||
JailDuration: 600 * time.Second, | ||
SlashFraction: math.LegacyNewDec(0), // no slashing for downtime on the consumer | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters