Skip to content

Commit

Permalink
Use one test to run chain reader interface tests, and properly skip u…
Browse files Browse the repository at this point in the history
…nimplemented events (#708)
  • Loading branch information
nolag authored May 16, 2024
1 parent 691bd53 commit 1549341
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 19 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0
github.com/pelletier/go-toml/v2 v2.1.1
github.com/prometheus/client_golang v1.17.0
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240507142850-569a909ad3b4
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240516150131-e1be553a9d10
github.com/smartcontractkit/libocr v0.0.0-20240326191951-2bbe9382d052
github.com/stretchr/testify v1.9.0
go.uber.org/zap v1.26.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,8 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
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.20240507142850-569a909ad3b4 h1:6PP8T5py2K+0Vd+8LP0DlDvPKhyXXhz1i2RwKoFhKPI=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240507142850-569a909ad3b4/go.mod h1:sj0pjL+METqeYL9ibp0T8SXquymlaQsofa6bdfLgXX8=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240516150131-e1be553a9d10 h1:IwJKWZHPBJbbh4oI3BGX8VNT3c/ChNiPZ/XI4iq6c0E=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240516150131-e1be553a9d10/go.mod h1:sj0pjL+METqeYL9ibp0T8SXquymlaQsofa6bdfLgXX8=
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
2 changes: 1 addition & 1 deletion integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/lib/pq v1.10.9
github.com/onsi/gomega v1.30.0
github.com/rs/zerolog v1.30.0
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240514153505-0ddba5aa4d2c
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240516150131-e1be553a9d10
github.com/smartcontractkit/chainlink-solana v1.0.3-0.20240510181707-46b1311a5a83
github.com/smartcontractkit/chainlink-testing-framework v1.28.12
github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20240515225456-aeb9f4d50d65
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1406,8 +1406,8 @@ github.com/smartcontractkit/chain-selectors v1.0.10 h1:t9kJeE6B6G+hKD0GYR4kGJSCq
github.com/smartcontractkit/chain-selectors v1.0.10/go.mod h1:d4Hi+E1zqjy9HqMkjBE5q1vcG9VGgxf5VxiRHfzi2kE=
github.com/smartcontractkit/chainlink-automation v1.0.3 h1:h/ijT0NiyV06VxYVgcNfsE3+8OEzT3Q0Z9au0z1BPWs=
github.com/smartcontractkit/chainlink-automation v1.0.3/go.mod h1:RjboV0Qd7YP+To+OrzHGXaxUxoSONveCoAK2TQ1INLU=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240514153505-0ddba5aa4d2c h1:KiG8PAwUrdYn/AGBQ+B4p6erEUbEB+g6LJKhAaDjJ2s=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240514153505-0ddba5aa4d2c/go.mod h1:sj0pjL+METqeYL9ibp0T8SXquymlaQsofa6bdfLgXX8=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240516150131-e1be553a9d10 h1:IwJKWZHPBJbbh4oI3BGX8VNT3c/ChNiPZ/XI4iq6c0E=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240516150131-e1be553a9d10/go.mod h1:sj0pjL+METqeYL9ibp0T8SXquymlaQsofa6bdfLgXX8=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240508101745-af1ed7bc8a69 h1:Sec/GpBpUVaTEax1kSHlTvkzF/+d3w5roAQXaj5+SLA=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240508101745-af1ed7bc8a69/go.mod h1:ZQKf+0OLzCLYIisH/OdOIQuFRI6bDuw+jPBTATyHfFM=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240220203239-09be0ea34540 h1:xFSv8561jsLtF6gYZr/zW2z5qUUAkcFkApin2mnbYTo=
Expand Down
50 changes: 37 additions & 13 deletions pkg/solana/chainreader/chain_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package chainreader_test
import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
"strconv"
Expand Down Expand Up @@ -42,8 +41,9 @@ func TestSolanaChainReaderService_ReaderInterface(t *testing.T) {
t.Parallel()

it := &chainReaderInterfaceTester{}
RunChainReaderGetLatestValueInterfaceTests(t, it)
RunChainReaderGetLatestValueInterfaceTests(t, commontestutils.WrapChainReaderTesterForLoop(it))
RunChainReaderInterfaceTests(t, it)
lsIt := &skipEventsChainReaderTester{ChainReaderInterfaceTester: commontestutils.WrapChainReaderTesterForLoop(it)}
RunChainReaderInterfaceTests(t, lsIt)
}

func TestSolanaChainReaderService_ServiceCtx(t *testing.T) {
Expand Down Expand Up @@ -534,12 +534,10 @@ func (r *chainReaderInterfaceTester) GetChainReader(t *testing.T) types.ChainRea
})

