Skip to content

Commit

Permalink
Add an option for skipping logs unwrapping.
Browse files Browse the repository at this point in the history
  • Loading branch information
dowlandaiello committed Jun 29, 2024
1 parent 6421c25 commit 09da67b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/neutron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ fn main() -> Result<(), Box<dyn Error>> {

// Create a testcontext
let mut ctx = TestContextBuilder::default()
.with_unwrap_raw_logs(true)
.with_api_url("http://localhost:42069/")
.with_artifacts_dir("contracts")
.with_chain(ConfigChainBuilder::default_neutron().build()?)
Expand Down
4 changes: 4 additions & 0 deletions src/utils/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ impl TestContext {
/// Gets the event log of a transaction as a JSON object,
/// or returns an error if it does not exist.
pub fn guard_tx_errors(&self, chain_name: &str, hash: &str) -> Result<(), Error> {
if !self.unwrap_logs {
return Ok(());
}

let chain = self.get_chain(chain_name);
let logs = chain.rb.query_tx_hash(hash);

Expand Down
14 changes: 14 additions & 0 deletions src/utils/test_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub struct TestContextBuilder {
connection_ids: HashMap<(String, String), String>,
ibc_denoms: HashMap<(String, String), String>,
artifacts_dir: Option<String>,
unwrap_raw_logs: bool,
}

impl Default for TestContextBuilder {
Expand All @@ -39,6 +40,7 @@ impl Default for TestContextBuilder {
connection_ids: Default::default(),
ibc_denoms: Default::default(),
artifacts_dir: Default::default(),
unwrap_raw_logs: Default::default(),
}
}
}
Expand Down Expand Up @@ -164,6 +166,13 @@ impl TestContextBuilder {
self
}

/// Sets the artifacts dir to the specified directory.
pub fn with_unwrap_raw_logs(&mut self, unwrap_logs: bool) -> &mut Self {
self.unwrap_raw_logs = unwrap_logs;

self
}

/// Builds a TestContext from the specified options.
pub fn build(&self) -> Result<TestContext, BuildError> {
let TestContextBuilder {
Expand All @@ -174,6 +183,7 @@ impl TestContextBuilder {
ibc_denoms,
api_url,
artifacts_dir,
unwrap_raw_logs,
} = self;

// Upload contract artifacts
Expand Down Expand Up @@ -230,6 +240,7 @@ impl TestContextBuilder {
auctions_manager: None,
astroport_token_registry: None,
astroport_factory: None,
unwrap_logs: *unwrap_raw_logs,
})
}
}
Expand All @@ -254,6 +265,9 @@ pub struct TestContext {
/// Astroport deployment info
pub astroport_token_registry: Option<DeployedContractInfo>,
pub astroport_factory: Option<DeployedContractInfo>,

/// Whether or not logs should be expected and guarded for each tx
pub unwrap_logs: bool,
}

#[derive(Debug)]
Expand Down

0 comments on commit 09da67b

Please sign in to comment.