From 665cf9b6c072368b8963be1544b59fdbb6df2ebe Mon Sep 17 00:00:00 2001 From: asoliman Date: Fri, 12 Jul 2024 20:11:06 +0400 Subject: [PATCH] Clean up --- .../ccip_integration_tests/ocr3_node_test.go | 67 +++---------------- .../ccip_integration_tests/ocr_node_helper.go | 51 +++++++------- 2 files changed, 37 insertions(+), 81 deletions(-) diff --git a/core/services/ocr3/plugins/ccip_integration_tests/ocr3_node_test.go b/core/services/ocr3/plugins/ccip_integration_tests/ocr3_node_test.go index 7935b2a4038..46d6f9c6d98 100644 --- a/core/services/ocr3/plugins/ccip_integration_tests/ocr3_node_test.go +++ b/core/services/ocr3/plugins/ccip_integration_tests/ocr3_node_test.go @@ -1,9 +1,7 @@ package ccip_integration_tests import ( - "context" "fmt" - "sync" "testing" "time" @@ -21,7 +19,6 @@ import ( func TestIntegration_OCR3Nodes(t *testing.T) { numChains := 3 homeChainUni, universes := createUniverses(t, numChains) - //homeChainUni, universes := createUniverses(t, 3) numNodes := 4 t.Log("creating ocr3 nodes") var ( @@ -74,69 +71,27 @@ func TestIntegration_OCR3Nodes(t *testing.T) { } } - t.Log("starting ticker to commit blocks") - tick := time.NewTicker(1 * time.Second) - defer tick.Stop() - tickCtx, tickCancel := context.WithCancel(testutils.Context(t)) - defer tickCancel() - var wg sync.WaitGroup - wg.Add(1) - go func() { - defer wg.Done() - for { - select { - case <-tick.C: - for _, uni := range universes { - uni.backend.Commit() - } - case <-tickCtx.Done(): - return - } - } - }() - t.Cleanup(func() { - tickCancel() - wg.Wait() - }) - - bootstrapNode := nodes[0] - - t.Log("adding bootstrap node job") - err := bootstrapNode.app.Start(testutils.Context(t)) - require.NoError(t, err, "failed to start bootstrap node") - t.Cleanup(func() { - require.NoError(t, bootstrapNode.app.Stop()) - }) - - evmChains := bootstrapNode.app.GetRelayers().LegacyEVMChains() - require.NotNil(t, evmChains) - require.Len(t, evmChains.Slice(), numChains) + // Start committing periodically in the background for all the chains + commitBlocksBackground(t, universes, time.NewTicker(1*time.Second)) t.Log("creating ocr3 jobs") for i := 0; i < numNodes; i++ { - //err := apps[i].Start(testutils.Context(t)) - //require.NoError(t, err) - //tApp := apps[i] - //t.Cleanup(func() { - // require.NoError(t, tApp.Stop()) - //}) - // - //ccipSpecToml := createCCIPSpecToml(nodes[i].peerID, bootstrapP2PID.String(), bootstrapPort, nodes[i].keybundle.ID()) - //t.Log("Creating ccip job with spec:\n", ccipSpecToml) - - //ccipJob, err2 := ccipcapability(ccipSpecToml) - //require.NoError(t, err2, "failed to validate ccip job") - //err2 = apps[i].AddJobV2(testutils.Context(t), &ccipJob) - //require.NoError(t, err2, "failed to add ccip job") + err := apps[i].Start(testutils.Context(t)) + require.NoError(t, err) + tApp := apps[i] + t.Cleanup(func() { + require.NoError(t, tApp.Stop()) + }) + //TODO: Create Jobs and add them to the app } - // add the ccip dons to the capability registry. ccipCapabilityID, err := homeChainUni.capabilityRegistry.GetHashedCapabilityId(nil, CapabilityLabelledName, CapabilityVersion) require.NoError(t, err, "failed to get hashed capability id for ccip") require.NotEqual(t, [32]byte{}, ccipCapabilityID, "ccip capability id is empty") + // Need to Add nodes and assign capabilities to them before creating DONS homeChainUni.AddNodes(t, p2pIDs, [][32]byte{ccipCapabilityID}) - // create a DON for each chain + // Create a DON for each chain for _, uni := range universes { // Add nodes and give them the capability t.Log("AddingDON for universe: ", uni.chainID) diff --git a/core/services/ocr3/plugins/ccip_integration_tests/ocr_node_helper.go b/core/services/ocr3/plugins/ccip_integration_tests/ocr_node_helper.go index ea4f9e2b63b..6f43fba5363 100644 --- a/core/services/ocr3/plugins/ccip_integration_tests/ocr_node_helper.go +++ b/core/services/ocr3/plugins/ccip_integration_tests/ocr_node_helper.go @@ -5,6 +5,7 @@ import ( "fmt" "math/big" "net/http" + "sync" "testing" "time" @@ -250,29 +251,29 @@ func createConfigV2Chain(chainID *big.Int) *v2toml.EVMConfig { } } -func createCCIPSpecToml(nodeP2PID, bootstrapP2PID string, bootstrapPort int, ocrKeyBundleID string) string { - return fmt.Sprintf(` -type = "ccip" -capabilityVersion = "%s" -capabilityLabelledName = "%s" -p2pKeyID = "%s" -p2pV2Bootstrappers = ["%s"] -[ocrKeyBundleIDs] -evm = "%s" -[relayConfigs.evm.chainReaderConfig.contracts.Offramp] -contractABI = "the abi" - -[relayConfigs.evm.chainReaderConfig.contracts.Offramp.configs.getStuff] -chainSpecificName = "getStuffEVM" - -[pluginConfig] -tokenPricesPipeline = "the pipeline"`, - CapabilityVersion, - CcipCapabilityLabelledName, - nodeP2PID, - fmt.Sprintf("%s@127.0.0.1:%d", bootstrapP2PID, - bootstrapPort, - ), - ocrKeyBundleID, - ) +// Commit blocks periodically in the background for all chains +func commitBlocksBackground(t *testing.T, universes map[uint64]onchainUniverse, tick *time.Ticker) { + t.Log("starting ticker to commit blocks") + defer tick.Stop() + tickCtx, tickCancel := context.WithCancel(testutils.Context(t)) + defer tickCancel() + var wg sync.WaitGroup + wg.Add(1) + go func() { + defer wg.Done() + for { + select { + case <-tick.C: + for _, uni := range universes { + uni.backend.Commit() + } + case <-tickCtx.Done(): + return + } + } + }() + t.Cleanup(func() { + tickCancel() + wg.Wait() + }) }