Skip to content

Commit

Permalink
fix(rpc): default to Latest block instead of the backend's if none is… (
Browse files Browse the repository at this point in the history
gakonst#136)

* fix(rpc): default to Latest block instead of the backend's if none is provided

* feat(cli): exit -1 if error in tests
  • Loading branch information
gakonst authored Nov 17, 2021
1 parent 3084676 commit 3184f05
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 5 additions & 1 deletion dapptools/src/dapp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ fn test<A: ArtifactOutput + 'static, S: Clone, E: evm_adapters::Evm<S>>(
) -> eyre::Result<HashMap<String, HashMap<String, dapp::TestResult>>> {
let mut runner = builder.build(project, evm)?;

let mut exit_code = 0;

let results = runner.test(pattern)?;

if json {
Expand All @@ -272,6 +274,8 @@ fn test<A: ArtifactOutput + 'static, S: Clone, E: evm_adapters::Evm<S>>(
let status = if result.success {
Colour::Green.paint("[PASS]")
} else {
// if an error is found, return a -1 exit code
exit_code = -1;
let txt = if let Some(ref reason) = result.reason {
format!("[FAIL: {}]", reason)
} else {
Expand Down Expand Up @@ -308,5 +312,5 @@ fn test<A: ArtifactOutput + 'static, S: Clone, E: evm_adapters::Evm<S>>(
}
}

Ok(results)
std::process::exit(exit_code);
}
7 changes: 6 additions & 1 deletion evm-adapters/src/blocking_provider.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use ethers::{
prelude::BlockNumber,
providers::Middleware,
types::{Address, Block, BlockId, Bytes, TxHash, H256, U256, U64},
};
Expand Down Expand Up @@ -30,7 +31,11 @@ where
self.runtime.block_on(f)
}

pub fn block_and_chainid(&self, block_id: BlockId) -> eyre::Result<(Block<TxHash>, U256)> {
pub fn block_and_chainid(
&self,
block_id: Option<impl Into<BlockId>>,
) -> eyre::Result<(Block<TxHash>, U256)> {
let block_id = block_id.map(Into::into).unwrap_or(BlockId::Number(BlockNumber::Latest));
let f = async {
let block = self.provider.get_block(block_id);
let chain_id = self.provider.get_chainid();
Expand Down
3 changes: 1 addition & 2 deletions evm-adapters/src/sputnik/forked_backend/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ where
init_cache: BTreeMap<H160, MemoryAccount>,
) -> Self {
let provider = BlockingProvider::new(provider);
let pin_block = pin_block.unwrap_or_else(|| backend.block_number().as_u64()).into();

// get the remaining block metadata
let (block, chain_id) =
Expand All @@ -57,7 +56,7 @@ where
provider,
backend,
cache: RefCell::new(init_cache),
pin_block: Some(pin_block),
pin_block: pin_block.map(Into::into),
pin_block_meta: block,
chain_id,
}
Expand Down

0 comments on commit 3184f05

Please sign in to comment.