Skip to content

Commit c5eecef

Browse files
Add a test demonstrating how to pass multiple mutations in the node_service. (#4539)
## Motivation It is quite reasonable for users to want to do several operations in just one block. ## Proposal The solution is simply to formulate the multiple mutations by using a construction of the GraphQL queries. ## Test Plan In order to have multiple operations, an operation `repeated_transfer` was added to the `NativeFungibleApp`. The test `test_wasm_end_to_end_same_wallet_fungible` was modified accordingly. ## Release Plan The change is fully compatible with the existing codebase. ## Links None.
1 parent 2854448 commit c5eecef

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

linera-service/src/cli_wrappers/wallet.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,6 +1652,15 @@ impl<A> ApplicationWrapper<A> {
16521652
self.run_graphql_query(&format!("mutation {{ {mutation} }}"))
16531653
.await
16541654
}
1655+
1656+
pub async fn multiple_mutate(&self, mutations: &[String]) -> Result<Value> {
1657+
let mut out = String::from("mutation {\n");
1658+
for (index, mutation) in mutations.iter().enumerate() {
1659+
out = format!("{} u{}: {}\n", out, index, mutation);
1660+
}
1661+
out.push_str("}\n");
1662+
self.run_graphql_query(&out).await
1663+
}
16551664
}
16561665

16571666
impl<A> From<String> for ApplicationWrapper<A> {

linera-service/tests/linera_net_tests.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,23 @@ impl NativeFungibleApp {
155155
self.0.mutate(mutation).await.unwrap()
156156
}
157157

158+
async fn repeated_transfer(
159+
&self,
160+
account_owner: &AccountOwner,
161+
amount_transfer: Amount,
162+
destination: Account,
163+
num_operations: usize,
164+
) -> Value {
165+
let mutation = format!(
166+
"transfer(owner: {}, amount: \"{}\", targetAccount: {})",
167+
account_owner.to_value(),
168+
amount_transfer,
169+
destination.to_value(),
170+
);
171+
let mutations = vec![mutation; num_operations];
172+
self.0.multiple_mutate(&mutations).await.unwrap()
173+
}
174+
158175
async fn claim(&self, source: Account, target: Account, amount: Amount) {
159176
// Claiming tokens from chain1 to chain2.
160177
let mutation = format!(
@@ -2375,21 +2392,22 @@ async fn test_wasm_end_to_end_same_wallet_fungible(
23752392
app1.assert_entries(expected_balances).await;
23762393
app1.assert_keys([account_owner1, account_owner2]).await;
23772394
// Transferring
2378-
app1.transfer(
2395+
app1.repeated_transfer(
23792396
&account_owner1,
23802397
Amount::ONE,
23812398
Account {
23822399
chain_id: chain2,
23832400
owner: account_owner2,
23842401
},
2402+
4,
23852403
)
23862404
.await;
23872405

23882406
assert_eq!(node_service.process_inbox(&chain2).await?.len(), 1);
23892407

23902408
// Checking the final values on chain1 and chain2.
23912409
let expected_balances = [
2392-
(account_owner1, Amount::from_tokens(4)),
2410+
(account_owner1, Amount::from_tokens(1)),
23932411
(account_owner2, Amount::from_tokens(2)),
23942412
];
23952413
app1.assert_balances(expected_balances).await;
@@ -2398,7 +2416,7 @@ async fn test_wasm_end_to_end_same_wallet_fungible(
23982416

23992417
let app2 = NativeFungibleApp(node_service.make_application(&chain2, &application_id)?);
24002418

2401-
let expected_balances = [(account_owner2, Amount::ONE)];
2419+
let expected_balances = [(account_owner2, Amount::from_tokens(4))];
24022420
app2.assert_balances(expected_balances).await;
24032421
app2.assert_entries(expected_balances).await;
24042422
app2.assert_keys([account_owner2]).await;

0 commit comments

Comments
 (0)