mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-07-25 11:45:40 +00:00
Added logic for ABI
This commit is contained in:
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
use alloy::json_abi::JsonAbi;
|
use alloy::json_abi::JsonAbi;
|
||||||
use alloy::primitives::Bytes;
|
use alloy::primitives::Bytes;
|
||||||
use alloy::rpc::types::TransactionInput;
|
use alloy::rpc::types::trace::geth::GethTrace;
|
||||||
|
use alloy::rpc::types::{TransactionInput, TransactionReceipt};
|
||||||
use alloy::{
|
use alloy::{
|
||||||
primitives::{Address, TxKind, map::HashMap},
|
primitives::{Address, TxKind, map::HashMap},
|
||||||
rpc::types::{
|
rpc::types::{
|
||||||
@@ -17,6 +18,7 @@ use revive_dt_node_interaction::EthereumNode;
|
|||||||
use revive_dt_report::reporter::{CompilationTask, Report, Span};
|
use revive_dt_report::reporter::{CompilationTask, Report, Span};
|
||||||
use revive_solc_json_interface::SolcStandardJsonOutput;
|
use revive_solc_json_interface::SolcStandardJsonOutput;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
use std::collections::HashMap as StdHashMap;
|
||||||
|
|
||||||
use crate::Platform;
|
use crate::Platform;
|
||||||
|
|
||||||
@@ -29,8 +31,8 @@ pub struct State<'a, T: Platform> {
|
|||||||
config: &'a Arguments,
|
config: &'a Arguments,
|
||||||
span: Span,
|
span: Span,
|
||||||
contracts: Contracts<T>,
|
contracts: Contracts<T>,
|
||||||
deployed_contracts: HashMap<String, Address>,
|
deployed_contracts: StdHashMap<String, Address>,
|
||||||
deployed_abis: HashMap<String, JsonAbi>,
|
deployed_abis: StdHashMap<String, JsonAbi>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T> State<'a, T>
|
impl<'a, T> State<'a, T>
|
||||||
|
|||||||
+62
-27
@@ -6,6 +6,8 @@ use alloy::{
|
|||||||
primitives::{Address, Bytes, TxKind},
|
primitives::{Address, Bytes, TxKind},
|
||||||
rpc::types::{TransactionInput, TransactionRequest},
|
rpc::types::{TransactionInput, TransactionRequest},
|
||||||
};
|
};
|
||||||
|
use alloy_primitives::U256;
|
||||||
|
use alloy_sol_types::SolValue;
|
||||||
use semver::VersionReq;
|
use semver::VersionReq;
|
||||||
use serde::{Deserialize, de::Deserializer};
|
use serde::{Deserialize, de::Deserializer};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
@@ -142,35 +144,68 @@ impl Input {
|
|||||||
_ => anyhow::bail!("Expected compound calldata for function call"),
|
_ => anyhow::bail!("Expected compound calldata for function call"),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Convert each argument
|
if calldata_args.len() != function.inputs.len() {
|
||||||
let mut tokens = Vec::new();
|
anyhow::bail!(
|
||||||
for (i, param) in function.inputs.iter().enumerate() {
|
"Function expects {} args, but got {}",
|
||||||
let arg = calldata_args
|
function.inputs.len(),
|
||||||
.get(i)
|
calldata_args.len()
|
||||||
.ok_or_else(|| anyhow::anyhow!("Missing calldata argument {}", i))?;
|
);
|
||||||
let token = match arg {
|
}
|
||||||
CalldataArg::Literal(value) => match param.ty.to_string().as_str() {
|
|
||||||
"uint256" | "uint" => Token::Uint(value.parse()?),
|
let mut encoded = selector.to_vec();
|
||||||
"address" => Token::Address(value.parse()?),
|
|
||||||
_ => anyhow::bail!("Unsupported literal type {}", param.ty),
|
for (i, param) in function.inputs.iter().enumerate() {
|
||||||
},
|
let arg = calldata_args.get(i).unwrap();
|
||||||
CalldataArg::AddressRef(name) => {
|
let encoded_arg = match arg {
|
||||||
let addr = if name.ends_with(".address") {
|
CalldataArg::Literal(value) => match param.ty.as_str() {
|
||||||
let contract_name = name.trim_end_matches(".address");
|
"uint256" | "uint" => {
|
||||||
deployed_contracts.get(contract_name).copied()
|
let val: U256 = value.parse()?;
|
||||||
} else {
|
val.abi_encode()
|
||||||
None
|
}
|
||||||
};
|
"uint24" => {
|
||||||
Token::Address(
|
let val: u32 = value.parse()?;
|
||||||
addr.ok_or_else(|| anyhow::anyhow!("Address for '{}' not found", name))?,
|
(val & 0xFFFFFF).abi_encode()
|
||||||
)
|
}
|
||||||
}
|
"bool" => {
|
||||||
};
|
let val: bool = value.parse()?;
|
||||||
tokens.push(token);
|
val.abi_encode()
|
||||||
|
}
|
||||||
|
"address" => {
|
||||||
|
let addr: Address = value.parse()?;
|
||||||
|
addr.abi_encode()
|
||||||
|
}
|
||||||
|
"string" => value.abi_encode(),
|
||||||
|
"bytes32" => {
|
||||||
|
let val = hex::decode(value.trim_start_matches("0x"))?;
|
||||||
|
let mut fixed = [0u8; 32];
|
||||||
|
fixed[..val.len()].copy_from_slice(&val);
|
||||||
|
fixed.abi_encode()
|
||||||
|
}
|
||||||
|
"uint256[]" | "uint[]" => {
|
||||||
|
let nums: Vec<u64> = serde_json::from_str(value)?;
|
||||||
|
nums.abi_encode()
|
||||||
|
}
|
||||||
|
"bytes" => {
|
||||||
|
let val = hex::decode(value.trim_start_matches("0x"))?;
|
||||||
|
val.abi_encode()
|
||||||
|
}
|
||||||
|
_ => anyhow::bail!("Unsupported type: {}", param.ty),
|
||||||
|
},
|
||||||
|
CalldataArg::AddressRef(name) => {
|
||||||
|
let contract_name = name.trim_end_matches(".address");
|
||||||
|
let addr = deployed_contracts
|
||||||
|
.get(contract_name)
|
||||||
|
.copied()
|
||||||
|
.ok_or_else(|| {
|
||||||
|
anyhow::anyhow!("Address for '{}' not found", contract_name)
|
||||||
|
})?;
|
||||||
|
addr.abi_encode()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
encoded.extend(encoded_arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode
|
|
||||||
let encoded = function.encode_input(&tokens)?;
|
|
||||||
Ok(Bytes::from(encoded))
|
Ok(Bytes::from(encoded))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
//! The go-ethereum node implementation.
|
//! The go-ethereum node implementation.
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
|
collections::HashMap as StdHashMap,
|
||||||
fs::{File, create_dir_all, remove_dir_all},
|
fs::{File, create_dir_all, remove_dir_all},
|
||||||
io::{BufRead, BufReader, Read, Write},
|
io::{BufRead, BufReader, Read, Write},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
@@ -50,7 +51,7 @@ pub struct Instance {
|
|||||||
network_id: u64,
|
network_id: u64,
|
||||||
start_timeout: u64,
|
start_timeout: u64,
|
||||||
wallet: EthereumWallet,
|
wallet: EthereumWallet,
|
||||||
nonces: Mutex<HashMap<Address, u64>>,
|
nonces: Mutex<StdHashMap<Address, u64>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Instance {
|
impl Instance {
|
||||||
@@ -158,6 +159,8 @@ impl EthereumNode for Instance {
|
|||||||
let connection_string = self.connection_string();
|
let connection_string = self.connection_string();
|
||||||
let wallet = self.wallet.clone();
|
let wallet = self.wallet.clone();
|
||||||
|
|
||||||
|
log::debug!("Submitting transaction: {:#?}", transaction);
|
||||||
|
|
||||||
execute_transaction(Box::pin(async move {
|
execute_transaction(Box::pin(async move {
|
||||||
Ok(ProviderBuilder::new()
|
Ok(ProviderBuilder::new()
|
||||||
.wallet(wallet)
|
.wallet(wallet)
|
||||||
@@ -235,7 +238,7 @@ impl Node for Instance {
|
|||||||
network_id: config.network_id,
|
network_id: config.network_id,
|
||||||
start_timeout: config.geth_start_timeout,
|
start_timeout: config.geth_start_timeout,
|
||||||
wallet: config.wallet(),
|
wallet: config.wallet(),
|
||||||
nonces: Mutex::new(HashMap::new()),
|
nonces: Mutex::new(StdHashMap::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use std::{
|
use std::{
|
||||||
|
collections::HashMap as StdHashMap,
|
||||||
fs::create_dir_all,
|
fs::create_dir_all,
|
||||||
io::BufRead,
|
io::BufRead,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
@@ -44,7 +45,7 @@ pub struct KitchensinkNode {
|
|||||||
base_directory: PathBuf,
|
base_directory: PathBuf,
|
||||||
process_substrate: Option<Child>,
|
process_substrate: Option<Child>,
|
||||||
process_proxy: Option<Child>,
|
process_proxy: Option<Child>,
|
||||||
nonces: Mutex<HashMap<Address, u64>>,
|
nonces: Mutex<StdHashMap<Address, u64>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KitchensinkNode {
|
impl KitchensinkNode {
|
||||||
@@ -251,6 +252,8 @@ impl EthereumNode for KitchensinkNode {
|
|||||||
let url = self.rpc_url.clone();
|
let url = self.rpc_url.clone();
|
||||||
let wallet = self.wallet.clone();
|
let wallet = self.wallet.clone();
|
||||||
|
|
||||||
|
log::debug!("Submitting transaction: {:#?}", transaction);
|
||||||
|
|
||||||
execute_transaction(Box::pin(async move {
|
execute_transaction(Box::pin(async move {
|
||||||
Ok(ProviderBuilder::new()
|
Ok(ProviderBuilder::new()
|
||||||
.wallet(wallet)
|
.wallet(wallet)
|
||||||
@@ -325,7 +328,7 @@ impl Node for KitchensinkNode {
|
|||||||
base_directory,
|
base_directory,
|
||||||
process_substrate: None,
|
process_substrate: None,
|
||||||
process_proxy: None,
|
process_proxy: None,
|
||||||
nonces: Mutex::new(HashMap::new()),
|
nonces: Mutex::new(StdHashMap::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user