Documentation
¶
Overview ¶
Package test contains generic tests and benchmarks for wallet backend implementation. Furthermore, it exports random generators of Addresses and Accounts.
Index ¶
- func GenericAccountBenchmark(b *testing.B, s *Setup)
- func GenericBackendBenchmark(b *testing.B, s *Setup)
- func GenericSignatureSizeTest(t *testing.T, s *Setup)
- func NewRandomAccount(rng *rand.Rand, bID wallet.BackendID) wallet.Account
- func NewRandomAccountMap(rng *rand.Rand, bID wallet.BackendID) map[wallet.BackendID]wallet.Account
- func NewRandomAccountMapSlice(rng *rand.Rand, bID wallet.BackendID, n int) []map[wallet.BackendID]wallet.Account
- func NewRandomAccounts(rng *rand.Rand, n int, bID wallet.BackendID) ([]map[wallet.BackendID]wallet.Account, []map[wallet.BackendID]wallet.Address)
- func NewRandomAddress(rng *rand.Rand, bID wallet.BackendID) wallet.Address
- func NewRandomAddressArray(rng *rand.Rand, n int, bID wallet.BackendID) []wallet.Address
- func NewRandomAddresses(rng *rand.Rand, bID wallet.BackendID) map[wallet.BackendID]wallet.Address
- func NewRandomAddressesMap(rng *rand.Rand, n int, bID wallet.BackendID) []map[wallet.BackendID]wallet.Address
- func SetRandomizer(b Randomizer, bID wallet.BackendID)
- func TestAccountWithWalletAndBackend(t *testing.T, s *Setup)
- func TestAddress(t *testing.T, s *Setup)
- type Randomizer
- type Setup
- type UnlockedAccount
- type Wallet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenericAccountBenchmark ¶
GenericAccountBenchmark runs a suite designed to benchmark the general speed of an implementation of an Account. This function should be called by every implementation of the Account interface.
func GenericBackendBenchmark ¶
GenericBackendBenchmark runs a suite designed to benchmark the general speed of an implementation of a Backend.
This function should be called by every implementation of the Backend interface.
func GenericSignatureSizeTest ¶
GenericSignatureSizeTest tests that the size of the signatures produced by Account.Sign(…) does not vary between executions (tested with 2048 samples).
func NewRandomAccount ¶
NewRandomAccount returns a new random account by calling the currently set wallet randomizer. The account is generated from the randomizer wallet available via RandomWallet. It should already be unlocked.
func NewRandomAccountMap ¶ added in v0.13.0
NewRandomAccountMap returns a slice of new random accounts by calling NewRandomAccount.
func NewRandomAccountMapSlice ¶ added in v0.13.0
func NewRandomAccountMapSlice(rng *rand.Rand, bID wallet.BackendID, n int) []map[wallet.BackendID]wallet.Account
NewRandomAccountMapSlice returns a slice of new random accounts map by calling NewRandomAccount.
func NewRandomAccounts ¶ added in v0.2.1
func NewRandomAccounts(rng *rand.Rand, n int, bID wallet.BackendID) ([]map[wallet.BackendID]wallet.Account, []map[wallet.BackendID]wallet.Address)
NewRandomAccounts returns a slice of new random accounts by calling NewRandomAccount.
func NewRandomAddress ¶
NewRandomAddress returns a new random address by calling the currently set wallet randomizer.
func NewRandomAddressArray ¶ added in v0.13.0
NewRandomAddressArray returns a slice of new random addresses.
func NewRandomAddresses ¶ added in v0.3.0
NewRandomAddresses returns a new random address by calling the currently set wallet randomizer.
func NewRandomAddressesMap ¶ added in v0.13.0
func NewRandomAddressesMap(rng *rand.Rand, n int, bID wallet.BackendID) []map[wallet.BackendID]wallet.Address
NewRandomAddressesMap returns a slice of new random address maps.
func SetRandomizer ¶
func SetRandomizer(b Randomizer, bID wallet.BackendID)
SetRandomizer sets the wallet randomizer. It may be set multiple times.
func TestAccountWithWalletAndBackend ¶ added in v0.8.0
TestAccountWithWalletAndBackend tests an account implementation together with a corresponding wallet and backend implementation. This function should be called by every implementation of the wallet interface.
func TestAddress ¶ added in v0.8.0
TestAddress runs a test suite designed to test the general functionality of an address implementation.
Types ¶
type Randomizer ¶
type Randomizer interface { // NewRandomAddress should return a new random address generated from the // passed rng. NewRandomAddress(*rand.Rand) wallet.Address // RandomWallet should return a fixed random wallet that is part of the // randomizer's state. It will be used to generate accounts with // NewRandomAccount. RandomWallet() Wallet // NewWallet should return a fresh, temporary Wallet that doesn't hold any // accounts yet. NewWallet() Wallet }
Randomizer is a wallet testing backend. It should support the generation of random addresses and accounts.
type Setup ¶
type Setup struct { Backend wallet.Backend // backend implementation Wallet wallet.Wallet // the wallet instance used for testing AddressInWallet wallet.Address // an address of an account in the test wallet ZeroAddress wallet.Address // an address that is less or equal to any other address DataToSign []byte // some data to sign AddressMarshalled []byte // a valid nonzero address not in the wallet }
Setup provides all objects needed for the generic tests.
type UnlockedAccount ¶
UnlockedAccount provides an unlocked account.
type Wallet ¶ added in v0.2.1
type Wallet interface { wallet.Wallet // NewRandomAccount should return an account generated from the passed rng. // The account should be stored and unlocked in the Wallet. NewRandomAccount(*rand.Rand) wallet.Account }
A Wallet is an extension of a wallet.Wallet to also generate random accounts in test settings.
func NewWallet ¶ added in v0.2.1
NewWallet returns a fresh, temporary Wallet for testing purposes that doesn't hold any accounts yet. New random accounts can be generated using method NewRandomAccount.
func RandomWallet ¶ added in v0.2.1
RandomWallet returns the randomizer backend's wallet. All accounts created with NewRandomAccount can be found in this wallet.