File size: 900 Bytes
ff2afe2
 
 
 
 
 
 
 
2a70ee5
ff2afe2
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import fs from "node:fs/promises";
import path from "node:path";
import { execSync } from "node:child_process";

export async function createEmptyFoundryProject(targetDir: string, sourceCode: string, contractName: string) {
  await fs.mkdir(targetDir, { recursive: true });
  execSync("forge init --no-git --force", { 
    cwd: targetDir,
    env: { ...process.env } // Deixa o PATH nativo agir (configurado pelo bash ou Dockerfile)
  });
  
  // Clean up default files
  await fs.rm(path.join(targetDir, "src", "Counter.sol"), { force: true });
  await fs.rm(path.join(targetDir, "test", "Counter.t.sol"), { force: true });
  await fs.rm(path.join(targetDir, "script", "Counter.s.sol"), { force: true });

  // Write the vulnerable contract source
  const sourcePath = path.join(targetDir, "src", `${contractName}.sol`);
  await fs.writeFile(sourcePath, sourceCode, "utf8");

  return sourcePath;
}