test

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2020 License: Apache-2.0 Imports: 18 Imported by: 2

Documentation

Overview

Package test contains helpers for testing the client

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alice

type Alice struct {
	Proposer
}

Alice is a Proposer. She proposes the new channel.

func NewAlice

func NewAlice(setup RoleSetup, t *testing.T) *Alice

NewAlice creates a new Proposer that executes the Alice protocol.

func (*Alice) AcceptAllPropHandler added in v0.3.0

func (r *Alice) AcceptAllPropHandler(rng *rand.Rand) *acceptAllPropHandler

AcceptAllPropHandler returns a ProposalHandler that accepts all requests to this Role. The paymentChannel is saved to the Role's state upon acceptal. The rng is used to generate a new random account for accepting the proposal. Next can be called on the handler to wait for the next incoming proposal.

func (*Alice) ChannelProposal added in v0.3.0

func (r *Alice) ChannelProposal(rng *rand.Rand, cfg *ExecConfig) *client.ChannelProposal

func (*Alice) EnableStages added in v0.3.0

func (r *Alice) EnableStages() Stages

EnableStages optionally enables the synchronization of this role at different stages of the Execute protocol. EnableStages should be called on a single role and the resulting slice set on all remaining roles by calling SetStages on them.

func (*Alice) Execute

func (r *Alice) Execute(cfg ExecConfig)

Execute executes the Alice protocol.

func (*Alice) GoHandle added in v0.3.0

func (r *Alice) GoHandle(rng *rand.Rand) (h *acceptAllPropHandler, wait func())

GoHandle starts the handler routine on the current client and returns a wait() function with which it can be waited for the handler routine to stop.

func (*Alice) GoListen added in v0.3.0

func (r *Alice) GoListen(l peer.Listener) (wait func())

GoListen starts the peer listener routine on the current client and returns a wait() function with which it can be waited for the listener routine to stop.

func (*Alice) Idxs added in v0.3.0

func (r *Alice) Idxs(peers [2]peer.Address) (our, their int)

Idxs maps the passed addresses to the indices in the 2-party-channel. If the setup's Identity is not found in peers, Idxs panics.

func (*Alice) OnNewChannel added in v0.3.0

func (r *Alice) OnNewChannel(callback func(ch *paymentChannel))

func (*Alice) ProposeChannel added in v0.3.0

func (r *Alice) ProposeChannel(req *client.ChannelProposal) (*paymentChannel, error)

ProposeChannel sends the channel proposal req. It times out after the timeout specified in the Role's setup.

func (*Alice) SetStages added in v0.3.0

func (r *Alice) SetStages(st Stages)

SetStages optionally sets a slice of WaitGroup barriers to wait on at different stages of the Execute protocol. It should be created by any role by calling EnableStages().

func (*Alice) UpdateHandler added in v0.3.0

func (r *Alice) UpdateHandler() *roleUpdateHandler

type Bob

type Bob struct {
	Responder
}

Bob is a Responder. He accepts an incoming channel proposal.

func NewBob

func NewBob(setup RoleSetup, t *testing.T) *Bob

NewBob creates a new Responder that executes the Bob protocol.

func (*Bob) AcceptAllPropHandler added in v0.3.0

func (r *Bob) AcceptAllPropHandler(rng *rand.Rand) *acceptAllPropHandler

AcceptAllPropHandler returns a ProposalHandler that accepts all requests to this Role. The paymentChannel is saved to the Role's state upon acceptal. The rng is used to generate a new random account for accepting the proposal. Next can be called on the handler to wait for the next incoming proposal.

func (*Bob) ChannelProposal added in v0.3.0

func (r *Bob) ChannelProposal(rng *rand.Rand, cfg *ExecConfig) *client.ChannelProposal

func (*Bob) EnableStages added in v0.3.0

func (r *Bob) EnableStages() Stages

EnableStages optionally enables the synchronization of this role at different stages of the Execute protocol. EnableStages should be called on a single role and the resulting slice set on all remaining roles by calling SetStages on them.

func (*Bob) Execute

