Skip to content

Commit

Permalink
More mocked sources tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghestrimtu committed Feb 28, 2022
1 parent 9333b56 commit 6d558d8
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 23 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ require (
github.com/go-openapi/jsonreference v0.19.6 // indirect
github.com/go-openapi/swag v0.19.15 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/gateway v1.1.0 // indirect
Expand Down Expand Up @@ -304,7 +303,6 @@ require (
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
golang.org/x/tools v0.1.7 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220107163113-42d7afdf6368 // indirect
google.golang.org/grpc v1.43.0 // indirect
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,6 @@ github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LB
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw=
github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/go-test/deep v1.0.7/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8=
github.com/go-zookeeper/zk v1.0.2/go.mod h1:nOB03cncLtlp4t+UAkGSV+9beXP/akpekBwL+UX1Qcw=
Expand Down
3 changes: 1 addition & 2 deletions tests/e2e/chaos/chaos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
tc "github.com/smartcontractkit/chainlink-terra/tests/e2e/common"
"github.com/smartcontractkit/chainlink-terra/tests/e2e/smoke/common"
"github.com/smartcontractkit/integrations-framework/actions"
)
Expand All @@ -16,7 +15,7 @@ var _ = Describe("Solana chaos suite", func() {
By("Deploying OCRv2 cluster", func() {
state.DeployCluster(5, true)
state.LabelChaosGroups()
tc.ImitateSource(state.MockServer, common.SourceChangeInterval, 2, 10)
state.ImitateSource(common.SourceChangeInterval, 2, 10)
})
})
It("Can tolerate chaos experiments", func() {
Expand Down
13 changes: 1 addition & 12 deletions tests/e2e/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,6 @@ func DefaultOffChainConfigParamsFromNodes(nodes []client.Chainlink) (contracts.O
}, nkb, nil
}

func ImitateSource(mockServer *client.MockserverClient, changeInterval time.Duration, min int, max int) {
go func() {
for {
_ = mockServer.SetValuePath("/variable", min)
time.Sleep(changeInterval)
_ = mockServer.SetValuePath("/variable", max)
time.Sleep(changeInterval)
}
}()
}

func CreateJobs(ocr2Addr string, nodes []client.Chainlink, nkb []NodeKeysBundle, mock *client.MockserverClient) error {
bootstrapPeers := []client.P2PData{
{
Expand All @@ -184,7 +173,7 @@ func CreateJobs(ocr2Addr string, nodes []client.Chainlink, nkb []NodeKeysBundle,
}
sourceValueBridge := client.BridgeTypeAttributes{
Name: "variable",
URL: fmt.Sprintf("%s/variable", mock.Config.ClusterURL),
URL: fmt.Sprintf("%s/node%d", mock.Config.ClusterURL, nIdx),
RequestData: "{}",
}
observationSource := client.ObservationSourceSpecBridge(sourceValueBridge)
Expand Down
3 changes: 1 addition & 2 deletions tests/e2e/migration/ocr2_spec_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/smartcontractkit/chainlink-terra/tests/e2e/common"
tc "github.com/smartcontractkit/chainlink-terra/tests/e2e/smoke/common"
"github.com/smartcontractkit/integrations-framework/actions"
)
Expand All @@ -30,7 +29,7 @@ var _ = Describe("Terra OCRv2 @ocr-spec-migration", func() {
Fail("Provide CHAINLINK_VERSION_TO variable: a version on which we migrate")
}
state.DeployCluster(nodes, true)
common.ImitateSource(state.MockServer, 1*time.Second, 2, 10)
state.ImitateSource(1*time.Second, 2, 10)
})
})

Expand Down
31 changes: 29 additions & 2 deletions tests/e2e/smoke/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package common

import (
"encoding/json"
"fmt"
"math/big"
"os"
"time"
Expand Down Expand Up @@ -159,10 +160,36 @@ func (m *OCRv2State) DeployContracts() {
Expect(m.Err).ShouldNot(HaveOccurred())
}

func (m *OCRv2State) SetAllAdapterResponsesToTheSameValue(response int) {
for i := range m.Nodes {
path := fmt.Sprintf("/node%d", i)
m.Err = m.MockServer.SetValuePath(path, response)
Expect(m.Err).ShouldNot(HaveOccurred())
}
}

func (m *OCRv2State) SetAllAdapterResponsesToDifferentValues(responses []int) {
Expect(len(responses)).Should(BeNumerically("==", len(m.Nodes)))
for i := range m.Nodes {
m.Err = m.MockServer.SetValuePath(fmt.Sprintf("/node%d", i), responses[i])
Expect(m.Err).ShouldNot(HaveOccurred())
}
}

func (m *OCRv2State) ImitateSource(changeInterval time.Duration, min int, max int) {
go func() {
for {
m.SetAllAdapterResponsesToTheSameValue(min)
time.Sleep(changeInterval)
m.SetAllAdapterResponsesToTheSameValue(max)
time.Sleep(changeInterval)
}
}()
}

// CreateJobs creating OCR jobs and EA stubs
func (m *OCRv2State) CreateJobs() {
m.Err = m.MockServer.SetValuePath("/variable", 5)
Expect(m.Err).ShouldNot(HaveOccurred())
m.SetAllAdapterResponsesToTheSameValue(5)
m.Err = m.MockServer.SetValuePath("/juels", 1)
Expect(m.Err).ShouldNot(HaveOccurred())
m.Err = common.CreateJobs(m.OCR2.Address(), m.Nodes, m.NodeKeysBundle, m.MockServer)
Expand Down
3 changes: 1 addition & 2 deletions tests/e2e/smoke/ocr2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/smartcontractkit/chainlink-terra/tests/e2e/common"
tc "github.com/smartcontractkit/chainlink-terra/tests/e2e/smoke/common"
"github.com/smartcontractkit/integrations-framework/actions"
)
Expand All @@ -17,7 +16,7 @@ var _ = Describe("Terra OCRv2 @ocr", func() {
state = &tc.OCRv2State{}
By("Deoloying the cluster", func() {
state.DeployCluster(5, false)
common.ImitateSource(state.MockServer, 1*time.Second, 2, 10)
state.ImitateSource(1*time.Second, 2, 10)
})
})

Expand Down

0 comments on commit 6d558d8

Please sign in to comment.