4
4
"bytes"
5
5
"context"
6
6
"encoding/hex"
7
+ "errors"
7
8
"fmt"
8
9
"reflect"
9
10
"sort"
@@ -2174,6 +2175,17 @@ func AssertBalances(t *testing.T, client taprpc.TaprootAssetsClient,
2174
2175
2175
2176
t .Helper ()
2176
2177
2178
+ err := wait .NoError (func () error {
2179
+ return assertBalances (t , client , balance , opts ... )
2180
+ }, 10 * time .Second )
2181
+ if err != nil {
2182
+ t .Fatal (err )
2183
+ }
2184
+ }
2185
+
2186
+ func assertBalances (t * testing.T , client taprpc.TaprootAssetsClient ,
2187
+ balance uint64 , opts ... BalanceOption ) error {
2188
+
2177
2189
config := & balanceConfig {}
2178
2190
for _ , opt := range opts {
2179
2191
opt (config )
@@ -2231,7 +2243,9 @@ func AssertBalances(t *testing.T, client taprpc.TaprootAssetsClient,
2231
2243
GroupKeyFilter : config .groupKey ,
2232
2244
},
2233
2245
)
2234
- require .NoError (t , err )
2246
+ if err != nil {
2247
+ return err
2248
+ }
2235
2249
2236
2250
// Spent assets (burns/tombstones) are never included in the balance,
2237
2251
// even if we specifically query for their type. So we skip the balance
@@ -2242,11 +2256,9 @@ func AssertBalances(t *testing.T, client taprpc.TaprootAssetsClient,
2242
2256
* config .scriptKeyType != asset .ScriptKeyTombstone )) &&
2243
2257
len (config .scriptKey ) == 0
2244
2258
if checkBalance {
2245
- require .Equal (
2246
- t , balance , balanceSum (assetIDBalances , false ),
2247
- "asset balance, wanted %d, got: %v" , balance ,
2248
- toJSON (t , assetIDBalances ),
2249
- )
2259
+ if balance != balanceSum (assetIDBalances , false ) {
2260
+ return fmt .Errorf ("asset balance, wanted %d, got: %v" , balance , toJSON (t , assetIDBalances ))
2261
+ }
2250
2262
}
2251
2263
2252
2264
// Next, we do the same but grouped by group keys (if requested, since
@@ -2261,18 +2273,17 @@ func AssertBalances(t *testing.T, client taprpc.TaprootAssetsClient,
2261
2273
GroupKeyFilter : config .groupKey ,
2262
2274
},
2263
2275
)
2264
- require .NoError (t , err )
2276
+ if err != nil {
2277
+ return err
2278
+ }
2265
2279
2266
2280
// Spent assets (burns/tombstones) are never included in the
2267
2281
// balance, even if we specifically query for their type. So we
2268
2282
// skip the balance check in that case.
2269
2283
if checkBalance {
2270
- require .Equalf (
2271
- t , config .groupedAssetBalance ,
2272
- balanceSum (assetGroupBalances , true ),
2273
- "grouped balance, wanted %d, got: %v" , balance ,
2274
- toJSON (t , assetGroupBalances ),
2275
- )
2284
+ if config .groupedAssetBalance != balanceSum (assetGroupBalances , true ) {
2285
+ return fmt .Errorf ("grouped balance, wanted %d, got: %v" , balance , toJSON (t , assetGroupBalances ))
2286
+ }
2276
2287
}
2277
2288
}
2278
2289
@@ -2282,7 +2293,9 @@ func AssertBalances(t *testing.T, client taprpc.TaprootAssetsClient,
2282
2293
IncludeLeased : config .includeLeased ,
2283
2294
ScriptKeyType : rpcTypeQuery ,
2284
2295
})
2285
- require .NoError (t , err )
2296
+ if err != nil {
2297
+ return err
2298
+ }
2286
2299
2287
2300
var (
2288
2301
totalBalance uint64
@@ -2320,26 +2333,26 @@ func AssertBalances(t *testing.T, client taprpc.TaprootAssetsClient,
2320
2333
totalBalance += a .Amount
2321
2334
numUtxos ++
2322
2335
}
2323
- require .Equalf (
2324
- t , balance , totalBalance , "ListAssets balance, wanted %d, " +
2325
- "got: %v" , balance , toJSON (t , assetList ),
2326
- )
2336
+ if balance != totalBalance {
2337
+ return fmt .Errorf ("ListAssets balance, wanted %d, got: %v" , balance , toJSON (t , assetList ))
2338
+ }
2327
2339
2328
2340
// The number of UTXOs means asset outputs in this case. We check the
2329
2341
// BTC-level UTXOs below as well, but that's just to make sure the
2330
2342
// output of that RPC lists the same assets.
2331
2343
if config .numAssetUtxos > 0 {
2332
- require .Equal (
2333
- t , config .numAssetUtxos , numUtxos , "ListAssets num " +
2334
- "asset utxos" ,
2335
- )
2344
+ if config .numAssetUtxos != numUtxos {
2345
+ return errors .New ("ListAssets num asset utxos" )
2346
+ }
2336
2347
}
2337
2348
2338
2349
utxoList , err := client .ListUtxos (ctxt , & taprpc.ListUtxosRequest {
2339
2350
IncludeLeased : config .includeLeased ,
2340
2351
ScriptKeyType : rpcTypeQuery ,
2341
2352
})
2342
- require .NoError (t , err )
2353
+ if err != nil {
2354
+ return err
2355
+ }
2343
2356
2344
2357
// Make sure the ListUtxos call returns the same number of (asset) UTXOs
2345
2358
// as the ListAssets call.
@@ -2386,20 +2399,22 @@ func AssertBalances(t *testing.T, client taprpc.TaprootAssetsClient,
2386
2399
numUtxos ++
2387
2400
}
2388
2401
}
2389
- require .Equal (t , balance , totalBalance , "ListUtxos balance" )
2402
+ if balance != totalBalance {
2403
+ return errors .New ("ListUtxos balance" )
2404
+ }
2390
2405
2391
2406
if config .numAnchorUtxos > 0 {
2392
- require .Equal (
2393
- t , config .numAnchorUtxos , numAnchorUtxos , "num anchor " +
2394
- "utxos" ,
2395
- )
2407
+ if config .numAnchorUtxos != numAnchorUtxos {
2408
+ return errors .New ("num anchor utxos" )
2409
+ }
2396
2410
}
2397
2411
if config .numAssetUtxos > 0 {
2398
- require .Equal (
2399
- t , config .numAssetUtxos , numUtxos , "ListUtxos num " +
2400
- "asset utxos" ,
2401
- )
2412
+ if config .numAssetUtxos != numUtxos {
2413
+ return errors .New ("ListUtxos num asset utxos" )
2414
+ }
2402
2415
}
2416
+
2417
+ return nil
2403
2418
}
2404
2419
2405
2420
func assertGroups (t * testing.T , client taprpc.TaprootAssetsClient ,
0 commit comments