Skip to content

Commit

Permalink
another fix for forwarder tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofel committed Jun 26, 2024
1 parent f648817 commit 1779ee9
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 82 deletions.
4 changes: 2 additions & 2 deletions integration-tests/actions/ocr2_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func CreateOCRv2Jobs(
mockserver *ctfClient.MockserverClient,
mockServerValue int, // Value to get from the mock server when querying the path
chainId int64, // EVM chain ID
forwardingAllowed bool,
withForwarders bool,
) error {
// Collect P2P ID
bootstrapP2PIds, err := bootstrapNode.MustReadP2PKeys()
Expand Down Expand Up @@ -266,7 +266,7 @@ func CreateOCRv2Jobs(
JobType: "offchainreporting2",
MaxTaskDuration: "1m",
ObservationSource: client.ObservationSourceSpecBridge(bta),
ForwardingAllowed: forwardingAllowed,
ForwardingAllowed: withForwarders,
OCR2OracleSpec: job.OCR2OracleSpec{
PluginType: "median",
Relay: "evm",
Expand Down
73 changes: 5 additions & 68 deletions integration-tests/actions/ocr_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ package actions
import (
"fmt"
"strings"
"testing"

"github.com/google/uuid"
"github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"

ctfClient "github.com/smartcontractkit/chainlink-testing-framework/client"
Expand All @@ -26,7 +24,8 @@ func CreateOCRJobs(
workerNodes []*client.ChainlinkK8sClient,
mockValue int,
mockserver *ctfClient.MockserverClient,
evmChainID string,
evmChainID int64,
withForwarders bool,
) error {
for _, ocrInstance := range ocrInstances {
bootstrapP2PIds, err := bootstrapNode.MustReadP2PKeys()
Expand All @@ -37,7 +36,7 @@ func CreateOCRJobs(
bootstrapSpec := &client.OCRBootstrapJobSpec{
Name: fmt.Sprintf("bootstrap-%s", uuid.New().String()),
ContractAddress: ocrInstance.Address(),
EVMChainID: evmChainID,
EVMChainID: fmt.Sprint(evmChainID),
P2PPeerID: bootstrapP2PId,
IsBootstrapPeer: true,
}
Expand Down Expand Up @@ -82,12 +81,13 @@ func CreateOCRJobs(
bootstrapPeers := []*client.ChainlinkClient{bootstrapNode.ChainlinkClient}
ocrSpec := &client.OCRTaskJobSpec{
ContractAddress: ocrInstance.Address(),
EVMChainID: evmChainID,
EVMChainID: fmt.Sprint(evmChainID),
P2PPeerID: nodeP2PId,
P2PBootstrapPeers: bootstrapPeers,
KeyBundleID: nodeOCRKeyId,
TransmitterAddress: nodeTransmitterAddress,
ObservationSource: client.ObservationSourceSpecBridge(bta),
ForwardingAllowed: withForwarders,
}
_, err = node.MustCreateJob(ocrSpec)
if err != nil {
Expand All @@ -98,69 +98,6 @@ func CreateOCRJobs(
return nil
}

// CreateOCRJobsWithForwarder bootstraps the first node and to the other nodes sends ocr jobs that
// read from different adapters, to be used in combination with SetAdapterResponses
func CreateOCRJobsWithForwarder(
t *testing.T,
ocrInstances []contracts.OffchainAggregator,
bootstrapNode *client.ChainlinkK8sClient,
workerNodes []*client.ChainlinkK8sClient,
mockValue int,
mockserver *ctfClient.MockserverClient,
evmChainID int64,
) {
for _, ocrInstance := range ocrInstances {
bootstrapP2PIds, err := bootstrapNode.MustReadP2PKeys()
require.NoError(t, err, "Shouldn't fail reading P2P keys from bootstrap node")
bootstrapP2PId := bootstrapP2PIds.Data[0].Attributes.PeerID
bootstrapSpec := &client.OCRBootstrapJobSpec{
Name: fmt.Sprintf("bootstrap-%s", uuid.New().String()),
ContractAddress: ocrInstance.Address(),
EVMChainID: fmt.Sprint(evmChainID),
P2PPeerID: bootstrapP2PId,
IsBootstrapPeer: true,
}
_, err = bootstrapNode.MustCreateJob(bootstrapSpec)
require.NoError(t, err, "Shouldn't fail creating bootstrap job on bootstrap node")

for nodeIndex, node := range workerNodes {
nodeP2PIds, err := node.MustReadP2PKeys()
require.NoError(t, err, "Shouldn't fail reading P2P keys from OCR node %d", nodeIndex+1)
nodeP2PId := nodeP2PIds.Data[0].Attributes.PeerID
nodeTransmitterAddress, err := node.PrimaryEthAddress()
require.NoError(t, err, "Shouldn't fail getting primary ETH address from OCR node %d", nodeIndex+1)
nodeOCRKeys, err := node.MustReadOCRKeys()
require.NoError(t, err, "Shouldn't fail getting OCR keys from OCR node %d", nodeIndex+1)
nodeOCRKeyId := nodeOCRKeys.Data[0].ID

nodeContractPairID, err := BuildNodeContractPairID(node, ocrInstance)
require.NoError(t, err, "Failed building node contract pair ID for mockserver")
bta := &client.BridgeTypeAttributes{
Name: nodeContractPairID,
URL: fmt.Sprintf("%s/%s", mockserver.Config.ClusterURL, strings.TrimPrefix(nodeContractPairID, "/")),
}
err = SetAdapterResponse(mockValue, ocrInstance, node, mockserver)
require.NoError(t, err, "Failed setting adapter responses for node %d", nodeIndex+1)
err = node.MustCreateBridge(bta)
require.NoError(t, err, "Failed creating bridge on OCR node %d", nodeIndex+1)

bootstrapPeers := []*client.ChainlinkClient{bootstrapNode.ChainlinkClient}
ocrSpec := &client.OCRTaskJobSpec{
ContractAddress: ocrInstance.Address(),
EVMChainID: fmt.Sprint(evmChainID),
P2PPeerID: nodeP2PId,
P2PBootstrapPeers: bootstrapPeers,
KeyBundleID: nodeOCRKeyId,
TransmitterAddress: nodeTransmitterAddress,
ObservationSource: client.ObservationSourceSpecBridge(bta),
ForwardingAllowed: true,
}
_, err = node.MustCreateJob(ocrSpec)
require.NoError(t, err, "Shouldn't fail creating OCR Task job on OCR node %d", nodeIndex+1)
}
}
}

// SetAdapterResponse sets a single adapter response that correlates with an ocr contract and a chainlink node
func SetAdapterResponse(
response int,
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/chaos/ocr_chaos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func TestOCRChaos(t *testing.T) {

ocrInstances, err := actions.DeployOCRv1Contracts(l, seth, 1, common.HexToAddress(linkContract.Address()), contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(workerNodes))
require.NoError(t, err)
err = actions.CreateOCRJobs(ocrInstances, bootstrapNode, workerNodes, 5, ms, fmt.Sprint(seth.ChainID))
err = actions.CreateOCRJobs(ocrInstances, bootstrapNode, workerNodes, 5, ms, seth.ChainID, false)
require.NoError(t, err)

chaosApplied := false
Expand Down
3 changes: 1 addition & 2 deletions integration-tests/load/ocr/helper.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ocr

import (
"fmt"
"math/big"
"math/rand"
"time"
Expand Down Expand Up @@ -45,7 +44,7 @@ func SetupFeed(
if err != nil {
return nil, err
}
err = actions.CreateOCRJobs(ocrInstances, bootstrapNode, workerNodes, 5, msClient, fmt.Sprint(seth.ChainID))
err = actions.CreateOCRJobs(ocrInstances, bootstrapNode, workerNodes, 5, msClient, seth.ChainID, false)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions integration-tests/load/ocr/vu.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ocr

import (
"context"
"fmt"
"sync/atomic"
"time"

Expand Down Expand Up @@ -82,7 +81,7 @@ func (m *VU) Setup(_ *wasp.Generator) error {
if err != nil {
return err
}
err = actions.CreateOCRJobs(ocrInstances, m.bootstrapNode, m.workerNodes, 5, m.msClient, fmt.Sprint(m.seth.ChainID))
err = actions.CreateOCRJobs(ocrInstances, m.bootstrapNode, m.workerNodes, 5, m.msClient, m.seth.ChainID, false)
if err != nil {
return err
}
Expand Down
9 changes: 2 additions & 7 deletions integration-tests/testsetups/ocr.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,14 +392,9 @@ func (o *OCRSoakTest) Run() {
o.startingBlockNum = latestBlockNum

startingValue := 5
if o.OperatorForwarderFlow {
actions.CreateOCRJobsWithForwarder(o.t, o.ocrV1Instances, o.bootstrapNode, o.workerNodes, startingValue, o.mockServer, o.seth.ChainID)
} else if o.OCRVersion == "1" {
ctx, cancel := context.WithTimeout(testcontext.Get(o.t), time.Second*5)
chainId, err := o.seth.Client.ChainID(ctx)
cancel()
if o.OCRVersion == "1" {
require.NoError(o.t, err, "Error getting chain ID")
err = actions.CreateOCRJobs(o.ocrV1Instances, o.bootstrapNode, o.workerNodes, startingValue, o.mockServer, chainId.String())
err = actions.CreateOCRJobs(o.ocrV1Instances, o.bootstrapNode, o.workerNodes, startingValue, o.mockServer, o.seth.ChainID, o.OperatorForwarderFlow)
require.NoError(o.t, err, "Error creating OCR jobs")
} else if o.OCRVersion == "2" {
err := actions.CreateOCRv2Jobs(o.ocrV2Instances, o.bootstrapNode, o.workerNodes, o.mockServer, startingValue, o.seth.ChainID, o.OperatorForwarderFlow)
Expand Down

0 comments on commit 1779ee9

Please sign in to comment.