test

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: Apache-2.0 Imports: 7 Imported by: 13

Documentation

Overview

Package test contains generic tests and benchmarks for wallet backend implementation. Furthermore, it exports random generators of Addresses and Accounts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenericAccountBenchmark

func GenericAccountBenchmark(b *testing.B, s *Setup)

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

func GenericBackendBenchmark(b *testing.B, s *Setup)

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

func GenericSignatureSizeTest(t *testing.T, s *Setup)

GenericSignatureSizeTest tests that the size of the signatures produced by Account.Sign(…) does not vary between executions (tested with 2048 samples).

func NewRandomAccount

func NewRandomAccount(rng *rand.Rand) wallet.Account

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

func NewRandomAccounts(rng *rand.Rand, n int) ([]wallet.Account, []wallet.Address)

NewRandomAccounts returns a slice of new random accounts by calling NewRandomAccount.

func NewRandomAddress

func NewRandomAddress(rng *rand.Rand) wallet.Address

NewRandomAddress returns a new random address by calling the currently set wallet randomizer.

func NewRandomAddresses added in v0.3.0

func NewRandomAddresses(rng *rand.Rand, n int) []wallet.Address

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

func TestAccountWithWalletAndBackend(t *testing.T, s *Setup)

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

func TestAddress(t *testing.T, s *Setup)

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

type UnlockedAccount func() (wallet.Account, error)

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.

Jump to

Keyboard shortcuts

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