Documentation
¶
Overview ¶
Package ethereumtest provides test helpers for using ethereum backend in test.
Index ¶
- Constants
- func ContractAddrs() (adjudicator, asset pwallet.Address)
- func NewRandomAddress(rnd *rand.Rand) pwallet.Address
- func NewTestWalletBackend() perun.WalletBackend
- func SetupContracts(chainURL string, onChainTxTimeout time.Duration) (adjudicator, asset pwallet.Address, _ error)
- func SetupContractsT(t *testing.T, chainURL string, onChainTxTimeout time.Duration) (adjudicator, asset pwallet.Address)
- type ChainBackendSetup
- type WalletSetup
Constants ¶
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
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 ¶
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 ¶
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
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.