Skip to content

Commit fc83acd

Browse files
authored
Assert that the inboxes are not empty. (#2542)
1 parent b6aaf55 commit fc83acd

File tree

2 files changed

+64
-53
lines changed

2 files changed

+64
-53
lines changed

linera-service/src/cli_wrappers/wallet.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -911,10 +911,10 @@ impl NodeService {
911911
self.child.ensure_is_running()
912912
}
913913

914-
pub async fn process_inbox(&self, chain_id: &ChainId) -> Result<()> {
914+
pub async fn process_inbox(&self, chain_id: &ChainId) -> Result<Vec<CryptoHash>> {
915915
let query = format!("mutation {{ processInbox(chainId: \"{chain_id}\") }}");
916-
self.query_node(query).await?;
917-
Ok(())
916+
let mut data = self.query_node(query).await?;
917+
Ok(serde_json::from_value(data["processInbox"].take())?)
918918
}
919919

920920
pub async fn make_application<A: ContractAbi>(

linera-service/tests/linera_net_tests.rs

+61-50
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ async fn test_wasm_end_to_end_fungible(
744744
);
745745

746746
// Needed synchronization though removing it does not get error in 100% of cases.
747-
node_service1.process_inbox(&chain1).await?;
747+
assert_eq!(node_service1.process_inbox(&chain1).await?.len(), 1);
748748

749749
let expected_balances = [
750750
(account_owner1, Amount::from_tokens(5)),
@@ -774,7 +774,7 @@ async fn test_wasm_end_to_end_fungible(
774774
app1.assert_entries(expected_balances).await;
775775
app1.assert_keys([account_owner1, account_owner2]).await;
776776

777-
node_service2.process_inbox(&chain2).await?;
777+
assert_eq!(node_service2.process_inbox(&chain2).await?.len(), 1);
778778

779779
// Fungible didn't exist on chain2 initially but now it does and we can talk to it.
780780
let app2 = FungibleApp(
@@ -807,8 +807,8 @@ async fn test_wasm_end_to_end_fungible(
807807
.await;
808808

809809
// Make sure that the cross-chain communication happens fast enough.
810-
node_service1.process_inbox(&chain1).await?;
811-
node_service2.process_inbox(&chain2).await?;
810+
assert_eq!(node_service1.process_inbox(&chain1).await?.len(), 1);
811+
assert_eq!(node_service2.process_inbox(&chain2).await?.len(), 1);
812812

813813
// Checking the final value
814814
let expected_balances = [
@@ -914,7 +914,7 @@ async fn test_wasm_end_to_end_same_wallet_fungible(
914914
);
915915

916916
// Needed synchronization though removing it does not get error in 100% of cases.
917-
node_service.process_inbox(&chain1).await?;
917+
assert_eq!(node_service.process_inbox(&chain1).await?.len(), 1);
918918

919919
let expected_balances = [
920920
(account_owner1, Amount::from_tokens(5)),
@@ -935,7 +935,7 @@ async fn test_wasm_end_to_end_same_wallet_fungible(
935935
)
936936
.await;
937937

938-
node_service.process_inbox(&chain2).await?;
938+
assert_eq!(node_service.process_inbox(&chain2).await?.len(), 1);
939939

940940
// Checking the final values on chain1 and chain2.
941941
let expected_balances = [
@@ -1054,7 +1054,7 @@ async fn test_wasm_end_to_end_non_fungible(config: impl LineraNetConfig) -> Resu
10541054
)
10551055
.await;
10561056

1057-
node_service2.process_inbox(&chain2).await?;
1057+
assert_eq!(node_service2.process_inbox(&chain2).await?.len(), 1);
10581058

10591059
// Checking the NFT is removed from chain1
10601060
assert!(app1.get_nft(&nft1_id).await.is_err());
@@ -1092,8 +1092,8 @@ async fn test_wasm_end_to_end_non_fungible(config: impl LineraNetConfig) -> Resu
10921092
.await;
10931093

10941094
// Make sure that the cross-chain communication happens fast enough.
1095-
node_service2.process_inbox(&chain2).await?;
1096-
node_service1.process_inbox(&chain1).await?;
1095+
assert_eq!(node_service2.process_inbox(&chain2).await?.len(), 1);
1096+
assert_eq!(node_service1.process_inbox(&chain1).await?.len(), 1);
10971097

10981098
// Checking the NFT is removed from chain2
10991099
assert!(app2.get_nft(&nft1_id).await.is_err());
@@ -1119,7 +1119,7 @@ async fn test_wasm_end_to_end_non_fungible(config: impl LineraNetConfig) -> Resu
11191119
.await;
11201120

11211121
// The transfer is received by chain2 and needs to be processed.
1122-
node_service2.process_inbox(&chain2).await?;
1122+
assert_eq!(node_service2.process_inbox(&chain2).await?.len(), 1);
11231123

11241124
// Checking the NFT is removed from chain1
11251125
assert!(app1.get_nft(&nft1_id).await.is_err());
@@ -1187,7 +1187,7 @@ async fn test_wasm_end_to_end_non_fungible(config: impl LineraNetConfig) -> Resu
11871187
.await;
11881188

11891189
// The transfer from chain2 has to be received from chain1.
1190-
node_service1.process_inbox(&chain1).await?;
1190+
assert_eq!(node_service1.process_inbox(&chain1).await?.len(), 1);
11911191

11921192
// Checking the NFT is removed from chain2
11931193
assert!(app2.get_nft(&nft2_id).await.is_err());
@@ -1217,8 +1217,8 @@ async fn test_wasm_end_to_end_non_fungible(config: impl LineraNetConfig) -> Resu
12171217
.await;
12181218

12191219
// Make sure that the cross-chain communication happens fast enough.
1220-
node_service1.process_inbox(&chain1).await?;
1221-
node_service2.process_inbox(&chain2).await?;
1220+
assert_eq!(node_service1.process_inbox(&chain1).await?.len(), 1);
1221+
assert_eq!(node_service2.process_inbox(&chain2).await?.len(), 1);
12221222

12231223
// Checking the final state
12241224

@@ -1344,8 +1344,8 @@ async fn test_wasm_end_to_end_crowd_funding(config: impl LineraNetConfig) -> Res
13441344

13451345
// Chain2 requests the application from chain1, so chain1 has
13461346
// to receive the request and then chain2 receive the answer.
1347-
node_service1.process_inbox(&chain1).await?;
1348-
node_service2.process_inbox(&chain2).await?;
1347+
assert_eq!(node_service1.process_inbox(&chain1).await?.len(), 1);
1348+
assert_eq!(node_service2.process_inbox(&chain2).await?.len(), 1);
13491349

13501350
let app_crowd2 = node_service2
13511351
.make_application(&chain2, &application_id_crowd)
@@ -1360,7 +1360,7 @@ async fn test_wasm_end_to_end_crowd_funding(config: impl LineraNetConfig) -> Res
13601360
app_crowd2.mutate(mutation).await?;
13611361

13621362
// Make sure that the pledge is processed fast enough by client1.
1363-
node_service1.process_inbox(&chain1).await?;
1363+
assert_eq!(node_service1.process_inbox(&chain1).await?.len(), 1);
13641364

13651365
// Ending the campaign.
13661366
app_crowd1.mutate("collect").await?;
@@ -1475,10 +1475,13 @@ async fn test_wasm_end_to_end_matching_engine(config: impl LineraNetConfig) -> R
14751475
// In an operation node_service_a.request_application(&chain_a, app_b)
14761476
// chain_b needs to process the request first and then chain_a
14771477
// the answer.
1478-
node_service_a.process_inbox(&chain_a).await?;
1479-
node_service_b.process_inbox(&chain_b).await?;
1480-
node_service_a.process_inbox(&chain_a).await?;
1481-
node_service_admin.process_inbox(&chain_admin).await?;
1478+
assert_eq!(node_service_a.process_inbox(&chain_a).await?.len(), 1);
1479+
assert_eq!(node_service_b.process_inbox(&chain_b).await?.len(), 1);
1480+
assert_eq!(node_service_a.process_inbox(&chain_a).await?.len(), 1);
1481+
assert_eq!(
1482+
node_service_admin.process_inbox(&chain_admin).await?.len(),
1483+
1
1484+
);
14821485

14831486
let app_fungible0_a = FungibleApp(node_service_a.make_application(&chain_a, &token0).await?);
14841487
let app_fungible1_a = FungibleApp(node_service_a.make_application(&chain_a, &token1).await?);
@@ -1557,9 +1560,12 @@ async fn test_wasm_end_to_end_matching_engine(config: impl LineraNetConfig) -> R
15571560

15581561
// First chain_admin needs to process the two requests and
15591562
// then chain_a / chain_b the answers.
1560-
node_service_admin.process_inbox(&chain_admin).await?;
1561-
node_service_a.process_inbox(&chain_a).await?;
1562-
node_service_b.process_inbox(&chain_b).await?;
1563+
assert_eq!(
1564+
node_service_admin.process_inbox(&chain_admin).await?.len(),
1565+
1
1566+
);
1567+
assert_eq!(node_service_a.process_inbox(&chain_a).await?.len(), 1);
1568+
assert_eq!(node_service_b.process_inbox(&chain_b).await?.len(), 1);
15631569

15641570
let app_matching_a = MatchingEngineApp(
15651571
node_service_a
@@ -1598,9 +1604,12 @@ async fn test_wasm_end_to_end_matching_engine(config: impl LineraNetConfig) -> R
15981604
// The orders are sent on chain_a / chain_b. First they are
15991605
// rerouted to the admin chain for processing. This leads
16001606
// to order being sent to chain_a / chain_b.
1601-
node_service_admin.process_inbox(&chain_admin).await?;
1602-
node_service_a.process_inbox(&chain_a).await?;
1603-
node_service_b.process_inbox(&chain_b).await?;
1607+
assert_eq!(
1608+
node_service_admin.process_inbox(&chain_admin).await?.len(),
1609+
1
1610+
);
1611+
assert_eq!(node_service_a.process_inbox(&chain_a).await?.len(), 1);
1612+
assert_eq!(node_service_b.process_inbox(&chain_b).await?.len(), 1);
16041613

16051614
// Now reading the order_ids
16061615
let order_ids_a = app_matching_admin.get_account_info(&owner_a).await;
@@ -1628,9 +1637,12 @@ async fn test_wasm_end_to_end_matching_engine(config: impl LineraNetConfig) -> R
16281637
}
16291638

16301639
// Same logic as for the insertion of orders.
1631-
node_service_admin.process_inbox(&chain_admin).await?;
1632-
node_service_a.process_inbox(&chain_a).await?;
1633-
node_service_b.process_inbox(&chain_b).await?;
1640+
assert_eq!(
1641+
node_service_admin.process_inbox(&chain_admin).await?.len(),
1642+
1
1643+
);
1644+
assert_eq!(node_service_a.process_inbox(&chain_a).await?.len(), 1);
1645+
assert_eq!(node_service_b.process_inbox(&chain_b).await?.len(), 1);
16341646

16351647
// Check balances
16361648
app_fungible0_a
@@ -1803,8 +1815,8 @@ async fn test_wasm_end_to_end_amm(config: impl LineraNetConfig) -> Result<()> {
18031815
)
18041816
.await;
18051817

1806-
node_service0.process_inbox(&chain0).await?;
1807-
node_service1.process_inbox(&chain1).await?;
1818+
assert_eq!(node_service0.process_inbox(&chain0).await?.len(), 1);
1819+
assert_eq!(node_service1.process_inbox(&chain1).await?.len(), 1);
18081820

18091821
let app_fungible0_0 = FungibleApp(node_service0.make_application(&chain0, &token0).await?);
18101822
let app_fungible1_0 = FungibleApp(node_service0.make_application(&chain0, &token1).await?);
@@ -1893,9 +1905,9 @@ async fn test_wasm_end_to_end_amm(config: impl LineraNetConfig) -> Result<()> {
18931905

18941906
// The chain_amm must first requests those two requests
18951907
// and then chain0 / chain1 must handle the answers.
1896-
node_service_amm.process_inbox(&chain_amm).await?;
1897-
node_service0.process_inbox(&chain0).await?;
1898-
node_service1.process_inbox(&chain1).await?;
1908+
assert_eq!(node_service_amm.process_inbox(&chain_amm).await?.len(), 1);
1909+
assert_eq!(node_service0.process_inbox(&chain0).await?.len(), 1);
1910+
assert_eq!(node_service1.process_inbox(&chain1).await?.len(), 1);
18991911

19001912
let app_amm0 = AmmApp(
19011913
node_service0
@@ -1919,8 +1931,7 @@ async fn test_wasm_end_to_end_amm(config: impl LineraNetConfig) -> Result<()> {
19191931
.add_liquidity(owner0, Amount::from_tokens(100), Amount::from_tokens(100))
19201932
.await?;
19211933

1922-
node_service_amm.process_inbox(&chain_amm).await?;
1923-
node_service0.process_inbox(&chain0).await?;
1934+
assert_eq!(node_service_amm.process_inbox(&chain_amm).await?.len(), 1);
19241935

19251936
// Ownership of the used owner_amm_chain's tokens should be with the AMM now
19261937
app_fungible0_amm
@@ -1979,8 +1990,8 @@ async fn test_wasm_end_to_end_amm(config: impl LineraNetConfig) -> Result<()> {
19791990
.add_liquidity(owner1, Amount::from_tokens(120), Amount::from_tokens(100))
19801991
.await?;
19811992

1982-
node_service_amm.process_inbox(&chain_amm).await?;
1983-
node_service1.process_inbox(&chain1).await?;
1993+
assert_eq!(node_service_amm.process_inbox(&chain_amm).await?.len(), 1);
1994+
assert_eq!(node_service1.process_inbox(&chain1).await?.len(), 1);
19841995

19851996
app_fungible0_amm
19861997
.assert_balances([
@@ -2039,8 +2050,8 @@ async fn test_wasm_end_to_end_amm(config: impl LineraNetConfig) -> Result<()> {
20392050
.expect_err("Swapping from the AMM chain should fail");
20402051

20412052
app_amm1.swap(owner1, 0, Amount::from_tokens(50)).await?;
2042-
node_service_amm.process_inbox(&chain_amm).await?;
2043-
node_service1.process_inbox(&chain1).await?;
2053+
assert_eq!(node_service_amm.process_inbox(&chain_amm).await?.len(), 1);
2054+
assert_eq!(node_service1.process_inbox(&chain1).await?.len(), 1);
20442055

20452056
app_fungible0_amm
20462057
.assert_balances([
@@ -2108,8 +2119,8 @@ async fn test_wasm_end_to_end_amm(config: impl LineraNetConfig) -> Result<()> {
21082119
app_amm1
21092120
.remove_liquidity(owner1, 0, Amount::from_tokens(500))
21102121
.await?;
2111-
node_service_amm.process_inbox(&chain_amm).await?;
2112-
node_service1.process_inbox(&chain1).await?;
2122+
assert_eq!(node_service_amm.process_inbox(&chain_amm).await?.len(), 1);
2123+
assert_eq!(node_service1.process_inbox(&chain1).await?.len(), 0);
21132124

21142125
// Balances will be unaltered
21152126
app_fungible0_amm
@@ -2164,8 +2175,8 @@ async fn test_wasm_end_to_end_amm(config: impl LineraNetConfig) -> Result<()> {
21642175
.await;
21652176

21662177
app_amm1.swap(owner1, 1, Amount::from_tokens(40)).await?;
2167-
node_service_amm.process_inbox(&chain_amm).await?;
2168-
node_service1.process_inbox(&chain1).await?;
2178+
assert_eq!(node_service_amm.process_inbox(&chain_amm).await?.len(), 1);
2179+
assert_eq!(node_service1.process_inbox(&chain1).await?.len(), 1);
21692180

21702181
app_fungible0_amm
21712182
.assert_balances([
@@ -2221,8 +2232,8 @@ async fn test_wasm_end_to_end_amm(config: impl LineraNetConfig) -> Result<()> {
22212232
app_amm1
22222233
.remove_liquidity(owner1, 0, Amount::from_tokens(100))
22232234
.await?;
2224-
node_service_amm.process_inbox(&chain_amm).await?;
2225-
node_service1.process_inbox(&chain1).await?;
2235+
assert_eq!(node_service_amm.process_inbox(&chain_amm).await?.len(), 1);
2236+
assert_eq!(node_service1.process_inbox(&chain1).await?.len(), 1);
22262237

22272238
app_fungible0_amm
22282239
.assert_balances([
@@ -2276,8 +2287,8 @@ async fn test_wasm_end_to_end_amm(config: impl LineraNetConfig) -> Result<()> {
22762287
.await;
22772288

22782289
app_amm0.swap(owner0, 1, Amount::from_tokens(25)).await?;
2279-
node_service_amm.process_inbox(&chain_amm).await?;
2280-
node_service0.process_inbox(&chain0).await?;
2290+
assert_eq!(node_service_amm.process_inbox(&chain_amm).await?.len(), 1);
2291+
assert_eq!(node_service0.process_inbox(&chain0).await?.len(), 1);
22812292

22822293
app_fungible0_amm
22832294
.assert_balances([
@@ -2331,8 +2342,8 @@ async fn test_wasm_end_to_end_amm(config: impl LineraNetConfig) -> Result<()> {
23312342
.await;
23322343

23332344
app_amm0.remove_all_added_liquidity(owner0).await?;
2334-
node_service_amm.process_inbox(&chain_amm).await?;
2335-
node_service0.process_inbox(&chain0).await?;
2345+
assert_eq!(node_service_amm.process_inbox(&chain_amm).await?.len(), 1);
2346+
assert_eq!(node_service0.process_inbox(&chain0).await?.len(), 1);
23362347

23372348
app_fungible0_amm
23382349
.assert_balances([

0 commit comments

Comments
 (0)