diff --git a/.changeset/three-lizards-shave.md b/.changeset/three-lizards-shave.md new file mode 100644 index 0000000000..66466f5cc8 --- /dev/null +++ b/.changeset/three-lizards-shave.md @@ -0,0 +1,7 @@ +--- +"@latticexyz/cli": patch +"@latticexyz/common": patch +"@latticexyz/world": minor +--- + +Replaced temporary `.mudtest` file in favor of `WORLD_ADDRESS` environment variable when running tests with `MudTest` contract diff --git a/packages/cli/src/commands/test.ts b/packages/cli/src/commands/test.ts index ab0465cb29..0e255aa8b0 100644 --- a/packages/cli/src/commands/test.ts +++ b/packages/cli/src/commands/test.ts @@ -7,8 +7,6 @@ import { DeployOptions, deployHandler } from "../utils/deployHandler"; type Options = DeployOptions & { port?: number; worldAddress?: string; forgeOptions?: string }; -const WORLD_ADDRESS_FILE = ".mudtest"; - const commandModule: CommandModule = { command: "test", @@ -48,23 +46,19 @@ const commandModule: CommandModule = { console.log(chalk.blue("World address", worldAddress)); - // Create a temporary file to pass the world address to the tests - writeFileSync(WORLD_ADDRESS_FILE, worldAddress); - const userOptions = args.forgeOptions?.replaceAll("\\", "").split(" ") ?? []; try { - const testResult = await forge(["test", "--fork-url", forkRpc, ...userOptions], { + await forge(["test", "--fork-url", forkRpc, ...userOptions], { profile: args.profile, + env: { + WORLD_ADDRESS: worldAddress, + }, }); - console.log(testResult); + process.exit(0); } catch (e) { console.error(e); - rmSync(WORLD_ADDRESS_FILE); process.exit(1); } - - rmSync(WORLD_ADDRESS_FILE); - process.exit(0); }, }; diff --git a/packages/common/src/foundry/index.ts b/packages/common/src/foundry/index.ts index fa46956b9b..2faffc9acd 100644 --- a/packages/common/src/foundry/index.ts +++ b/packages/common/src/foundry/index.ts @@ -84,9 +84,12 @@ export async function getRemappings(profile?: string): Promise<[string, string][ * @param args The arguments to pass to forge * @param options { profile?: The foundry profile to use; silent?: If true, nothing will be logged to the console } */ -export async function forge(args: string[], options?: { profile?: string; silent?: boolean }): Promise { +export async function forge( + args: string[], + options?: { profile?: string; silent?: boolean; env?: NodeJS.ProcessEnv } +): Promise { const execOptions: Options = { - env: { FOUNDRY_PROFILE: options?.profile }, + env: { FOUNDRY_PROFILE: options?.profile, ...options?.env }, stdout: "inherit", stderr: "pipe", }; diff --git a/packages/world/test/MudTest.t.sol b/packages/world/test/MudTest.t.sol index 098a487ae5..5960e4ac68 100644 --- a/packages/world/test/MudTest.t.sol +++ b/packages/world/test/MudTest.t.sol @@ -8,7 +8,7 @@ abstract contract MudTest is Test { address public worldAddress; function setUp() public virtual { - worldAddress = vm.parseAddress(vm.readFile(".mudtest")); + worldAddress = vm.envAddress("WORLD_ADDRESS"); StoreSwitch.setStoreAddress(worldAddress); } }