Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ilija42 committed Feb 9, 2025
1 parent 2eb51fe commit a9c0e7c
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 172 deletions.
70 changes: 35 additions & 35 deletions integration-tests/relayinterface/chain_components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ func TestChainComponents(t *testing.T) {
helper := &helper{}
helper.Init(t)

//t.Run("RunChainComponentsSolanaTests", func(t *testing.T) {
// t.Parallel()
// it := &SolanaChainComponentsInterfaceTester[*testing.T]{Helper: helper, testContext: make(map[string]uint64), testContextMu: &sync.RWMutex{}, testIdx: &atomic.Uint64{}}
// DisableTests(it)
// it.Setup(t)
// RunChainComponentsSolanaTests(t, it)
//})
t.Run("RunChainComponentsSolanaTests", func(t *testing.T) {
t.Parallel()
it := &SolanaChainComponentsInterfaceTester[*testing.T]{Helper: helper, testContext: make(map[string]uint64), testContextMu: &sync.RWMutex{}, testIdx: &atomic.Uint64{}}
DisableTests(it)
it.Setup(t)
RunChainComponentsSolanaTests(t, it)
})

t.Run("RunChainComponentsInLoopSolanaTests", func(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -209,31 +209,31 @@ type TimestampedUnixBig struct {
func RunContractReaderInLoopTests[T WrappedTestingT[T]](t T, it ChainComponentsInterfaceTester[T]) {
//RunContractReaderInterfaceTests(t, it, false, true)
testCases := []Testcase[T]{
//{
// Name: ContractReaderGetLatestValueUsingMultiReader,
// Test: func(t T) {
// cr := it.GetContractReader(t)
// bindings := it.GetBindings(t)
// ctx := tests.Context(t)
//
// bound := BindingsByName(bindings, AnyContractName)[0]
//
// require.NoError(t, cr.Bind(ctx, bindings))
//
// type MultiReadResult struct {
// A uint8
// B int16
// U string
// V bool
// }
//
// mRR := MultiReadResult{}
// require.NoError(t, cr.GetLatestValue(ctx, bound.ReadIdentifier(MultiRead), primitives.Unconfirmed, nil, &mRR))
//
// expectedMRR := MultiReadResult{A: 1, B: 2, U: "Hello", V: true}
// require.Equal(t, expectedMRR, mRR)
// },
//},
{
Name: ContractReaderGetLatestValueUsingMultiReader,
Test: func(t T) {
cr := it.GetContractReader(t)
bindings := it.GetBindings(t)
ctx := tests.Context(t)

bound := BindingsByName(bindings, AnyContractName)[0]

require.NoError(t, cr.Bind(ctx, bindings))

type MultiReadResult struct {
A uint8
B int16
U string
V bool
}

mRR := MultiReadResult{}
require.NoError(t, cr.GetLatestValue(ctx, bound.ReadIdentifier(MultiRead), primitives.Unconfirmed, nil, &mRR))

expectedMRR := MultiReadResult{A: 1, B: 2, U: "Hello", V: true}
require.Equal(t, expectedMRR, mRR)
},
},
{
Name: ContractReaderGetLatestValueUsingSplitParamsReader,
Test: func(t T) {
Expand Down Expand Up @@ -632,7 +632,7 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractReaderConfig(t T
},
&commoncodec.PropertyExtractorConfig{FieldName: "Response"},
},
ReadType: config.AccountSplitParams,
ReadType: config.Account,
},
MultiRead: {
ChainSpecificName: "MultiRead1",
Expand All @@ -644,10 +644,10 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractReaderConfig(t T
{
ChainSpecificName: "MultiRead2",
PDADefinition: codec.PDATypeDef{Prefix: []byte("multi_read2")},
ReadType: config.AccountPDA,
ReadType: config.Account,
},
}},
ReadType: config.AccountPDA,
ReadType: config.Account,
},
MethodReturningUint64: uint64ReadDef,
MethodReturningUint64Slice: {
Expand Down
16 changes: 5 additions & 11 deletions pkg/solana/chainreader/account_read_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import (
"context"
"errors"
"fmt"
"slices"

"github.com/gagliardetto/solana-go"

commoncodec "github.com/smartcontractkit/chainlink-common/pkg/codec"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/query"
"github.com/smartcontractkit/chainlink-solana/pkg/solana/config"

"github.com/smartcontractkit/chainlink-solana/pkg/solana/codec"
)
Expand All @@ -21,16 +19,16 @@ type accountReadBinding struct {
namespace, genericName string
codec types.RemoteCodec
key solana.PublicKey
prefix []byte
readType config.ReadType
isPda bool // flag to signify whether or not the account read is for a PDA
prefix []byte // only used for PDA public key calculation
}

func newAccountReadBinding(namespace, genericName string, prefix []byte, readType config.ReadType) *accountReadBinding {
func newAccountReadBinding(namespace, genericName string, prefix []byte, isPda bool) *accountReadBinding {
return &accountReadBinding{
namespace: namespace,
genericName: genericName,
prefix: prefix,
readType: readType,
isPda: isPda,
}
}

Expand All @@ -48,7 +46,7 @@ func (b *accountReadBinding) SetAddress(key solana.PublicKey) {

func (b *accountReadBinding) GetAddress(ctx context.Context, params any) (solana.PublicKey, error) {
// Return the bound key if normal account read
if !slices.Contains([]config.ReadType{config.AccountSplitParams, config.AccountPDA}, b.readType) {
if !b.isPda {
return b.key, nil
}
// Calculate the public key if PDA account read
Expand All @@ -71,10 +69,6 @@ func (b *accountReadBinding) Decode(ctx context.Context, bts []byte, outVal any)
return b.codec.Decode(ctx, bts, outVal, codec.WrapItemType(false, b.namespace, b.genericName))
}

func (b *accountReadBinding) ReadType() config.ReadType {
return b.readType
}

// buildSeedsSlice encodes and builds the seedslist to calculate the PDA public key
func (b *accountReadBinding) buildSeedsSlice(ctx context.Context, params any) ([][]byte, error) {
flattenedSeeds := make([]byte, 0, solana.MaxSeeds*solana.MaxSeedLength)
Expand Down
1 change: 1 addition & 0 deletions pkg/solana/chainreader/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func doMethodBatchCall(ctx context.Context, client MultipleAccountGetter, bindin
decodeReturnVal(ctx, rBinding, data[idx], results[idx].returnVal),
results[idx].err)
}

return results, nil
}

Expand Down
2 changes: 0 additions & 2 deletions pkg/solana/chainreader/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
commoncodec "github.com/smartcontractkit/chainlink-common/pkg/codec"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/query"
"github.com/smartcontractkit/chainlink-solana/pkg/solana/config"
)

type readBinding interface {
Expand All @@ -21,7 +20,6 @@ type readBinding interface {
CreateType(bool) (any, error)
Decode(context.Context, []byte, any) error
QueryKey(context.Context, query.KeyFilter, query.LimitAndSort, any) ([]types.Sequence, error)
ReadType() config.ReadType
}

type bindingsRegistry struct {
Expand Down
5 changes: 0 additions & 5 deletions pkg/solana/chainreader/bindings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
commoncodec "github.com/smartcontractkit/chainlink-common/pkg/codec"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/query"
"github.com/smartcontractkit/chainlink-solana/pkg/solana/config"
)

func TestBindings_CreateType(t *testing.T) {
Expand Down Expand Up @@ -49,10 +48,6 @@ type mockBinding struct {
mock.Mock
}

func (_m *mockBinding) ReadType() config.ReadType {
return config.ReadType(0)
}

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

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

0 comments on commit a9c0e7c

Please sign in to comment.