@@ -44,10 +44,12 @@ import (
44
44
45
45
const NumKeys = 5
46
46
47
+ // TODO(marun) Extract the common elements of test execution for reuse across test setups
48
+
47
49
func main () {
48
50
// TODO(marun) Support choosing the log format
49
- tc := tests . NewTestContext (tests .NewDefaultLogger ("" ))
50
- defer tc .Cleanup ()
51
+ tc := antithesis . NewInstrumentedTestContext (tests .NewDefaultLogger ("" ))
52
+ defer tc .RecoverAndExit ()
51
53
require := require .New (tc )
52
54
53
55
c := antithesis .NewConfig (
@@ -57,17 +59,12 @@ func main() {
57
59
},
58
60
)
59
61
ctx := tests .DefaultNotifyContext (c .Duration , tc .DeferCleanup )
62
+ // Ensure contexts sourced from the test context use the notify context as their parent
63
+ tc .SetDefaultContextParent (ctx )
60
64
61
65
kc := secp256k1fx .NewKeychain (genesis .EWOQKey )
62
66
walletSyncStartTime := time .Now ()
63
- wallet , err := primary .MakeWallet (
64
- ctx ,
65
- c .URIs [0 ],
66
- kc ,
67
- kc ,
68
- primary.WalletConfig {},
69
- )
70
- require .NoError (err , "failed to initialize wallet" )
67
+ wallet := e2e .NewWallet (tc , kc , tmpnet.NodeURI {URI : c .URIs [0 ]})
71
68
tc .Log ().Info ("synced wallet" ,
72
69
zap .Duration ("duration" , time .Since (walletSyncStartTime )),
73
70
)
@@ -122,14 +119,7 @@ func main() {
122
119
uri := c .URIs [i % len (c .URIs )]
123
120
kc := secp256k1fx .NewKeychain (key )
124
121
walletSyncStartTime := time .Now ()
125
- wallet , err := primary .MakeWallet (
126
- ctx ,
127
- uri ,
128
- kc ,
129
- kc ,
130
- primary.WalletConfig {},
131
- )
132
- require .NoError (err , "failed to initialize wallet" )
122
+ wallet := e2e .NewWallet (tc , kc , tmpnet.NodeURI {URI : uri })
133
123
tc .Log ().Info ("synced wallet" ,
134
124
zap .Duration ("duration" , time .Since (walletSyncStartTime )),
135
125
)
@@ -162,11 +152,25 @@ type workload struct {
162
152
uris []string
163
153
}
164
154
155
+ // newTestContext returns a test context that ensures that log output and assertions are
156
+ // associated with this worker.
157
+ func (w * workload ) newTestContext (ctx context.Context ) * tests.SimpleTestContext {
158
+ return antithesis .NewInstrumentedTestContextWithArgs (
159
+ ctx ,
160
+ w .log ,
161
+ map [string ]any {
162
+ "worker" : w .id ,
163
+ },
164
+ )
165
+ }
166
+
165
167
func (w * workload ) run (ctx context.Context ) {
166
168
timer := timerpkg .StoppedTimer ()
167
169
168
- tc := tests .NewTestContext (w .log )
169
- defer tc .Cleanup ()
170
+ tc := w .newTestContext (ctx )
171
+ // Any assertion failure from this test context will result in process exit due to the
172
+ // panic being rethrown. This ensures that failures in test setup are fatal.
173
+ defer tc .RecoverAndRethrow ()
170
174
require := require .New (tc )
171
175
172
176
xAVAX , pAVAX := e2e .GetWalletBalances (tc , w .wallet )
@@ -177,28 +181,9 @@ func (w *workload) run(ctx context.Context) {
177
181
})
178
182
179
183
for {
180
- val , err := rand .Int (rand .Reader , big .NewInt (5 ))
181
- require .NoError (err , "failed to read randomness" )
182
-
183
- flowID := val .Int64 ()
184
- w .log .Info ("executing test" ,
185
- zap .Int ("workerID" , w .id ),
186
- zap .Int64 ("flowID" , flowID ),
187
- )
188
- switch flowID {
189
- case 0 :
190
- w .issueXChainBaseTx (ctx )
191
- case 1 :
192
- w .issueXChainCreateAssetTx (ctx )
193
- case 2 :
194
- w .issueXChainOperationTx (ctx )
195
- case 3 :
196
- w .issueXToPTransfer (ctx )
197
- case 4 :
198
- w .issuePToXTransfer (ctx )
199
- }
184
+ w .executeTest (ctx )
200
185
201
- val , err = rand .Int (rand .Reader , big .NewInt (int64 (time .Second )))
186
+ val , err : = rand .Int (rand .Reader , big .NewInt (int64 (time .Second )))
202
187
require .NoError (err , "failed to read randomness" )
203
188
204
189
timer .Reset (time .Duration (val .Int64 ()))
@@ -210,6 +195,48 @@ func (w *workload) run(ctx context.Context) {
210
195
}
211
196
}
212
197
198
+ // executeTest executes a test at random.
199
+ func (w * workload ) executeTest (ctx context.Context ) {
200
+ tc := w .newTestContext (ctx )
201
+ // Panics will be recovered without being rethrown, ensuring that test failures are not fatal.
202
+ defer tc .Recover ()
203
+ require := require .New (tc )
204
+
205
+ // Ensure this value matches the number of tests + 1 to offset
206
+ // 0-based + 1 for sleep case in the switch statement for flowID
207
+ testCount := int64 (6 )
208
+
209
+ val , err := rand .Int (rand .Reader , big .NewInt (testCount ))
210
+ require .NoError (err , "failed to read randomness" )
211
+
212
+ flowID := val .Int64 ()
213
+ switch flowID {
214
+ case 0 :
215
+ // TODO(marun) Create abstraction for a test that supports a name e.g. `aTest{name: "foo", mytestfunc}`
216
+ w .log .Info ("executing issueXChainBaseTx" )
217
+ w .issueXChainBaseTx (ctx )
218
+ case 1 :
219
+ w .log .Info ("executing issueXChainCreateAssetTx" )
220
+ w .issueXChainCreateAssetTx (ctx )
221
+ case 2 :
222
+ w .log .Info ("executing issueXChainOperationTx" )
223
+ w .issueXChainOperationTx (ctx )
224
+ case 3 :
225
+ w .log .Info ("executing issueXToPTransfer" )
226
+ w .issueXToPTransfer (ctx )
227
+ case 4 :
228
+ w .log .Info ("executing issuePToXTransfer" )
229
+ w .issuePToXTransfer (ctx )
230
+ case 5 :
231
+ w .log .Info ("sleeping" )
232
+ }
233
+
234
+ // TODO(marun) Enable execution of the banff e2e test as part of https://github.com/ava-labs/avalanchego/issues/4049
235
+ // w.log.Info("executing banff.TestCustomAssetTransfer")
236
+ // addr, _ := w.addrs.Peek()
237
+ // banff.TestCustomAssetTransfer(tc, *w.wallet, addr)
238
+ }
239
+
213
240
func (w * workload ) issueXChainBaseTx (ctx context.Context ) {
214
241
var (
215
242
xWallet = w .wallet .X ()
0 commit comments