Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
asoliman92 committed Jul 15, 2024
1 parent 5d1f229 commit 1b3cec4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
17 changes: 7 additions & 10 deletions core/services/ocr3/plugins/ccip_integration_tests/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ccip_integration_tests
import (
"encoding/hex"
"math/big"
"sort"
"strconv"
"testing"
"time"
Expand Down Expand Up @@ -283,14 +284,10 @@ func setupHomeChain(t *testing.T, owner *bind.TransactOpts, backend *backends.Si
}

// bubble sort, n^2 but p2pIDs never should be more than a handful
func sortP2pIDS(p2pIDs [][32]byte) {
for i := 0; i < len(p2pIDs); i++ {
for j := i + 1; j < len(p2pIDs); j++ {
if hex.EncodeToString(p2pIDs[i][:]) > hex.EncodeToString(p2pIDs[j][:]) {
p2pIDs[i], p2pIDs[j] = p2pIDs[j], p2pIDs[i]
}
}
}
func sortP2PIDS(p2pIDs [][32]byte) {
sort.Slice(p2pIDs, func(i, j int) bool {
return hex.EncodeToString(p2pIDs[i][:]) < hex.EncodeToString(p2pIDs[j][:])
})
}

func (h *homeChain) AddNodes(
Expand All @@ -299,7 +296,7 @@ func (h *homeChain) AddNodes(
capabilityIDs [][32]byte,
) {
// Need to sort, otherwise _checkIsValidUniqueSubset onChain will fail
sortP2pIDS(p2pIDs)
sortP2PIDS(p2pIDs)
var nodeParams []kcr.CapabilitiesRegistryNodeParams
for _, p2pID := range p2pIDs {
nodeParam := kcr.CapabilitiesRegistryNodeParams{
Expand All @@ -326,7 +323,7 @@ func (h *homeChain) AddDON(
oracles []confighelper2.OracleIdentityExtra,
) {
// Need to sort, otherwise _checkIsValidUniqueSubset onChain will fail
sortP2pIDS(p2pIDs)
sortP2PIDS(p2pIDs)
// First Add ChainConfig that includes all p2pIDs as readers
chainConfig := SetupConfigInfo(chainSelector, p2pIDs, FChainA, []byte(strconv.FormatUint(chainSelector, 10)))
inputConfig := []ccip_config.CCIPConfigTypesChainConfigInfo{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,16 @@ func TestIntegration_OCR3Nodes(t *testing.T) {
// The bootstrap node will be the first node (index 0)
bootstrapPort int
bootstrapP2PID p2pkey.PeerID
bootStrappers []commontypes.BootstrapperLocator
bootstrappers []commontypes.BootstrapperLocator
)

ports := freeport.GetN(t, numNodes)
for i := 0; i < numNodes; i++ {
node := setupNodeOCR3(t, ports[i], bootStrappers, universes)
node := setupNodeOCR3(t, ports[i], bootstrappers, universes)

apps = append(apps, node.app)
for chainID, transmitter := range node.transmitters {
transmitters[chainID] = append(transmitters[chainID], transmitter)
}
for chainID, transmitter := range node.transmitters {
identity := confighelper2.OracleIdentityExtra{
OracleIdentity: confighelper2.OracleIdentity{
OnchainPublicKey: node.keybundle.PublicKey(),
Expand All @@ -66,7 +64,7 @@ func TestIntegration_OCR3Nodes(t *testing.T) {
if i == 0 {
bootstrapPort = ports[i]
bootstrapP2PID = peerID
bootStrappers = []commontypes.BootstrapperLocator{
bootstrappers = []commontypes.BootstrapperLocator{
{PeerID: node.peerID, Addrs: []string{
fmt.Sprintf("127.0.0.1:%d", bootstrapPort),
}},
Expand All @@ -75,11 +73,14 @@ func TestIntegration_OCR3Nodes(t *testing.T) {
}

// Start committing periodically in the background for all the chains
commitBlocksBackground(t, universes, time.NewTicker(1*time.Second))
tick := time.NewTicker(1 * time.Second)
defer tick.Stop()
commitBlocksBackground(t, universes, tick)

ctx := testutils.Context(t)
t.Log("creating ocr3 jobs")
for i := 0; i < len(nodes); i++ {
err := nodes[i].app.Start(testutils.Context(t))
err := nodes[i].app.Start(ctx)
require.NoError(t, err)
tApp := apps[i]
t.Cleanup(func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,7 @@ func createConfigV2Chain(chainID *big.Int) *v2toml.EVMConfig {
// 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() {
Expand Down

0 comments on commit 1b3cec4

Please sign in to comment.