Skip to content

Commit eab9ac3

Browse files
committed
it_should_track_space_state_in_wallets test
1 parent 697c180 commit eab9ac3

File tree

1 file changed

+139
-1
lines changed

1 file changed

+139
-1
lines changed

client/tests/integration_tests.rs

+139-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use spaces_protocol::{
1111
bitcoin::{Amount, FeeRate},
1212
constants::RENEWAL_INTERVAL,
1313
script::SpaceScript,
14+
slabel::SLabel,
1415
Covenant,
1516
};
1617
use spaces_testutil::TestRig;
@@ -336,7 +337,7 @@ async fn it_should_allow_claim_on_or_after_claim_height(rig: &TestRig) -> anyhow
336337
assert_eq!(
337338
all_spaces.owned.len() + 1,
338339
all_spaces_2.owned.len(),
339-
"must be equal"
340+
"eve must have one more space"
340341
);
341342

342343
let space = rig
@@ -1282,6 +1283,140 @@ async fn it_should_allow_sign_verify_messages(rig: &TestRig) -> anyhow::Result<(
12821283
Ok(())
12831284
}
12841285

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+
12851420
async fn it_should_handle_reorgs(rig: &TestRig) -> anyhow::Result<()> {
12861421
rig.wait_until_wallet_synced(ALICE).await.expect("synced");
12871422
const NAME: &str = "hello_world";
@@ -1350,6 +1485,9 @@ async fn run_auction_tests() -> anyhow::Result<()> {
13501485
it_should_allow_sign_verify_messages(&rig)
13511486
.await
13521487
.expect("should sign verify");
1488+
it_should_track_space_state_in_wallets(&rig)
1489+
.await
1490+
.expect("should track space state");
13531491

13541492
// keep reorgs last as it can drop some txs from mempool and mess up wallet state
13551493
it_should_handle_reorgs(&rig)

0 commit comments

Comments
 (0)