Skip to content

Commit

Permalink
rpc: Fix deserialization of /block_results response when some tx re…
Browse files Browse the repository at this point in the history
…sults are non-ok (#1391)

* rpc: Add fixture test for Sei `block_results` with failed txs

* rpc: Fix deserialization of `/block_results` response when some tx results are non-ok

* Add changelog entry
  • Loading branch information
romac authored Mar 14, 2024
1 parent 6e2baf2 commit ac27ea5
Show file tree
Hide file tree
Showing 5 changed files with 3,446 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .changelog/unreleased/bug-fixes/1391-block-results-not-ok.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- `[tendermint-rpc]` Fix deserialization of `/block_results` response when some
tx results are non-ok ([\#1391](https://github.com/informalsystems/tendermint-
rs/pull/1391))
18 changes: 15 additions & 3 deletions rpc/src/dialect/deliver_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,39 @@ pub struct DeliverTx<Ev> {
/// This code should be `0` only if the transaction is fully valid. However,
/// invalid transactions included in a block will still be executed against
/// the application state.
#[serde(default)]
pub code: Code,

/// Result bytes, if any.
#[serde(with = "serializers::nullable")]
#[serde(default, with = "serializers::nullable")]
pub data: Bytes,

/// The output of the application's logger.
///
/// **May be non-deterministic**.
#[serde(default)]
pub log: String,

/// Additional information.
///
/// **May be non-deterministic**.
#[serde(default)]
pub info: String,

/// Amount of gas requested for the transaction.
#[serde(with = "serializers::from_str")]
#[serde(default, with = "serializers::from_str")]
pub gas_wanted: i64,

/// Amount of gas consumed by the transaction.
#[serde(with = "serializers::from_str")]
#[serde(default, with = "serializers::from_str")]
pub gas_used: i64,

/// Events that occurred while executing the transaction.
#[serde(default = "Vec::new")]
pub events: Vec<Ev>,

/// The namespace for the `code`.
#[serde(default)]
pub codespace: String,
}

Expand Down
53 changes: 53 additions & 0 deletions rpc/tests/sei_fixtures.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use std::{fs, path::PathBuf};

use tendermint_rpc::{endpoint, Response};

use walkdir::WalkDir;

fn find_fixtures(in_out_folder_name: &str) -> Vec<PathBuf> {
WalkDir::new(
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests")
.join("sei_fixtures")
.join(in_out_folder_name),
)
.into_iter()
.filter_map(|e| e.ok())
.filter(|e| {
e.file_type().is_file()
&& e.path().extension().is_some()
&& e.path().extension().unwrap() == "json"
})
.map(|e| e.into_path())
.collect::<Vec<PathBuf>>()
}

#[test]
fn incoming_fixtures() {
for json_file in find_fixtures("incoming") {
let file_name = json_file
.file_name()
.unwrap()
.to_str()
.unwrap()
.strip_suffix(".json")
.unwrap();

let content = fs::read_to_string(&json_file).unwrap();

match file_name {
"block_results_with_failed_txs" => {
let r = endpoint::block_results::Response::from_string(&content);
dbg!(&r);
assert!(r.is_ok(), "block_results_with_failed_txs (v0.37+): {r:?}");

let r = endpoint::block_results::v0_34::DialectResponse::from_string(&content);
dbg!(&r);
assert!(r.is_ok(), "block_results_with_failed_txs (v0.34): {r:?}");
},
_ => {
panic!("unhandled incoming fixture: {file_name}");
},
}
}
}
Loading

0 comments on commit ac27ea5

Please sign in to comment.