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) wallet.Account
- func NewRandomAccounts(rng *rand.Rand, n int) ([]wallet.Account, []wallet.Address)
- func NewRandomAddress(rng *rand.Rand) wallet.Address
- func NewRandomAddresses(rng *rand.Rand, n int) []wallet.Address
- func SetRandomizer(b Randomizer)
- 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 NewRandomAccounts ¶ added in v0.2.1
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 NewRandomAddresses ¶ added in v0.3.0
NewRandomAddresses returns a slice of new random addresses.
func SetRandomizer ¶
func SetRandomizer(b Randomizer)
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
func NewWallet() Wallet
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
func RandomWallet() Wallet
RandomWallet returns the randomizer backend's wallet. All accounts created with NewRandomAccount can be found in this wallet.