Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
rauljordan committed Feb 4, 2025
1 parent e3112f3 commit e4d8260
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
17 changes: 9 additions & 8 deletions stylus-test/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,14 @@ impl TestVMBuilder {
}
/// Returns and TestVM instance from the builder with the specified parameters.
pub fn build(self) -> TestVM {
let mut state = VMState::default();
state.msg_sender = self.sender.unwrap_or(Address::ZERO);
state.msg_value = self.value.unwrap_or_default();
state.storage = self.storage.unwrap_or_default();
state.block_number = self.block_num.unwrap_or_default();
state.contract_address = self.contract_address.unwrap_or(Address::ZERO);
state.provider = self.provider;
TestVM::from(state)
TestVM::from(VMState {
msg_sender: self.sender.unwrap_or(Address::ZERO),
msg_value: self.value.unwrap_or_default(),
storage: self.storage.unwrap_or_default(),
block_number: self.block_num.unwrap_or_default(),
contract_address: self.contract_address.unwrap_or(Address::ZERO),
provider: self.provider,
..Default::default()
})
}
}
21 changes: 15 additions & 6 deletions stylus-test/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@
use alloy_primitives::{Address, B256, U256};
use alloy_provider::{network::Ethereum, RootProvider};
use std::{collections::HashMap, sync::Arc, u64};
use std::{collections::HashMap, sync::Arc};

use crate::constants::{DEFAULT_CHAIN_ID, DEFAULT_CONTRACT_ADDRESS, DEFAULT_SENDER};

/// Type aliases for the return values of mocked calls and deployments.
type CallReturn = Result<Vec<u8>, Vec<u8>>;
type DeploymentReturn = Result<Address, Vec<u8>>;
type MockCallWithAddress = (Address, Vec<u8>);
type DeploymentWithSalt = (Vec<u8>, Option<B256>);

/// Type alias for the RPC provider used in the test VM.
type RPCProvider = Arc<RootProvider<Ethereum>>;

/// Defines the internal state of the Stylus test VM for unit testing.
/// Internally, it tracks information such as mocked calls and their return values,
/// balances of addresses, and the storage of the contract being tested.
Expand All @@ -32,12 +41,12 @@ pub struct VMState {
pub block_basefee: U256,
pub tx_gas_price: U256,
pub tx_ink_price: u32,
pub call_returns: HashMap<(Address, Vec<u8>), Result<Vec<u8>, Vec<u8>>>,
pub delegate_call_returns: HashMap<(Address, Vec<u8>), Result<Vec<u8>, Vec<u8>>>,
pub static_call_returns: HashMap<(Address, Vec<u8>), Result<Vec<u8>, Vec<u8>>>,
pub deploy_returns: HashMap<(Vec<u8>, Option<B256>), Result<Address, Vec<u8>>>,
pub call_returns: HashMap<MockCallWithAddress, CallReturn>,
pub delegate_call_returns: HashMap<MockCallWithAddress, CallReturn>,
pub static_call_returns: HashMap<MockCallWithAddress, CallReturn>,
pub deploy_returns: HashMap<DeploymentWithSalt, DeploymentReturn>,
pub emitted_logs: Vec<(Vec<B256>, Vec<u8>)>,
pub provider: Option<Arc<RootProvider<Ethereum>>>,
pub provider: Option<RPCProvider>,
}

impl Default for VMState {
Expand Down
2 changes: 1 addition & 1 deletion stylus-test/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ impl StorageAccess for TestVM {
fn storage_load_bytes32(&self, key: U256) -> B256 {
if let Some(provider) = self.state.borrow().provider.clone() {
let rt = Runtime::new().expect("Failed to create runtime");
let addr = self.state.borrow().contract_address.clone();
let addr = self.state.borrow().contract_address;
let storage = rt
.block_on(async { provider.get_storage_at(addr, key).await })
.unwrap_or_default();
Expand Down

0 comments on commit e4d8260

Please sign in to comment.