Skip to content

Commit

Permalink
Replacing with Mergo
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz-sekara committed Feb 26, 2025
1 parent 5ad49b4 commit 6532652
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 36 deletions.
43 changes: 7 additions & 36 deletions deployment/ccip/changeset/globals/ocr3.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package globals

import (
"fmt"
"time"

"dario.cat/mergo"

"github.com/smartcontractkit/chainlink/deployment/common/types"
)

Expand Down Expand Up @@ -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
}
25 changes: 25 additions & 0 deletions deployment/ccip/changeset/globals/ocr3_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package globals

import (
"github.com/stretchr/testify/assert"

Check failure on line 4 in deployment/ccip/changeset/globals/ocr3_test.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (deployment)

File is not properly formatted (goimports)
"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)
}

0 comments on commit 6532652

Please sign in to comment.