mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-06-14 08:41:06 +00:00
fixes
This commit is contained in:
@@ -1,2 +0,0 @@
|
|||||||
// Re-export the cached compiler from core to avoid code duplication
|
|
||||||
pub use revive_dt_core::CachedCompiler;
|
|
||||||
@@ -312,9 +312,9 @@ async fn execute_test_file(
|
|||||||
info!("Using existing node");
|
info!("Using existing node");
|
||||||
let existing_node: Box<dyn revive_dt_node_interaction::EthereumNode> = match args.platform {
|
let existing_node: Box<dyn revive_dt_node_interaction::EthereumNode> = match args.platform {
|
||||||
TestingPlatform::Geth =>
|
TestingPlatform::Geth =>
|
||||||
Box::new(revive_dt_node::node_implementations::geth::GethNode::new_existing(&args.private_key)?),
|
Box::new(revive_dt_node::node_implementations::geth::GethNode::new_existing(&args.private_key).await?),
|
||||||
TestingPlatform::Kitchensink | TestingPlatform::Zombienet => Box::new(
|
TestingPlatform::Kitchensink | TestingPlatform::Zombienet => Box::new(
|
||||||
revive_dt_node::node_implementations::substrate::SubstrateNode::new_existing(&args.private_key)?,
|
revive_dt_node::node_implementations::substrate::SubstrateNode::new_existing(&args.private_key).await?,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
Box::leak(existing_node)
|
Box::leak(existing_node)
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ impl GethNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_existing(private_key: &str) -> anyhow::Result<Self> {
|
pub async fn new_existing(private_key: &str) -> anyhow::Result<Self> {
|
||||||
use alloy::{primitives::FixedBytes, signers::local::PrivateKeySigner};
|
use alloy::{primitives::FixedBytes, signers::local::PrivateKeySigner};
|
||||||
|
|
||||||
let key_str = private_key.trim().strip_prefix("0x").unwrap_or(private_key.trim());
|
let key_str = private_key.trim().strip_prefix("0x").unwrap_or(private_key.trim());
|
||||||
@@ -147,9 +147,10 @@ impl GethNode {
|
|||||||
let signer = PrivateKeySigner::from_bytes(&FixedBytes(bytes))
|
let signer = PrivateKeySigner::from_bytes(&FixedBytes(bytes))
|
||||||
.map_err(|e| anyhow::anyhow!("Failed to create signer from private key: {}", e))?;
|
.map_err(|e| anyhow::anyhow!("Failed to create signer from private key: {}", e))?;
|
||||||
|
|
||||||
|
let address = signer.address();
|
||||||
let wallet = Arc::new(EthereumWallet::new(signer));
|
let wallet = Arc::new(EthereumWallet::new(signer));
|
||||||
|
|
||||||
Ok(Self {
|
let node = Self {
|
||||||
connection_string: "http://localhost:8545".to_string(),
|
connection_string: "http://localhost:8545".to_string(),
|
||||||
base_directory: PathBuf::new(),
|
base_directory: PathBuf::new(),
|
||||||
data_directory: PathBuf::new(),
|
data_directory: PathBuf::new(),
|
||||||
@@ -162,7 +163,66 @@ impl GethNode {
|
|||||||
wallet,
|
wallet,
|
||||||
nonce_manager: Default::default(),
|
nonce_manager: Default::default(),
|
||||||
provider: Default::default(),
|
provider: Default::default(),
|
||||||
})
|
};
|
||||||
|
|
||||||
|
// Check balance and fund if needed
|
||||||
|
node.ensure_funded(address).await?;
|
||||||
|
|
||||||
|
Ok(node)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn ensure_funded(&self, address: Address) -> anyhow::Result<()> {
|
||||||
|
use alloy::{
|
||||||
|
primitives::utils::{format_ether, parse_ether},
|
||||||
|
providers::{Provider, ProviderBuilder},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create a simple HTTP provider without wallet for balance check
|
||||||
|
let simple_provider =
|
||||||
|
ProviderBuilder::new().connect_http(self.connection_string.parse()?);
|
||||||
|
|
||||||
|
// Check current balance
|
||||||
|
let balance = simple_provider.get_balance(address).await?;
|
||||||
|
let min_balance = parse_ether("1000")?; // 1000 ETH
|
||||||
|
|
||||||
|
if balance >= min_balance {
|
||||||
|
tracing::info!(
|
||||||
|
"Wallet {} already has sufficient balance: {} ETH",
|
||||||
|
address,
|
||||||
|
format_ether(balance)
|
||||||
|
);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
tracing::info!(
|
||||||
|
"Funding wallet {} (current: {} ETH, target: 1000 ETH)",
|
||||||
|
address,
|
||||||
|
format_ether(balance)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Need to fund the account - get the node's managed account
|
||||||
|
let accounts = simple_provider.get_accounts().await?;
|
||||||
|
if accounts.is_empty() {
|
||||||
|
anyhow::bail!("No managed accounts available on the node to fund wallet");
|
||||||
|
}
|
||||||
|
|
||||||
|
let from_account = accounts[0];
|
||||||
|
|
||||||
|
// Send funding transaction from managed account (unsigned, node will sign)
|
||||||
|
let funding_amount = min_balance - balance;
|
||||||
|
let tx =
|
||||||
|
TransactionRequest::default().from(from_account).to(address).value(funding_amount);
|
||||||
|
|
||||||
|
simple_provider
|
||||||
|
.send_transaction(tx)
|
||||||
|
.await?
|
||||||
|
.get_receipt()
|
||||||
|
.await
|
||||||
|
.context("Failed to get receipt for funding transaction")?;
|
||||||
|
|
||||||
|
tracing::info!("Successfully funded wallet {}", address);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create the node directory and call `geth init` to configure the genesis.
|
/// Create the node directory and call `geth init` to configure the genesis.
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ impl SubstrateNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_existing(private_key: &str) -> anyhow::Result<Self> {
|
pub async fn new_existing(private_key: &str) -> anyhow::Result<Self> {
|
||||||
use alloy::{primitives::FixedBytes, signers::local::PrivateKeySigner};
|
use alloy::{primitives::FixedBytes, signers::local::PrivateKeySigner};
|
||||||
|
|
||||||
let key_str = private_key.trim().strip_prefix("0x").unwrap_or(private_key.trim());
|
let key_str = private_key.trim().strip_prefix("0x").unwrap_or(private_key.trim());
|
||||||
@@ -140,7 +140,10 @@ impl SubstrateNode {
|
|||||||
.map_err(|e| anyhow::anyhow!("Failed to decode private key hex: {}", e))?;
|
.map_err(|e| anyhow::anyhow!("Failed to decode private key hex: {}", e))?;
|
||||||
|
|
||||||
if key_bytes.len() != 32 {
|
if key_bytes.len() != 32 {
|
||||||
anyhow::bail!("Private key must be 32 bytes (64 hex characters), got {}", key_bytes.len());
|
anyhow::bail!(
|
||||||
|
"Private key must be 32 bytes (64 hex characters), got {}",
|
||||||
|
key_bytes.len()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut bytes = [0u8; 32];
|
let mut bytes = [0u8; 32];
|
||||||
|
|||||||
Reference in New Issue
Block a user