Skip to content

Commit

Permalink
test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
EasterTheBunny committed Jan 16, 2025
1 parent 4a27203 commit 743e40f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 32 deletions.
8 changes: 8 additions & 0 deletions pkg/solana/chainreader/bindings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-common/pkg/codec"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/query"
)

func TestBindings_CreateType(t *testing.T) {
Expand Down Expand Up @@ -48,6 +50,8 @@ type mockBinding struct {

func (_m *mockBinding) SetCodec(_ types.RemoteCodec) {}

func (_m *mockBinding) SetModifier(_ codec.Modifier) {}

func (_m *mockBinding) SetAddress(_ solana.PublicKey) {}

func (_m *mockBinding) GetAddress() solana.PublicKey {
Expand All @@ -63,3 +67,7 @@ func (_m *mockBinding) CreateType(b bool) (any, error) {
func (_m *mockBinding) Decode(_ context.Context, _ []byte, _ any) error {
return nil
}

func (_m *mockBinding) QueryKey(context.Context, query.KeyFilter, query.LimitAndSort, any) ([]types.Sequence, error) {
return nil, nil
}
23 changes: 12 additions & 11 deletions pkg/solana/chainreader/chain_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestSolanaChainReaderService_ServiceCtx(t *testing.T) {
t.Parallel()

ctx := tests.Context(t)
svc, err := chainreader.NewChainReaderService(logger.Test(t), new(mockedRPCClient), config.ContractReader{})
svc, err := chainreader.NewContractReaderService(logger.Test(t), new(mockedRPCClient), config.ContractReader{}, nil)

require.NoError(t, err)
require.NotNil(t, svc)
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestSolanaChainReaderService_GetLatestValue(t *testing.T) {
require.NoError(t, err)

client := new(mockedRPCClient)
svc, err := chainreader.NewChainReaderService(logger.Test(t), client, conf)
svc, err := chainreader.NewContractReaderService(logger.Test(t), client, conf, nil)

require.NoError(t, err)
require.NotNil(t, svc)
Expand Down Expand Up @@ -136,7 +136,7 @@ func TestSolanaChainReaderService_GetLatestValue(t *testing.T) {

client := new(mockedRPCClient)
expectedErr := fmt.Errorf("expected error")
svc, err := chainreader.NewChainReaderService(logger.Test(t), client, conf)
svc, err := chainreader.NewContractReaderService(logger.Test(t), client, conf, nil)

require.NoError(t, err)
require.NotNil(t, svc)
Expand Down Expand Up @@ -170,7 +170,7 @@ func TestSolanaChainReaderService_GetLatestValue(t *testing.T) {
_, conf := newTestConfAndCodec(t)

client := new(mockedRPCClient)
svc, err := chainreader.NewChainReaderService(logger.Test(t), client, conf)
svc, err := chainreader.NewContractReaderService(logger.Test(t), client, conf, nil)

require.NoError(t, err)
require.NotNil(t, svc)
Expand All @@ -191,7 +191,7 @@ func TestSolanaChainReaderService_GetLatestValue(t *testing.T) {
_, conf := newTestConfAndCodec(t)

client := new(mockedRPCClient)
svc, err := chainreader.NewChainReaderService(logger.Test(t), client, conf)
svc, err := chainreader.NewContractReaderService(logger.Test(t), client, conf, nil)

require.NoError(t, err)
require.NotNil(t, svc)
Expand All @@ -212,7 +212,7 @@ func TestSolanaChainReaderService_GetLatestValue(t *testing.T) {
_, conf := newTestConfAndCodec(t)

client := new(mockedRPCClient)
svc, err := chainreader.NewChainReaderService(logger.Test(t), client, conf)
svc, err := chainreader.NewContractReaderService(logger.Test(t), client, conf, nil)

require.NoError(t, err)
require.NotNil(t, svc)
Expand Down Expand Up @@ -382,9 +382,10 @@ func (_m *mockedRPCClient) SetForAddress(pk ag_solana.PublicKey, bts []byte, err

type chainReaderInterfaceTester struct {
TestSelectionSupport
conf config.ContractReader
address []string
reader *wrappedTestChainReader
conf config.ContractReader
address []string
reader *wrappedTestChainReader
eventSource chainreader.EventSourcer
}

func (r *chainReaderInterfaceTester) GetAccountBytes(i int) []byte {
Expand Down Expand Up @@ -465,7 +466,7 @@ func (r *chainReaderInterfaceTester) Setup(t *testing.T) {

func (r *chainReaderInterfaceTester) GetContractReader(t *testing.T) types.ContractReader {
client := new(mockedRPCClient)
svc, err := chainreader.NewChainReaderService(logger.Test(t), client, r.conf)
svc, err := chainreader.NewContractReaderService(logger.Test(t), client, r.conf, r.eventSource)
if err != nil {
t.Logf("chain reader service was not able to start: %s", err.Error())
t.FailNow()
Expand All @@ -491,7 +492,7 @@ type wrappedTestChainReader struct {
types.UnimplementedContractReader

test *testing.T
service *chainreader.SolanaChainReaderService
service *chainreader.ContractReaderService
client *mockedRPCClient
tester ChainComponentsInterfaceTester[*testing.T]
testStructQueue []*TestStruct
Expand Down
26 changes: 12 additions & 14 deletions pkg/solana/logpoller/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import (
)

const (
blockFieldName = "block_number"
chainIDFieldName = "chain_id"
timestampFieldName = "block_timestamp"
txHashFieldName = "tx_hash"
addressFieldName = "address"
eventSigFieldName = "event_sig"
defaultSort = "block_number ASC, log_index ASC"
blockFieldName = "block_number"
chainIDFieldName = "chain_id"
timestampFieldName = "block_timestamp"
txHashFieldName = "tx_hash"
addressFieldName = "address"
eventSubkeyFieldName = "event_subkey"
defaultSort = "block_number ASC, log_index ASC"
)

var (
Expand Down Expand Up @@ -134,13 +134,11 @@ func (v *pgDSLParser) VisitEventSubkeyFilter(p *eventSubkeyFilter) {
// TODO: the value type will be the off-chain field type that a raw IDL codec would decode into
// this value will need to be wrapped in a special type that will encode the value properly for
// direct comparison.
/*
v.expression = fmt.Sprintf(
"%s = :%s",
eventSigFieldName,
v.args.withIndexedField(eventSigFieldName, p.eventSig),
)
*/
v.expression = fmt.Sprintf(
"%s = :%s",
eventSubkeyFieldName,
v.args.withIndexedField(eventSubkeyFieldName, p.Subkey),
)
}

func (v *pgDSLParser) buildQuery(
Expand Down
23 changes: 16 additions & 7 deletions pkg/solana/logpoller/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,18 @@ func TestDSLParser(t *testing.T) {
parser := &pgDSLParser{}
expressions := []query.Expression{
NewAddressFilter(pk),
NewEventSigFilter([]byte("test")),
NewEventSubkeyFilter([]string{"test"}, []primitives.ValueComparator{
{Value: 42, Operator: primitives.Gte},
{Value: "test_value", Operator: primitives.Eq},
}),
query.Confidence(primitives.Unconfirmed),
}
limiter := query.NewLimitAndSort(query.CursorLimit(fmt.Sprintf("10-5-%s", txHash), query.CursorFollowing, 20))

result, args, err := parser.buildQuery(chainID, expressions, limiter)
expected := logsQuery(
" WHERE chain_id = :chain_id " +
"AND (address = :address_0 AND event_sig = :event_sig_0) " +
"AND (address = :address_0 AND event_subkey = :event_subkey_0) " +
"AND (block_number > :cursor_block_number OR (block_number = :cursor_block_number " +
"AND log_index > :cursor_log_index)) " +
"ORDER BY block_number ASC, log_index ASC, tx_hash ASC LIMIT 20")
Expand All @@ -82,14 +85,17 @@ func TestDSLParser(t *testing.T) {
parser := &pgDSLParser{}
expressions := []query.Expression{
NewAddressFilter(pk),
NewEventSigFilter([]byte("test")),
NewEventSubkeyFilter([]string{"test"}, []primitives.ValueComparator{
{Value: 42, Operator: primitives.Gte},
{Value: "test_value", Operator: primitives.Eq},
}),
}
limiter := query.NewLimitAndSort(query.CountLimit(20))

result, args, err := parser.buildQuery(chainID, expressions, limiter)
expected := logsQuery(
" WHERE chain_id = :chain_id " +
"AND (address = :address_0 AND event_sig = :event_sig_0) " +
"AND (address = :address_0 AND event_subkey = :event_subkey_0) " +
"ORDER BY " + defaultSort + " " +
"LIMIT 20")

Expand Down Expand Up @@ -237,9 +243,13 @@ func TestDSLParser(t *testing.T) {
t.Run("nested query deep", func(t *testing.T) {
t.Parallel()

sigFilter := NewEventSigFilter([]byte("test"))
parser := &pgDSLParser{}
sigFilter := NewEventSubkeyFilter([]string{"test"}, []primitives.ValueComparator{
{Value: 42, Operator: primitives.Gte},
{Value: "test_value", Operator: primitives.Eq},
})

limiter := query.LimitAndSort{}
expressions := []query.Expression{
{BoolExpression: query.BoolExpression{
Expressions: []query.Expression{
Expand All @@ -261,13 +271,12 @@ func TestDSLParser(t *testing.T) {
BoolOperator: query.AND,
}},
}
limiter := query.LimitAndSort{}

result, args, err := parser.buildQuery(chainID, expressions, limiter)
expected := logsQuery(
" WHERE chain_id = :chain_id " +
"AND (block_timestamp = :block_timestamp_0 " +
"AND (tx_hash = :tx_hash_0 OR event_sig = :event_sig_0)) " +
"AND (tx_hash = :tx_hash_0 OR event_subkey = :event_subkey_0)) " +
"ORDER BY " + defaultSort)

require.NoError(t, err)
Expand Down

0 comments on commit 743e40f

Please sign in to comment.