From 56ff6f2a5aa85ff0293c015623c3b7c56b89a977 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Tue, 19 Sep 2023 11:55:18 -0700 Subject: [PATCH] old methods --- x/ccv/provider/keeper/migration.go | 31 +++++++++++++++++++++++++ x/ccv/provider/keeper/migration_test.go | 15 ++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 x/ccv/provider/keeper/migration_test.go diff --git a/x/ccv/provider/keeper/migration.go b/x/ccv/provider/keeper/migration.go index ed0e794ce3..24669bb3c7 100644 --- a/x/ccv/provider/keeper/migration.go +++ b/x/ccv/provider/keeper/migration.go @@ -84,3 +84,34 @@ func (k Keeper) GetAllThrottledPacketData(ctx sdktypes.Context, consumerChainID return slashData, vscMaturedData } + +// Note this method is adapted from throttle v1 code. +func (k Keeper) QueueThrottledPacketDataOnlyForTesting( + ctx sdktypes.Context, consumerChainID string, ibcSeqNum uint64, packetData interface{}, +) error { + store := ctx.KVStore(k.storeKey) + + var bz []byte + var err error + switch data := packetData.(type) { + case ccvtypes.SlashPacketData: + bz, err = data.Marshal() + if err != nil { + return fmt.Errorf("failed to marshal slash packet data: %v", err) + } + bz = append([]byte{slashPacketData}, bz...) + case ccvtypes.VSCMaturedPacketData: + bz, err = data.Marshal() + if err != nil { + return fmt.Errorf("failed to marshal vsc matured packet data: %v", err) + } + bz = append([]byte{vscMaturedPacketData}, bz...) + default: + // Indicates a developer error, this method should only be called + // by tests, QueueThrottledSlashPacketData, or QueueThrottledVSCMaturedPacketData. + panic(fmt.Sprintf("unexpected packet data type: %T", data)) + } + + store.Set(providertypes.ThrottledPacketDataKey(consumerChainID, ibcSeqNum), bz) + return nil +} diff --git a/x/ccv/provider/keeper/migration_test.go b/x/ccv/provider/keeper/migration_test.go new file mode 100644 index 0000000000..4a7c3d695d --- /dev/null +++ b/x/ccv/provider/keeper/migration_test.go @@ -0,0 +1,15 @@ +package keeper_test + +import ( + "testing" + + testutil "github.com/cosmos/interchain-security/v3/testutil/keeper" +) + +func TestMigrate2To3(t *testing.T) { + consumerKeeper, ctx, ctrl, _ := testutil.GetProviderKeeperAndCtx(t, testutil.NewInMemKeeperParams(t)) + defer ctrl.Finish() + + // Set some data in old format + +}