Skip to content

Commit

Permalink
transact test finished 😃
Browse files Browse the repository at this point in the history
  • Loading branch information
Autoparallel committed Jul 25, 2023
1 parent a9b7653 commit 5067c4d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
9 changes: 9 additions & 0 deletions core/src/bindings/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
31 changes: 25 additions & 6 deletions core/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -100,22 +100,41 @@ 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),
};
match output {
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<ethers::core::types::Log> = 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);
}
}
Expand Down
10 changes: 10 additions & 0 deletions core/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand Down
8 changes: 6 additions & 2 deletions core/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5067c4d

Please sign in to comment.