Documentation ¶
Overview ¶
Package test provides a PersistRestorer implementation for testing purposes as well as a generic PersistRestorer implementation test.
Index ¶
- func GenericPersistRestorerTest(ctx context.Context, t *testing.T, rng *rand.Rand, ...)
- type Channel
- func (c *Channel) AssertPersisted(ctx context.Context, t require.TestingT)
- func (c *Channel) DiscardUpdate(t require.TestingT)
- func (c *Channel) EnableFinal(t require.TestingT)
- func (c *Channel) EnableInit(t require.TestingT)
- func (c *Channel) EnableUpdate(t require.TestingT)
- func (c *Channel) Init(t require.TestingT, rng *rand.Rand)
- func (c *Channel) RequireEqual(t require.TestingT, ch channel.Source)
- func (c *Channel) SetFunded(t require.TestingT)
- func (c *Channel) SetRegistered(t require.TestingT, r *channel.RegisteredEvent)
- func (c *Channel) SetRegistering(t require.TestingT)
- func (c *Channel) SetWithdrawing(t require.TestingT)
- func (c *Channel) SetWithdrawn(t require.TestingT)
- func (c *Channel) Settle(t require.TestingT)
- func (c *Channel) SignAll(t require.TestingT)
- func (c *Channel) Update(t require.TestingT, state *channel.State, idx channel.Index) error
- type Client
- type PersistRestorer
- func (pr *PersistRestorer) ActivePeers(context.Context) ([]wire.Address, error)
- func (pr *PersistRestorer) AssertEqual(s channel.Source)
- func (pr *PersistRestorer) ChannelCreated(_ context.Context, source channel.Source, peers []wire.Address) error
- func (pr *PersistRestorer) ChannelRemoved(_ context.Context, id channel.ID) error
- func (pr *PersistRestorer) Close() error
- func (pr *PersistRestorer) Enabled(_ context.Context, s channel.Source) error
- func (pr *PersistRestorer) PhaseChanged(_ context.Context, s channel.Source) error
- func (pr *PersistRestorer) RestoreChannel(_ context.Context, id channel.ID) (*persistence.Channel, error)
- func (pr *PersistRestorer) RestorePeer(peer wire.Address) (persistence.ChannelIterator, error)
- func (pr *PersistRestorer) SigAdded(_ context.Context, s channel.Source, idx channel.Index) error
- func (pr *PersistRestorer) Staged(_ context.Context, s channel.Source) error
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, 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
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
DiscardUpdate calls DiscardUpdate on the state machine and then checks the persistence.
func (*Channel) EnableFinal ¶ added in v0.3.0
EnableFinal calls EnableFinal on the state machine and then checks the persistence.
func (*Channel) EnableInit ¶ added in v0.3.0
EnableInit calls EnableInit on the state machine and then checks the persistence.
func (*Channel) EnableUpdate ¶ added in v0.3.0
EnableUpdate calls EnableUpdate on the state machine and then checks the persistence.
func (*Channel) Init ¶ added in v0.3.0
Init calls Init on the state machine and then checks the persistence.
func (*Channel) RequireEqual ¶ added in v0.4.0
RequireEqual asserts that the channel is equal to the provided channel state.
func (*Channel) SetFunded ¶ added in v0.3.0
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, r *channel.RegisteredEvent)
SetRegistered calls SetRegistered on the state machine and then checks the persistence.
func (*Channel) SetRegistering ¶ added in v0.3.0
SetRegistering calls SetRegistering on the state machine and then checks the persistence.
func (*Channel) SetWithdrawing ¶ added in v0.3.0
SetWithdrawing calls SetWithdrawing on the state machine and then checks the persistence.
func (*Channel) SetWithdrawn ¶ added in v0.3.0
SetWithdrawn calls SetWithdrawn on the state machine and then checks the persistence.
func (*Channel) Settle ¶ added in v0.4.0
Settle removes the channels data from the db and checks whether it really was removed from said db or not.
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.
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
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) ChannelCreated ¶ added in v0.3.0
func (pr *PersistRestorer) ChannelCreated( _ context.Context, source channel.Source, peers []wire.Address) error
ChannelCreated fully persists all of the source's data.
func (*PersistRestorer) ChannelRemoved ¶ added in v0.3.0
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
Enabled fully persists the current and staging transaction and phase. The staging transaction should be nil.
func (*PersistRestorer) PhaseChanged ¶ added in v0.3.0
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.