From 2724ef3742c839256e6cf6418976a14c59083463 Mon Sep 17 00:00:00 2001 From: Dowland Aiello Date: Fri, 28 Jun 2024 07:59:20 -0700 Subject: [PATCH] Allow another logs format for get_tx_events. --- examples/configs/logs.json | 6 +++--- src/utils/fixtures.rs | 30 ++++++++++++++++++++++-------- src/utils/setup/astroport.rs | 13 +------------ 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/examples/configs/logs.json b/examples/configs/logs.json index c089c9e..d88c6e8 100644 --- a/examples/configs/logs.json +++ b/examples/configs/logs.json @@ -1,5 +1,5 @@ { - "start_time": 1719573012, + "start_time": 1719586636, "chains": [ { "chain_id": "localcosmos-1", @@ -7,7 +7,7 @@ "rpc_address": "http://0.0.0.0:26658", "rest_address": "http://0.0.0.0:1318", "grpc_address": "0.0.0.0:9091", - "p2p_address": "0.0.0.0:45505", + "p2p_address": "0.0.0.0:35401", "ibc_paths": [] }, { @@ -16,7 +16,7 @@ "rpc_address": "http://0.0.0.0:26657", "rest_address": "http://0.0.0.0:1317", "grpc_address": "0.0.0.0:9090", - "p2p_address": "0.0.0.0:45843", + "p2p_address": "0.0.0.0:33347", "ibc_paths": [] } ], diff --git a/src/utils/fixtures.rs b/src/utils/fixtures.rs index 9e27976..1a10a37 100644 --- a/src/utils/fixtures.rs +++ b/src/utils/fixtures.rs @@ -12,7 +12,7 @@ use std::path::PathBuf; impl TestContext { /// Gets the event log of a transaction as a JSON object, /// or returns an error if it does not exist. - pub fn get_tx_events(&self, chain_id: &str, hash: &str) -> Result, Error> { + pub fn get_tx_events(&self, chain_id: &str, hash: &str) -> Result>, Error> { let chain = self.get_chain(chain_id); let logs = chain.rb.query_tx_hash(hash); @@ -21,14 +21,25 @@ impl TestContext { .and_then(|raw_log| raw_log.as_str()) .ok_or(Error::TxMissingLogs)?; - if serde_json::from_str::(raw_log).is_err() { - return Err(Error::TxFailed { - hash: hash.to_owned(), - error: raw_log.to_owned(), - }); + let logs = serde_json::from_str::(raw_log).map_err(|_| Error::TxFailed { + hash: hash.to_owned(), + error: raw_log.to_owned(), + })?; + + // raw_log can be an array or just the event itself + if let Some(arr) = logs.as_array() { + return arr + .into_iter() + .map(|msg| { + msg.get("events") + .cloned() + .and_then(|events| events.as_array().cloned()) + .ok_or(Error::TxMissingLogs) + }) + .collect::>, Error>>(); } - let logs = logs.get("events").ok_or(Error::TxMissingLogs)?; + let events = logs.get("events").ok_or(Error::TxMissingLogs)?; if let Some(err) = logs.as_str() { return Err(Error::TxFailed { @@ -37,7 +48,10 @@ impl TestContext { }); } - logs.as_array().cloned().ok_or(Error::TxMissingLogs) + Ok(vec![events + .as_array() + .cloned() + .ok_or(Error::TxMissingLogs)?]) } /// Get a new CosmWasm instance for a contract identified by a name. diff --git a/src/utils/setup/astroport.rs b/src/utils/setup/astroport.rs index be9304b..fe5d64a 100644 --- a/src/utils/setup/astroport.rs +++ b/src/utils/setup/astroport.rs @@ -400,18 +400,7 @@ impl TestContext { "transaction did not produce a tx hash", )))?; - let logs = self.get_tx_events(NEUTRON_CHAIN_ID, tx_hash.as_str())?; - - let addr = logs - .into_iter() - .find(|event| { - event.get("type").and_then(|maybe_ty| maybe_ty.as_str()) == Some("instantiate") - }) - .and_then(|mut event| event.get_mut("attributes").map(|e| e.take())) - .and_then(|attrs| Some(attrs.as_array()?.get(0)?.get("value")?.as_str()?.to_owned())) - .ok_or(Error::ContainerCmd(String::from("query create_pool logs")))?; - - log::debug!("created pool: {}", addr); + let _ = self.get_tx_events(NEUTRON_CHAIN_ID, tx_hash.as_str())?; Ok(()) }