From 4481ff1bca76ebf5af9859b0dfbe7dcbcc8cdca4 Mon Sep 17 00:00:00 2001 From: lumtis Date: Sat, 6 Jan 2024 14:43:45 -0800 Subject: [PATCH] rename SetObervers into SetObserverSet --- x/crosschain/types/expected_keepers.go | 1 - x/emissions/types/expected_keepers.go | 1 - x/fungible/types/expected_keepers.go | 1 - x/observer/genesis.go | 2 +- .../keeper/msg_server_add_block_header_test.go | 2 +- .../keeper/msg_server_update_observer_test.go | 16 ++++++++-------- x/observer/keeper/observer_set.go | 10 +++++----- x/observer/keeper/observer_set_test.go | 8 ++++---- x/observer/keeper/utils_test.go | 6 +++--- 9 files changed, 22 insertions(+), 25 deletions(-) diff --git a/x/crosschain/types/expected_keepers.go b/x/crosschain/types/expected_keepers.go index f670357102..efe117117b 100644 --- a/x/crosschain/types/expected_keepers.go +++ b/x/crosschain/types/expected_keepers.go @@ -45,7 +45,6 @@ type BankKeeper interface { } type ObserverKeeper interface { - SetObservers(ctx sdk.Context, om observertypes.ObserverSet) GetObserverSet(ctx sdk.Context) (val observertypes.ObserverSet, found bool) SetBallot(ctx sdk.Context, ballot *observertypes.Ballot) GetBallot(ctx sdk.Context, index string) (val observertypes.Ballot, found bool) diff --git a/x/emissions/types/expected_keepers.go b/x/emissions/types/expected_keepers.go index 693fa1c475..e8b3a4d601 100644 --- a/x/emissions/types/expected_keepers.go +++ b/x/emissions/types/expected_keepers.go @@ -15,7 +15,6 @@ type AccountKeeper interface { type ObserverKeeper interface { GetMaturedBallotList(ctx sdk.Context) []string - SetObservers(ctx sdk.Context, om observertypes.ObserverSet) GetObserverSet(ctx sdk.Context) (val observertypes.ObserverSet, found bool) SetBallot(ctx sdk.Context, ballot *observertypes.Ballot) GetBallot(ctx sdk.Context, index string) (val observertypes.Ballot, found bool) diff --git a/x/fungible/types/expected_keepers.go b/x/fungible/types/expected_keepers.go index 99b59821bb..43e9607820 100644 --- a/x/fungible/types/expected_keepers.go +++ b/x/fungible/types/expected_keepers.go @@ -40,7 +40,6 @@ type BankKeeper interface { } type ObserverKeeper interface { - SetObservers(ctx sdk.Context, om observertypes.ObserverSet) GetObserverSet(ctx sdk.Context) (val observertypes.ObserverSet, found bool) SetBallot(ctx sdk.Context, ballot *observertypes.Ballot) GetBallot(ctx sdk.Context, index string) (val observertypes.Ballot, found bool) diff --git a/x/observer/genesis.go b/x/observer/genesis.go index 066bfcb5fa..ca98575668 100644 --- a/x/observer/genesis.go +++ b/x/observer/genesis.go @@ -13,7 +13,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) observerCount := uint64(0) if genState.Observers.Len() > 0 { - k.SetObservers(ctx, genState.Observers) + k.SetObserverSet(ctx, genState.Observers) observerCount = uint64(len(genState.Observers.ObserverList)) } // If core params are defined set them, otherwise set default diff --git a/x/observer/keeper/msg_server_add_block_header_test.go b/x/observer/keeper/msg_server_add_block_header_test.go index fc77041429..04e9e9c560 100644 --- a/x/observer/keeper/msg_server_add_block_header_test.go +++ b/x/observer/keeper/msg_server_add_block_header_test.go @@ -136,7 +136,7 @@ func TestMsgServer_AddBlockHeader(t *testing.T) { t.Run(tc.name, func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) srv := keeper.NewMsgServerImpl(*k) - k.SetObservers(ctx, types.ObserverSet{ + k.SetObserverSet(ctx, types.ObserverSet{ ObserverList: []string{observerAddress.String()}, }) k.GetStakingKeeper().SetValidator(ctx, tc.validator) diff --git a/x/observer/keeper/msg_server_update_observer_test.go b/x/observer/keeper/msg_server_update_observer_test.go index d93e1a3fba..181c360bb1 100644 --- a/x/observer/keeper/msg_server_update_observer_test.go +++ b/x/observer/keeper/msg_server_update_observer_test.go @@ -46,7 +46,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { count := uint64(0) - k.SetObservers(ctx, types.ObserverSet{ + k.SetObserverSet(ctx, types.ObserverSet{ ObserverList: []string{accAddressOfValidator.String()}, }) count = 1 @@ -99,7 +99,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { assert.NoError(t, err) count := uint64(0) - k.SetObservers(ctx, types.ObserverSet{ + k.SetObserverSet(ctx, types.ObserverSet{ ObserverList: []string{accAddressOfValidator.String()}, }) count = 1 @@ -147,7 +147,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { assert.NoError(t, err) count := uint64(0) - k.SetObservers(ctx, types.ObserverSet{ + k.SetObserverSet(ctx, types.ObserverSet{ ObserverList: []string{accAddressOfValidator.String()}, }) count += 1 @@ -197,7 +197,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { accAddressOfValidator, err := types.GetAccAddressFromOperatorAddress(validator.OperatorAddress) assert.NoError(t, err) count := uint64(0) - k.SetObservers(ctx, types.ObserverSet{ + k.SetObserverSet(ctx, types.ObserverSet{ ObserverList: []string{accAddressOfValidator.String()}, }) count += 1 @@ -247,7 +247,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { accAddressOfValidator, err := types.GetAccAddressFromOperatorAddress(validator.OperatorAddress) assert.NoError(t, err) count := uint64(0) - k.SetObservers(ctx, types.ObserverSet{ + k.SetObserverSet(ctx, types.ObserverSet{ ObserverList: []string{accAddressOfValidator.String()}, }) count += 1 @@ -293,7 +293,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { accAddressOfValidator, err := types.GetAccAddressFromOperatorAddress(validator.OperatorAddress) assert.NoError(t, err) count := uint64(0) - k.SetObservers(ctx, types.ObserverSet{ + k.SetObserverSet(ctx, types.ObserverSet{ ObserverList: []string{accAddressOfValidator.String()}, }) count += 1 @@ -341,7 +341,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { accAddressOfValidator, err := types.GetAccAddressFromOperatorAddress(validator.OperatorAddress) assert.NoError(t, err) count := uint64(0) - k.SetObservers(ctx, types.ObserverSet{ + k.SetObserverSet(ctx, types.ObserverSet{ ObserverList: []string{accAddressOfValidator.String()}, }) count += 1 @@ -394,7 +394,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { accAddressOfValidator, err := types.GetAccAddressFromOperatorAddress(validator.OperatorAddress) assert.NoError(t, err) count := uint64(0) - k.SetObservers(ctx, types.ObserverSet{ + k.SetObserverSet(ctx, types.ObserverSet{ ObserverList: []string{accAddressOfValidator.String()}, }) count += 1 diff --git a/x/observer/keeper/observer_set.go b/x/observer/keeper/observer_set.go index 4997ea445f..b8c45bfd30 100644 --- a/x/observer/keeper/observer_set.go +++ b/x/observer/keeper/observer_set.go @@ -6,7 +6,7 @@ import ( "github.com/zeta-chain/zetacore/x/observer/types" ) -func (k Keeper) SetObservers(ctx sdk.Context, om types.ObserverSet) { +func (k Keeper) SetObserverSet(ctx sdk.Context, om types.ObserverSet) { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ObserverSetKey)) b := k.cdc.MustMarshal(&om) store.Set([]byte{0}, b) @@ -39,7 +39,7 @@ func (k Keeper) IsAddressPartOfObserverSet(ctx sdk.Context, address string) bool func (k Keeper) AddObserverToSet(ctx sdk.Context, address string) { observerSet, found := k.GetObserverSet(ctx) if !found { - k.SetObservers(ctx, types.ObserverSet{ + k.SetObserverSet(ctx, types.ObserverSet{ ObserverList: []string{address}, }) return @@ -50,7 +50,7 @@ func (k Keeper) AddObserverToSet(ctx sdk.Context, address string) { } } observerSet.ObserverList = append(observerSet.ObserverList, address) - k.SetObservers(ctx, observerSet) + k.SetObserverSet(ctx, observerSet) } func (k Keeper) RemoveObserverFromSet(ctx sdk.Context, address string) { @@ -61,7 +61,7 @@ func (k Keeper) RemoveObserverFromSet(ctx sdk.Context, address string) { for i, addr := range observerSet.ObserverList { if addr == address { observerSet.ObserverList = append(observerSet.ObserverList[:i], observerSet.ObserverList[i+1:]...) - k.SetObservers(ctx, observerSet) + k.SetObserverSet(ctx, observerSet) return } } @@ -75,7 +75,7 @@ func (k Keeper) UpdateObserverAddress(ctx sdk.Context, oldObserverAddress, newOb for i, addr := range observerSet.ObserverList { if addr == oldObserverAddress { observerSet.ObserverList[i] = newObserverAddress - k.SetObservers(ctx, observerSet) + k.SetObserverSet(ctx, observerSet) return nil } } diff --git a/x/observer/keeper/observer_set_test.go b/x/observer/keeper/observer_set_test.go index e0314638e7..04bf871a4e 100644 --- a/x/observer/keeper/observer_set_test.go +++ b/x/observer/keeper/observer_set_test.go @@ -33,7 +33,7 @@ func TestKeeper_AddObserverToSet(t *testing.T) { t.Run("add observer to set", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) os := sample.ObserverSet(10) - k.SetObservers(ctx, os) + k.SetObserverSet(ctx, os) newObserver := sample.AccAddress() k.AddObserverToSet(ctx, newObserver) assert.True(t, k.IsAddressPartOfObserverSet(ctx, newObserver)) @@ -64,7 +64,7 @@ func TestKeeper_UpdateObserverAddress(t *testing.T) { newObserverAddress := sample.AccAddress() observerSet := sample.ObserverSet(10) observerSet.ObserverList = append(observerSet.ObserverList, oldObserverAddress) - k.SetObservers(ctx, observerSet) + k.SetObserverSet(ctx, observerSet) err := k.UpdateObserverAddress(ctx, oldObserverAddress, newObserverAddress) assert.NoError(t, err) observerSet, found := k.GetObserverSet(ctx) @@ -77,7 +77,7 @@ func TestKeeper_UpdateObserverAddress(t *testing.T) { newObserverAddress := sample.AccAddress() observerSet := sample.ObserverSet(10000) observerSet.ObserverList = append(observerSet.ObserverList, oldObserverAddress) - k.SetObservers(ctx, observerSet) + k.SetObserverSet(ctx, observerSet) err := k.UpdateObserverAddress(ctx, oldObserverAddress, newObserverAddress) assert.NoError(t, err) observerMappers, found := k.GetObserverSet(ctx) @@ -90,7 +90,7 @@ func TestKeeper_UpdateObserverAddress(t *testing.T) { newObserverAddress := sample.AccAddress() observerSet := sample.ObserverSet(1) observerSet.ObserverList = append(observerSet.ObserverList, oldObserverAddress) - k.SetObservers(ctx, observerSet) + k.SetObserverSet(ctx, observerSet) err := k.UpdateObserverAddress(ctx, oldObserverAddress, newObserverAddress) assert.NoError(t, err) observerMappers, found := k.GetObserverSet(ctx) diff --git a/x/observer/keeper/utils_test.go b/x/observer/keeper/utils_test.go index 3d68f0b407..a958fb5dc3 100644 --- a/x/observer/keeper/utils_test.go +++ b/x/observer/keeper/utils_test.go @@ -32,7 +32,7 @@ func TestKeeper_IsAuthorized(t *testing.T) { accAddressOfValidator, err := types.GetAccAddressFromOperatorAddress(validator.OperatorAddress) - k.SetObservers(ctx, types.ObserverSet{ + k.SetObserverSet(ctx, types.ObserverSet{ ObserverList: []string{accAddressOfValidator.String()}, }) assert.True(t, k.IsAuthorized(ctx, accAddressOfValidator.String())) @@ -57,7 +57,7 @@ func TestKeeper_IsAuthorized(t *testing.T) { }) accAddressOfValidator, err := types.GetAccAddressFromOperatorAddress(validator.OperatorAddress) - k.SetObservers(ctx, types.ObserverSet{ + k.SetObserverSet(ctx, types.ObserverSet{ ObserverList: []string{accAddressOfValidator.String()}, }) @@ -83,7 +83,7 @@ func TestKeeper_IsAuthorized(t *testing.T) { }) accAddressOfValidator, err := types.GetAccAddressFromOperatorAddress(validator.OperatorAddress) - k.SetObservers(ctx, types.ObserverSet{ + k.SetObserverSet(ctx, types.ObserverSet{ ObserverList: []string{accAddressOfValidator.String()}, })