Add tests for fixed network behavior #96
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
fixednetwork implementation used bytlock.periodandgenesisbehave as expected.ChainHash,PublicKey,Scheme) return the configured values.SetSignature/SignatureandSwitchChainHashbehave as expected.NewNetwork.Problem
The
tlock/networks/fixedpackage provides aNetworkimplementation that:genesistime andperiod.ChainHash()andScheme().However, most of the generated tests in
fixed_test.gowere left as emptyscaffolds with
// TODO: Add test cases.. That meant there was no coveragefor the core behavior of the fixed network implementation, including basic
accessors and the
NewNetworkconstructor.Changes
File:
networks/fixed/fixed_test.goTestNetwork_ChainHashNetworkwith a knownchainHashand asserts that
ChainHash()returns that value.TestNetwork_Currentgenesistime,Currentreturns round1.periodaftergenesis,Currentreturns round2.TestNetwork_RoundNumberRoundNumber:genesistime,RoundNumberreturns round1.genesis,RoundNumberreturns round3.TestNetwork_PublicKeyNetworkwith a non-nilpublicKeyand assert thatPublicKey()returns the samekyber.Point.TestNetwork_Schemeschemeon theNetworkand asserts thatScheme()returns the same value (by value, not by pointer).TestNetwork_SetSignatureSetSignaturewith a byte slice and then assert thatSignature()returns the same slice without error.TestNetwork_Signaturenil, no error)and the “signature set” case (returns the configured bytes, no error).
TestNetwork_SwitchChainHashSwitchChainHashupdates the internalchainHashfieldand returns
nilfor a normal update.TestNewNetworkcrypto.UnchainedSchemeID) to confirmthat
NewNetworksucceeds and populates fields likechainHash,period, andgenesisas expected.NewNetworkreturnsErrNotUnchainedand noNetworkinstance.These tests are intentionally simple and deterministic: they use fixed
genesistimestamps andperioddurations to avoid relying on wall-clocktime 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
fixednetwork implementation.Testing
From the
tlockmodule:This runs:
github.com/drand/tlockgithub.com/drand/tlock/networks/fixedgithub.com/drand/tlock/networks/httpgithub.com/drand/tlock/cmd/tle/commandsand passes with the new tests in place.