Skip to content

Commit

Permalink
fix execution tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ncitron committed Aug 22, 2023
1 parent a3ed492 commit 618c437
Show file tree
Hide file tree
Showing 9 changed files with 277 additions and 282 deletions.
8 changes: 7 additions & 1 deletion common/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fmt::Display;
use ethers::types::{Address, Bytes, Transaction, H256, U256, U64};
use serde::{de::Error, ser::SerializeSeq, Deserialize, Serialize};

#[derive(Deserialize, Serialize, Debug, Clone)]
#[derive(Deserialize, Serialize, Debug, Clone, Default)]
#[serde(rename_all = "camelCase")]
pub struct Block {
pub number: U64,
Expand Down Expand Up @@ -35,6 +35,12 @@ pub enum Transactions {
Full(Vec<Transaction>),
}

impl Default for Transactions {
fn default() -> Self {
Self::Full(Vec::new())
}
}

impl Transactions {
pub fn hashes(&self) -> Vec<H256> {
match self {
Expand Down
6 changes: 3 additions & 3 deletions consensus/tests/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ async fn setup() -> ConsensusClient<MockRpc, ConfigDB> {

#[tokio::test]
async fn test_sync() {
let mut client = setup().await;
let client = setup().await;

let payload = client.payload_recv.recv().await.unwrap();
assert_eq!(payload.block_number().as_u64(), 17923113);
let block = client.block_recv.unwrap().recv().await.unwrap();
assert_eq!(block.number.as_u64(), 17923113);
}
2 changes: 1 addition & 1 deletion examples/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async fn main() -> eyre::Result<()> {
gas: Some(U256::from(U64::MAX.as_u64())),
gas_price: None,
value: None,
data: Some(encoded_call.to_vec()),
data: Some(encoded_call),
};
log::debug!("Calling helios client on block: {block:?}");
let result = client.call(&call_opts, block).await?;
Expand Down
57 changes: 16 additions & 41 deletions execution/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,10 @@ impl<R: ExecutionRpc> Evm<R> {
let mut db = self.evm.db.take().unwrap();

if res.is_err() && db.state.needs_update() {
println!("updating state");
db.state.update_state().await.unwrap();
self.evm = EVM::<ProofDB<R>>::new();
self.evm.database(db);
} else {
println!("breaking");
break res;
}
};
Expand Down Expand Up @@ -352,58 +350,35 @@ fn is_precompile(address: &B160) -> bool {

#[cfg(test)]
mod tests {
use common::utils::hex_str_to_bytes;
use consensus::types::{primitives::ByteVector, ExecutionPayloadBellatrix};
use tokio::sync::{mpsc::channel, watch};

use crate::rpc::mock_rpc::MockRpc;
use crate::{rpc::mock_rpc::MockRpc, state::State};

use super::*;

fn get_client() -> ExecutionClient<MockRpc> {
ExecutionClient::new("testdata/").unwrap()
let (_, block_recv) = channel(256);
let (_, finalized_recv) = watch::channel(None);
let state = State::new(block_recv, finalized_recv, 64);
ExecutionClient::new("testdata/", state).unwrap()
}

#[tokio::test]
async fn test_proof_db() {
// Construct proofdb params
let execution = get_client();
let address = Address::from_str("14f9D4aF749609c1438528C0Cce1cC3f6D411c47").unwrap();
let payload = ExecutionPayload::Bellatrix(ExecutionPayloadBellatrix {
state_root: ByteVector::try_from(
hex_str_to_bytes(
"0xaa02f5db2ee75e3da400d10f3c30e894b6016ce8a2501680380a907b6674ce0d",
)
.unwrap(),
)
.unwrap(),
..ExecutionPayloadBellatrix::default()
});

let mut payloads = BTreeMap::new();
payloads.insert(7530933, payload.clone());

// Construct the proof database with the given client and payloads
let mut proof_db = ProofDB::new(Arc::new(execution), &payload, &payloads);

// Set the proof db accounts
let slot = U256::from(1337);
let mut accounts = HashMap::new();
let account = Account {
balance: U256::from(100),
code: hex_str_to_bytes("0x").unwrap(),
..Default::default()
};
accounts.insert(address, account);
proof_db.set_accounts(accounts);
let tag = BlockTag::Latest;

// Construct the proof database with the given client
let mut proof_db = ProofDB::new(tag, Arc::new(execution));

let address = B160::from_str("0x388C818CA8B9251b393131C08a736A67ccB19297").unwrap();
let info = AccountInfo::new(U256::from(500), 10, Bytecode::new_raw(Bytes::default()));
proof_db.state.basic.insert(address, info.clone());

// Get the account from the proof database
let storage_proof = proof_db.storage(address, slot);
let account = proof_db.basic(address).unwrap().unwrap();

// Check that the storage proof correctly returns a slot not found error
let expected_err: eyre::Report = SlotNotFoundError::new(H256::from_uint(&slot)).into();
assert_eq!(
expected_err.to_string(),
storage_proof.unwrap_err().to_string()
);
assert_eq!(account, info);
}
}
4 changes: 4 additions & 0 deletions execution/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ impl State {
Self { inner }
}

pub async fn push_block(&self, block: Block) {
self.inner.write().await.push_block(block);
}

// full block fetch

pub async fn get_block(&self, tag: BlockTag) -> Option<Block> {
Expand Down
Loading

0 comments on commit 618c437

Please sign in to comment.