Skip to content

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reductionista committed Oct 21, 2023
1 parent e669585 commit 1561c36
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 18 deletions.
5 changes: 3 additions & 2 deletions pkg/loop/internal/pb/median.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/loop/internal/pb/median_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pkg/loop/internal/pb/relayer.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/loop/internal/pb/relayer_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pkg/loop/internal/pb/reporting.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/loop/internal/pb/reporting_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions pkg/loop/internal/test/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ package test
import (
"bytes"
"context"
"encoding/json"
"fmt"
"math/big"
"time"

libocr "github.com/smartcontractkit/libocr/offchainreporting2plus/types"

"github.com/stretchr/testify/assert"

"github.com/smartcontractkit/chainlink-relay/pkg/types"
)

type staticConfigProvider struct{}
Expand Down Expand Up @@ -85,3 +90,29 @@ func (s staticContractTransmitter) LatestConfigDigestAndEpoch(ctx context.Contex
func (s staticContractTransmitter) FromAccount() (libocr.Account, error) {
return account, nil
}

type staticChainReader struct{}

func (c staticChainReader) GetLatestValue(ctx context.Context, bc types.BoundContract, method string, params, returnVal any) ([]byte, error) {
if !assert.ObjectsAreEqual(bc, boundContract) {
return nil, fmt.Errorf("expected report context %v but got %v", boundContract, bc)
}
if method != medianContractGenericMethod {
return nil, fmt.Errorf("expected generic contract method %v but got %v", medianContractGenericMethod, method)
}
if !assert.ObjectsAreEqual(params, getLatestValueParams) {
return nil, fmt.Errorf("expected params %v but got %v", params, getLatestValueParams)
}

retStruct := struct {
Epoch uint32
Round uint8
LatestAnswer *big.Int
LatestTimestamp time.Time
}{epoch, round, latestAnswer, latestTimestamp}
ret, err := json.Marshal(retStruct)
if err != nil {
return nil, fmt.Errorf("Failed constructing static return data from GetLatestValue")
}
return ret, nil
}
4 changes: 4 additions & 0 deletions pkg/loop/internal/test/median.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ func (s StaticMedianProvider) OnchainConfigCodec() median.OnchainConfigCodec {
return staticOnchainConfigCodec{}
}

func (s StaticMedianProvider) ChainReader() types.ChainReader {
return staticChainReader{}
}

type staticReportCodec struct{}

func (s staticReportCodec) BuildReport(os []median.ParsedAttributedObservation) (libocr.Report, error) {
Expand Down
6 changes: 6 additions & 0 deletions pkg/loop/internal/test/plugin_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"

libocr "github.com/smartcontractkit/libocr/offchainreporting2plus/types"

"github.com/smartcontractkit/chainlink-relay/pkg/types"
)

type StaticPluginProvider struct{}
Expand All @@ -29,3 +31,7 @@ func (s StaticPluginProvider) ContractConfigTracker() libocr.ContractConfigTrack
func (s StaticPluginProvider) ContractTransmitter() libocr.ContractTransmitter {
return staticContractTransmitter{}
}

func (s StaticPluginProvider) ChainReader() types.ChainReader {
return staticChainReader{}
}
10 changes: 10 additions & 0 deletions pkg/loop/internal/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,14 @@ URL = 'https://test.url'
signed = []byte{13: 37}
sigs = []libocr.AttributedOnchainSignature{{Signature: []byte{9: 8, 7: 6}, Signer: commontypes.OracleID(54)}}
value = big.NewInt(999)
boundContract = types.BoundContract{
Name: "my median contract",
Address: "0xBbf078A8849D74653e36E6DBBdC7e1a35E657C26",
Pending: false,
}
medianContractGenericMethod = "LatestTransmissionDetails"
getLatestValueParams = struct {
Param1 string
Param2 string
}{"value1", "value2"}
)

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pkg/reportingplugins/mercury/mercury_config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pkg/reportingplugins/mercury/v1/mercury_observation_v1.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pkg/reportingplugins/mercury/v2/mercury_observation_v2.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pkg/reportingplugins/mercury/v3/mercury_observation_v3.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1561c36

Please sign in to comment.