Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AnieeG committed Dec 17, 2024
1 parent 6bb2a6d commit 8d2ea2a
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 41 deletions.
12 changes: 6 additions & 6 deletions deployment/ccip/changeset/test_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (d *DeployedEnv) SetupJobs(t *testing.T) {

type MemoryEnvironment struct {
DeployedEnv
chains map[uint64]deployment.Chain
Chains map[uint64]deployment.Chain
}

func (m *MemoryEnvironment) DeployedEnvironment() DeployedEnv {
Expand All @@ -210,13 +210,13 @@ func (m *MemoryEnvironment) DeployedEnvironment() DeployedEnv {
func (m *MemoryEnvironment) StartChains(t *testing.T, tc *TestConfigs) {
ctx := testcontext.Get(t)
chains, users := memory.NewMemoryChains(t, tc.Chains, tc.NumOfUsersPerChain)
m.chains = chains
m.Chains = chains
homeChainSel, feedSel := allocateCCIPChainSelectors(chains)
replayBlocks, err := LatestBlocksByChain(ctx, chains)
require.NoError(t, err)
m.DeployedEnv = DeployedEnv{
Env: deployment.Environment{
Chains: m.chains,
Chains: m.Chains,
},
HomeChainSel: homeChainSel,
FeedChainSel: feedSel,
Expand All @@ -226,9 +226,9 @@ func (m *MemoryEnvironment) StartChains(t *testing.T, tc *TestConfigs) {
}

func (m *MemoryEnvironment) StartNodes(t *testing.T, tc *TestConfigs, crConfig deployment.CapabilityRegistryConfig) {
require.NotNil(t, m.chains, "start chains first, chains are empty")
require.NotNil(t, m.Chains, "start chains first, chains are empty")
require.NotNil(t, m.DeployedEnv, "start chains and initiate deployed env first before starting nodes")
nodes := memory.NewNodes(t, zapcore.InfoLevel, m.chains, tc.Nodes, tc.Bootstraps, crConfig)
nodes := memory.NewNodes(t, zapcore.InfoLevel, m.Chains, tc.Nodes, tc.Bootstraps, crConfig)
ctx := testcontext.Get(t)
lggr := logger.Test(t)
for _, node := range nodes {
Expand All @@ -237,7 +237,7 @@ func (m *MemoryEnvironment) StartNodes(t *testing.T, tc *TestConfigs, crConfig d
require.NoError(t, node.App.Stop())
})
}
m.DeployedEnv.Env = memory.NewMemoryEnvironmentFromChainsNodes(func() context.Context { return ctx }, lggr, m.chains, nodes)
m.DeployedEnv.Env = memory.NewMemoryEnvironmentFromChainsNodes(func() context.Context { return ctx }, lggr, m.Chains, nodes)
}

func (m *MemoryEnvironment) MockUSDCAttestationServer(t *testing.T, isUSDCAttestationMissing bool) string {
Expand Down
16 changes: 3 additions & 13 deletions deployment/ccip/changeset/v1_5/cs_jobspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package v1_5

import (
"fmt"
"strconv"

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

"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset"
Expand All @@ -28,6 +25,7 @@ func (c JobSpecsForLanesConfig) Validate() error {
type JobSpecInput struct {
SourceChainSelector uint64
DestinationChainSelector uint64
DestEVMChainID uint64
DestinationStartBlock uint64
TokenPricesUSDPipeline string
PriceGetterConfigJson string
Expand Down Expand Up @@ -86,24 +84,16 @@ func jobSpecsForLane(
for _, node := range nodes {
var specs []string
for _, cfg := range lanesCfg.Configs {
var err error
destChainState := state.Chains[cfg.DestinationChainSelector]
sourceChain := env.Chains[cfg.SourceChainSelector]
destChain := env.Chains[cfg.DestinationChainSelector]
destEVMChainIdStr, err := chain_selectors.GetChainIDFromSelector(cfg.DestinationChainSelector)
if err != nil {
return nil, fmt.Errorf("failed to get chain ID from selector for chain %s: %w", destChain.String(), err)
}
destEVMChainId, err := strconv.ParseUint(destEVMChainIdStr, 10, 64)
if err != nil {
return nil, fmt.Errorf("failed to parse chain ID %s for chain %s: %w", destEVMChainIdStr, destChain.String(), err)
}

ccipJobParam := integrationtesthelpers.CCIPJobSpecParams{
OffRamp: destChainState.EVM2EVMOffRamp[cfg.SourceChainSelector].Address(),
CommitStore: destChainState.CommitStore[cfg.SourceChainSelector].Address(),
SourceChainName: sourceChain.Name(),
DestChainName: destChain.Name(),
DestEvmChainId: destEVMChainId,
DestEvmChainId: cfg.DestEVMChainID,
TokenPricesUSDPipeline: cfg.TokenPricesUSDPipeline,
PriceGetterConfig: cfg.PriceGetterConfigJson,
DestStartBlock: cfg.DestinationStartBlock,
Expand Down
5 changes: 3 additions & 2 deletions deployment/ccip/changeset/v1_5/cs_ocr2_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,9 @@ func deriveOCR2Config(
OnchainPublicKey: cfg.OnchainPublicKey,
TransmitAccount: cfg.TransmitAccount,
OffchainPublicKey: cfg.OffchainPublicKey,
PeerID: cfg.PeerID.String()[4:],
}, ConfigEncryptionPublicKey: cfg.ConfigEncryptionPublicKey,
PeerID: cfg.PeerID.Raw(),
},
ConfigEncryptionPublicKey: cfg.ConfigEncryptionPublicKey,
})
}

Expand Down
17 changes: 14 additions & 3 deletions deployment/ccip/changeset/v1_5/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,31 @@ import (
"testing"

"github.com/ethereum/go-ethereum/common"
chainselectors "github.com/smartcontractkit/chain-selectors"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink/deployment/ccip/changeset"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router"
)

// This test only works if the destination chain id is 1337
func TestE2ELegacy(t *testing.T) {
e := NewMemoryEnvironment(t)
e := NewMemoryEnvironment(t, changeset.WithChains(3))
state, err := changeset.LoadOnchainState(e.Env)
require.NoError(t, err)
allChains := e.Env.AllChainSelectors()
src, dest := allChains[0], allChains[1]
allChains := e.Env.AllChainSelectorsExcluding([]uint64{chainselectors.GETH_TESTNET.Selector})
require.Contains(t, e.Env.AllChainSelectors(), chainselectors.GETH_TESTNET.Selector)
require.Len(t, allChains, 2)
src, dest := allChains[1], chainselectors.GETH_TESTNET.Selector
srcChain := e.Env.Chains[src]
destChain := e.Env.Chains[dest]
pairs := []changeset.SourceDestPair{
{SourceChainSelector: src, DestChainSelector: dest},
}
e.Env = AddLanes(t, e.Env, state, pairs)
// reload state after adding lanes
state, err = changeset.LoadOnchainState(e.Env)
require.NoError(t, err)
sentEvent, err := SendRequest(t, e.Env, state,
changeset.WithSourceChain(src),
changeset.WithDestChain(dest),
Expand Down
69 changes: 52 additions & 17 deletions deployment/ccip/changeset/v1_5/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import (
"math/big"
"net/http"
"net/http/httptest"
"strconv"
"testing"
"time"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
chain_selectors "github.com/smartcontractkit/chain-selectors"
"github.com/smartcontractkit/chainlink-common/pkg/config"
cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccip"
jobv1 "github.com/smartcontractkit/chainlink-protos/job-distributor/v1/job"
"github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext"
"github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
Expand Down Expand Up @@ -72,14 +75,45 @@ func (j *LegacyJobclient) ProposeJob(ctx context.Context, in *jobv1.ProposeJobRe
}}, nil
}

type MemoryEnvironment struct {
changeset.MemoryEnvironment
}

// StartChains is to override the default changeset.MemoryEnvironment.StartChains method
// to ensure we always have a chain with chain id 1337
// this is required for the offchain config digest to be consistent with onchain config digest
// off chain config digests are calculated based on the chain id which needs to be always 1337 for simulated backend
// chains, otherwise it will not match with the onchain config digest
func (m *MemoryEnvironment) StartChains(t *testing.T, tc *changeset.TestConfigs) {
ctx := testcontext.Get(t)
chains, users := memory.NewMemoryChains(t, tc.Chains-1, tc.NumOfUsersPerChain)
// Add chain with chain id 1337
chain1337 := memory.NewMemoryChainsWithChainIDs(t, []uint64{1337})
for k, v := range chain1337 {
chains[k] = v
}
replayBlocks, err := changeset.LatestBlocksByChain(ctx, chains)
require.NoError(t, err)
m.Chains = chains
m.DeployedEnv = changeset.DeployedEnv{
Env: deployment.Environment{
Chains: chains,
},
ReplayBlocks: replayBlocks,
Users: users,
}
}

// NewMemoryEnvironment creates an in-memory environment based on the testconfig requested
// This environment currently only works when destination chain is 1337
// Otherwise it shows error for offchain and onchain config digest mismatch
func NewMemoryEnvironment(t *testing.T, opts ...changeset.TestOps) changeset.DeployedEnv {
testCfg := changeset.DefaultTestConfigs()
for _, opt := range opts {
opt(testCfg)
}
require.NoError(t, testCfg.Validate(), "invalid test config")
env := &changeset.MemoryEnvironment{}
env := &MemoryEnvironment{}
return NewEnvironment(t, testCfg, env)
}

Expand All @@ -90,8 +124,10 @@ func NewEnvironment(t *testing.T, tc *changeset.TestConfigs, tEnv changeset.Test
require.NotEmpty(t, e.Env.Chains)
tEnv.StartNodes(t, tc, deployment.CapabilityRegistryConfig{})
e = tEnv.DeployedEnvironment()
e.Env.Offchain = &LegacyJobclient{
JobClient: e.Env.Offchain.(*memory.JobClient),
if _, ok := e.Env.Offchain.(*memory.JobClient); ok {
e.Env.Offchain = &LegacyJobclient{
JobClient: e.Env.Offchain.(*memory.JobClient),
}
}
allChains := e.Env.AllChainSelectors()

Expand Down Expand Up @@ -136,21 +172,15 @@ func NewEnvironment(t *testing.T, tc *changeset.TestConfigs, tEnv changeset.Test
},
})
require.NoError(t, err)
state, err := changeset.LoadOnchainState(e.Env)
return e
}

func AddLanes(t *testing.T, e deployment.Environment, state changeset.CCIPOnChainState, pairs []changeset.SourceDestPair) deployment.Environment {
state, err := changeset.LoadOnchainState(e)
require.NoError(t, err)
var pairs []changeset.SourceDestPair
for _, src := range allChains {
for _, dest := range allChains {
if src != dest {
pairs = append(pairs, changeset.SourceDestPair{
SourceChainSelector: src,
DestChainSelector: dest,
})
}
}
}
addLanesCfg, commitOCR2Configs, execOCR2Configs, jobspecs := LaneConfigsForChains(t, e.Env, state, pairs)
e.Env, err = commonchangeset.ApplyChangesets(t, e.Env, nil, []commonchangeset.ChangesetApplication{

addLanesCfg, commitOCR2Configs, execOCR2Configs, jobspecs := LaneConfigsForChains(t, e, state, pairs)
e, err = commonchangeset.ApplyChangesets(t, e, nil, []commonchangeset.ChangesetApplication{
{
Changeset: commonchangeset.WrapChangeSet(DeployLanes),
Config: DeployLanesConfig{
Expand Down Expand Up @@ -202,9 +232,14 @@ func LaneConfigsForChains(t *testing.T, env deployment.Environment, state change
tokenPrice, _, _ := CreatePricesPipeline(t, state, src, dest)
block, err := env.Chains[dest].Client.HeaderByNumber(context.Background(), nil)
require.NoError(t, err)
destEVMChainIdStr, err := chain_selectors.GetChainIDFromSelector(dest)
require.NoError(t, err)
destEVMChainId, err := strconv.ParseUint(destEVMChainIdStr, 10, 64)
require.NoError(t, err)
jobSpecs = append(jobSpecs, JobSpecInput{
SourceChainSelector: src,
DestinationChainSelector: dest,
DestEVMChainID: destEVMChainId,
TokenPricesUSDPipeline: tokenPrice,
DestinationStartBlock: block.Number.Uint64(),
})
Expand Down
42 changes: 42 additions & 0 deletions integration-tests/smoke/ccip/ccip_legacy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package smoke

import (
"context"
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink/deployment/ccip/changeset"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/v1_5"
testsetups "github.com/smartcontractkit/chainlink/integration-tests/testsetups/ccip"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router"
)

func TestE2ELegacy(t *testing.T) {
e := testsetups.NewIntegrationLegacyEnvironment(t)
state, err := changeset.LoadOnchainState(e.Env)
require.NoError(t, err)
allChains := e.Env.AllChainSelectors()
src, dest := allChains[0], allChains[1]
srcChain := e.Env.Chains[src]
destChain := e.Env.Chains[dest]
sentEvent, err := v1_5.SendRequest(t, e.Env, state,
changeset.WithSourceChain(src),
changeset.WithDestChain(dest),
changeset.WithTestRouter(false),
changeset.WithEvm2AnyMessage(router.ClientEVM2AnyMessage{
Receiver: common.LeftPadBytes(state.Chains[dest].Receiver.Address().Bytes(), 32),
Data: []byte("hello"),
TokenAmounts: nil,
FeeToken: common.HexToAddress("0x0"),
ExtraArgs: nil,
}),
)
require.NoError(t, err)
require.NotNil(t, sentEvent)
destStartBlock, err := destChain.Client.HeaderByNumber(context.Background(), nil)
require.NoError(t, err)
v1_5.WaitForCommit(t, srcChain, destChain, state.Chains[dest].CommitStore[src], sentEvent.Message.SequenceNumber)
v1_5.WaitForExecute(t, srcChain, destChain, state.Chains[dest].EVM2EVMOffRamp[src], []uint64{sentEvent.Message.SequenceNumber}, destStartBlock.Number.Uint64())
}
24 changes: 24 additions & 0 deletions integration-tests/testsetups/ccip/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/v1_5"
integrationnodes "github.com/smartcontractkit/chainlink/integration-tests/types/config/node"
evmcfg "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
corechainlink "github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
Expand Down Expand Up @@ -137,6 +138,29 @@ func (l *DeployedLocalDevEnvironment) RestartChainlinkNodes(t *testing.T) error
return errGrp.Wait()
}

func NewIntegrationLegacyEnvironment(t *testing.T, opts ...changeset.TestOps) changeset.DeployedEnv {
testCfg := changeset.DefaultTestConfigs()
for _, opt := range opts {
opt(testCfg)
}
// check for EnvType env var
testCfg.MustSetEnvTypeOrDefault(t)
require.NoError(t, testCfg.Validate(), "invalid test config")
switch testCfg.Type {
case changeset.Memory:
memEnv := v1_5.NewMemoryEnvironment(t, opts...)
return memEnv
case changeset.Docker:
dockerEnv := &DeployedLocalDevEnvironment{}
deployedEnv := v1_5.NewEnvironment(t, testCfg, dockerEnv)
require.NotNil(t, dockerEnv.testEnv, "empty docker environment")
return deployedEnv
default:
require.Failf(t, "Type %s not supported in integration tests choose between %s and %s", string(testCfg.Type), changeset.Memory, changeset.Docker)
}
return changeset.DeployedEnv{}
}

// NewIntegrationEnvironment creates a new integration test environment based on the provided test config
// It can create a memory environment or a docker environment based on env var CCIP_V16_TEST_ENV
// By default, it creates a memory environment if env var CCIP_V16_TEST_ENV is not set
Expand Down

0 comments on commit 8d2ea2a

Please sign in to comment.