Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AnieeG committed Dec 18, 2024
1 parent 207a6bc commit d64279b
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 48 deletions.
4 changes: 2 additions & 2 deletions deployment/ccip/changeset/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
32 changes: 27 additions & 5 deletions deployment/ccip/changeset/test_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion deployment/ccip/changeset/v1_5/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
32 changes: 1 addition & 31 deletions deployment/ccip/changeset/v1_5/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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)
}

Expand Down
8 changes: 4 additions & 4 deletions deployment/common/changeset/internal/mcms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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],
Expand Down
5 changes: 3 additions & 2 deletions deployment/environment/memory/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
Expand Down
12 changes: 9 additions & 3 deletions deployment/environment/memory/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d64279b

Please sign in to comment.