Documentation ¶
Overview ¶
Package test contains generic tests for channel backend implementations and random generators of Params, States etc. for tests.
Index ¶
- Variables
- func GenericBackendTest(t *testing.T, s *Setup, opts ...GenericTestOption)
- func GenericStateEqualTest(t *testing.T, s1, s2 *channel.State, opts ...GenericTestOption)
- func NewRandomAllocation(rng *rand.Rand, opts ...RandomOpt) *channel.Allocation
- func NewRandomApp(rng *rand.Rand, opts ...RandomOpt) channel.App
- func NewRandomAppAndData(rng *rand.Rand, opts ...RandomOpt) (channel.App, channel.Data)
- func NewRandomAppID(rng *rand.Rand) channel.AppID
- func NewRandomAsset(rng *rand.Rand) channel.Asset
- func NewRandomAssets(rng *rand.Rand, opts ...RandomOpt) []channel.Asset
- func NewRandomBal(rng *rand.Rand, opts ...RandomOpt) channel.Bal
- func NewRandomBalances(rng *rand.Rand, opts ...RandomOpt) channel.Balances
- func NewRandomBals(rng *rand.Rand, numBals int, opts ...RandomOpt) []channel.Bal
- func NewRandomChannelID(rng *rand.Rand, opts ...RandomOpt) (id channel.ID)
- func NewRandomChannelIDs(rng *rand.Rand, n int) (ids []channel.ID)
- func NewRandomData(rng *rand.Rand, opts ...RandomOpt) channel.Data
- func NewRandomIndexMap(rng *rand.Rand, numParts int, numPartsParent int) (m []channel.Index)
- func NewRandomIndexMaps(rng *rand.Rand, numParts int, numPartsParent int) (maps [][]channel.Index)
- func NewRandomLocked(rng *rand.Rand, opts ...RandomOpt) []channel.SubAlloc
- func NewRandomLockedIDs(rng *rand.Rand, opts ...RandomOpt) []channel.ID
- func NewRandomParams(rng *rand.Rand, opts ...RandomOpt) *channel.Params
- func NewRandomParamsAndState(rng *rand.Rand, opts ...RandomOpt) (params *channel.Params, state *channel.State)
- func NewRandomPhase(rng *rand.Rand) channel.Phase
- func NewRandomState(rng *rand.Rand, opts ...RandomOpt) (state *channel.State)
- func NewRandomSubAlloc(rng *rand.Rand, opts ...RandomOpt) *channel.SubAlloc
- func NewRandomTimeout(rng *rand.Rand) channel.Timeout
- func NewRandomTransaction(rng *rand.Rand, sigMask []bool, opts ...RandomOpt) *channel.Transaction
- func SetAppRandomizer(r AppRandomizer)
- func SetNewRandomAppID(f NewRandomAppIDFunc)
- func SetRandomizer(r Randomizer)
- func ShuffleBalances(rng *rand.Rand, b channel.Balances) channel.Balances
- type AppRandomizer
- type GenericTestOption
- type GenericTestOptions
- type MockAppRandomizer
- type NewRandomAppIDFunc
- type RandomOpt
- func WithAllocation(alloc *channel.Allocation) RandomOpt
- func WithApp(app channel.App) RandomOpt
- func WithAppData(data channel.Data) RandomOpt
- func WithAppDef(appDef wallet.Address) RandomOpt
- func WithAppRandomizer(randomizer AppRandomizer) RandomOpt
- func WithAssets(assets ...channel.Asset) RandomOpt
- func WithBalances(balances ...[]channel.Bal) RandomOpt
- func WithBalancesInRange(min, max channel.Bal) RandomOpt
- func WithChallengeDuration(d uint64) RandomOpt
- func WithFirstPart(part wallet.Address) RandomOpt
- func WithID(id channel.ID) RandomOpt
- func WithIsFinal(isFinal bool) RandomOpt
- func WithLedgerChannel(ledger bool) RandomOpt
- func WithLocked(locked ...channel.SubAlloc) RandomOpt
- func WithLockedBals(bals ...channel.Bal) RandomOpt
- func WithLockedID(id channel.ID) RandomOpt
- func WithLockedIDs(ids ...channel.ID) RandomOpt
- func WithNonce(nonce channel.Nonce) RandomOpt
- func WithNumAssets(numAssets int) RandomOpt
- func WithNumLocked(numLocked int) RandomOpt
- func WithNumParts(numParts int) RandomOpt
- func WithParams(params *channel.Params) RandomOpt
- func WithParts(parts ...wallet.Address) RandomOpt
- func WithState(state *channel.State) RandomOpt
- func WithVersion(version uint64) RandomOpt
- func WithVirtualChannel(b bool) RandomOpt
- func WithoutApp() RandomOpt
- func (o RandomOpt) Allocation() *channel.Allocation
- func (o RandomOpt) App() channel.App
- func (o RandomOpt) AppData() channel.Data
- func (o RandomOpt) AppDef() channel.AppID
- func (o RandomOpt) AppRandomizer() AppRandomizer
- func (o RandomOpt) Append(opts ...RandomOpt) RandomOpt
- func (o RandomOpt) Assets() []channel.Asset
- func (o RandomOpt) Balances() channel.Balances
- func (o RandomOpt) BalancesRange() (min, max channel.Bal)
- func (o RandomOpt) ChallengeDuration(rng *rand.Rand) uint64
- func (o RandomOpt) FirstPart() wallet.Address
- func (o RandomOpt) ID() (id channel.ID, valid bool)
- func (o RandomOpt) IsFinal(rng *rand.Rand) bool
- func (o RandomOpt) LedgerChannel(rng io.Reader) bool
- func (o RandomOpt) Locked() (locked []channel.SubAlloc, valid bool)
- func (o RandomOpt) LockedBals() []channel.Bal
- func (o RandomOpt) LockedID(rng *rand.Rand) channel.ID
- func (o RandomOpt) LockedIDs(rng *rand.Rand) (ids []channel.ID)
- func (o RandomOpt) Nonce(rng io.Reader) channel.Nonce
- func (o RandomOpt) NumAssets(rng *rand.Rand) int
- func (o RandomOpt) NumLocked(rng *rand.Rand) int
- func (o RandomOpt) NumParts(rng *rand.Rand) int
- func (o RandomOpt) Params() *channel.Params
- func (o RandomOpt) Parts() []wallet.Address
- func (o RandomOpt) State() *channel.State
- func (o RandomOpt) Version(rng *rand.Rand) uint64
- func (o RandomOpt) VirtualChannel(rng io.Reader) bool
- type Randomizer
- type Setup
Constants ¶
This section is empty.
Variables ¶
var ( // MaxBalance is the maximum balance used for testing. // It is set to 2 ^ 128 - 1 since when 2 ^ 256 - 1 is used, the faucet // key is depleted. // The production limit can be found in `go-perun/channel.MaxBalance`. MaxBalance = new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 128), big.NewInt(1)) //nolint:gomnd )
Functions ¶
func GenericBackendTest ¶
func GenericBackendTest(t *testing.T, s *Setup, opts ...GenericTestOption)
GenericBackendTest tests the interface functions of the global channel.Backend with the passed test data.
func GenericStateEqualTest ¶ added in v0.3.0
func GenericStateEqualTest(t *testing.T, s1, s2 *channel.State, opts ...GenericTestOption)
GenericStateEqualTest tests the State.Equal function.
func NewRandomAllocation ¶
func NewRandomAllocation(rng *rand.Rand, opts ...RandomOpt) *channel.Allocation
NewRandomAllocation generates a new random `channel.Allocation`. Options: all from `NewRandomAssets`, `NewRandomBalances` and `NewRandomLocked`.
func NewRandomApp ¶
NewRandomApp creates a new random channel.App.
func NewRandomAppAndData ¶ added in v0.5.0
NewRandomAppAndData creates a new random channel.App and new random channel.Data.
func NewRandomAppID ¶ added in v0.11.0
NewRandomAppID creates a new random channel.AppID.
func NewRandomAsset ¶
NewRandomAsset generates a new random `channel.Asset`.
func NewRandomAssets ¶ added in v0.2.1
NewRandomAssets generates new random `channel.Asset`s. Options: `WithAssets` and `WithNumAssets`.
func NewRandomBal ¶
NewRandomBal generates a new random `channel.Bal`. Options: `WithBalancesRange`.
func NewRandomBalances ¶ added in v0.2.1
NewRandomBalances generates a new random `channel.Balances`. Options: `WithBalances`, `WithNumAssets`, `WithNumParts` and all from `NewRandomBals`.
func NewRandomBals ¶
NewRandomBals generates new random `channel.Bal`s. Options: all from `NewRandomBal`.
func NewRandomChannelID ¶
NewRandomChannelID generates a new random `channel.ID`. Options: `WithID`.
func NewRandomChannelIDs ¶ added in v0.7.0
NewRandomChannelIDs generates a list of random channel IDs.
func NewRandomData ¶
NewRandomData creates new random data for an app.
func NewRandomIndexMap ¶ added in v0.7.0
NewRandomIndexMap generates a random index map.
func NewRandomIndexMaps ¶ added in v0.7.0
NewRandomIndexMaps generates a list of random index maps.
func NewRandomLocked ¶ added in v0.2.1
NewRandomLocked generates new random `channel.SubAlloc`s. Options: `WithLocked`, `WithNumLocked` and all from `NewRandomLockedIDs`.
func NewRandomLockedIDs ¶ added in v0.2.1
NewRandomLockedIDs generates new random `channel.ID`s used in `channel.SubAlloc`. Options: `WithLockedIDs` and `WithNumLocked`.
func NewRandomParams ¶
NewRandomParams generates a new random `channel.Params`. Options: `WithParams`, `WithNumParts`, `WithParts`, `WithFirstPart`, `WithNonce`, `WithChallengeDuration` and all from `NewRandomApp`.
func NewRandomParamsAndState ¶ added in v0.2.1
func NewRandomParamsAndState(rng *rand.Rand, opts ...RandomOpt) (params *channel.Params, state *channel.State)
NewRandomParamsAndState generates a new random `channel.Params` and `channel.State`. Options: all from `NewRandomParams` and `NewRandomState`.
func NewRandomPhase ¶ added in v0.6.0
NewRandomPhase generates a random channel machine phase.
func NewRandomState ¶
NewRandomState generates a new random `channel.State`. Options: `WithState`, `WithVersion`, `WithIsFinal` and all from `NewRandomChannelID`, `NewRandomApp`, `NewRandomAllocation` and `NewRandomData`.
func NewRandomSubAlloc ¶
NewRandomSubAlloc generates a new random `channel.SubAlloc`. Options: `WithLockedID`, `WithLockedBals` and all from `NewRandomBals`.
func NewRandomTimeout ¶ added in v0.6.0
NewRandomTimeout creates a new random timeout object.
func NewRandomTransaction ¶ added in v0.2.1
NewRandomTransaction generates a new random `channel.Transaction`. `sigMask` defines which signatures are generated. `len(sigmask)` is assumed to be the number of participants. If an entry is false, nil is set as signature for that index. Options: all from `NewRandomParamsAndState`.
func SetAppRandomizer ¶
func SetAppRandomizer(r AppRandomizer)
SetAppRandomizer sets the global `appRandomizer`.
func SetNewRandomAppID ¶ added in v0.11.0
func SetNewRandomAppID(f NewRandomAppIDFunc)
SetNewRandomAppID sets the function generating a new app identifier.
func SetRandomizer ¶
func SetRandomizer(r Randomizer)
SetRandomizer sets the global Randomizer variable.
Types ¶
type AppRandomizer ¶
type AppRandomizer interface { NewRandomApp(*rand.Rand) channel.App NewRandomData(*rand.Rand) channel.Data }
The AppRandomizer interface provides functionality for creating random data and apps which is useful for testing.
type GenericTestOption ¶ added in v0.8.0
type GenericTestOption int
GenericTestOption can be used to control the behaviour of generic tests.
const ( // IgnoreAssets ignores the Assets in tests that support it. IgnoreAssets GenericTestOption = iota // IgnoreApp ignores the App in tests that support it. IgnoreApp )
type GenericTestOptions ¶ added in v0.8.0
type GenericTestOptions map[GenericTestOption]bool
GenericTestOptions is a collection of GenericTestOption.
type MockAppRandomizer ¶
type MockAppRandomizer struct {
// contains filtered or unexported fields
}
MockAppRandomizer implements the AppRandomizer interface.
func NewMockAppRandomizer ¶ added in v0.11.0
func NewMockAppRandomizer() *MockAppRandomizer
NewMockAppRandomizer creates a new instance of MockAppRandomizer with a unique identifier.
func (*MockAppRandomizer) Equal ¶ added in v0.11.0
func (m *MockAppRandomizer) Equal(other *MockAppRandomizer) bool
Equal returns false for any comparison, ensuring two MockAppRandomizers are always considered different.
func (MockAppRandomizer) NewRandomApp ¶
func (MockAppRandomizer) NewRandomApp(rng *rand.Rand) channel.App
NewRandomApp creates a new MockApp with a random address.
func (MockAppRandomizer) NewRandomData ¶
func (MockAppRandomizer) NewRandomData(rng *rand.Rand) channel.Data
NewRandomData creates a new MockOp with a random operation.
type NewRandomAppIDFunc ¶ added in v0.11.0
NewRandomAppIDFunc is an app identifier randomizer function.
type RandomOpt ¶ added in v0.2.1
type RandomOpt map[string]interface{}
RandomOpt defines a map of options than can be passed to `NewRandomX` functions in order to alter their default behaviour. Should only be constructed by `WithX` functions.
func WithAllocation ¶ added in v0.2.1
func WithAllocation(alloc *channel.Allocation) RandomOpt
WithAllocation sets the `Allocation` that should be used. Also defines `WithAssets`, `WithBalances` and `WithLocked`.
func WithAppData ¶ added in v0.2.1
WithAppData sets the `AppData` that should be used.
func WithAppDef ¶ added in v0.2.1
WithAppDef sets the `AppDef` that should be used.
func WithAppRandomizer ¶ added in v0.5.0
func WithAppRandomizer(randomizer AppRandomizer) RandomOpt
WithAppRandomizer sets the `AppRandomizer` that should be used.
func WithAssets ¶ added in v0.2.1
WithAssets sets the `Assets` that should be used. Also sets `WithNumAssets`.
func WithBalances ¶ added in v0.2.1
WithBalances sets the `Balances` that should be used in a generated Allocation. Also sets `WithNumAssets` and `WithNumParts` iff `balances` is not empty.
func WithBalancesInRange ¶ added in v0.2.1
WithBalancesInRange sets the range within which balances are randomly generated to [min, max].
func WithChallengeDuration ¶ added in v0.2.1
WithChallengeDuration sets the `ChallengeDuration` that should be used.
func WithFirstPart ¶ added in v0.2.1
WithFirstPart sets the first participant that should be used in randomly generated Params. Overrides `WithParts`.
func WithIsFinal ¶ added in v0.2.1
WithIsFinal sets whether the generated State is final.
func WithLedgerChannel ¶ added in v0.7.0
WithLedgerChannel sets the `LedgerChannel` attribute.
func WithLocked ¶ added in v0.2.1
WithLocked sets the `Locked` sub-allocations in the generated Allocation. Also sets `WithNumLocked` and `WithNumAssets` iff `locked` is not empty.
func WithLockedBals ¶ added in v0.2.1
WithLockedBals causes exactly one sub-allocation with the given balances to be generated in the Allocation. Also sets `WithNumAssets` and `WithNumLocked` to 1.
func WithLockedID ¶ added in v0.2.1
WithLockedID sets the channel id that should be used when generating a single sub-allocation with `NewRandomSubAlloc`.
func WithLockedIDs ¶ added in v0.2.1
WithLockedIDs sets the locked channel ids that should be used. Also sets `WithNumLocked`.
func WithNumAssets ¶ added in v0.2.1
WithNumAssets sets the `NumAssets` that should be used.
func WithNumLocked ¶ added in v0.2.1
WithNumLocked sets the `NumLocked` that should be used.
func WithNumParts ¶ added in v0.2.1
WithNumParts sets the `NumParts` that should be used.
func WithParams ¶ added in v0.2.1
WithParams sets the `Params` that should be used. Also sets `WithID`, `WithChallengeDuration`, `WithParts`, `WithApp` and `WithNonce`.
func WithParts ¶ added in v0.2.1
WithParts sets the `Parts` that should be used when generating Params. Also sets `WithNumParts`.
func WithState ¶ added in v0.2.1
WithState sets the `State` that should be used. Also sets `WithID`, `WithVersion`, `WithApp`, `WithAllocation`, `WithAppData` and `WithIsFinal`.
func WithVersion ¶ added in v0.2.1
WithVersion sets the `Version` that should be used when generating a State.
func WithVirtualChannel ¶ added in v0.7.0
WithVirtualChannel sets the `VirtualChannel` attribute.
func WithoutApp ¶ added in v0.5.0
func WithoutApp() RandomOpt
WithoutApp configures a NoApp and NoData.
func (RandomOpt) Allocation ¶ added in v0.2.1
func (o RandomOpt) Allocation() *channel.Allocation
Allocation returns the `Allocation` value of the `RandomOpt`. If not present, returns nil.
func (RandomOpt) App ¶ added in v0.2.1
App returns the `App` value of the `RandomOpt`. If not present, returns nil.
func (RandomOpt) AppData ¶ added in v0.2.1
AppData returns the `AppData` value of the `RandomOpt`. If not present, returns nil.
func (RandomOpt) AppDef ¶ added in v0.2.1
AppDef returns the `AppDef` value of the `RandomOpt`. If not present, returns nil.
func (RandomOpt) AppRandomizer ¶ added in v0.5.0
func (o RandomOpt) AppRandomizer() AppRandomizer
AppRandomizer returns the `AppRandomizer` value of the `RandomOpt`. If not present, returns the default appRandomizer.
func (RandomOpt) Append ¶ added in v0.2.1
Append inserts all `opts` into the receiving object and returns the result. Overrides entries that occur more than once with the last occurrence.
func (RandomOpt) Assets ¶ added in v0.2.1
Assets returns the `Assets` value of the `RandomOpt`. If not present, returns nil.
func (RandomOpt) Balances ¶ added in v0.2.1
Balances returns the `Balances` value of the `RandomOpt`. If not present, returns nil.
func (RandomOpt) BalancesRange ¶ added in v0.2.1
BalancesRange returns the `BalancesRange` value of the `RandomOpt`. If not present, returns nil,nil.
func (RandomOpt) ChallengeDuration ¶ added in v0.2.1
ChallengeDuration returns the `ChallengeDuration` value of the `RandomOpt`. If not present, a random value is generated with `rng` as entropy source.
func (RandomOpt) FirstPart ¶ added in v0.2.1
FirstPart returns the `FirstPart` value of the `RandomOpt`. If not present, returns nil.
func (RandomOpt) ID ¶ added in v0.2.1
ID returns the `ID` value of the `RandomOpt`. If not present, returns `false` as second argument.
func (RandomOpt) IsFinal ¶ added in v0.2.1
IsFinal returns the `IsFinal` value of the `RandomOpt`. If not present, a random value is generated with `rng` as entropy source.
func (RandomOpt) LedgerChannel ¶ added in v0.7.0
LedgerChannel returns the `LedgerChannel` value of the `RandomOpt`. If not present, a random value is generated with `rng` as entropy source.
func (RandomOpt) Locked ¶ added in v0.2.1
Locked returns the `Locked` value of the `RandomOpt`. If not present, returns `false` as second argument.
func (RandomOpt) LockedBals ¶ added in v0.2.1
LockedBals returns the `LockedBals` value of the `RandomOpt`. If not present, returns nil.
func (RandomOpt) LockedID ¶ added in v0.2.1
LockedID returns the `LockedID` value of the `RandomOpt`. If not present, a random value is generated with `rng` as entropy source.
func (RandomOpt) LockedIDs ¶ added in v0.2.1
LockedIDs returns the `LockedIDs` value of the `RandomOpt`. If not present, returns nil.
func (RandomOpt) Nonce ¶ added in v0.2.1
Nonce returns the `Nonce` value of the `RandomOpt`. If not present, a random value is generated with `rng` as entropy source.
func (RandomOpt) NumAssets ¶ added in v0.2.1
NumAssets returns the `NumAssets` value of the `RandomOpt`. If not present, a random value is generated with `rng` as entropy source.
func (RandomOpt) NumLocked ¶ added in v0.2.1
NumLocked returns the `NumLocked` value of the `RandomOpt`. If not present, returns 0.
func (RandomOpt) NumParts ¶ added in v0.2.1
NumParts returns the `NumParts` value of the `RandomOpt`. If not present, a random value between 2 and 11 is generated with `rng` as entropy source.
func (RandomOpt) Params ¶ added in v0.2.1
Params returns the `Params` value of the `RandomOpt`. If not present, returns nil.
func (RandomOpt) Parts ¶ added in v0.2.1
Parts returns the `Parts` value of the `RandomOpt`. If not present, returns nil.
func (RandomOpt) State ¶ added in v0.2.1
State returns the `State` value of the `RandomOpt`. If not present, returns nil.
type Randomizer ¶
The Randomizer interface provides the ability to create random assets. This is useful for testing.
type Setup ¶
type Setup struct { // Params are the random parameters of `State` Params *channel.Params // Params2 are the parameters of `State2` and must differ in all fields from `Params` Params2 *channel.Params // State is a random state with parameters `Params` State *channel.State // State2 is a random state with parameters `Params2` and should differ in all fields from `State` State2 *channel.State // Account is a random account Account wallet.Account // RandomAddress returns a new random address RandomAddress addressCreator }
Setup provides all objects needed for the generic channel tests.