-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: set up mock game for test data, use in zustand tests (#2361)
- Loading branch information
Showing
26 changed files
with
1,893 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
190 changes: 146 additions & 44 deletions
190
packages/store-sync/src/zustand/createStorageAdapter.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { createPublicClient, createTestClient, http } from "viem"; | ||
|
||
export const anvilHost = "127.0.0.1"; | ||
export const anvilPort = 8555; | ||
|
||
// ID of the current test worker. Used by the `@viem/anvil` proxy server. | ||
export const poolId = Number(process.env.VITEST_POOL_ID ?? 1); | ||
|
||
export const anvilRpcUrl = `http://${anvilHost}:${anvilPort}/${poolId}`; | ||
|
||
export const testClient = createTestClient({ | ||
mode: "anvil", | ||
transport: http(anvilRpcUrl), | ||
}); | ||
|
||
export const publicClient = createPublicClient({ | ||
transport: http(anvilRpcUrl), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { execa } from "execa"; | ||
import { anvilRpcUrl, testClient } from "./common"; | ||
import mudConfig from "mock-game-contracts/mud.config"; | ||
import { resolveConfig } from "@latticexyz/store"; | ||
|
||
export const config = resolveConfig(mudConfig); | ||
|
||
export async function deployMockGame(): Promise<void> { | ||
const automine = await testClient.getAutomine(); | ||
|
||
if (!automine) { | ||
console.log("turning on automine for deploy"); | ||
await testClient.setAutomine(true); | ||
} | ||
|
||
// TODO: build in globalSetup so we don't have to build here? | ||
console.log("deploying mud"); | ||
const { stdout, stderr } = await execa("pnpm", ["mud", "deploy", "--rpc", anvilRpcUrl, "--saveDeployment", "false"], { | ||
cwd: `${__dirname}/../../../test/mock-game-contracts`, | ||
env: { | ||
// anvil default account | ||
PRIVATE_KEY: "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", | ||
DEBUG: "mud:*", | ||
}, | ||
}); | ||
if (stderr) console.error(stderr); | ||
if (stdout) console.log(stdout); | ||
|
||
if (!automine) { | ||
console.log("turning off automine"); | ||
await testClient.setAutomine(false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { startProxy as startAnvilProxy } from "@viem/anvil"; | ||
import { anvilHost, anvilPort } from "./common"; | ||
|
||
export default async function globalSetup(): Promise<() => Promise<void>> { | ||
const shutdownAnvilProxy = await startAnvilProxy({ | ||
host: anvilHost, | ||
port: anvilPort, | ||
options: { | ||
noMining: true, | ||
}, | ||
}); | ||
|
||
return async () => { | ||
await shutdownAnvilProxy(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { defineConfig } from "vitest/config"; | ||
|
||
export default defineConfig({ | ||
test: { | ||
globalSetup: ["test/globalSetup.ts"], | ||
}, | ||
}); |
Oops, something went wrong.