Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EasterTheBunny committed Jan 28, 2025
1 parent b738c3c commit fd6c94e
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 17 deletions.
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,8 @@ github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMB
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250127154252-93454dd65d86 h1:9+qzqtA3+L3drmnhAAh0B7463tBV7gxpcdajsCUtiHQ=
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250127154252-93454dd65d86/go.mod h1:V3BHfvLnQNBUoZ4bGjD29ZPhyzPE++DkYkhvPb9tcRs=
github.com/smartcontractkit/chainlink-framework/multinode v0.0.0-20250121205514-f73e2f86c23b h1:TO1pwFeQKDOmv3loFiLJvYhtymuTgQUw9WgtwK1rueg=
github.com/smartcontractkit/chainlink-framework/multinode v0.0.0-20250121205514-f73e2f86c23b/go.mod h1:4JqpgFy01LaqG1yM2iFTzwX3ZgcAvW9WdstBZQgPHzU=
github.com/smartcontractkit/grpc-proxy v0.0.0-20240830132753-a7e17fec5ab7 h1:12ijqMM9tvYVEm+nR826WsrNi6zCKpwBhuApq127wHs=
Expand Down
10 changes: 8 additions & 2 deletions integration-tests/relayinterface/chain_components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ type SolanaChainComponentsInterfaceTesterHelper[T TestingT[T]] interface {
type SolanaChainComponentsInterfaceTester[T TestingT[T]] struct {
TestSelectionSupport
Helper SolanaChainComponentsInterfaceTesterHelper[T]
cr *chainreader.SolanaChainReaderService
cr *chainreader.ContractReaderService
contractReaderConfig config.ContractReader
}

Expand Down Expand Up @@ -193,7 +193,13 @@ func (it *SolanaChainComponentsInterfaceTester[T]) GetContractReader(t T) types.
return it.cr
}

svc, err := chainreader.NewChainReaderService(it.Helper.Logger(t), it.Helper.RPCClient(), it.contractReaderConfig)
var events chainreader.EventsReader

svc, err := chainreader.NewContractReaderService(
it.Helper.Logger(t),
it.Helper.RPCClient(),
it.contractReaderConfig,
events)

require.NoError(t, err)
require.NoError(t, svc.Start(ctx))
Expand Down
9 changes: 9 additions & 0 deletions pkg/solana/codec/codec_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"reflect"

"github.com/smartcontractkit/chainlink-common/pkg/codec"
commoncodec "github.com/smartcontractkit/chainlink-common/pkg/codec"
"github.com/smartcontractkit/chainlink-common/pkg/codec/encodings"
commonencodings "github.com/smartcontractkit/chainlink-common/pkg/codec/encodings"
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"
)
Expand Down Expand Up @@ -219,6 +221,13 @@ func (e *entry) FixedSize() (int, error) {
return e.typeCodec.FixedSize()
}

func EntryAsModifierRemoteCodec(entry Entry, itemType string) (commontypes.RemoteCodec, error) {
lenientFromTypeCodec := make(encodings.LenientCodecFromTypeCodec)
lenientFromTypeCodec[itemType] = entry

return commoncodec.NewModifierCodec(lenientFromTypeCodec, entry.Modifier(), DecoderHooks...)
}