func (r *Bob) Execute(cfg ExecConfig)

Execute executes the Bob protocol.

func (*Bob) GoHandle added in v0.3.0

func (r *Bob) GoHandle(rng *rand.Rand) (h *acceptAllPropHandler, wait func())

GoHandle starts the handler routine on the current client and returns a wait() function with which it can be waited for the handler routine to stop.

func (*Bob) GoListen added in v0.3.0

func (r *Bob) GoListen(l peer.Listener) (wait func())

GoListen starts the peer listener routine on the current client and returns a wait() function with which it can be waited for the listener routine to stop.

func (*Bob) Idxs added in v0.3.0

func (r *Bob) Idxs(peers [2]peer.Address) (our, their int)

Idxs maps the passed addresses to the indices in the 2-party-channel. If the setup's Identity is not found in peers, Idxs panics.

func (*Bob) OnNewChannel added in v0.3.0

func (r *Bob) OnNewChannel(callback func(ch *paymentChannel))

func (*Bob) ProposeChannel added in v0.3.0

func (r *Bob) ProposeChannel(req *client.ChannelProposal) (*paymentChannel, error)

ProposeChannel sends the channel proposal req. It times out after the timeout specified in the Role's setup.

func (*Bob) SetStages added in v0.3.0

func (r *Bob) SetStages(st Stages)

SetStages optionally sets a slice of WaitGroup barriers to wait on at different stages of the Execute protocol. It should be created by any role by calling EnableStages().

func (*Bob) UpdateHandler added in v0.3.0

func (r *Bob) UpdateHandler() *roleUpdateHandler

type Carol added in v0.2.0

type Carol struct {
	Responder
}

Carol is a Responder. She accepts an incoming channel proposal.

func NewCarol added in v0.2.0

func NewCarol(setup RoleSetup, t *testing.T) *Carol

NewCarol creates a new Responder that executes the Carol protocol.

func (*Carol) AcceptAllPropHandler added in v0.3.0

func (r *Carol) AcceptAllPropHandler(rng *rand.Rand) *acceptAllPropHandler

AcceptAllPropHandler returns a ProposalHandler that accepts all requests to this Role. The paymentChannel is saved to the Role's state upon acceptal. The rng is used to generate a new random account for accepting the proposal. Next can be called on the handler to wait for the next incoming proposal.

func (*Carol) ChannelProposal added in v0.3.0

func (r *Carol) ChannelProposal(rng *rand.Rand, cfg *ExecConfig) *client.ChannelProposal

func (*Carol) EnableStages added in v0.3.0

func (r *Carol) EnableStages() Stages

EnableStages optionally enables the synchronization of this role at different stages of the Execute protocol. EnableStages should be called on a single role and the resulting slice set on all remaining roles by calling SetStages on them.

func (*Carol) Execute added in v0.2.0

func (r *Carol) Execute(cfg ExecConfig)

Execute executes the Carol protocol.

func (*Carol) GoHandle added in v0.3.0

func (r *Carol) GoHandle(rng *rand.Rand) (h *acceptAllPropHandler, wait func())

GoHandle starts the handler routine on the current client and returns a wait() function with which it can be waited for the handler routine to stop.

func (*Carol) GoListen added in v0.3.0

func (r *Carol) GoListen(l peer.Listener) (wait func())

GoListen starts the peer listener routine on the current client and returns a wait() function with which it can be waited for the listener routine to stop.

func (*Carol) Idxs added in v0.3.0

func (r *Carol) Idxs(peers [2]peer.Address) (our, their int)

Idxs maps the passed addresses to the indices in the 2-party-channel. If the setup's Identity is not found in peers, Idxs panics.

func (*Carol) OnNewChannel added in v0.3.0

func (r *Carol) OnNewChannel(callback func(ch *paymentChannel))

func (*Carol) ProposeChannel added in v0.3.0

func (r *Carol) ProposeChannel(req *client.ChannelProposal) (*paymentChannel, error)

ProposeChannel sends the channel proposal req. It times out after the timeout specified in the Role's setup.

