ethereumtest

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package ethereumtest provides test helpers for using ethereum backend in test.

Index

Constants

View Source
const (
	RandSeedForTestAccs = 1729 // Seed required for generating accounts used in integration tests.
	OnChainTxTimeout    = 1 * time.Minute
	ChainURL            = "ws://127.0.0.1:8545"
	ChainConnTimeout    = 10 * time.Second
)

Chain related parameters for connecting to ganache-cli node in integration test environment.

Variables

This section is empty.

Functions

func ContractAddrs added in v0.4.0

func ContractAddrs() (adjudicator, asset pwallet.Address)

ContractAddrs returns the contract addresses of adjudicator and asset contracts used in test setups. Address generation mechanism in ethereum is used to pre-compute the contract address.

On a fresh ganache-cli node run the setup contracts helper function to deploy these contracts.

func NewRandomAddress

func NewRandomAddress(rnd *rand.Rand) pwallet.Address

NewRandomAddress generates a random wallet address. It generates the address only as a byte array. Hence it does not generate any public or private keys corresponding to the address. If you need an address with keys, use Wallet.NewAccount method.

func NewTestWalletBackend

func NewTestWalletBackend() perun.WalletBackend

NewTestWalletBackend initializes an ethereum specific wallet backend with weak encryption parameters.

func SetupContracts

func SetupContracts(chainURL string, onChainTxTimeout time.Duration) (
	adjudicator, asset pwallet.Address, _ error)

SetupContracts checks if valid contracts are deployed in pre-computed addresses, if not it deployes them. Address generation mechanism in ethereum is used to pre-compute the contract address.

func SetupContractsT added in v0.4.0

func SetupContractsT(t *testing.T, chainURL string, onChainTxTimeout time.Duration) (
	adjudicator, asset pwallet.Address)

SetupContractsT is the test friendly version of SetupContracts. It uses the passed testing.T to handle the errors and registers the cleanup functions on it.

Types

type ChainBackendSetup

type ChainBackendSetup struct {
	*WalletSetup
	ChainBackend       perun.ChainBackend
	AdjAddr, AssetAddr pwallet.Address
}

ChainBackendSetup is a test setup that uses a simulated blockchain backend (for details on this backend, see go-ethereum) with required contracts deployed on it and a UserSetup.

func NewChainBackendSetup

func NewChainBackendSetup(t *testing.T, rng *rand.Rand, numAccs uint) *ChainBackendSetup

NewChainBackendSetup returns a simulated contract backend with assetHolder and adjudicator contracts deployed. It also generates the given number of accounts and funds them each with 10 ether. and returns a test ChainBackend using the given randomness.

type WalletSetup

type WalletSetup struct {
	WalletBackend perun.WalletBackend
	KeystorePath  string
	Keystore      *keystore.KeyStore
	Wallet        pwallet.Wallet
	Accs          []pwallet.Account
}

WalletSetup can generate any number of keys for testing. To enable faster unlocking of the keys, it uses weak encryption parameters for the storage encryption of the keys.

func NewWalletSetup

func NewWalletSetup(rng *rand.Rand, n uint) (*WalletSetup, error)

NewWalletSetup initializes a wallet with n accounts. Empty password string and weak encrytion parameters are used.

func NewWalletSetupT added in v0.4.0

func NewWalletSetupT(t *testing.T, rng *rand.Rand, n uint) *WalletSetup

NewWalletSetupT is the test friendly version of NewWalletSetup. It uses the passed testing.T to handle the errors and registers the cleanup functions on it.

Jump to

Keyboard shortcuts

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