-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Node/CCQ: Solana min context slot support
- Loading branch information
1 parent
0c15b07
commit 400e0b0
Showing
5 changed files
with
301 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package solana | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/gagliardetto/solana-go/rpc/jsonrpc" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCcqIsMinContextSlotErrorSuccess(t *testing.T) { | ||
myErr := &jsonrpc.RPCError{ | ||
Code: -32016, | ||
Message: "Minimum context slot has not been reached", | ||
Data: map[string]interface{}{ | ||
"contextSlot": json.Number("13526"), | ||
}, | ||
} | ||
|
||
isMinContext, currentSlot, err := ccqIsMinContextSlotError(error(myErr)) | ||
require.NoError(t, err) | ||
require.True(t, isMinContext) | ||
assert.Equal(t, uint64(13526), currentSlot) | ||
} | ||
|
||
func TestCcqIsMinContextSlotErrorSomeOtherError(t *testing.T) { | ||
myErr := fmt.Errorf("Some other error") | ||
isMinContext, _, err := ccqIsMinContextSlotError(error(myErr)) | ||
require.NoError(t, err) | ||
require.False(t, isMinContext) | ||
} | ||
|
||
func TestCcqIsMinContextSlotErrorSomeOtherRPCError(t *testing.T) { | ||
myErr := &jsonrpc.RPCError{ | ||
Code: -32000, | ||
Message: "Some other RPC error", | ||
Data: map[string]interface{}{ | ||
"contextSlot": json.Number("13526"), | ||
}, | ||
} | ||
|
||
isMinContext, _, err := ccqIsMinContextSlotError(error(myErr)) | ||
require.NoError(t, err) | ||
require.False(t, isMinContext) | ||
} | ||
|
||
func TestCcqIsMinContextSlotErrorNoData(t *testing.T) { | ||
myErr := &jsonrpc.RPCError{ | ||
Code: -32016, | ||
Message: "Minimum context slot has not been reached", | ||
} | ||
|
||
_, _, err := ccqIsMinContextSlotError(error(myErr)) | ||
assert.EqualError(t, err, `failed to extract data from min context slot error`) | ||
} | ||
|
||
func TestCcqIsMinContextSlotErrorContextSlotMissing(t *testing.T) { | ||
myErr := &jsonrpc.RPCError{ | ||
Code: -32016, | ||
Message: "Minimum context slot has not been reached", | ||
Data: map[string]interface{}{ | ||
"someOtherField": json.Number("13526"), | ||
}, | ||
} | ||
|
||
_, _, err := ccqIsMinContextSlotError(error(myErr)) | ||
assert.EqualError(t, err, `min context slot error does not contain "contextSlot"`) | ||
} | ||
|
||
func TestCcqIsMinContextSlotErrorContextSlotIsNotAJsonNumber(t *testing.T) { | ||
myErr := &jsonrpc.RPCError{ | ||
Code: -32016, | ||
Message: "Minimum context slot has not been reached", | ||
Data: map[string]interface{}{ | ||
"contextSlot": "13526", | ||
}, | ||
} | ||
|
||
_, _, err := ccqIsMinContextSlotError(error(myErr)) | ||
assert.EqualError(t, err, `min context slot error "contextSlot" is not json.Number`) | ||
} | ||
|
||
func TestCcqIsMinContextSlotErrorContextSlotIsNotUint64(t *testing.T) { | ||
myErr := &jsonrpc.RPCError{ | ||
Code: -32016, | ||
Message: "Minimum context slot has not been reached", | ||
Data: map[string]interface{}{ | ||
"contextSlot": json.Number("HelloWorld"), | ||
}, | ||
} | ||
|
||
_, _, err := ccqIsMinContextSlotError(error(myErr)) | ||
assert.True(t, strings.Contains(err.Error(), `min context slot error "contextSlot" is not uint64`)) | ||
} |
Oops, something went wrong.