func (*Carol) SetStages added in v0.3.0

func (r *Carol) SetStages(st Stages)

SetStages optionally sets a slice of WaitGroup barriers to wait on at different stages of the Execute protocol. It should be created by any role by calling EnableStages().

func (*Carol) UpdateHandler added in v0.3.0

func (r *Carol) UpdateHandler() *roleUpdateHandler

type ConnHub added in v0.3.0

type ConnHub interface {
	NewListener(addr peer.Address) peer.Listener
	NewDialer() peer.Dialer
}

A ConnHub can be used to create related Listeners and Dialers. This is (almost) fulfilled by the peer/test.ConnHub but in order to be able to use possible other netorking infrastructure for the tests in the future, it is consumed as an interface in the client persistence tests.

type ExecConfig

type ExecConfig struct {
	PeerAddrs  [2]peer.Address // must match the RoleSetup.Identity's
	Asset      channel.Asset   // single Asset to use in this channel
	InitBals   [2]*big.Int     // channel deposit of each role
	NumUpdates [2]int          // how many updates each role sends
	TxAmounts  [2]*big.Int     // amounts that are to be sent by each role
}

ExecConfig contains additional config parameters for the tests.

type Executer added in v0.2.0

type Executer interface {
	// Execute executes the protocol according to the given configuration.
	Execute(cfg ExecConfig)
	// EnableStages enables role synchronization.
	EnableStages() Stages
	// SetStages enables role synchronization using the given stages.
	SetStages(Stages)
}

An Executer is a Role that can execute a protocol.

type Mallory added in v0.2.0

type Mallory struct {
	Proposer
}

Mallory is a test client role. She proposes the new channel.

func NewMallory added in v0.2.0

func NewMallory(setup RoleSetup, t *testing.T) *Mallory

NewMallory creates a new party that executes the Mallory protocol.

func (*Mallory) AcceptAllPropHandler added in v0.3.0

func (r *Mallory) AcceptAllPropHandler(rng *rand.Rand) *acceptAllPropHandler

AcceptAllPropHandler returns a ProposalHandler that accepts all requests to this Role. The paymentChannel is saved to the Role's state upon acceptal. The rng is used to generate a new random account for accepting the proposal. Next can be called on the handler to wait for the next incoming proposal.

func (*Mallory) ChannelProposal added in v0.3.0

func (r *Mallory) ChannelProposal(rng *rand.Rand, cfg *ExecConfig) *client.ChannelProposal

func (*Mallory) EnableStages added in v0.3.0

func (r *Mallory) EnableStages() Stages

EnableStages optionally enables the synchronization of this role at different stages of the Execute protocol. EnableStages should be called on a single role and the resulting slice set on all remaining roles by calling SetStages on them.

func (*Mallory) Execute added in v0.2.0

func (r *Mallory) Execute(cfg ExecConfig)

Execute executes the Mallory protocol.

func (*Mallory) GoHandle added in v0.3.0

func (r *Mallory) GoHandle(rng *rand.Rand) (h *acceptAllPropHandler, wait func())

GoHandle starts the handler routine on the current client and returns a wait() function with which it can be waited for the handler routine to stop.

func (*Mallory) GoListen added in v0.3.0

func (r *Mallory) GoListen(l peer.Listener) (wait func())

GoListen starts the peer listener routine on the current client and returns a wait() function with which it can be waited for the listener routine to stop.

func (*Mallory) Idxs added in v0.3.0

func (r *Mallory) Idxs(peers [2]peer.Address) (our, their int)

Idxs maps the passed addresses to the indices in the 2-party-channel. If the setup's Identity is not found in peers, Idxs panics.

func (*Mallory) OnNewChannel added in v0.3.0

func (r *Mallory) OnNewChannel(callback func(ch *paymentChannel))

func (*Mallory) ProposeChannel added in v0.3.0

func (r *Mallory) ProposeChannel(req *client.ChannelProposal) (*paymentChannel, error)

ProposeChannel sends the channel proposal req. It times out after the timeout specified in the Role's setup.

