From d1ef60d8911362083eba18d4bdcd6d37b3e30659 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Fri, 9 Aug 2024 13:49:19 -0400 Subject: [PATCH] add comments for tests --- x/observer/keeper/msg_server_add_observer_test.go | 5 +++++ .../keeper/msg_server_update_observer_test.go | 15 +++++++-------- x/observer/keeper/observer_set_test.go | 9 ++++++++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/x/observer/keeper/msg_server_add_observer_test.go b/x/observer/keeper/msg_server_add_observer_test.go index a135d0c324..183a97c8e8 100644 --- a/x/observer/keeper/msg_server_add_observer_test.go +++ b/x/observer/keeper/msg_server_add_observer_test.go @@ -53,6 +53,7 @@ func TestMsgServer_AddObserver(t *testing.T) { }) t.Run("unable to add observer if observer already exists", func(t *testing.T) { + //ARRANGE k, ctx, _, _ := keepertest.ObserverKeeperWithMocks(t, keepertest.ObserverMockOptions{ UseAuthorityMock: true, }) @@ -73,7 +74,11 @@ func TestMsgServer_AddObserver(t *testing.T) { ObserverAddress: observerAddress, } keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) + + // ACT _, err := srv.AddObserver(wctx, &msg) + + // ASSERT require.ErrorIs(t, err, types.ErrDuplicateObserver) }) diff --git a/x/observer/keeper/msg_server_update_observer_test.go b/x/observer/keeper/msg_server_update_observer_test.go index 5ac3654746..66e646eb53 100644 --- a/x/observer/keeper/msg_server_update_observer_test.go +++ b/x/observer/keeper/msg_server_update_observer_test.go @@ -76,11 +76,11 @@ func TestMsgServer_UpdateObserver(t *testing.T) { t.Run( "unable to update a tombstoned observer if the new address already exists in the observer set", func(t *testing.T) { + //ARRANGE k, ctx, _, _ := keepertest.ObserverKeeper(t) srv := keeper.NewMsgServerImpl(*k) // #nosec G404 test purpose - weak randomness is not an issue here r := rand.New(rand.NewSource(9)) - // Set validator in the store validator := sample.Validator(t, r) validatorNew := sample.Validator(t, r) @@ -104,27 +104,26 @@ func TestMsgServer_UpdateObserver(t *testing.T) { newOperatorAddress, err := types.GetAccAddressFromOperatorAddress(validatorNew.OperatorAddress) require.NoError(t, err) - count := uint64(0) - + observerList := []string{accAddressOfValidator.String(), newOperatorAddress.String()} k.SetObserverSet(ctx, types.ObserverSet{ - ObserverList: []string{accAddressOfValidator.String(), newOperatorAddress.String()}, + ObserverList: observerList, }) - count = 1 - k.SetNodeAccount(ctx, types.NodeAccount{ Operator: accAddressOfValidator.String(), }) - k.SetLastObserverCount(ctx, &types.LastObserverCount{ - Count: count, + Count: uint64(len(observerList)), }) + //ACT _, err = srv.UpdateObserver(sdk.WrapSDKContext(ctx), &types.MsgUpdateObserver{ Creator: accAddressOfValidator.String(), OldObserverAddress: accAddressOfValidator.String(), NewObserverAddress: newOperatorAddress.String(), UpdateReason: types.ObserverUpdateReason_Tombstoned, }) + + // ASSERT require.ErrorContains(t, err, types.ErrDuplicateObserver.Error()) }, ) diff --git a/x/observer/keeper/observer_set_test.go b/x/observer/keeper/observer_set_test.go index 4e568b1fe3..dd13fd72f1 100644 --- a/x/observer/keeper/observer_set_test.go +++ b/x/observer/keeper/observer_set_test.go @@ -96,17 +96,24 @@ func TestKeeper_UpdateObserverAddress(t *testing.T) { require.Equal(t, newObserverAddress, observerSet.ObserverList[len(observerSet.ObserverList)-1]) }) t.Run("unable to update observer list if the new list is not valid", func(t *testing.T) { + // ARRANGE k, ctx, _, _ := keepertest.ObserverKeeper(t) oldObserverAddress := sample.AccAddress() newObserverAddress := sample.AccAddress() observerSet := sample.ObserverSet(10) observerSet.ObserverList = append(observerSet.ObserverList, []string{oldObserverAddress, newObserverAddress}...) + // ACT 1 err := k.UpdateObserverAddress(ctx, oldObserverAddress, newObserverAddress) + + // ASSERT 1 require.ErrorIs(t, err, types.ErrObserverSetNotFound) - k.SetObserverSet(ctx, observerSet) + // ACT 2 + k.SetObserverSet(ctx, observerSet) err = k.UpdateObserverAddress(ctx, oldObserverAddress, newObserverAddress) + + // ASSERT 2 require.ErrorContains(t, err, types.ErrDuplicateObserver.Error()) }) t.Run("should error if observer address not found", func(t *testing.T) {