From 5067c4d7ae43bf5463cad86fb844eb9fa811172a Mon Sep 17 00:00:00 2001 From: Colin Roberts Date: Tue, 25 Jul 2023 11:29:49 -0600 Subject: [PATCH] transact test finished :smiley: --- core/src/bindings/mod.rs | 9 +++++++++ core/src/middleware.rs | 31 +++++++++++++++++++++++++------ core/src/tests/mod.rs | 10 ++++++++++ core/src/utils.rs | 8 ++++++-- 4 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 core/src/bindings/mod.rs diff --git a/core/src/bindings/mod.rs b/core/src/bindings/mod.rs new file mode 100644 index 00000000..89a6a7db --- /dev/null +++ b/core/src/bindings/mod.rs @@ -0,0 +1,9 @@ +#![allow(clippy::all)] +#![allow(missing_docs)] +//! This lib contains abigen! generated bindings for solidity contracts. +//! This is autogenerated code. +//! Do not manually edit these files. +//! These files may be overwritten by the codegen system at any time. +pub mod arbiter_math; +pub mod arbiter_token; +pub mod liquid_exchange; \ No newline at end of file diff --git a/core/src/middleware.rs b/core/src/middleware.rs index 79d16b00..cca637f7 100644 --- a/core/src/middleware.rs +++ b/core/src/middleware.rs @@ -18,7 +18,7 @@ use revm::primitives::{CreateScheme, ExecutionResult, Output, TransactTo, TxEnv, use std::fmt::Debug; use crate::environment::Connection; -use crate::utils::recast_address; +use crate::utils::{recast_address, recast_b256}; // TODO: Refactor the connection and channels slightly to be more intuitive #[derive(Debug)] @@ -100,8 +100,8 @@ impl Middleware for RevmMiddleware { .send((true, tx_env.clone(), self.result_sender.clone())) .unwrap(); let result = self.result_receiver.recv().unwrap(); - let output = match result.clone() { - ExecutionResult::Success { output, .. } => output, + let (output, revm_logs) = match result.clone() { + ExecutionResult::Success { output, logs, .. } => (output, logs), ExecutionResult::Revert { output, .. } => panic!("Failed due to revert: {:?}", output), ExecutionResult::Halt { reason, .. } => panic!("Failed due to halt: {:?}", reason), }; @@ -109,13 +109,32 @@ impl Middleware for RevmMiddleware { Output::Create(_, address) => { let mut pending_tx = PendingTransaction::new(ethers::types::H256::zero(), self.provider()); - pending_tx.state = PendingTxState::RevmReceipt(recast_address(address.unwrap())); + pending_tx.state = PendingTxState::RevmDeployOutput(recast_address(address.unwrap())); return Ok(pending_tx); } - Output::Call(bytes) => { + Output::Call(_) => { let mut pending_tx = PendingTransaction::new(ethers::types::H256::zero(), self.provider()); - pending_tx.state = PendingTxState::RevmReceipt(Address::from_low_u64_be(1)); + let mut logs: Vec = vec![]; + for revm_log in revm_logs { + let topics = revm_log.topics.into_iter().map(|x| recast_b256(x)).collect(); + let log = ethers::core::types::Log { + address: recast_address(revm_log.address), + topics: topics, + data: ethers::core::types::Bytes::from(revm_log.data), + block_hash: None, + block_number: None, + transaction_hash: None, + transaction_index: None, + log_index: None, + transaction_log_index: None, + log_type: None, + removed: None, + }; + logs.push(log); + } + + pending_tx.state = PendingTxState::RevmTransactOutput(logs); return Ok(pending_tx); } } diff --git a/core/src/tests/mod.rs b/core/src/tests/mod.rs index d0eea263..06240616 100644 --- a/core/src/tests/mod.rs +++ b/core/src/tests/mod.rs @@ -87,6 +87,16 @@ async fn transact() -> Result<()> { let arbiter_token = deploy().await?; let mint = arbiter_token.mint(Address::from_str(TEST_MINT_TO).unwrap(), ethers::types::U256::from(TEST_MINT_AMOUNT)); let receipt = mint.send().await?.await?.unwrap(); + assert_eq!(receipt.logs[0].address, arbiter_token.address()); + let topics = vec![ + ethers::core::types::H256::from_str("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef").unwrap(), + ethers::core::types::H256::from_str("0x0000000000000000000000000000000000000000000000000000000000000000").unwrap(), + ethers::core::types::H256::from_str("0x000000000000000000000000f7e93cc543d97af6632c9b8864417379dba4bf15").unwrap(), + ]; + assert_eq!(receipt.logs[0].topics, topics); + let bytes = hex::decode("0000000000000000000000000000000000000000000000000000000000000001")?; + assert_eq!(receipt.logs[0].data, ethers::core::types::Bytes::from(bytes)); + println!("logs are: {:#?}", receipt.logs); Ok(()) } diff --git a/core/src/utils.rs b/core/src/utils.rs index 8dbeb018..220cadde 100644 --- a/core/src/utils.rs +++ b/core/src/utils.rs @@ -6,8 +6,8 @@ use std::{ }; use bytes::Bytes; -use ethers::prelude::Address; -use revm::primitives::{ExecutionResult, Output, B160}; +use ethers::{prelude::Address, types::H256}; +use revm::primitives::{ExecutionResult, Output, B160, B256}; #[derive(Debug)] // We should use anyhow / thisError instead @@ -42,6 +42,10 @@ pub fn recast_address(address: B160) -> Address { Address::from(temp) } +pub fn recast_b256(input: B256) -> H256 { + let temp: [u8; 32] = input.as_bytes().try_into().unwrap(); + H256::from(temp) +} // TODO: Can maybe get rid of this with middleware /// Takes an `ExecutionResult` and returns the raw bytes of the output that can then be decoded. /// # Arguments