func (*Mallory) SetStages added in v0.3.0

func (r *Mallory) SetStages(st Stages)

SetStages optionally sets a slice of WaitGroup barriers to wait on at different stages of the Execute protocol. It should be created by any role by calling EnableStages().

func (*Mallory) UpdateHandler added in v0.3.0

func (r *Mallory) UpdateHandler() *roleUpdateHandler

type Petra added in v0.3.0

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

Petra is the Proposer in a Persistence test.

func NewPetra added in v0.3.0

func NewPetra(setup RoleSetup, hub ConnHub, t *testing.T) *Petra

NewPetra creates a new Proposer that executes the Petra protocol.

func (*Petra) Execute added in v0.3.0

func (r *Petra) Execute(cfg ExecConfig)

Execute executes the Petra protocol.

func (*Petra) NewListener added in v0.3.0

func (r *Petra) NewListener() peer.Listener

func (*Petra) ReplaceClient added in v0.3.0

func (r *Petra) ReplaceClient()

ReplaceClient replaces the client instance of the Role. Useful for persistence testing.

type Proposer added in v0.3.0

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

Proposer is a test client role. He proposes the new channel.

func NewProposer added in v0.3.0

func NewProposer(setup RoleSetup, t *testing.T, numStages int) *Proposer

NewProposer creates a new party that executes the Proposer protocol.

func (*Proposer) AcceptAllPropHandler added in v0.3.0

func (r *Proposer) AcceptAllPropHandler(rng *rand.Rand) *acceptAllPropHandler

AcceptAllPropHandler returns a ProposalHandler that accepts all requests to this Role. The paymentChannel is saved to the Role's state upon acceptal. The rng is used to generate a new random account for accepting the proposal. Next can be called on the handler to wait for the next incoming proposal.

func (*Proposer) ChannelProposal added in v0.3.0

func (r *Proposer) ChannelProposal(rng *rand.Rand, cfg *ExecConfig) *client.ChannelProposal

func (*Proposer) EnableStages added in v0.3.0

func (r *Proposer) EnableStages() Stages

EnableStages optionally enables the synchronization of this role at different stages of the Execute protocol. EnableStages should be called on a single role and the resulting slice set on all remaining roles by calling SetStages on them.

func (*Proposer) Execute added in v0.3.0

func (r *Proposer) Execute(cfg ExecConfig, exec func(ExecConfig, *paymentChannel))

Execute executes the Proposer protocol.

func (*Proposer) GoHandle added in v0.3.0

func (r *Proposer) GoHandle(rng *rand.Rand) (h *acceptAllPropHandler, wait func())

GoHandle starts the handler routine on the current client and returns a wait() function with which it can be waited for the handler routine to stop.

func (*Proposer) GoListen added in v0.3.0

func (r *Proposer) GoListen(l peer.Listener) (wait func())

GoListen starts the peer listener routine on the current client and returns a wait() function with which it can be waited for the listener routine to stop.

func (*Proposer) Idxs added in v0.3.0

func (r *Proposer) Idxs(peers [2]peer.Address) (our, their int)

Idxs maps the passed addresses to the indices in the 2-party-channel. If the setup's Identity is not found in peers, Idxs panics.

func (*Proposer) OnNewChannel added in v0.3.0

func (r *Proposer) OnNewChannel(callback func(ch *paymentChannel))

func (*Proposer) ProposeChannel added in v0.3.0

func (r *Proposer) ProposeChannel(req *client.ChannelProposal) (*paymentChannel, error)

ProposeChannel sends the channel proposal req. It times out after the timeout specified in the Role's setup.

func (*Proposer) SetStages added in v0.3.0

func (r *Proposer) SetStages(st Stages)

SetStages optionally sets a slice of WaitGroup barriers to wait on at different stages of the Execute protocol. It should be created by any role by calling EnableStages().

func (*Proposer) UpdateHandler added in v0.3.0

func (r *Proposer) UpdateHandler() *roleUpdateHandler

type Responder added in v0.3.0

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

Responder is a test client role. He accepts an incoming channel proposal.

