Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Aug 7, 2024
1 parent 2a49bda commit b5e6ed5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
14 changes: 11 additions & 3 deletions x/observer/keeper/msg_server_vote_tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ func (k msgServer) VoteTSS(goCtx context.Context, msg *types.MsgVoteTSS) (*types
}

// Use a separate transaction to update keygen status to pending when trying to change the TSS address.
if keygen.Status == types.KeygenStatus_KeyGenSuccess {
return &types.MsgVoteTSSResponse{}, errorsmod.Wrap(types.ErrKeygenCompleted, voteTSSid)
}
//if keygen.Status == types.KeygenStatus_KeyGenSuccess {
// return &types.MsgVoteTSSResponse{}, errorsmod.Wrap(types.ErrKeygenCompleted, voteTSSid)
//}

// GetBallot checks against the supported chains list before querying for Ballot.
ballotCreated := false
Expand Down Expand Up @@ -94,6 +94,14 @@ func (k msgServer) VoteTSS(goCtx context.Context, msg *types.MsgVoteTSS) (*types
}, nil
}

if keygen.Status != types.KeygenStatus_PendingKeygen {
return &types.MsgVoteTSSResponse{}, nil
}

if msg.KeygenZetaHeight != keygen.BlockNumber {
return &types.MsgVoteTSSResponse{}, nil
}

// Set TSS only on success, set keygen either way.
// Keygen block can be updated using a policy transaction if keygen fails.
keygenSuccess := false
Expand Down
13 changes: 7 additions & 6 deletions x/observer/keeper/msg_server_vote_tss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestMsgServer_VoteTSS(t *testing.T) {
KeygenZetaHeight: 42,
Status: chains.ReceiveStatus_success,
})
require.ErrorIs(t, err, types.ErrKeygenCompleted)
require.NoError(t, err)
})

t.Run("can create a new ballot, vote success and finalize", func(t *testing.T) {
Expand All @@ -74,6 +74,7 @@ func TestMsgServer_VoteTSS(t *testing.T) {
nodeAcc := sample.NodeAccount()
keygen := sample.Keygen(t)
keygen.Status = types.KeygenStatus_PendingKeygen
keygen.BlockNumber = 42
k.SetNodeAccount(ctx, *nodeAcc)
k.SetKeygen(ctx, *keygen)

Expand Down Expand Up @@ -106,6 +107,7 @@ func TestMsgServer_VoteTSS(t *testing.T) {
// setup state
nodeAcc := sample.NodeAccount()
keygen := sample.Keygen(t)
keygen.BlockNumber = 42
keygen.Status = types.KeygenStatus_PendingKeygen
k.SetNodeAccount(ctx, *nodeAcc)
k.SetKeygen(ctx, *keygen)
Expand Down Expand Up @@ -141,6 +143,7 @@ func TestMsgServer_VoteTSS(t *testing.T) {
nodeAcc2 := sample.NodeAccount()
nodeAcc3 := sample.NodeAccount()
keygen := sample.Keygen(t)
keygen.BlockNumber = 42
keygen.Status = types.KeygenStatus_PendingKeygen
tss := sample.Tss()
k.SetNodeAccount(ctx, *nodeAcc1)
Expand Down Expand Up @@ -346,11 +349,9 @@ func TestMsgServer_VoteTSS(t *testing.T) {

newKeygen, found = k.GetKeygen(ctx)
require.True(t, found)
require.EqualValues(t, types.KeygenStatus_KeyGenSuccess, newKeygen.Status)
require.EqualValues(t, types.KeygenStatus_PendingKeygen, newKeygen.Status)

newTss, found := k.GetTSS(ctx)
require.True(t, found)
require.EqualValues(t, tss.TssPubkey, newTss.TssPubkey)
require.EqualValues(t, 42, newTss.KeyGenZetaHeight)
_, found = k.GetTSS(ctx)
require.False(t, found)
})
}

0 comments on commit b5e6ed5

Please sign in to comment.