test

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package test provides a PersistRestorer implementation for testing purposes as well as a generic PersistRestorer implementation test.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenericPersistRestorerTest added in v0.3.0

func GenericPersistRestorerTest(
	ctx context.Context,
	t *testing.T,
	rng *rand.Rand,
	pr persistence.PersistRestorer,
	numPeers int,
	numChans int,
)

GenericPersistRestorerTest tests a PersistRestorer by persisting 2-party channels and then asserting equality of the restored channels. pr must be fresh and not contain any previous channels. The parameter numChans controls the channels created per wire. numPeers is the number of separate peers to generate.

Types

type Channel added in v0.3.0

type Channel struct {
	*persistence.StateMachine
	// contains filtered or unexported fields
}

Channel is a wrapper around a persisted channel and its participants, as well as the associated persister and restorer.

func NewRandomChannel added in v0.3.0

func NewRandomChannel(
	ctx context.Context,
	t require.TestingT,
	pr persistence.PersistRestorer,
	user channel.Index,
	peers []wire.Address,
	parent *Channel,
	rng *rand.Rand,
) (c *Channel)

NewRandomChannel creates a random channel with the requested persister and restorer, as well as the selected peer addresses for the participants (other than the owner's). The owner's index in the channel participants can be controlled via the 'user' argument. The wallet accounts and addresses used by the participants are generated randomly. The persister is notified and called to persist the new channel before it is returned.

func (*Channel) AssertPersisted added in v0.4.0

func (c *Channel) AssertPersisted(ctx context.Context, t require.TestingT)

AssertPersisted reads the channel state from the restorer and compares it to the actual channel state. If an error occurs while restoring the channel or if the restored channel does not match the actual channel state, then the test fails.

func (*Channel) DiscardUpdate added in v0.3.0

func (c *Channel) DiscardUpdate(t require.TestingT)

DiscardUpdate calls DiscardUpdate on the state machine and then checks the persistence.

func (*Channel) EnableFinal added in v0.3.0

func (c *Channel) EnableFinal(t require.TestingT)

EnableFinal calls EnableFinal on the state machine and then checks the persistence.

func (*Channel) EnableInit added in v0.3.0

func (c *Channel) EnableInit(t require.TestingT)

EnableInit calls EnableInit on the state machine and then checks the persistence.

func (*Channel) EnableUpdate added in v0.3.0

func (c *Channel) EnableUpdate(t require.TestingT)

EnableUpdate calls EnableUpdate on the state machine and then checks the persistence.

func (*Channel) Init added in v0.3.0

func (c *Channel) Init(ctx context.Context, t require.TestingT, rng *rand.Rand)

Init calls Init on the state machine and then checks the persistence.

func (*Channel) RequireEqual added in v0.4.0

func (c *Channel) RequireEqual(t require.TestingT, ch channel.Source)

RequireEqual asserts that the channel is equal to the provided channel state.

func (*Channel) SetFunded added in v0.3.0

func (c *Channel) SetFunded(t require.TestingT)

SetFunded calls SetFunded on the state machine and then checks the persistence.

func (*Channel) SetRegistered added in v0.3.0

func (c *Channel) SetRegistered(t require.TestingT)

SetRegistered calls SetRegistered on the state machine and then checks the persistence.

func (*Channel) SetRegistering added in v0.3.0

func (c *Channel) SetRegistering(t require.TestingT)

SetRegistering calls SetRegistering on the state machine and then checks the persistence.

func (*Channel) SetWithdrawing added in v0.3.0

func (c *Channel) SetWithdrawing(t require.TestingT)

SetWithdrawing calls SetWithdrawing on the state machine and then checks the persistence.

func (*Channel) SetWithdrawn added in v0.3.0

func (c *Channel) SetWithdrawn(t require.TestingT)

SetWithdrawn calls SetWithdrawn on the state machine and then checks the persistence.

func (*Channel) SignAll added in v0.3.0

func (c *Channel) SignAll(ctx context.Context, t require.TestingT)

SignAll signs the current staged state by all parties.

func (*Channel) Update added in v0.3.0

func (c *Channel) Update(t require.TestingT, state *channel.State, idx channel.Index) error

Update calls Update on the state machine and then checks the persistence.

type Client added in v0.3.0

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

Client is a mock client that can be used to create channels.

func NewClient added in v0.3.0

func NewClient(ctx context.Context, t *testing.T, rng *rand.Rand, pr persistence.PersistRestorer) *Client

NewClient creates a client.

func (*Client) NewChannel added in v0.3.0

func (c *Client) NewChannel(t require.TestingT, p wire.Address, parent *Channel) *Channel

NewChannel creates a new channel with the supplied peer as the other participant. The client's participant index is randomly chosen.

type PersistRestorer added in v0.3.0

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

A PersistRestorer is a persistence.PersistRestorer implementation for testing purposes. It is create by passing a *testing.T to NewPersistRestorer. Besides the methods implementing PersistRestorer, it provides methods for asserting the currently persisted state of channels.

func NewPersistRestorer added in v0.3.0

func NewPersistRestorer(t *testing.T) *PersistRestorer

NewPersistRestorer creates a new testing PersistRestorer that reports assert errors on the passed *testing.T t.

func (*PersistRestorer) ActivePeers added in v0.3.0

func (pr *PersistRestorer) ActivePeers(context.Context) ([]wire.Address, error)

ActivePeers returns all peers that channels are persisted for.

func (*PersistRestorer) AssertEqual added in v0.3.0

func (pr *PersistRestorer) AssertEqual(s channel.Source)

AssertEqual asserts that a channel of the same ID got persisted and that all its data fields match the data coming from Source s.

func (*PersistRestorer) AssertNotExists added in v0.6.0

func (pr *PersistRestorer) AssertNotExists(id channel.ID)

AssertNotExists asserts that a channel with the given ID does not exist.

func (*PersistRestorer) ChannelCreated added in v0.3.0

func (pr *PersistRestorer) ChannelCreated(
	_ context.Context, source channel.Source, peers []wire.Address, parent *channel.ID,
) error

ChannelCreated fully persists all of the source's data.

func (*PersistRestorer) ChannelRemoved added in v0.3.0

func (pr *PersistRestorer) ChannelRemoved(_ context.Context, id channel.ID) error

ChannelRemoved removes the channel from the test persister's memory.

func (*PersistRestorer) Close added in v0.3.0

func (pr *PersistRestorer) Close() error

Close resets the persister's memory, i.e., all internally persisted channel data is deleted. It can be reused afterwards.

func (*PersistRestorer) Enabled added in v0.3.0

func (pr *PersistRestorer) Enabled(_ context.Context, s channel.Source) error

Enabled fully persists the current and staging transaction and phase. The staging transaction should be nil.

func (*PersistRestorer) PhaseChanged added in v0.3.0

func (pr *PersistRestorer) PhaseChanged(_ context.Context, s channel.Source) error

PhaseChanged only persists the phase.

func (*PersistRestorer) RestoreChannel added in v0.4.0

func (pr *PersistRestorer) RestoreChannel(_ context.Context, id channel.ID) (*persistence.Channel, error)

RestoreChannel should return the channel with the requested ID.

func (*PersistRestorer) RestorePeer added in v0.3.0

func (pr *PersistRestorer) RestorePeer(peer wire.Address) (persistence.ChannelIterator, error)

RestorePeer returns an iterator over all persisted channels which the given peer is a part of.

func (*PersistRestorer) SigAdded added in v0.3.0

func (pr *PersistRestorer) SigAdded(_ context.Context, s channel.Source, idx channel.Index) error

SigAdded only persists the signature for the given index.

func (*PersistRestorer) Staged added in v0.3.0

Staged only persists a channel's staged state, all its currently known signatures and the phase.

Jump to

Keyboard shortcuts

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