Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
EasterTheBunny committed Feb 4, 2025
1 parent 77f0055 commit 0752da2
Show file tree
Hide file tree
Showing 19 changed files with 217 additions and 168 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/prometheus/client_golang v1.20.5
github.com/smartcontractkit/chainlink-ccip v0.0.0-20250203132120-f0d42463e405
github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20250128162345-af4c8fd4481a
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250127125541-a8fa42cc0f36
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250203172907-aea9294a7d55
github.com/smartcontractkit/chainlink-framework/multinode v0.0.0-20250203183025-939526523893
github.com/smartcontractkit/libocr v0.0.0-20241223215956-e5b78d8e3919
github.com/stretchr/testify v1.10.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,8 @@ github.com/smartcontractkit/chainlink-ccip v0.0.0-20250203132120-f0d42463e405 h1
github.com/smartcontractkit/chainlink-ccip v0.0.0-20250203132120-f0d42463e405/go.mod h1:UEnHaxkUsfreeA7rR45LMmua1Uen95tOFUR8/AI9BAo=
github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20250128162345-af4c8fd4481a h1:1MrD2OiP/CRfyBSwTQE66R1+gLWBgWcU/SYl/+DmZ/Y=
github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20250128162345-af4c8fd4481a/go.mod h1:Bmwq4lNb5tE47sydN0TKetcLEGbgl+VxHEWp4S0LI60=
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250127125541-a8fa42cc0f36 h1:dytZPggag6auyzmbhpIDmkHu7KrflIBEhLLec4/xFIk=
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250127125541-a8fa42cc0f36/go.mod h1:Z2e1ynSJ4pg83b4Qldbmryc5lmnrI3ojOdg1FUloa68=
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250203172907-aea9294a7d55 h1:/POgmPxqFOLfFHy3WH0dnYBJ2AT+H2aRZ2XJ6Fda600=
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250203172907-aea9294a7d55/go.mod h1:Z2e1ynSJ4pg83b4Qldbmryc5lmnrI3ojOdg1FUloa68=
github.com/smartcontractkit/chainlink-framework/multinode v0.0.0-20250203183025-939526523893 h1:hQEEpKrWRqZ//SkA/m1G5puVHK1mYhZzturgX7VsPhk=
github.com/smartcontractkit/chainlink-framework/multinode v0.0.0-20250203183025-939526523893/go.mod h1:4JqpgFy01LaqG1yM2iFTzwX3ZgcAvW9WdstBZQgPHzU=
github.com/smartcontractkit/grpc-proxy v0.0.0-20240830132753-a7e17fec5ab7 h1:12ijqMM9tvYVEm+nR826WsrNi6zCKpwBhuApq127wHs=
Expand Down
10 changes: 5 additions & 5 deletions integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ require (
github.com/lib/pq v1.10.9
github.com/pelletier/go-toml/v2 v2.2.3
github.com/rs/zerolog v1.33.0
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250130202959-6f1f48342e36
github.com/smartcontractkit/chainlink-solana v1.1.2-0.20250203214419-38982a7fc48b
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250203172907-aea9294a7d55
github.com/smartcontractkit/chainlink-solana v1.1.2-0.20250203204555-c245a7640475
github.com/smartcontractkit/chainlink-testing-framework/lib v1.50.21
github.com/smartcontractkit/chainlink-testing-framework/seth v1.50.10
github.com/smartcontractkit/chainlink/deployment v0.0.0-20250203214543-d9da97d53b9b
github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20250203214543-d9da97d53b9b
github.com/smartcontractkit/chainlink/v2 v2.19.0-ccip1.5.16-alpha.0.0.20250203214543-d9da97d53b9b
github.com/smartcontractkit/chainlink/deployment v0.0.0-20250204104013-aa7b9062ca41
github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20250204104013-aa7b9062ca41
github.com/smartcontractkit/chainlink/v2 v2.19.0-ccip1.5.16-alpha.0.0.20250204104013-aa7b9062ca41
github.com/smartcontractkit/libocr v0.0.0-20241223215956-e5b78d8e3919
github.com/stretchr/testify v1.10.0
github.com/testcontainers/testcontainers-go v0.35.0
Expand Down
16 changes: 8 additions & 8 deletions integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1231,8 +1231,8 @@ github.com/smartcontractkit/chainlink-ccip v0.0.0-20250203132120-f0d42463e405 h1
github.com/smartcontractkit/chainlink-ccip v0.0.0-20250203132120-f0d42463e405/go.mod h1:UEnHaxkUsfreeA7rR45LMmua1Uen95tOFUR8/AI9BAo=
github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20250128162345-af4c8fd4481a h1:1MrD2OiP/CRfyBSwTQE66R1+gLWBgWcU/SYl/+DmZ/Y=
github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20250128162345-af4c8fd4481a/go.mod h1:Bmwq4lNb5tE47sydN0TKetcLEGbgl+VxHEWp4S0LI60=
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250130202959-6f1f48342e36 h1:bS51NFGHVjkCy7yu9L2Ss4sBsCW6jpa5GuhRAdWWxzM=
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250130202959-6f1f48342e36/go.mod h1:Z2e1ynSJ4pg83b4Qldbmryc5lmnrI3ojOdg1FUloa68=
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250203172907-aea9294a7d55 h1:/POgmPxqFOLfFHy3WH0dnYBJ2AT+H2aRZ2XJ6Fda600=
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250203172907-aea9294a7d55/go.mod h1:Z2e1ynSJ4pg83b4Qldbmryc5lmnrI3ojOdg1FUloa68=
github.com/smartcontractkit/chainlink-cosmos v0.5.2-0.20250130125138-3df261e09ddc h1:WZERXv2hTYRA0NpWg79ci/ZZSxucmvkty39iUOV8d7I=
github.com/smartcontractkit/chainlink-cosmos v0.5.2-0.20250130125138-3df261e09ddc/go.mod h1:2iGmU7fkVsy21Sw8D+OhtYekHLUlJKHzwePKcxIx3Ac=
github.com/smartcontractkit/chainlink-data-streams v0.1.1-0.20250128203428-08031923fbe5 h1:CvDfgWoLoYPapOumE/UZCplfCu5oNmy9BuH+6V6+fJ8=
Expand All @@ -1253,12 +1253,12 @@ github.com/smartcontractkit/chainlink-testing-framework/lib v1.50.21 h1:1UYLu0QA
github.com/smartcontractkit/chainlink-testing-framework/lib v1.50.21/go.mod h1:y6pVvAT/R+YGocAqoQIat+AEaZz2Jdmj/0uUBmwvLCU=
github.com/smartcontractkit/chainlink-testing-framework/seth v1.50.10 h1:Yf+n3T/fnUWcYyfe7bsygV4sWAkNo0QhN58APJFIKIc=
github.com/smartcontractkit/chainlink-testing-framework/seth v1.50.10/go.mod h1:05duR85P8YHuIfIkA7sn2bvrhKo/pDpFKV2rliYHNOo=
github.com/smartcontractkit/chainlink/deployment v0.0.0-20250203214543-d9da97d53b9b h1:CJbV0ra65AiR5K1GZpbXHyDcPtDP5j82U6RY1pDWpPg=
github.com/smartcontractkit/chainlink/deployment v0.0.0-20250203214543-d9da97d53b9b/go.mod h1:/9iouaqMDOAyPkHKFiYzzPL/5516U7mjp/t14XiN59I=
github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20250203214543-d9da97d53b9b h1:x3mtyzJAGovCmjawrmTHW4XHvchFjOXJtrL15OujeM0=
github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20250203214543-d9da97d53b9b/go.mod h1:e/GI2DNI54CKvpTY6Wqq8fcpZ3xYztWv+ihG5CF1XUc=
github.com/smartcontractkit/chainlink/v2 v2.19.0-ccip1.5.16-alpha.0.0.20250203214543-d9da97d53b9b h1:fWFIcI6tzCzF3j2FBcbOGv3E7rfX0URmxI2zO3tFuXA=
github.com/smartcontractkit/chainlink/v2 v2.19.0-ccip1.5.16-alpha.0.0.20250203214543-d9da97d53b9b/go.mod h1:huBdm7XEfj6DniyGxYLxV7g41McNvkyUhPRQIO/yXko=
github.com/smartcontractkit/chainlink/deployment v0.0.0-20250204104013-aa7b9062ca41 h1:PIHj5e/DaPbnYeAWPKJfhvjBz+wkYtLYikRek0f9+cA=
github.com/smartcontractkit/chainlink/deployment v0.0.0-20250204104013-aa7b9062ca41/go.mod h1:KRMU2lZAX1GUQIQt3v215V5UjDK8sLK7NsKPBsCkKos=
github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20250204104013-aa7b9062ca41 h1:i/xavohSvXTcu6v2vSIZ8OzDAbkXlz0gnHA9ZIXIRUQ=
github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20250204104013-aa7b9062ca41/go.mod h1:ooiapPo2WrfkphIcs0dNMxQAvH09GO6GatXmZYWV9DI=
github.com/smartcontractkit/chainlink/v2 v2.19.0-ccip1.5.16-alpha.0.0.20250204104013-aa7b9062ca41 h1:qPPhG7DxwnYihRU0w/9x1qHxUZFrxS2o6h4oPTlDr9I=
github.com/smartcontractkit/chainlink/v2 v2.19.0-ccip1.5.16-alpha.0.0.20250204104013-aa7b9062ca41/go.mod h1:uEepbp7GWQFAVsG5RWbHwbD8PQTv0FNOeUebT7cnjmI=
github.com/smartcontractkit/grpc-proxy v0.0.0-20240830132753-a7e17fec5ab7 h1:12ijqMM9tvYVEm+nR826WsrNi6zCKpwBhuApq127wHs=
github.com/smartcontractkit/grpc-proxy v0.0.0-20240830132753-a7e17fec5ab7/go.mod h1:FX7/bVdoep147QQhsOPkYsPEXhGZjeYx6lBSaSXtZOA=
github.com/smartcontractkit/libocr v0.0.0-20241223215956-e5b78d8e3919 h1:IpGoPTXpvllN38kT2z2j13sifJMz4nbHglidvop7mfg=
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
2 changes: 2 additions & 0 deletions pkg/solana/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/core"
"github.com/smartcontractkit/chainlink-common/pkg/types/query"
"github.com/smartcontractkit/chainlink-common/pkg/utils"
mn "github.com/smartcontractkit/chainlink-framework/multinode"

Expand All @@ -42,6 +43,7 @@ type LogPoller interface {
Close() error
RegisterFilter(ctx context.Context, filter logpoller.Filter) error
UnregisterFilter(ctx context.Context, name string) error
FilteredLogs(context.Context, []query.Expression, query.LimitAndSort, string) ([]logpoller.Log, error)
}

type Chain interface {
Expand Down
31 changes: 21 additions & 10 deletions pkg/solana/chainreader/chain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type ContractReaderService struct {
// provided dependencies
lggr logger.Logger
client MultipleAccountGetter
events EventsReader
reader EventsReader

// internal values
bindings namespaceBindings
Expand All @@ -60,7 +60,7 @@ func NewContractReaderService(
lggr logger.Logger,
dataReader MultipleAccountGetter,
cfg config.ContractReader,
events EventsReader,
reader EventsReader,
) (*ContractReaderService, error) {
svc := &ContractReaderService{
lggr: logger.Named(lggr, ServiceName),
Expand All @@ -69,6 +69,7 @@ func NewContractReaderService(
lookup: newLookup(),
parsed: &codec.ParsedTypes{EncoderDefs: map[string]codec.Entry{}, DecoderDefs: map[string]codec.Entry{}},
filters: []logpoller.Filter{},
reader: reader,
}

if err := svc.init(cfg.Namespaces); err != nil {
Expand Down Expand Up @@ -100,7 +101,7 @@ func (s *ContractReaderService) Start(ctx context.Context) error {
return s.StartOnce(ServiceName, func() error {
// registering filters needs a context so we should be able to use the start function context.
for _, filter := range s.filters {
if err := s.events.RegisterFilter(ctx, filter); err != nil {
if err := s.reader.RegisterFilter(ctx, filter); err != nil {
return err
}
}
Expand Down Expand Up @@ -342,7 +343,7 @@ func (s *ContractReaderService) init(namespaces map[string]config.ChainContractR
nameSpaceDef.ContractAddress,
nameSpaceDef.IDL, eventIDlDef,
read,
s.events,
s.reader,
); err != nil {
return err
}
Expand Down Expand Up @@ -392,18 +393,21 @@ func (s *ContractReaderService) addEventRead(
readDefinition config.ReadDefinition,
events EventsReader,
) error {
subKeys := [][]string{}
for _, onChain := range readDefinition.IndexedFields {
subKeys = append(subKeys, strings.Split(onChain, "."))
}
mappedTuples := make(map[string]uint64)
subKeys := [4][]string{}

applyIndexedFieldTuple(mappedTuples, subKeys, readDefinition.IndexedField0, 0)
applyIndexedFieldTuple(mappedTuples, subKeys, readDefinition.IndexedField1, 1)
applyIndexedFieldTuple(mappedTuples, subKeys, readDefinition.IndexedField2, 2)
applyIndexedFieldTuple(mappedTuples, subKeys, readDefinition.IndexedField3, 3)

filter := toLPFilter(readDefinition.PollingFilter, contractAddress, subKeys)
filter := toLPFilter(readDefinition.PollingFilter, contractAddress, subKeys[:])

s.filters = append(s.filters, filter)
s.bindings.AddReadBinding(namespace, genericName, newEventReadBinding(
namespace,
genericName,
readDefinition.IndexedFields,
mappedTuples,
events,
filter.EventSig,
))
Expand Down Expand Up @@ -462,3 +466,10 @@ func toLPFilter(
MaxLogsKept: f.MaxLogsKept,
}
}

func applyIndexedFieldTuple(lookup map[string]uint64, subKeys [4][]string, conf *config.IndexedField, idx uint64) {
if conf != nil {
lookup[conf.OffChainPath] = idx
subKeys[idx] = strings.Split(conf.OnChainPath, ".")
}
}
18 changes: 9 additions & 9 deletions pkg/solana/chainreader/event_read_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ type eventReadBinding struct {
modifier commoncodec.Modifier
key solana.PublicKey
remapper remapHelper
indexedSubkeys map[string]string
events EventsReader
indexedSubKeys map[string]uint64
reader EventsReader
eventSig [logpoller.EventSignatureLength]byte
}

func newEventReadBinding(
namespace, genericName string,
indexedSubkeys map[string]string,
events EventsReader,
indexedSubKeys map[string]uint64,
reader EventsReader,
eventSig [logpoller.EventSignatureLength]byte,
) *eventReadBinding {
binding := &eventReadBinding{
namespace: namespace,
genericName: genericName,
indexedSubkeys: indexedSubkeys,
events: events,
indexedSubKeys: indexedSubKeys,
reader: reader,
eventSig: eventSig,
}

Expand Down Expand Up @@ -102,7 +102,7 @@ func (b *eventReadBinding) QueryKey(

itemType := strings.Join([]string{b.namespace, b.genericName}, ".")

logs, err := b.events.FilteredLogs(ctx, filter.Expressions, limitAndSort, itemType)
logs, err := b.reader.FilteredLogs(ctx, filter.Expressions, limitAndSort, itemType)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -135,7 +135,7 @@ func (b *eventReadBinding) remapPrimitive(expression query.Expression) (query.Ex
}

func (b *eventReadBinding) encodeComparator(comparator *primitives.Comparator) (query.Expression, error) {
onChainName, ok := b.indexedSubkeys[comparator.Name]
subKeyIndex, ok := b.indexedSubKeys[comparator.Name]
if !ok {
return query.Expression{}, fmt.Errorf("%w: unknown indexed subkey mapping %s", types.ErrInvalidConfig, comparator.Name)
}
Expand All @@ -152,7 +152,7 @@ func (b *eventReadBinding) encodeComparator(comparator *primitives.Comparator) (
comparator.ValueComparators[idx].Value = newValue
}

return logpoller.NewEventSubkeyFilter(strings.Split(onChainName, "."), comparator.ValueComparators), nil
return logpoller.NewEventBySubKeyFilter(subKeyIndex, comparator.ValueComparators)
}

func (b *eventReadBinding) decodeLogsIntoSequences(
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 := "input.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
Loading

0 comments on commit 0752da2

Please sign in to comment.