@@ -11,6 +11,7 @@ use spaces_protocol::{
11
11
bitcoin:: { Amount , FeeRate } ,
12
12
constants:: RENEWAL_INTERVAL ,
13
13
script:: SpaceScript ,
14
+ slabel:: SLabel ,
14
15
Covenant ,
15
16
} ;
16
17
use spaces_testutil:: TestRig ;
@@ -336,7 +337,7 @@ async fn it_should_allow_claim_on_or_after_claim_height(rig: &TestRig) -> anyhow
336
337
assert_eq ! (
337
338
all_spaces. owned. len( ) + 1 ,
338
339
all_spaces_2. owned. len( ) ,
339
- "must be equal "
340
+ "eve must have one more space "
340
341
) ;
341
342
342
343
let space = rig
@@ -1282,6 +1283,140 @@ async fn it_should_allow_sign_verify_messages(rig: &TestRig) -> anyhow::Result<(
1282
1283
Ok ( ( ) )
1283
1284
}
1284
1285
1286
+ async fn it_should_track_space_state_in_wallets ( rig : & TestRig ) -> anyhow:: Result < ( ) > {
1287
+ let space = SLabel :: from_str ( "@example9999" ) . expect ( "space name should be correct" ) ;
1288
+ macro_rules! assert_space_in_wallet_collection {
1289
+ ( $wallet: expr, $collection: ident) => { {
1290
+ let spaces = rig. spaced. client. wallet_list_spaces( $wallet) . await ?;
1291
+ assert!(
1292
+ spaces. $collection. iter( ) . any( |s| s
1293
+ . spaceout
1294
+ . space
1295
+ . as_ref( )
1296
+ . map_or( false , |s| s. name == space) ) ,
1297
+ "{} should have {} in the {} set" ,
1298
+ stringify!( $wallet) ,
1299
+ space,
1300
+ stringify!( $collection) ,
1301
+ ) ;
1302
+ } } ;
1303
+ }
1304
+ macro_rules! assert_space_not_in_wallet_collection {
1305
+ ( $wallet: expr, $collection: ident) => { {
1306
+ let spaces = rig. spaced. client. wallet_list_spaces( $wallet) . await ?;
1307
+ assert!(
1308
+ !spaces. $collection. iter( ) . any( |s| s
1309
+ . spaceout
1310
+ . space
1311
+ . as_ref( )
1312
+ . map_or( false , |s| s. name == space) ) ,
1313
+ "{} should not have {} in the {} set" ,
1314
+ stringify!( $wallet) ,
1315
+ space,
1316
+ stringify!( $collection) ,
1317
+ ) ;
1318
+ } } ;
1319
+ }
1320
+ macro_rules! assert_space_not_in_wallet {
1321
+ ( $wallet: expr) => { {
1322
+ assert_space_not_in_wallet_collection!( $wallet, outbid) ;
1323
+ assert_space_not_in_wallet_collection!( $wallet, winning) ;
1324
+ assert_space_not_in_wallet_collection!( $wallet, owned) ;
1325
+ } } ;
1326
+ }
1327
+
1328
+ rig. wait_until_synced ( ) . await ?;
1329
+ rig. wait_until_wallet_synced ( ALICE ) . await ?;
1330
+
1331
+ wallet_do (
1332
+ rig,
1333
+ ALICE ,
1334
+ vec ! [ RpcWalletRequest :: Open ( OpenParams {
1335
+ name: space. to_string( ) ,
1336
+ amount: 1000 ,
1337
+ } ) ] ,
1338
+ false ,
1339
+ )
1340
+ . await
1341
+ . expect ( "send request" ) ;
1342
+
1343
+ rig. mine_blocks ( 1 , None ) . await ?;
1344
+ rig. wait_until_synced ( ) . await ?;
1345
+ rig. wait_until_wallet_synced ( ALICE ) . await ?;
1346
+
1347
+ assert_space_in_wallet_collection ! ( ALICE , winning) ;
1348
+
1349
+ wallet_do (
1350
+ rig,
1351
+ BOB ,
1352
+ vec ! [ RpcWalletRequest :: Bid ( BidParams {
1353
+ name: space. to_string( ) ,
1354
+ amount: 1000000 ,
1355
+ } ) ] ,
1356
+ false ,
1357
+ )
1358
+ . await
1359
+ . expect ( "send request" ) ;
1360
+
1361
+ for _ in 0 ..11 {
1362
+ rig. mine_blocks ( 144 , None ) . await ?;
1363
+ rig. wait_until_synced ( ) . await ?;
1364
+ }
1365
+ rig. wait_until_wallet_synced ( ALICE ) . await ?;
1366
+ rig. wait_until_wallet_synced ( BOB ) . await ?;
1367
+
1368
+ assert_space_in_wallet_collection ! ( ALICE , outbid) ;
1369
+ assert_space_in_wallet_collection ! ( BOB , winning) ;
1370
+
1371
+ wallet_do (
1372
+ rig,
1373
+ BOB ,
1374
+ vec ! [ RpcWalletRequest :: Register ( RegisterParams {
1375
+ name: space. to_string( ) ,
1376
+ to: None ,
1377
+ } ) ] ,
1378
+ false ,
1379
+ )
1380
+ . await
1381
+ . expect ( "send request" ) ;
1382
+
1383
+ rig. mine_blocks ( 1 , None ) . await ?;
1384
+ rig. wait_until_synced ( ) . await ?;
1385
+ rig. wait_until_wallet_synced ( ALICE ) . await ?;
1386
+ rig. wait_until_wallet_synced ( BOB ) . await ?;
1387
+
1388
+ assert_space_not_in_wallet ! ( ALICE ) ;
1389
+ assert_space_in_wallet_collection ! ( BOB , owned) ;
1390
+
1391
+ wallet_do (
1392
+ rig,
1393
+ BOB ,
1394
+ vec ! [ RpcWalletRequest :: Transfer ( TransferSpacesParams {
1395
+ spaces: vec![ space. to_string( ) ] ,
1396
+ to: Some ( rig
1397
+ . spaced
1398
+ . client
1399
+ . wallet_get_new_address( EVE , AddressKind :: Space )
1400
+ . await ?) ,
1401
+ } ) ] ,
1402
+ false ,
1403
+ )
1404
+ . await
1405
+ . expect ( "send request" ) ;
1406
+
1407
+ rig. mine_blocks ( 1 , None ) . await ?;
1408
+ rig. wait_until_synced ( ) . await ?;
1409
+ rig. wait_until_wallet_synced ( ALICE ) . await ?;
1410
+ rig. wait_until_wallet_synced ( BOB ) . await ?;
1411
+ rig. wait_until_wallet_synced ( EVE ) . await ?;
1412
+
1413
+ assert_space_not_in_wallet ! ( ALICE ) ;
1414
+ assert_space_not_in_wallet ! ( BOB ) ;
1415
+ assert_space_in_wallet_collection ! ( EVE , owned) ;
1416
+
1417
+ Ok ( ( ) )
1418
+ }
1419
+
1285
1420
async fn it_should_handle_reorgs ( rig : & TestRig ) -> anyhow:: Result < ( ) > {
1286
1421
rig. wait_until_wallet_synced ( ALICE ) . await . expect ( "synced" ) ;
1287
1422
const NAME : & str = "hello_world" ;
@@ -1350,6 +1485,9 @@ async fn run_auction_tests() -> anyhow::Result<()> {
1350
1485
it_should_allow_sign_verify_messages ( & rig)
1351
1486
. await
1352
1487
. expect ( "should sign verify" ) ;
1488
+ it_should_track_space_state_in_wallets ( & rig)
1489
+ . await
1490
+ . expect ( "should track space state" ) ;
1353
1491
1354
1492
// keep reorgs last as it can drop some txs from mempool and mess up wallet state
1355
1493
it_should_handle_reorgs ( & rig)
0 commit comments