func NewResponder added in v0.3.0

func NewResponder(setup RoleSetup, t *testing.T, numStages int) *Responder

NewResponder creates a new party that executes the Responder protocol.

func (*Responder) AcceptAllPropHandler added in v0.3.0

func (r *Responder) AcceptAllPropHandler(rng *rand.Rand) *acceptAllPropHandler

AcceptAllPropHandler returns a ProposalHandler that accepts all requests to this Role. The paymentChannel is saved to the Role's state upon acceptal. The rng is used to generate a new random account for accepting the proposal. Next can be called on the handler to wait for the next incoming proposal.

func (*Responder) ChannelProposal added in v0.3.0

func (r *Responder) ChannelProposal(rng *rand.Rand, cfg *ExecConfig) *client.ChannelProposal

func (*Responder) EnableStages added in v0.3.0

func (r *Responder) EnableStages() Stages

EnableStages optionally enables the synchronization of this role at different stages of the Execute protocol. EnableStages should be called on a single role and the resulting slice set on all remaining roles by calling SetStages on them.

func (*Responder) Execute added in v0.3.0

func (r *Responder) Execute(cfg ExecConfig, exec func(ExecConfig, *paymentChannel))

Execute executes the Responder protocol.

func (*Responder) GoHandle added in v0.3.0

func (r *Responder) GoHandle(rng *rand.Rand) (h *acceptAllPropHandler, wait func())

GoHandle starts the handler routine on the current client and returns a wait() function with which it can be waited for the handler routine to stop.

func (*Responder) GoListen added in v0.3.0

func (r *Responder) GoListen(l peer.Listener) (wait func())

GoListen starts the peer listener routine on the current client and returns a wait() function with which it can be waited for the listener routine to stop.

func (*Responder) Idxs added in v0.3.0

func (r *Responder) Idxs(peers [2]peer.Address) (our, their int)

Idxs maps the passed addresses to the indices in the 2-party-channel. If the setup's Identity is not found in peers, Idxs panics.

func (*Responder) OnNewChannel added in v0.3.0

func (r *Responder) OnNewChannel(callback func(ch *paymentChannel))

func (*Responder) ProposeChannel added in v0.3.0

func (r *Responder) ProposeChannel(req *client.ChannelProposal) (*paymentChannel, error)

ProposeChannel sends the channel proposal req. It times out after the timeout specified in the Role's setup.

func (*Responder) SetStages added in v0.3.0

func (r *Responder) SetStages(st Stages)

SetStages optionally sets a slice of WaitGroup barriers to wait on at different stages of the Execute protocol. It should be created by any role by calling EnableStages().

func (*Responder) UpdateHandler added in v0.3.0

func (r *Responder) UpdateHandler() *roleUpdateHandler

type Robert added in v0.3.0

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

Robert is the Responder in a persistence test.

func NewRobert added in v0.3.0

func NewRobert(setup RoleSetup, hub ConnHub, t *testing.T) *Robert

NewRobert creates a new Responder that executes the Robert protocol.

func (*Robert) Execute added in v0.3.0

func (r *Robert) Execute(cfg ExecConfig)

Execute executes the Robert protocol.

func (*Robert) NewListener added in v0.3.0

func (r *Robert) NewListener() peer.Listener

func (*Robert) ReplaceClient added in v0.3.0

func (r *Robert) ReplaceClient()

ReplaceClient replaces the client instance of the Role. Useful for persistence testing.

type RoleSetup

type RoleSetup struct {
	Name        string
	Identity    peer.Identity
	Dialer      peer.Dialer
	Listener    peer.Listener
	Funder      channel.Funder
	Adjudicator channel.Adjudicator
	Wallet      wallettest.Wallet
	PR          persistence.PersistRestorer // Optional PersistRestorer
	Timeout     time.Duration               // Timeout waiting for other role, not challenge duration
}

RoleSetup contains the injectables for setting up the client.

type Stages added in v0.2.0

type Stages = []sync.WaitGroup

Stages are used to synchronize multiple roles.

Jump to

Keyboard shortcuts

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