Documentation
¶
Overview ¶
Package testutil provides common test helper utilities for the Dingo project. It replaces ad-hoc time.Sleep patterns with deterministic synchronization helpers that make tests faster and more reliable.
Index ¶
- Constants
- func BuildDecodableConwayBlockBytes(t *testing.T, slot, blockNumber uint64) []byte
- func FreePort(t *testing.T) string
- func GenerateTestTLSCertKey(t *testing.T) (certPath, keyPath string)
- func InsecureHTTPClient() *http.Client
- func RequireNoReceive[T any](t *testing.T, ch <-chan T, duration time.Duration, msg string)
- func RequireReceive[T any](t *testing.T, ch <-chan T, timeout time.Duration, msg string) T
- func RestrictFileToCurrentUser(t testing.TB, path string)
- func WaitForCondition(t *testing.T, condition func() bool, timeout time.Duration, msg string)
- func WaitForConditionWithInterval(t *testing.T, condition func() bool, timeout time.Duration, ...)
- type MockInput
Constants ¶
const BindAttempts = 8
BindAttempts bounds how many ports a test tries before giving up when racing another process for a loopback port (see FreePort). Shared by every built-in API provider's TLS/auth test suite (Blockfrost, Mesh, UTxO RPC).
Variables ¶
This section is empty.
Functions ¶
func BuildDecodableConwayBlockBytes ¶ added in v0.70.0
BuildDecodableConwayBlockBytes constructs a minimal, valid (10-field header), individually decodable Conway block with a correct block body hash and empty transaction components, for the given slot and block number. It is shared by tests across packages (database/models, ledger) that need a cheap, uniquely-identifiable, real Conway block rather than a hand-rolled mock.
func FreePort ¶ added in v0.70.0
FreePort reserves a loopback port and releases it, returning the bound address ("host:port"). The port is not guaranteed to still be free when the caller binds it -- retry up to BindAttempts times instead of treating one bind failure as a test failure.
func GenerateTestTLSCertKey ¶ added in v0.70.0
GenerateTestTLSCertKey generates a throwaway self-signed certificate/key pair valid for 127.0.0.1 and writes them as PEM files under a fresh t.TempDir(), returning their paths. Used to exercise a listener's TLS startup path (Blockfrost, Mesh, UTxORPC, Bark) without depending on any fixed certificate checked into the repo.
func InsecureHTTPClient ¶ added in v0.70.0
InsecureHTTPClient returns an *http.Client that skips TLS certificate verification, for exercising a listener's throwaway self-signed test certificate (see GenerateTestTLSCertKey).
func RequireNoReceive ¶
RequireNoReceive verifies that no value is received on the given channel within the specified duration. This replaces the pattern of time.Sleep followed by a non-blocking channel read to confirm that nothing was sent.
func RequireReceive ¶
RequireReceive waits for a value on the given channel or fails the test if the timeout expires. This replaces the common pattern of time.Sleep followed by reading a channel.
func RestrictFileToCurrentUser ¶ added in v0.70.0
RestrictFileToCurrentUser makes a test fixture acceptable to secret-key permission checks on Unix.
func WaitForCondition ¶
WaitForCondition polls the given condition function until it returns true or the timeout expires. This replaces the common pattern of time.Sleep followed by an assertion check.
Types ¶
type MockInput ¶ added in v0.37.0
MockInput is a reusable transaction input for database tests.
func NewMockInput ¶ added in v0.37.0
func (*MockInput) Id ¶ added in v0.37.0
func (m *MockInput) Id() lcommon.Blake2b256
func (*MockInput) ToPlutusData ¶ added in v0.37.0
func (m *MockInput) ToPlutusData() pdata.PlutusData