Merge pull request #60 from paritytech/feature/handle-values

Handle values
This commit is contained in:
Omar
2025-07-22 13:57:05 +03:00
committed by GitHub
5 changed files with 53 additions and 8 deletions
+6
View File
@@ -251,6 +251,12 @@ where
let tx = {
let tx = TransactionRequest::default().from(input.caller);
let tx = match input.value {
Some(ref value) if deploy_with_constructor_arguments => {
tx.value(value.into_inner())
}
_ => tx,
};
TransactionBuilder::<Ethereum>::with_deploy_code(tx, code)
};
+43 -5
View File
@@ -7,13 +7,16 @@ use alloy::{
primitives::{Address, Bytes, U256},
rpc::types::TransactionRequest,
};
use alloy_primitives::FixedBytes;
use alloy_primitives::{FixedBytes, utils::parse_units};
use semver::VersionReq;
use serde::Deserialize;
use serde::{Deserialize, Serialize};
use revive_dt_node_interaction::EthereumNode;
use crate::metadata::{AddressReplacementMap, ContractInstance};
use crate::{
define_wrapper_type,
metadata::{AddressReplacementMap, ContractInstance},
};
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)]
pub struct Input {
@@ -26,7 +29,7 @@ pub struct Input {
#[serde(default)]
pub calldata: Calldata,
pub expected: Option<Expected>,
pub value: Option<String>,
pub value: Option<EtherValue>,
pub storage: Option<HashMap<String, Calldata>>,
}
@@ -82,6 +85,37 @@ pub enum Method {
FunctionName(String),
}
define_wrapper_type!(
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
EtherValue(U256);
);
impl Serialize for EtherValue {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
format!("{} wei", self.0).serialize(serializer)
}
}
impl<'de> Deserialize<'de> for EtherValue {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let string = String::deserialize(deserializer)?;
let mut splitted = string.split(' ');
let (Some(value), Some(unit)) = (splitted.next(), splitted.next()) else {
return Err(serde::de::Error::custom("Failed to parse the value"));
};
let parsed = parse_units(value, unit.replace("eth", "ether"))
.map_err(|_| serde::de::Error::custom("Failed to parse units"))?
.into();
Ok(Self(parsed))
}
}
impl ExpectedOutput {
pub fn new() -> Self {
Default::default()
@@ -324,7 +358,11 @@ impl Input {
chain_state_provider: &impl EthereumNode,
) -> anyhow::Result<TransactionRequest> {
let input_data = self.encoded_input(deployed_contracts, chain_state_provider)?;
let transaction_request = TransactionRequest::default().from(self.caller);
let transaction_request = TransactionRequest::default().from(self.caller).value(
self.value
.map(|value| value.into_inner())
.unwrap_or_default(),
);
match self.method {
Method::Deployer => Ok(transaction_request.with_deploy_code(input_data)),
_ => Ok(transaction_request
+2 -1
View File
@@ -85,7 +85,8 @@ impl Instance {
<EthereumWallet as NetworkWallet<Ethereum>>::signer_addresses(&self.wallet)
{
genesis.alloc.entry(signer_address).or_insert(
GenesisAccount::default().with_balance(1000000000000000000u128.try_into().unwrap()),
GenesisAccount::default()
.with_balance(10000000000000000000000u128.try_into().unwrap()),
);
}
let genesis_path = self.base_directory.join(Self::GENESIS_JSON_FILE);
+1 -1
View File
@@ -131,7 +131,7 @@ impl KitchensinkNode {
{
genesis.alloc.entry(signer_address).or_insert(
GenesisAccount::default()
.with_balance(1000000000000000000u128.try_into().unwrap()),
.with_balance(10000000000000000000000u128.try_into().unwrap()),
);
}
self.extract_balance_from_genesis_file(&genesis)?
+1 -1
View File
@@ -35,7 +35,7 @@
"timestamp": "0x00",
"alloc": {
"90F8bf6A479f320ead074411a4B0e7944Ea8c9C1": {
"balance": "1000000000000000000"
"balance": "10000000000000000000000"
}
}
}