Documentation ¶
Overview ¶
Package ethereumtest provides test helpers for using ethereum backend in test.
Index ¶
- Constants
- func ContractAddrs() (adjudicator, assetETH pwallet.Address, ...)
- func NewRandomAddress(rnd *rand.Rand) pwallet.Address
- func NewTestWalletBackend() perun.WalletBackend
- func SetupContracts(chainURL string, chainID int, onChainTxTimeout time.Duration, ...) (perun.ContractRegistry, error)
- func SetupContractsT(t *testing.T, chainURL string, chainID int, onChainTxTimeout time.Duration, ...) perun.ContractRegistry
- 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 ChainID = 1337 // Default chain id for ganache-cli private network. )
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, assetETH pwallet.Address, assetERC20s map[pwallet.Address]pwallet.Address)
ContractAddrs returns the contract addresses of adjudicator, asset ETH asset ERC20 contracts (along with the corresponding erc20 token 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, chainID int, onChainTxTimeout time.Duration, incAssetERC20s bool) ( perun.ContractRegistry, error)
SetupContracts on its first invocation, deploys the contracts to blockchain and sets the addresses to package level variables. It checks first time invocation by checking if all any of the package level variables are nil.
On every consequent calls, a contract registry will be initialized using these addresses in package level variables and will be returned directly.
Every calls returns a new instance of contract registry, so that modifying the contract registry in one test does not affect other tests.
func SetupContractsT ¶ added in v0.4.0
func SetupContractsT(t *testing.T, chainURL string, chainID int, onChainTxTimeout time.Duration, incAssetERC20s bool) perun.ContractRegistry
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 Adjudicator, AssetETH pwallet.Address AssetERC20s map[pwallet.Address]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 NewSimChainBackendSetup ¶ added in v0.6.0
NewSimChainBackendSetup returns a simulated contract backend with asset ETH 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.