if r.reader == nil {
r.reader = &wrappedTestChainReader{
test: t,
tester: r,
}
r.reader = &wrappedTestChainReader{tester: r}
}

r.reader.test = t
r.reader.service = svc
r.reader.client = client

Expand All @@ -561,9 +559,7 @@ func (r *wrappedTestChainReader) GetLatestValue(ctx context.Context, contractNam
)
switch contractName + method {
case AnyContractName + EventName:
// t.Skip won't skip the test here
// returning the expected error to satisfy the test
return types.ErrNotFound
r.test.Skip("Events are not yet supported in Solana")
case AnyContractName + MethodReturningUint64:
cdc := makeTestCodec(r.test, fmt.Sprintf(baseIDL, uint64BaseTypeIDL, ""), config.EncodingTypeBorsh)
onChainStruct := struct {
Expand Down Expand Up @@ -650,7 +646,8 @@ func (r *wrappedTestChainReader) GetLatestValue(ctx context.Context, contractNam

// QueryKey implements the types.ChainReader interface.
func (r *wrappedTestChainReader) QueryKey(ctx context.Context, contractName string, filter query.KeyFilter, limitAndSort query.LimitAndSort, sequenceDataType any) ([]types.Sequence, error) {
return nil, errors.New("unimplemented")
r.test.Skip("QueryKey is not yet supported in Solana")
return nil, nil
}

func getAddresses(t *testing.T, tester ChainReaderInterfaceTester, a, b int) (ag_solana.PublicKey, ag_solana.PublicKey) {
Expand All @@ -668,8 +665,7 @@ func (r *wrappedTestChainReader) Bind(ctx context.Context, bindings []types.Boun

func (r *wrappedTestChainReader) CreateContractType(contractName, itemType string, forEncoding bool) (any, error) {
if AnyContractName+EventName == contractName+itemType {
// events are not supported, so just make the tests pass
return nil, types.ErrNotFound
r.test.Skip("Events are not yet supported in Solana")
}

return r.service.CreateContractType(contractName, itemType, forEncoding)
Expand Down Expand Up @@ -825,3 +821,31 @@ const (
}
}`
)

// Required to allow test skipping to be on the same goroutine
type skipEventsChainReaderTester struct{ ChainReaderInterfaceTester }

func (s *skipEventsChainReaderTester) GetChainReader(t *testing.T) types.ChainReader {
return &skipEventsChainReader{
ChainReader: s.ChainReaderInterfaceTester.GetChainReader(t),
t: t,
}
}

type skipEventsChainReader struct {
types.ChainReader
t *testing.T
}

func (s *skipEventsChainReader) GetLatestValue(ctx context.Context, contractName string, method string, params, returnVal any) error {
if contractName == AnyContractName && method == EventName {
s.t.Skip("Events are not yet supported in Solana")
}

return s.ChainReader.GetLatestValue(ctx, contractName, method, params, returnVal)
}

func (s *skipEventsChainReader) QueryKey(ctx context.Context, contractName string, filter query.KeyFilter, limitAndSort query.LimitAndSort, sequenceDataType any) ([]types.Sequence, error) {
s.t.Skip("QueryKey is not yet supported in Solana")
return nil, nil
}

0 comments on commit 1549341

Please sign in to comment.