Skip to content

Commit

Permalink
add comments for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Aug 9, 2024
1 parent 275da58 commit d1ef60d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
5 changes: 5 additions & 0 deletions x/observer/keeper/msg_server_add_observer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand All @@ -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)
})

Expand Down
15 changes: 7 additions & 8 deletions x/observer/keeper/msg_server_update_observer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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())
},
)
Expand Down
9 changes: 8 additions & 1 deletion x/observer/keeper/observer_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d1ef60d

Please sign in to comment.