From b9ddb174d1ef94ba1052fe509e7d729c9e755b61 Mon Sep 17 00:00:00 2001 From: Nwokedi Uche Date: Mon, 31 Aug 2026 13:06:30 +0100 Subject: [PATCH] test(SorokitProvider): cover switchNetwork clearing stale account state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a regression test asserting that switchNetwork clears address, account, and balances left over from the previous network — the provider already does this (see the reset in switchNetwork), but nothing in the suite exercised it, so a regression here (e.g. showing mainnet balances while the UI reports testnet) would go unnoticed. Related to #523, #522, and #519, which were already fixed on main by earlier work (#611, #640) but left open because those PRs used disclosure comments instead of closing keywords. --- src/context/SorokitProvider.test.tsx | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/context/SorokitProvider.test.tsx b/src/context/SorokitProvider.test.tsx index d9a2316..629888c 100644 --- a/src/context/SorokitProvider.test.tsx +++ b/src/context/SorokitProvider.test.tsx @@ -131,6 +131,31 @@ describe("SorokitProvider", () => { expect(mockClient.network.switchNetwork).toHaveBeenCalledWith("testnet"); }); + it("switchNetwork clears stale address, account, and balances from the previous network (#523)", async () => { + renderWithProvider(, { client: mockClient }); + + await act(async () => { + fireEvent.click(screen.getByText("Connect")); + }); + + expect(screen.getByTestId("address")).toHaveTextContent("GABC"); + await waitFor(() => { + expect(screen.getByTestId("account")).toHaveTextContent("100"); + expect(screen.getByTestId("balances")).toHaveTextContent("1"); + }); + + // Switching networks without this reset would leave the previous + // network's address/account/balances on screen — e.g. showing mainnet + // balances while the UI reports the user is now on testnet. + await act(async () => { + fireEvent.click(screen.getByText("Switch")); + }); + + expect(screen.getByTestId("address")).toHaveTextContent("none"); + expect(screen.getByTestId("account")).toHaveTextContent("none"); + expect(screen.getByTestId("balances")).toHaveTextContent("0"); + }); + it("memoizes the context value across parent re-renders", async () => { const Wrapper = ({ client }: { client: ReturnType }) => { const [, setTick] = useState(0);