diff --git a/go.mod b/go.mod index ccdd48c..efe6366 100644 --- a/go.mod +++ b/go.mod @@ -7,9 +7,9 @@ require ( github.com/pkg/errors v0.9.1 github.com/shopspring/decimal v1.3.1 github.com/smartcontractkit/chain-selectors v1.0.5 - github.com/smartcontractkit/chainlink-common v0.1.7-0.20240220201513-6cb818f8800d - github.com/smartcontractkit/libocr v0.0.0-20240112202000-6359502d2ff1 - github.com/stretchr/testify v1.8.4 + github.com/smartcontractkit/chainlink-common v0.1.7-0.20240324182820-92b84cfb6373 + github.com/smartcontractkit/libocr v0.0.0-20240322223357-61738d25af14 + github.com/stretchr/testify v1.9.0 google.golang.org/protobuf v1.32.0 ) @@ -18,8 +18,8 @@ require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cenkalti/backoff/v4 v4.2.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/fatih/color v1.13.0 // indirect + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect + github.com/fatih/color v1.14.1 // indirect github.com/fxamacker/cbor/v2 v2.5.0 // indirect github.com/go-json-experiment/json v0.0.0-20231102232822-2e55bd4e08b0 // indirect github.com/go-logr/logr v1.2.4 // indirect diff --git a/go.sum b/go.sum index c833e34..7f2da0e 100644 --- a/go.sum +++ b/go.sum @@ -56,8 +56,9 @@ github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnht github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 h1:/inchEIKaYC1Akx+H+gqO04wryn5h75LSazbRlnya1k= github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -66,8 +67,9 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.m github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/envoyproxy/protoc-gen-validate v1.0.2 h1:QkIBuU5k+x7/QXPvPPnWXWlCdaBFApVqftFV6k087DA= github.com/envoyproxy/protoc-gen-validate v1.0.2/go.mod h1:GpiZQP3dDbg4JouG/NNS7QWXpgx6x8QiMKdmN72jogE= -github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= +github.com/fatih/color v1.14.1 h1:qfhVLaG5s+nCROl1zJsZRxFeYrHLqWroPOQ8BWiNb4w= +github.com/fatih/color v1.14.1/go.mod h1:2oHN61fhTpgcxD3TSWCgKDiH1+x4OiDVVGH8WlgGZGg= github.com/fxamacker/cbor/v2 v2.5.0 h1:oHsG0V/Q6E/wqTS2O1Cozzsy69nqCiguo5Q1a1ADivE= github.com/fxamacker/cbor/v2 v2.5.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= @@ -207,31 +209,28 @@ github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5g github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/smartcontractkit/chain-selectors v1.0.5 h1:NOefQsogPZS4aBbWPFrgAyoke0gppN2ojfa8SQkhu8c= github.com/smartcontractkit/chain-selectors v1.0.5/go.mod h1:WBhLlODF5b95vvx2tdKK55vGACg1+qZpuBhOGu1UXVo= -github.com/smartcontractkit/chainlink-common v0.1.7-0.20240216181624-ccf0da042f11 h1:zazCJSjz60/V5B8+8LxLX7BrtN1AXGUv+B/E1Xrq2OA= -github.com/smartcontractkit/chainlink-common v0.1.7-0.20240216181624-ccf0da042f11/go.mod h1:6aXWSEQawX2oZXcPPOdxnEGufAhj7PqPKolXf6ijRGA= -github.com/smartcontractkit/chainlink-common v0.1.7-0.20240220164325-44ed6b4009cb h1:E0K6uq+9SjpktUeqTg8NVarUAfwRBL/reIuZb4msrtA= -github.com/smartcontractkit/chainlink-common v0.1.7-0.20240220164325-44ed6b4009cb/go.mod h1:6aXWSEQawX2oZXcPPOdxnEGufAhj7PqPKolXf6ijRGA= -github.com/smartcontractkit/chainlink-common v0.1.7-0.20240220165243-0b144b02fd8d h1:OOezTy1Z4sITGuOx3oegof47O0AbloW/YLPjzVLXn1E= -github.com/smartcontractkit/chainlink-common v0.1.7-0.20240220165243-0b144b02fd8d/go.mod h1:6aXWSEQawX2oZXcPPOdxnEGufAhj7PqPKolXf6ijRGA= -github.com/smartcontractkit/chainlink-common v0.1.7-0.20240220201513-6cb818f8800d h1:XByRw7oF2mG+yBuoMpBqm5Ogu1vlunPZfhL74Ny3NFU= -github.com/smartcontractkit/chainlink-common v0.1.7-0.20240220201513-6cb818f8800d/go.mod h1:6aXWSEQawX2oZXcPPOdxnEGufAhj7PqPKolXf6ijRGA= +github.com/smartcontractkit/chainlink-common v0.1.7-0.20240324182820-92b84cfb6373 h1:zlPLi+aJRwOp4Y/JlHSqKnBd038rCCUzgDSYszbmySI= +github.com/smartcontractkit/chainlink-common v0.1.7-0.20240324182820-92b84cfb6373/go.mod h1:kmBPIyrTt8Q3HuSC3qdK96uwr4edw9SYbxjWmle7la4= github.com/smartcontractkit/go-plugin v0.0.0-20240208201424-b3b91517de16 h1:TFe+FvzxClblt6qRfqEhUfa4kFQx5UobuoFGO2W4mMo= github.com/smartcontractkit/go-plugin v0.0.0-20240208201424-b3b91517de16/go.mod h1:lBS5MtSSBZk0SHc66KACcjjlU6WzEVP/8pwz68aMkCI= github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f h1:hgJif132UCdjo8u43i7iPN1/MFnu49hv7lFGFftCHKU= github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f/go.mod h1:MvMXoufZAtqExNexqi4cjrNYE9MefKddKylxjS+//n0= -github.com/smartcontractkit/libocr v0.0.0-20240112202000-6359502d2ff1 h1:3y9WsXkZ5lxFrmfH7DQHs/q308lylKId5l/3VC0QAdM= -github.com/smartcontractkit/libocr v0.0.0-20240112202000-6359502d2ff1/go.mod h1:kC0qmVPUaVkFqGiZMNhmRmjdphuUmeyLEdlWFOQzFWI= +github.com/smartcontractkit/libocr v0.0.0-20240322223357-61738d25af14 h1:sGlxJ7y3guP20ohhn23XDj5kPXf+sOR7iFJaWjIvao0= +github.com/smartcontractkit/libocr v0.0.0-20240322223357-61738d25af14/go.mod h1:SJEZCHgMCAzzBvo9vMV2DQ9onfEcIJCYSViyP4JI6c4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/llo/plugin.go b/llo/plugin.go index 770dad3..731b978 100644 --- a/llo/plugin.go +++ b/llo/plugin.go @@ -17,7 +17,7 @@ import ( chainselectors "github.com/smartcontractkit/chain-selectors" "github.com/smartcontractkit/libocr/offchainreporting2/types" ocr2types "github.com/smartcontractkit/libocr/offchainreporting2/types" - ocr3types "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types" + "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types" ) // TODO: Split out this file and write unit tests: https://smartcontract-it.atlassian.net/browse/MERC-3524 @@ -179,7 +179,7 @@ type PluginFactory struct { Codecs map[llotypes.ReportFormat]ReportCodec } -func (f *PluginFactory) NewReportingPlugin(cfg ocr3types.ReportingPluginConfig) (ocr3types.ReportingPlugin[llotypes.ReportInfo], ocr3types.ReportingPluginInfo, error) { +func (f *PluginFactory) NewReportingPlugin(ctx context.Context, cfg ocr3types.ReportingPluginConfig) (ocr3types.ReportingPlugin[llotypes.ReportInfo], ocr3types.ReportingPluginInfo, error) { offchainCfg, err := DecodeOffchainConfig(cfg.OffchainConfig) if err != nil { return nil, ocr3types.ReportingPluginInfo{}, fmt.Errorf("NewReportingPlugin failed to decode offchain config; got: 0x%x (len: %d); %w", cfg.OffchainConfig, len(cfg.OffchainConfig), err) @@ -374,7 +374,7 @@ func (p *LLOPlugin) Observation(ctx context.Context, outctx ocr3types.OutcomeCon // *not* strictly) across the lifetime of a protocol instance and that // outctx.previousOutcome contains the consensus outcome with sequence // number (outctx.SeqNr-1). -func (p *LLOPlugin) ValidateObservation(outctx ocr3types.OutcomeContext, query types.Query, ao types.AttributedObservation) error { +func (p *LLOPlugin) ValidateObservation(ctx context.Context, outctx ocr3types.OutcomeContext, query types.Query, ao types.AttributedObservation) error { if outctx.SeqNr <= 1 { if len(ao.Observation) != 0 { return fmt.Errorf("Observation is not empty") @@ -515,7 +515,7 @@ func (out *Outcome) ReportableChannels() []llotypes.ChannelID { // // libocr guarantees that this will always be called with at least 2f+1 // AttributedObservations -func (p *LLOPlugin) Outcome(outctx ocr3types.OutcomeContext, query types.Query, aos []types.AttributedObservation) (ocr3types.Outcome, error) { +func (p *LLOPlugin) Outcome(ctx context.Context, outctx ocr3types.OutcomeContext, query types.Query, aos []types.AttributedObservation) (ocr3types.Outcome, error) { if len(aos) < 2*p.F+1 { return nil, fmt.Errorf("invariant violation: expected at least 2f+1 attributed observations, got %d (f: %d)", len(aos), p.F) } @@ -797,7 +797,7 @@ func (p *LLOPlugin) encodeReport(r Report, format llotypes.ReportFormat) (types. // *not* strictly) across the lifetime of a protocol instance and that // outctx.previousOutcome contains the consensus outcome with sequence // number (outctx.SeqNr-1). -func (p *LLOPlugin) Reports(seqNr uint64, rawOutcome ocr3types.Outcome) ([]ocr3types.ReportWithInfo[llotypes.ReportInfo], error) { +func (p *LLOPlugin) Reports(ctx context.Context, seqNr uint64, rawOutcome ocr3types.Outcome) ([]ocr3types.ReportWithInfo[llotypes.ReportInfo], error) { if seqNr <= 1 { // no reports for initial round return nil, nil @@ -888,7 +888,7 @@ func (p *LLOPlugin) ShouldTransmitAcceptedReport(context.Context, uint64, ocr3ty // This is an advanced feature. The "default" approach (what OCR1 & OCR2 // did) is to have an empty ValidateObservation function and return // QuorumTwoFPlusOne from this function. -func (p *LLOPlugin) ObservationQuorum(outctx ocr3types.OutcomeContext, query types.Query) (ocr3types.Quorum, error) { +func (p *LLOPlugin) ObservationQuorum(ctx context.Context, outctx ocr3types.OutcomeContext, query types.Query) (ocr3types.Quorum, error) { return ocr3types.QuorumTwoFPlusOne, nil } diff --git a/mercury/onchain_config.go b/mercury/onchain_config.go index 977f0a3..c551421 100644 --- a/mercury/onchain_config.go +++ b/mercury/onchain_config.go @@ -1,6 +1,7 @@ package mercury import ( + "context" "math/big" pkgerrors "github.com/pkg/errors" @@ -27,7 +28,7 @@ var _ mercury.OnchainConfigCodec = StandardOnchainConfigCodec{} // returned by EncodeValueInt192. type StandardOnchainConfigCodec struct{} -func (StandardOnchainConfigCodec) Decode(b []byte) (mercury.OnchainConfig, error) { +func (StandardOnchainConfigCodec) Decode(ctx context.Context, b []byte) (mercury.OnchainConfig, error) { if len(b) != onchainConfigEncodedLength { return mercury.OnchainConfig{}, pkgerrors.Errorf("unexpected length of OnchainConfig, expected %v, got %v", onchainConfigEncodedLength, len(b)) } @@ -56,7 +57,7 @@ func (StandardOnchainConfigCodec) Decode(b []byte) (mercury.OnchainConfig, error return mercury.OnchainConfig{Min: min, Max: max}, nil } -func (StandardOnchainConfigCodec) Encode(c mercury.OnchainConfig) ([]byte, error) { +func (StandardOnchainConfigCodec) Encode(ctx context.Context, c mercury.OnchainConfig) ([]byte, error) { verBytes, err := bigbigendian.SerializeSigned(32, onchainConfigVersionBig) if err != nil { return nil, err diff --git a/mercury/onchain_config_test.go b/mercury/onchain_config_test.go index 1d1d09c..6386b03 100644 --- a/mercury/onchain_config_test.go +++ b/mercury/onchain_config_test.go @@ -6,10 +6,11 @@ import ( "testing" "github.com/smartcontractkit/chainlink-common/pkg/types/mercury" + "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" ) func FuzzDecodeOnchainConfig(f *testing.F) { - valid, err := StandardOnchainConfigCodec{}.Encode(mercury.OnchainConfig{Min: big.NewInt(1), Max: big.NewInt(1000)}) + valid, err := StandardOnchainConfigCodec{}.Encode(tests.Context(f), mercury.OnchainConfig{Min: big.NewInt(1), Max: big.NewInt(1000)}) if err != nil { f.Fatalf("failed to construct valid OnchainConfig: %s", err) } @@ -17,12 +18,13 @@ func FuzzDecodeOnchainConfig(f *testing.F) { f.Add([]byte{}) f.Add([]byte(valid)) f.Fuzz(func(t *testing.T, encoded []byte) { - decoded, err := StandardOnchainConfigCodec{}.Decode(encoded) + ctx := tests.Context(t) + decoded, err := StandardOnchainConfigCodec{}.Decode(ctx, encoded) if err != nil { return } - encoded2, err := StandardOnchainConfigCodec{}.Encode(decoded) + encoded2, err := StandardOnchainConfigCodec{}.Encode(ctx, decoded) if err != nil { t.Fatalf("failed to re-encode decoded input: %s", err) } diff --git a/mercury/v1/mercury.go b/mercury/v1/mercury.go index 0fd90ea..4b9c387 100644 --- a/mercury/v1/mercury.go +++ b/mercury/v1/mercury.go @@ -78,18 +78,18 @@ func NewFactory(ds DataSource, lggr logger.Logger, occ mercurytypes.OnchainConfi return Factory{ds, lggr, occ, rc} } -func (fac Factory) NewMercuryPlugin(configuration ocr3types.MercuryPluginConfig) (ocr3types.MercuryPlugin, ocr3types.MercuryPluginInfo, error) { +func (fac Factory) NewMercuryPlugin(ctx context.Context, configuration ocr3types.MercuryPluginConfig) (ocr3types.MercuryPlugin, ocr3types.MercuryPluginInfo, error) { offchainConfig, err := mercury.DecodeOffchainConfig(configuration.OffchainConfig) if err != nil { return nil, ocr3types.MercuryPluginInfo{}, err } - onchainConfig, err := fac.onchainConfigCodec.Decode(configuration.OnchainConfig) + onchainConfig, err := fac.onchainConfigCodec.Decode(ctx, configuration.OnchainConfig) if err != nil { return nil, ocr3types.MercuryPluginInfo{}, err } - maxReportLength, err := fac.reportCodec.MaxReportLength(configuration.N) + maxReportLength, err := fac.reportCodec.MaxReportLength(ctx, configuration.N) if err != nil { return nil, ocr3types.MercuryPluginInfo{}, err } @@ -328,7 +328,7 @@ func parseAttributedObservations(lggr logger.Logger, aos []types.AttributedObser return paos } -func (rp *reportingPlugin) Report(repts types.ReportTimestamp, previousReport types.Report, aos []types.AttributedObservation) (shouldReport bool, report types.Report, err error) { +func (rp *reportingPlugin) Report(ctx context.Context, repts types.ReportTimestamp, previousReport types.Report, aos []types.AttributedObservation) (shouldReport bool, report types.Report, err error) { paos := parseAttributedObservations(rp.logger, aos) if len(paos) == 0 { @@ -340,7 +340,7 @@ func (rp *reportingPlugin) Report(repts types.ReportTimestamp, previousReport ty return false, nil, pkgerrors.Errorf("only received %v valid attributed observations, but need at least f+1 (%v)", len(paos), rp.f+1) } - rf, err := rp.buildReportFields(previousReport, paos) + rf, err := rp.buildReportFields(ctx, previousReport, paos) if err != nil { rp.logger.Errorw("failed to build report fields", "paos", paos, "f", rp.f, "reportFields", rf, "repts", repts, "err", err) return false, nil, err @@ -359,7 +359,7 @@ func (rp *reportingPlugin) Report(repts types.ReportTimestamp, previousReport ty "timestamp", repts, ) - report, err = rp.reportCodec.BuildReport(rf) + report, err = rp.reportCodec.BuildReport(ctx, rf) if err != nil { rp.logger.Debugw("failed to BuildReport", "paos", paos, "f", rp.f, "reportFields", rf, "repts", repts) return false, nil, err @@ -373,11 +373,11 @@ func (rp *reportingPlugin) Report(repts types.ReportTimestamp, previousReport ty return true, report, nil } -func (rp *reportingPlugin) buildReportFields(previousReport types.Report, paos []PAO) (rf v1.ReportFields, merr error) { +func (rp *reportingPlugin) buildReportFields(ctx context.Context, previousReport types.Report, paos []PAO) (rf v1.ReportFields, merr error) { var err error if previousReport != nil { var maxFinalizedBlockNumber int64 - maxFinalizedBlockNumber, err = rp.reportCodec.CurrentBlockNumFromReport(previousReport) + maxFinalizedBlockNumber, err = rp.reportCodec.CurrentBlockNumFromReport(ctx, previousReport) if err != nil { merr = errors.Join(merr, err) } else { diff --git a/mercury/v1/mercury_test.go b/mercury/v1/mercury_test.go index b3786fa..00eaef8 100644 --- a/mercury/v1/mercury_test.go +++ b/mercury/v1/mercury_test.go @@ -23,6 +23,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/logger" mercurytypes "github.com/smartcontractkit/chainlink-common/pkg/types/mercury" v1 "github.com/smartcontractkit/chainlink-common/pkg/types/mercury/v1" + "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" "github.com/smartcontractkit/chainlink-data-streams/mercury" ) @@ -42,7 +43,7 @@ func (trc *testReportCodec) reset() { trc.builtReportFields = nil } -func (trc *testReportCodec) BuildReport(rf v1.ReportFields) (types.Report, error) { +func (trc *testReportCodec) BuildReport(ctx context.Context, rf v1.ReportFields) (types.Report, error) { if trc.buildReportShouldFail { return nil, errors.New("buildReportShouldFail=true") } @@ -50,7 +51,7 @@ func (trc *testReportCodec) BuildReport(rf v1.ReportFields) (types.Report, error return trc.builtReport, nil } -func (trc *testReportCodec) MaxReportLength(n int) (int, error) { +func (trc *testReportCodec) MaxReportLength(ctx context.Context, n int) (int, error) { return 8*32 + // feed ID 32 + // timestamp 192 + // benchmarkPrice @@ -62,12 +63,12 @@ func (trc *testReportCodec) MaxReportLength(n int) (int, error) { nil } -func (trc *testReportCodec) CurrentBlockNumFromReport(types.Report) (int64, error) { +func (trc *testReportCodec) CurrentBlockNumFromReport(context.Context, types.Report) (int64, error) { return trc.currentBlock, trc.currentBlockErr } func newReportingPlugin(t *testing.T, codec *testReportCodec) *reportingPlugin { - maxReportLength, err := codec.MaxReportLength(4) + maxReportLength, err := codec.MaxReportLength(tests.Context(t), 4) require.NoError(t, err) return &reportingPlugin{ f: 1, @@ -712,7 +713,7 @@ func Test_Plugin_Report(t *testing.T) { rp := newReportingPlugin(t, codec) t.Run("errors if not enough attributed observations", func(t *testing.T) { - _, _, err := rp.Report(repts, nil, []types.AttributedObservation{}) + _, _, err := rp.Report(tests.Context(t), repts, nil, []types.AttributedObservation{}) assert.EqualError(t, err, "got zero valid attributed observations") }) t.Run("succeeds, ignoring unparseable attributed observations", func(t *testing.T) { @@ -722,7 +723,7 @@ func Test_Plugin_Report(t *testing.T) { newAttributedObservation(t, newValidMercuryObservationProto()), newUnparseableAttributedObservation(), } - should, report, err := rp.Report(repts, nil, aos) + should, report, err := rp.Report(tests.Context(t), repts, nil, aos) assert.NoError(t, err) assert.True(t, should) @@ -737,7 +738,7 @@ func Test_Plugin_Report(t *testing.T) { newAttributedObservation(t, newValidMercuryObservationProto()), newAttributedObservation(t, newValidMercuryObservationProto()), } - should, report, err := rp.Report(repts, nil, aos) + should, report, err := rp.Report(tests.Context(t), repts, nil, aos) assert.True(t, should) assert.Equal(t, codec.builtReport, report) @@ -762,7 +763,7 @@ func Test_Plugin_Report(t *testing.T) { newAttributedObservation(t, obs[2]), newAttributedObservation(t, obs[3]), } - _, _, err := rp.Report(repts, nil, aos) + _, _, err := rp.Report(tests.Context(t), repts, nil, aos) assert.EqualError(t, err, "no valid maxFinalizedBlockNumber with at least f+1 votes (got counts: map[0:1 1:1 2:1 3:1], f=1)") }) @@ -783,7 +784,7 @@ func Test_Plugin_Report(t *testing.T) { newAttributedObservation(t, obs[2]), newAttributedObservation(t, obs[3]), } - _, _, err := rp.Report(repts, nil, aos) + _, _, err := rp.Report(tests.Context(t), repts, nil, aos) require.Error(t, err) assert.Contains(t, err.Error(), "GetConsensusCurrentBlock failed: cannot come to consensus on latest block number") @@ -806,7 +807,7 @@ func Test_Plugin_Report(t *testing.T) { newAttributedObservation(t, obs[2]), newAttributedObservation(t, obs[3]), } - _, _, err := rp.Report(repts, nil, aos) + _, _, err := rp.Report(tests.Context(t), repts, nil, aos) require.Error(t, err) assert.Contains(t, err.Error(), "GetConsensusCurrentBlock failed: cannot come to consensus on latest block number") @@ -827,7 +828,7 @@ func Test_Plugin_Report(t *testing.T) { newAttributedObservation(t, obs[2]), newAttributedObservation(t, obs[3]), } - should, report, err := rp.Report(repts, nil, aos) + should, report, err := rp.Report(tests.Context(t), repts, nil, aos) assert.False(t, should) assert.Nil(t, report) @@ -844,7 +845,7 @@ func Test_Plugin_Report(t *testing.T) { newAttributedObservation(t, newValidMercuryObservationProto()), newUnparseableAttributedObservation(), } - _, _, err := rp.Report(repts, nil, aos) + _, _, err := rp.Report(tests.Context(t), repts, nil, aos) assert.EqualError(t, err, "buildReportShouldFail=true") }) @@ -856,7 +857,7 @@ func Test_Plugin_Report(t *testing.T) { newAttributedObservation(t, newValidMercuryObservationProto()), newUnparseableAttributedObservation(), } - _, _, err := rp.Report(repts, nil, aos) + _, _, err := rp.Report(tests.Context(t), repts, nil, aos) assert.EqualError(t, err, "report with len 9999 violates MaxReportLength limit set by ReportCodec (1248)") }) @@ -868,7 +869,7 @@ func Test_Plugin_Report(t *testing.T) { newAttributedObservation(t, newValidMercuryObservationProto()), newUnparseableAttributedObservation(), } - _, _, err := rp.Report(repts, nil, aos) + _, _, err := rp.Report(tests.Context(t), repts, nil, aos) assert.EqualError(t, err, "report may not have zero length (invariant violation)") }) @@ -892,7 +893,7 @@ func Test_Plugin_Report(t *testing.T) { newAttributedObservation(t, newValidMercuryObservationProto()), newAttributedObservation(t, newValidMercuryObservationProto()), } - should, report, err := rp.Report(repts, previousReport, aos) + should, report, err := rp.Report(tests.Context(t), repts, previousReport, aos) assert.True(t, should) assert.Equal(t, codec.builtReport, report) @@ -911,7 +912,7 @@ func Test_Plugin_Report(t *testing.T) { newAttributedObservation(t, newValidMercuryObservationProto()), newAttributedObservation(t, newValidMercuryObservationProto()), } - should, _, err := rp.Report(repts, previousReport, aos) + should, _, err := rp.Report(tests.Context(t), repts, previousReport, aos) assert.False(t, should) assert.EqualError(t, err, "test error current block fail") @@ -926,7 +927,7 @@ func Test_Plugin_Report(t *testing.T) { newAttributedObservation(t, newValidMercuryObservationProto()), newAttributedObservation(t, newValidMercuryObservationProto()), } - should, _, err := rp.Report(repts, previousReport, aos) + should, _, err := rp.Report(tests.Context(t), repts, previousReport, aos) assert.False(t, should) assert.NoError(t, err) diff --git a/mercury/v2/mercury.go b/mercury/v2/mercury.go index ec5f592..ad6660a 100644 --- a/mercury/v2/mercury.go +++ b/mercury/v2/mercury.go @@ -64,18 +64,18 @@ func NewFactory(ds DataSource, lggr logger.Logger, occ mercurytypes.OnchainConfi return Factory{ds, lggr, occ, rc} } -func (fac Factory) NewMercuryPlugin(configuration ocr3types.MercuryPluginConfig) (ocr3types.MercuryPlugin, ocr3types.MercuryPluginInfo, error) { +func (fac Factory) NewMercuryPlugin(ctx context.Context, configuration ocr3types.MercuryPluginConfig) (ocr3types.MercuryPlugin, ocr3types.MercuryPluginInfo, error) { offchainConfig, err := mercury.DecodeOffchainConfig(configuration.OffchainConfig) if err != nil { return nil, ocr3types.MercuryPluginInfo{}, err } - onchainConfig, err := fac.onchainConfigCodec.Decode(configuration.OnchainConfig) + onchainConfig, err := fac.onchainConfigCodec.Decode(ctx, configuration.OnchainConfig) if err != nil { return nil, ocr3types.MercuryPluginInfo{}, err } - maxReportLength, err := fac.reportCodec.MaxReportLength(configuration.N) + maxReportLength, err := fac.reportCodec.MaxReportLength(ctx, configuration.N) if err != nil { return nil, ocr3types.MercuryPluginInfo{}, err } @@ -262,7 +262,7 @@ func parseAttributedObservations(lggr logger.Logger, aos []types.AttributedObser return paos } -func (rp *reportingPlugin) Report(repts types.ReportTimestamp, previousReport types.Report, aos []types.AttributedObservation) (shouldReport bool, report types.Report, err error) { +func (rp *reportingPlugin) Report(ctx context.Context, repts types.ReportTimestamp, previousReport types.Report, aos []types.AttributedObservation) (shouldReport bool, report types.Report, err error) { paos := parseAttributedObservations(rp.logger, aos) if len(paos) == 0 { @@ -274,7 +274,7 @@ func (rp *reportingPlugin) Report(repts types.ReportTimestamp, previousReport ty return false, nil, pkgerrors.Errorf("only received %v valid attributed observations, but need at least f+1 (%v)", len(paos), rp.f+1) } - rf, err := rp.buildReportFields(previousReport, paos) + rf, err := rp.buildReportFields(ctx, previousReport, paos) if err != nil { rp.logger.Errorw("failed to build report fields", "paos", paos, "f", rp.f, "reportFields", rf, "repts", repts, "err", err) return false, nil, err @@ -291,7 +291,7 @@ func (rp *reportingPlugin) Report(repts types.ReportTimestamp, previousReport ty } rp.logger.Debugw("shouldReport: yes", "repts", repts) - report, err = rp.reportCodec.BuildReport(rf) + report, err = rp.reportCodec.BuildReport(ctx, rf) if err != nil { rp.logger.Debugw("failed to BuildReport", "paos", paos, "f", rp.f, "reportFields", rf, "repts", repts) return false, nil, err @@ -306,14 +306,14 @@ func (rp *reportingPlugin) Report(repts types.ReportTimestamp, previousReport ty return true, report, nil } -func (rp *reportingPlugin) buildReportFields(previousReport types.Report, paos []PAO) (rf v2.ReportFields, merr error) { +func (rp *reportingPlugin) buildReportFields(ctx context.Context, previousReport types.Report, paos []PAO) (rf v2.ReportFields, merr error) { mPaos := convert(paos) rf.Timestamp = mercury.GetConsensusTimestamp(mPaos) var err error if previousReport != nil { var maxFinalizedTimestamp uint32 - maxFinalizedTimestamp, err = rp.reportCodec.ObservationTimestampFromReport(previousReport) + maxFinalizedTimestamp, err = rp.reportCodec.ObservationTimestampFromReport(ctx, previousReport) merr = errors.Join(merr, err) rf.ValidFromTimestamp = maxFinalizedTimestamp + 1 } else { diff --git a/mercury/v2/mercury_test.go b/mercury/v2/mercury_test.go index ff64d0a..e75a1b8 100644 --- a/mercury/v2/mercury_test.go +++ b/mercury/v2/mercury_test.go @@ -18,6 +18,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/logger" mercurytypes "github.com/smartcontractkit/chainlink-common/pkg/types/mercury" v2 "github.com/smartcontractkit/chainlink-common/pkg/types/mercury/v2" + "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" "github.com/smartcontractkit/libocr/commontypes" "github.com/smartcontractkit/libocr/offchainreporting2plus/types" @@ -41,17 +42,17 @@ type testReportCodec struct { err error } -func (rc *testReportCodec) BuildReport(rf v2.ReportFields) (types.Report, error) { +func (rc *testReportCodec) BuildReport(ctx context.Context, rf v2.ReportFields) (types.Report, error) { rc.builtReportFields = &rf return rc.builtReport, nil } -func (rc testReportCodec) MaxReportLength(n int) (int, error) { +func (rc testReportCodec) MaxReportLength(ctx context.Context, n int) (int, error) { return 123, nil } -func (rc testReportCodec) ObservationTimestampFromReport(types.Report) (uint32, error) { +func (rc testReportCodec) ObservationTimestampFromReport(context.Context, types.Report) (uint32, error) { return rc.observationTimestamp, rc.err } @@ -64,7 +65,7 @@ func newTestReportPlugin(t *testing.T, codec *testReportCodec, ds *testDataSourc Min: big.NewInt(1), Max: big.NewInt(1000), } - maxReportLength, _ := codec.MaxReportLength(4) + maxReportLength, _ := codec.MaxReportLength(tests.Context(t), 4) return &reportingPlugin{ offchainConfig: offchainConfig, onchainConfig: onchainConfig, @@ -166,7 +167,7 @@ func Test_Plugin_Report(t *testing.T) { t.Run("when previous report is nil", func(t *testing.T) { t.Run("errors if not enough attributed observations", func(t *testing.T) { - _, _, err := rp.Report(repts, nil, newValidAos(t)[0:1]) + _, _, err := rp.Report(tests.Context(t), repts, nil, newValidAos(t)[0:1]) assert.EqualError(t, err, "only received 1 valid attributed observations, but need at least f+1 (2)") }) t.Run("errors if too many maxFinalizedTimestamp observations are invalid", func(t *testing.T) { @@ -176,7 +177,7 @@ func Test_Plugin_Report(t *testing.T) { ps[2].MaxFinalizedTimestampValid = false aos := newValidAos(t, ps...) - should, _, err := rp.Report(types.ReportTimestamp{}, nil, aos) + should, _, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, nil, aos) assert.False(t, should) assert.EqualError(t, err, "fewer than f+1 observations have a valid maxFinalizedTimestamp (got: 1/4)") }) @@ -188,7 +189,7 @@ func Test_Plugin_Report(t *testing.T) { ps[3].MaxFinalizedTimestamp = math.MaxUint32 aos := newValidAos(t, ps...) - should, _, err := rp.Report(types.ReportTimestamp{}, nil, aos) + should, _, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, nil, aos) assert.False(t, should) assert.EqualError(t, err, "maxFinalizedTimestamp is too large, got: 4294967295") }) @@ -196,7 +197,7 @@ func Test_Plugin_Report(t *testing.T) { t.Run("succeeds and generates validFromTimestamp from maxFinalizedTimestamp when maxFinalizedTimestamp is positive", func(t *testing.T) { aos := newValidAos(t) - should, report, err := rp.Report(types.ReportTimestamp{}, nil, aos) + should, report, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, nil, aos) assert.True(t, should) assert.NoError(t, err) assert.Equal(t, codec.builtReport, report) @@ -217,7 +218,7 @@ func Test_Plugin_Report(t *testing.T) { } aos := newValidAos(t, protos...) - should, report, err := rp.Report(types.ReportTimestamp{}, nil, aos) + should, report, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, nil, aos) assert.True(t, should) assert.NoError(t, err) assert.Equal(t, codec.builtReport, report) @@ -238,7 +239,7 @@ func Test_Plugin_Report(t *testing.T) { } aos := newValidAos(t, protos...) - should, report, err := rp.Report(types.ReportTimestamp{}, nil, aos) + should, report, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, nil, aos) assert.True(t, should) assert.NoError(t, err) assert.Equal(t, codec.builtReport, report) @@ -257,7 +258,7 @@ func Test_Plugin_Report(t *testing.T) { aos := newValidAos(t) aos[0] = newUnparseableAttributedObservation() - should, report, err := rp.Report(repts, nil, aos) + should, report, err := rp.Report(tests.Context(t), repts, nil, aos) require.NoError(t, err) assert.True(t, should) @@ -290,7 +291,7 @@ func Test_Plugin_Report(t *testing.T) { } aos := newValidAos(t, protos...) - should, report, err := rp.Report(repts, previousReport, aos) + should, report, err := rp.Report(tests.Context(t), repts, previousReport, aos) require.NoError(t, err) assert.True(t, should) @@ -310,7 +311,7 @@ func Test_Plugin_Report(t *testing.T) { codec.err = errors.New("something exploded trying to extract timestamp") aos := newValidAos(t) - should, _, err := rp.Report(types.ReportTimestamp{}, previousReport, aos) + should, _, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, previousReport, aos) assert.False(t, should) assert.EqualError(t, err, "something exploded trying to extract timestamp") }) @@ -324,7 +325,7 @@ func Test_Plugin_Report(t *testing.T) { } aos := newValidAos(t, protos...) - should, _, err := rp.Report(types.ReportTimestamp{}, previousReport, aos) + should, _, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, previousReport, aos) assert.False(t, should) assert.NoError(t, err) }) @@ -339,7 +340,7 @@ func Test_Plugin_Report(t *testing.T) { } aos := newValidAos(t, protos...) - should, report, err := rp.Report(types.ReportTimestamp{}, previousReport, aos) + should, report, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, previousReport, aos) assert.True(t, should) assert.NoError(t, err) @@ -356,7 +357,7 @@ func Test_Plugin_Report(t *testing.T) { aos := newValidAos(t) codec.builtReport = make([]byte, 1<<16) - _, _, err := rp.Report(types.ReportTimestamp{}, nil, aos) + _, _, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, nil, aos) assert.EqualError(t, err, "report with len 65536 violates MaxReportLength limit set by ReportCodec (123)") }) @@ -364,7 +365,7 @@ func Test_Plugin_Report(t *testing.T) { t.Run("Report errors when the report length is 0", func(t *testing.T) { aos := newValidAos(t) codec.builtReport = []byte{} - _, _, err := rp.Report(types.ReportTimestamp{}, nil, aos) + _, _, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, nil, aos) assert.EqualError(t, err, "report may not have zero length (invariant violation)") }) diff --git a/mercury/v3/mercury.go b/mercury/v3/mercury.go index 853b7a1..9aa5989 100644 --- a/mercury/v3/mercury.go +++ b/mercury/v3/mercury.go @@ -66,18 +66,18 @@ func NewFactory(ds DataSource, lggr logger.Logger, occ mercurytypes.OnchainConfi return Factory{ds, lggr, occ, rc} } -func (fac Factory) NewMercuryPlugin(configuration ocr3types.MercuryPluginConfig) (ocr3types.MercuryPlugin, ocr3types.MercuryPluginInfo, error) { +func (fac Factory) NewMercuryPlugin(ctx context.Context, configuration ocr3types.MercuryPluginConfig) (ocr3types.MercuryPlugin, ocr3types.MercuryPluginInfo, error) { offchainConfig, err := mercury.DecodeOffchainConfig(configuration.OffchainConfig) if err != nil { return nil, ocr3types.MercuryPluginInfo{}, err } - onchainConfig, err := fac.onchainConfigCodec.Decode(configuration.OnchainConfig) + onchainConfig, err := fac.onchainConfigCodec.Decode(ctx, configuration.OnchainConfig) if err != nil { return nil, ocr3types.MercuryPluginInfo{}, err } - maxReportLength, err := fac.reportCodec.MaxReportLength(configuration.N) + maxReportLength, err := fac.reportCodec.MaxReportLength(ctx, configuration.N) if err != nil { return nil, ocr3types.MercuryPluginInfo{}, err } @@ -295,7 +295,7 @@ func parseAttributedObservations(lggr logger.Logger, aos []types.AttributedObser return paos } -func (rp *reportingPlugin) Report(repts types.ReportTimestamp, previousReport types.Report, aos []types.AttributedObservation) (shouldReport bool, report types.Report, err error) { +func (rp *reportingPlugin) Report(ctx context.Context, repts types.ReportTimestamp, previousReport types.Report, aos []types.AttributedObservation) (shouldReport bool, report types.Report, err error) { paos := parseAttributedObservations(rp.logger, aos) if len(paos) == 0 { @@ -307,7 +307,7 @@ func (rp *reportingPlugin) Report(repts types.ReportTimestamp, previousReport ty return false, nil, pkgerrors.Errorf("only received %v valid attributed observations, but need at least f+1 (%v)", len(paos), rp.f+1) } - rf, err := rp.buildReportFields(previousReport, paos) + rf, err := rp.buildReportFields(ctx, previousReport, paos) if err != nil { rp.logger.Errorw("failed to build report fields", "paos", paos, "f", rp.f, "reportFields", rf, "repts", repts, "err", err) return false, nil, err @@ -324,7 +324,7 @@ func (rp *reportingPlugin) Report(repts types.ReportTimestamp, previousReport ty } rp.logger.Debugw("shouldReport: yes", "repts", repts) - report, err = rp.reportCodec.BuildReport(rf) + report, err = rp.reportCodec.BuildReport(ctx, rf) if err != nil { rp.logger.Debugw("failed to BuildReport", "paos", paos, "f", rp.f, "reportFields", rf, "repts", repts) return false, nil, err @@ -339,14 +339,14 @@ func (rp *reportingPlugin) Report(repts types.ReportTimestamp, previousReport ty return true, report, nil } -func (rp *reportingPlugin) buildReportFields(previousReport types.Report, paos []PAO) (rf v3.ReportFields, merr error) { +func (rp *reportingPlugin) buildReportFields(ctx context.Context, previousReport types.Report, paos []PAO) (rf v3.ReportFields, merr error) { mPaos := convert(paos) rf.Timestamp = mercury.GetConsensusTimestamp(mPaos) var err error if previousReport != nil { var maxFinalizedTimestamp uint32 - maxFinalizedTimestamp, err = rp.reportCodec.ObservationTimestampFromReport(previousReport) + maxFinalizedTimestamp, err = rp.reportCodec.ObservationTimestampFromReport(ctx, previousReport) merr = errors.Join(merr, err) rf.ValidFromTimestamp = maxFinalizedTimestamp + 1 } else { diff --git a/mercury/v3/mercury_test.go b/mercury/v3/mercury_test.go index 1d01f61..cf2b204 100644 --- a/mercury/v3/mercury_test.go +++ b/mercury/v3/mercury_test.go @@ -21,6 +21,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/logger" mercurytypes "github.com/smartcontractkit/chainlink-common/pkg/types/mercury" v3 "github.com/smartcontractkit/chainlink-common/pkg/types/mercury/v3" + "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" "github.com/smartcontractkit/chainlink-data-streams/mercury" ) @@ -41,17 +42,17 @@ type testReportCodec struct { err error } -func (rc *testReportCodec) BuildReport(rf v3.ReportFields) (types.Report, error) { +func (rc *testReportCodec) BuildReport(ctx context.Context, rf v3.ReportFields) (types.Report, error) { rc.builtReportFields = &rf return rc.builtReport, nil } -func (rc testReportCodec) MaxReportLength(n int) (int, error) { +func (rc testReportCodec) MaxReportLength(ctx context.Context, n int) (int, error) { return 123, nil } -func (rc testReportCodec) ObservationTimestampFromReport(types.Report) (uint32, error) { +func (rc testReportCodec) ObservationTimestampFromReport(context.Context, types.Report) (uint32, error) { return rc.observationTimestamp, rc.err } @@ -64,7 +65,7 @@ func newTestReportPlugin(t *testing.T, codec *testReportCodec, ds *testDataSourc Min: big.NewInt(1), Max: big.NewInt(1000), } - maxReportLength, _ := codec.MaxReportLength(4) + maxReportLength, _ := codec.MaxReportLength(tests.Context(t), 4) return &reportingPlugin{ offchainConfig: offchainConfig, onchainConfig: onchainConfig, @@ -174,7 +175,7 @@ func Test_Plugin_Report(t *testing.T) { t.Run("when previous report is nil", func(t *testing.T) { t.Run("errors if not enough attributed observations", func(t *testing.T) { - _, _, err := rp.Report(repts, nil, newValidAos(t)[0:1]) + _, _, err := rp.Report(tests.Context(t), repts, nil, newValidAos(t)[0:1]) assert.EqualError(t, err, "only received 1 valid attributed observations, but need at least f+1 (2)") }) @@ -185,7 +186,7 @@ func Test_Plugin_Report(t *testing.T) { ps[2].MaxFinalizedTimestampValid = false aos := newValidAos(t, ps...) - should, _, err := rp.Report(types.ReportTimestamp{}, nil, aos) + should, _, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, nil, aos) assert.False(t, should) assert.EqualError(t, err, "fewer than f+1 observations have a valid maxFinalizedTimestamp (got: 1/4)") }) @@ -197,7 +198,7 @@ func Test_Plugin_Report(t *testing.T) { ps[3].MaxFinalizedTimestamp = math.MaxUint32 aos := newValidAos(t, ps...) - should, _, err := rp.Report(types.ReportTimestamp{}, nil, aos) + should, _, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, nil, aos) assert.False(t, should) assert.EqualError(t, err, "maxFinalizedTimestamp is too large, got: 4294967295") }) @@ -205,7 +206,7 @@ func Test_Plugin_Report(t *testing.T) { t.Run("succeeds and generates validFromTimestamp from maxFinalizedTimestamp when maxFinalizedTimestamp is positive", func(t *testing.T) { aos := newValidAos(t) - should, report, err := rp.Report(types.ReportTimestamp{}, nil, aos) + should, report, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, nil, aos) assert.True(t, should) assert.NoError(t, err) assert.Equal(t, codec.builtReport, report) @@ -228,7 +229,7 @@ func Test_Plugin_Report(t *testing.T) { } aos := newValidAos(t, protos...) - should, report, err := rp.Report(types.ReportTimestamp{}, nil, aos) + should, report, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, nil, aos) assert.True(t, should) assert.NoError(t, err) assert.Equal(t, codec.builtReport, report) @@ -251,7 +252,7 @@ func Test_Plugin_Report(t *testing.T) { } aos := newValidAos(t, protos...) - should, report, err := rp.Report(types.ReportTimestamp{}, nil, aos) + should, report, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, nil, aos) assert.True(t, should) assert.NoError(t, err) assert.Equal(t, codec.builtReport, report) @@ -272,7 +273,7 @@ func Test_Plugin_Report(t *testing.T) { aos := newValidAos(t) aos[0] = newUnparseableAttributedObservation() - should, report, err := rp.Report(repts, nil, aos) + should, report, err := rp.Report(tests.Context(t), repts, nil, aos) require.NoError(t, err) assert.True(t, should) @@ -307,7 +308,7 @@ func Test_Plugin_Report(t *testing.T) { } aos := newValidAos(t, protos...) - should, report, err := rp.Report(repts, previousReport, aos) + should, report, err := rp.Report(tests.Context(t), repts, previousReport, aos) require.NoError(t, err) assert.True(t, should) @@ -329,7 +330,7 @@ func Test_Plugin_Report(t *testing.T) { codec.err = errors.New("something exploded trying to extract timestamp") aos := newValidAos(t) - should, _, err := rp.Report(types.ReportTimestamp{}, previousReport, aos) + should, _, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, previousReport, aos) assert.False(t, should) assert.EqualError(t, err, "something exploded trying to extract timestamp") }) @@ -343,7 +344,7 @@ func Test_Plugin_Report(t *testing.T) { } aos := newValidAos(t, protos...) - should, _, err := rp.Report(types.ReportTimestamp{}, previousReport, aos) + should, _, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, previousReport, aos) assert.False(t, should) assert.NoError(t, err) }) @@ -358,7 +359,7 @@ func Test_Plugin_Report(t *testing.T) { } aos := newValidAos(t, protos...) - should, report, err := rp.Report(types.ReportTimestamp{}, previousReport, aos) + should, report, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, previousReport, aos) assert.True(t, should) assert.NoError(t, err) @@ -375,7 +376,7 @@ func Test_Plugin_Report(t *testing.T) { aos := newValidAos(t) codec.builtReport = make([]byte, 1<<16) - _, _, err := rp.Report(types.ReportTimestamp{}, nil, aos) + _, _, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, nil, aos) assert.EqualError(t, err, "report with len 65536 violates MaxReportLength limit set by ReportCodec (123)") }) @@ -383,7 +384,7 @@ func Test_Plugin_Report(t *testing.T) { t.Run("Report errors when the report length is 0", func(t *testing.T) { aos := newValidAos(t) codec.builtReport = []byte{} - _, _, err := rp.Report(types.ReportTimestamp{}, nil, aos) + _, _, err := rp.Report(tests.Context(t), types.ReportTimestamp{}, nil, aos) assert.EqualError(t, err, "report may not have zero length (invariant violation)") })