-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtesteth.go
65 lines (55 loc) · 1.67 KB
/
testeth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package testeth
import (
"math/big"
"testing"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/node"
"storj.io/common/testcontext"
)
// Run creates Ethereum test network with deployed test token and executes test function.
func Run(t *testing.T, numNetworks, numAccounts int, test func(ctx *testcontext.Context, t *testing.T, network []*Network)) {
t.Run("Ethereum", func(t *testing.T) {
t.Parallel()
ctx := testcontext.New(t)
defer ctx.Cleanup()
// node config
nodeConfig := node.DefaultConfig
nodeConfig.Name = "testeth"
nodeConfig.DataDir = ""
nodeConfig.HTTPHost = "127.0.0.1"
nodeConfig.HTTPPort = 0
nodeConfig.AuthPort = 0
nodeConfig.HTTPModules = append(nodeConfig.HTTPModules, "eth")
nodeConfig.P2P.MaxPeers = 0
nodeConfig.P2P.ListenAddr = ""
nodeConfig.P2P.NoDial = true
nodeConfig.P2P.NoDiscovery = true
nodeConfig.P2P.DiscoveryV5 = false
var networks []*Network
for i := 0; i < numNetworks; i++ {
// eth config
ethConfig := ethconfig.Defaults
ethConfig.NetworkId = 1337 + uint64(i)
ethConfig.SyncMode = downloader.FullSync
ethConfig.Miner.GasPrice = big.NewInt(1)
ethConfig.FilterLogCacheSize = 100
network, err := NewNetwork(nodeConfig, ethConfig, numAccounts)
if err != nil {
t.Fatal(err)
}
defer ctx.Check(network.Close)
if err = network.Start(); err != nil {
t.Fatal(err)
}
err = DeployToken(ctx, network, 1000000)
if err != nil {
t.Fatal(err)
}
networks = append(networks, network)
}
test(ctx, t, networks)
})
}