test

package
v0.0.0-...-8619d99 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Funded = setupModifier(func(s *Setup) {
	chID := s.State.ID
	for i, part := range s.Parts {
		_ = s.Adj.Mint(s.IDs[i], s.State.Balances[i])
		if err := s.Adj.Deposit(s.IDs[i], chID, part, s.State.Balances[i]); err != nil {
			panic(fmt.Sprintf("Setup: error funding participant[%d]: %v", i, err))
		}
	}
})

Funded performs minting and deposit for all participants. Therefore, the state channel is prefunded.

View Source
var WithFinalState = setupModifier(func(s *Setup) {
	s.State.IsFinal = true
})

WithFinalState allows to set the channel final flag to true.

Functions

func RandomParams

func RandomParams(rng *rand.Rand) *adj.Params

RandomParams returns random channel parameters for testing.

func RandomState

func RandomState(rng *rand.Rand) *adj.State

RandomState returns a random channel state for testing.

func RandomStateReg

func RandomStateReg(rng *rand.Rand, opts ...chtest.RandomOpt) *adj.StateReg

RandomStateReg returns a random state registration for testing.

Types

type Setup

type Setup struct {
	IDs     []adj.AccountID
	Parts   []wallet.Address
	Accs    []wallet.Account
	Params  *adj.Params
	State   *adj.State
	Ledger  *TestLedger
	Adj     *adj.Adjudicator
	Timeout adj.Timestamp
}

Setup provides necessary elements for testing.

func NewSetup

func NewSetup(rng *rand.Rand, opts ...SetupOption) *Setup

NewSetup generates a new test setup. Each setup is created with new random accounts and an initial channel state.

func (*Setup) SignedChannel

func (s *Setup) SignedChannel() *adj.SignedChannel

SignedChannel returns a signed channel based on the current channel state (Params, State, Accs) of the Setup.

func (*Setup) StateReg

func (s *Setup) StateReg() *adj.StateReg

StateReg returns the StateReg according to the current state and ledger's now.

type SetupOption

type SetupOption interface {
	// contains filtered or unexported methods
}

SetupOption extends the Setup constructor.

func WithAccounts

func WithAccounts(accs ...wallet.Account) SetupOption

WithAccounts allows setting own Accounts instead of using random ones.

func WithChannelBalances

func WithChannelBalances(bals ...channel.Bal) SetupOption

WithChannelBalances allows giving own balances instead of the default ones.

func WithMintedTokens

func WithMintedTokens(fund ...*big.Int) SetupOption

WithMintedTokens mints for all participants the given amount of tokens at start.

func WithVersion

func WithVersion(v uint64) SetupOption

WithVersion allows to set the state version.

type TestLedger

type TestLedger struct {
	*adj.MemLedger
	// contains filtered or unexported fields
}

TestLedger is a MemLedger with a controllable clock. The timestamp returned by Now stays constant until it is advanced with AdvanceNow. The initial value of now is set at creation to MemLedger.Now().

func NewTestLedger

func NewTestLedger() *TestLedger

NewTestLedger creates a test ledger with a controllable clock.

func (*TestLedger) AdvanceNow

func (l *TestLedger) AdvanceNow(duration uint64)

AdvanceNow adds the given duration onto the current time of the TestLedger.

func (*TestLedger) Now

func (l *TestLedger) Now() adj.Timestamp

Now returns the current time on the TestLedger.

Jump to

Keyboard shortcuts

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