Skip to content

Commit

Permalink
fix: get the work_dir from the configuration instead of hardcoding …
Browse files Browse the repository at this point in the history
…it. (#370)
  • Loading branch information
0xxfu authored Nov 21, 2023
1 parent bddfd25 commit f911413
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/evm/contract_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ impl ContractLoader {
}
}

pub fn from_setup(offchain_artifacts: &Vec<OffChainArtifact>, setup_file: String) -> Self {
pub fn from_setup(offchain_artifacts: &Vec<OffChainArtifact>, setup_file: String, work_dir: String) -> Self {
let mut contracts: Vec<ContractInfo> = vec![];
let mut abis: Vec<ABIInfo> = vec![];

Expand All @@ -698,7 +698,7 @@ impl ContractLoader {
all_slugs.push(slug.clone());
if slug == setup_file {
found = true;
setup_data = Some(Self::call_setup(contract_artifact.deploy_bytecode.clone()));
setup_data = Some(Self::call_setup(contract_artifact.deploy_bytecode.clone(), work_dir));

break 'artifacts;
}
Expand Down Expand Up @@ -747,13 +747,14 @@ impl ContractLoader {

fn get_vm_with_cheatcode(
deployer: EVMAddress,
work_dir: String,
) -> (
EVMExecutor<EVMState, ConciseEVMInput, StdScheduler<EVMFuzzState>>,
EVMFuzzState,
) {
let mut state: EVMFuzzState = FuzzState::new(0);
let mut executor = EVMExecutor::new(
FuzzHost::new(StdScheduler::new(), "work_dir".to_string()),
FuzzHost::new(StdScheduler::new(), work_dir),
deployer, // todo: change to foundry default address
);
executor.host.set_code(
Expand All @@ -768,11 +769,11 @@ impl ContractLoader {
/// Deploy the contract and invoke "setUp()", returns the code, state, and
/// environment after deployment. Foundry VM Cheatcodes and Hardhat
/// consoles are enabled here.
fn call_setup(deploy_code: Bytes) -> SetupData {
fn call_setup(deploy_code: Bytes, work_dir: String) -> SetupData {
let deployer = EVMAddress::from_str(FOUNDRY_DEPLOYER).unwrap();
let deployed_addr = EVMAddress::from_str(FOUNDRY_SETUP_ADDR).unwrap();

let (mut evm_executor, mut state) = Self::get_vm_with_cheatcode(deployer);
let (mut evm_executor, mut state) = Self::get_vm_with_cheatcode(deployer, work_dir);

// deploy contract

Expand Down
1 change: 1 addition & 0 deletions src/evm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ pub fn evm_main(args: EvmArgs) {
EVMTargetType::Setup => ContractLoader::from_setup(
&offchain_artifacts.expect("offchain artifacts is required for config target type"),
args.setup_file,
args.work_dir.clone(),
),
EVMTargetType::Address => {
if onchain.is_none() {
Expand Down

0 comments on commit f911413

Please sign in to comment.