-
Notifications
You must be signed in to change notification settings - Fork 732
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 (#3747)
* Node/CCQ: Solana min context slot support * Code review rework * Add port number to solana test URL
- Loading branch information
1 parent
5f54773
commit 10b83f7
Showing
5 changed files
with
326 additions
and
13 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,103 @@ | ||
package solana | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/certusone/wormhole/node/pkg/query" | ||
"github.com/gagliardetto/solana-go/rpc/jsonrpc" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRetrySlopIsValid(t *testing.T) { | ||
assert.Less(t, CCQ_RETRY_SLOP, query.RetryInterval) | ||
} | ||
|
||
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.