solana-go/rpc/client_test.go

2418 lines
476 KiB
Go
Raw Normal View History

2020-11-09 10:09:50 -08:00
// Copyright 2020 dfuse Platform Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package rpc
import (
"bytes"
2020-11-06 08:20:48 -08:00
"context"
stdjson "encoding/json"
"testing"
"github.com/AlekSi/pointer"
"github.com/gagliardetto/solana-go"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestClient_GetAccountInfo(t *testing.T) {
2021-07-07 08:52:58 -07:00
responseBody := `{"context":{"slot":83986105},"value":{"data":["dGVzdA==","base64"],"executable":true,"lamports":999999,"owner":"11111111111111111111111111111111","rentEpoch":207}}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
pubkeyString := "7xLk17EQQ5KLDLDe44wCmupJKJjTGd8hs3eSVVhCx932"
pubKey := solana.MustPublicKeyFromBase58(pubkeyString)
out, err := client.GetAccountInfo(context.Background(), pubKey)
2020-11-06 08:47:26 -08:00
require.NoError(t, err)
2021-07-09 08:36:53 -07:00
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getAccountInfo",
"params": []interface{}{
pubkeyString,
map[string]interface{}{
"encoding": "base64",
},
},
},
server.RequestBody(t),
)
2021-07-07 08:52:58 -07:00
assert.Equal(t,
&GetAccountInfoResult{
RPCContext: RPCContext{
Context{Slot: 83986105},
},
Value: &Account{
Lamports: 999999,
Owner: solana.MustPublicKeyFromBase58("11111111111111111111111111111111"),
Data: &DataBytesOrJSON{
rawDataEncoding: solana.EncodingBase64,
2021-07-12 07:00:27 -07:00
asDecodedBinary: solana.Data{
Content: []byte{0x74, 0x65, 0x73, 0x74},
Encoding: solana.EncodingBase64,
},
},
2021-07-07 08:52:58 -07:00
Executable: true,
RentEpoch: 207,
},
}, out)
2020-11-11 11:38:52 -08:00
}
2021-07-09 08:36:53 -07:00
func TestClient_GetAccountInfoWithOpts(t *testing.T) {
responseBody := `{"context":{"slot":83986105},"value":{"data":["dGVzdA==","base64"],"executable":true,"lamports":999999,"owner":"11111111111111111111111111111111","rentEpoch":207}}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
2021-07-09 08:56:15 -07:00
offset := uint64(22)
length := uint64(33)
2021-07-09 08:36:53 -07:00
pubkeyString := "7xLk17EQQ5KLDLDe44wCmupJKJjTGd8hs3eSVVhCx932"
pubKey := solana.MustPublicKeyFromBase58(pubkeyString)
opts := &GetAccountInfoOpts{
Encoding: solana.EncodingJSON,
2021-07-09 08:36:53 -07:00
Commitment: CommitmentMax,
DataSlice: &DataSlice{
Offset: &offset,
Length: &length,
},
2021-07-09 08:36:53 -07:00
}
_, err := client.GetAccountInfoWithOpts(
context.Background(),
pubKey,
opts,
)
require.NoError(t, err)
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getAccountInfo",
"params": []interface{}{
pubkeyString,
map[string]interface{}{
"encoding": string(solana.EncodingJSON),
2021-07-09 08:36:53 -07:00
"commitment": string(CommitmentMax),
"dataSlice": map[string]interface{}{
"offset": float64(offset),
"length": float64(length),
},
},
},
},
server.RequestBody(t),
)
}
2020-11-11 11:38:52 -08:00
func TestClient_GetConfirmedSignaturesForAddress2(t *testing.T) {
server, closer := mockJSONRPC(t, stdjson.RawMessage(`{"jsonrpc":"2.0","result":[{"err":null,"memo":null,"signature":"mgw5vw4tnbou1wVStKckVcVncbpRwfZPcMNbVBoigbSPXBMa3857CNzhwoCkRzM5K7nG32wcbpVJDHttQeBRaHB","slot":1}],"id":0}`))
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
account := solana.MustPublicKeyFromBase58("H7ATJQGhwG8Uf8sUntUognFpsKixPy2buFnXkvyNbGUb")
limit := uint64(1)
out, err := client.GetConfirmedSignaturesForAddress2(context.Background(), account, &GetConfirmedSignaturesForAddress2Opts{Limit: &limit})
2020-11-11 11:38:52 -08:00
require.NoError(t, err)
2021-07-09 08:36:53 -07:00
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getConfirmedSignaturesForAddress2",
"params": []interface{}{
"H7ATJQGhwG8Uf8sUntUognFpsKixPy2buFnXkvyNbGUb",
map[string]interface{}{"limit": float64(1)},
}},
server.RequestBody(t),
)
expected := []*TransactionSignature{
2021-07-07 08:52:58 -07:00
{Slot: 1, Signature: solana.MustSignatureFromBase58("mgw5vw4tnbou1wVStKckVcVncbpRwfZPcMNbVBoigbSPXBMa3857CNzhwoCkRzM5K7nG32wcbpVJDHttQeBRaHB")},
}
2020-11-11 11:38:52 -08:00
assert.Equal(t, GetConfirmedSignaturesForAddress2Result(expected), out)
2020-11-11 11:38:52 -08:00
}
func TestClient_GetConfirmedTransaction(t *testing.T) {
server, closer := mockJSONRPC(t, stdjson.RawMessage(`{"jsonrpc":"2.0","result":{"meta":{"err":null,"fee":5000,"innerInstructions":[],"logMessages":[],"postBalances":[],"preBalances":[],"status":{"Ok":null}},"slot":48291656,"transaction":{"message":{"accountKeys":["GKu2xfGZopa8C9K11wduQWgP4W4H7EEcaNdsUb7mxhyr"],"header":{"numReadonlySignedAccounts":0,"numReadonlyUnsignedAccounts":3,"numRequiredSignatures":1},"instructions":[{"accounts":[1,2,3,0],"data":"3yZe7d","programIdIndex":4}],"recentBlockhash":"uoEAQCWCKjV9ecsBvngctJ7upNBZX7hpN4SfdR6TaUz"},"signatures":["53hoZ98EsCMA6L63GWM65M3Bd3WqA4LxD8bcJkbKoKWhbJFqX9M1WZ4fSjt8bYyZn21NwNnV2A25zirBni9Qk6LR"]}},"id":0}`))
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2020-11-11 11:38:52 -08:00
2021-07-10 06:12:23 -07:00
out, err := client.GetConfirmedTransaction(
context.Background(),
solana.MustSignatureFromBase58("53hoZ98EsCMA6L63GWM65M3Bd3WqA4LxD8bcJkbKoKWhbJFqX9M1WZ4fSjt8bYyZn21NwNnV2A25zirBni9Qk6LR"),
)
2020-11-11 11:38:52 -08:00
require.NoError(t, err)
2021-07-09 08:36:53 -07:00
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getConfirmedTransaction",
"params": []interface{}{
"53hoZ98EsCMA6L63GWM65M3Bd3WqA4LxD8bcJkbKoKWhbJFqX9M1WZ4fSjt8bYyZn21NwNnV2A25zirBni9Qk6LR",
"json",
},
},
server.RequestBody(t),
)
2020-11-11 11:38:52 -08:00
signature, err := solana.SignatureFromBase58("53hoZ98EsCMA6L63GWM65M3Bd3WqA4LxD8bcJkbKoKWhbJFqX9M1WZ4fSjt8bYyZn21NwNnV2A25zirBni9Qk6LR")
2020-11-11 11:38:52 -08:00
require.NoError(t, err)
2020-11-06 08:47:26 -08:00
2021-07-14 10:37:10 -07:00
assert.Equal(t, &TransactionWithMeta{
Transaction: &solana.Transaction{
Message: solana.Message{
Header: solana.MessageHeader{NumRequiredSignatures: 1, NumReadonlySignedAccounts: 0, NumReadonlyUnsignedAccounts: 3},
2021-07-07 08:52:58 -07:00
RecentBlockhash: solana.MustHashFromBase58("uoEAQCWCKjV9ecsBvngctJ7upNBZX7hpN4SfdR6TaUz"),
AccountKeys: []solana.PublicKey{solana.MustPublicKeyFromBase58("GKu2xfGZopa8C9K11wduQWgP4W4H7EEcaNdsUb7mxhyr")},
Instructions: []solana.CompiledInstruction{
{Accounts: []uint16{1, 2, 3, 0}, Data: solana.Base58([]byte{0x74, 0x65, 0x73, 0x74}), ProgramIDIndex: 4},
},
},
Signatures: []solana.Signature{signature},
},
2021-07-07 08:52:58 -07:00
Meta: &TransactionMeta{
Fee: 5000,
PreBalances: []uint64{},
PostBalances: []uint64{},
2021-07-07 08:52:58 -07:00
InnerInstructions: []InnerInstruction{},
LogMessages: []string{},
Status: DeprecatedTransactionMetaStatus{
"Ok": nil,
},
},
}, out)
2020-11-06 08:47:26 -08:00
}
2020-11-25 11:25:32 -08:00
2021-07-07 08:52:58 -07:00
// mustAnyToJSON marshals the provided variable
// to JSON bytes.
func mustAnyToJSON(raw interface{}) []byte {
out, err := json.Marshal(raw)
if err != nil {
panic(err)
}
return out
}
// mustJSONToInterface unmarshals the provided JSON bytes
// into an `interface{}` type variable, and returns it.
func mustJSONToInterface(rawJSON []byte) interface{} {
var out interface{}
2021-07-27 09:26:32 -07:00
err := json.Unmarshal(rawJSON, &out)
if err != nil {
panic(err)
}
return out
}
// mustJSONToInterfaceWithUseNumber unmarshals the provided JSON bytes
// into an `interface{}` type variable, and returns it.
// The decoder is configured with `UseNumber()`.
func mustJSONToInterfaceWithUseNumber(rawJSON []byte) interface{} {
var out interface{}
dec := json.NewDecoder(bytes.NewReader(rawJSON))
dec.UseNumber()
err := dec.Decode(&out)
2021-07-07 08:52:58 -07:00
if err != nil {
panic(err)
}
return out
}
// wrapIntoRPC wraps the provided string is an RPC payload as result.
func wrapIntoRPC(res string) string {
return `{"jsonrpc":"2.0","result":` + res + `,"id":0}`
}
2021-07-09 09:30:07 -07:00
func TestClient_GetRecentBlockhash(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `{"context":{"slot":83986105},"value":{"blockhash":"DvLEyV2GHk86K5GojpqnRsvhfMF5kdZomKMnhVpvHyqK","feeCalculator":{"lamportsPerSignature":5000}}}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
out, err := client.GetRecentBlockhash(
context.Background(),
CommitmentMax,
)
require.NoError(t, err)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getRecentBlockhash",
"params": []interface{}{
map[string]interface{}{
"commitment": string(CommitmentMax),
},
},
},
server.RequestBody(t),
)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
expected := mustJSONToInterface([]byte(responseBody))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
got := mustJSONToInterface(mustAnyToJSON(out))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetBalance(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `{"context":{"slot":83987501},"value":19039980000}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
pubkeyString := "7xLk17EQQ5KLDLDe44wCmupJKJjTGd8hs3eSVVhCx932"
pubKey := solana.MustPublicKeyFromBase58(pubkeyString)
out, err := client.GetBalance(
context.Background(),
pubKey,
CommitmentMax,
)
require.NoError(t, err)
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getBalance",
"params": []interface{}{
pubkeyString,
map[string]interface{}{
"commitment": string(CommitmentMax),
2021-07-07 08:52:58 -07:00
},
2021-07-09 08:36:53 -07:00
},
},
server.RequestBody(t),
)
assert.Equal(t,
&GetBalanceResult{
RPCContext: RPCContext{
Context{Slot: 83987501},
},
Value: 19039980000,
}, out)
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetBlock(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `{"blockHeight":69213636,"blockTime":1625227950,"blockhash":"5M77sHdwzH6rckuQwF8HL1w52n7hjrh4GVTFiF6T8QyB","parentSlot":83987983,"previousBlockhash":"Aq9jSXe1jRzfiaBcRFLe4wm7j499vWVEeFQrq5nnXfZN","rewards":[{"lamports":1595000,"postBalance":482032983798,"pubkey":"5rL3AaidKJa4ChSV3ys1SvpDg9L4amKiwYayGR5oL3dq","rewardType":"Fee"}],"transactions":[{"meta":{"err":null,"fee":5000,"innerInstructions":[],"logMessages":["Program Vote111111111111111111111111111111111111111 invoke [1]","Program Vote111111111111111111111111111111111111111 success"],"postBalances":[441866063495,40905918933763,1,1,1],"postTokenBalances":[],"preBalances":[441866068495,40905918933763,1,1,1],"preTokenBalances":[],"rewards":[],"status":{"Ok":null}},"transaction":{"message":{"accountKeys":["EVd8FFVB54svYdZdG6hH4F4hTbqre5mpQ7XyF5rKUmes","72miaovmbPqccdbAA861r2uxwB5yL1sMjrgbCnc4JfVT","SysvarS1otHashes111111111111111111111111111","SysvarC1ock11111111111111111111111111111111","Vote111111111111111111111111111111111111111"],"header":{"numReadonlySignedAccounts":0,"numReadonlyUnsignedAccounts":3,"numRequiredSignatures":1},"instructions":[{"accounts":[1,2,3,0],"data":"3yZe7d","programIdIndex":4}],"recentBlockhash":"CnyzpJmBydX1X2FyXXzsPFc5WPT9UFdLVkEhnvW33at"},"signatures":["D8emaP3CaepSGigD3TCrev7j67yPLMi82qfzTb9iZYPxHcCmm6sQBKTU4bzAee4445zbnbWduVAZ87WfbWbXoAU"]}},{"meta":{"err":null,"fee":5000,"innerInstructions":[],"logMessages":["Program Vote111111111111111111111111111111111111111 invoke [1]","Program Vote111111111111111111111111111111111111111 success"],"postBalances":[334759887662,151357332545078,1,1,1],"postTokenBalances":[],"preBalances":[334759892662,151357332545078,1,1,1],"preTokenBalances":[],"rewards":[],"status":{"Ok":null}},"transaction":{"message":{"accountKeys":["5rxRt2GVpSUFJTqQ5E4urqJCDbcBPakb46t6URyxQ5Za","HdzdTTjrmRLYVRy3umzZX4NcUmGTHu6hvYLQN2jGJo53","SysvarS1otHashes111111111111111111111111111","SysvarC1ock11111111111111111111111111111111","Vote111111111111111111111111111111111111111"],"header":{"numReadonlySignedAccounts":0,"numReadonlyUnsignedAccounts":3,"numRequiredSignatures":1},"instructions":[{"accounts":[1,2,3,0],"data":"3yZe7d","programIdIndex":4}],"recentBlockhash":"BL8oo42yoSTKUYpbXR3kdxeV5X1P8JUUZBZaeBL8K6G"},"signatures":["xvrkWXwj5h9SsJvboPMtn4jbR6XNmnHYp4MAikKFwdtkpwMxceFZ46QRzeyGUqm5P1kmCagdUubr3aPdxo7vzyq"]}}]}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
block := 33
out, err := client.GetBlock(
context.Background(),
2021-07-09 08:56:15 -07:00
uint64(block),
2021-07-09 08:36:53 -07:00
)
require.NoError(t, err)
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getBlock",
"params": []interface{}{
float64(block),
map[string]interface{}{
"encoding": string(solana.EncodingJSON),
2021-07-07 08:52:58 -07:00
},
2021-07-09 08:36:53 -07:00
},
},
server.RequestBody(t),
)
// TODO:
// - test also when requesting only signatures
assert.Equal(t,
&GetBlockResult{
BlockHeight: pointer.ToUint64(69213636),
BlockTime: pointer.ToInt64(1625227950),
2021-07-09 08:36:53 -07:00
Blockhash: solana.MustHashFromBase58("5M77sHdwzH6rckuQwF8HL1w52n7hjrh4GVTFiF6T8QyB"),
ParentSlot: 83987983,
PreviousBlockhash: solana.MustHashFromBase58("Aq9jSXe1jRzfiaBcRFLe4wm7j499vWVEeFQrq5nnXfZN"),
Rewards: []BlockReward{
{
Lamports: 1595000,
PostBalance: 482032983798,
Pubkey: solana.MustPublicKeyFromBase58("5rL3AaidKJa4ChSV3ys1SvpDg9L4amKiwYayGR5oL3dq"),
RewardType: RewardTypeFee,
},
},
Transactions: []TransactionWithMeta{
{
Meta: &TransactionMeta{
Err: nil,
Fee: 5000,
InnerInstructions: []InnerInstruction{},
LogMessages: []string{
"Program Vote111111111111111111111111111111111111111 invoke [1]", "Program Vote111111111111111111111111111111111111111 success",
},
PostBalances: []uint64{
2021-07-09 08:36:53 -07:00
441866063495, 40905918933763, 1, 1, 1,
},
PostTokenBalances: []TokenBalance{},
PreBalances: []uint64{
2021-07-09 08:36:53 -07:00
441866068495, 40905918933763, 1, 1, 1,
},
PreTokenBalances: []TokenBalance{},
Rewards: []BlockReward{},
Status: DeprecatedTransactionMetaStatus{
"Ok": nil,
},
},
Transaction: &solana.Transaction{
Message: solana.Message{
AccountKeys: []solana.PublicKey{
solana.MustPublicKeyFromBase58("EVd8FFVB54svYdZdG6hH4F4hTbqre5mpQ7XyF5rKUmes"),
solana.MustPublicKeyFromBase58("72miaovmbPqccdbAA861r2uxwB5yL1sMjrgbCnc4JfVT"),
solana.MustPublicKeyFromBase58("SysvarS1otHashes111111111111111111111111111"),
solana.MustPublicKeyFromBase58("SysvarC1ock11111111111111111111111111111111"),
solana.MustPublicKeyFromBase58("Vote111111111111111111111111111111111111111"),
2021-07-07 08:52:58 -07:00
},
2021-07-09 08:36:53 -07:00
Header: solana.MessageHeader{
NumReadonlySignedAccounts: 0,
NumReadonlyUnsignedAccounts: 3,
NumRequiredSignatures: 1,
2021-07-07 08:52:58 -07:00
},
2021-07-09 08:36:53 -07:00
Instructions: []solana.CompiledInstruction{
{
Accounts: []uint16{1, 2, 3, 0},
2021-07-09 08:36:53 -07:00
Data: solana.Base58([]byte{0x74, 0x65, 0x73, 0x74}),
ProgramIDIndex: 4,
2021-07-07 08:52:58 -07:00
},
},
2021-07-09 08:36:53 -07:00
RecentBlockhash: solana.MustHashFromBase58("CnyzpJmBydX1X2FyXXzsPFc5WPT9UFdLVkEhnvW33at"),
},
Signatures: []solana.Signature{
solana.MustSignatureFromBase58("D8emaP3CaepSGigD3TCrev7j67yPLMi82qfzTb9iZYPxHcCmm6sQBKTU4bzAee4445zbnbWduVAZ87WfbWbXoAU"),
2021-07-07 08:52:58 -07:00
},
},
2021-07-09 08:36:53 -07:00
},
{
Meta: &TransactionMeta{
Err: nil,
Fee: 5000,
InnerInstructions: []InnerInstruction{},
LogMessages: []string{
"Program Vote111111111111111111111111111111111111111 invoke [1]", "Program Vote111111111111111111111111111111111111111 success",
},
PostBalances: []uint64{
2021-07-09 08:36:53 -07:00
334759887662, 151357332545078, 1, 1, 1,
},
PostTokenBalances: []TokenBalance{},
PreBalances: []uint64{
2021-07-09 08:36:53 -07:00
334759892662, 151357332545078, 1, 1, 1,
},
PreTokenBalances: []TokenBalance{},
Rewards: []BlockReward{},
Status: DeprecatedTransactionMetaStatus{
"Ok": nil,
},
},
Transaction: &solana.Transaction{
Message: solana.Message{
AccountKeys: []solana.PublicKey{
solana.MustPublicKeyFromBase58("5rxRt2GVpSUFJTqQ5E4urqJCDbcBPakb46t6URyxQ5Za"),
solana.MustPublicKeyFromBase58("HdzdTTjrmRLYVRy3umzZX4NcUmGTHu6hvYLQN2jGJo53"),
solana.MustPublicKeyFromBase58("SysvarS1otHashes111111111111111111111111111"),
solana.MustPublicKeyFromBase58("SysvarC1ock11111111111111111111111111111111"),
solana.MustPublicKeyFromBase58("Vote111111111111111111111111111111111111111"),
2021-07-07 08:52:58 -07:00
},
2021-07-09 08:36:53 -07:00
Header: solana.MessageHeader{
NumReadonlySignedAccounts: 0,
NumReadonlyUnsignedAccounts: 3,
NumRequiredSignatures: 1,
2021-07-07 08:52:58 -07:00
},
2021-07-09 08:36:53 -07:00
Instructions: []solana.CompiledInstruction{
{
Accounts: []uint16{1, 2, 3, 0},
2021-07-09 08:36:53 -07:00
Data: solana.Base58([]byte{0x74, 0x65, 0x73, 0x74}),
ProgramIDIndex: 4,
2021-07-07 08:52:58 -07:00
},
},
2021-07-09 08:36:53 -07:00
RecentBlockhash: solana.MustHashFromBase58("BL8oo42yoSTKUYpbXR3kdxeV5X1P8JUUZBZaeBL8K6G"),
},
Signatures: []solana.Signature{
solana.MustSignatureFromBase58("xvrkWXwj5h9SsJvboPMtn4jbR6XNmnHYp4MAikKFwdtkpwMxceFZ46QRzeyGUqm5P1kmCagdUubr3aPdxo7vzyq"),
2021-07-07 08:52:58 -07:00
},
},
},
2021-07-09 08:36:53 -07:00
},
}, out)
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetBlockWithOpts(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `{"blockHeight":69213636,"blockTime":1625227950,"blockhash":"5M77sHdwzH6rckuQwF8HL1w52n7hjrh4GVTFiF6T8QyB","parentSlot":83987983,"previousBlockhash":"Aq9jSXe1jRzfiaBcRFLe4wm7j499vWVEeFQrq5nnXfZN","rewards":[{"lamports":1595000,"postBalance":482032983798,"pubkey":"5rL3AaidKJa4ChSV3ys1SvpDg9L4amKiwYayGR5oL3dq","rewardType":"Fee"}],"transactions":[{"meta":{"err":null,"fee":5000,"innerInstructions":[],"logMessages":["Program Vote111111111111111111111111111111111111111 invoke [1]","Program Vote111111111111111111111111111111111111111 success"],"postBalances":[441866063495,40905918933763,1,1,1],"postTokenBalances":[],"preBalances":[441866068495,40905918933763,1,1,1],"preTokenBalances":[],"rewards":[],"status":{"Ok":null}},"transaction":{"message":{"accountKeys":["EVd8FFVB54svYdZdG6hH4F4hTbqre5mpQ7XyF5rKUmes","72miaovmbPqccdbAA861r2uxwB5yL1sMjrgbCnc4JfVT","SysvarS1otHashes111111111111111111111111111","SysvarC1ock11111111111111111111111111111111","Vote111111111111111111111111111111111111111"],"header":{"numReadonlySignedAccounts":0,"numReadonlyUnsignedAccounts":3,"numRequiredSignatures":1},"instructions":[{"accounts":[1,2,3,0],"data":"3yZe7d","programIdIndex":4}],"recentBlockhash":"CnyzpJmBydX1X2FyXXzsPFc5WPT9UFdLVkEhnvW33at"},"signatures":["D8emaP3CaepSGigD3TCrev7j67yPLMi82qfzTb9iZYPxHcCmm6sQBKTU4bzAee4445zbnbWduVAZ87WfbWbXoAU"]}},{"meta":{"err":null,"fee":5000,"innerInstructions":[],"logMessages":["Program Vote111111111111111111111111111111111111111 invoke [1]","Program Vote111111111111111111111111111111111111111 success"],"postBalances":[334759887662,151357332545078,1,1,1],"postTokenBalances":[],"preBalances":[334759892662,151357332545078,1,1,1],"preTokenBalances":[],"rewards":[],"status":{"Ok":null}},"transaction":{"message":{"accountKeys":["5rxRt2GVpSUFJTqQ5E4urqJCDbcBPakb46t6URyxQ5Za","HdzdTTjrmRLYVRy3umzZX4NcUmGTHu6hvYLQN2jGJo53","SysvarS1otHashes111111111111111111111111111","SysvarC1ock11111111111111111111111111111111","Vote111111111111111111111111111111111111111"],"header":{"numReadonlySignedAccounts":0,"numReadonlyUnsignedAccounts":3,"numRequiredSignatures":1},"instructions":[{"accounts":[1,2,3,0],"data":"3yZe7d","programIdIndex":4}],"recentBlockhash":"BL8oo42yoSTKUYpbXR3kdxeV5X1P8JUUZBZaeBL8K6G"},"signatures":["xvrkWXwj5h9SsJvboPMtn4jbR6XNmnHYp4MAikKFwdtkpwMxceFZ46QRzeyGUqm5P1kmCagdUubr3aPdxo7vzyq"]}}]}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-07 08:52:58 -07:00
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
block := 33
rewards := true
_, err := client.GetBlockWithOpts(
context.Background(),
2021-07-09 08:56:15 -07:00
uint64(block),
2021-07-09 08:36:53 -07:00
&GetBlockOpts{
TransactionDetails: TransactionDetailsSignatures,
Rewards: &rewards,
Commitment: CommitmentMax,
},
)
require.NoError(t, err)
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getBlock",
"params": []interface{}{
float64(block),
map[string]interface{}{
"encoding": string(solana.EncodingJSON),
2021-07-09 08:36:53 -07:00
"transactionDetails": string(TransactionDetailsSignatures),
"rewards": rewards,
"commitment": string(CommitmentMax),
},
},
},
server.RequestBody(t),
)
// TODO:
// - test also when requesting only signatures
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetBlockHeight(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `69217140`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
out, err := client.GetBlockHeight(
context.Background(),
CommitmentMax,
)
require.NoError(t, err)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getBlockHeight",
"params": []interface{}{
map[string]interface{}{
"commitment": string(CommitmentMax),
},
},
},
server.RequestBody(t),
)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
expected := mustJSONToInterface([]byte(responseBody))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
got := mustJSONToInterface(mustAnyToJSON(out))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetBlockProduction(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `{"context":{"slot":83992896},"value":{"byIdentity":{"121cur1YFVPZSoKQGNyjNr9sZZRa3eX2bSuYjXHtKD6":[44,38],"123vij84ecQEKUvQ7gYMKxKwKF6PbYSzCzzURYA4xULY":[52,49],"12QYHqRxPuTPfkBVLetEuGkLGHD9GhqM5coP67xK7wfG":[64,55],"12Y25eHzGPaK5R5DjQ1kgJWuVd7zrtQ7cmaMPfmacsJV":[40,29],"12uDsSSWyPRGNK3HqcLBRNZiNFJWXCcHvHD7V4RYsKMr":[60,54],"132GXL3pzAjyEKoYLBS3QDTWDLqPnLJdZNcK4cWNDrmb":[64,43],"13nbrL1VjkfTZuaz7rNriYw6fWDFggqEf2g1C4mPETkr":[36,20],"14Z57kkY62p2UZyqeQyoGsXfkKbguAF1G8g2kZdV7Vae":[16,0],"1B4UocjePKwr58Jw4sLBsBHFt9nXGWxi1QDv9g73mrs":[48,36],"1DdfupGTrYUKtRxN9ukGCf3HBquc4buGPPmZr9WEjY4":[36,16],"21Ew2QbeiXprspa96d76RgueZ6HvrQMDTFAHpa71hpoR":[68,53],"234u57PuEif5LkTBwS7rHzu1XF5VWg79ddLLDkYBh44Q":[4,0],"238Fmy2TwU26Fo8XFRu2PzDWNbcn3bitywEPYG6tpztu":[44,36],"23eke7qW4tibp13JfiHKLErVsdmLDTwVsqg52bVQwBCZ":[32,23],"23xMZ9ijUgM9mRVB8sk7ZUR9yCRdP9eWU4ohjgbQbhGV":[64,45],"25UM59KCvciYwhjCq7t1rC8ZuvsxQBC2QRcaRNfq7xML":[56,50],"27JQHoxJi8kpJzwED2eTv8jDPB81gjqNFYBNN6rjM3UM":[44,43],"28LgQ7MeEZVgNJfYRc6UnoAz2SnSjKbyCKM6sntCRotb":[64,49],"28aB6dFf5TPKz3ghnYnu7nNaLsinoAE4xNyid1sy9j9e":[52,49],"295DP6WSsiJ3oLNPhZ3oSZUA6gwbGe7KDoHWRnRBZAHu":[76,59],"29Xwdi4HpBr1u9EAqDz3tBbMuwqBuczLPuVe2gGkg7ZF":[44,33],"29mA6zhspyms8m17FX8ztzz5UU9Fdqbumk1vxEGUkC7H":[52,38],"29tXWWzvGNvE5j8i6FLfHpmanPC9treZsCo1uA4ik1kL":[56,43],"2AY3bKHAMkdj4cCn1UcWCjewrg3ccDnhVmvJ3WrmmkAL":[36,33],"2BT25HZHpyzYmTbqyqzxBK7YjjH4a6aZ783TEgTTGYo5":[48,42],"2C26iHJcU5dqJJQ6NME3Lq583RT1Js9QDtgfmzknRajc":[52,43],"2C9pDcbRQJxbUHivgDdg4LGuMwm5oeVCnHS9w5JktNTo":[68,49],"2CGskjnksG9YwAFMJkPDwsKx1iRAXJSzfpAxyoWzGj6M":[60,36],"2Ceu5z672tACCDB6cmB3n4tih7B8dikv6k6kfYr3Li1e":[44,36],"2CjEU72sCTy1D6GyvpAjtKVGz94jdz8geN2JNWJCzZ6q":[56,0],"2D1oCLRK6geGhV5RyZ52JD9Qzqt311AEH1XrTjZdzbRh":[48,38],"2DvsPbbKrBaJm7SbdVvRjZL1NGCU3MwciGCoCw42fTMu":[4,0],"2Ebt7yP857s1WfdoqNm9FsGeahCvjdXcqhvsVjzNgUfx":[60,38],"2F5vGa1L5f1kKKwfcQvWGQCkJ7aoAxDRg4mZmxq9Ti3i":[40,34],"2FCxeG7mBYy2kpYgvgTZLCYXnaqDc4hGwYunhzHmEUD1":[68,46],"2FTDGeDUAXJokjVSjRXX2WoTc4tW2uMagYB5jk4JCJAK":[36,31],"2GAdxV8QafdRnkTwy9AuX8HvVcNME6JqK2yANaDunhXp":[40,32],"2H6AvmuhZ2yWSN8K8CQTPcAfVaGM63cr3oUeVSw6pUhT":[40,34],"2JPBDCGefojYLyy87VfJkHUVjMhD4H49KPgdCkitRwTi":[52,19],"2KFrkqEeSBKEHiMjUugPxTkBJ2jXepgFBqHu5ZFxtaFg":[56,38],"2LsRRgttA1PKXXeKTZP2QhetgM94Dj5uecmTzyQkTvXK":[32,13],"2MKNRRH59tZXPUas1UcozqZtAHmXJBzpvNHUGySQUaw4":[64,46],"2P3YH9psWAAM6QQgA8NaQnKHQ973cKNqTSFFCNYE4gjk":[64,56],"2PDvmDx6HeKv3wtdwmGQGmz9pGXXDKNFVvGizGGaAqxL":[56,38],"2Pik6jn6yLQVi8jmwvZCibTygPWvhh3pXoGJrGT3eVGf":[44,41],"2PvsR9DM2GZavFQGDsdJwXJvPWsyneyT9Gpu7wXGDkSr":[52,38],"2Pvzm7bGYjCpfjj8iyF724eesh12PejtKgxzv53ctgXk":[4,4],"2RLf3RSy1ScBFL5UzVDw3jYKCAuGA9vHpr9dnbQzJt8V":[52,51],"2RNHZTsFQF7BwgTrrwH4qvibWeguU67BKnPAxysaLUVi":[52,51],"2RpZdDc9ss5VsVUgHox2e6u6yV1SKUrQV6iuzvggdLKK":[48,47],"2TEGxhx2CgHw5fpkrvJWBsRKbJNAT3y6Fco4Lj5DsJjk":[52,39],"2TGWTnUbjfZqvFYTgwUTdA3rXLHshRbeDgVMEMg7icZy":[24,23],"2TcLzmdcpQqbNEBjU2Hxp1MiETSww1HJeWW84F61Z13k":[56,53],"2UCNzcnSVGtkgzpm1guxR6hEDQ5A8gVDkwVTWfZ31bPg":[36,31],"2UJ4q96QBg8dQom8JFgCMASdJnngrxhafgjY3XA5ddso":[40,31],"2Uv6KbG9Smt8PVMiPVGcRzt2GMvUvnvydSsgVRUZZZdS":[56,43],"2VEnBfmR1LW44oemZK29MtBHxTuprLizjPcLycNyGkTt":[56,33],"2VL9dMnHPJG6sD9CuB1BkPCpB6S5EMnvXBECHHnKqz3z":[32,32],"2VzCLy98rzmvKGo23e1eM4LANCt9JFrtVTBBMZzGT4FW":[56,48],"2X2APoUmQcbyVfVNCmivzYRkydxZkfVdXXaSCHQTa8mC":[76,66],"2X5JSTLN9m2wm3ejCxfWRNMieuC2VMtaMWSoqLPbC4Pq":[28,21],"2XP9MfzWQnX3DiAJQFSKXKyqBr4M7GKhHnKc9P7z519H":[4,0],"2YeoCYp1KT5W6S8MEVbu1omSrHVtZPEVcpFFKRdXwfAK":[8,7],"2YgttBBx9Ax6WhF9xu8CSWw5usKFWxaxzJtg8zPajadx":[4,4],"2YtaVYd8fZHXpPezG5gRp9nudXGBEPcqFtJe8ikN1DZ7":[44,38],"2YvDq2K7zBvsqZFVqTGVcKqJqSLZaJH1hny6fah14mqt":[16,11],"2ZETk6Sy3wdrbTRRCFa6u1gzNjg59B5yFJwjiACC6Evc":[56,36],"2ZQbsxdEab52wEFELQnn2wsN4LRhsPrjyCeqfDdtD2f1":[56,29],"2ZZkgKcBfp4tW8qCLj2yjxRYh9CuvEVJWb6e2KKS91Mj":[60,52],"2ZqaTLm1TZfpYdR7d8XhRntPjmrF6q69YZVLb6j4GcWz":[64,38],"2anGa2owPRuQyHyEaWSbrrWws6NiyoakByaXEufuU3hH":[72,51],"2bQyrSEPaQ9BMbu7Ftv7ye1fxtSLW3oZRj4d2U64AJmc":[52,40],"2bZXLja7MqWiTtDfxTm78rvxaxfa34RhF4msQmvCBAWn":[52,37],"2cgXfdfA4EcJjouu5jxruaCMPy
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
out, err := client.GetBlockProduction(
context.Background(),
)
require.NoError(t, err)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getBlockProduction",
"params": []interface{}{},
},
server.RequestBody(t),
)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
expected := mustJSONToInterface([]byte(responseBody))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
got := mustJSONToInterface(mustAnyToJSON(out))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t, expected, got, "both deserialized values must be equal")
}
2021-07-07 08:52:58 -07:00
2021-07-09 09:30:07 -07:00
func TestClient_GetBlockProductionWithOpts(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `{"context":{"slot":83992896},"value":{"byIdentity":{"121cur1YFVPZSoKQGNyjNr9sZZRa3eX2bSuYjXHtKD6":[44,38],"123vij84ecQEKUvQ7gYMKxKwKF6PbYSzCzzURYA4xULY":[52,49],"12QYHqRxPuTPfkBVLetEuGkLGHD9GhqM5coP67xK7wfG":[64,55],"12Y25eHzGPaK5R5DjQ1kgJWuVd7zrtQ7cmaMPfmacsJV":[40,29],"12uDsSSWyPRGNK3HqcLBRNZiNFJWXCcHvHD7V4RYsKMr":[60,54],"132GXL3pzAjyEKoYLBS3QDTWDLqPnLJdZNcK4cWNDrmb":[64,43],"13nbrL1VjkfTZuaz7rNriYw6fWDFggqEf2g1C4mPETkr":[36,20],"14Z57kkY62p2UZyqeQyoGsXfkKbguAF1G8g2kZdV7Vae":[16,0],"1B4UocjePKwr58Jw4sLBsBHFt9nXGWxi1QDv9g73mrs":[48,36],"1DdfupGTrYUKtRxN9ukGCf3HBquc4buGPPmZr9WEjY4":[36,16],"21Ew2QbeiXprspa96d76RgueZ6HvrQMDTFAHpa71hpoR":[68,53],"234u57PuEif5LkTBwS7rHzu1XF5VWg79ddLLDkYBh44Q":[4,0],"238Fmy2TwU26Fo8XFRu2PzDWNbcn3bitywEPYG6tpztu":[44,36],"23eke7qW4tibp13JfiHKLErVsdmLDTwVsqg52bVQwBCZ":[32,23],"23xMZ9ijUgM9mRVB8sk7ZUR9yCRdP9eWU4ohjgbQbhGV":[64,45],"25UM59KCvciYwhjCq7t1rC8ZuvsxQBC2QRcaRNfq7xML":[56,50],"27JQHoxJi8kpJzwED2eTv8jDPB81gjqNFYBNN6rjM3UM":[44,43],"28LgQ7MeEZVgNJfYRc6UnoAz2SnSjKbyCKM6sntCRotb":[64,49],"28aB6dFf5TPKz3ghnYnu7nNaLsinoAE4xNyid1sy9j9e":[52,49],"295DP6WSsiJ3oLNPhZ3oSZUA6gwbGe7KDoHWRnRBZAHu":[76,59],"29Xwdi4HpBr1u9EAqDz3tBbMuwqBuczLPuVe2gGkg7ZF":[44,33],"29mA6zhspyms8m17FX8ztzz5UU9Fdqbumk1vxEGUkC7H":[52,38],"29tXWWzvGNvE5j8i6FLfHpmanPC9treZsCo1uA4ik1kL":[56,43],"2AY3bKHAMkdj4cCn1UcWCjewrg3ccDnhVmvJ3WrmmkAL":[36,33],"2BT25HZHpyzYmTbqyqzxBK7YjjH4a6aZ783TEgTTGYo5":[48,42],"2C26iHJcU5dqJJQ6NME3Lq583RT1Js9QDtgfmzknRajc":[52,43],"2C9pDcbRQJxbUHivgDdg4LGuMwm5oeVCnHS9w5JktNTo":[68,49],"2CGskjnksG9YwAFMJkPDwsKx1iRAXJSzfpAxyoWzGj6M":[60,36],"2Ceu5z672tACCDB6cmB3n4tih7B8dikv6k6kfYr3Li1e":[44,36],"2CjEU72sCTy1D6GyvpAjtKVGz94jdz8geN2JNWJCzZ6q":[56,0],"2D1oCLRK6geGhV5RyZ52JD9Qzqt311AEH1XrTjZdzbRh":[48,38],"2DvsPbbKrBaJm7SbdVvRjZL1NGCU3MwciGCoCw42fTMu":[4,0],"2Ebt7yP857s1WfdoqNm9FsGeahCvjdXcqhvsVjzNgUfx":[60,38],"2F5vGa1L5f1kKKwfcQvWGQCkJ7aoAxDRg4mZmxq9Ti3i":[40,34],"2FCxeG7mBYy2kpYgvgTZLCYXnaqDc4hGwYunhzHmEUD1":[68,46],"2FTDGeDUAXJokjVSjRXX2WoTc4tW2uMagYB5jk4JCJAK":[36,31],"2GAdxV8QafdRnkTwy9AuX8HvVcNME6JqK2yANaDunhXp":[40,32],"2H6AvmuhZ2yWSN8K8CQTPcAfVaGM63cr3oUeVSw6pUhT":[40,34],"2JPBDCGefojYLyy87VfJkHUVjMhD4H49KPgdCkitRwTi":[52,19],"2KFrkqEeSBKEHiMjUugPxTkBJ2jXepgFBqHu5ZFxtaFg":[56,38],"2LsRRgttA1PKXXeKTZP2QhetgM94Dj5uecmTzyQkTvXK":[32,13],"2MKNRRH59tZXPUas1UcozqZtAHmXJBzpvNHUGySQUaw4":[64,46],"2P3YH9psWAAM6QQgA8NaQnKHQ973cKNqTSFFCNYE4gjk":[64,56],"2PDvmDx6HeKv3wtdwmGQGmz9pGXXDKNFVvGizGGaAqxL":[56,38],"2Pik6jn6yLQVi8jmwvZCibTygPWvhh3pXoGJrGT3eVGf":[44,41],"2PvsR9DM2GZavFQGDsdJwXJvPWsyneyT9Gpu7wXGDkSr":[52,38],"2Pvzm7bGYjCpfjj8iyF724eesh12PejtKgxzv53ctgXk":[4,4],"2RLf3RSy1ScBFL5UzVDw3jYKCAuGA9vHpr9dnbQzJt8V":[52,51],"2RNHZTsFQF7BwgTrrwH4qvibWeguU67BKnPAxysaLUVi":[52,51],"2RpZdDc9ss5VsVUgHox2e6u6yV1SKUrQV6iuzvggdLKK":[48,47],"2TEGxhx2CgHw5fpkrvJWBsRKbJNAT3y6Fco4Lj5DsJjk":[52,39],"2TGWTnUbjfZqvFYTgwUTdA3rXLHshRbeDgVMEMg7icZy":[24,23],"2TcLzmdcpQqbNEBjU2Hxp1MiETSww1HJeWW84F61Z13k":[56,53],"2UCNzcnSVGtkgzpm1guxR6hEDQ5A8gVDkwVTWfZ31bPg":[36,31],"2UJ4q96QBg8dQom8JFgCMASdJnngrxhafgjY3XA5ddso":[40,31],"2Uv6KbG9Smt8PVMiPVGcRzt2GMvUvnvydSsgVRUZZZdS":[56,43],"2VEnBfmR1LW44oemZK29MtBHxTuprLizjPcLycNyGkTt":[56,33],"2VL9dMnHPJG6sD9CuB1BkPCpB6S5EMnvXBECHHnKqz3z":[32,32],"2VzCLy98rzmvKGo23e1eM4LANCt9JFrtVTBBMZzGT4FW":[56,48],"2X2APoUmQcbyVfVNCmivzYRkydxZkfVdXXaSCHQTa8mC":[76,66],"2X5JSTLN9m2wm3ejCxfWRNMieuC2VMtaMWSoqLPbC4Pq":[28,21],"2XP9MfzWQnX3DiAJQFSKXKyqBr4M7GKhHnKc9P7z519H":[4,0],"2YeoCYp1KT5W6S8MEVbu1omSrHVtZPEVcpFFKRdXwfAK":[8,7],"2YgttBBx9Ax6WhF9xu8CSWw5usKFWxaxzJtg8zPajadx":[4,4],"2YtaVYd8fZHXpPezG5gRp9nudXGBEPcqFtJe8ikN1DZ7":[44,38],"2YvDq2K7zBvsqZFVqTGVcKqJqSLZaJH1hny6fah14mqt":[16,11],"2ZETk6Sy3wdrbTRRCFa6u1gzNjg59B5yFJwjiACC6Evc":[56,36],"2ZQbsxdEab52wEFELQnn2wsN4LRhsPrjyCeqfDdtD2f1":[56,29],"2ZZkgKcBfp4tW8qCLj2yjxRYh9CuvEVJWb6e2KKS91Mj":[60,52],"2ZqaTLm1TZfpYdR7d8XhRntPjmrF6q69YZVLb6j4GcWz":[64,38],"2anGa2owPRuQyHyEaWSbrrWws6NiyoakByaXEufuU3hH":[72,51],"2bQyrSEPaQ9BMbu7Ftv7ye1fxtSLW3oZRj4d2U64AJmc":[52,40],"2bZXLja7MqWiTtDfxTm78rvxaxfa34RhF4msQmvCBAWn":[52,37],"2cgXfdfA4EcJjouu5jxruaCMPy
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-07 08:52:58 -07:00
2021-07-09 08:56:15 -07:00
firstSlot := uint64(2)
lastSlot := uint64(3)
pubkeyString := "7xLk17EQQ5KLDLDe44wCmupJKJjTGd8hs3eSVVhCx932"
pubKey := solana.MustPublicKeyFromBase58(pubkeyString)
identity := pubKey
2021-07-09 08:36:53 -07:00
_, err := client.GetBlockProductionWithOpts(
context.Background(),
&GetBlockProductionOpts{
Commitment: CommitmentMax,
Range: &SlotRangeRequest{
FirstSlot: firstSlot,
LastSlot: &lastSlot,
Identity: &identity,
2021-07-09 08:36:53 -07:00
},
},
)
require.NoError(t, err)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getBlockProduction",
"params": []interface{}{
map[string]interface{}{
"commitment": string(CommitmentMax),
"range": map[string]interface{}{
"firstSlot": float64(firstSlot),
"lastSlot": float64(lastSlot),
"identity": string(identity.String()),
2021-07-09 08:36:53 -07:00
},
},
},
},
server.RequestBody(t),
)
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetBlockCommitment(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `{"commitment":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,44854495719374,0,51599979318189,5070972605440,140323113958535,169550804919131,272061505737107,860587424880950,1374732609383053,2334359721325133,4664454087479672,10122947678661428,52107037802932750],"totalStake":73611541921665680}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
block := 33
2021-07-09 09:30:07 -07:00
2021-07-09 08:36:53 -07:00
out, err := client.GetBlockCommitment(
context.Background(),
2021-07-09 08:56:15 -07:00
uint64(block),
2021-07-09 08:36:53 -07:00
)
require.NoError(t, err)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getBlockCommitment",
"params": []interface{}{
float64(block),
},
},
server.RequestBody(t),
)
expected := map[string]interface{}{"commitment": []interface{}{
stdjson.Number("0"),
stdjson.Number("0"),
stdjson.Number("0"),
stdjson.Number("0"),
stdjson.Number("0"),
stdjson.Number("0"),
stdjson.Number("0"),
stdjson.Number("0"),
stdjson.Number("0"),
stdjson.Number("0"),
stdjson.Number("0"),
stdjson.Number("0"),
stdjson.Number("0"),
stdjson.Number("0"),
stdjson.Number("0"),
stdjson.Number("0"),
stdjson.Number("0"),
stdjson.Number("0"),
stdjson.Number("0"),
stdjson.Number("44854495719374"),
stdjson.Number("0"),
stdjson.Number("51599979318189"),
stdjson.Number("5070972605440"),
stdjson.Number("140323113958535"),
stdjson.Number("169550804919131"),
stdjson.Number("272061505737107"),
stdjson.Number("860587424880950"),
stdjson.Number("1374732609383053"),
stdjson.Number("2334359721325133"),
stdjson.Number("4664454087479672"),
stdjson.Number("10122947678661428"),
stdjson.Number("52107037802932750"),
},
"totalStake": stdjson.Number("73611541921665680"),
2021-07-09 08:36:53 -07:00
}
2021-07-07 08:52:58 -07:00
got := mustJSONToInterfaceWithUseNumber(mustAnyToJSON(out))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetBlocks(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `[83993598,83993599,83993600]`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
startSlot := 1
2021-07-09 08:56:15 -07:00
endSlot := uint64(33)
2021-07-09 08:36:53 -07:00
out, err := client.GetBlocks(
context.Background(),
2021-07-09 08:56:15 -07:00
uint64(startSlot),
2021-07-09 08:36:53 -07:00
&endSlot,
CommitmentMax,
)
require.NoError(t, err)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getBlocks",
"params": []interface{}{
float64(startSlot),
float64(endSlot),
map[string]interface{}{
"commitment": string(CommitmentMax),
},
},
},
server.RequestBody(t),
)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
expected := mustJSONToInterface([]byte(responseBody))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
got := mustJSONToInterface(mustAnyToJSON(out))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetBlocksWithLimit(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `[83993712,83993713]`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
startSlot := 1
2021-07-09 08:56:15 -07:00
limit := uint64(10)
2021-07-09 08:36:53 -07:00
out, err := client.GetBlocksWithLimit(
context.Background(),
2021-07-09 08:56:15 -07:00
uint64(startSlot),
2021-07-09 08:36:53 -07:00
limit,
CommitmentMax,
)
require.NoError(t, err)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getBlocksWithLimit",
"params": []interface{}{
float64(startSlot),
float64(limit),
map[string]interface{}{
"commitment": string(CommitmentMax),
},
},
},
server.RequestBody(t),
)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
expected := mustJSONToInterface([]byte(responseBody))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
got := mustJSONToInterface(mustAnyToJSON(out))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetBlockTime(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `1625230849`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
block := 55
out, err := client.GetBlockTime(
context.Background(),
2021-07-09 08:56:15 -07:00
uint64(block),
2021-07-09 08:36:53 -07:00
)
require.NoError(t, err)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getBlockTime",
"params": []interface{}{
float64(block),
},
},
server.RequestBody(t),
)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
expected := mustJSONToInterface([]byte(responseBody))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
got := mustJSONToInterface(mustAnyToJSON(out))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetClusterNodes(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `[{"featureSet":743297851,"gossip":"162.55.111.250:8001","pubkey":"DMeohMfD3JzmYZA34jL9iiTXp5N7tpAR3rAoXMygdH3U","rpc":null,"shredVersion":18122,"tpu":"162.55.111.250:8004","version":"1.7.3"},{"featureSet":743297851,"gossip":"136.243.131.82:8000","pubkey":"59TSbYfnbb4zx4xf54ApjE8fJRhwzTiSjh9vdHfgyg1U","rpc":"136.243.131.82:8899","shredVersion":18122,"tpu":"136.243.131.82:8003","version":"1.7.3"},{"featureSet":743297851,"gossip":"135.181.114.15:8001","pubkey":"7vu7Q2d4uu9V4xnySHXieeyWvoNh37321kqTd2ATuoj6","rpc":null,"shredVersion":18122,"tpu":null,"version":"1.7.3"}]`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
out, err := client.GetClusterNodes(
context.Background(),
)
require.NoError(t, err)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getClusterNodes",
},
server.RequestBody(t),
)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
expected := mustJSONToInterface([]byte(responseBody))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
got := mustJSONToInterface(mustAnyToJSON(out))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetEpochInfo(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `{"absoluteSlot":83994151,"blockHeight":69218302,"epoch":207,"slotIndex":93895,"slotsInEpoch":432000,"transactionCount":27287000257}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
out, err := client.GetEpochInfo(
context.Background(),
CommitmentMax,
)
require.NoError(t, err)
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getEpochInfo",
"params": []interface{}{
map[string]interface{}{
"commitment": string(CommitmentMax),
},
},
},
server.RequestBody(t),
)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
expected := map[string]interface{}{
"absoluteSlot": 8.3994151e+07,
"blockHeight": 6.9218302e+07,
"epoch": 207.0,
"slotIndex": 93895.0,
"slotsInEpoch": 432000.0,
"transactionCount": 27287000257.0,
}
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
got := mustJSONToInterface(mustAnyToJSON(out))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetEpochSchedule(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `{"firstNormalEpoch":14,"firstNormalSlot":524256,"leaderScheduleSlotOffset":432000,"slotsPerEpoch":432000,"warmup":true}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
out, err := client.GetEpochSchedule(
context.Background(),
)
require.NoError(t, err)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getEpochSchedule",
},
server.RequestBody(t),
)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
expected := mustJSONToInterface([]byte(responseBody))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
got := mustJSONToInterface(mustAnyToJSON(out))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t, expected, got, "both deserialized values must be equal")
}
2021-07-07 08:52:58 -07:00
2021-07-09 09:30:07 -07:00
func TestClient_GetFeeCalculatorForBlockhash(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `{"context":{"slot":83994405},"value":{"feeCalculator":{"lamportsPerSignature":5000}}}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
out, err := client.GetFeeCalculatorForBlockhash(
context.Background(),
solana.Hash{},
CommitmentMax,
)
require.NoError(t, err)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getFeeCalculatorForBlockhash",
"params": []interface{}{
solana.Hash{}.String(),
map[string]interface{}{
"commitment": string(CommitmentMax),
},
},
},
server.RequestBody(t),
)
expected := mustJSONToInterface([]byte(responseBody))
got := mustJSONToInterface(mustAnyToJSON(out))
assert.Equal(t, expected, got, "both deserialized values must be equal")
}
2021-07-09 09:30:07 -07:00
func TestClient_GetFeeRateGovernor(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `{"context":{"slot":83994521},"value":{"feeRateGovernor":{"burnPercent":50,"maxLamportsPerSignature":100000,"minLamportsPerSignature":5000,"targetLamportsPerSignature":10000,"targetSignaturesPerSlot":20000}}}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
out, err := client.GetFeeRateGovernor(
context.Background(),
)
require.NoError(t, err)
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getFeeRateGovernor",
},
server.RequestBody(t),
)
expected := mustJSONToInterface([]byte(responseBody))
got := mustJSONToInterface(mustAnyToJSON(out))
assert.Equal(t, expected, got, "both deserialized values must be equal")
}
2021-07-09 09:30:07 -07:00
func TestClient_GetFees(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `{"context":{"slot":83994536},"value":{"blockhash":"HrPVENs6RtqRAxu14o63ZCkhCQR3vsNur1HU7K3GqKxb","feeCalculator":{"lamportsPerSignature":5000},"lastValidBlockHeight":69218886,"lastValidSlot":83994836}}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
out, err := client.GetFees(
context.Background(),
CommitmentMax,
)
require.NoError(t, err)
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getFees",
"params": []interface{}{
map[string]interface{}{
"commitment": string(CommitmentMax),
},
},
},
server.RequestBody(t),
)
expected := mustJSONToInterface([]byte(responseBody))
got := mustJSONToInterface(mustAnyToJSON(out))
assert.Equal(t, expected, got, "both deserialized values must be equal")
}
2021-07-09 09:30:07 -07:00
func TestClient_GetFirstAvailableBlock(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `39368303`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
out, err := client.GetFirstAvailableBlock(
context.Background(),
)
require.NoError(t, err)
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getFirstAvailableBlock",
},
server.RequestBody(t),
)
expected := mustJSONToInterface([]byte(responseBody))
got := mustJSONToInterface(mustAnyToJSON(out))
assert.Equal(t, expected, got, "both deserialized values must be equal")
}
2021-07-09 09:30:07 -07:00
func TestClient_GetGenesisHash(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `"4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY"`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
out, err := client.GetGenesisHash(
context.Background(),
)
require.NoError(t, err)
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getGenesisHash",
},
server.RequestBody(t),
)
expected := mustJSONToInterface([]byte(responseBody))
got := mustJSONToInterface(mustAnyToJSON(out))
assert.Equal(t, expected, got, "both deserialized values must be equal")
}
2021-07-09 09:30:07 -07:00
func TestClient_GetHealth(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `"ok"`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
out, err := client.GetHealth(
context.Background(),
)
require.NoError(t, err)
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getHealth",
},
server.RequestBody(t),
)
expected := mustJSONToInterface([]byte(responseBody))
got := mustJSONToInterface(mustAnyToJSON(out))
assert.Equal(t, expected, got, "both deserialized values must be equal")
}
2021-07-09 09:30:07 -07:00
func TestClient_GetIdentity(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `{"identity":"DMeohMfD3JzmYZA34jL9iiTXp5N7tpAR3rAoXMygdH3U"}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
out, err := client.GetIdentity(
context.Background(),
)
require.NoError(t, err)
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getIdentity",
},
server.RequestBody(t),
)
expected := mustJSONToInterface([]byte(responseBody))
got := mustJSONToInterface(mustAnyToJSON(out))
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetInflationGovernor(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `{"foundation":0,"foundationTerm":0,"initial":0.15,"taper":0.15,"terminal":0.015}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
out, err := client.GetInflationGovernor(
context.Background(),
CommitmentMax,
)
require.NoError(t, err)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getInflationGovernor",
"params": []interface{}{
map[string]interface{}{
"commitment": string(CommitmentMax),
},
},
},
server.RequestBody(t),
)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
expected := mustJSONToInterface([]byte(responseBody))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
got := mustJSONToInterface(mustAnyToJSON(out))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetInflationRate(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `{"epoch":207,"foundation":0,"total":0.1403151524615605,"validator":0.1403151524615605}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
out, err := client.GetInflationRate(
context.Background(),
)
require.NoError(t, err)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getInflationRate",
},
server.RequestBody(t),
)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
expected := mustJSONToInterface([]byte(responseBody))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
got := mustJSONToInterface(mustAnyToJSON(out))
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetInflationReward(t *testing.T) {
2021-07-21 09:27:07 -07:00
// TODO: add test with real value
2021-07-09 08:36:53 -07:00
responseBody := `[null]`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
pubkeyString := "7xLk17EQQ5KLDLDe44wCmupJKJjTGd8hs3eSVVhCx932"
pubKey := solana.MustPublicKeyFromBase58(pubkeyString)
keys := []solana.PublicKey{
pubKey,
2021-07-07 08:52:58 -07:00
}
2021-07-09 08:56:15 -07:00
epoch := uint64(56)
2021-07-09 08:36:53 -07:00
opts := GetInflationRewardOpts{
Commitment: CommitmentMax,
Epoch: &epoch,
}
2021-07-09 09:30:07 -07:00
2021-07-09 08:36:53 -07:00
out, err := client.GetInflationReward(
context.Background(),
keys,
&opts,
)
require.NoError(t, err)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getInflationReward",
"params": []interface{}{
[]interface{}{
pubkeyString,
2021-07-07 08:52:58 -07:00
},
2021-07-09 08:36:53 -07:00
map[string]interface{}{
"commitment": string(CommitmentMax),
"epoch": float64(epoch),
2021-07-07 08:52:58 -07:00
},
2021-07-09 08:36:53 -07:00
},
},
server.RequestBody(t),
)
expected := mustJSONToInterface([]byte(responseBody))
got := mustJSONToInterface(mustAnyToJSON(out))
assert.Equal(t, expected, got, "both deserialized values must be equal")
}
2021-07-09 09:30:07 -07:00
func TestClient_GetLargestAccounts(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `{"context":{"slot":83995022},"value":[{"address":"4Rf9mGD7FeYknun5JczX5nGLTfQuS1GRjNVfkEMKE92b","lamports":398178060209179300},{"address":"KchK7WTjPzq9QL5aCwnV1dLsT8rFjruS1Zfzamxus9G","lamports":215100454508495000},{"address":"8oRw7qpj6XgLGXYCDuNoTMCqoJnDd6A8LTpNyqApSfkA","lamports":99999674507283220},{"address":"9oKrJ9iiEnCC7bewcRFbcdo4LKL2PhUEqcu8gH2eDbVM","lamports":97721650553633650},{"address":"3ANJb42D3pkVtntgT6VtW2cD3icGVyoHi2NGwtXYHQAs","lamports":91160815129021260},{"address":"K7DbiDcRngs4KY3KxSUcMFNEzXW7iQgi3zFzerXYYDZ","lamports":80000000000000000},{"address":"mvines9iiHiQTysrwkJjGf2gb9Ex9jXJX8ns3qwf2kN","lamports":53925298123552904},{"address":"71bhKKL89U3dNHzuZVZ7KarqV6XtHEgjXjvJTsguD11B","lamports":20949230980018784},{"address":"57DPUrAncC4BUY7KBqRMCQUt4eQeMaJWpmLQwsL35ojZ","lamports":18210921605995270},{"address":"hQBS6cu8RHkXcCzE6N8mQxhgrtbNy4kivoRjTMzF2cA","lamports":18191952118880490},{"address":"5vxoRv2P12q4K4cWPCJkvPjg6jYnuCYxzF3juJZJiwba","lamports":14225826149332328},{"address":"2tZoLFgcbeW8Howq8QMRnExvuwHFUeEnx9ZhHq2qX77E","lamports":10099331225079048},{"address":"5NH47Zk9NAzfbtqNpUtn8CQgNZeZE88aa2NRpfe7DyTD","lamports":10000060317056686},{"address":"4xxV5Svt3LPsDv81seuqKB4QXxwhdQiFXzbj9GNYXkEr","lamports":10000000000000000},{"address":"GoCxdowvFindZVAXP3QsKRP3rR2LZBNXWwp3FB1yZznF","lamports":9796480999955000},{"address":"7arfejY2YxX9QrmzHrhu3rG3HofjMqKtfBzQLf8s3Wop","lamports":5465066164230830},{"address":"5TkrtJfHoX85sti8xSVvfggVV9SDvhjYjiXe9PqMJVN9","lamports":5384143441736968},{"address":"123vij84ecQEKUvQ7gYMKxKwKF6PbYSzCzzURYA4xULY","lamports":4350560741967702},{"address":"7vYe2KRUL2sbqSqbCn4UCvn2taaTJWvo3HBsPjZcEogG","lamports":3983999997415000},{"address":"7aeNmoVKnbxUSZGukYz2Gyr3UazXpaxATNszKu8XMW1k","lamports":3324774979081580}]}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
filter := LargestAccountsFilterCirculating
out, err := client.GetLargestAccounts(
context.Background(),
CommitmentMax,
filter,
)
require.NoError(t, err)
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getLargestAccounts",
"params": []interface{}{
map[string]interface{}{
"commitment": string(CommitmentMax),
"filter": string(filter),
2021-07-07 08:52:58 -07:00
},
},
2021-07-09 08:36:53 -07:00
},
server.RequestBody(t),
)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
expected := &GetLargestAccountsResult{
RPCContext: RPCContext{
Context: Context{
Slot: 83995022,
},
},
Value: []LargestAccountsResult{
{
Address: solana.MustPublicKeyFromBase58("4Rf9mGD7FeYknun5JczX5nGLTfQuS1GRjNVfkEMKE92b"),
Lamports: 398178060209179300,
},
{
Address: solana.MustPublicKeyFromBase58("KchK7WTjPzq9QL5aCwnV1dLsT8rFjruS1Zfzamxus9G"),
Lamports: 215100454508495000,
},
{
Address: solana.MustPublicKeyFromBase58("8oRw7qpj6XgLGXYCDuNoTMCqoJnDd6A8LTpNyqApSfkA"),
Lamports: 99999674507283220,
},
{
Address: solana.MustPublicKeyFromBase58("9oKrJ9iiEnCC7bewcRFbcdo4LKL2PhUEqcu8gH2eDbVM"),
Lamports: 97721650553633650,
},
{
Address: solana.MustPublicKeyFromBase58("3ANJb42D3pkVtntgT6VtW2cD3icGVyoHi2NGwtXYHQAs"),
Lamports: 91160815129021260,
},
{
Address: solana.MustPublicKeyFromBase58("K7DbiDcRngs4KY3KxSUcMFNEzXW7iQgi3zFzerXYYDZ"),
Lamports: 80000000000000000,
},
{
Address: solana.MustPublicKeyFromBase58("mvines9iiHiQTysrwkJjGf2gb9Ex9jXJX8ns3qwf2kN"),
Lamports: 53925298123552904,
},
{
Address: solana.MustPublicKeyFromBase58("71bhKKL89U3dNHzuZVZ7KarqV6XtHEgjXjvJTsguD11B"),
Lamports: 20949230980018784,
},
{
Address: solana.MustPublicKeyFromBase58("57DPUrAncC4BUY7KBqRMCQUt4eQeMaJWpmLQwsL35ojZ"),
Lamports: 18210921605995270,
},
{
Address: solana.MustPublicKeyFromBase58("hQBS6cu8RHkXcCzE6N8mQxhgrtbNy4kivoRjTMzF2cA"),
Lamports: 18191952118880490,
},
{
Address: solana.MustPublicKeyFromBase58("5vxoRv2P12q4K4cWPCJkvPjg6jYnuCYxzF3juJZJiwba"),
Lamports: 14225826149332328,
},
{
Address: solana.MustPublicKeyFromBase58("2tZoLFgcbeW8Howq8QMRnExvuwHFUeEnx9ZhHq2qX77E"),
Lamports: 10099331225079048,
},
{
Address: solana.MustPublicKeyFromBase58("5NH47Zk9NAzfbtqNpUtn8CQgNZeZE88aa2NRpfe7DyTD"),
Lamports: 10000060317056686,
},
{
Address: solana.MustPublicKeyFromBase58("4xxV5Svt3LPsDv81seuqKB4QXxwhdQiFXzbj9GNYXkEr"),
Lamports: 10000000000000000,
},
{
Address: solana.MustPublicKeyFromBase58("GoCxdowvFindZVAXP3QsKRP3rR2LZBNXWwp3FB1yZznF"),
Lamports: 9796480999955000,
},
{
Address: solana.MustPublicKeyFromBase58("7arfejY2YxX9QrmzHrhu3rG3HofjMqKtfBzQLf8s3Wop"),
Lamports: 5465066164230830,
},
{
Address: solana.MustPublicKeyFromBase58("5TkrtJfHoX85sti8xSVvfggVV9SDvhjYjiXe9PqMJVN9"),
Lamports: 5384143441736968,
},
{
Address: solana.MustPublicKeyFromBase58("123vij84ecQEKUvQ7gYMKxKwKF6PbYSzCzzURYA4xULY"),
Lamports: 4350560741967702,
},
{
Address: solana.MustPublicKeyFromBase58("7vYe2KRUL2sbqSqbCn4UCvn2taaTJWvo3HBsPjZcEogG"),
Lamports: 3983999997415000,
},
{
Address: solana.MustPublicKeyFromBase58("7aeNmoVKnbxUSZGukYz2Gyr3UazXpaxATNszKu8XMW1k"),
Lamports: 3324774979081580,
},
},
2021-07-07 08:52:58 -07:00
}
2021-07-09 08:36:53 -07:00
assert.Equal(t, expected, out)
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetLeaderSchedule(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `{"DsaF77cCADh79q7HPfz5TrWPfEmD5Gw1c15zSm4eaFyt":[128,129,130,131,9480,9481,9482,9483,9752,9753,9754,9755,16272,16273,16274,16275,19860,19861,19862,19863,19932,19933,19934,19935,26616,26617,26618,26619,28856,28857,28858,28859,36556,36557,36558,36559,37500,37501,37502,37503,47220,47221,47222,47223,58436,58437,58438,58439,79524,79525,79526,79527,90452,90453,90454,90455,90952,90953,90954,90955,91900,91901,91902,91903,102772,102773,102774,102775,103568,103569,103570,103571,111164,111165,111166,111167,117068,117069,117070,117071,123116,123117,123118,123119,136224,136225,136226,136227,145072,145073,145074,145075,146124,146125,146126,146127,148824,148825,148826,148827,158400,158401,158402,158403,158792,158793,158794,158795,161988,161989,161990,161991,163548,163549,163550,163551,167528,167529,167530,167531,174584,174585,174586,174587,176388,176389,176390,176391,184700,184701,184702,184703,186132,186133,186134,186135,199876,199877,199878,199879,201568,201569,201570,201571,205376,205377,205378,205379,207452,207453,207454,207455,223384,223385,223386,223387,225772,225773,225774,225775,255776,255777,255778,255779,256640,256641,256642,256643,262364,262365,262366,262367,269128,269129,269130,269131,272920,272921,272922,272923,274180,274181,274182,274183,293660,293661,293662,293663,303004,303005,303006,303007,317092,317093,317094,317095,323184,323185,323186,323187,323252,323253,323254,323255,328216,328217,328218,328219,333508,333509,333510,333511,336908,336909,336910,336911,337036,337037,337038,337039,341392,341393,341394,341395,341848,341849,341850,341851,351972,351973,351974,351975,363532,363533,363534,363535,397416,397417,397418,397419,398756,398757,398758,398759,414788,414789,414790,414791,428144,428145,428146,428147,428432,428433,428434,428435,430140,430141,430142,430143]}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
2021-07-09 08:56:15 -07:00
epoch := uint64(333)
pubkeyString := "7xLk17EQQ5KLDLDe44wCmupJKJjTGd8hs3eSVVhCx932"
pubKey := solana.MustPublicKeyFromBase58(pubkeyString)
identity := pubKey
2021-07-09 08:36:53 -07:00
out, err := client.GetLeaderScheduleWithOpts(
context.Background(),
&GetLeaderScheduleOpts{
Epoch: &epoch,
Commitment: CommitmentMax,
Identity: &identity,
2021-07-09 08:36:53 -07:00
},
)
require.NoError(t, err)
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getLeaderSchedule",
"params": []interface{}{
float64(epoch),
map[string]interface{}{
"commitment": string(CommitmentMax),
"identity": string(identity.String()),
2021-07-09 08:36:53 -07:00
},
},
},
server.RequestBody(t),
)
expected := mustJSONToInterface([]byte(responseBody))
got := mustJSONToInterface(mustAnyToJSON(out))
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetMaxRetransmitSlot(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `83996101`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
out, err := client.GetMaxRetransmitSlot(
context.Background(),
)
require.NoError(t, err)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getMaxRetransmitSlot",
},
server.RequestBody(t),
)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
expected := mustJSONToInterface([]byte(responseBody))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
got := mustJSONToInterface(mustAnyToJSON(out))
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetMaxShredInsertSlot(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `83996150`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
out, err := client.GetMaxShredInsertSlot(
context.Background(),
)
require.NoError(t, err)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getMaxShredInsertSlot",
},
server.RequestBody(t),
)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
expected := mustJSONToInterface([]byte(responseBody))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
got := mustJSONToInterface(mustAnyToJSON(out))
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetMinimumBalanceForRentExemption(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `70490880`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
dataSize := uint64(1000)
2021-07-09 08:36:53 -07:00
out, err := client.GetMinimumBalanceForRentExemption(
context.Background(),
dataSize,
CommitmentMax,
)
require.NoError(t, err)
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getMinimumBalanceForRentExemption",
"params": []interface{}{
float64(dataSize),
map[string]interface{}{
"commitment": string(CommitmentMax),
},
},
},
server.RequestBody(t),
)
expected := mustJSONToInterface([]byte(responseBody))
got := mustJSONToInterface(mustAnyToJSON(out))
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetMultipleAccounts(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `{"context":{"slot":83996178},"value":[{"data":["","base64"],"executable":true,"lamports":19039980000,"owner":"11111111111111111111111111111111","rentEpoch":207}]}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
pubkeyString := "7xLk17EQQ5KLDLDe44wCmupJKJjTGd8hs3eSVVhCx932"
pubKey := solana.MustPublicKeyFromBase58(pubkeyString)
out, err := client.GetMultipleAccounts(
context.Background(),
pubKey,
)
require.NoError(t, err)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getMultipleAccounts",
"params": []interface{}{
[]interface{}{pubkeyString},
},
},
server.RequestBody(t),
)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
expected := &GetMultipleAccountsResult{
RPCContext: RPCContext{
Context: Context{
Slot: 83996178,
2021-07-07 08:52:58 -07:00
},
2021-07-09 08:36:53 -07:00
},
Value: []*Account{
{
Lamports: 19039980000,
Owner: solana.MustPublicKeyFromBase58("11111111111111111111111111111111"),
Data: &DataBytesOrJSON{
2021-07-12 07:00:27 -07:00
asDecodedBinary: solana.Data{
Content: []byte{},
Encoding: solana.EncodingBase64,
},
rawDataEncoding: solana.EncodingBase64,
},
2021-07-09 08:36:53 -07:00
Executable: true,
RentEpoch: 207,
2021-07-07 08:52:58 -07:00
},
2021-07-09 08:36:53 -07:00
},
2021-07-07 08:52:58 -07:00
}
2021-07-09 08:36:53 -07:00
assert.Equal(t, expected, out)
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetProgramAccounts(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `[{"account":{"data":["dGVzdA==","base64"],"executable":true,"lamports":2039280,"owner":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","rentEpoch":206},"pubkey":"7xLk17EQQ5KLDLDe44wCmupJKJjTGd8hs3eSVVhCx932"}]`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
pubkeyString := "7xLk17EQQ5KLDLDe44wCmupJKJjTGd8hs3eSVVhCx932"
pubKey := solana.MustPublicKeyFromBase58(pubkeyString)
2021-07-09 08:56:15 -07:00
offset := uint64(13)
length := uint64(30)
2021-07-09 08:36:53 -07:00
opts := GetProgramAccountsOpts{
Commitment: CommitmentMax,
Encoding: solana.EncodingBase58,
2021-07-09 08:36:53 -07:00
DataSlice: &DataSlice{
Offset: &offset,
Length: &length,
},
Filters: []RPCFilter{
2021-07-07 08:52:58 -07:00
{
2021-07-09 08:36:53 -07:00
// TODO: make an actual example:
Memcmp: &RPCFilterMemcmp{
Offset: offset,
Bytes: pubKey[:],
2021-07-07 08:52:58 -07:00
},
},
2021-07-09 08:36:53 -07:00
},
}
out, err := client.GetProgramAccountsWithOpts(
context.Background(),
pubKey,
&opts,
)
require.NoError(t, err)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getProgramAccounts",
"params": []interface{}{
pubkeyString,
map[string]interface{}{
"encoding": string(solana.EncodingBase58),
2021-07-09 08:36:53 -07:00
"commitment": string(CommitmentMax),
"dataSlice": map[string]interface{}{
"offset": float64(offset),
"length": float64(length),
},
"filters": []interface{}{
map[string]interface{}{
"memcmp": map[string]interface{}{
"bytes": "7xLk17EQQ5KLDLDe44wCmupJKJjTGd8hs3eSVVhCx932",
"offset": float64(offset),
},
},
},
},
},
},
server.RequestBody(t),
)
expected := GetProgramAccountsResult{
{
Pubkey: solana.MustPublicKeyFromBase58("7xLk17EQQ5KLDLDe44wCmupJKJjTGd8hs3eSVVhCx932"),
Account: &Account{
Lamports: 2039280,
Owner: solana.MustPublicKeyFromBase58("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"),
Data: &DataBytesOrJSON{
2021-07-12 07:00:27 -07:00
asDecodedBinary: solana.Data{
Content: []byte{0x74, 0x65, 0x73, 0x74},
Encoding: solana.EncodingBase64,
},
rawDataEncoding: solana.EncodingBase64,
},
2021-07-09 08:36:53 -07:00
Executable: true,
RentEpoch: 206,
},
},
2021-07-07 08:52:58 -07:00
}
2021-07-09 08:36:53 -07:00
assert.Equal(t, expected, out)
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetRecentPerformanceSamples(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `[{"numSlots":84,"numTransactions":90402,"samplePeriodSecs":60,"slot":83998844}]`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-07 08:52:58 -07:00
2021-07-27 07:24:08 -07:00
limit := uint(1002)
2021-07-09 08:36:53 -07:00
out, err := client.GetRecentPerformanceSamples(
context.Background(),
&limit,
)
require.NoError(t, err)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getRecentPerformanceSamples",
"params": []interface{}{
float64(limit),
},
},
server.RequestBody(t),
)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
expected := mustJSONToInterface([]byte(responseBody))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
got := mustJSONToInterface(mustAnyToJSON(out))
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetSnapshotSlot(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `83998606`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
out, err := client.GetSnapshotSlot(
context.Background(),
)
require.NoError(t, err)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getSnapshotSlot",
},
server.RequestBody(t),
)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
expected := mustJSONToInterface([]byte(responseBody))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
got := mustJSONToInterface(mustAnyToJSON(out))
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetSignaturesForAddress(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `[{"blockTime":1625231961,"confirmationStatus":"finalized","err":null,"memo":null,"signature":"4Yig3yd33o2hyZV2qZBJkScDArwVmzurkxhBfKdqJeujTrdKHwrR3U8KR6LrhN5eWNTyugS5rkkYagVXCNnk7pks","slot":83994671},{"blockTime":1625231952,"confirmationStatus":"finalized","err":null,"memo":null,"signature":"3oQ7qqpJs5CtH1Xnnn8Ru5MtxkR3SZgshqzXwokuxFRArLihKdvCb9km6gbSiiUaNSHE7zVJqUVUZGfYuEaqWZPV","slot":83994656},{"blockTime":1625231913,"confirmationStatus":"finalized","err":null,"memo":null,"signature":"2UyvpGHknssUFJ77vZgUUzhRjMTTttKeMRKvJgmwaW12WLjmhTXJMF7WmVy5DBJtVFbuE25XJH247ma19JFrFb5K","slot":83994591},{"blockTime":1625225568,"confirmationStatus":"finalized","err":null,"memo":null,"signature":"2PCayD6PMA5BEkLC5SydWWWong5XPfNZMyH4LwMdRV2cCW7h28hkySmb8Y4RDzjE2YuMHwYMdxnXkvx9mbhGokFt","slot":83984016},{"blockTime":1625225568,"confirmationStatus":"finalized","err":null,"memo":null,"signature":"MqfYQzuJmdCYmwVLSGxvwSEG9kxeB4iudWbUanNrg4DcG8nH267iamAS6dxi4ckYnCPS3H8SANsy5Mo77YbF1ya","slot":83984016},{"blockTime":1625225508,"confirmationStatus":"finalized","err":null,"memo":null,"signature":"3RW4i3vVrymSSU32BQGkhDDwBmLnmr4CwFeWBjckddWyGJMLqhjWtY4kCCqbev32cm1WkTX3rvS8Y5mqSN3mWBQe","slot":83983916},{"blockTime":1625225370,"confirmationStatus":"finalized","err":null,"memo":null,"signature":"67kpcDECq6V6VZhwwRnn79XRNW3sS3VvM7UkFA5MmrzEY84wTU8hgSq1Q63UjSn9fprcBYZiNtWsUZepVzVsxGy","slot":83983688},{"blockTime":1625225370,"confirmationStatus":"finalized","err":null,"memo":null,"signature":"4n81J2KQjTvjPnS4rbirWJic8D6uoCzoHkjJzVFegApCgdomJ16uLBgGGydZKLsd443ht8iuGCJaDsVaz2pyPXk3","slot":83983686},{"blockTime":1625225365,"confirmationStatus":"finalized","err":null,"memo":null,"signature":"Hi4CKo8kYjXw6sQpT6GncYgbH69TKPTm4rHgF5Y8JaLuUvgcyicoBW2CQiaVdoXUVwXVmCLtgWTE38MkbrgdX1g","slot":83983680},{"blockTime":1625225361,"confirmationStatus":"finalized","err":null,"memo":null,"signature":"2oGCdmEv8qSrNPwjLy82s8E4jqejEsWUY9DAYFd9xH4pS7ZjwW8NpTScQZk86eMh4nMHs8YSvLiGB8iKYiLpiyPm","slot":83983671},{"blockTime":1625225352,"confirmationStatus":"finalized","err":null,"memo":null,"signature":"5oufLDV3eg1BaiUgMXScfqhtU1JszLYdoJHjmKSdJkWdmkRZnVzHXsPCSXji9haAyXxAmzm3De7peBFPVZoDNi3F","slot":83983658},{"blockTime":1625225344,"confirmationStatus":"finalized","err":null,"memo":null,"signature":"3zsq9V5asSpgwQiHTjBA6PUBBGh5Tzwuij2pemzmxCEqB9TiRmgpeP7fVYMdiuTNo9RWsjDYjUyAp4ETtPSrGQSR","slot":83983644},{"blockTime":1625225340,"confirmationStatus":"finalized","err":null,"memo":null,"signature":"4RQobEstLtiXMMB7XTeFy7HxAJgnivQZyLwkAg4kgDWd4996XVQb7M6JsbGxqzfohTbWz7EHxvJ9Eet8ip1SLDVu","slot":83983638},{"blockTime":1625225340,"confirmationStatus":"finalized","err":null,"memo":null,"signature":"5AMjJzE6qPG4cJ9Vck1z2g5tCwwQjZWGreEqK6CfNM9aiFUzCqtZ6sY6r5vfoFUQ9DkJrF9unroHbUdLrEoZ3b32","slot":83983636},{"blockTime":1625225337,"confirmationStatus":"finalized","err":null,"memo":null,"signature":"3ek35DoRGcWxjQksRmVg1EEv7ZHXraHtfJyCvE84jYYt9roDSQYMjaQEkajFPkJWarJMH87wcxQMHuo4H1D6cstm","slot":83983632},{"blockTime":1625225337,"confirmationStatus":"finalized","err":null,"memo":null,"signature":"3SUKt8qG1UwMaN2x5HS6hn1jbYkz9uy9qmR9efSb1W6mxAc2kBQPWGCHRPpaNvUHMPMW9M2bnv8mzpnXw3aL5dY3","slot":83983632},{"blockTime":1625225337,"confirmationStatus":"finalized","err":null,"memo":null,"signature":"GBDLedioeZo8JRQ3BDoQyZFCdCexbuMfH4cxD2A691f9kE9Y2BxpvSdiyudNPechNjbsTZteNstykM8titNAXVd","slot":83983632},{"blockTime":1625225334,"confirmationStatus":"finalized","err":null,"memo":null,"signature":"5YJKDebNExQ9BSq8aqwRJHDYdCcWz9dP8TsgZg3RMNXzUno6juKFhM4GRdrKDDnoQLrmyXwQ5T7RB9kbkb1hyHsv","slot":83983627},{"blockTime":1625225332,"confirmationStatus":"finalized","err":null,"memo":null,"signature":"3Zx3j7CB4xGN1QRfy3P6sKLTxAYuJRhHaDs2GqK1AeyWgBVAoffKWFfNoJxBbkrwqtbpiLZNr1PneaooRC8CmUC8","slot":83983625},{"blockTime":1625225329,"confirmationStatus":"finalized","err":null,"memo":null,"signature":"UqiJtFokGzU654Gxx3c4G9Q7hV7Kswz9UjNCT6Zcp6vcG3GUaHEm9wKfZiWSgGBEYKzHFeseEZSwaT2DQNynaP8","slot":83983619},{"blockTime":1625225328,"confirmationStatus":"finalized","err":null,"memo":null,"
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
pubkeyString := "7xLk17EQQ5KLDLDe44wCmupJKJjTGd8hs3eSVVhCx932"
pubKey := solana.MustPublicKeyFromBase58(pubkeyString)
limit := 10
before := solana.MustSignatureFromBase58("qN7RF6YSJT5QpVuhPNzjL8zNZ111NKVpJtBD53cxJHinorVW6AYLVE7bYtJnh42RjFfUTSKLrHhDBaG7AtEkymr")
until := solana.MustSignatureFromBase58("zJTw3PHXJRqpmR2bqnTChcySGET1pZTCQZebCtJbxRp3966MHttJgCgA75jwrjHRPa7mqeuWYceqxqo2jgVAtZa")
opts := GetSignaturesForAddressOpts{
Limit: &limit,
Before: before,
Until: until,
Commitment: CommitmentMax,
2021-07-07 08:52:58 -07:00
}
2021-07-09 08:36:53 -07:00
out, err := client.GetSignaturesForAddressWithOpts(
context.Background(),
pubKey,
&opts,
)
require.NoError(t, err)
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getSignaturesForAddress",
"params": []interface{}{
pubkeyString,
map[string]interface{}{
"commitment": string(CommitmentMax),
"before": before.String(),
"until": until.String(),
"limit": float64(limit),
},
},
},
server.RequestBody(t),
)
expected := mustJSONToInterface([]byte(responseBody))
got := mustJSONToInterface(mustAnyToJSON(out))
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetSignatureStatuses(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `{"context":{"slot":83999323},"value":[{"confirmationStatus":"finalized","confirmations":null,"err":null,"slot":82233105,"status":{"Ok":null}},{"confirmationStatus":"finalized","confirmations":null,"err":null,"slot":82232349,"status":{"Ok":null}}]}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
sig1 := solana.MustSignatureFromBase58("APPAzLobMg62AW7tdot1s7qKjya4Htt7AqjvT4uMUje8FuFNKD6qnoSk3JvBrkBnBnUyknqXJUXpj9BXENSExSQ")
sig2 := solana.MustSignatureFromBase58("eue8eTRd4puKR2aqsW9AigzyBsF9Em4uVKWKEkMeYUuT9XevvrYwk6Ps5ApCHKEdYDYxPsmE8tb9Gik6jZM1xHT")
out, err := client.GetSignatureStatuses(
context.Background(),
true,
sig1,
sig2,
)
require.NoError(t, err)
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getSignatureStatuses",
"params": []interface{}{
[]interface{}{
sig1.String(),
sig2.String(),
},
map[string]interface{}{
"searchTransactionHistory": true,
},
},
},
server.RequestBody(t),
)
expected := mustJSONToInterface([]byte(responseBody))
got := mustJSONToInterface(mustAnyToJSON(out))
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetSlot(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `83999325`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
out, err := client.GetSlot(
context.Background(),
CommitmentMax,
)
require.NoError(t, err)
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getSlot",
"params": []interface{}{
map[string]interface{}{
"commitment": string(CommitmentMax),
},
},
},
server.RequestBody(t),
)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
expected := mustJSONToInterface([]byte(responseBody))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
got := mustJSONToInterface(mustAnyToJSON(out))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetSlotLeader(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `"Bdd4XhquueXBB7aZXVYUn1XBdJ18G7Wx3LUe6aKkmXEV"`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
out, err := client.GetSlotLeader(
context.Background(),
CommitmentMax,
)
require.NoError(t, err)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getSlotLeader",
"params": []interface{}{
map[string]interface{}{
"commitment": string(CommitmentMax),
},
},
},
server.RequestBody(t),
)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
expected := mustJSONToInterface([]byte(responseBody))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
got := mustJSONToInterface(mustAnyToJSON(out))
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetSlotLeaders(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `["GDoZFWJNuiQdP3DMupgBeGr6mQJYCcWuUvcrnr7xhSqj","J1mnigj2PmzRCuLvjqBX3h6Lb5b6PoPt2Cvqu8g2wNG3","J1mnigj2PmzRCuLvjqBX3h6Lb5b6PoPt2Cvqu8g2wNG3","J1mnigj2PmzRCuLvjqBX3h6Lb5b6PoPt2Cvqu8g2wNG3","J1mnigj2PmzRCuLvjqBX3h6Lb5b6PoPt2Cvqu8g2wNG3","FcWgrc99RAix3y9th526GnzN23MQSkFmyWaeo9xJ6Jfo","FcWgrc99RAix3y9th526GnzN23MQSkFmyWaeo9xJ6Jfo","FcWgrc99RAix3y9th526GnzN23MQSkFmyWaeo9xJ6Jfo","FcWgrc99RAix3y9th526GnzN23MQSkFmyWaeo9xJ6Jfo","E9bcuniYQhMscfMjE8zaAXQ47TH56gsQoKuzvqXHxnAY"]`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
2021-07-09 08:56:15 -07:00
start := uint64(83220831)
limit := uint64(10)
2021-07-09 08:36:53 -07:00
out, err := client.GetSlotLeaders(
context.Background(),
start,
limit,
)
require.NoError(t, err)
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getSlotLeaders",
"params": []interface{}{
float64(start),
float64(limit),
},
},
server.RequestBody(t),
)
expected := mustJSONToInterface([]byte(responseBody))
got := mustJSONToInterface(mustAnyToJSON(out))
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetSupply(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `{"context":{"slot":83999524},"value":{"circulating":1370901328666198300,"nonCirculating":154690270000000,"nonCirculatingAccounts":["Br3aeVGapRb2xTq17RU2pYZCoJpWA7bq6TKBCcYtMSmt","AzHQ8Bia1grVVbcGyci7wzueSWkgvu7YZVZ4B9rkL5P6","GpYnVDgB7dzvwSgsjQFeHznjG6Kt1DLBFYrKxjGU1LuD","6ii8XC6KrfRcCR63cvJVhE73iCB1G44ZEaLW4WFYzy61","CoqCEzUA7KpCUxkV8ihGn9oru6imf6oVnjYKpa6jY5TC","CqqiPBWPqr3qN4gjiBQjWNT52eRFys5xdGdbQ69ywHfX","CND6ZjRTzaCFVdX7pSSWgjTfHZuhxqFDoUBqWBJguNoA","2qXZP8ZUCpvEd3VPow2zobf9S1db1vTBG3oqLWUANVNm","3s7wyR22skqVwwYRLiboJ9BYaEMsKkKqgetGZw7xtkgc","5TXdcD9Sq8UE2h6wSQj6HC7TYHZNqTdXPvmVZWFMsDzp","DQQGPtj7pphPHCLzzBuEyDDQByUcKGrsJdsH7SP3hAug","EAJJD6nDqtXcZ4DnQb19F9XEz8y8bRDHxbWbahatZNbL","DrKzW5koKSZp4mg4BdHLwr72MMXscd2kTiWgckCvvPXz","BhvLngiqqKeZ8rpxch2uGjeCiC88zzewoWPRuoxpp1aS","CVgyXrbEd1ctEuvq11QdpnCQVnPit8NLdhyqXQHLprM2","4bDVNTq2xJKK4WjKQ214DaYBh1NE5s2H1PvcoRuPdnSf","3ZrsTmNM6AkMcqFfv3ryfhQ2jMfqP64RQbqVyAaxqhrQ","E6HM7ny8AAY28Q8Za9RyrX7x1MyEdDkaXYFGUwoy4kM2","AVYpwVou2BhdLivAwLxKPALZQsY7aZNkNmGbP2fZw7RU","H3Ni7vG1CsmJZdTvxF7RkAf9UM5qk4RsohJsmPvtZNnu","Ga7HnuewhNo3htQxy6mgs2oM6WxuZpA9hJCnBhP75J8o","AG3m2bAibcY8raMt4oXEGqRHwX4FWKPPJVjZxn1LySDX","CsUqV42gVQLJwQsKyjWHqGkfHarxn9hcY4YeSjgaaeTd","5XdtyEDREHJXXW1CTtCsVjJRjBapAwK78ZquzvnNVRrV","3jnknRabs7G2V9dKhxd2KP85pNWXKXiedYnYxtySnQMs","8W58E8JVJjH1jCy5CeHJQgvwFXTyAVyesuXRZGbcSUGG","3bTGcGB9F98XxnrBNftmmm48JGfPgi5sYxDEKiCjQYk3","JCwT5Ygmq3VeBEbDjL8s8E82Ra2rP9bq45QfZE7Xyaq7","Es13uD2p64UVPFpEWfDtd6SERdoNR2XVgqBQBZcZSLqW","C7C8odR8oashR5Feyrq2tJKaXL18id1dSj2zbkDGL2C2","GdnSyH3YtwcxFvQrVVJMm1JhTS4QVX7MFsX56uJLUfiZ","CuatS6njAcfkFHnvai7zXCs7syA9bykXWsDCJEWfhjHG","6nN69B4uZuESZYxr9nrLDjmKRtjDZQXrehwkfQTKw62U","Hm9JW7of5i9dnrboS8pCUCSeoQUPh7JsP1rkbJnW7An4","GvpCiTgq9dmEeojCDBivoLoZqc4AkbUDACpqPMwYLWKh","GK2zqSsXLA2rwVZk347RYhh6jJpRsCA69FjLW93ZGi3B","F9MWFw8cnYVwsRq8Am1PGfFL3cQUZV37mbGoxZftzLjN","63DtkW7zuARcd185EmHAkfF44bDcC2SiTSEj2spLP3iA","GEWSkfWgHkpiLbeKaAnwvqnECGdRNf49at5nFccVey7c","DbF5Cmc4A8gSVaLCxurLoRZE93K164xF4Mjcqqe1xsHk","HKJgYGTTYYR2ZkfJKHbn58w676fKueQXmvbtpyvrSM3N","3euMq5VfpURASdXrHComyoovnfQDPgBKV8Wa4omQ3Qpd","6zw7em7uQdmMpuS9fGz8Nq9TLHa5YQhEKKwPjo5PwDK4","3o6xgkJ9sTmDeQWyfj3sxwon18fXJB9PV5LDc8sfgR4a","9LJrasfs648fi2uzmFqNVSrcCtz6xQaYC5E1BeyPHTJM","8DE8fqPfv1fp9DHyGyDFFaMjpopMgDeXspzoi9jpBJjC","FgnjRCqdtAhdLxNmhMN2zGdUjm364QQhPR2Z9C5d9wut","GHzNBbsKr43UeJ2wQpkGdmNqowZsv1xnLpq1bPNqAiHn","5q54XjQ7vDx4y6KphPeE97LUNiYGtP55spjvXAWPGBuf","4sxwau4mdqZ8zEJsfryXq4QFYnMJSCp3HWuZQod8WU5k","Hz9nydgN1k15wnwffKX7CSmZp4VFTnTwLXAEdomFGNXy","CWeRmXme7LmbaUWTZWFLt6FMnpzLCHaQLuR2TdgFn4Lq","8CUUMKYNGxdgYio5CLHRHyzMEhhVRMcqefgE6dLqnVRK","DE1bawNcRJB9rVm3buyMVfr8mBEoyyu73NBovf2oXJsJ","xQadXQiUTCCFhfHjvQx1hyJK6KVWr1w2fD6DT3cdwj7","7Np41oeYqPefeNQEHSv1UDhYrehxin3NStELsSKCT4K2","BuCEvc9ze8UoAQwwsQLy8d447C8sA4zeVtVpc6m5wQeS","CUageMFi49kzoDqtdU8NvQ4Bq3sbtJygjKDAXJ45nmAi","14FUT96s9swbmH7ZjpDvfEDywnAYy9zaNhv4xvezySGu","H1rt8KvXkNhQExTRfkY8r9wjZbZ8yCih6J4wQ5Fz9HGP","9huDUZfxoJ7wGMTffUE7vh1xePqef7gyrLJu9NApncqA","BUnRE27mYXN9p8H1Ay24GXhJC88q2CuwLoNU2v2CrW4W","H3EP5q7LL6XfqPmxLp8yBvDwgUHfvhvQxKxrq644K8d5","FwfaykN7ACnsEUDHANzGHqTGQZMcGnUSsahAHUqbdPrz","Fg12tB1tz8w6zJSQ4ZAGotWoCztdMJF9hqK8R11pakog","8UVjvYyoqP6sqcctTso3xpCdCfgTMiv3VRh7vraC2eJk","GNiz4Mq886bTNDT3pijGsu2gbw6it7sqrwncro45USeB","7W8FhaRLM2Hr9sZMXFwWbe4QqphkCnVvPDvjv7YbRuDj","CQDYc4ET2mbFhVpgj41gXahL6Exn5ZoPcGAzSHuYxwmE","2WWb1gRzuXDd5viZLQF7pNRR6Y7UiyeaPpaL35X6j3ve","3epceuFZLxwjCKhMdiigxconx8GDGH9HVDQZ8eqazaHA","8rT45mqpuDBR1vcnDc9kwP9DrZAXDR4ZeuKWw3u1gTGa","GhsotwFMH6XUrRLJCxcx62h7748N2Uq8mf87hUGkmPhg","Fgyh8EeYGZtbW8sS33YmNQnzx54WXPrJ5KWNPkCfWPot","3itU5ME8L6FDqtMiRoUiT1F7PwbkTtHBbW51YWD5jtjm","7cvkjYAkUYs4W8XcXsca7cBrEGFeSUjeZmKoNBvEwyri","FiWYY85b58zEEcPtxe3PuqzWPjqBJXqdwgZeqSBmT9Cn","8vqrX3H2BYLaXVintse3gorPEM4TgTwTFZNN1Fm9TdYs","FbGeZS8LiPCZiFpFwdUUeF2yxXtSsdfJoHTsVMvM8STh","3ahQgaKYVhsKq5ybdxzHDD6nAgHCZNkxrNDfGo21ykUT","EziVYi3Sv5kJWxmU77PnbrT8jmkVuqwdiFLLzZpLVEn7","Ep5Y58PaSyALPrdFxDVAdfKtVdP55vApvsWjb3jSmXsG","9hknftBZAQL4f48tWfk3bUEV5YSLcYYtDRqNmpNnhCWG","6yKHERk8rsbmJxvMpPuwPs1ct3hRiP7xaJF2tvnGU6nK"
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
out, err := client.GetSupply(
context.Background(),
CommitmentMax,
)
require.NoError(t, err)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getSupply",
"params": []interface{}{
map[string]interface{}{
"commitment": string(CommitmentMax),
},
},
},
server.RequestBody(t),
)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
expected := mustJSONToInterface([]byte(responseBody))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
got := mustJSONToInterface(mustAnyToJSON(out))
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetTokenLargestAccounts(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `{"context":{"slot":86069724},"value":[{"address":"7xLk17EQQ5KLDLDe44wCmupJKJjTGd8hs3eSVVhCx932","amount":"100","decimals":0,"uiAmount":100,"uiAmountString":"100"},{"address":"H7YZoNkQq96FX6gwy1ZqVgunXhSm7hpSPtK7orjxgQDb","amount":"0","decimals":0,"uiAmount":0,"uiAmountString":"0"},{"address":"2UjQFRQRjqorKVBCsaYYSiRnRnydXpiwgbaykwKJFCjr","amount":"0","decimals":0,"uiAmount":0,"uiAmountString":"0"},{"address":"DSBUsy1rPjjLnhagcStNmBBicuVXjSRr7bBddMU37LEp","amount":"0","decimals":0,"uiAmount":0,"uiAmountString":"0"},{"address":"BZ3a2XdfAeWHscJNEMuBbq34n2MMtLeeb4PSPcKEvCjh","amount":"0","decimals":0,"uiAmount":0,"uiAmountString":"0"}]}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
pubkeyString := "7xLk17EQQ5KLDLDe44wCmupJKJjTGd8hs3eSVVhCx932"
pubKey := solana.MustPublicKeyFromBase58(pubkeyString)
2021-07-09 09:30:07 -07:00
2021-07-09 08:36:53 -07:00
out, err := client.GetTokenLargestAccounts(
context.Background(),
pubKey,
CommitmentMax,
)
require.NoError(t, err)
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getTokenLargestAccounts",
"params": []interface{}{
pubkeyString,
map[string]interface{}{
"commitment": string(CommitmentMax),
},
},
},
server.RequestBody(t),
)
expected := mustJSONToInterface([]byte(responseBody))
got := mustJSONToInterface(mustAnyToJSON(out))
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetTokenSupply(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `{"context":{"slot":86069939},"value":{"amount":"100","decimals":0,"uiAmount":100,"uiAmountString":"100"}}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
pubkeyString := "7xLk17EQQ5KLDLDe44wCmupJKJjTGd8hs3eSVVhCx932"
pubKey := solana.MustPublicKeyFromBase58(pubkeyString)
2021-07-09 09:30:07 -07:00
2021-07-09 08:36:53 -07:00
out, err := client.GetTokenSupply(
context.Background(),
pubKey,
CommitmentMax,
)
require.NoError(t, err)
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getTokenSupply",
"params": []interface{}{
pubkeyString,
map[string]interface{}{
"commitment": string(CommitmentMax),
},
},
},
server.RequestBody(t),
)
expected := mustJSONToInterface([]byte(responseBody))
got := mustJSONToInterface(mustAnyToJSON(out))
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetTransaction(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `{"blockTime":1624821990,"meta":{"err":null,"fee":5000,"innerInstructions":[],"logMessages":["Program Vote111111111111111111111111111111111111111 invoke [1]","Program Vote111111111111111111111111111111111111111 success"],"postBalances":[199247210749,90459349430703,1,1,1],"postTokenBalances":[],"preBalances":[199247215749,90459349430703,1,1,1],"preTokenBalances":[],"rewards":[],"status":{"Ok":null}},"slot":83311386,"transaction":{"message":{"accountKeys":["2ZZkgKcBfp4tW8qCLj2yjxRYh9CuvEVJWb6e2KKS91Mj","53R9tmVrTQwJAgaUCWEA7SiVf7eWAbaQarZ159ixt2D9","SysvarS1otHashes111111111111111111111111111","SysvarC1ock11111111111111111111111111111111","Vote111111111111111111111111111111111111111"],"header":{"numReadonlySignedAccounts":0,"numReadonlyUnsignedAccounts":3,"numRequiredSignatures":1},"instructions":[{"accounts":[1,2,3,0],"data":"3yZe7d","programIdIndex":4}],"recentBlockhash":"6o9C27iJ5rPi7wEpvQu1cFbB1WnRudtsPnbY8GvFWrgR"},"signatures":["QPzWhnwHnCwk3nj1zVCcjz1VP7EcAKouPg9Joietje3GnQTVQ5XyWxyPC3zHby8K5ahSn9SbQupauDbVRvv5DuL"]}}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
tx := "KBVcTWwgEhVzwywtunhAXRKjXYYEdPcSCpuEkg484tiE3dFGzHDu9LKKH23uBMdfYt3JCPHeaVeDTZWecboyTrd"
2021-07-09 09:30:07 -07:00
2021-07-09 08:36:53 -07:00
opts := GetTransactionOpts{
Encoding: solana.EncodingJSON,
2021-07-09 08:36:53 -07:00
Commitment: CommitmentMax,
}
out, err := client.GetTransaction(
context.Background(),
solana.MustSignatureFromBase58(tx),
&opts,
)
require.NoError(t, err)
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getTransaction",
"params": []interface{}{
tx,
map[string]interface{}{
"encoding": string(solana.EncodingJSON),
2021-07-09 08:36:53 -07:00
"commitment": string(CommitmentMax),
2021-07-07 08:52:58 -07:00
},
},
2021-07-09 08:36:53 -07:00
},
server.RequestBody(t),
)
blockTimeSeconds := int64(1624821990)
2021-09-11 08:09:40 -07:00
blockTime := solana.UnixTimeSeconds(blockTimeSeconds)
2021-07-09 08:36:53 -07:00
expected := &GetTransactionResult{
Slot: 83311386,
BlockTime: &blockTime,
2021-07-27 07:24:08 -07:00
Transaction: &TransactionResultEnvelope{
asParsedTransaction: &ParsedTransaction{
Signatures: []solana.Signature{
solana.MustSignatureFromBase58("QPzWhnwHnCwk3nj1zVCcjz1VP7EcAKouPg9Joietje3GnQTVQ5XyWxyPC3zHby8K5ahSn9SbQupauDbVRvv5DuL"),
2021-07-07 08:52:58 -07:00
},
2021-07-27 07:24:08 -07:00
Message: Message{
AccountKeys: []solana.PublicKey{
solana.MustPublicKeyFromBase58("2ZZkgKcBfp4tW8qCLj2yjxRYh9CuvEVJWb6e2KKS91Mj"),
solana.MustPublicKeyFromBase58("53R9tmVrTQwJAgaUCWEA7SiVf7eWAbaQarZ159ixt2D9"),
solana.MustPublicKeyFromBase58("SysvarS1otHashes111111111111111111111111111"),
solana.MustPublicKeyFromBase58("SysvarC1ock11111111111111111111111111111111"),
solana.MustPublicKeyFromBase58("Vote111111111111111111111111111111111111111"),
},
RecentBlockhash: solana.MustHashFromBase58("6o9C27iJ5rPi7wEpvQu1cFbB1WnRudtsPnbY8GvFWrgR"),
Instructions: []ParsedInstruction{
{
Accounts: []int64{
2021-07-27 07:24:08 -07:00
1,
2,
3,
0,
},
Data: solana.Base58([]byte{0x74, 0x65, 0x73, 0x74}),
Parsed: nil,
Program: "",
ProgramIDIndex: 4,
2021-07-09 08:36:53 -07:00
},
},
2021-07-27 07:24:08 -07:00
Header: solana.MessageHeader{
NumRequiredSignatures: 1,
NumReadonlySignedAccounts: 0,
NumReadonlyUnsignedAccounts: 3,
},
2021-07-07 08:52:58 -07:00
},
},
2021-07-09 08:36:53 -07:00
},
Meta: &TransactionMeta{
Err: nil,
Fee: 5000,
PreBalances: []uint64{
2021-07-09 08:36:53 -07:00
199247215749,
90459349430703,
1,
1,
1,
},
PostBalances: []uint64{
2021-07-09 08:36:53 -07:00
199247210749,
90459349430703,
1,
1,
1,
},
InnerInstructions: []InnerInstruction{},
PreTokenBalances: []TokenBalance{},
PostTokenBalances: []TokenBalance{},
LogMessages: []string{
"Program Vote111111111111111111111111111111111111111 invoke [1]",
"Program Vote111111111111111111111111111111111111111 success",
},
Status: DeprecatedTransactionMetaStatus{
"Ok": nil,
},
Rewards: []BlockReward{},
},
2021-07-07 08:52:58 -07:00
}
2021-07-09 08:36:53 -07:00
assert.Equal(t, expected, out, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetTransactionCount(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `27293302873`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
out, err := client.GetTransactionCount(
context.Background(),
CommitmentMax,
)
require.NoError(t, err)
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getTransactionCount",
"params": []interface{}{
map[string]interface{}{
"commitment": string(CommitmentMax),
},
},
},
server.RequestBody(t),
)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
expected := mustJSONToInterface([]byte(responseBody))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
got := mustJSONToInterface(mustAnyToJSON(out))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetVersion(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `{"feature-set":743297851,"solana-core":"1.7.3"}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
out, err := client.GetVersion(
context.Background(),
)
require.NoError(t, err)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getVersion",
},
server.RequestBody(t),
)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
expected := mustJSONToInterface([]byte(responseBody))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
got := mustJSONToInterface(mustAnyToJSON(out))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_GetVoteAccounts(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `{"current":[],"delinquent":[{"activatedStake":4997717120,"commission":100,"epochCredits":[[127,1124979,892885],[128,1435333,1124979],[129,1603147,1435333],[131,1739262,1603147],[132,1895556,1739262]],"epochVoteAccount":true,"lastVote":51699331,"nodePubkey":"z3roU4WgvZvYkAEAYmUGK4LkPK6qFii6uzgMAswGYjb","rootSlot":51699288,"votePubkey":"vot33MHDqT6nSwubGzqtc6m16ChcUywxV7tNULF19Vu"}]}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
opts := &GetVoteAccountsOpts{
VotePubkey: solana.MustPublicKeyFromBase58("vot33MHDqT6nSwubGzqtc6m16ChcUywxV7tNULF19Vu").ToPointer(),
2021-07-09 08:36:53 -07:00
Commitment: CommitmentMax,
}
out, err := client.GetVoteAccounts(
context.Background(),
opts,
)
require.NoError(t, err)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getVoteAccounts",
"params": []interface{}{
map[string]interface{}{
"votePubkey": opts.VotePubkey.String(),
"commitment": string(CommitmentMax),
},
2021-07-07 08:52:58 -07:00
},
2021-07-09 08:36:53 -07:00
},
server.RequestBody(t),
)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
expected := mustJSONToInterface([]byte(responseBody))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
got := mustJSONToInterface(mustAnyToJSON(out))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_MinimumLedgerSlot(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `83686753`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
out, err := client.MinimumLedgerSlot(
context.Background(),
)
require.NoError(t, err)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "minimumLedgerSlot",
},
server.RequestBody(t),
)
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
expected := mustJSONToInterface([]byte(responseBody))
2021-07-07 08:52:58 -07:00
2021-07-09 08:36:53 -07:00
got := mustJSONToInterface(mustAnyToJSON(out))
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-07 08:52:58 -07:00
}
2021-07-09 09:30:07 -07:00
func TestClient_RequestAirdrop(t *testing.T) {
2021-07-09 08:36:53 -07:00
responseBody := `"3ZmWDnFJ5REjxtmtQRrczmVDraVZs7BpUFo3NRfnoQs6wvTJ2kTkw9YyGod291UHjK5Qg6w63Hqn7t6nrGMLWhga"`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
2021-07-09 08:36:53 -07:00
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
2021-07-09 08:36:53 -07:00
pubkeyString := "7xLk17EQQ5KLDLDe44wCmupJKJjTGd8hs3eSVVhCx932"
pubKey := solana.MustPublicKeyFromBase58(pubkeyString)
2021-07-09 09:30:07 -07:00
2021-07-09 08:56:15 -07:00
lamports := uint64(10000000)
2021-07-09 08:36:53 -07:00
out, err := client.RequestAirdrop(
context.Background(),
pubKey,
lamports,
CommitmentMax,
)
require.NoError(t, err)
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "requestAirdrop",
"params": []interface{}{
pubkeyString,
float64(lamports),
map[string]interface{}{
"commitment": string(CommitmentMax),
},
},
},
server.RequestBody(t),
)
expected := mustJSONToInterface([]byte(responseBody))
got := mustJSONToInterface(mustAnyToJSON(out))
assert.Equal(t, expected, got, "both deserialized values must be equal")
2020-11-25 11:25:32 -08:00
}
2021-07-09 09:45:20 -07:00
func TestClient_GetStakeActivation(t *testing.T) {
responseBody := `{"active":197717120,"inactive":0,"state":"active"}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
pubkeyString := "7xLk17EQQ5KLDLDe44wCmupJKJjTGd8hs3eSVVhCx932"
pubKey := solana.MustPublicKeyFromBase58(pubkeyString)
epoch := uint64(123)
out, err := client.GetStakeActivation(
context.Background(),
pubKey,
CommitmentMax,
&epoch,
)
require.NoError(t, err)
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getStakeActivation",
"params": []interface{}{
pubkeyString,
map[string]interface{}{
"commitment": string(CommitmentMax),
"epoch": float64(epoch),
},
},
},
server.RequestBody(t),
)
expected := mustJSONToInterface([]byte(responseBody))
got := mustJSONToInterface(mustAnyToJSON(out))
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-09 09:45:20 -07:00
}
func TestClient_GetTokenAccountBalance(t *testing.T) {
responseBody := `{"context":{"slot":1114},"value":{"amount":"9864","decimals":2,"uiAmount":98.64,"uiAmountString":"98.64"}}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
pubkeyString := "7xLk17EQQ5KLDLDe44wCmupJKJjTGd8hs3eSVVhCx932"
pubKey := solana.MustPublicKeyFromBase58(pubkeyString)
out, err := client.GetTokenAccountBalance(
context.Background(),
pubKey,
CommitmentMax,
)
require.NoError(t, err)
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getTokenAccountBalance",
"params": []interface{}{
pubkeyString,
map[string]interface{}{
"commitment": string(CommitmentMax),
},
},
},
server.RequestBody(t),
)
expected := mustJSONToInterface([]byte(responseBody))
got := mustJSONToInterface(mustAnyToJSON(out))
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-09 09:45:20 -07:00
}
func TestClient_GetTokenAccountsByDelegate(t *testing.T) {
responseBody := `{"context":{"slot":1114},"value":[{"data":{"program":"spl-token","parsed":{"accountType":"account","info":{"tokenAmount":{"amount":"1","decimals":1,"uiAmount":0.1,"uiAmountString":"0.1"},"delegate":"4Nd1mBQtrMJVYVfKf2PJy9NZUZdTAsp7D4xWLs4gDB4T","delegatedAmount":1,"isInitialized":true,"isNative":false,"mint":"3wyAj7Rt1TWVPZVteFJPLa26JmLvdb1CAKEFZm3NY75E","owner":"CnPoSPKXu7wJqxe59Fs72tkBeALovhsCxYeFwPCQH9TD"}}},"executable":false,"lamports":1726080,"owner":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","rentEpoch":4}]}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
pubkeyString := "7xLk17EQQ5KLDLDe44wCmupJKJjTGd8hs3eSVVhCx932"
pubKey := solana.MustPublicKeyFromBase58(pubkeyString)
programIDString := "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
programID := solana.MustPublicKeyFromBase58(programIDString)
out, err := client.GetTokenAccountsByDelegate(
context.Background(),
pubKey,
&GetTokenAccountsConfig{
ProgramId: &programID,
},
&GetTokenAccountsOpts{
Commitment: CommitmentMax,
Encoding: solana.EncodingJSONParsed,
},
)
require.NoError(t, err)
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getTokenAccountsByDelegate",
"params": []interface{}{
pubkeyString,
map[string]interface{}{
"programId": string(programIDString),
},
map[string]interface{}{
"commitment": string(CommitmentMax),
"encoding": string(solana.EncodingJSONParsed),
},
},
},
server.RequestBody(t),
)
expected := mustJSONToInterface([]byte(responseBody))
got := mustJSONToInterface(mustAnyToJSON(out))
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-09 09:45:20 -07:00
}
func TestClient_GetTokenAccountsByOwner(t *testing.T) {
responseBody := `{"context":{"slot":1114},"value":[{"data":{"program":"spl-token","parsed":{"accountType":"account","info":{"tokenAmount":{"amount":"1","decimals":1,"uiAmount":0.1,"uiAmountString":"0.1"},"delegate":null,"delegatedAmount":1,"isInitialized":true,"isNative":false,"mint":"3wyAj7Rt1TWVPZVteFJPLa26JmLvdb1CAKEFZm3NY75E","owner":"4Qkev8aNZcqFNSRhQzwyLMFSsi94jHqE8WNVTJzTP99F"}}},"executable":false,"lamports":1726080,"owner":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","rentEpoch":4}]}`
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
defer closer()
2021-07-20 12:29:06 -07:00
client := New(server.URL)
pubkeyString := "7xLk17EQQ5KLDLDe44wCmupJKJjTGd8hs3eSVVhCx932"
pubKey := solana.MustPublicKeyFromBase58(pubkeyString)
programIDString := "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
programID := solana.MustPublicKeyFromBase58(programIDString)
out, err := client.GetTokenAccountsByOwner(
context.Background(),
pubKey,
&GetTokenAccountsConfig{
ProgramId: &programID,
},
&GetTokenAccountsOpts{
Commitment: CommitmentMax,
Encoding: solana.EncodingJSONParsed,
},
)
require.NoError(t, err)
assert.Equal(t,
map[string]interface{}{
"id": float64(0),
"jsonrpc": "2.0",
"method": "getTokenAccountsByOwner",
"params": []interface{}{
pubkeyString,
map[string]interface{}{
"programId": string(programIDString),
},
map[string]interface{}{
"commitment": string(CommitmentMax),
"encoding": string(solana.EncodingJSONParsed),
},
},
},
server.RequestBody(t),
)
expected := mustJSONToInterface([]byte(responseBody))
got := mustJSONToInterface(mustAnyToJSON(out))
assert.Equal(t, expected, got, "both deserialized values must be equal")
2021-07-09 09:45:20 -07:00
}
func TestClient_SendTransaction(t *testing.T) {
// TODO
}
func TestClient_SimulateTransaction(t *testing.T) {
// TODO
}