Skip to content

Conversation

@alienx5499
Copy link
Contributor

Summary

  • Add unit tests for the fixed network implementation used by tlock.
  • Verify that round calculations based on period and genesis behave as expected.
  • Ensure accessor methods (ChainHash, PublicKey, Scheme) return the configured values.
  • Test that SetSignature / Signature and SwitchChainHash behave as expected.
  • Cover allowed and disallowed schemes in NewNetwork.

Problem

The tlock/networks/fixed package provides a Network implementation that:

  • Computes current and specific round numbers from a genesis time and period.
  • Exposes basic metadata such as ChainHash() and Scheme().

However, most of the generated tests in fixed_test.go were left as empty
scaffolds with // TODO: Add test cases.. That meant there was no coverage
for the core behavior of the fixed network implementation, including basic
accessors and the NewNetwork constructor.

Changes

File: networks/fixed/fixed_test.go

  • TestNetwork_ChainHash

    • Add a concrete case that constructs a Network with a known chainHash
      and asserts that ChainHash() returns that value.
  • TestNetwork_Current

    • Add tests to confirm the mapping from time to current round:
      • At genesis time, Current returns round 1.
      • One period after genesis, Current returns round 2.
  • TestNetwork_RoundNumber

    • Add tests to validate RoundNumber:
      • At genesis time, RoundNumber returns round 1.
      • Two periods after genesis, RoundNumber returns round 3.
  • TestNetwork_PublicKey

    • Construct a Network with a non-nil publicKey and assert that
      PublicKey() returns the same kyber.Point.
  • TestNetwork_Scheme

    • Add a case that sets scheme on the Network and asserts that
      Scheme() returns the same value (by value, not by pointer).
  • TestNetwork_SetSignature

    • Call SetSignature with a byte slice and then assert that
      Signature() returns the same slice without error.
  • TestNetwork_Signature

    • Cover both the “no signature set” case (returns nil, no error)
      and the “signature set” case (returns the configured bytes, no error).
  • TestNetwork_SwitchChainHash

    • Verify that SwitchChainHash updates the internal chainHash field
      and returns nil for a normal update.
  • TestNewNetwork

    • Use a supported scheme (e.g. crypto.UnchainedSchemeID) to confirm
      that NewNetwork succeeds and populates fields like chainHash,
      period, and genesis as expected.
    • Use an unsupported scheme name to confirm that NewNetwork returns
      ErrNotUnchained and no Network instance.

These tests are intentionally simple and deterministic: they use fixed
genesis timestamps and period durations to avoid relying on wall-clock
time and to keep the behavior easy to reason about. They also avoid hitting
any real networking or cryptographic randomness, focusing purely on the
logic within the fixed network implementation.

Testing

From the tlock module:

cd tlock
go test ./...

This runs:

  • github.com/drand/tlock
  • github.com/drand/tlock/networks/fixed
  • github.com/drand/tlock/networks/http
  • github.com/drand/tlock/cmd/tle/commands

and passes with the new tests in place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant