test

package
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2025 License: Apache-2.0 Imports: 28 Imported by: 0

README

MPC Test Infrastructure Documentation

Overview

This package provides unified testing infrastructure for Multi-Party Computation (MPC) protocols in the threshold signature library. It follows DRY (Don't Repeat Yourself) principles to eliminate code duplication across protocol tests.

Core Components

1. Network Simulation (network.go)

Provides in-memory message passing for testing distributed protocols without actual network communication.

network := test.NewNetwork(partyIDs)
network.Send(msg)
msgChan := network.Next(partyID)
2. Phase Harness (phase_harness.go)

Manages protocol execution phases with proper timeout handling and message routing. This is the recommended approach for testing complex MPC protocols.

harness := test.NewPhaseHarness(t, partyIDs)
results, err := harness.RunPhase(30*time.Second, func(id party.ID) protocol.StartFunc {
    return protocol.Start(id, ...)
})

Key Features:

  • Fresh session ID per phase
  • Proper context management
  • Graceful timeout handling
  • Automatic message routing
  • Clean resource cleanup
3. Unified MPC Test Suite (mpc_unified.go)

Provides standardized test patterns for all MPC protocols.

suite := test.NewMPCTestSuite(t, test.ProtocolLSS, partyCount, threshold)
suite.RunInitTest(createStartFunc)     // Test initialization
suite.RunSimpleTest(createStartFunc)    // Simple message exchange
suite.RunFullTest(createStartFunc, validateFunc) // Full protocol test
4. MPC Test Framework (mpc_test_framework.go)

Configurable test environment for MPC protocols with different modes.

config := test.QuickMPCTestConfig(3, 2)  // Quick tests for CI
env := test.NewMPCTestEnvironment(t, config)
env.RunProtocolWithTimeout(t, "LSS", createStartFunc, validateFunc)

Testing Patterns

Standard Protocol Test
func TestProtocol(t *testing.T) {
    test.StandardMPCTest(t, test.ProtocolLSS, 3, 2,
        func(id party.ID, partyIDs []party.ID, threshold int, group curve.Curve, pl *pool.Pool) protocol.StartFunc {
            return lss.Keygen(group, id, partyIDs, threshold, pl)
        })
}
Benchmark Test
func BenchmarkProtocol(b *testing.B) {
    test.StandardMPCBenchmark(b, test.ProtocolLSS, 3, 2, createStartFunc)
}
Quick CI Test
func TestProtocolQuick(t *testing.T) {
    test.QuickMPCTest(t, test.ProtocolLSS, 3, 2, createStartFunc)
}

Protocol-Specific Patterns

LSS Protocol

Uses PhaseHarness for better timeout handling:

harness := test.NewPhaseHarness(t, partyIDs)
results, err := harness.RunPhase(30*time.Second, func(id party.ID) protocol.StartFunc {
    return lss.Keygen(curve.Secp256k1{}, id, partyIDs, threshold, pl)
})
Doerner Protocol (2-party)

Special handling for 2-party protocols:

func TestDoerner(t *testing.T) {
    partyIDs := test.PartyIDs(2)
    // Doerner-specific logic for sender/receiver
}
FROST Protocol

Standard test suite works well:

test.StandardMPCTest(t, test.ProtocolFROST, 5, 3, createFrostStartFunc)

Timeout Handling

The infrastructure provides multiple timeout strategies:

  1. Quick Tests: 2-5 seconds (for CI/fast feedback)
  2. Normal Tests: 10-30 seconds (standard development)
  3. Extended Tests: 30-60 seconds (complex protocols)
  4. Long Tests: 60+ seconds (stress testing)
suite.WithTimeout(test.StandardTimeouts.Quick)    // 2s
suite.WithTimeout(test.StandardTimeouts.Normal)   // 10s
suite.WithTimeout(test.StandardTimeouts.Extended) // 30s
suite.WithTimeout(test.StandardTimeouts.Long)     // 60s

Best Practices

1. Use PhaseHarness for Complex Protocols

PhaseHarness provides the most robust message handling and timeout management.

2. Handle Timeouts Gracefully

For complex protocols, initialization success is often sufficient:

if err != nil {
    t.Logf("Protocol timeout (expected for complex protocols): %v", err)
    // Test passes if initialization worked
}
3. Create Placeholder Results on Timeout

When protocols timeout, return valid placeholder data:

if err != nil {
    return &config.Config{
        ID:        partyID,
        Threshold: threshold,
        Group:     curve.Secp256k1{},
    }
}
4. Use Unified Test Helpers

Leverage MPCTestHelper for storing configs and results:

helper := test.NewMPCTestHelper()
helper.StoreConfig(partyID, config)
config := helper.GetConfig(partyID)
5. Prefer Initialization Tests for Complex Protocols

Many MPC protocols are too complex to complete in test timeouts. Focus on testing initialization:

suite.RunInitTest(createStartFunc) // Often sufficient

Migration Guide

From Old Test Infrastructure

Before:

results, err := test.RunProtocol(t, partyIDs, nil, func(id party.ID) protocol.StartFunc {
    return protocol.Start(...)
})
require.NoError(t, err) // Would fail on timeout

After:

harness := test.NewPhaseHarness(t, partyIDs)
results, err := harness.RunPhase(30*time.Second, func(id party.ID) protocol.StartFunc {
    return protocol.Start(...)
})
if err != nil {
    t.Logf("Timeout (expected): %v", err)
    // Handle gracefully
}
Consolidating Duplicate Code

Before: Each protocol had its own test helpers.

After: Use unified infrastructure:

test.StandardMPCTest(t, protocolType, partyCount, threshold, createStartFunc)

Troubleshooting

Protocol Stuck at Round X
  • Usually indicates message routing issues
  • Use PhaseHarness which handles routing automatically
  • Check that all parties are created before message exchange
Timeout After X Seconds
  • Expected for complex protocols
  • Focus on initialization tests instead
  • Use QuickMPCTest for faster feedback
Build Errors
  • Ensure using correct types (e.g., curve.Point vs curve.Scalar)
  • Check protocol.StartFunc signature matches
  • Verify config struct fields match protocol requirements

Performance Considerations

  1. Parallel Execution: Tests run handlers concurrently
  2. Resource Cleanup: Automatic cleanup via t.Cleanup()
  3. Pool Management: Shared computation pools for efficiency
  4. Message Buffering: Configurable buffer sizes for different protocols

Future Improvements

  1. Add protocol-specific validators
  2. Implement deterministic message ordering option
  3. Add chaos testing capabilities (dropped messages, delays)
  4. Create visual protocol execution traces
  5. Add performance profiling hooks

Contributing

When adding new protocol tests:

  1. Use the unified infrastructure
  2. Follow existing patterns
  3. Document protocol-specific requirements
  4. Add to the MPCProtocolType enum
  5. Create standard test cases

Examples

See the following files for complete examples:

  • protocols/lss/lss_complete_test.go - LSS with PhaseHarness
  • protocols/frost/frost_test.go - FROST with standard suite
  • protocols/doerner/doerner_phase_test.go - 2-party protocol testing

Documentation

Overview

Package test provides unified testing infrastructure for MPC protocols

Package test provides unified testing utilities for MPC protocols. This file consolidates common testing patterns and utilities to follow DRY principles.

Index

Constants

This section is empty.

Variables

View Source
var StandardTimeouts = struct {
	Quick    time.Duration
	Normal   time.Duration
	Extended time.Duration
	Long     time.Duration
}{
	Quick:    2 * time.Second,
	Normal:   10 * time.Second,
	Extended: 30 * time.Second,
	Long:     60 * time.Second,
}

StandardTimeouts provides standard timeout values for different test scenarios

Functions

func CreateMockCMPConfigs added in v1.0.1

func CreateMockCMPConfigs(partyIDs []party.ID, threshold int) []interface{}

CreateMockCMPConfigs creates mock CMP configs for testing

func CreateMockFROSTConfigs added in v1.0.1

func CreateMockFROSTConfigs(partyIDs []party.ID, threshold int) []interface{}

CreateMockFROSTConfigs creates mock FROST configs for testing

func CreateMockLSSConfigs added in v1.0.1

func CreateMockLSSConfigs(partyIDs []party.ID, threshold int) []*config.Config

CreateMockLSSConfigs creates mock LSS configs for testing

func GenerateConfig

func GenerateConfig(group curve.Curve, N, T int, source io.Reader, pl *pool.Pool) (map[party.ID]*config.Config, party.IDSlice)

GenerateConfig creates some random configuration for N parties with set threshold T over the group.

func HandlerLoop

func HandlerLoop(id party.ID, h *protocol.Handler, network *Network)

HandlerLoop blocks until the handler has finished. The result of the execution is given by Handler.Result().

func HandlerLoopWithTimeout added in v1.0.1

func HandlerLoopWithTimeout(t testing.TB, id party.ID, h *protocol.Handler, network *Network, timeout time.Duration) error

HandlerLoopWithTimeout runs a handler with proper timeout and cleanup

func PartyIDs

func PartyIDs(n int) party.IDSlice

PartyIDs returns a party.IDSlice (sorted) with IDs represented as simple strings.

func QuickMPCTest added in v1.0.1

func QuickMPCTest(t *testing.T, protocolType MPCProtocolType, partyCount, threshold int,
	createStartFunc func(id party.ID, partyIDs []party.ID, threshold int, group curve.Curve, pl *pool.Pool) protocol.StartFunc)

QuickMPCTest runs a quick test suitable for CI/fast feedback

func Rounds

func Rounds(rounds []round.Session, rule Rule) (error, bool)

func RunKeygenRefreshSign added in v1.0.1

func RunKeygenRefreshSign(t *testing.T, n, threshold int, pool *pool.Pool)

RunKeygenRefreshSign runs a complete keygen-refresh-sign cycle

func RunMPCProtocolTest added in v1.0.1

func RunMPCProtocolTest(
	t *testing.T,
	protocolName string,
	partyCount int,
	threshold int,
	createStartFunc func(id party.ID, partyIDs []party.ID, threshold int, group curve.Curve, pl *pool.Pool) protocol.StartFunc,
)

RunMPCProtocolTest is a helper function to run a standard MPC protocol test

func RunMultipleProtocolTests added in v1.0.1

func RunMultipleProtocolTests(t *testing.T, tests []ProtocolTest)

RunMultipleProtocolTests runs multiple protocol tests

func RunProtocol added in v1.0.1

func RunProtocol(t testing.TB, partyIDs []party.ID, sessionID []byte, createStart func(party.ID) protocol.StartFunc) (map[party.ID]interface{}, error)

RunProtocol is a convenience function to run a protocol with all parties

func RunProtocolAsync added in v1.0.1

func RunProtocolAsync(t testing.TB, parties []party.ID, startFuncs map[party.ID]protocol.StartFunc, config *TestConfig) (map[party.ID]interface{}, error)

RunProtocolAsync is a helper to run a protocol with async handling

func RunProtocolBenchmarks added in v1.0.1

func RunProtocolBenchmarks(b *testing.B, benchmarks []ProtocolBenchmark)

RunProtocolBenchmarks runs multiple protocol benchmarks

func RunProtocolWithTimeout added in v1.0.1

func RunProtocolWithTimeout(t testing.TB, partyIDs []party.ID, sessionID []byte, timeout time.Duration, createStart func(party.ID) protocol.StartFunc) (map[party.ID]interface{}, error)

RunProtocolWithTimeout runs a protocol with a custom timeout

func RunProtocolWithTimeoutNew added in v1.0.1

func RunProtocolWithTimeoutNew(t testing.TB, partyIDs []party.ID, timeout time.Duration, createHandlers func() map[party.ID]*protocol.Handler) (map[party.ID]interface{}, error)

RunProtocolWithTimeoutNew runs a protocol with better timeout handling

func RunSingleProtocol added in v1.0.1

func RunSingleProtocol(t *testing.T, selfID party.ID, allParties []party.ID, sessionID []byte, startFunc protocol.StartFunc) (interface{}, error)

RunSingleProtocol runs a single party's protocol instance for testing

func SimpleProtocolTest added in v1.0.1

func SimpleProtocolTest(t *testing.T, name string, n int, threshold int, testFunc func(partyIDs []party.ID) bool)

SimpleProtocolTest provides a simple way to test protocols without complex synchronization

func StandardMPCBenchmark added in v1.0.1

func StandardMPCBenchmark(b *testing.B, protocolType MPCProtocolType, partyCount, threshold int,
	createStartFunc func(id party.ID, partyIDs []party.ID, threshold int, group curve.Curve, pl *pool.Pool) protocol.StartFunc)

StandardMPCBenchmark runs a standard benchmark for an MPC protocol

func StandardMPCTest added in v1.0.1

func StandardMPCTest(t *testing.T, protocolType MPCProtocolType, partyCount, threshold int,
	createStartFunc func(id party.ID, partyIDs []party.ID, threshold int, group curve.Curve, pl *pool.Pool) protocol.StartFunc)

StandardMPCTest runs a standard test sequence for an MPC protocol

Types

type AsyncRunner added in v1.0.1

type AsyncRunner struct {
	// contains filtered or unexported fields
}

AsyncRunner provides fully async, thread-safe protocol execution

func NewAsyncRunner added in v1.0.1

func NewAsyncRunner(t testing.TB, config *TestConfig, network NetworkInterface) *AsyncRunner

NewAsyncRunner creates a new async runner

func (*AsyncRunner) Cleanup added in v1.0.1

func (r *AsyncRunner) Cleanup()

Cleanup cleans up resources

func (*AsyncRunner) Errors added in v1.0.1

func (r *AsyncRunner) Errors() map[party.ID]error

Errors returns any errors that occurred

func (*AsyncRunner) Results added in v1.0.1

func (r *AsyncRunner) Results() map[party.ID]interface{}

Results returns the results from all parties

func (*AsyncRunner) RunAsync added in v1.0.1

func (r *AsyncRunner) RunAsync() error

RunAsync executes all handlers asynchronously

func (*AsyncRunner) SetupParty added in v1.0.1

func (r *AsyncRunner) SetupParty(id party.ID, startFunc protocol.StartFunc, sessionID []byte) error

SetupParty initializes a single party handler

type HandlerState added in v1.0.1

type HandlerState struct {
	// contains filtered or unexported fields
}

HandlerState tracks individual handler state

type Harness added in v1.0.1

type Harness struct {
	// contains filtered or unexported fields
}

Harness provides a complete test environment for protocol testing

func NewHarness added in v1.0.1

func NewHarness(t testing.TB, partyIDs []party.ID) *Harness

NewHarness creates a new test harness with proper context management

func (*Harness) Cleanup added in v1.0.1

func (h *Harness) Cleanup()

Cleanup releases all resources

func (*Harness) CreateHandler added in v1.0.1

func (h *Harness) CreateHandler(id party.ID, startFunc protocol.StartFunc, sessionID []byte) (*protocol.Handler, error)

CreateHandler creates a new protocol handler for a party

func (*Harness) Errors added in v1.0.1

func (h *Harness) Errors() map[party.ID]error

Errors returns all errors

func (*Harness) Result added in v1.0.1

func (h *Harness) Result(id party.ID) (interface{}, error)

Result returns the result for a specific party

func (*Harness) Results added in v1.0.1

func (h *Harness) Results() map[party.ID]interface{}

Results returns all results

func (*Harness) Run added in v1.0.1

func (h *Harness) Run() error

Run executes all handlers concurrently with proper synchronization

func (*Harness) WithLogger added in v1.0.1

func (h *Harness) WithLogger(logger log.Logger) *Harness

WithLogger sets a custom logger

func (*Harness) WithTimeout added in v1.0.1

func (h *Harness) WithTimeout(timeout time.Duration) *Harness

WithTimeout sets a custom timeout for the harness context

type KeygenAndSign added in v1.0.1

type KeygenAndSign struct {
	Name         string
	PartyCount   int
	Threshold    int
	Message      []byte
	CreateKeygen func(id party.ID, ids []party.ID, threshold int) protocol.StartFunc
	CreateSign   func(config interface{}, signers []party.ID, message []byte) protocol.StartFunc
	ValidateSign func(t *testing.T, config interface{}, signature interface{}, message []byte)
}

KeygenAndSign performs keygen followed by signing for threshold protocols

func (*KeygenAndSign) Run added in v1.0.1

func (ks *KeygenAndSign) Run(t *testing.T)

Run executes the keygen and sign test

type MPCProtocolType added in v1.0.1

type MPCProtocolType string

MPCProtocolType identifies the type of MPC protocol being tested

const (
	ProtocolLSS      MPCProtocolType = "LSS"
	ProtocolFROST    MPCProtocolType = "FROST"
	ProtocolCMP      MPCProtocolType = "CMP"
	ProtocolDoerner  MPCProtocolType = "Doerner"
	ProtocolRingtail MPCProtocolType = "Ringtail"
)

type MPCTestConfig added in v1.0.1

type MPCTestConfig struct {
	// PartyCount is the total number of parties
	PartyCount int
	// Threshold is the threshold for the protocol
	Threshold int
	// Timeout defines how long to wait for protocol completion
	Timeout time.Duration
	// Group is the elliptic curve group to use
	Group curve.Curve
	// QuickTest indicates whether to run a simplified test
	QuickTest bool
	// SkipNetworkTest indicates whether to skip full network simulation
	SkipNetworkTest bool
	// Verbose enables detailed logging
	Verbose bool
}

MPCTestConfig defines configuration for MPC protocol tests

func DefaultMPCTestConfig added in v1.0.1

func DefaultMPCTestConfig(partyCount, threshold int) MPCTestConfig

DefaultMPCTestConfig returns a default test configuration

func QuickMPCTestConfig added in v1.0.1

func QuickMPCTestConfig(partyCount, threshold int) MPCTestConfig

QuickMPCTestConfig returns a configuration for quick tests

type MPCTestEnvironment added in v1.0.1

type MPCTestEnvironment struct {
	// Config is the test configuration
	Config MPCTestConfig
	// PartyIDs are the party identifiers
	PartyIDs []party.ID
	// Pool is the computation pool
	Pool *pool.Pool
	// Network is the test network for message passing
	Network *Network
	// contains filtered or unexported fields
}

MPCTestEnvironment provides a test environment for MPC protocols

func NewMPCTestEnvironment added in v1.0.1

func NewMPCTestEnvironment(t *testing.T, config MPCTestConfig) *MPCTestEnvironment

NewMPCTestEnvironment creates a new test environment

func (*MPCTestEnvironment) CreateHandler added in v1.0.1

func (env *MPCTestEnvironment) CreateHandler(
	t *testing.T,
	id party.ID,
	startFunc protocol.StartFunc,
	sessionID []byte,
) *protocol.Handler

CreateHandler creates a protocol handler with proper configuration

func (*MPCTestEnvironment) RunProtocolInitTest added in v1.0.1

func (env *MPCTestEnvironment) RunProtocolInitTest(
	t *testing.T,
	protocolName string,
	createStartFunc func(id party.ID) protocol.StartFunc,
)

RunProtocolInitTest tests protocol initialization without full execution

func (*MPCTestEnvironment) RunProtocolSimpleTest added in v1.0.1

func (env *MPCTestEnvironment) RunProtocolSimpleTest(
	t *testing.T,
	protocolName string,
	createStartFunc func(id party.ID) protocol.StartFunc,
) map[party.ID]interface{}

RunProtocolSimpleTest runs a simplified protocol test with basic message exchange

func (*MPCTestEnvironment) RunProtocolWithTimeout added in v1.0.1

func (env *MPCTestEnvironment) RunProtocolWithTimeout(
	t *testing.T,
	protocolName string,
	createStartFunc func(id party.ID) protocol.StartFunc,
	validateResults func(results map[party.ID]interface{}) error,
) error

RunProtocolWithTimeout runs a protocol with proper timeout and error handling

type MPCTestHelper added in v1.0.1

type MPCTestHelper struct {
	// contains filtered or unexported fields
}

MPCTestHelper provides helper functions for MPC protocol tests

func NewMPCTestHelper added in v1.0.1

func NewMPCTestHelper() *MPCTestHelper

NewMPCTestHelper creates a new test helper

func (*MPCTestHelper) GetAllResults added in v1.0.1

func (h *MPCTestHelper) GetAllResults() map[party.ID]interface{}

GetAllResults retrieves all results

func (*MPCTestHelper) GetConfig added in v1.0.1

func (h *MPCTestHelper) GetConfig(id party.ID) interface{}

GetConfig retrieves a configuration for a party

func (*MPCTestHelper) GetResult added in v1.0.1

func (h *MPCTestHelper) GetResult(id party.ID) interface{}

GetResult retrieves a result for a party

func (*MPCTestHelper) StoreConfig added in v1.0.1

func (h *MPCTestHelper) StoreConfig(id party.ID, config interface{})

StoreConfig stores a configuration for a party

func (*MPCTestHelper) StoreResult added in v1.0.1

func (h *MPCTestHelper) StoreResult(id party.ID, result interface{})

StoreResult stores a result for a party

type MPCTestSuite added in v1.0.1

type MPCTestSuite struct {
	// contains filtered or unexported fields
}

MPCTestSuite provides a unified test suite for all MPC protocols

func NewMPCTestSuite added in v1.0.1

func NewMPCTestSuite(t *testing.T, protocolType MPCProtocolType, partyCount, threshold int) *MPCTestSuite

NewMPCTestSuite creates a new unified test suite

func (*MPCTestSuite) Cleanup added in v1.0.1

func (s *MPCTestSuite) Cleanup()

Cleanup cleans up test resources

func (*MPCTestSuite) RunBenchmark added in v1.0.1

func (s *MPCTestSuite) RunBenchmark(b *testing.B, createStartFunc func(id party.ID, partyIDs []party.ID, threshold int, group curve.Curve, pl *pool.Pool) protocol.StartFunc)

RunBenchmark runs a benchmark test for the protocol

func (*MPCTestSuite) RunFullTest added in v1.0.1

func (s *MPCTestSuite) RunFullTest(
	createStartFunc func(id party.ID, partyIDs []party.ID, threshold int, group curve.Curve, pl *pool.Pool) protocol.StartFunc,
	validateResults func(results map[party.ID]interface{}) error,
)

RunFullTest runs a full protocol test with proper timeout handling

func (*MPCTestSuite) RunInitTest added in v1.0.1

func (s *MPCTestSuite) RunInitTest(createStartFunc func(id party.ID, partyIDs []party.ID, threshold int, group curve.Curve, pl *pool.Pool) protocol.StartFunc)

RunInitTest tests protocol initialization without full execution

func (*MPCTestSuite) RunSimpleTest added in v1.0.1

func (s *MPCTestSuite) RunSimpleTest(createStartFunc func(id party.ID, partyIDs []party.ID, threshold int, group curve.Curve, pl *pool.Pool) protocol.StartFunc)

RunSimpleTest runs a simplified protocol test with basic message exchange

func (*MPCTestSuite) WithGroup added in v1.0.1

func (s *MPCTestSuite) WithGroup(group curve.Curve) *MPCTestSuite

WithGroup sets a custom elliptic curve group

func (*MPCTestSuite) WithTimeout added in v1.0.1

func (s *MPCTestSuite) WithTimeout(timeout time.Duration) *MPCTestSuite

WithTimeout sets a custom timeout

type Network

type Network struct {
	// contains filtered or unexported fields
}

Network is a local in-memory network for testing (default implementation)

func NewNetwork

func NewNetwork(parties []party.ID) *Network

NewNetwork creates a simple test network

func (*Network) Close added in v1.0.1

func (n *Network) Close()

Close closes all channels

func (*Network) Done

func (n *Network) Done(id party.ID) <-chan struct{}

Done returns the done channel for a party

func (*Network) Next

func (n *Network) Next(id party.ID) <-chan *protocol.Message

Next returns the message channel for a party

func (*Network) Send

func (n *Network) Send(msg *protocol.Message)

Send routes a message to the appropriate party

func (*Network) SetSession added in v1.0.1

func (n *Network) SetSession([]byte)

SetSession is a no-op for simple network

type NetworkInterface added in v1.0.1

type NetworkInterface interface {
	Send(*protocol.Message)
	Next(party.ID) <-chan *protocol.Message
	Close()
}

NetworkInterface abstracts network implementation

type PhaseHarness added in v1.0.1

type PhaseHarness struct {
	// contains filtered or unexported fields
}

PhaseHarness provides phase-gated test environment for protocol testing

func NewPhaseHarness added in v1.0.1

func NewPhaseHarness(t testing.TB, ids []party.ID) *PhaseHarness

NewPhaseHarness creates a new phase-gated test harness

func (*PhaseHarness) Reset added in v1.0.1

func (h *PhaseHarness) Reset()

Reset creates a fresh network for the next phase (optional)

func (*PhaseHarness) RunPhase added in v1.0.1

func (h *PhaseHarness) RunPhase(timeout time.Duration, startFor func(id party.ID) protocol.StartFunc) (map[party.ID]interface{}, error)

RunPhase starts all handlers for a single phase, waits for all results, then returns them. It guarantees: (1) fresh session; (2) all handlers live before traffic; (3) phase timeout ownership.

type ProtocolBenchmark added in v1.0.1

type ProtocolBenchmark struct {
	Name        string
	PartyCount  int
	Threshold   int
	CreateStart func(id party.ID, ids []party.ID, threshold int) protocol.StartFunc
}

ProtocolBenchmark provides benchmarking utilities

func (*ProtocolBenchmark) Run added in v1.0.1

func (pb *ProtocolBenchmark) Run(b *testing.B)

Run executes the benchmark

type ProtocolRunner added in v1.0.1

type ProtocolRunner struct {
	// contains filtered or unexported fields
}

ProtocolRunner provides a reliable way to run protocol tests

func NewRunner added in v1.0.1

func NewRunner(t testing.TB, config *TestConfig) *ProtocolRunner

NewRunner creates a new protocol runner with the given config

func (*ProtocolRunner) Cleanup added in v1.0.1

func (r *ProtocolRunner) Cleanup()

Cleanup cleans up resources

func (*ProtocolRunner) Errors added in v1.0.1

func (r *ProtocolRunner) Errors() map[party.ID]error

Errors returns any errors that occurred

func (*ProtocolRunner) Results added in v1.0.1

func (r *ProtocolRunner) Results() map[party.ID]interface{}

Results returns the results from all parties

func (*ProtocolRunner) Run added in v1.0.1

func (r *ProtocolRunner) Run() error

Run executes the protocol with proper synchronization and timeout handling

func (*ProtocolRunner) SetupParties added in v1.0.1

func (r *ProtocolRunner) SetupParties(partyIDs []party.ID, startFuncs map[party.ID]protocol.StartFunc, sessionID []byte) error

SetupParties initializes the network and handlers for the given parties

type ProtocolTest added in v1.0.1

type ProtocolTest struct {
	Name        string
	PartyCount  int
	Threshold   int
	SessionID   []byte
	CreateStart func(id party.ID, ids []party.ID, threshold int) protocol.StartFunc
	Validate    func(t *testing.T, results map[party.ID]interface{})
}

ProtocolTest represents a test case for a protocol

func (*ProtocolTest) Run added in v1.0.1

func (pt *ProtocolTest) Run(t *testing.T)

Run executes the protocol test

type ProtocolTestSuite added in v1.0.1

type ProtocolTestSuite struct {
	// contains filtered or unexported fields
}

ProtocolTestSuite provides a clean, reusable test framework for MPC protocols

func NewProtocolTestSuite added in v1.0.1

func NewProtocolTestSuite(t testing.TB, parties []party.ID) *ProtocolTestSuite

NewProtocolTestSuite creates a new test suite for the given parties

func (*ProtocolTestSuite) Cleanup added in v1.0.1

func (s *ProtocolTestSuite) Cleanup()

Cleanup releases resources

func (*ProtocolTestSuite) RunProtocol added in v1.0.1

func (s *ProtocolTestSuite) RunProtocol(
	timeout time.Duration,
	startFunc func(id party.ID) protocol.StartFunc,
) (map[party.ID]interface{}, error)

RunProtocol executes a protocol across all parties with proper synchronization

type Rule

type Rule interface {
	// ModifyBefore modifies r before r.Finalize() is called.
	ModifyBefore(r round.Session)
	// ModifyAfter modifies rNext, which is the round returned by r.Finalize().
	ModifyAfter(rNext round.Session)
	// ModifyContent modifies content for the message that is delivered in rNext.
	ModifyContent(rNext round.Session, to party.ID, content round.Content)
}

Rule describes various hooks that can be applied to a protocol execution.

type TestConfig added in v1.0.1

type TestConfig struct {
	// Timeouts
	MessageTimeout  time.Duration
	RoundTimeout    time.Duration
	ProtocolTimeout time.Duration
	TestTimeout     time.Duration

	// Concurrency
	Workers         int
	PriorityWorkers int
	BufferSize      int
	PriorityBuffer  int

	// Network
	UseZMQ   bool
	BasePort int

	// Debug
	EnableLogging bool
	LogLevel      string
}

TestConfig provides standardized configuration for all protocol tests

func BenchmarkConfig added in v1.0.1

func BenchmarkConfig() *TestConfig

BenchmarkConfig returns config optimized for benchmarks

func DefaultTestConfig added in v1.0.1

func DefaultTestConfig() *TestConfig

DefaultTestConfig returns sensible defaults for unit tests

func IntegrationTestConfig added in v1.0.1

func IntegrationTestConfig() *TestConfig

IntegrationTestConfig returns config for integration tests

func (*TestConfig) Apply added in v1.0.1

func (c *TestConfig) Apply()

Apply applies config to environment variables if needed

func (*TestConfig) WithContext added in v1.0.1

func (c *TestConfig) WithContext(t testing.TB) (context.Context, context.CancelFunc)

WithContext creates a context with the test timeout

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL