Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
asoliman92 committed Jul 12, 2024
1 parent 43c4622 commit 5d1f229
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 97 deletions.
30 changes: 15 additions & 15 deletions core/services/ocr3/plugins/ccip_integration_tests/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/ocr3_config_encoder"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/weth9"
cctypes "github.com/smartcontractkit/chainlink/v2/core/services/ccipcapability/types"
confighelper2 "github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper"
"github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3confighelper"

"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/ccip_config"

chainsel "github.com/smartcontractkit/chain-selectors"

"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/arm_proxy_contract"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/ccip_config"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/evm_2_evm_multi_offramp"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/evm_2_evm_multi_onramp"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/mock_arm_contract"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/nonce_manager"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/ocr3_config_encoder"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/price_registry"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/token_admin_registry"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/weth9"
kcr "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/shared/generated/link_token"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
cctypes "github.com/smartcontractkit/chainlink/v2/core/services/ccipcapability/types"

confighelper2 "github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper"
"github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3confighelper"

chainsel "github.com/smartcontractkit/chain-selectors"

"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -341,8 +341,7 @@ func (h *homeChain) AddDON(
for range oracles {
schedule = append(schedule, 1)
}
offchainConfig, onchainConfig := []byte{}, []byte{}
signers, transmitters, f, onchainConfig, offchainConfigVersion, offchainConfig, err := ocr3confighelper.ContractSetConfigArgsForTests(
signers, transmitters, f, _, offchainConfigVersion, offchainConfig, err := ocr3confighelper.ContractSetConfigArgsForTests(
30*time.Second, // deltaProgress
10*time.Second, // deltaResend
20*time.Second, // deltaInitial
Expand All @@ -353,13 +352,13 @@ func (h *homeChain) AddDON(
3, // rmax
schedule,
oracles,
offchainConfig,
[]byte{}, // empty offchain config
50*time.Millisecond, // maxDurationQuery
5*time.Second, // maxDurationObservation
10*time.Second, // maxDurationShouldAcceptAttestedReport
10*time.Second, // maxDurationShouldTransmitAcceptedReport
int(f),
onchainConfig)
[]byte{}) // empty OnChainConfig
require.NoError(t, err, "failed to create contract config")

tabi, err := ocr3_config_encoder.IOCR3ConfigEncoderMetaData.GetAbi()
Expand All @@ -372,8 +371,9 @@ func (h *homeChain) AddDON(

transmittersBytes := make([][]byte, len(transmitters))
for i, transmitter := range transmitters {
parsed, err := common.ParseHexOrString(string(transmitter))
require.NoError(t, err)
// anotherErr because linting doesn't want to shadow err
parsed, anotherErr := common.ParseHexOrString(string(transmitter))
require.NoError(t, anotherErr)
transmittersBytes[i] = parsed
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import (
libocrtypes "github.com/smartcontractkit/libocr/ragep2p/types"

ccipreader "github.com/smartcontractkit/chainlink-ccip/pkg/reader"

cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3"

capcfg "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/ccip_config"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/logger"

"github.com/stretchr/testify/require"
)

Expand Down
72 changes: 15 additions & 57 deletions core/services/ocr3/plugins/ccip_integration_tests/ocr3_node_test.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
package ccip_integration_tests

import (
"context"
"fmt"
"sync"
"testing"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/hashicorp/consul/sdk/freeport"

"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey"

"github.com/smartcontractkit/libocr/commontypes"
confighelper2 "github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types"

"github.com/stretchr/testify/require"
)

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 (
Expand Down Expand Up @@ -74,69 +74,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")
for i := 0; i < len(nodes); i++ {
err := nodes[i].app.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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math/big"
"net/http"
"sync"
"testing"
"time"

Expand All @@ -14,9 +15,11 @@ import (
gethtypes "github.com/ethereum/go-ethereum/core/types"

"github.com/jmoiron/sqlx"

"github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink-common/pkg/loop"
"github.com/smartcontractkit/chainlink-common/pkg/utils/mailbox"

"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
v2toml "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
Expand All @@ -32,6 +35,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ocr2key"
"github.com/smartcontractkit/chainlink/v2/core/utils"
"github.com/smartcontractkit/chainlink/v2/plugins"

"github.com/smartcontractkit/libocr/commontypes"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"
Expand Down Expand Up @@ -250,29 +254,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("%[email protected]:%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()
})
}

0 comments on commit 5d1f229

Please sign in to comment.