Skip to content

Commit

Permalink
add interface tests that ensure service functions in loop mode
Browse files Browse the repository at this point in the history
  • Loading branch information
EasterTheBunny committed Mar 7, 2024
1 parent a7fefc0 commit 8bbbbf4
Show file tree
Hide file tree
Showing 7 changed files with 443 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/pelletier/go-toml/v2 v2.1.1
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.17.0
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240228160036-7d796e1d1680
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240306212342-bde2560306e8
github.com/smartcontractkit/libocr v0.0.0-20240112202000-6359502d2ff1
github.com/stretchr/testify v1.8.4
github.com/test-go/testify v1.1.4
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,8 @@ 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.1.7-0.20240228160036-7d796e1d1680 h1:cfqibCkmWq4x8ufMvYNirQMoNxj2kcawnn06HhNy3rw=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240228160036-7d796e1d1680/go.mod h1:6aXWSEQawX2oZXcPPOdxnEGufAhj7PqPKolXf6ijRGA=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240306212342-bde2560306e8 h1:9u6BdqwDqIPW9w9O+8eH7zB2Qqu05YKweEoinzt2Bsw=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240306212342-bde2560306e8/go.mod h1:6aXWSEQawX2oZXcPPOdxnEGufAhj7PqPKolXf6ijRGA=
github.com/smartcontractkit/go-plugin v0.0.0-20231003134350-e49dad63b306 h1:ko88+ZznniNJZbZPWAvHQU8SwKAdHngdDZ+pvVgB5ss=
github.com/smartcontractkit/go-plugin v0.0.0-20231003134350-e49dad63b306/go.mod h1:w1sAEES3g3PuV/RzUrgow20W2uErMly84hhD3um1WL4=
github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f h1:hgJif132UCdjo8u43i7iPN1/MFnu49hv7lFGFftCHKU=
Expand Down
6 changes: 5 additions & 1 deletion pkg/solana/account_read_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type BinaryDataReader interface {
type accountReadBinding struct {
idlAccount string
account solana.PublicKey
codec types.Codec
codec types.RemoteCodec
reader BinaryDataReader
}

Expand All @@ -45,3 +45,7 @@ func (b *accountReadBinding) Bind(contract types.BoundContract) error {

return nil
}

func (b *accountReadBinding) CreateType(_ bool) (any, error) {
return b.codec.CreateType(b.idlAccount, false)
}
16 changes: 16 additions & 0 deletions pkg/solana/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
type readBinding interface {
GetLatestValue(ctx context.Context, params, returnVal any) error
Bind(types.BoundContract) error
CreateType(bool) (any, error)
}

// key is namespace
Expand Down Expand Up @@ -52,6 +53,21 @@ func (b namespaceBindings) GetReadBindings(namespace, methodName string) ([]read
return rbs, nil
}

func (b namespaceBindings) CreateType(namespace, methodName string, forEncoding bool) (any, error) {
bindings, err := b.GetReadBindings(namespace, methodName)
if err != nil {
return nil, err
}

if len(bindings) == 1 {
// get the item type from the binding codec
return bindings[0].CreateType(forEncoding)
}

// default to map when multiple bindings exist
return &map[string]any{}, nil
}

func (b namespaceBindings) Bind(boundContracts []types.BoundContract) error {
for _, bc := range boundContracts {
parts := strings.Split(bc.Name, ".")
Expand Down
6 changes: 6 additions & 0 deletions pkg/solana/chain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ func (s *SolanaChainReaderService) Bind(_ context.Context, bindings []types.Boun
return s.bindings.Bind(bindings)
}

// CreateContractType implements the ContractTypeProvider interface and allows the chain reader
// service to explicitly define the expected type for a grpc server to provide.
func (s *SolanaChainReaderService) CreateContractType(contractName, itemType string, forEncoding bool) (any, error) {
return s.bindings.CreateType(contractName, itemType, forEncoding)
}

func (s *SolanaChainReaderService) init(namespaces map[string]config.ChainReaderMethods) error {
for namespace, methods := range namespaces {
for methodName, method := range methods.Methods {
Expand Down
Loading

0 comments on commit 8bbbbf4

Please sign in to comment.