Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion src/components/hooks/__tests__/useTrust.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { renderHook, waitFor } from "@testing-library/react";
import { useTrust } from "../useTrust";
import { useTrust, useTrustForAddress } from "../useTrust";

jest.mock("@/hooks/useAccount", () => ({
useAccount: jest.fn(),
Expand Down Expand Up @@ -57,4 +57,36 @@ describe("useTrust", () => {
expect(typeof result.current.suspicious).toBe("boolean");
});
});

it("does not leak current-user overrides into address-specific trust lookups", async () => {
localStorage.setItem(
"trustInfo",
JSON.stringify({
reputation: 15,
isVerified: false,
}),
);

const { result, rerender } = renderHook(
({ address }: { address?: string }) => useTrustForAddress(address),
{ initialProps: { address: undefined } },
);

await waitFor(() => {
expect(result.current.reputation).toBe(15);
expect(result.current.isVerified).toBe(false);
});

rerender({ address: "0xdef" });

await waitFor(() => {
const expectedReputation = Array.from("0xdef").reduce(
(sum, character) => sum + character.charCodeAt(0),
0,
) % 101;

expect(result.current.reputation).toBe(expectedReputation);
expect(result.current.isVerified).toBe(true);
});
});
});
2 changes: 2 additions & 0 deletions src/components/hooks/useTrust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export function useTrustForAddress(address?: string): TrustInfo {
useEffect(() => {
if (!address) {
setOverrideInfo(parseTrustInfoFromStorage());
} else {
setOverrideInfo(null);
}
}, [address]);

Expand Down
Loading