Skip to content

Commit

Permalink
feat(cli): remove .mudtest file in favor of env var (#1722)
Browse files Browse the repository at this point in the history
  • Loading branch information
holic authored Oct 10, 2023
1 parent 0660561 commit 25086be
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
7 changes: 7 additions & 0 deletions .changeset/three-lizards-shave.md
Original file line number Diff line number Diff line change
@@ -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
16 changes: 5 additions & 11 deletions packages/cli/src/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Options, Options> = {
command: "test",

Expand Down Expand Up @@ -48,23 +46,19 @@ const commandModule: CommandModule<Options, Options> = {

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);
},
};

Expand Down
7 changes: 5 additions & 2 deletions packages/common/src/foundry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
export async function forge(
args: string[],
options?: { profile?: string; silent?: boolean; env?: NodeJS.ProcessEnv }
): Promise<void> {
const execOptions: Options<string> = {
env: { FOUNDRY_PROFILE: options?.profile },
env: { FOUNDRY_PROFILE: options?.profile, ...options?.env },
stdout: "inherit",
stderr: "pipe",
};
Expand Down
2 changes: 1 addition & 1 deletion packages/world/test/MudTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 25086be

Please sign in to comment.