App_test.ts
1 import "./happyDomSetup.ts"; 2 import { cleanup, render, screen } from "@testing-library/react"; 3 import { createConfig, http } from "wagmi"; 4 import { mainnet, sepolia } from "wagmi/chains"; 5 import { generatePrivateKey, privateKeyToAccount } from "viem/accounts"; 6 import { discoverRelay, RelayClient } from "@massmarket/client"; 7 import { random256BigInt } from "@massmarket/utils"; 8 import { relayURL, testClient } from "./testutils/mod.tsx"; 9 10 Deno.test("check that we can render the app", { 11 sanitizeResources: false, 12 sanitizeOps: false, 13 }, async () => { 14 // we need to import App.tsx here since wagmi and rainbowkit setup timers 15 const { default: App } = await import("./App.tsx"); 16 17 const config = createConfig({ 18 chains: [mainnet, sepolia], 19 transports: { 20 [mainnet.id]: http("https://mainnet.example.com"), 21 [sepolia.id]: http("https://sepolia.example.com"), 22 }, 23 }); 24 25 const { unmount } = render(App({ wagmiConfig: config })); 26 27 // Just check that the element is rendered. This will throw if element is not found 28 screen.getByTestId("homepage"); 29 30 unmount(); 31 cleanup(); 32 33 // Wait for any rainbowkit/wagmi timers/tasks to complete 34 await new Promise((resolve) => setTimeout(resolve, 100)); 35 }); 36 37 Deno.test("check that we can connect to the relay client", { 38 sanitizeResources: false, 39 sanitizeOps: false, 40 }, async (t) => { 41 // Create a mock wallet client and account 42 const privateKey = generatePrivateKey(); 43 const account = privateKeyToAccount(privateKey as `0x${string}`); 44 45 await t.step("can create and connect to relay client", async () => { 46 // Create relay client 47 const shopId = random256BigInt(); 48 const relayEndpoint = await discoverRelay(relayURL); 49 50 const client = new RelayClient({ 51 relayEndpoint, 52 walletClient: testClient, 53 keycard: account, 54 shopId, 55 }); 56 57 // Test connection 58 const connectPromise = client.connect(); 59 60 // Verify connection was attempted 61 await connectPromise; 62 63 // Test disconnection 64 await client.disconnect(); 65 }); 66 });