Skip to content

Commit

Permalink
foundry test: abi.encodeWithSignature
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-chia committed Oct 23, 2023
1 parent 6b4a908 commit aaa5076
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion foundry_test.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import "forge-std/Test.sol";
{{{solution}}}
*/

contract EGD is Test {
contract {{contract_name}} is Test {
function setUp() public {
{{#if is_onchain}}
vm.createSelectFork("{{chain}}", {{block_number}});
Expand Down
21 changes: 13 additions & 8 deletions src/evm/solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,7 @@ pub fn generate_test<T: SolutionTx>(solution: String, inputs: Vec<T>) {
return;
}

let filename = if args.is_onchain {
&args.target[2..6]
} else {
let path = Path::new(&args.target);
path.parent().unwrap().file_name().unwrap().to_str().unwrap()
};

let path = format!("{}/{}.t.sol", args.output_dir, filename);
let path = format!("{}/{}.t.sol", args.output_dir, args.contract_name);
let mut output = File::create(&path).unwrap();
if let Err(e) = handlebars.render_to_write("foundry_test", &args, &mut output) {
println!("generate_test error: failed to render template: {:?}", e);
Expand Down Expand Up @@ -111,6 +104,7 @@ impl<T: SolutionTx> From<&T> for Tx {

#[derive(Debug, Serialize, Default)]
pub struct TemplateArgs {
contract_name: String,
is_onchain: bool,
need_swap: bool,
router: String,
Expand Down Expand Up @@ -159,7 +153,18 @@ impl TemplateArgs {
String::from("")
};

// Contract name
let contract_name = if cli_args.is_onchain {
format!("C{}", &cli_args.target[2..6])
} else {
let path = Path::new(&cli_args.target);
let dirname = path.parent().unwrap().file_name().unwrap().to_str().unwrap();
let name: String = dirname.chars().filter(|c| c.is_alphanumeric() || *c == '_').collect();
format!("{}{}", &name[..1].to_uppercase(), &name[1..])
};

Ok(Self {
contract_name,
is_onchain: cli_args.is_onchain,
need_swap: trace.iter().any(|x| x.is_borrow || x.liq_percent > 0),
router,
Expand Down

0 comments on commit aaa5076

Please sign in to comment.