-
Notifications
You must be signed in to change notification settings - Fork 431
Expand file tree
/
Copy pathgetMinContextSlot_test.go
More file actions
138 lines (121 loc) · 3.85 KB
/
getMinContextSlot_test.go
File metadata and controls
138 lines (121 loc) · 3.85 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package rpc
import (
"context"
"testing"
"github.com/gagliardetto/solana-go"
stdjson "github.com/goccy/go-json"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestClient_GetProgramAccountsWithOpts_MinContextSlot pins that the
// minContextSlot opt is forwarded into the params object.
func TestClient_GetProgramAccountsWithOpts_MinContextSlot(t *testing.T) {
responseBody := `[{"account":{"data":["dGVzdA==","base64"],"executable":true,"lamports":2039280,"owner":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","rentEpoch":206},"pubkey":"7xLk17EQQ5KLDLDe44wCmupJKJjTGd8hs3eSVVhCx932"}]`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
defer closer()
client := New(server.URL)
pubkeyString := "7xLk17EQQ5KLDLDe44wCmupJKJjTGd8hs3eSVVhCx932"
pubKey := solana.MustPublicKeyFromBase58(pubkeyString)
minSlot := uint64(123456789)
_, err := client.GetProgramAccountsWithOpts(
context.Background(),
pubKey,
&GetProgramAccountsOpts{
MinContextSlot: &minSlot,
},
)
require.NoError(t, err)
reqBody := server.RequestBody(t)
reqBody["id"] = any(nil)
assert.Equal(t,
map[string]any{
"id": any(nil),
"jsonrpc": "2.0",
"method": "getProgramAccounts",
"params": []any{
pubkeyString,
map[string]any{
"encoding": "base64",
"minContextSlot": float64(minSlot),
},
},
},
reqBody,
)
}
// TestClient_GetTokenAccountsByOwner_MinContextSlot pins that the
// minContextSlot opt is forwarded into the params object for the owner variant.
func TestClient_GetTokenAccountsByOwner_MinContextSlot(t *testing.T) {
responseBody := `{"context":{"slot":1},"value":[]}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
defer closer()
client := New(server.URL)
ownerString := "7xLk17EQQ5KLDLDe44wCmupJKJjTGd8hs3eSVVhCx932"
owner := solana.MustPublicKeyFromBase58(ownerString)
programIDString := "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
programID := solana.MustPublicKeyFromBase58(programIDString)
minSlot := uint64(987654321)
_, err := client.GetTokenAccountsByOwner(
context.Background(),
owner,
&GetTokenAccountsConfig{ProgramId: &programID},
&GetTokenAccountsOpts{MinContextSlot: &minSlot},
)
require.NoError(t, err)
reqBody := server.RequestBody(t)
reqBody["id"] = any(nil)
assert.Equal(t,
map[string]any{
"id": any(nil),
"jsonrpc": "2.0",
"method": "getTokenAccountsByOwner",
"params": []any{
ownerString,
map[string]any{"programId": programIDString},
map[string]any{
"encoding": "base64",
"minContextSlot": float64(minSlot),
},
},
},
reqBody,
)
}
// TestClient_GetTokenAccountsByDelegate_MinContextSlot pins the same for the
// delegate variant.
func TestClient_GetTokenAccountsByDelegate_MinContextSlot(t *testing.T) {
responseBody := `{"context":{"slot":1},"value":[]}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
defer closer()
client := New(server.URL)
delegateString := "7xLk17EQQ5KLDLDe44wCmupJKJjTGd8hs3eSVVhCx932"
delegate := solana.MustPublicKeyFromBase58(delegateString)
programIDString := "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
programID := solana.MustPublicKeyFromBase58(programIDString)
minSlot := uint64(42)
_, err := client.GetTokenAccountsByDelegate(
context.Background(),
delegate,
&GetTokenAccountsConfig{ProgramId: &programID},
&GetTokenAccountsOpts{MinContextSlot: &minSlot},
)
require.NoError(t, err)
reqBody := server.RequestBody(t)
reqBody["id"] = any(nil)
assert.Equal(t,
map[string]any{
"id": any(nil),
"jsonrpc": "2.0",
"method": "getTokenAccountsByDelegate",
"params": []any{
delegateString,
map[string]any{"programId": programIDString},
map[string]any{
"encoding": "base64",
"minContextSlot": float64(minSlot),
},
},
},
reqBody,
)
}