-
Notifications
You must be signed in to change notification settings - Fork 5k
/
Copy pathwallet.test.ts
73 lines (63 loc) · 2.33 KB
/
wallet.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { describe, it, expect, beforeEach, vi, afterEach } from "vitest";
import { defaultCharacter } from "@elizaos/core";
import { getFlowConnectorInstance } from "../providers/connector.provider";
import { FlowWalletProvider } from "../providers/wallet.provider";
// Mock NodeCache
vi.mock("node-cache", () => ({
default: vi.fn().mockImplementation(() => ({
set: vi.fn(),
get: vi.fn().mockReturnValue(null),
})),
}));
// Mock path module
vi.mock("path", async () => {
const actual = await vi.importActual("path");
return {
...actual,
join: vi.fn().mockImplementation((...args) => args.join("/")),
};
});
// Mock the ICacheManager
const mockCacheManager = {
get: vi.fn().mockResolvedValue(null),
set: vi.fn(),
delete: vi.fn(),
};
describe("WalletProvider", () => {
let walletProvider: FlowWalletProvider;
let mockedRuntime;
beforeEach(async () => {
vi.clearAllMocks();
mockCacheManager.get.mockResolvedValue(null);
mockedRuntime = {
character: defaultCharacter,
getSetting: vi.fn().mockImplementation((key: string) => {
if (key === "FLOW_NETWORK") return "testnet";
if (key === "FLOW_ENDPOINT_URL") return undefined;
if (key === "FLOW_ADDRESS") return "0xad5a851aeb126bca";
// This is the private key for the testnet address above
if (key === "FLOW_PRIVATE_KEY")
return "0x09e3d2e8f479a63e011ec776b39f89ce0ba8ca115f450a7e2d1909e5f113f831";
return undefined;
}),
};
// Create new instance of TokenProvider with mocked dependencies
const connector = await getFlowConnectorInstance(mockedRuntime);
walletProvider = new FlowWalletProvider(
mockedRuntime,
connector,
mockCacheManager as any
);
});
afterEach(() => {
vi.clearAllTimers();
});
describe("Wallet Integration", () => {
it("should check wallet info", async () => {
const result = await walletProvider.queryAccountBalanceInfo();
const balance = await walletProvider.getWalletBalance();
expect(walletProvider.address).toEqual(result.address);
expect(balance).toEqual(result.balance);
});
});
});