From 9c24f5106ce28aee57376dcd249b32ff002eec73 Mon Sep 17 00:00:00 2001 From: Fergal Gribben Date: Tue, 19 Dec 2023 23:41:46 +0000 Subject: [PATCH 1/6] Move automation types into common Add service functions to BlockSubscriber and LogEventProvider Add a makefile with a generate task Generate mocks for automation types --- GNUmakefile | 7 + pkg/types/automation/basetypes.go | 349 +++++++++++ pkg/types/automation/basetypes_test.go | 588 ++++++++++++++++++ pkg/types/automation/interfaces.go | 154 +++++ .../mocks/block_subscriber.generated.go | 121 ++++ .../conditionalupkeepprovider.generated.go | 60 ++ .../automation/mocks/coordinator.generated.go | 156 +++++ .../automation/mocks/encoder.generated.go | 93 +++ .../mocks/logeventprovider.generated.go | 96 +++ .../mocks/metadatastore.generated.go | 133 ++++ .../mocks/payloadbuilder.generated.go | 67 ++ pkg/types/automation/mocks/ratio.generated.go | 42 ++ .../mocks/recoverableprovider.generated.go | 60 ++ .../mocks/result_store.generated.go | 79 +++ .../automation/mocks/runnable.generated.go | 67 ++ .../transmit_event_provider.generated.go | 60 ++ .../automation/mocks/upkeep_state_reader.go | 67 ++ .../mocks/upkeep_state_updater.generated.go | 48 ++ pkg/types/automation/trigger.go | 87 +++ pkg/types/provider_automation.go | 11 + 20 files changed, 2345 insertions(+) create mode 100644 GNUmakefile create mode 100644 pkg/types/automation/basetypes.go create mode 100644 pkg/types/automation/basetypes_test.go create mode 100644 pkg/types/automation/interfaces.go create mode 100644 pkg/types/automation/mocks/block_subscriber.generated.go create mode 100644 pkg/types/automation/mocks/conditionalupkeepprovider.generated.go create mode 100644 pkg/types/automation/mocks/coordinator.generated.go create mode 100644 pkg/types/automation/mocks/encoder.generated.go create mode 100644 pkg/types/automation/mocks/logeventprovider.generated.go create mode 100644 pkg/types/automation/mocks/metadatastore.generated.go create mode 100644 pkg/types/automation/mocks/payloadbuilder.generated.go create mode 100644 pkg/types/automation/mocks/ratio.generated.go create mode 100644 pkg/types/automation/mocks/recoverableprovider.generated.go create mode 100644 pkg/types/automation/mocks/result_store.generated.go create mode 100644 pkg/types/automation/mocks/runnable.generated.go create mode 100644 pkg/types/automation/mocks/transmit_event_provider.generated.go create mode 100644 pkg/types/automation/mocks/upkeep_state_reader.go create mode 100644 pkg/types/automation/mocks/upkeep_state_updater.generated.go create mode 100644 pkg/types/automation/trigger.go diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 000000000..b3b7d3f1b --- /dev/null +++ b/GNUmakefile @@ -0,0 +1,7 @@ +.PHONY: generate +generate: mockery + go generate -x ./... + +.PHONY: mockery +mockery: $(mockery) ## Install mockery. + go install github.com/vektra/mockery/v2@v2.38.0 diff --git a/pkg/types/automation/basetypes.go b/pkg/types/automation/basetypes.go new file mode 100644 index 000000000..45874ccde --- /dev/null +++ b/pkg/types/automation/basetypes.go @@ -0,0 +1,349 @@ +package automation + +import ( + "encoding/hex" + "encoding/json" + "fmt" + "math/big" + "strings" + "time" +) + +const ( + checkResultDelimiter = 0x09 +) + +// checkResultStringTemplate is a JSON template, used for debugging purposes only. +var checkResultStringTemplate = `{ + "PipelineExecutionState":%d, + "Retryable":%v, + "Eligible":%v, + "IneligibilityReason":%d, + "UpkeepID":%s, + "Trigger":%s, + "WorkID":"%s", + "GasAllocated":%d, + "PerformData":"%s", + "FastGasWei":%s, + "LinkNative":%s, + "RetryInterval":%d +}` + +func init() { + checkResultStringTemplate = strings.Replace(checkResultStringTemplate, " ", "", -1) + checkResultStringTemplate = strings.Replace(checkResultStringTemplate, "\t", "", -1) + checkResultStringTemplate = strings.Replace(checkResultStringTemplate, "\n", "", -1) +} + +type UpkeepType uint8 + +const ( + // Exploratory AUTO 4335: add type for unknown + ConditionTrigger UpkeepType = iota + LogTrigger +) + +type TransmitEventType int + +const ( + UnknownEvent TransmitEventType = iota + PerformEvent + StaleReportEvent + ReorgReportEvent + InsufficientFundsReportEvent +) + +// UpkeepState is a final state of some unit of work. +type UpkeepState uint8 + +const ( + UnknownState UpkeepState = iota + // Performed means the upkeep was performed + Performed + // Ineligible means the upkeep was not eligible to be performed + Ineligible +) + +// UpkeepIdentifier is a unique identifier for the upkeep, represented as uint256 in the contract. +type UpkeepIdentifier [32]byte + +// String returns a base 10 numerical string representation of the upkeep identifier. +func (u UpkeepIdentifier) String() string { + return u.BigInt().String() +} + +func (u UpkeepIdentifier) BigInt() *big.Int { + return big.NewInt(0).SetBytes(u[:]) +} + +// FromBigInt sets the upkeep identifier from a big.Int, +// returning true if the big.Int is valid and false otherwise. +// in case of an invalid big.Int the upkeep identifier is set to 32 zeros. +func (u *UpkeepIdentifier) FromBigInt(i *big.Int) bool { + *u = [32]byte{} + if i.Cmp(big.NewInt(0)) == -1 { + return false + } + b := i.Bytes() + if len(b) == 0 { + return true + } + if len(b) <= 32 { + copy(u[32-len(b):], i.Bytes()) + return true + } + return false +} + +type BlockNumber uint64 + +// BlockKey represent a block (number and hash) +// NOTE: This struct is sent on the p2p network as part of observations to get quorum +// Any change here should be backwards compatible and should keep validation and +// quorum requirements in mind. Please ensure to get a proper review along with an +// upgrade plan before changing this +type BlockKey struct { + Number BlockNumber + Hash [32]byte +} + +type TransmitEvent struct { + // Type describes the type of event + Type TransmitEventType + // TransmitBlock is the block height of the transmit event + TransmitBlock BlockNumber + // Confirmations is the block height behind latest + Confirmations int64 + // TransactionHash is the hash for the transaction where the event originated + TransactionHash [32]byte + // UpkeepID uniquely identifies the upkeep in the registry + UpkeepID UpkeepIdentifier + // WorkID uniquely identifies the unit of work for the specified upkeep + WorkID string + // CheckBlock is the block value that the upkeep was originally checked at + CheckBlock BlockNumber +} + +// NOTE: This struct is sent on the p2p network as part of observations to get quorum +// Any change here should be backwards compatible and should keep validation and +// quorum requirements in mind. Any field that is needed to be encoded should be added +// as well to checkResultMsg struct, and to be encoded/decoded in the MarshalJSON and +// UnmarshalJSON functions. Please ensure to get a proper review along with an upgrade +// plan before changing this. +type CheckResult struct { + // zero if success, else indicates an error code + PipelineExecutionState uint8 + // if PipelineExecutionState is non zero, then retryable indicates that the same + // payload can be processed again in order to get a successful execution + Retryable bool + // Rest of these fields are only applicable if PipelineExecutionState is zero + // Eligible indicates whether this result is eligible to be performed + Eligible bool + // If result is not eligible then the reason it failed. Should be 0 if eligible + IneligibilityReason uint8 + // Upkeep is all the information that identifies the upkeep + UpkeepID UpkeepIdentifier + // Trigger is the event that triggered the upkeep to be checked + Trigger Trigger + // WorkID represents the unit of work for the check result + // Exploratory: Make workID an internal field and an external WorkID() function which generates WID + WorkID string + // GasAllocated is the gas to provide an upkeep in a report + GasAllocated uint64 + // PerformData is the raw data returned when simulating an upkeep perform + PerformData []byte + // FastGasWei is the fast gas price in wei when performing this upkeep + FastGasWei *big.Int + // Link to native ratio to be used when performing this upkeep + LinkNative *big.Int + // RetryInterval is the time interval after which the same payload can be retried. + // This field is used is special cases (such as mercury lookup), where we want to + // have a different retry interval than the default one (30s) + // NOTE: this field is not encoded in JSON and is only used internally + RetryInterval time.Duration +} + +// checkResultMsg is used for encoding and decoding check results. +type checkResultMsg struct { + PipelineExecutionState uint8 + Retryable bool + Eligible bool + IneligibilityReason uint8 + UpkeepID UpkeepIdentifier + Trigger Trigger + WorkID string + GasAllocated uint64 + PerformData []byte + FastGasWei *big.Int + LinkNative *big.Int +} + +// UniqueID returns a unique identifier for the check result. +// It is used to achieve quorum on results before being sent within a report. +func (r CheckResult) UniqueID() string { + var resultBytes []byte + + resultBytes = append(resultBytes, r.PipelineExecutionState) + resultBytes = append(resultBytes, checkResultDelimiter) + + resultBytes = append(resultBytes, []byte(fmt.Sprintf("%+v", r.Retryable))...) + resultBytes = append(resultBytes, checkResultDelimiter) + + resultBytes = append(resultBytes, []byte(fmt.Sprintf("%+v", r.Eligible))...) + resultBytes = append(resultBytes, checkResultDelimiter) + + resultBytes = append(resultBytes, r.IneligibilityReason) + resultBytes = append(resultBytes, checkResultDelimiter) + + resultBytes = append(resultBytes, r.UpkeepID[:]...) + resultBytes = append(resultBytes, checkResultDelimiter) + + resultBytes = append(resultBytes, r.Trigger.BlockHash[:]...) + resultBytes = append(resultBytes, checkResultDelimiter) + + resultBytes = append(resultBytes, big.NewInt(int64(r.Trigger.BlockNumber)).Bytes()...) + resultBytes = append(resultBytes, checkResultDelimiter) + + if r.Trigger.LogTriggerExtension != nil { + // Note: We encode the whole trigger extension so the behaiour of + // LogTriggerExtentsion.BlockNumber and LogTriggerExtentsion.BlockHash should be + // consistent across nodes when sending observations + resultBytes = append(resultBytes, []byte(fmt.Sprintf("%+v", r.Trigger.LogTriggerExtension))...) + } + resultBytes = append(resultBytes, checkResultDelimiter) + + resultBytes = append(resultBytes, r.WorkID[:]...) + resultBytes = append(resultBytes, checkResultDelimiter) + + resultBytes = append(resultBytes, big.NewInt(int64(r.GasAllocated)).Bytes()...) + resultBytes = append(resultBytes, checkResultDelimiter) + + resultBytes = append(resultBytes, r.PerformData[:]...) + resultBytes = append(resultBytes, checkResultDelimiter) + + if r.FastGasWei != nil { + resultBytes = append(resultBytes, r.FastGasWei.Bytes()...) + } + resultBytes = append(resultBytes, checkResultDelimiter) + + if r.LinkNative != nil { + resultBytes = append(resultBytes, r.LinkNative.Bytes()...) + } + resultBytes = append(resultBytes, checkResultDelimiter) + + return fmt.Sprintf("%x", resultBytes) +} + +// NOTE: this function is used for debugging purposes only. +// for encoding check results, please use the Encoder interface +func (r CheckResult) String() string { + return fmt.Sprintf( + checkResultStringTemplate, r.PipelineExecutionState, r.Retryable, r.Eligible, + r.IneligibilityReason, r.UpkeepID, r.Trigger, r.WorkID, r.GasAllocated, + hex.EncodeToString(r.PerformData), r.FastGasWei, r.LinkNative, r.RetryInterval, + ) +} + +func (r CheckResult) MarshalJSON() ([]byte, error) { + crm := &checkResultMsg{ + PipelineExecutionState: r.PipelineExecutionState, + Retryable: r.Retryable, + Eligible: r.Eligible, + IneligibilityReason: r.IneligibilityReason, + UpkeepID: r.UpkeepID, + Trigger: r.Trigger, + WorkID: r.WorkID, + GasAllocated: r.GasAllocated, + PerformData: r.PerformData, + FastGasWei: r.FastGasWei, + LinkNative: r.LinkNative, + } + + return json.Marshal(crm) +} + +func (r *CheckResult) UnmarshalJSON(data []byte) error { + var crm checkResultMsg + + if err := json.Unmarshal(data, &crm); err != nil { + return err + } + + r.PipelineExecutionState = crm.PipelineExecutionState + r.Retryable = crm.Retryable + r.Eligible = crm.Eligible + r.IneligibilityReason = crm.IneligibilityReason + r.UpkeepID = crm.UpkeepID + r.Trigger = crm.Trigger + r.WorkID = crm.WorkID + r.GasAllocated = crm.GasAllocated + r.PerformData = crm.PerformData + r.FastGasWei = crm.FastGasWei + r.LinkNative = crm.LinkNative + + return nil +} + +// BlockHistory is a list of block keys +type BlockHistory []BlockKey + +func (bh BlockHistory) Latest() (BlockKey, error) { + if len(bh) == 0 { + return BlockKey{}, fmt.Errorf("empty block history") + } + + return bh[0], nil +} + +type UpkeepPayload struct { + // Upkeep is all the information that identifies the upkeep + UpkeepID UpkeepIdentifier + // Trigger is the event that triggered the upkeep to be checked + Trigger Trigger + // WorkID uniquely identifies the unit of work for the specified upkeep + WorkID string + // CheckData is the data used to check the upkeep + CheckData []byte +} + +// Determines whether the payload is empty, used within filtering +func (p UpkeepPayload) IsEmpty() bool { + return p.WorkID == "" +} + +// CoordinatedBlockProposal is used to represent a unit of work that can be performed +// after a check block has been coordinated between nodes. +// NOTE: This struct is sent on the p2p network as part of observations to get quorum +// Any change here should be backwards compatible and should keep validation and +// quorum requirements in mind. Please ensure to get a proper review along with an +// upgrade plan before changing this +// NOTE: Only the trigger.BlockHash and trigger.BlockNumber are coordinated across +// the network to get a quorum. WorkID is guaranteed to be correctly generated. +// Rest of the fields here SHOULD NOT BE TRUSTED as they can be manipulated by +// a single malicious node. +type CoordinatedBlockProposal struct { + // UpkeepID is the id of the proposed upkeep + UpkeepID UpkeepIdentifier + // Trigger represents the event that triggered the upkeep to be checked + Trigger Trigger + // WorkID represents the unit of work for the coordinated proposal + WorkID string +} + +// ReportedUpkeep contains details of an upkeep for which a report was generated. +type ReportedUpkeep struct { + // UpkeepID id of the underlying upkeep + UpkeepID UpkeepIdentifier + // Trigger data for the upkeep + Trigger Trigger + // WorkID represents the unit of work for the reported upkeep + WorkID string +} + +// RetryRecord is a record of a payload that can be retried after a certain interval. +type RetryRecord struct { + // payload is the desired unit of work to be retried + Payload UpkeepPayload + // Interval is the time interval after which the same payload can be retried. + Interval time.Duration +} diff --git a/pkg/types/automation/basetypes_test.go b/pkg/types/automation/basetypes_test.go new file mode 100644 index 000000000..84a9cc90f --- /dev/null +++ b/pkg/types/automation/basetypes_test.go @@ -0,0 +1,588 @@ +package automation + +import ( + "encoding/hex" + "encoding/json" + "fmt" + "math/big" + "reflect" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestTriggerUnmarshal(t *testing.T) { + input := Trigger{ + BlockNumber: 5, + BlockHash: [32]byte{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}, + LogTriggerExtension: &LogTriggerExtension{ + TxHash: [32]byte{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}, + Index: 99, + }, + } + + encoded, _ := json.Marshal(input) + + rawJSON := `{"BlockNumber":5,"BlockHash":[1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4],"LogTriggerExtension":{"TxHash":[1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4],"Index":99,"BlockHash":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"BlockNumber":0}}` + + // the encoded value above should match the rawjson expected + assert.Equal(t, rawJSON, string(encoded), "encoded should match expected") + + // the plugin will decode and re-encode the trigger value at least once + // before some decoding might happen + var decodeOnce Trigger + _ = json.Unmarshal([]byte(rawJSON), &decodeOnce) + + encoded, _ = json.Marshal(decodeOnce) + + // used the re-encoded output to verify data integrity + var output Trigger + err := json.Unmarshal(encoded, &output) + + assert.NoError(t, err, "no error expected from decoding") + + expected := Trigger{ + BlockNumber: 5, + BlockHash: [32]byte{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}, + LogTriggerExtension: &LogTriggerExtension{ + TxHash: [32]byte{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}, + Index: 99, + }, + } + + assert.Equal(t, expected, output, "decoding should leave extension in its raw encoded state") +} + +func TestTriggerString(t *testing.T) { + input := Trigger{ + BlockNumber: 5, + BlockHash: [32]byte{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}, + LogTriggerExtension: &LogTriggerExtension{ + TxHash: [32]byte{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}, + Index: 99, + }, + } + + stringified := fmt.Sprintf("%v", input) + expected := ` + { + "BlockNumber":5, + "BlockHash":"0102030401020304010203040102030401020304010203040102030401020304", + "LogTriggerExtension": { + "BlockHash":"0000000000000000000000000000000000000000000000000000000000000000", + "BlockNumber":0, + "Index":99, + "TxHash":"0102030401020304010203040102030401020304010203040102030401020304" + } + }` + + assertJSONEqual(t, expected, stringified) + + input = Trigger{ + BlockNumber: 5, + BlockHash: [32]byte{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}, + } + + stringified = fmt.Sprintf("%v", input) + expected = `{"BlockNumber":5,"BlockHash":"0102030401020304010203040102030401020304010203040102030401020304"}` + + assertJSONEqual(t, expected, stringified) +} + +func TestLogIdentifier(t *testing.T) { + input := Trigger{ + BlockNumber: 5, + BlockHash: [32]byte{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}, + LogTriggerExtension: &LogTriggerExtension{ + TxHash: [32]byte{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}, + Index: 99, + BlockHash: [32]byte{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}, + }, + } + + logIdentifier := input.LogTriggerExtension.LogIdentifier() + assert.Equal(t, hex.EncodeToString(logIdentifier), "0102030401020304010203040102030401020304010203040102030401020304010203040102030401020304010203040102030401020304010203040102030400000063") +} + +func TestTriggerUnmarshal_EmptyExtension(t *testing.T) { + input := Trigger{ + BlockNumber: 5, + BlockHash: [32]byte{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}, + } + + encoded, _ := json.Marshal(input) + + rawJSON := `{"BlockNumber":5,"BlockHash":[1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4],"LogTriggerExtension":null}` + + // the encoded value above should match the rawjson expected + assert.Equal(t, rawJSON, string(encoded), "encoded should match expected") + + // the plugin will decode and re-encode the trigger value at least once + // before some decoding might happen + var decodeOnce Trigger + _ = json.Unmarshal([]byte(rawJSON), &decodeOnce) + + encoded, _ = json.Marshal(decodeOnce) + + // used the re-encoded output to verify data integrity + var output Trigger + err := json.Unmarshal(encoded, &output) + + assert.NoError(t, err, "no error expected from decoding") + + expected := Trigger{ + BlockNumber: 5, + BlockHash: [32]byte{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}, + } + + assert.Equal(t, expected, output, "decoding should leave extension in its raw encoded state") +} + +func TestUpkeepIdentifier_BigInt(t *testing.T) { + tests := []struct { + name string + id *big.Int + want string + ignoreConvert bool + }{ + { + name: "log trigger from decimal", + id: func() *big.Int { + id, _ := big.NewInt(0).SetString("32329108151019397958065800113404894502874153543356521479058624064899121404671", 10) + return id + }(), + want: "32329108151019397958065800113404894502874153543356521479058624064899121404671", + }, + { + name: "condition trigger from hex", + id: func() *big.Int { + id, _ := big.NewInt(0).SetString("4779a07400000000000000000000000042d780684c0bbe59fab87e6ea7f3daff", 16) + return id + }(), + want: "32329108151019397958065800113404894502533871176435583015595249457467353193215", + }, + { + name: "0 upkeep ID", + id: big.NewInt(0), + want: "0", + }, + { + name: "random upkeep ID", + id: func() *big.Int { + id, _ := big.NewInt(0).SetString("32329108151019423423423", 10) + return id + }(), + want: "32329108151019423423423", + }, + { + name: "negative upkeep ID", + id: big.NewInt(-10), + want: "0", + ignoreConvert: true, + }, + { + name: "max upkeep ID (2^256-1)", + id: func() *big.Int { + id, _ := big.NewInt(0).SetString("115792089237316195423570985008687907853269984665640564039457584007913129639935", 10) + return id + }(), + want: "115792089237316195423570985008687907853269984665640564039457584007913129639935", + }, + { + name: "out of range upkeep ID (2^256)", + id: func() *big.Int { + id, _ := big.NewInt(0).SetString("115792089237316195423570985008687907853269984665640564039457584007913129639936", 10) + return id + }(), + want: "0", + ignoreConvert: true, + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + uid := new(UpkeepIdentifier) + ok := uid.FromBigInt(tc.id) + assert.Equal(t, !tc.ignoreConvert, ok) + assert.Equal(t, tc.want, uid.String()) + if !tc.ignoreConvert { + assert.Equal(t, tc.id.String(), uid.BigInt().String()) + } + }) + } +} + +func TestCheckResultEncoding(t *testing.T) { + tests := []struct { + name string + input CheckResult + expected string + decoded CheckResult + }{ + { + name: "check result with retry interval", + input: CheckResult{ + PipelineExecutionState: 1, + Retryable: true, + Eligible: true, + IneligibilityReason: 10, + UpkeepID: UpkeepIdentifier{1, 2, 3, 4, 5, 6, 7, 8}, + Trigger: Trigger{ + BlockNumber: 5, + BlockHash: [32]byte{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}, + LogTriggerExtension: &LogTriggerExtension{ + TxHash: [32]byte{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}, + Index: 99, + }, + }, + WorkID: "work id", + GasAllocated: 1001, + PerformData: []byte{1, 2, 3, 4, 5, 6}, + FastGasWei: big.NewInt(12), + LinkNative: big.NewInt(13), + RetryInterval: 1, + }, + expected: `{"PipelineExecutionState":1,"Retryable":true,"Eligible":true,"IneligibilityReason":10,"UpkeepID":[1,2,3,4,5,6,7,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"Trigger":{"BlockNumber":5,"BlockHash":[1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4],"LogTriggerExtension":{"TxHash":[1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4],"Index":99,"BlockHash":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"BlockNumber":0}},"WorkID":"work id","GasAllocated":1001,"PerformData":"AQIDBAUG","FastGasWei":12,"LinkNative":13}`, + decoded: CheckResult{ + PipelineExecutionState: 1, + Retryable: true, + Eligible: true, + IneligibilityReason: 10, + UpkeepID: UpkeepIdentifier{1, 2, 3, 4, 5, 6, 7, 8}, + Trigger: Trigger{ + BlockNumber: 5, + BlockHash: [32]byte{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}, + LogTriggerExtension: &LogTriggerExtension{ + TxHash: [32]byte{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}, + Index: 99, + }, + }, + WorkID: "work id", + GasAllocated: 1001, + PerformData: []byte{1, 2, 3, 4, 5, 6}, + FastGasWei: big.NewInt(12), + LinkNative: big.NewInt(13), + }, + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + encoded, err := json.Marshal(tc.input) + require.NoError(t, err) + assert.Equal(t, tc.expected, string(encoded)) + + var decoded CheckResult + err = json.Unmarshal(encoded, &decoded) + require.NoError(t, err) + assert.True(t, reflect.DeepEqual(tc.decoded, decoded)) + }) + } +} + +func TestCheckResultString(t *testing.T) { + input := CheckResult{ + PipelineExecutionState: 1, + Retryable: true, + Eligible: true, + IneligibilityReason: 10, + UpkeepID: UpkeepIdentifier{1, 2, 3, 4, 5, 6, 7, 8}, + Trigger: Trigger{ + BlockNumber: 5, + BlockHash: [32]byte{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}, + LogTriggerExtension: &LogTriggerExtension{ + TxHash: [32]byte{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}, + Index: 99, + }, + }, + WorkID: "work id", + GasAllocated: 1001, + PerformData: []byte{1, 2, 3, 4, 5, 6}, + FastGasWei: big.NewInt(12), + LinkNative: big.NewInt(13), + RetryInterval: 1, + } + + result := fmt.Sprintf("%v", input) + expected := ` + { + "PipelineExecutionState":1, + "Retryable":true, + "Eligible":true, + "IneligibilityReason":10, + "UpkeepID":455867356320691211288303676705517652851520854420902457558325773249309310976, + "Trigger": { + "BlockHash":"0102030401020304010203040102030401020304010203040102030401020304", + "BlockNumber":5, + "LogTriggerExtension": { + "BlockHash":"0000000000000000000000000000000000000000000000000000000000000000", + "BlockNumber":0, + "Index":99, + "TxHash":"0102030401020304010203040102030401020304010203040102030401020304" + } + }, + "WorkID":"work id", + "GasAllocated":1001, + "PerformData":"010203040506", + "FastGasWei":12, + "LinkNative":13, + "RetryInterval":1 + } + ` + assertJSONEqual(t, expected, result) + assertJSONContainsAllStructFields(t, result, input) +} + +func TestCheckResult_UniqueID(t *testing.T) { + for _, tc := range []struct { + name string + result CheckResult + wantID string + }{ + { + name: "empty check result", + result: CheckResult{ + PipelineExecutionState: 0, + Retryable: false, + Eligible: false, + IneligibilityReason: 0, + UpkeepID: UpkeepIdentifier{}, + Trigger: Trigger{}, + WorkID: "", + GasAllocated: 0, + PerformData: nil, + FastGasWei: nil, + LinkNative: nil, + }, + wantID: "000966616c73650966616c736509000900000000000000000000000000000000000000000000000000000000000000000900000000000000000000000000000000000000000000000000000000000000000909090909090909", + }, + { + name: "errored execution state", + result: CheckResult{ + PipelineExecutionState: 1, + Retryable: false, + Eligible: false, + IneligibilityReason: 0, + UpkeepID: UpkeepIdentifier{}, + Trigger: Trigger{}, + WorkID: "", + GasAllocated: 0, + PerformData: nil, + FastGasWei: nil, + LinkNative: nil, + }, + wantID: "010966616c73650966616c736509000900000000000000000000000000000000000000000000000000000000000000000900000000000000000000000000000000000000000000000000000000000000000909090909090909", + }, + { + name: "retryable errored execution state", + result: CheckResult{ + PipelineExecutionState: 2, + Retryable: true, + Eligible: false, + IneligibilityReason: 0, + UpkeepID: UpkeepIdentifier{}, + Trigger: Trigger{}, + WorkID: "", + GasAllocated: 0, + PerformData: nil, + FastGasWei: nil, + LinkNative: nil, + }, + wantID: "0209747275650966616c736509000900000000000000000000000000000000000000000000000000000000000000000900000000000000000000000000000000000000000000000000000000000000000909090909090909", + }, + { + name: "retryable eligible errored execution state", + result: CheckResult{ + PipelineExecutionState: 2, + Retryable: true, + Eligible: true, + IneligibilityReason: 0, + UpkeepID: UpkeepIdentifier{}, + Trigger: Trigger{}, + WorkID: "", + GasAllocated: 0, + PerformData: nil, + FastGasWei: nil, + LinkNative: nil, + }, + wantID: "020974727565097472756509000900000000000000000000000000000000000000000000000000000000000000000900000000000000000000000000000000000000000000000000000000000000000909090909090909", + }, + { + name: "retryable eligible errored execution state with non zero ineligibilty reason", + result: CheckResult{ + PipelineExecutionState: 2, + Retryable: true, + Eligible: true, + IneligibilityReason: 6, + UpkeepID: UpkeepIdentifier{}, + Trigger: Trigger{}, + WorkID: "", + GasAllocated: 0, + PerformData: nil, + FastGasWei: nil, + LinkNative: nil, + }, + wantID: "020974727565097472756509060900000000000000000000000000000000000000000000000000000000000000000900000000000000000000000000000000000000000000000000000000000000000909090909090909", + }, + { + name: "retryable eligible errored execution state with non zero ineligibilty reason and upkeep ID", + result: CheckResult{ + PipelineExecutionState: 2, + Retryable: true, + Eligible: true, + IneligibilityReason: 6, + UpkeepID: UpkeepIdentifier([32]byte{9, 9, 9, 9}), + Trigger: Trigger{}, + WorkID: "", + GasAllocated: 0, + PerformData: nil, + FastGasWei: nil, + LinkNative: nil, + }, + wantID: "020974727565097472756509060909090909000000000000000000000000000000000000000000000000000000000900000000000000000000000000000000000000000000000000000000000000000909090909090909", + }, + { + name: "retryable eligible errored execution state with non zero ineligibilty reason, upkeep ID, and trigger", + result: CheckResult{ + PipelineExecutionState: 2, + Retryable: true, + Eligible: true, + IneligibilityReason: 6, + UpkeepID: UpkeepIdentifier([32]byte{9, 9, 9, 9}), + Trigger: Trigger{ + BlockNumber: BlockNumber(44), + BlockHash: [32]byte{8, 8, 8, 8}, + LogTriggerExtension: &LogTriggerExtension{ + TxHash: [32]byte{7, 7, 7, 7}, + Index: 63, + BlockHash: [32]byte{6, 6, 6, 6}, + BlockNumber: BlockNumber(55), + }, + }, + WorkID: "", + GasAllocated: 0, + PerformData: nil, + FastGasWei: nil, + LinkNative: nil, + }, + wantID: "02097472756509747275650906090909090900000000000000000000000000000000000000000000000000000000090808080800000000000000000000000000000000000000000000000000000000092c097b22426c6f636b48617368223a2230363036303630363030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030222c22426c6f636b4e756d626572223a35352c22496e646578223a36332c22547848617368223a2230373037303730373030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030227d090909090909", + }, + { + name: "retryable eligible errored execution state with non zero ineligibilty reason, upkeep ID, trigger, and workID", + result: CheckResult{ + PipelineExecutionState: 2, + Retryable: true, + Eligible: true, + IneligibilityReason: 6, + UpkeepID: UpkeepIdentifier([32]byte{9, 9, 9, 9}), + Trigger: Trigger{ + BlockNumber: BlockNumber(44), + BlockHash: [32]byte{8, 8, 8, 8}, + LogTriggerExtension: &LogTriggerExtension{ + TxHash: [32]byte{7, 7, 7, 7}, + Index: 63, + BlockHash: [32]byte{6, 6, 6, 6}, + BlockNumber: BlockNumber(55), + }, + }, + WorkID: "abcdef", + GasAllocated: 0, + PerformData: nil, + FastGasWei: nil, + LinkNative: nil, + }, + wantID: "02097472756509747275650906090909090900000000000000000000000000000000000000000000000000000000090808080800000000000000000000000000000000000000000000000000000000092c097b22426c6f636b48617368223a2230363036303630363030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030222c22426c6f636b4e756d626572223a35352c22496e646578223a36332c22547848617368223a2230373037303730373030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030227d096162636465660909090909", + }, + { + name: "retryable eligible errored execution state with non zero ineligibilty reason, upkeep ID, trigger, and workID", + result: CheckResult{ + PipelineExecutionState: 2, + Retryable: true, + Eligible: true, + IneligibilityReason: 6, + UpkeepID: UpkeepIdentifier([32]byte{9, 9, 9, 9}), + Trigger: Trigger{ + BlockNumber: BlockNumber(44), + BlockHash: [32]byte{8, 8, 8, 8}, + LogTriggerExtension: &LogTriggerExtension{ + TxHash: [32]byte{7, 7, 7, 7}, + Index: 63, + BlockHash: [32]byte{6, 6, 6, 6}, + BlockNumber: BlockNumber(55), + }, + }, + WorkID: "abcdef", + GasAllocated: 543, + PerformData: []byte("xyz"), + FastGasWei: nil, + LinkNative: nil, + }, + wantID: "02097472756509747275650906090909090900000000000000000000000000000000000000000000000000000000090808080800000000000000000000000000000000000000000000000000000000092c097b22426c6f636b48617368223a2230363036303630363030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030222c22426c6f636b4e756d626572223a35352c22496e646578223a36332c22547848617368223a2230373037303730373030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030227d0961626364656609021f0978797a090909", + }, + { + name: "all fields", + result: CheckResult{ + PipelineExecutionState: 2, + Retryable: true, + Eligible: true, + IneligibilityReason: 6, + UpkeepID: UpkeepIdentifier([32]byte{9, 9, 9, 9}), + Trigger: Trigger{ + BlockNumber: BlockNumber(44), + BlockHash: [32]byte{8, 8, 8, 8}, + LogTriggerExtension: &LogTriggerExtension{ + TxHash: [32]byte{7, 7, 7, 7}, + Index: 63, + BlockHash: [32]byte{6, 6, 6, 6}, + BlockNumber: BlockNumber(55), + }, + }, + WorkID: "abcdef", + GasAllocated: 543, + PerformData: []byte("xyz"), + FastGasWei: big.NewInt(456), + LinkNative: big.NewInt(789), + }, + wantID: "02097472756509747275650906090909090900000000000000000000000000000000000000000000000000000000090808080800000000000000000000000000000000000000000000000000000000092c097b22426c6f636b48617368223a2230363036303630363030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030222c22426c6f636b4e756d626572223a35352c22496e646578223a36332c22547848617368223a2230373037303730373030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030227d0961626364656609021f0978797a0901c809031509", + }, + } { + t.Run(tc.name, func(t *testing.T) { + id := tc.result.UniqueID() + assert.Equal(t, tc.wantID, id) + }) + } +} + +func assertJSONEqual(t *testing.T, expected, actual string) { + var expectedMap, actualMap map[string]interface{} + require.NoError(t, json.Unmarshal([]byte(expected), &expectedMap), "expected is invalid json") + require.NoError(t, json.Unmarshal([]byte(actual), &actualMap), "actual is invalid json") + assert.True(t, reflect.DeepEqual(expectedMap, actualMap), "expected and result json strings do not match") +} + +func assertJSONContainsAllStructFields(t *testing.T, jsonString string, anyStruct interface{}) { + // if fields are added to the struct in the future, but omitted from the "pretty" string template, this test will fail + var jsonMap map[string]interface{} + var structMap map[string]interface{} + require.NoError(t, json.Unmarshal([]byte(jsonString), &jsonMap), "jsonString is invalid json") + structJson, err := json.Marshal(anyStruct) + require.NoError(t, err) + require.NoError(t, json.Unmarshal(structJson, &structMap)) + assertCongruentKeyStructure(t, structMap, jsonMap) +} + +func assertCongruentKeyStructure(t *testing.T, structMap, jsonMap map[string]interface{}) { + // this functions asserts that the two inputs have congruent key shapes, while disregarding + // the values + for k := range structMap { + assert.True(t, jsonMap[k] != nil, "json string does not contain field %s", k) + if nested1, ok := structMap[k].(map[string]interface{}); ok { + if nested2, ok := jsonMap[k].(map[string]interface{}); ok { + assertCongruentKeyStructure(t, nested1, nested2) + } else { + assert.Fail(t, "maps do not contain the same type for key %s", k) + } + } + } +} diff --git a/pkg/types/automation/interfaces.go b/pkg/types/automation/interfaces.go new file mode 100644 index 000000000..303b3f009 --- /dev/null +++ b/pkg/types/automation/interfaces.go @@ -0,0 +1,154 @@ +package automation + +import ( + "context" + "io" +) + +type UpkeepTypeGetter func(UpkeepIdentifier) UpkeepType +type WorkIDGenerator func(UpkeepIdentifier, Trigger) string + +// UpkeepStateStore is the interface for managing upkeeps final state in a local store. +type UpkeepStateStore interface { + UpkeepStateUpdater + UpkeepStateReader + Start(context.Context) error + io.Closer +} + +type Registry interface { + CheckUpkeeps(ctx context.Context, keys ...UpkeepPayload) ([]CheckResult, error) + Name() string + Start(ctx context.Context) error + Close() error + HealthReport() map[string]error +} + +type EventProvider interface { + Name() string + Start(_ context.Context) error + Close() error + Ready() error + HealthReport() map[string]error + GetLatestEvents(ctx context.Context) ([]TransmitEvent, error) +} + +type LogRecoverer interface { + RecoverableProvider + GetProposalData(context.Context, CoordinatedBlockProposal) ([]byte, error) + + Start(context.Context) error + io.Closer +} + +// UpkeepStateReader is the interface for reading the current state of upkeeps. +// +//go:generate mockery --quiet --name UpkeepStateReader --output ./mocks/ --case=underscore +type UpkeepStateReader interface { + SelectByWorkIDs(ctx context.Context, workIDs ...string) ([]UpkeepState, error) +} + +//go:generate mockery --name Encoder --structname MockEncoder --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename encoder.generated.go +type Encoder interface { + Encode(...CheckResult) ([]byte, error) + Extract([]byte) ([]ReportedUpkeep, error) +} + +//go:generate mockery --name LogEventProvider --structname MockLogEventProvider --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename logeventprovider.generated.go +type LogEventProvider interface { + GetLatestPayloads(context.Context) ([]UpkeepPayload, error) + Start(context.Context) error + Close() error +} + +//go:generate mockery --name RecoverableProvider --structname MockRecoverableProvider --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename recoverableprovider.generated.go +type RecoverableProvider interface { + GetRecoveryProposals(context.Context) ([]UpkeepPayload, error) +} + +//go:generate mockery --name TransmitEventProvider --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename transmit_event_provider.generated.go +type TransmitEventProvider interface { + GetLatestEvents(context.Context) ([]TransmitEvent, error) +} + +//go:generate mockery --name ConditionalUpkeepProvider --structname MockConditionalUpkeepProvider --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename conditionalupkeepprovider.generated.go +type ConditionalUpkeepProvider interface { + GetActiveUpkeeps(context.Context) ([]UpkeepPayload, error) +} + +//go:generate mockery --name PayloadBuilder --structname MockPayloadBuilder --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename payloadbuilder.generated.go +type PayloadBuilder interface { + // Can get payloads for a subset of proposals along with an error + BuildPayloads(context.Context, ...CoordinatedBlockProposal) ([]UpkeepPayload, error) +} + +//go:generate mockery --name Runnable --structname MockRunnable --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename runnable.generated.go +type Runnable interface { + // Can get results for a subset of payloads along with an error + CheckUpkeeps(context.Context, ...UpkeepPayload) ([]CheckResult, error) +} + +//go:generate mockery --name BlockSubscriber --structname MockBlockSubscriber --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename block_subscriber.generated.go +type BlockSubscriber interface { + // Subscribe provides an identifier integer, a new channel, and potentially an error + Subscribe() (int, chan BlockHistory, error) + // Unsubscribe requires an identifier integer and indicates the provided channel should be closed + Unsubscribe(int) error + Start(context.Context) error + Close() error +} + +//go:generate mockery --name UpkeepStateUpdater --structname MockUpkeepStateUpdater --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename upkeep_state_updater.generated.go +type UpkeepStateUpdater interface { + SetUpkeepState(context.Context, CheckResult, UpkeepState) error +} + +type RetryQueue interface { + // Enqueue adds new items to the queue + Enqueue(items ...RetryRecord) error + // Dequeue returns the next n items in the queue, considering retry time schedules + Dequeue(n int) ([]UpkeepPayload, error) +} + +type ProposalQueue interface { + // Enqueue adds new items to the queue + Enqueue(items ...CoordinatedBlockProposal) error + // Dequeue returns the next n items in the queue, considering retry time schedules + Dequeue(t UpkeepType, n int) ([]CoordinatedBlockProposal, error) +} + +//go:generate mockery --name ResultStore --structname MockResultStore --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename result_store.generated.go +type ResultStore interface { + Add(...CheckResult) + Remove(...string) + View() ([]CheckResult, error) +} + +//go:generate mockery --name Coordinator --structname MockCoordinator --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename coordinator.generated.go +type Coordinator interface { + PreProcess(_ context.Context, payloads []UpkeepPayload) ([]UpkeepPayload, error) + + Accept(ReportedUpkeep) bool + ShouldTransmit(ReportedUpkeep) bool + FilterResults([]CheckResult) ([]CheckResult, error) + FilterProposals([]CoordinatedBlockProposal) ([]CoordinatedBlockProposal, error) +} + +//go:generate mockery --name MetadataStore --structname MockMetadataStore --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename metadatastore.generated.go +type MetadataStore interface { + SetBlockHistory(BlockHistory) + GetBlockHistory() BlockHistory + + AddProposals(proposals ...CoordinatedBlockProposal) + ViewProposals(utype UpkeepType) []CoordinatedBlockProposal + RemoveProposals(proposals ...CoordinatedBlockProposal) + + Start(context.Context) error + Close() error +} + +//go:generate mockery --name Ratio --structname MockRatio --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename ratio.generated.go +type Ratio interface { + // OfInt should return n out of x such that n/x ~ r (ratio) + OfInt(int) int +} diff --git a/pkg/types/automation/mocks/block_subscriber.generated.go b/pkg/types/automation/mocks/block_subscriber.generated.go new file mode 100644 index 000000000..a96f9be96 --- /dev/null +++ b/pkg/types/automation/mocks/block_subscriber.generated.go @@ -0,0 +1,121 @@ +// Code generated by mockery v2.38.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + + automation "github.com/smartcontractkit/chainlink-common/pkg/types/automation" + + mock "github.com/stretchr/testify/mock" +) + +// MockBlockSubscriber is an autogenerated mock type for the BlockSubscriber type +type MockBlockSubscriber struct { + mock.Mock +} + +// Close provides a mock function with given fields: +func (_m *MockBlockSubscriber) Close() error { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Close") + } + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Start provides a mock function with given fields: _a0 +func (_m *MockBlockSubscriber) Start(_a0 context.Context) error { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for Start") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Subscribe provides a mock function with given fields: +func (_m *MockBlockSubscriber) Subscribe() (int, chan automation.BlockHistory, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Subscribe") + } + + var r0 int + var r1 chan automation.BlockHistory + var r2 error + if rf, ok := ret.Get(0).(func() (int, chan automation.BlockHistory, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() int); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(int) + } + + if rf, ok := ret.Get(1).(func() chan automation.BlockHistory); ok { + r1 = rf() + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(chan automation.BlockHistory) + } + } + + if rf, ok := ret.Get(2).(func() error); ok { + r2 = rf() + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// Unsubscribe provides a mock function with given fields: _a0 +func (_m *MockBlockSubscriber) Unsubscribe(_a0 int) error { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for Unsubscribe") + } + + var r0 error + if rf, ok := ret.Get(0).(func(int) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// NewMockBlockSubscriber creates a new instance of MockBlockSubscriber. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockBlockSubscriber(t interface { + mock.TestingT + Cleanup(func()) +}) *MockBlockSubscriber { + mock := &MockBlockSubscriber{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/types/automation/mocks/conditionalupkeepprovider.generated.go b/pkg/types/automation/mocks/conditionalupkeepprovider.generated.go new file mode 100644 index 000000000..76cc8334f --- /dev/null +++ b/pkg/types/automation/mocks/conditionalupkeepprovider.generated.go @@ -0,0 +1,60 @@ +// Code generated by mockery v2.38.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + + automation "github.com/smartcontractkit/chainlink-common/pkg/types/automation" + + mock "github.com/stretchr/testify/mock" +) + +// MockConditionalUpkeepProvider is an autogenerated mock type for the ConditionalUpkeepProvider type +type MockConditionalUpkeepProvider struct { + mock.Mock +} + +// GetActiveUpkeeps provides a mock function with given fields: _a0 +func (_m *MockConditionalUpkeepProvider) GetActiveUpkeeps(_a0 context.Context) ([]automation.UpkeepPayload, error) { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for GetActiveUpkeeps") + } + + var r0 []automation.UpkeepPayload + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]automation.UpkeepPayload, error)); ok { + return rf(_a0) + } + if rf, ok := ret.Get(0).(func(context.Context) []automation.UpkeepPayload); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]automation.UpkeepPayload) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NewMockConditionalUpkeepProvider creates a new instance of MockConditionalUpkeepProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockConditionalUpkeepProvider(t interface { + mock.TestingT + Cleanup(func()) +}) *MockConditionalUpkeepProvider { + mock := &MockConditionalUpkeepProvider{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/types/automation/mocks/coordinator.generated.go b/pkg/types/automation/mocks/coordinator.generated.go new file mode 100644 index 000000000..7fee23e99 --- /dev/null +++ b/pkg/types/automation/mocks/coordinator.generated.go @@ -0,0 +1,156 @@ +// Code generated by mockery v2.38.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + + automation "github.com/smartcontractkit/chainlink-common/pkg/types/automation" + + mock "github.com/stretchr/testify/mock" +) + +// MockCoordinator is an autogenerated mock type for the Coordinator type +type MockCoordinator struct { + mock.Mock +} + +// Accept provides a mock function with given fields: _a0 +func (_m *MockCoordinator) Accept(_a0 automation.ReportedUpkeep) bool { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for Accept") + } + + var r0 bool + if rf, ok := ret.Get(0).(func(automation.ReportedUpkeep) bool); ok { + r0 = rf(_a0) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// FilterProposals provides a mock function with given fields: _a0 +func (_m *MockCoordinator) FilterProposals(_a0 []automation.CoordinatedBlockProposal) ([]automation.CoordinatedBlockProposal, error) { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for FilterProposals") + } + + var r0 []automation.CoordinatedBlockProposal + var r1 error + if rf, ok := ret.Get(0).(func([]automation.CoordinatedBlockProposal) ([]automation.CoordinatedBlockProposal, error)); ok { + return rf(_a0) + } + if rf, ok := ret.Get(0).(func([]automation.CoordinatedBlockProposal) []automation.CoordinatedBlockProposal); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]automation.CoordinatedBlockProposal) + } + } + + if rf, ok := ret.Get(1).(func([]automation.CoordinatedBlockProposal) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// FilterResults provides a mock function with given fields: _a0 +func (_m *MockCoordinator) FilterResults(_a0 []automation.CheckResult) ([]automation.CheckResult, error) { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for FilterResults") + } + + var r0 []automation.CheckResult + var r1 error + if rf, ok := ret.Get(0).(func([]automation.CheckResult) ([]automation.CheckResult, error)); ok { + return rf(_a0) + } + if rf, ok := ret.Get(0).(func([]automation.CheckResult) []automation.CheckResult); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]automation.CheckResult) + } + } + + if rf, ok := ret.Get(1).(func([]automation.CheckResult) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// PreProcess provides a mock function with given fields: _a0, payloads +func (_m *MockCoordinator) PreProcess(_a0 context.Context, payloads []automation.UpkeepPayload) ([]automation.UpkeepPayload, error) { + ret := _m.Called(_a0, payloads) + + if len(ret) == 0 { + panic("no return value specified for PreProcess") + } + + var r0 []automation.UpkeepPayload + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []automation.UpkeepPayload) ([]automation.UpkeepPayload, error)); ok { + return rf(_a0, payloads) + } + if rf, ok := ret.Get(0).(func(context.Context, []automation.UpkeepPayload) []automation.UpkeepPayload); ok { + r0 = rf(_a0, payloads) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]automation.UpkeepPayload) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []automation.UpkeepPayload) error); ok { + r1 = rf(_a0, payloads) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ShouldTransmit provides a mock function with given fields: _a0 +func (_m *MockCoordinator) ShouldTransmit(_a0 automation.ReportedUpkeep) bool { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for ShouldTransmit") + } + + var r0 bool + if rf, ok := ret.Get(0).(func(automation.ReportedUpkeep) bool); ok { + r0 = rf(_a0) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// NewMockCoordinator creates a new instance of MockCoordinator. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockCoordinator(t interface { + mock.TestingT + Cleanup(func()) +}) *MockCoordinator { + mock := &MockCoordinator{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/types/automation/mocks/encoder.generated.go b/pkg/types/automation/mocks/encoder.generated.go new file mode 100644 index 000000000..3e262cbc9 --- /dev/null +++ b/pkg/types/automation/mocks/encoder.generated.go @@ -0,0 +1,93 @@ +// Code generated by mockery v2.38.0. DO NOT EDIT. + +package mocks + +import ( + automation "github.com/smartcontractkit/chainlink-common/pkg/types/automation" + mock "github.com/stretchr/testify/mock" +) + +// MockEncoder is an autogenerated mock type for the Encoder type +type MockEncoder struct { + mock.Mock +} + +// Encode provides a mock function with given fields: _a0 +func (_m *MockEncoder) Encode(_a0 ...automation.CheckResult) ([]byte, error) { + _va := make([]interface{}, len(_a0)) + for _i := range _a0 { + _va[_i] = _a0[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for Encode") + } + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(...automation.CheckResult) ([]byte, error)); ok { + return rf(_a0...) + } + if rf, ok := ret.Get(0).(func(...automation.CheckResult) []byte); ok { + r0 = rf(_a0...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(...automation.CheckResult) error); ok { + r1 = rf(_a0...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Extract provides a mock function with given fields: _a0 +func (_m *MockEncoder) Extract(_a0 []byte) ([]automation.ReportedUpkeep, error) { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for Extract") + } + + var r0 []automation.ReportedUpkeep + var r1 error + if rf, ok := ret.Get(0).(func([]byte) ([]automation.ReportedUpkeep, error)); ok { + return rf(_a0) + } + if rf, ok := ret.Get(0).(func([]byte) []automation.ReportedUpkeep); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]automation.ReportedUpkeep) + } + } + + if rf, ok := ret.Get(1).(func([]byte) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NewMockEncoder creates a new instance of MockEncoder. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockEncoder(t interface { + mock.TestingT + Cleanup(func()) +}) *MockEncoder { + mock := &MockEncoder{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/types/automation/mocks/logeventprovider.generated.go b/pkg/types/automation/mocks/logeventprovider.generated.go new file mode 100644 index 000000000..4b88fc9ff --- /dev/null +++ b/pkg/types/automation/mocks/logeventprovider.generated.go @@ -0,0 +1,96 @@ +// Code generated by mockery v2.38.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + + automation "github.com/smartcontractkit/chainlink-common/pkg/types/automation" + + mock "github.com/stretchr/testify/mock" +) + +// MockLogEventProvider is an autogenerated mock type for the LogEventProvider type +type MockLogEventProvider struct { + mock.Mock +} + +// Close provides a mock function with given fields: +func (_m *MockLogEventProvider) Close() error { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Close") + } + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// GetLatestPayloads provides a mock function with given fields: _a0 +func (_m *MockLogEventProvider) GetLatestPayloads(_a0 context.Context) ([]automation.UpkeepPayload, error) { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for GetLatestPayloads") + } + + var r0 []automation.UpkeepPayload + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]automation.UpkeepPayload, error)); ok { + return rf(_a0) + } + if rf, ok := ret.Get(0).(func(context.Context) []automation.UpkeepPayload); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]automation.UpkeepPayload) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Start provides a mock function with given fields: _a0 +func (_m *MockLogEventProvider) Start(_a0 context.Context) error { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for Start") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// NewMockLogEventProvider creates a new instance of MockLogEventProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockLogEventProvider(t interface { + mock.TestingT + Cleanup(func()) +}) *MockLogEventProvider { + mock := &MockLogEventProvider{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/types/automation/mocks/metadatastore.generated.go b/pkg/types/automation/mocks/metadatastore.generated.go new file mode 100644 index 000000000..5ff1804e7 --- /dev/null +++ b/pkg/types/automation/mocks/metadatastore.generated.go @@ -0,0 +1,133 @@ +// Code generated by mockery v2.38.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + + automation "github.com/smartcontractkit/chainlink-common/pkg/types/automation" + + mock "github.com/stretchr/testify/mock" +) + +// MockMetadataStore is an autogenerated mock type for the MetadataStore type +type MockMetadataStore struct { + mock.Mock +} + +// AddProposals provides a mock function with given fields: proposals +func (_m *MockMetadataStore) AddProposals(proposals ...automation.CoordinatedBlockProposal) { + _va := make([]interface{}, len(proposals)) + for _i := range proposals { + _va[_i] = proposals[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + _m.Called(_ca...) +} + +// Close provides a mock function with given fields: +func (_m *MockMetadataStore) Close() error { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Close") + } + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// GetBlockHistory provides a mock function with given fields: +func (_m *MockMetadataStore) GetBlockHistory() automation.BlockHistory { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetBlockHistory") + } + + var r0 automation.BlockHistory + if rf, ok := ret.Get(0).(func() automation.BlockHistory); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(automation.BlockHistory) + } + } + + return r0 +} + +// RemoveProposals provides a mock function with given fields: proposals +func (_m *MockMetadataStore) RemoveProposals(proposals ...automation.CoordinatedBlockProposal) { + _va := make([]interface{}, len(proposals)) + for _i := range proposals { + _va[_i] = proposals[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + _m.Called(_ca...) +} + +// SetBlockHistory provides a mock function with given fields: _a0 +func (_m *MockMetadataStore) SetBlockHistory(_a0 automation.BlockHistory) { + _m.Called(_a0) +} + +// Start provides a mock function with given fields: _a0 +func (_m *MockMetadataStore) Start(_a0 context.Context) error { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for Start") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context) error); ok { + r0 = rf(_a0) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// ViewProposals provides a mock function with given fields: utype +func (_m *MockMetadataStore) ViewProposals(utype automation.UpkeepType) []automation.CoordinatedBlockProposal { + ret := _m.Called(utype) + + if len(ret) == 0 { + panic("no return value specified for ViewProposals") + } + + var r0 []automation.CoordinatedBlockProposal + if rf, ok := ret.Get(0).(func(automation.UpkeepType) []automation.CoordinatedBlockProposal); ok { + r0 = rf(utype) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]automation.CoordinatedBlockProposal) + } + } + + return r0 +} + +// NewMockMetadataStore creates a new instance of MockMetadataStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockMetadataStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockMetadataStore { + mock := &MockMetadataStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/types/automation/mocks/payloadbuilder.generated.go b/pkg/types/automation/mocks/payloadbuilder.generated.go new file mode 100644 index 000000000..87f5718dc --- /dev/null +++ b/pkg/types/automation/mocks/payloadbuilder.generated.go @@ -0,0 +1,67 @@ +// Code generated by mockery v2.38.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + + automation "github.com/smartcontractkit/chainlink-common/pkg/types/automation" + + mock "github.com/stretchr/testify/mock" +) + +// MockPayloadBuilder is an autogenerated mock type for the PayloadBuilder type +type MockPayloadBuilder struct { + mock.Mock +} + +// BuildPayloads provides a mock function with given fields: _a0, _a1 +func (_m *MockPayloadBuilder) BuildPayloads(_a0 context.Context, _a1 ...automation.CoordinatedBlockProposal) ([]automation.UpkeepPayload, error) { + _va := make([]interface{}, len(_a1)) + for _i := range _a1 { + _va[_i] = _a1[_i] + } + var _ca []interface{} + _ca = append(_ca, _a0) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for BuildPayloads") + } + + var r0 []automation.UpkeepPayload + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, ...automation.CoordinatedBlockProposal) ([]automation.UpkeepPayload, error)); ok { + return rf(_a0, _a1...) + } + if rf, ok := ret.Get(0).(func(context.Context, ...automation.CoordinatedBlockProposal) []automation.UpkeepPayload); ok { + r0 = rf(_a0, _a1...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]automation.UpkeepPayload) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, ...automation.CoordinatedBlockProposal) error); ok { + r1 = rf(_a0, _a1...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NewMockPayloadBuilder creates a new instance of MockPayloadBuilder. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockPayloadBuilder(t interface { + mock.TestingT + Cleanup(func()) +}) *MockPayloadBuilder { + mock := &MockPayloadBuilder{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/types/automation/mocks/ratio.generated.go b/pkg/types/automation/mocks/ratio.generated.go new file mode 100644 index 000000000..89c15149a --- /dev/null +++ b/pkg/types/automation/mocks/ratio.generated.go @@ -0,0 +1,42 @@ +// Code generated by mockery v2.38.0. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// MockRatio is an autogenerated mock type for the Ratio type +type MockRatio struct { + mock.Mock +} + +// OfInt provides a mock function with given fields: _a0 +func (_m *MockRatio) OfInt(_a0 int) int { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for OfInt") + } + + var r0 int + if rf, ok := ret.Get(0).(func(int) int); ok { + r0 = rf(_a0) + } else { + r0 = ret.Get(0).(int) + } + + return r0 +} + +// NewMockRatio creates a new instance of MockRatio. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockRatio(t interface { + mock.TestingT + Cleanup(func()) +}) *MockRatio { + mock := &MockRatio{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/types/automation/mocks/recoverableprovider.generated.go b/pkg/types/automation/mocks/recoverableprovider.generated.go new file mode 100644 index 000000000..7b914c78c --- /dev/null +++ b/pkg/types/automation/mocks/recoverableprovider.generated.go @@ -0,0 +1,60 @@ +// Code generated by mockery v2.38.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + + automation "github.com/smartcontractkit/chainlink-common/pkg/types/automation" + + mock "github.com/stretchr/testify/mock" +) + +// MockRecoverableProvider is an autogenerated mock type for the RecoverableProvider type +type MockRecoverableProvider struct { + mock.Mock +} + +// GetRecoveryProposals provides a mock function with given fields: _a0 +func (_m *MockRecoverableProvider) GetRecoveryProposals(_a0 context.Context) ([]automation.UpkeepPayload, error) { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for GetRecoveryProposals") + } + + var r0 []automation.UpkeepPayload + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]automation.UpkeepPayload, error)); ok { + return rf(_a0) + } + if rf, ok := ret.Get(0).(func(context.Context) []automation.UpkeepPayload); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]automation.UpkeepPayload) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NewMockRecoverableProvider creates a new instance of MockRecoverableProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockRecoverableProvider(t interface { + mock.TestingT + Cleanup(func()) +}) *MockRecoverableProvider { + mock := &MockRecoverableProvider{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/types/automation/mocks/result_store.generated.go b/pkg/types/automation/mocks/result_store.generated.go new file mode 100644 index 000000000..625aad245 --- /dev/null +++ b/pkg/types/automation/mocks/result_store.generated.go @@ -0,0 +1,79 @@ +// Code generated by mockery v2.38.0. DO NOT EDIT. + +package mocks + +import ( + automation "github.com/smartcontractkit/chainlink-common/pkg/types/automation" + mock "github.com/stretchr/testify/mock" +) + +// MockResultStore is an autogenerated mock type for the ResultStore type +type MockResultStore struct { + mock.Mock +} + +// Add provides a mock function with given fields: _a0 +func (_m *MockResultStore) Add(_a0 ...automation.CheckResult) { + _va := make([]interface{}, len(_a0)) + for _i := range _a0 { + _va[_i] = _a0[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + _m.Called(_ca...) +} + +// Remove provides a mock function with given fields: _a0 +func (_m *MockResultStore) Remove(_a0 ...string) { + _va := make([]interface{}, len(_a0)) + for _i := range _a0 { + _va[_i] = _a0[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + _m.Called(_ca...) +} + +// View provides a mock function with given fields: +func (_m *MockResultStore) View() ([]automation.CheckResult, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for View") + } + + var r0 []automation.CheckResult + var r1 error + if rf, ok := ret.Get(0).(func() ([]automation.CheckResult, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() []automation.CheckResult); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]automation.CheckResult) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NewMockResultStore creates a new instance of MockResultStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockResultStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockResultStore { + mock := &MockResultStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/types/automation/mocks/runnable.generated.go b/pkg/types/automation/mocks/runnable.generated.go new file mode 100644 index 000000000..808197751 --- /dev/null +++ b/pkg/types/automation/mocks/runnable.generated.go @@ -0,0 +1,67 @@ +// Code generated by mockery v2.38.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + + automation "github.com/smartcontractkit/chainlink-common/pkg/types/automation" + + mock "github.com/stretchr/testify/mock" +) + +// MockRunnable is an autogenerated mock type for the Runnable type +type MockRunnable struct { + mock.Mock +} + +// CheckUpkeeps provides a mock function with given fields: _a0, _a1 +func (_m *MockRunnable) CheckUpkeeps(_a0 context.Context, _a1 ...automation.UpkeepPayload) ([]automation.CheckResult, error) { + _va := make([]interface{}, len(_a1)) + for _i := range _a1 { + _va[_i] = _a1[_i] + } + var _ca []interface{} + _ca = append(_ca, _a0) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for CheckUpkeeps") + } + + var r0 []automation.CheckResult + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, ...automation.UpkeepPayload) ([]automation.CheckResult, error)); ok { + return rf(_a0, _a1...) + } + if rf, ok := ret.Get(0).(func(context.Context, ...automation.UpkeepPayload) []automation.CheckResult); ok { + r0 = rf(_a0, _a1...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]automation.CheckResult) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, ...automation.UpkeepPayload) error); ok { + r1 = rf(_a0, _a1...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NewMockRunnable creates a new instance of MockRunnable. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockRunnable(t interface { + mock.TestingT + Cleanup(func()) +}) *MockRunnable { + mock := &MockRunnable{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/types/automation/mocks/transmit_event_provider.generated.go b/pkg/types/automation/mocks/transmit_event_provider.generated.go new file mode 100644 index 000000000..da812eeaf --- /dev/null +++ b/pkg/types/automation/mocks/transmit_event_provider.generated.go @@ -0,0 +1,60 @@ +// Code generated by mockery v2.38.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + + automation "github.com/smartcontractkit/chainlink-common/pkg/types/automation" + + mock "github.com/stretchr/testify/mock" +) + +// TransmitEventProvider is an autogenerated mock type for the TransmitEventProvider type +type TransmitEventProvider struct { + mock.Mock +} + +// GetLatestEvents provides a mock function with given fields: _a0 +func (_m *TransmitEventProvider) GetLatestEvents(_a0 context.Context) ([]automation.TransmitEvent, error) { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for GetLatestEvents") + } + + var r0 []automation.TransmitEvent + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) ([]automation.TransmitEvent, error)); ok { + return rf(_a0) + } + if rf, ok := ret.Get(0).(func(context.Context) []automation.TransmitEvent); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]automation.TransmitEvent) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NewTransmitEventProvider creates a new instance of TransmitEventProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewTransmitEventProvider(t interface { + mock.TestingT + Cleanup(func()) +}) *TransmitEventProvider { + mock := &TransmitEventProvider{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/types/automation/mocks/upkeep_state_reader.go b/pkg/types/automation/mocks/upkeep_state_reader.go new file mode 100644 index 000000000..5a815987a --- /dev/null +++ b/pkg/types/automation/mocks/upkeep_state_reader.go @@ -0,0 +1,67 @@ +// Code generated by mockery v2.38.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + + automation "github.com/smartcontractkit/chainlink-common/pkg/types/automation" + + mock "github.com/stretchr/testify/mock" +) + +// UpkeepStateReader is an autogenerated mock type for the UpkeepStateReader type +type UpkeepStateReader struct { + mock.Mock +} + +// SelectByWorkIDs provides a mock function with given fields: ctx, workIDs +func (_m *UpkeepStateReader) SelectByWorkIDs(ctx context.Context, workIDs ...string) ([]automation.UpkeepState, error) { + _va := make([]interface{}, len(workIDs)) + for _i := range workIDs { + _va[_i] = workIDs[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for SelectByWorkIDs") + } + + var r0 []automation.UpkeepState + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, ...string) ([]automation.UpkeepState, error)); ok { + return rf(ctx, workIDs...) + } + if rf, ok := ret.Get(0).(func(context.Context, ...string) []automation.UpkeepState); ok { + r0 = rf(ctx, workIDs...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]automation.UpkeepState) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, ...string) error); ok { + r1 = rf(ctx, workIDs...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NewUpkeepStateReader creates a new instance of UpkeepStateReader. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewUpkeepStateReader(t interface { + mock.TestingT + Cleanup(func()) +}) *UpkeepStateReader { + mock := &UpkeepStateReader{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/types/automation/mocks/upkeep_state_updater.generated.go b/pkg/types/automation/mocks/upkeep_state_updater.generated.go new file mode 100644 index 000000000..dc550a14b --- /dev/null +++ b/pkg/types/automation/mocks/upkeep_state_updater.generated.go @@ -0,0 +1,48 @@ +// Code generated by mockery v2.38.0. DO NOT EDIT. + +package mocks + +import ( + context "context" + + automation "github.com/smartcontractkit/chainlink-common/pkg/types/automation" + + mock "github.com/stretchr/testify/mock" +) + +// MockUpkeepStateUpdater is an autogenerated mock type for the UpkeepStateUpdater type +type MockUpkeepStateUpdater struct { + mock.Mock +} + +// SetUpkeepState provides a mock function with given fields: _a0, _a1, _a2 +func (_m *MockUpkeepStateUpdater) SetUpkeepState(_a0 context.Context, _a1 automation.CheckResult, _a2 automation.UpkeepState) error { + ret := _m.Called(_a0, _a1, _a2) + + if len(ret) == 0 { + panic("no return value specified for SetUpkeepState") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, automation.CheckResult, automation.UpkeepState) error); ok { + r0 = rf(_a0, _a1, _a2) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// NewMockUpkeepStateUpdater creates a new instance of MockUpkeepStateUpdater. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockUpkeepStateUpdater(t interface { + mock.TestingT + Cleanup(func()) +}) *MockUpkeepStateUpdater { + mock := &MockUpkeepStateUpdater{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/types/automation/trigger.go b/pkg/types/automation/trigger.go new file mode 100644 index 000000000..a600ecbfe --- /dev/null +++ b/pkg/types/automation/trigger.go @@ -0,0 +1,87 @@ +package automation + +import ( + "bytes" + "encoding/binary" + "encoding/hex" + "fmt" +) + +// Trigger represents a trigger for an upkeep. +// It contains an extension per trigger type, and the block number + hash +// in which the trigger was checked. +// NOTE: This struct is sent on the p2p network as part of observations to get quorum +// Any change here should be backwards compatible and should keep validation and +// quorum requirements in mind. Please ensure to get a proper review along with an +// upgrade plan before changing this +type Trigger struct { + // BlockNumber is the block number in which the trigger was checked + BlockNumber BlockNumber + // BlockHash is the block hash in which the trigger was checked + BlockHash [32]byte + // LogTriggerExtension is the extension for log triggers + LogTriggerExtension *LogTriggerExtension +} + +func (r Trigger) String() string { + res := fmt.Sprintf(`{"BlockNumber":%d,"BlockHash":"%s"`, r.BlockNumber, hex.EncodeToString(r.BlockHash[:])) + if r.LogTriggerExtension != nil { + res += fmt.Sprintf(`,"LogTriggerExtension":%s`, r.LogTriggerExtension) + } + res += "}" + return res +} + +// NewTrigger returns a new basic trigger w/o extension +func NewTrigger(blockNumber BlockNumber, blockHash [32]byte) Trigger { + return Trigger{ + BlockNumber: blockNumber, + BlockHash: blockHash, + } +} + +func NewLogTrigger(blockNumber BlockNumber, blockHash [32]byte, logTriggerExtension *LogTriggerExtension) Trigger { + return Trigger{ + BlockNumber: blockNumber, + BlockHash: blockHash, + LogTriggerExtension: logTriggerExtension, + } +} + +// LogTriggerExtension is the extension used for log triggers, +// It contains information of the log event that was triggered. +// NOTE: This struct is sent on the p2p network as part of observations to get quorum +// Any change here should be backwards compatible and should keep validation and +// quorum requirements in mind. Please ensure to get a proper review along with an +// upgrade plan before changing this +type LogTriggerExtension struct { + // LogTxHash is the transaction hash of the log event + TxHash [32]byte + // Index is the index of the log event in the transaction + Index uint32 + // BlockHash is the block hash in which the event occurred + BlockHash [32]byte + // BlockNumber is the block number in which the event occurred + // NOTE: This field might be empty. If relying on this field check + // it is non empty, if it's empty derive from BlockHash + BlockNumber BlockNumber +} + +// LogIdentifier returns a unique identifier for the log event, +// composed of the transaction hash and the log index bytes. +func (e LogTriggerExtension) LogIdentifier() []byte { + indexBytes := make([]byte, 4) // uint32 is 4 bytes + binary.BigEndian.PutUint32(indexBytes, e.Index) + return bytes.Join([][]byte{ + e.BlockHash[:], + e.TxHash[:], + indexBytes, + }, []byte{}) +} + +func (e LogTriggerExtension) String() string { + return fmt.Sprintf( + `{"BlockHash":"%s","BlockNumber":%d,"Index":%d,"TxHash":"%s"}`, + hex.EncodeToString(e.BlockHash[:]), e.BlockNumber, e.Index, hex.EncodeToString(e.TxHash[:]), + ) +} diff --git a/pkg/types/provider_automation.go b/pkg/types/provider_automation.go index f3ea3407c..ee4f217f2 100644 --- a/pkg/types/provider_automation.go +++ b/pkg/types/provider_automation.go @@ -1,6 +1,17 @@ package types +import "github.com/smartcontractkit/chainlink-common/pkg/types/automation" + // AutomationProvider provides components needed for the automation OCR2 plugin. type AutomationProvider interface { PluginProvider + Registry() automation.Registry + Encoder() automation.Encoder + TransmitEventProvider() automation.EventProvider + BlockSubscriber() automation.BlockSubscriber + PayloadBuilder() automation.PayloadBuilder + UpkeepStateStore() automation.UpkeepStateStore + LogEventProvider() automation.LogEventProvider + LogRecoverer() automation.LogRecoverer + UpkeepProvider() automation.ConditionalUpkeepProvider } From c9da5865273d6dead7739945103b9fc35b7b9fe3 Mon Sep 17 00:00:00 2001 From: Fergal Gribben Date: Mon, 8 Jan 2024 14:24:16 +0000 Subject: [PATCH 2/6] Remove mocks --- GNUmakefile | 7 - pkg/types/automation/interfaces.go | 15 -- .../mocks/block_subscriber.generated.go | 121 -------------- .../conditionalupkeepprovider.generated.go | 60 ------- .../automation/mocks/coordinator.generated.go | 156 ------------------ .../automation/mocks/encoder.generated.go | 93 ----------- .../mocks/logeventprovider.generated.go | 96 ----------- .../mocks/metadatastore.generated.go | 133 --------------- .../mocks/payloadbuilder.generated.go | 67 -------- pkg/types/automation/mocks/ratio.generated.go | 42 ----- .../mocks/recoverableprovider.generated.go | 60 ------- .../mocks/result_store.generated.go | 79 --------- .../automation/mocks/runnable.generated.go | 67 -------- .../transmit_event_provider.generated.go | 60 ------- .../automation/mocks/upkeep_state_reader.go | 67 -------- .../mocks/upkeep_state_updater.generated.go | 48 ------ 16 files changed, 1171 deletions(-) delete mode 100644 GNUmakefile delete mode 100644 pkg/types/automation/mocks/block_subscriber.generated.go delete mode 100644 pkg/types/automation/mocks/conditionalupkeepprovider.generated.go delete mode 100644 pkg/types/automation/mocks/coordinator.generated.go delete mode 100644 pkg/types/automation/mocks/encoder.generated.go delete mode 100644 pkg/types/automation/mocks/logeventprovider.generated.go delete mode 100644 pkg/types/automation/mocks/metadatastore.generated.go delete mode 100644 pkg/types/automation/mocks/payloadbuilder.generated.go delete mode 100644 pkg/types/automation/mocks/ratio.generated.go delete mode 100644 pkg/types/automation/mocks/recoverableprovider.generated.go delete mode 100644 pkg/types/automation/mocks/result_store.generated.go delete mode 100644 pkg/types/automation/mocks/runnable.generated.go delete mode 100644 pkg/types/automation/mocks/transmit_event_provider.generated.go delete mode 100644 pkg/types/automation/mocks/upkeep_state_reader.go delete mode 100644 pkg/types/automation/mocks/upkeep_state_updater.generated.go diff --git a/GNUmakefile b/GNUmakefile deleted file mode 100644 index b3b7d3f1b..000000000 --- a/GNUmakefile +++ /dev/null @@ -1,7 +0,0 @@ -.PHONY: generate -generate: mockery - go generate -x ./... - -.PHONY: mockery -mockery: $(mockery) ## Install mockery. - go install github.com/vektra/mockery/v2@v2.38.0 diff --git a/pkg/types/automation/interfaces.go b/pkg/types/automation/interfaces.go index 303b3f009..9a3fdbff2 100644 --- a/pkg/types/automation/interfaces.go +++ b/pkg/types/automation/interfaces.go @@ -42,53 +42,43 @@ type LogRecoverer interface { } // UpkeepStateReader is the interface for reading the current state of upkeeps. -// -//go:generate mockery --quiet --name UpkeepStateReader --output ./mocks/ --case=underscore type UpkeepStateReader interface { SelectByWorkIDs(ctx context.Context, workIDs ...string) ([]UpkeepState, error) } -//go:generate mockery --name Encoder --structname MockEncoder --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename encoder.generated.go type Encoder interface { Encode(...CheckResult) ([]byte, error) Extract([]byte) ([]ReportedUpkeep, error) } -//go:generate mockery --name LogEventProvider --structname MockLogEventProvider --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename logeventprovider.generated.go type LogEventProvider interface { GetLatestPayloads(context.Context) ([]UpkeepPayload, error) Start(context.Context) error Close() error } -//go:generate mockery --name RecoverableProvider --structname MockRecoverableProvider --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename recoverableprovider.generated.go type RecoverableProvider interface { GetRecoveryProposals(context.Context) ([]UpkeepPayload, error) } -//go:generate mockery --name TransmitEventProvider --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename transmit_event_provider.generated.go type TransmitEventProvider interface { GetLatestEvents(context.Context) ([]TransmitEvent, error) } -//go:generate mockery --name ConditionalUpkeepProvider --structname MockConditionalUpkeepProvider --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename conditionalupkeepprovider.generated.go type ConditionalUpkeepProvider interface { GetActiveUpkeeps(context.Context) ([]UpkeepPayload, error) } -//go:generate mockery --name PayloadBuilder --structname MockPayloadBuilder --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename payloadbuilder.generated.go type PayloadBuilder interface { // Can get payloads for a subset of proposals along with an error BuildPayloads(context.Context, ...CoordinatedBlockProposal) ([]UpkeepPayload, error) } -//go:generate mockery --name Runnable --structname MockRunnable --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename runnable.generated.go type Runnable interface { // Can get results for a subset of payloads along with an error CheckUpkeeps(context.Context, ...UpkeepPayload) ([]CheckResult, error) } -//go:generate mockery --name BlockSubscriber --structname MockBlockSubscriber --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename block_subscriber.generated.go type BlockSubscriber interface { // Subscribe provides an identifier integer, a new channel, and potentially an error Subscribe() (int, chan BlockHistory, error) @@ -98,7 +88,6 @@ type BlockSubscriber interface { Close() error } -//go:generate mockery --name UpkeepStateUpdater --structname MockUpkeepStateUpdater --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename upkeep_state_updater.generated.go type UpkeepStateUpdater interface { SetUpkeepState(context.Context, CheckResult, UpkeepState) error } @@ -117,14 +106,12 @@ type ProposalQueue interface { Dequeue(t UpkeepType, n int) ([]CoordinatedBlockProposal, error) } -//go:generate mockery --name ResultStore --structname MockResultStore --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename result_store.generated.go type ResultStore interface { Add(...CheckResult) Remove(...string) View() ([]CheckResult, error) } -//go:generate mockery --name Coordinator --structname MockCoordinator --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename coordinator.generated.go type Coordinator interface { PreProcess(_ context.Context, payloads []UpkeepPayload) ([]UpkeepPayload, error) @@ -134,7 +121,6 @@ type Coordinator interface { FilterProposals([]CoordinatedBlockProposal) ([]CoordinatedBlockProposal, error) } -//go:generate mockery --name MetadataStore --structname MockMetadataStore --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename metadatastore.generated.go type MetadataStore interface { SetBlockHistory(BlockHistory) GetBlockHistory() BlockHistory @@ -147,7 +133,6 @@ type MetadataStore interface { Close() error } -//go:generate mockery --name Ratio --structname MockRatio --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename ratio.generated.go type Ratio interface { // OfInt should return n out of x such that n/x ~ r (ratio) OfInt(int) int diff --git a/pkg/types/automation/mocks/block_subscriber.generated.go b/pkg/types/automation/mocks/block_subscriber.generated.go deleted file mode 100644 index a96f9be96..000000000 --- a/pkg/types/automation/mocks/block_subscriber.generated.go +++ /dev/null @@ -1,121 +0,0 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. - -package mocks - -import ( - context "context" - - automation "github.com/smartcontractkit/chainlink-common/pkg/types/automation" - - mock "github.com/stretchr/testify/mock" -) - -// MockBlockSubscriber is an autogenerated mock type for the BlockSubscriber type -type MockBlockSubscriber struct { - mock.Mock -} - -// Close provides a mock function with given fields: -func (_m *MockBlockSubscriber) Close() error { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for Close") - } - - var r0 error - if rf, ok := ret.Get(0).(func() error); ok { - r0 = rf() - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// Start provides a mock function with given fields: _a0 -func (_m *MockBlockSubscriber) Start(_a0 context.Context) error { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for Start") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context) error); ok { - r0 = rf(_a0) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// Subscribe provides a mock function with given fields: -func (_m *MockBlockSubscriber) Subscribe() (int, chan automation.BlockHistory, error) { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for Subscribe") - } - - var r0 int - var r1 chan automation.BlockHistory - var r2 error - if rf, ok := ret.Get(0).(func() (int, chan automation.BlockHistory, error)); ok { - return rf() - } - if rf, ok := ret.Get(0).(func() int); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(int) - } - - if rf, ok := ret.Get(1).(func() chan automation.BlockHistory); ok { - r1 = rf() - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(chan automation.BlockHistory) - } - } - - if rf, ok := ret.Get(2).(func() error); ok { - r2 = rf() - } else { - r2 = ret.Error(2) - } - - return r0, r1, r2 -} - -// Unsubscribe provides a mock function with given fields: _a0 -func (_m *MockBlockSubscriber) Unsubscribe(_a0 int) error { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for Unsubscribe") - } - - var r0 error - if rf, ok := ret.Get(0).(func(int) error); ok { - r0 = rf(_a0) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// NewMockBlockSubscriber creates a new instance of MockBlockSubscriber. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewMockBlockSubscriber(t interface { - mock.TestingT - Cleanup(func()) -}) *MockBlockSubscriber { - mock := &MockBlockSubscriber{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/pkg/types/automation/mocks/conditionalupkeepprovider.generated.go b/pkg/types/automation/mocks/conditionalupkeepprovider.generated.go deleted file mode 100644 index 76cc8334f..000000000 --- a/pkg/types/automation/mocks/conditionalupkeepprovider.generated.go +++ /dev/null @@ -1,60 +0,0 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. - -package mocks - -import ( - context "context" - - automation "github.com/smartcontractkit/chainlink-common/pkg/types/automation" - - mock "github.com/stretchr/testify/mock" -) - -// MockConditionalUpkeepProvider is an autogenerated mock type for the ConditionalUpkeepProvider type -type MockConditionalUpkeepProvider struct { - mock.Mock -} - -// GetActiveUpkeeps provides a mock function with given fields: _a0 -func (_m *MockConditionalUpkeepProvider) GetActiveUpkeeps(_a0 context.Context) ([]automation.UpkeepPayload, error) { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for GetActiveUpkeeps") - } - - var r0 []automation.UpkeepPayload - var r1 error - if rf, ok := ret.Get(0).(func(context.Context) ([]automation.UpkeepPayload, error)); ok { - return rf(_a0) - } - if rf, ok := ret.Get(0).(func(context.Context) []automation.UpkeepPayload); ok { - r0 = rf(_a0) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]automation.UpkeepPayload) - } - } - - if rf, ok := ret.Get(1).(func(context.Context) error); ok { - r1 = rf(_a0) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// NewMockConditionalUpkeepProvider creates a new instance of MockConditionalUpkeepProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewMockConditionalUpkeepProvider(t interface { - mock.TestingT - Cleanup(func()) -}) *MockConditionalUpkeepProvider { - mock := &MockConditionalUpkeepProvider{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/pkg/types/automation/mocks/coordinator.generated.go b/pkg/types/automation/mocks/coordinator.generated.go deleted file mode 100644 index 7fee23e99..000000000 --- a/pkg/types/automation/mocks/coordinator.generated.go +++ /dev/null @@ -1,156 +0,0 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. - -package mocks - -import ( - context "context" - - automation "github.com/smartcontractkit/chainlink-common/pkg/types/automation" - - mock "github.com/stretchr/testify/mock" -) - -// MockCoordinator is an autogenerated mock type for the Coordinator type -type MockCoordinator struct { - mock.Mock -} - -// Accept provides a mock function with given fields: _a0 -func (_m *MockCoordinator) Accept(_a0 automation.ReportedUpkeep) bool { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for Accept") - } - - var r0 bool - if rf, ok := ret.Get(0).(func(automation.ReportedUpkeep) bool); ok { - r0 = rf(_a0) - } else { - r0 = ret.Get(0).(bool) - } - - return r0 -} - -// FilterProposals provides a mock function with given fields: _a0 -func (_m *MockCoordinator) FilterProposals(_a0 []automation.CoordinatedBlockProposal) ([]automation.CoordinatedBlockProposal, error) { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for FilterProposals") - } - - var r0 []automation.CoordinatedBlockProposal - var r1 error - if rf, ok := ret.Get(0).(func([]automation.CoordinatedBlockProposal) ([]automation.CoordinatedBlockProposal, error)); ok { - return rf(_a0) - } - if rf, ok := ret.Get(0).(func([]automation.CoordinatedBlockProposal) []automation.CoordinatedBlockProposal); ok { - r0 = rf(_a0) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]automation.CoordinatedBlockProposal) - } - } - - if rf, ok := ret.Get(1).(func([]automation.CoordinatedBlockProposal) error); ok { - r1 = rf(_a0) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// FilterResults provides a mock function with given fields: _a0 -func (_m *MockCoordinator) FilterResults(_a0 []automation.CheckResult) ([]automation.CheckResult, error) { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for FilterResults") - } - - var r0 []automation.CheckResult - var r1 error - if rf, ok := ret.Get(0).(func([]automation.CheckResult) ([]automation.CheckResult, error)); ok { - return rf(_a0) - } - if rf, ok := ret.Get(0).(func([]automation.CheckResult) []automation.CheckResult); ok { - r0 = rf(_a0) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]automation.CheckResult) - } - } - - if rf, ok := ret.Get(1).(func([]automation.CheckResult) error); ok { - r1 = rf(_a0) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// PreProcess provides a mock function with given fields: _a0, payloads -func (_m *MockCoordinator) PreProcess(_a0 context.Context, payloads []automation.UpkeepPayload) ([]automation.UpkeepPayload, error) { - ret := _m.Called(_a0, payloads) - - if len(ret) == 0 { - panic("no return value specified for PreProcess") - } - - var r0 []automation.UpkeepPayload - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, []automation.UpkeepPayload) ([]automation.UpkeepPayload, error)); ok { - return rf(_a0, payloads) - } - if rf, ok := ret.Get(0).(func(context.Context, []automation.UpkeepPayload) []automation.UpkeepPayload); ok { - r0 = rf(_a0, payloads) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]automation.UpkeepPayload) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, []automation.UpkeepPayload) error); ok { - r1 = rf(_a0, payloads) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// ShouldTransmit provides a mock function with given fields: _a0 -func (_m *MockCoordinator) ShouldTransmit(_a0 automation.ReportedUpkeep) bool { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for ShouldTransmit") - } - - var r0 bool - if rf, ok := ret.Get(0).(func(automation.ReportedUpkeep) bool); ok { - r0 = rf(_a0) - } else { - r0 = ret.Get(0).(bool) - } - - return r0 -} - -// NewMockCoordinator creates a new instance of MockCoordinator. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewMockCoordinator(t interface { - mock.TestingT - Cleanup(func()) -}) *MockCoordinator { - mock := &MockCoordinator{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/pkg/types/automation/mocks/encoder.generated.go b/pkg/types/automation/mocks/encoder.generated.go deleted file mode 100644 index 3e262cbc9..000000000 --- a/pkg/types/automation/mocks/encoder.generated.go +++ /dev/null @@ -1,93 +0,0 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. - -package mocks - -import ( - automation "github.com/smartcontractkit/chainlink-common/pkg/types/automation" - mock "github.com/stretchr/testify/mock" -) - -// MockEncoder is an autogenerated mock type for the Encoder type -type MockEncoder struct { - mock.Mock -} - -// Encode provides a mock function with given fields: _a0 -func (_m *MockEncoder) Encode(_a0 ...automation.CheckResult) ([]byte, error) { - _va := make([]interface{}, len(_a0)) - for _i := range _a0 { - _va[_i] = _a0[_i] - } - var _ca []interface{} - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - if len(ret) == 0 { - panic("no return value specified for Encode") - } - - var r0 []byte - var r1 error - if rf, ok := ret.Get(0).(func(...automation.CheckResult) ([]byte, error)); ok { - return rf(_a0...) - } - if rf, ok := ret.Get(0).(func(...automation.CheckResult) []byte); ok { - r0 = rf(_a0...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]byte) - } - } - - if rf, ok := ret.Get(1).(func(...automation.CheckResult) error); ok { - r1 = rf(_a0...) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// Extract provides a mock function with given fields: _a0 -func (_m *MockEncoder) Extract(_a0 []byte) ([]automation.ReportedUpkeep, error) { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for Extract") - } - - var r0 []automation.ReportedUpkeep - var r1 error - if rf, ok := ret.Get(0).(func([]byte) ([]automation.ReportedUpkeep, error)); ok { - return rf(_a0) - } - if rf, ok := ret.Get(0).(func([]byte) []automation.ReportedUpkeep); ok { - r0 = rf(_a0) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]automation.ReportedUpkeep) - } - } - - if rf, ok := ret.Get(1).(func([]byte) error); ok { - r1 = rf(_a0) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// NewMockEncoder creates a new instance of MockEncoder. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewMockEncoder(t interface { - mock.TestingT - Cleanup(func()) -}) *MockEncoder { - mock := &MockEncoder{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/pkg/types/automation/mocks/logeventprovider.generated.go b/pkg/types/automation/mocks/logeventprovider.generated.go deleted file mode 100644 index 4b88fc9ff..000000000 --- a/pkg/types/automation/mocks/logeventprovider.generated.go +++ /dev/null @@ -1,96 +0,0 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. - -package mocks - -import ( - context "context" - - automation "github.com/smartcontractkit/chainlink-common/pkg/types/automation" - - mock "github.com/stretchr/testify/mock" -) - -// MockLogEventProvider is an autogenerated mock type for the LogEventProvider type -type MockLogEventProvider struct { - mock.Mock -} - -// Close provides a mock function with given fields: -func (_m *MockLogEventProvider) Close() error { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for Close") - } - - var r0 error - if rf, ok := ret.Get(0).(func() error); ok { - r0 = rf() - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// GetLatestPayloads provides a mock function with given fields: _a0 -func (_m *MockLogEventProvider) GetLatestPayloads(_a0 context.Context) ([]automation.UpkeepPayload, error) { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for GetLatestPayloads") - } - - var r0 []automation.UpkeepPayload - var r1 error - if rf, ok := ret.Get(0).(func(context.Context) ([]automation.UpkeepPayload, error)); ok { - return rf(_a0) - } - if rf, ok := ret.Get(0).(func(context.Context) []automation.UpkeepPayload); ok { - r0 = rf(_a0) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]automation.UpkeepPayload) - } - } - - if rf, ok := ret.Get(1).(func(context.Context) error); ok { - r1 = rf(_a0) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// Start provides a mock function with given fields: _a0 -func (_m *MockLogEventProvider) Start(_a0 context.Context) error { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for Start") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context) error); ok { - r0 = rf(_a0) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// NewMockLogEventProvider creates a new instance of MockLogEventProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewMockLogEventProvider(t interface { - mock.TestingT - Cleanup(func()) -}) *MockLogEventProvider { - mock := &MockLogEventProvider{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/pkg/types/automation/mocks/metadatastore.generated.go b/pkg/types/automation/mocks/metadatastore.generated.go deleted file mode 100644 index 5ff1804e7..000000000 --- a/pkg/types/automation/mocks/metadatastore.generated.go +++ /dev/null @@ -1,133 +0,0 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. - -package mocks - -import ( - context "context" - - automation "github.com/smartcontractkit/chainlink-common/pkg/types/automation" - - mock "github.com/stretchr/testify/mock" -) - -// MockMetadataStore is an autogenerated mock type for the MetadataStore type -type MockMetadataStore struct { - mock.Mock -} - -// AddProposals provides a mock function with given fields: proposals -func (_m *MockMetadataStore) AddProposals(proposals ...automation.CoordinatedBlockProposal) { - _va := make([]interface{}, len(proposals)) - for _i := range proposals { - _va[_i] = proposals[_i] - } - var _ca []interface{} - _ca = append(_ca, _va...) - _m.Called(_ca...) -} - -// Close provides a mock function with given fields: -func (_m *MockMetadataStore) Close() error { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for Close") - } - - var r0 error - if rf, ok := ret.Get(0).(func() error); ok { - r0 = rf() - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// GetBlockHistory provides a mock function with given fields: -func (_m *MockMetadataStore) GetBlockHistory() automation.BlockHistory { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for GetBlockHistory") - } - - var r0 automation.BlockHistory - if rf, ok := ret.Get(0).(func() automation.BlockHistory); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(automation.BlockHistory) - } - } - - return r0 -} - -// RemoveProposals provides a mock function with given fields: proposals -func (_m *MockMetadataStore) RemoveProposals(proposals ...automation.CoordinatedBlockProposal) { - _va := make([]interface{}, len(proposals)) - for _i := range proposals { - _va[_i] = proposals[_i] - } - var _ca []interface{} - _ca = append(_ca, _va...) - _m.Called(_ca...) -} - -// SetBlockHistory provides a mock function with given fields: _a0 -func (_m *MockMetadataStore) SetBlockHistory(_a0 automation.BlockHistory) { - _m.Called(_a0) -} - -// Start provides a mock function with given fields: _a0 -func (_m *MockMetadataStore) Start(_a0 context.Context) error { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for Start") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context) error); ok { - r0 = rf(_a0) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// ViewProposals provides a mock function with given fields: utype -func (_m *MockMetadataStore) ViewProposals(utype automation.UpkeepType) []automation.CoordinatedBlockProposal { - ret := _m.Called(utype) - - if len(ret) == 0 { - panic("no return value specified for ViewProposals") - } - - var r0 []automation.CoordinatedBlockProposal - if rf, ok := ret.Get(0).(func(automation.UpkeepType) []automation.CoordinatedBlockProposal); ok { - r0 = rf(utype) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]automation.CoordinatedBlockProposal) - } - } - - return r0 -} - -// NewMockMetadataStore creates a new instance of MockMetadataStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewMockMetadataStore(t interface { - mock.TestingT - Cleanup(func()) -}) *MockMetadataStore { - mock := &MockMetadataStore{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/pkg/types/automation/mocks/payloadbuilder.generated.go b/pkg/types/automation/mocks/payloadbuilder.generated.go deleted file mode 100644 index 87f5718dc..000000000 --- a/pkg/types/automation/mocks/payloadbuilder.generated.go +++ /dev/null @@ -1,67 +0,0 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. - -package mocks - -import ( - context "context" - - automation "github.com/smartcontractkit/chainlink-common/pkg/types/automation" - - mock "github.com/stretchr/testify/mock" -) - -// MockPayloadBuilder is an autogenerated mock type for the PayloadBuilder type -type MockPayloadBuilder struct { - mock.Mock -} - -// BuildPayloads provides a mock function with given fields: _a0, _a1 -func (_m *MockPayloadBuilder) BuildPayloads(_a0 context.Context, _a1 ...automation.CoordinatedBlockProposal) ([]automation.UpkeepPayload, error) { - _va := make([]interface{}, len(_a1)) - for _i := range _a1 { - _va[_i] = _a1[_i] - } - var _ca []interface{} - _ca = append(_ca, _a0) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - if len(ret) == 0 { - panic("no return value specified for BuildPayloads") - } - - var r0 []automation.UpkeepPayload - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, ...automation.CoordinatedBlockProposal) ([]automation.UpkeepPayload, error)); ok { - return rf(_a0, _a1...) - } - if rf, ok := ret.Get(0).(func(context.Context, ...automation.CoordinatedBlockProposal) []automation.UpkeepPayload); ok { - r0 = rf(_a0, _a1...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]automation.UpkeepPayload) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, ...automation.CoordinatedBlockProposal) error); ok { - r1 = rf(_a0, _a1...) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// NewMockPayloadBuilder creates a new instance of MockPayloadBuilder. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewMockPayloadBuilder(t interface { - mock.TestingT - Cleanup(func()) -}) *MockPayloadBuilder { - mock := &MockPayloadBuilder{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/pkg/types/automation/mocks/ratio.generated.go b/pkg/types/automation/mocks/ratio.generated.go deleted file mode 100644 index 89c15149a..000000000 --- a/pkg/types/automation/mocks/ratio.generated.go +++ /dev/null @@ -1,42 +0,0 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. - -package mocks - -import mock "github.com/stretchr/testify/mock" - -// MockRatio is an autogenerated mock type for the Ratio type -type MockRatio struct { - mock.Mock -} - -// OfInt provides a mock function with given fields: _a0 -func (_m *MockRatio) OfInt(_a0 int) int { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for OfInt") - } - - var r0 int - if rf, ok := ret.Get(0).(func(int) int); ok { - r0 = rf(_a0) - } else { - r0 = ret.Get(0).(int) - } - - return r0 -} - -// NewMockRatio creates a new instance of MockRatio. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewMockRatio(t interface { - mock.TestingT - Cleanup(func()) -}) *MockRatio { - mock := &MockRatio{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/pkg/types/automation/mocks/recoverableprovider.generated.go b/pkg/types/automation/mocks/recoverableprovider.generated.go deleted file mode 100644 index 7b914c78c..000000000 --- a/pkg/types/automation/mocks/recoverableprovider.generated.go +++ /dev/null @@ -1,60 +0,0 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. - -package mocks - -import ( - context "context" - - automation "github.com/smartcontractkit/chainlink-common/pkg/types/automation" - - mock "github.com/stretchr/testify/mock" -) - -// MockRecoverableProvider is an autogenerated mock type for the RecoverableProvider type -type MockRecoverableProvider struct { - mock.Mock -} - -// GetRecoveryProposals provides a mock function with given fields: _a0 -func (_m *MockRecoverableProvider) GetRecoveryProposals(_a0 context.Context) ([]automation.UpkeepPayload, error) { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for GetRecoveryProposals") - } - - var r0 []automation.UpkeepPayload - var r1 error - if rf, ok := ret.Get(0).(func(context.Context) ([]automation.UpkeepPayload, error)); ok { - return rf(_a0) - } - if rf, ok := ret.Get(0).(func(context.Context) []automation.UpkeepPayload); ok { - r0 = rf(_a0) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]automation.UpkeepPayload) - } - } - - if rf, ok := ret.Get(1).(func(context.Context) error); ok { - r1 = rf(_a0) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// NewMockRecoverableProvider creates a new instance of MockRecoverableProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewMockRecoverableProvider(t interface { - mock.TestingT - Cleanup(func()) -}) *MockRecoverableProvider { - mock := &MockRecoverableProvider{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/pkg/types/automation/mocks/result_store.generated.go b/pkg/types/automation/mocks/result_store.generated.go deleted file mode 100644 index 625aad245..000000000 --- a/pkg/types/automation/mocks/result_store.generated.go +++ /dev/null @@ -1,79 +0,0 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. - -package mocks - -import ( - automation "github.com/smartcontractkit/chainlink-common/pkg/types/automation" - mock "github.com/stretchr/testify/mock" -) - -// MockResultStore is an autogenerated mock type for the ResultStore type -type MockResultStore struct { - mock.Mock -} - -// Add provides a mock function with given fields: _a0 -func (_m *MockResultStore) Add(_a0 ...automation.CheckResult) { - _va := make([]interface{}, len(_a0)) - for _i := range _a0 { - _va[_i] = _a0[_i] - } - var _ca []interface{} - _ca = append(_ca, _va...) - _m.Called(_ca...) -} - -// Remove provides a mock function with given fields: _a0 -func (_m *MockResultStore) Remove(_a0 ...string) { - _va := make([]interface{}, len(_a0)) - for _i := range _a0 { - _va[_i] = _a0[_i] - } - var _ca []interface{} - _ca = append(_ca, _va...) - _m.Called(_ca...) -} - -// View provides a mock function with given fields: -func (_m *MockResultStore) View() ([]automation.CheckResult, error) { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for View") - } - - var r0 []automation.CheckResult - var r1 error - if rf, ok := ret.Get(0).(func() ([]automation.CheckResult, error)); ok { - return rf() - } - if rf, ok := ret.Get(0).(func() []automation.CheckResult); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]automation.CheckResult) - } - } - - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// NewMockResultStore creates a new instance of MockResultStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewMockResultStore(t interface { - mock.TestingT - Cleanup(func()) -}) *MockResultStore { - mock := &MockResultStore{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/pkg/types/automation/mocks/runnable.generated.go b/pkg/types/automation/mocks/runnable.generated.go deleted file mode 100644 index 808197751..000000000 --- a/pkg/types/automation/mocks/runnable.generated.go +++ /dev/null @@ -1,67 +0,0 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. - -package mocks - -import ( - context "context" - - automation "github.com/smartcontractkit/chainlink-common/pkg/types/automation" - - mock "github.com/stretchr/testify/mock" -) - -// MockRunnable is an autogenerated mock type for the Runnable type -type MockRunnable struct { - mock.Mock -} - -// CheckUpkeeps provides a mock function with given fields: _a0, _a1 -func (_m *MockRunnable) CheckUpkeeps(_a0 context.Context, _a1 ...automation.UpkeepPayload) ([]automation.CheckResult, error) { - _va := make([]interface{}, len(_a1)) - for _i := range _a1 { - _va[_i] = _a1[_i] - } - var _ca []interface{} - _ca = append(_ca, _a0) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - if len(ret) == 0 { - panic("no return value specified for CheckUpkeeps") - } - - var r0 []automation.CheckResult - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, ...automation.UpkeepPayload) ([]automation.CheckResult, error)); ok { - return rf(_a0, _a1...) - } - if rf, ok := ret.Get(0).(func(context.Context, ...automation.UpkeepPayload) []automation.CheckResult); ok { - r0 = rf(_a0, _a1...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]automation.CheckResult) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, ...automation.UpkeepPayload) error); ok { - r1 = rf(_a0, _a1...) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// NewMockRunnable creates a new instance of MockRunnable. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewMockRunnable(t interface { - mock.TestingT - Cleanup(func()) -}) *MockRunnable { - mock := &MockRunnable{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/pkg/types/automation/mocks/transmit_event_provider.generated.go b/pkg/types/automation/mocks/transmit_event_provider.generated.go deleted file mode 100644 index da812eeaf..000000000 --- a/pkg/types/automation/mocks/transmit_event_provider.generated.go +++ /dev/null @@ -1,60 +0,0 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. - -package mocks - -import ( - context "context" - - automation "github.com/smartcontractkit/chainlink-common/pkg/types/automation" - - mock "github.com/stretchr/testify/mock" -) - -// TransmitEventProvider is an autogenerated mock type for the TransmitEventProvider type -type TransmitEventProvider struct { - mock.Mock -} - -// GetLatestEvents provides a mock function with given fields: _a0 -func (_m *TransmitEventProvider) GetLatestEvents(_a0 context.Context) ([]automation.TransmitEvent, error) { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for GetLatestEvents") - } - - var r0 []automation.TransmitEvent - var r1 error - if rf, ok := ret.Get(0).(func(context.Context) ([]automation.TransmitEvent, error)); ok { - return rf(_a0) - } - if rf, ok := ret.Get(0).(func(context.Context) []automation.TransmitEvent); ok { - r0 = rf(_a0) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]automation.TransmitEvent) - } - } - - if rf, ok := ret.Get(1).(func(context.Context) error); ok { - r1 = rf(_a0) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// NewTransmitEventProvider creates a new instance of TransmitEventProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewTransmitEventProvider(t interface { - mock.TestingT - Cleanup(func()) -}) *TransmitEventProvider { - mock := &TransmitEventProvider{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/pkg/types/automation/mocks/upkeep_state_reader.go b/pkg/types/automation/mocks/upkeep_state_reader.go deleted file mode 100644 index 5a815987a..000000000 --- a/pkg/types/automation/mocks/upkeep_state_reader.go +++ /dev/null @@ -1,67 +0,0 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. - -package mocks - -import ( - context "context" - - automation "github.com/smartcontractkit/chainlink-common/pkg/types/automation" - - mock "github.com/stretchr/testify/mock" -) - -// UpkeepStateReader is an autogenerated mock type for the UpkeepStateReader type -type UpkeepStateReader struct { - mock.Mock -} - -// SelectByWorkIDs provides a mock function with given fields: ctx, workIDs -func (_m *UpkeepStateReader) SelectByWorkIDs(ctx context.Context, workIDs ...string) ([]automation.UpkeepState, error) { - _va := make([]interface{}, len(workIDs)) - for _i := range workIDs { - _va[_i] = workIDs[_i] - } - var _ca []interface{} - _ca = append(_ca, ctx) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - if len(ret) == 0 { - panic("no return value specified for SelectByWorkIDs") - } - - var r0 []automation.UpkeepState - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, ...string) ([]automation.UpkeepState, error)); ok { - return rf(ctx, workIDs...) - } - if rf, ok := ret.Get(0).(func(context.Context, ...string) []automation.UpkeepState); ok { - r0 = rf(ctx, workIDs...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]automation.UpkeepState) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, ...string) error); ok { - r1 = rf(ctx, workIDs...) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// NewUpkeepStateReader creates a new instance of UpkeepStateReader. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewUpkeepStateReader(t interface { - mock.TestingT - Cleanup(func()) -}) *UpkeepStateReader { - mock := &UpkeepStateReader{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/pkg/types/automation/mocks/upkeep_state_updater.generated.go b/pkg/types/automation/mocks/upkeep_state_updater.generated.go deleted file mode 100644 index dc550a14b..000000000 --- a/pkg/types/automation/mocks/upkeep_state_updater.generated.go +++ /dev/null @@ -1,48 +0,0 @@ -// Code generated by mockery v2.38.0. DO NOT EDIT. - -package mocks - -import ( - context "context" - - automation "github.com/smartcontractkit/chainlink-common/pkg/types/automation" - - mock "github.com/stretchr/testify/mock" -) - -// MockUpkeepStateUpdater is an autogenerated mock type for the UpkeepStateUpdater type -type MockUpkeepStateUpdater struct { - mock.Mock -} - -// SetUpkeepState provides a mock function with given fields: _a0, _a1, _a2 -func (_m *MockUpkeepStateUpdater) SetUpkeepState(_a0 context.Context, _a1 automation.CheckResult, _a2 automation.UpkeepState) error { - ret := _m.Called(_a0, _a1, _a2) - - if len(ret) == 0 { - panic("no return value specified for SetUpkeepState") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, automation.CheckResult, automation.UpkeepState) error); ok { - r0 = rf(_a0, _a1, _a2) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// NewMockUpkeepStateUpdater creates a new instance of MockUpkeepStateUpdater. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewMockUpkeepStateUpdater(t interface { - mock.TestingT - Cleanup(func()) -}) *MockUpkeepStateUpdater { - mock := &MockUpkeepStateUpdater{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} From 90323aedcd92ccf4209ed78babf2a966590ae526 Mon Sep 17 00:00:00 2001 From: Fergal Gribben Date: Mon, 8 Jan 2024 15:41:18 +0000 Subject: [PATCH 3/6] Add mercury credentials --- pkg/types/relayer.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pkg/types/relayer.go b/pkg/types/relayer.go index 5ad2d4568..9b7873863 100644 --- a/pkg/types/relayer.go +++ b/pkg/types/relayer.go @@ -16,12 +16,20 @@ type PluginArgs struct { } type RelayArgs struct { - ExternalJobID uuid.UUID - JobID int32 - ContractID string - New bool // Whether this is a first time job add. - RelayConfig []byte - ProviderType string + ExternalJobID uuid.UUID + JobID int32 + ContractID string + New bool // Whether this is a first time job add. + RelayConfig []byte + ProviderType string + MercuryCredentials *MercuryCredentials +} + +type MercuryCredentials struct { + LegacyURL string + URL string + Username string + Password string } type ChainStatus struct { From 15ef2ef0d74296bbf5c667bc8084e74d22ed0f26 Mon Sep 17 00:00:00 2001 From: Fergal Gribben Date: Tue, 9 Jan 2024 17:12:58 +0000 Subject: [PATCH 4/6] Use services.Service in EventProvider --- pkg/types/automation/interfaces.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pkg/types/automation/interfaces.go b/pkg/types/automation/interfaces.go index 9a3fdbff2..1e6da8dfc 100644 --- a/pkg/types/automation/interfaces.go +++ b/pkg/types/automation/interfaces.go @@ -2,6 +2,7 @@ package automation import ( "context" + "github.com/smartcontractkit/chainlink-common/pkg/services" "io" ) @@ -25,11 +26,7 @@ type Registry interface { } type EventProvider interface { - Name() string - Start(_ context.Context) error - Close() error - Ready() error - HealthReport() map[string]error + services.Service GetLatestEvents(ctx context.Context) ([]TransmitEvent, error) } From 1755c71029a27163963325579239003c8c8e6141 Mon Sep 17 00:00:00 2001 From: Fergal Gribben Date: Wed, 10 Jan 2024 15:16:34 +0000 Subject: [PATCH 5/6] goimports --- pkg/types/automation/interfaces.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/types/automation/interfaces.go b/pkg/types/automation/interfaces.go index 1e6da8dfc..6213f5722 100644 --- a/pkg/types/automation/interfaces.go +++ b/pkg/types/automation/interfaces.go @@ -2,8 +2,9 @@ package automation import ( "context" - "github.com/smartcontractkit/chainlink-common/pkg/services" "io" + + "github.com/smartcontractkit/chainlink-common/pkg/services" ) type UpkeepTypeGetter func(UpkeepIdentifier) UpkeepType From 306f99b807dff1321bdc620b6d78a5f89411f510 Mon Sep 17 00:00:00 2001 From: Fergal Gribben Date: Fri, 12 Jan 2024 18:28:18 +0000 Subject: [PATCH 6/6] Reduce the number of automation types needed in common --- pkg/types/automation/basetypes.go | 16 --------- pkg/types/automation/interfaces.go | 58 ------------------------------ 2 files changed, 74 deletions(-) diff --git a/pkg/types/automation/basetypes.go b/pkg/types/automation/basetypes.go index 45874ccde..96013c95f 100644 --- a/pkg/types/automation/basetypes.go +++ b/pkg/types/automation/basetypes.go @@ -35,14 +35,6 @@ func init() { checkResultStringTemplate = strings.Replace(checkResultStringTemplate, "\n", "", -1) } -type UpkeepType uint8 - -const ( - // Exploratory AUTO 4335: add type for unknown - ConditionTrigger UpkeepType = iota - LogTrigger -) - type TransmitEventType int const ( @@ -339,11 +331,3 @@ type ReportedUpkeep struct { // WorkID represents the unit of work for the reported upkeep WorkID string } - -// RetryRecord is a record of a payload that can be retried after a certain interval. -type RetryRecord struct { - // payload is the desired unit of work to be retried - Payload UpkeepPayload - // Interval is the time interval after which the same payload can be retried. - Interval time.Duration -} diff --git a/pkg/types/automation/interfaces.go b/pkg/types/automation/interfaces.go index 6213f5722..a42913ef7 100644 --- a/pkg/types/automation/interfaces.go +++ b/pkg/types/automation/interfaces.go @@ -7,9 +7,6 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/services" ) -type UpkeepTypeGetter func(UpkeepIdentifier) UpkeepType -type WorkIDGenerator func(UpkeepIdentifier, Trigger) string - // UpkeepStateStore is the interface for managing upkeeps final state in a local store. type UpkeepStateStore interface { UpkeepStateUpdater @@ -59,10 +56,6 @@ type RecoverableProvider interface { GetRecoveryProposals(context.Context) ([]UpkeepPayload, error) } -type TransmitEventProvider interface { - GetLatestEvents(context.Context) ([]TransmitEvent, error) -} - type ConditionalUpkeepProvider interface { GetActiveUpkeeps(context.Context) ([]UpkeepPayload, error) } @@ -72,11 +65,6 @@ type PayloadBuilder interface { BuildPayloads(context.Context, ...CoordinatedBlockProposal) ([]UpkeepPayload, error) } -type Runnable interface { - // Can get results for a subset of payloads along with an error - CheckUpkeeps(context.Context, ...UpkeepPayload) ([]CheckResult, error) -} - type BlockSubscriber interface { // Subscribe provides an identifier integer, a new channel, and potentially an error Subscribe() (int, chan BlockHistory, error) @@ -89,49 +77,3 @@ type BlockSubscriber interface { type UpkeepStateUpdater interface { SetUpkeepState(context.Context, CheckResult, UpkeepState) error } - -type RetryQueue interface { - // Enqueue adds new items to the queue - Enqueue(items ...RetryRecord) error - // Dequeue returns the next n items in the queue, considering retry time schedules - Dequeue(n int) ([]UpkeepPayload, error) -} - -type ProposalQueue interface { - // Enqueue adds new items to the queue - Enqueue(items ...CoordinatedBlockProposal) error - // Dequeue returns the next n items in the queue, considering retry time schedules - Dequeue(t UpkeepType, n int) ([]CoordinatedBlockProposal, error) -} - -type ResultStore interface { - Add(...CheckResult) - Remove(...string) - View() ([]CheckResult, error) -} - -type Coordinator interface { - PreProcess(_ context.Context, payloads []UpkeepPayload) ([]UpkeepPayload, error) - - Accept(ReportedUpkeep) bool - ShouldTransmit(ReportedUpkeep) bool - FilterResults([]CheckResult) ([]CheckResult, error) - FilterProposals([]CoordinatedBlockProposal) ([]CoordinatedBlockProposal, error) -} - -type MetadataStore interface { - SetBlockHistory(BlockHistory) - GetBlockHistory() BlockHistory - - AddProposals(proposals ...CoordinatedBlockProposal) - ViewProposals(utype UpkeepType) []CoordinatedBlockProposal - RemoveProposals(proposals ...CoordinatedBlockProposal) - - Start(context.Context) error - Close() error -} - -type Ratio interface { - // OfInt should return n out of x such that n/x ~ r (ratio) - OfInt(int) int -}