Skip to content

Commit 2472527

Browse files
authored
Merge pull request #4039 from anoma/grarco/adjust-tx-response-output
Improve tx result message
2 parents c61ef69 + 91bd7f3 commit 2472527

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Improved the display of transactions' results.
2+
([\#4039](https://github.com/anoma/namada/pull/4039))

crates/sdk/src/rpc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,8 @@ pub enum InnerTxResult<'a> {
658658
Success(&'a BatchedTxResult),
659659
/// Some VPs rejected the tx
660660
VpsRejected(&'a BatchedTxResult),
661-
/// Transaction failed in some other way
662-
OtherFailure,
661+
/// Transaction failed in some other way specified in the associated message
662+
OtherFailure(String),
663663
}
664664

665665
impl TryFrom<Event> for TxResponse {
@@ -720,7 +720,7 @@ impl TxResponse {
720720
InnerTxResult::VpsRejected(res)
721721
}
722722
}
723-
Err(_) => InnerTxResult::OtherFailure,
723+
Err(msg) => InnerTxResult::OtherFailure(msg.to_owned()),
724724
};
725725
result.insert(inner_hash.to_owned(), value);
726726
}

crates/sdk/src/tx.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -432,16 +432,28 @@ pub async fn submit_tx(
432432

433433
/// Display a result of a tx batch.
434434
pub fn display_batch_resp(context: &impl Namada, resp: &TxResponse) {
435-
for (inner_hash, result) in resp.batch_result() {
435+
// Wrapper-level logs
436+
display_line!(
437+
context.io(),
438+
"Transaction batch {} was applied at height {}, consuming {} gas \
439+
units.",
440+
resp.hash,
441+
resp.height,
442+
resp.gas_used
443+
);
444+
let batch_results = resp.batch_result();
445+
if !batch_results.is_empty() {
446+
display_line!(context.io(), "Batch results:");
447+
}
448+
449+
// Batch-level logs
450+
for (inner_hash, result) in batch_results {
436451
match result {
437452
InnerTxResult::Success(_) => {
438453
display_line!(
439454
context.io(),
440-
"Transaction {} was successfully applied at height {}, \
441-
consuming {} gas units.",
455+
"Transaction {} was successfully applied.",
442456
inner_hash,
443-
resp.height,
444-
resp.gas_used
445457
);
446458
}
447459
InnerTxResult::VpsRejected(inner) => {
@@ -464,12 +476,12 @@ pub fn display_batch_resp(context: &impl Namada, resp: &TxResponse) {
464476
serde_json::to_string_pretty(&changed_keys).unwrap(),
465477
);
466478
}
467-
InnerTxResult::OtherFailure => {
479+
InnerTxResult::OtherFailure(msg) => {
468480
edisplay_line!(
469481
context.io(),
470482
"Transaction {} failed.\nDetails: {}",
471483
inner_hash,
472-
serde_json::to_string_pretty(&resp).unwrap()
484+
msg
473485
);
474486
}
475487
}

crates/tests/src/e2e/ibc_tests.rs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ fn ibc_transfers() -> Result<()> {
120120
None,
121121
None,
122122
None,
123-
false,
124123
)?;
125124
wait_for_packet_relay(&port_id_namada, &channel_id_namada, &test)?;
126125

@@ -182,7 +181,6 @@ fn ibc_transfers() -> Result<()> {
182181
None,
183182
None,
184183
None,
185-
false,
186184
)?;
187185
wait_for_packet_relay(&port_id_namada, &channel_id_namada, &test)?;
188186

@@ -252,7 +250,6 @@ fn ibc_transfers() -> Result<()> {
252250
None,
253251
None,
254252
None,
255-
false,
256253
)?;
257254
wait_for_packet_relay(&port_id_namada, &channel_id_namada, &test)?;
258255
check_balance(&test, AB_VIEWING_KEY, &ibc_denom_on_namada, 40)?;
@@ -299,7 +296,6 @@ fn ibc_transfers() -> Result<()> {
299296
None,
300297
None,
301298
None,
302-
false,
303299
)?;
304300
wait_for_packet_relay(&port_id_namada, &channel_id_namada, &test)?;
305301
// The balance should not be changed
@@ -322,7 +318,6 @@ fn ibc_transfers() -> Result<()> {
322318
Some(Duration::new(10, 0)),
323319
None,
324320
None,
325-
false,
326321
)?;
327322
// wait for the timeout
328323
sleep(10);
@@ -349,7 +344,6 @@ fn ibc_transfers() -> Result<()> {
349344
None,
350345
None,
351346
None,
352-
false,
353347
)?;
354348
wait_for_packet_relay(&port_id_namada, &channel_id_namada, &test)?;
355349
// Check the token has been refunded to the refund target
@@ -374,7 +368,6 @@ fn ibc_transfers() -> Result<()> {
374368
Some(Duration::new(10, 0)),
375369
None,
376370
None,
377-
false,
378371
)?;
379372
// wait for the timeout
380373
sleep(10);
@@ -834,7 +827,6 @@ fn ibc_rate_limit() -> Result<()> {
834827
None,
835828
None,
836829
None,
837-
false,
838830
)?;
839831

840832
// Transfer 1 NAM from Namada to Gaia again will fail
@@ -853,7 +845,6 @@ fn ibc_rate_limit() -> Result<()> {
853845
Some(
854846
"Transfer exceeding the per-epoch throughput limit is not allowed",
855847
),
856-
false,
857848
)?;
858849

859850
// wait for the next epoch
@@ -876,7 +867,6 @@ fn ibc_rate_limit() -> Result<()> {
876867
None,
877868
None,
878869
None,
879-
false,
880870
)?;
881871

882872
// wait for the next epoch
@@ -1116,7 +1106,6 @@ fn try_invalid_transfers(
11161106
None,
11171107
// the IBC denom can't be parsed when using an invalid port
11181108
Some(&format!("Invalid IBC denom: {nam_addr}")),
1119-
false,
11201109
)?;
11211110

11221111
// invalid channel
@@ -1132,7 +1121,6 @@ fn try_invalid_transfers(
11321121
None,
11331122
None,
11341123
Some("IBC token transfer error: context error: `ICS04 Channel error"),
1135-
false,
11361124
)?;
11371125

11381126
Ok(())
@@ -1187,7 +1175,6 @@ fn transfer(
11871175
timeout_sec: Option<Duration>,
11881176
shielding_data_path: Option<PathBuf>,
11891177
expected_err: Option<&str>,
1190-
wait_reveal_pk: bool,
11911178
) -> Result<u32> {
11921179
let rpc = get_actor_rpc(test, Who::Validator(0));
11931180

@@ -1260,11 +1247,10 @@ fn transfer(
12601247
Ok(0)
12611248
}
12621249
None => {
1250+
let height = check_tx_height(test, &mut client)?;
12631251
client.exp_string(TX_APPLIED_SUCCESS)?;
1264-
if wait_reveal_pk {
1265-
client.exp_string(TX_APPLIED_SUCCESS)?;
1266-
}
1267-
check_tx_height(test, &mut client)
1252+
1253+
Ok(height)
12681254
}
12691255
}
12701256
}

0 commit comments

Comments
 (0)