From d64279ba042c4809bf7ae17637ff7d2b9e41bf23 Mon Sep 17 00:00:00 2001 From: AnieeG Date: Wed, 18 Dec 2024 15:12:16 -0800 Subject: [PATCH] review comments --- deployment/ccip/changeset/state.go | 4 +-- deployment/ccip/changeset/test_environment.go | 32 ++++++++++++++++--- deployment/ccip/changeset/v1_5/e2e_test.go | 2 +- .../ccip/changeset/v1_5/test_helpers.go | 32 +------------------ .../common/changeset/internal/mcms_test.go | 8 ++--- deployment/environment/memory/chain.go | 5 +-- deployment/environment/memory/environment.go | 12 +++++-- 7 files changed, 47 insertions(+), 48 deletions(-) diff --git a/deployment/ccip/changeset/state.go b/deployment/ccip/changeset/state.go index 8f1836912db..b96279d8956 100644 --- a/deployment/ccip/changeset/state.go +++ b/deployment/ccip/changeset/state.go @@ -252,10 +252,10 @@ func (c CCIPChainState) GenerateView() (view.ChainView, error) { } // Legacy contracts if c.CommitStore != nil { - for _, commitStore := range c.CommitStore { + for source, commitStore := range c.CommitStore { commitStoreView, err := v1_5.GenerateCommitStoreView(commitStore) if err != nil { - return chainView, errors.Wrapf(err, "failed to generate commit store view for commit store %s", commitStore.Address().String()) + return chainView, errors.Wrapf(err, "failed to generate commit store view for commit store %s for source %d", commitStore.Address().String(), source) } chainView.CommitStore[commitStore.Address().Hex()] = commitStoreView } diff --git a/deployment/ccip/changeset/test_environment.go b/deployment/ccip/changeset/test_environment.go index 393aa770077..813e3509ee0 100644 --- a/deployment/ccip/changeset/test_environment.go +++ b/deployment/ccip/changeset/test_environment.go @@ -43,10 +43,11 @@ type TestConfigs struct { CreateJob bool // TODO: This should be CreateContracts so the booleans make sense? CreateJobAndContracts bool - Chains int // only used in memory mode, for docker mode, this is determined by the integration-test config toml input - NumOfUsersPerChain int // only used in memory mode, for docker mode, this is determined by the integration-test config toml input - Nodes int // only used in memory mode, for docker mode, this is determined by the integration-test config toml input - Bootstraps int // only used in memory mode, for docker mode, this is determined by the integration-test config toml input + Chains int // only used in memory mode, for docker mode, this is determined by the integration-test config toml input + ChainIDs []uint64 // only used in memory mode, for docker mode, this is determined by the integration-test config toml input + NumOfUsersPerChain int // only used in memory mode, for docker mode, this is determined by the integration-test config toml input + Nodes int // only used in memory mode, for docker mode, this is determined by the integration-test config toml input + Bootstraps int // only used in memory mode, for docker mode, this is determined by the integration-test config toml input IsUSDC bool IsUSDCAttestationMissing bool IsMultiCall3 bool @@ -104,6 +105,12 @@ func WithMultiCall3() TestOps { } } +func WithChainIds(chainIDs []uint64) TestOps { + return func(testCfg *TestConfigs) { + testCfg.ChainIDs = chainIDs + } +} + func WithJobsOnly() TestOps { return func(testCfg *TestConfigs) { testCfg.CreateJobAndContracts = false @@ -228,7 +235,22 @@ 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) + var chains map[uint64]deployment.Chain + var users map[uint64][]*bind.TransactOpts + if len(tc.ChainIDs) > 0 { + chains, users = memory.NewMemoryChainsWithChainIDs(t, tc.ChainIDs, tc.NumOfUsersPerChain) + if tc.Chains > len(tc.ChainIDs) { + additionalChains, additionalUsers := memory.NewMemoryChains(t, tc.Chains-len(tc.ChainIDs), tc.NumOfUsersPerChain) + for k, v := range additionalChains { + chains[k] = v + } + for k, v := range additionalUsers { + users[k] = v + } + } + } else { + chains, users = memory.NewMemoryChains(t, tc.Chains, tc.NumOfUsersPerChain) + } m.Chains = chains homeChainSel, feedSel := allocateCCIPChainSelectors(chains) replayBlocks, err := LatestBlocksByChain(ctx, chains) diff --git a/deployment/ccip/changeset/v1_5/e2e_test.go b/deployment/ccip/changeset/v1_5/e2e_test.go index c7eadf08000..4a12fb4d03f 100644 --- a/deployment/ccip/changeset/v1_5/e2e_test.go +++ b/deployment/ccip/changeset/v1_5/e2e_test.go @@ -14,7 +14,7 @@ import ( // This test only works if the destination chain id is 1337 func TestE2ELegacy(t *testing.T) { - e := NewMemoryEnvironment(t, changeset.WithChains(3)) + e := NewMemoryEnvironment(t, changeset.WithChains(3), changeset.WithChainIds([]uint64{chainselectors.GETH_TESTNET.EvmChainID})) state, err := changeset.LoadOnchainState(e.Env) require.NoError(t, err) allChains := e.Env.AllChainSelectorsExcluding([]uint64{chainselectors.GETH_TESTNET.Selector}) diff --git a/deployment/ccip/changeset/v1_5/test_helpers.go b/deployment/ccip/changeset/v1_5/test_helpers.go index 11efe679ab2..826fe8bb77d 100644 --- a/deployment/ccip/changeset/v1_5/test_helpers.go +++ b/deployment/ccip/changeset/v1_5/test_helpers.go @@ -16,7 +16,6 @@ import ( "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" @@ -75,35 +74,6 @@ 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 @@ -113,7 +83,7 @@ func NewMemoryEnvironment(t *testing.T, opts ...changeset.TestOps) changeset.Dep opt(testCfg) } require.NoError(t, testCfg.Validate(), "invalid test config") - env := &MemoryEnvironment{} + env := &changeset.MemoryEnvironment{} return NewEnvironment(t, testCfg, env) } diff --git a/deployment/common/changeset/internal/mcms_test.go b/deployment/common/changeset/internal/mcms_test.go index ff013717d30..92822422daa 100644 --- a/deployment/common/changeset/internal/mcms_test.go +++ b/deployment/common/changeset/internal/mcms_test.go @@ -18,9 +18,9 @@ import ( func TestDeployMCMSWithConfig(t *testing.T) { lggr := logger.TestLogger(t) - chains := memory.NewMemoryChainsWithChainIDs(t, []uint64{ + chains, _ := memory.NewMemoryChainsWithChainIDs(t, []uint64{ chainsel.TEST_90000001.EvmChainID, - }) + }, 1) ab := deployment.NewMemoryAddressBook() _, err := internal.DeployMCMSWithConfig(types.ProposerManyChainMultisig, lggr, chains[chainsel.TEST_90000001.Selector], ab, proposalutils.SingleGroupMCMS(t)) @@ -29,9 +29,9 @@ func TestDeployMCMSWithConfig(t *testing.T) { func TestDeployMCMSWithTimelockContracts(t *testing.T) { lggr := logger.TestLogger(t) - chains := memory.NewMemoryChainsWithChainIDs(t, []uint64{ + chains, _ := memory.NewMemoryChainsWithChainIDs(t, []uint64{ chainsel.TEST_90000001.EvmChainID, - }) + }, 1) ab := deployment.NewMemoryAddressBook() _, err := internal.DeployMCMSWithTimelockContracts(lggr, chains[chainsel.TEST_90000001.Selector], diff --git a/deployment/environment/memory/chain.go b/deployment/environment/memory/chain.go index 40a20a02416..77a8f397d39 100644 --- a/deployment/environment/memory/chain.go +++ b/deployment/environment/memory/chain.go @@ -14,6 +14,7 @@ import ( chainsel "github.com/smartcontractkit/chain-selectors" "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" + "github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets" ) @@ -52,10 +53,10 @@ func GenerateChains(t *testing.T, numChains int, numUsers int) map[uint64]EVMCha return chains } -func GenerateChainsWithIds(t *testing.T, chainIDs []uint64) map[uint64]EVMChain { +func GenerateChainsWithIds(t *testing.T, chainIDs []uint64, numUsers int) map[uint64]EVMChain { chains := make(map[uint64]EVMChain) for _, chainID := range chainIDs { - chains[chainID] = evmChain(t, 1) + chains[chainID] = evmChain(t, numUsers) } return chains } diff --git a/deployment/environment/memory/environment.go b/deployment/environment/memory/environment.go index b90d97f44bf..a74d23a847b 100644 --- a/deployment/environment/memory/environment.go +++ b/deployment/environment/memory/environment.go @@ -59,9 +59,15 @@ func NewMemoryChains(t *testing.T, numChains int, numUsers int) (map[uint64]depl return generateMemoryChain(t, mchains), users } -func NewMemoryChainsWithChainIDs(t *testing.T, chainIDs []uint64) map[uint64]deployment.Chain { - mchains := GenerateChainsWithIds(t, chainIDs) - return generateMemoryChain(t, mchains) +func NewMemoryChainsWithChainIDs(t *testing.T, chainIDs []uint64, numUsers int) (map[uint64]deployment.Chain, map[uint64][]*bind.TransactOpts) { + mchains := GenerateChainsWithIds(t, chainIDs, numUsers) + users := make(map[uint64][]*bind.TransactOpts) + for id, chain := range mchains { + sel, err := chainsel.SelectorFromChainId(id) + require.NoError(t, err) + users[sel] = chain.Users + } + return generateMemoryChain(t, mchains), users } func generateMemoryChain(t *testing.T, inputs map[uint64]EVMChain) map[uint64]deployment.Chain {