Skip to content

Commit

Permalink
Adjusted existing unit tests for heartbeats
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszslabon committed May 14, 2024
1 parent 4e32ec6 commit 5434f36
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions pkg/tbtc/heartbeat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ func TestHeartbeatAction_HappyPath(t *testing.T) {
t.Fatal(err)
}

walletPublicKeyStr := hex.EncodeToString(walletPublicKeyHex)

startBlock := uint64(10)
expiryBlock := startBlock + heartbeatTotalProposalValidityBlocks

Expand All @@ -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")
Expand All @@ -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,
Expand All @@ -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",
Expand Down Expand Up @@ -260,7 +274,8 @@ func TestHeartbeatFailureCounter_Get(t *testing.T) {
}

type mockHeartbeatSigningExecutor struct {
shouldFail bool
shouldFail bool
activeOperatorsCount uint32

requestedMessage *big.Int
requestedStartBlock uint64
Expand All @@ -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
}

0 comments on commit 5434f36

Please sign in to comment.