-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.go
256 lines (222 loc) · 7.49 KB
/
setup.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
package btcregtest
import (
"fmt"
"github.com/btcsuite/btcd/chaincfg"
"github.com/jfixby/btcharness"
"github.com/jfixby/btcharness/memwallet"
"github.com/jfixby/btcharness/nodecls"
"github.com/jfixby/btcharness/walletcls"
"github.com/jfixby/coinharness"
"github.com/jfixby/pin"
"github.com/jfixby/pin/commandline"
"github.com/jfixby/pin/gobuilder"
"io/ioutil"
"os"
"path/filepath"
)
// Default harness name
const mainHarnessName = "main"
const mainWalletHarnessName = "main-wallet"
// SimpleTestSetup harbours:
// - rpctest setup
// - csf-fork test setup
// - and bip0009 test setup
type SimpleTestSetup struct {
// harnessPool stores and manages harnesses
// multiple harness instances may be run concurrently, to allow for testing
// complex scenarios involving multiple nodes.
harnessPool *pin.Pool
harnessWalletPool *pin.Pool
// Mainnet creates a mainnet test harness
Mainnet0 *coinharness.ChainWithMatureOutputsSpawner
// Regnet25 creates a regnet test harness
// with 25 mature outputs.
Regnet25 *coinharness.ChainWithMatureOutputsSpawner
// Simnet25 creates a simnet test harness
// with 25 mature outputs.
Simnet25 *coinharness.ChainWithMatureOutputsSpawner
// Regnet5 creates a regnet test harness
// with 5 mature outputs.
Regnet5 *coinharness.ChainWithMatureOutputsSpawner
// Regnet1 creates a regnet test harness
// with 1 mature output.
Regnet1 *coinharness.ChainWithMatureOutputsSpawner
// Simnet1 creates a simnet test harness
// with 1 mature output.
Simnet1 *coinharness.ChainWithMatureOutputsSpawner
// Regnet0 creates a regnet test harness
// with only the genesis block.
Regnet0 *coinharness.ChainWithMatureOutputsSpawner
// Simnet0 creates a simnet test harness
// with only the genesis block.
Simnet0 *coinharness.ChainWithMatureOutputsSpawner
// WorkingDir defines test setup working dir
WorkingDir *pin.TempDirHandler
}
// TearDown all harnesses in test Pool.
// This includes removing all temporary directories,
// and shutting down any created processes.
func (setup *SimpleTestSetup) TearDown() {
setup.harnessPool.DisposeAll()
setup.harnessWalletPool.DisposeAll()
//setup.nodeGoBuilder.Dispose()
setup.WorkingDir.Dispose()
}
// Setup deploys this test setup
func Setup() *SimpleTestSetup {
setup := &SimpleTestSetup{
WorkingDir: pin.NewTempDir(setupWorkingDir(), "simpleregtest").MakeDir(),
}
memWalletFactory := &memwallet.WalletFactory{}
wEXE := &commandline.ExplicitExecutablePathString{
PathString: "btcwallet",
}
consoleWalletFactory := &walletcls.ConsoleWalletFactory{
WalletExecutablePathProvider: wEXE,
}
regnetWalletFactory := memWalletFactory
mainnetWalletFactory := memWalletFactory
simnetWalletFactory := consoleWalletFactory
dEXE := &commandline.ExplicitExecutablePathString{
PathString: "btcd",
}
nodeFactory := &nodecls.ConsoleNodeFactory{
NodeExecutablePathProvider: dEXE,
}
portManager := &coinharness.LazyPortManager{
BasePort: 30000,
}
testSeed := btcharness.NewTestSeed
// Deploy harness spawner with generated
// test chain of 25 mature outputs
setup.Regnet25 = &coinharness.ChainWithMatureOutputsSpawner{
WorkingDir: setup.WorkingDir.Path(),
DebugNodeOutput: true,
DebugWalletOutput: true,
NumMatureOutputs: 25,
NetPortManager: portManager,
WalletFactory: regnetWalletFactory,
NodeFactory: nodeFactory,
ActiveNet: &btcharness.Network{&chaincfg.RegressionNetParams},
CreateTempWallet: true,
NewTestSeed: testSeed,
}
setup.Mainnet0 = &coinharness.ChainWithMatureOutputsSpawner{
WorkingDir: setup.WorkingDir.Path(),
DebugNodeOutput: true,
DebugWalletOutput: true,
NumMatureOutputs: 0,
NetPortManager: portManager,
WalletFactory: mainnetWalletFactory,
NodeFactory: nodeFactory,
ActiveNet: &btcharness.Network{&chaincfg.MainNetParams},
CreateTempWallet: true,
NewTestSeed: testSeed,
}
// Deploy harness spawner with generated
// test chain of 5 mature outputs
setup.Regnet5 = &coinharness.ChainWithMatureOutputsSpawner{
WorkingDir: setup.WorkingDir.Path(),
DebugNodeOutput: true,
DebugWalletOutput: true,
NumMatureOutputs: 5,
NetPortManager: portManager,
WalletFactory: regnetWalletFactory,
NodeFactory: nodeFactory,
ActiveNet: &btcharness.Network{&chaincfg.RegressionNetParams},
CreateTempWallet: true,
NewTestSeed: testSeed,
}
setup.Regnet1 = &coinharness.ChainWithMatureOutputsSpawner{
WorkingDir: setup.WorkingDir.Path(),
DebugNodeOutput: true,
DebugWalletOutput: true,
NumMatureOutputs: 1,
NetPortManager: portManager,
WalletFactory: regnetWalletFactory,
NodeFactory: nodeFactory,
ActiveNet: &btcharness.Network{&chaincfg.RegressionNetParams},
CreateTempWallet: true,
NewTestSeed: testSeed,
NodeStartExtraArguments: map[string]interface{}{
"rejectnonstd": commandline.NoArgumentValue,
},
}
setup.Simnet1 = &coinharness.ChainWithMatureOutputsSpawner{
WorkingDir: setup.WorkingDir.Path(),
DebugNodeOutput: true,
DebugWalletOutput: true,
NumMatureOutputs: 1,
NetPortManager: portManager,
WalletFactory: simnetWalletFactory,
NodeFactory: nodeFactory,
ActiveNet: &btcharness.Network{&chaincfg.SimNetParams},
CreateTempWallet: true,
NewTestSeed: testSeed,
NodeStartExtraArguments: map[string]interface{}{
"rejectnonstd": commandline.NoArgumentValue,
},
}
setup.Simnet25 = &coinharness.ChainWithMatureOutputsSpawner{
WorkingDir: setup.WorkingDir.Path(),
DebugNodeOutput: true,
DebugWalletOutput: true,
NumMatureOutputs: 25,
NetPortManager: portManager,
WalletFactory: simnetWalletFactory,
NodeFactory: nodeFactory,
ActiveNet: &btcharness.Network{&chaincfg.SimNetParams},
CreateTempWallet: true,
NewTestSeed: testSeed,
NodeStartExtraArguments: map[string]interface{}{
"rejectnonstd": commandline.NoArgumentValue,
},
}
// Deploy harness spawner with empty test chain
setup.Regnet0 = &coinharness.ChainWithMatureOutputsSpawner{
WorkingDir: setup.WorkingDir.Path(),
DebugNodeOutput: true,
DebugWalletOutput: true,
NumMatureOutputs: 0,
NetPortManager: portManager,
WalletFactory: regnetWalletFactory,
NodeFactory: nodeFactory,
ActiveNet: &btcharness.Network{&chaincfg.RegressionNetParams},
CreateTempWallet: true,
NewTestSeed: testSeed,
}
// Deploy harness spawner with empty test chain
setup.Simnet0 = &coinharness.ChainWithMatureOutputsSpawner{
WorkingDir: setup.WorkingDir.Path(),
DebugNodeOutput: true,
DebugWalletOutput: true,
NumMatureOutputs: 0,
NetPortManager: portManager,
WalletFactory: simnetWalletFactory,
NodeFactory: nodeFactory,
ActiveNet: &btcharness.Network{&chaincfg.SimNetParams},
CreateTempWallet: true,
NewTestSeed: testSeed,
}
setup.harnessPool = pin.NewPool(setup.Regnet25)
setup.harnessWalletPool = pin.NewPool(setup.Simnet25)
return setup
}
func setupWorkingDir() string {
testWorkingDir, err := ioutil.TempDir("", "integrationtest")
if err != nil {
fmt.Println("Unable to create working dir: ", err)
os.Exit(-1)
}
return testWorkingDir
}
func setupBuild(buildName string, workingDir string, nodeProjectGoPath string) *gobuilder.GoBuider {
tempBinDir := filepath.Join(workingDir, "bin")
pin.MakeDirs(tempBinDir)
nodeGoBuilder := &gobuilder.GoBuider{
GoProjectPath: nodeProjectGoPath,
OutputFolderPath: tempBinDir,
BuildFileName: buildName,
}
return nodeGoBuilder
}