Skip to content

Commit c84bca0

Browse files
committed
fix(rpc): allow json encoding in GetBlockWithOpts
1 parent aec058e commit c84bca0

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

rpc/client_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,44 @@ func TestClient_GetBlockWithOpts(t *testing.T) {
470470
// - test also when requesting only signatures
471471
}
472472

473+
func TestClient_GetBlockWithOpts_EncodingJSON(t *testing.T) {
474+
responseBody := `{}`
475+
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))
476+
defer closer()
477+
478+
client := New(server.URL)
479+
480+
block := 42
481+
_, err := client.GetBlockWithOpts(
482+
context.Background(),
483+
uint64(block),
484+
&GetBlockOpts{
485+
Encoding: solana.EncodingJSON,
486+
},
487+
)
488+
require.NoError(t, err)
489+
490+
// the ID is random, so we can't assert it; let's check that it is set, and then remove it
491+
reqBody := server.RequestBody(t)
492+
assert.NotNil(t, reqBody["id"])
493+
reqBody["id"] = any(nil)
494+
495+
assert.Equal(t,
496+
map[string]any{
497+
"id": any(nil),
498+
"jsonrpc": "2.0",
499+
"method": "getBlock",
500+
"params": []any{
501+
float64(block),
502+
map[string]any{
503+
"encoding": string(solana.EncodingJSON),
504+
},
505+
},
506+
},
507+
reqBody,
508+
)
509+
}
510+
473511
func TestClient_GetBlockWithOpts_AccountsMode(t *testing.T) {
474512
responseBody := `{"blockHeight":69213636,"blockTime":1625227950,"blockhash":"5M77sHdwzH6rckuQwF8HL1w52n7hjrh4GVTFiF6T8QyB","parentSlot":83987983,"previousBlockhash":"Aq9jSXe1jRzfiaBcRFLe4wm7j499vWVEeFQrq5nnXfZN","rewards":[],"transactions":[{"meta":{"err":null,"fee":5000,"innerInstructions":[],"logMessages":[],"postBalances":[441866063495,40905918933763,1],"postTokenBalances":[],"preBalances":[441866068495,40905918933763,1],"preTokenBalances":[],"rewards":[],"status":{"Ok":null}},"transaction":{"signatures":["D8emaP3CaepSGigD3TCrev7j67yPLMi82qfzTb9iZYPxHcCmm6sQBKTU4bzAee4445zbnbWduVAZ87WfbWbXoAU"],"accountKeys":[{"pubkey":"EVd8FFVB54svYdZdG6hH4F4hTbqre5mpQ7XyF5rKUmes","signer":true,"writable":true,"source":"transaction"},{"pubkey":"72miaovmbPqccdbAA861r2uxwB5yL1sMjrgbCnc4JfVT","signer":false,"writable":true,"source":"transaction"},{"pubkey":"Vote111111111111111111111111111111111111111","signer":false,"writable":false,"source":"lookupTable"}]},"version":0}]}`
475513
server, closer := mockJSONRPC(t, stdjson.RawMessage(wrapIntoRPC(responseBody)))

rpc/getBlock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (cl *Client) GetBlockWithOpts(
105105
if !solana.IsAnyOfEncodingType(
106106
opts.Encoding,
107107
// Valid encodings:
108-
// solana.EncodingJSON, // TODO
108+
solana.EncodingJSON,
109109
solana.EncodingJSONParsed, // TODO
110110
solana.EncodingBase58,
111111
solana.EncodingBase64,

0 commit comments

Comments
 (0)