-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_test.go
More file actions
79 lines (65 loc) · 2.11 KB
/
setup_test.go
File metadata and controls
79 lines (65 loc) · 2.11 KB
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
74
75
76
77
78
79
package blockrun
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
)
func TestSetupAgentWalletFromEnv(t *testing.T) {
t.Setenv("BASE_CHAIN_WALLET_KEY", testPrivateKey)
t.Setenv("BLOCKRUN_WALLET_KEY", "")
client, err := SetupAgentWallet()
if err != nil {
t.Fatalf("Failed to setup agent wallet: %v", err)
}
if client.GetWalletAddress() != testWalletAddress {
t.Errorf("Expected wallet address %s, got %s", testWalletAddress, client.GetWalletAddress())
}
}
func TestSetupAgentWalletWithOptions(t *testing.T) {
t.Setenv("BLOCKRUN_WALLET_KEY", testPrivateKey)
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(map[string]any{"ok": true})
}))
defer server.Close()
client, err := SetupAgentWallet(WithAPIURL(server.URL))
if err != nil {
t.Fatalf("Failed to setup agent wallet with options: %v", err)
}
if client.GetWalletAddress() != testWalletAddress {
t.Errorf("Expected wallet address %s, got %s", testWalletAddress, client.GetWalletAddress())
}
}
func TestStatus(t *testing.T) {
// Create a mock RPC server that returns a balance
rpcServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Return a hex-encoded balance (1.5 USDC = 1500000 = 0x16e360)
resp := map[string]any{
"jsonrpc": "2.0",
"id": 1,
"result": "0x000000000000000000000000000000000000000000000000000000000016e360",
}
json.NewEncoder(w).Encode(resp)
}))
defer rpcServer.Close()
// Override RPC endpoints for testing
origRPCs := baseMainnetRPCs
baseMainnetRPCs = []string{rpcServer.URL}
defer func() { baseMainnetRPCs = origRPCs }()
client, err := NewLLMClient(testPrivateKey)
if err != nil {
t.Fatalf("Failed to create client: %v", err)
}
address, balance, err := client.Status(context.Background())
if err != nil {
t.Fatalf("Failed to get status: %v", err)
}
if address != testWalletAddress {
t.Errorf("Expected address %s, got %s", testWalletAddress, address)
}
if balance != 1.5 {
t.Errorf("Expected balance 1.5, got %f", balance)
}
}