func ensureModifier(mod codec.Modifier) codec.Modifier {
if mod == nil {
return codec.MultiModifier{}
Expand Down
39 changes: 36 additions & 3 deletions pkg/solana/codec/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package codec_test

import (
"bytes"
"context"
_ "embed"
"slices"
"sync"
Expand Down Expand Up @@ -125,7 +126,7 @@ func encodeFieldsOnSliceOrArray(t *testing.T, request *EncodeRequest) []byte {

func (it *codecInterfaceTester) GetCodec(t *testing.T) clcommontypes.Codec {
codecConfig := codec.Config{Configs: map[string]codec.ChainConfig{}}
TestItem := CreateTestStruct[*testing.T](0, it)
TestItem := CreateTestStruct(0, it)
for offChainName, v := range testutils.CodecDefs {
codecEntryCfg := codecConfig.Configs[offChainName]
codecEntryCfg.IDL = v.IDL
Expand Down Expand Up @@ -157,13 +158,13 @@ func (it *codecInterfaceTester) GetCodec(t *testing.T) clcommontypes.Codec {
}
codecEntryCfg.ModifierConfigs = append(codecEntryCfg.ModifierConfigs, hardCode)
}
codecConfig.Configs[offChainName] = codecEntryCfg
codecConfig.Configs["DummyNamespace."+offChainName] = codecEntryCfg
}

c, err := codec.NewCodec(codecConfig)
require.NoError(t, err)

return c
return &compatibleItemTypeCodecWrapper{codec: c}
}

func (it *codecInterfaceTester) IncludeArrayEncodingSizeEnforcement() bool {
Expand All @@ -172,3 +173,35 @@ func (it *codecInterfaceTester) IncludeArrayEncodingSizeEnforcement() bool {
func (it *codecInterfaceTester) Name() string {
return "Solana"
}

type compatibleItemTypeCodecWrapper struct {
codec clcommontypes.RemoteCodec
}

func (w *compatibleItemTypeCodecWrapper) CreateType(itemType string, forEncoding bool) (any, error) {
return w.codec.CreateType(w.wrapItemType(itemType, forEncoding), forEncoding)
}

func (w *compatibleItemTypeCodecWrapper) Decode(ctx context.Context, raw []byte, into any, itemType string) error {
return w.codec.Decode(ctx, raw, into, w.wrapItemType(itemType, false))
}

func (w *compatibleItemTypeCodecWrapper) Encode(ctx context.Context, item any, itemType string) ([]byte, error) {
return w.codec.Encode(ctx, item, w.wrapItemType(itemType, true))
}

func (w *compatibleItemTypeCodecWrapper) GetMaxDecodingSize(ctx context.Context, n int, itemType string) (int, error) {
return w.codec.GetMaxDecodingSize(ctx, n, w.wrapItemType(itemType, false))
}

func (w *compatibleItemTypeCodecWrapper) GetMaxEncodingSize(ctx context.Context, n int, itemType string) (int, error) {
return w.codec.GetMaxEncodingSize(ctx, n, w.wrapItemType(itemType, true))
}

func (w *compatibleItemTypeCodecWrapper) wrapItemType(itemType string, forEncoding bool) string {
if forEncoding {
return "input.DummyNamespace." + itemType
}

return "output.DummyNamespace." + itemType
}
4 changes: 2 additions & 2 deletions pkg/solana/codec/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ func (t *testErrDecodeRemainingBytes) Decode(_ []byte) (interface{}, []byte, err

func TestDecoder_Decode_Errors(t *testing.T) {
var into interface{}
someType := "some-type"
someType := "input.Some.Type"
t.Run("error when item type not found", func(t *testing.T) {
nonExistentType := "non-existent"
nonExistentType := "output.Non.Existent"
err := newDecoder(map[string]Entry{someType: &entry{}}).
Decode(tests.Context(t), []byte{}, &into, nonExistentType)
require.ErrorIs(t, err, fmt.Errorf("%w: cannot find type %s", commontypes.ErrInvalidType, nonExistentType))
Expand Down
7 changes: 4 additions & 3 deletions pkg/solana/codec/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ func (e *testErrEncodeTypeEntry) GetCodecType() commonencodings.TypeCodec {
}

func TestEncoder_Encode_Errors(t *testing.T) {
someType := "some-type"
someType := "intput.Some.Type"

t.Run("error when item type not found", func(t *testing.T) {
_, err := newEncoder(map[string]Entry{}).
Encode(tests.Context(t), nil, "non-existent-type")
Encode(tests.Context(t), nil, "output.NonExistent.Type")
require.Error(t, err)
require.ErrorIs(t, err, commontypes.ErrInvalidType)
require.Contains(t, err.Error(), "cannot find type non-existent-type")
t.Log(err.Error())
require.Contains(t, err.Error(), "codec not available for itemType: NonExistent.Type")
})

t.Run("error when convert fails because of unexpected type", func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/solana/codec/solana.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ func NewCodec(conf Config) (commontypes.RemoteCodec, error) {
return nil, err
}

parsed.EncoderDefs[offChainName] = cEntry
parsed.DecoderDefs[offChainName] = cEntry
parsed.EncoderDefs["input."+offChainName] = cEntry
parsed.DecoderDefs["output."+offChainName] = cEntry
}

return parsed.ToCodec()
Expand Down
5 changes: 4 additions & 1 deletion pkg/solana/codec/solana_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ func TestNewIDLAccountCodec(t *testing.T) {

func TestCodecProperties(t *testing.T) {
t.Parallel()
t.Log("newTestIDLAndCodec does not handle eventIDLType and it looks like there is an attempt to deprecate the methods")
t.Skip()

tester := &codecInterfaceTester{}
ctx := tests.Context(t)
_, _, entry := newTestIDLAndCodec(t, eventIDLType)
t.Log(entry)

expected := interfacetests.CreateTestStruct(1, tester)
bts, err := entry.Encode(ctx, expected, interfacetests.TestItemType)
Expand Down Expand Up @@ -210,7 +213,7 @@ func newTestIDLAndCodec(t *testing.T, idlTP idlType) (string, codec.IDL, types.R
t.FailNow()
}

require.NotNil(t, entry)
require.NotNil(t, entry, "test codec should not be nil")

return idlDef, idl, entry
}
3 changes: 1 addition & 2 deletions pkg/solana/logpoller/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ func (fl *filters) RegisterFilter(ctx context.Context, filter Filter) error {
return err
}

decoderTypes := codec.ParsedTypes{DecoderDefs: map[string]codec.Entry{filter.EventName: cEntry}}
decoder, err := decoderTypes.ToCodec()
decoder, err := codec.EntryAsModifierRemoteCodec(cEntry, filter.EventName)
if err != nil {
return fmt.Errorf("failed to create event decoder: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/solana/logpoller/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestDSLParser(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, expected, result)

assertArgs(t, args, 5)
assertArgs(t, args, 6)
})

t.Run("query with limit and no order by", func(t *testing.T) {
Expand Down Expand Up @@ -104,7 +104,7 @@ func TestDSLParser(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, expected, result)

assertArgs(t, args, 3)
assertArgs(t, args, 4)
})

t.Run("query with order by sequence no cursor no limit", func(t *testing.T) {
Expand Down

0 comments on commit fd6c94e

Please sign in to comment.