From 6532652c28fe6b929420e03a829386249b7627f3 Mon Sep 17 00:00:00 2001 From: Mateusz Sekara Date: Wed, 26 Feb 2025 16:54:53 +0100 Subject: [PATCH] Replacing with Mergo --- deployment/ccip/changeset/globals/ocr3.go | 43 +++---------------- .../ccip/changeset/globals/ocr3_test.go | 25 +++++++++++ 2 files changed, 32 insertions(+), 36 deletions(-) create mode 100644 deployment/ccip/changeset/globals/ocr3_test.go diff --git a/deployment/ccip/changeset/globals/ocr3.go b/deployment/ccip/changeset/globals/ocr3.go index dd9fe3c5ada..903f9ab00ca 100644 --- a/deployment/ccip/changeset/globals/ocr3.go +++ b/deployment/ccip/changeset/globals/ocr3.go @@ -1,8 +1,11 @@ package globals import ( + "fmt" "time" + "dario.cat/mergo" + "github.com/smartcontractkit/chainlink/deployment/common/types" ) @@ -86,41 +89,9 @@ var ( ) func withOverrides(base types.OCRParameters, overrides types.OCRParameters) types.OCRParameters { - if overrides.DeltaProgress != 0 { - base.DeltaProgress = overrides.DeltaProgress - } - if overrides.DeltaResend != 0 { - base.DeltaResend = overrides.DeltaResend - } - if overrides.DeltaInitial != 0 { - base.DeltaInitial = overrides.DeltaInitial - } - if overrides.DeltaRound != 0 { - base.DeltaRound = overrides.DeltaRound - } - if overrides.DeltaGrace != 0 { - base.DeltaGrace = overrides.DeltaGrace - } - if overrides.DeltaCertifiedCommitRequest != 0 { - base.DeltaCertifiedCommitRequest = overrides.DeltaCertifiedCommitRequest - } - if overrides.DeltaStage != 0 { - base.DeltaStage = overrides.DeltaStage - } - if overrides.Rmax != 0 { - base.Rmax = overrides.Rmax - } - if overrides.MaxDurationQuery != 0 { - base.MaxDurationQuery = overrides.MaxDurationQuery - } - if overrides.MaxDurationObservation != 0 { - base.MaxDurationObservation = overrides.MaxDurationObservation - } - if overrides.MaxDurationShouldAcceptAttestedReport != 0 { - base.MaxDurationShouldAcceptAttestedReport = overrides.MaxDurationShouldAcceptAttestedReport - } - if overrides.MaxDurationShouldTransmitAcceptedReport != 0 { - base.MaxDurationShouldTransmitAcceptedReport = overrides.MaxDurationShouldTransmitAcceptedReport + outcome := base + if err := mergo.Merge(&outcome, overrides, mergo.WithOverride); err != nil { + panic(fmt.Sprintf("error while building an OCR config %v", err)) } - return base + return outcome } diff --git a/deployment/ccip/changeset/globals/ocr3_test.go b/deployment/ccip/changeset/globals/ocr3_test.go new file mode 100644 index 00000000000..d9699376a90 --- /dev/null +++ b/deployment/ccip/changeset/globals/ocr3_test.go @@ -0,0 +1,25 @@ +package globals + +import ( + "github.com/stretchr/testify/assert" + "testing" + "time" +) + +func Test_MergeWithOverrides(t *testing.T) { + assert.Equal(t, ExecOCRParams.DeltaProgress, ExecOCRParamsForEthereum.DeltaProgress) + assert.Equal(t, ExecOCRParams.DeltaResend, ExecOCRParamsForEthereum.DeltaResend) + assert.Equal(t, ExecOCRParams.DeltaInitial, ExecOCRParamsForEthereum.DeltaInitial) + assert.Equal(t, ExecOCRParams.DeltaGrace, ExecOCRParamsForEthereum.DeltaGrace) + assert.Equal(t, ExecOCRParams.DeltaCertifiedCommitRequest, ExecOCRParamsForEthereum.DeltaCertifiedCommitRequest) + assert.Equal(t, ExecOCRParams.MaxDurationQuery, ExecOCRParamsForEthereum.MaxDurationQuery) + assert.Equal(t, ExecOCRParams.MaxDurationObservation, ExecOCRParamsForEthereum.MaxDurationObservation) + assert.Equal(t, ExecOCRParams.MaxDurationShouldAcceptAttestedReport, ExecOCRParamsForEthereum.MaxDurationShouldAcceptAttestedReport) + assert.Equal(t, ExecOCRParams.MaxDurationShouldTransmitAcceptedReport, ExecOCRParamsForEthereum.MaxDurationShouldTransmitAcceptedReport) + assert.Equal(t, ExecOCRParams.MaxDurationQuery, ExecOCRParamsForEthereum.MaxDurationQuery) + + assert.Equal(t, 90*time.Second, ExecOCRParamsForEthereum.DeltaRound) + assert.Equal(t, 60*time.Second, ExecOCRParamsForEthereum.DeltaStage) + assert.Equal(t, 200*time.Millisecond, ExecOCRParams.MaxDurationQuery) + assert.Equal(t, 200*time.Millisecond, ExecOCRParamsForEthereum.MaxDurationQuery) +}