diff --git a/pkg/tbtc/heartbeat_test.go b/pkg/tbtc/heartbeat_test.go index 1bbab80b88..3485fd603f 100644 --- a/pkg/tbtc/heartbeat_test.go +++ b/pkg/tbtc/heartbeat_test.go @@ -21,6 +21,8 @@ func TestHeartbeatAction_HappyPath(t *testing.T) { t.Fatal(err) } + walletPublicKeyStr := hex.EncodeToString(walletPublicKeyHex) + startBlock := uint64(10) expiryBlock := startBlock + heartbeatTotalProposalValidityBlocks @@ -31,7 +33,10 @@ func TestHeartbeatAction_HappyPath(t *testing.T) { }, } + // Set the heartbeat failure counter to `1` for the given wallet. The value + // of the counter should be reset to `0` after executing the action. heartbeatFailureCounter := newHeartbeatFailureCounter() + heartbeatFailureCounter.increment(walletPublicKeyStr) // sha256(sha256(messageToSign)) sha256d, err := hex.DecodeString("38d30dacec5083c902952ce99fc0287659ad0b1ca2086827a8e78b0bef2c8bc1") @@ -42,7 +47,10 @@ func TestHeartbeatAction_HappyPath(t *testing.T) { hostChain := Connect() hostChain.setHeartbeatProposalValidationResult(proposal, true) + // Set the active operators count to the minimum required value. mockExecutor := &mockHeartbeatSigningExecutor{} + mockExecutor.activeOperatorsCount = heartbeatSigningMinimumActiveOperators + inactivityClaimExecutor := &inactivityClaimExecutor{} action := newHeartbeatAction( logger, @@ -66,6 +74,12 @@ func TestHeartbeatAction_HappyPath(t *testing.T) { t.Fatal(err) } + testutils.AssertUintsEqual( + t, + "heartbeat failure count", + 0, + uint64(heartbeatFailureCounter.get(walletPublicKeyStr)), + ) testutils.AssertBigIntsEqual( t, "message to sign", @@ -260,7 +274,8 @@ func TestHeartbeatFailureCounter_Get(t *testing.T) { } type mockHeartbeatSigningExecutor struct { - shouldFail bool + shouldFail bool + activeOperatorsCount uint32 requestedMessage *big.Int requestedStartBlock uint64 @@ -279,5 +294,5 @@ func (mhse *mockHeartbeatSigningExecutor) sign( } // TODO: Return the active members count and use it in unit tests. - return &tecdsa.Signature{}, 0, startBlock + 1, nil + return &tecdsa.Signature{}, mhse.activeOperatorsCount, startBlock + 1, nil }