Skip to content

Commit

Permalink
refactor LM test - l1/l2 based on config (LM-142) (#984)
Browse files Browse the repository at this point in the history
  • Loading branch information
anirudhwarrier authored Jun 10, 2024
1 parent 542f51d commit 998b818
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
4 changes: 1 addition & 3 deletions integration-tests/ccip-tests/actions/lm_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ type LMCommon struct {
BridgeAdapterAddr *common.Address
WrapperNative *common.Address
MinimumLiquidity *big.Int
IsL2 bool
ChainSelectror uint64
}

func DefaultLMModule(chainClient blockchain.EVMClient, minimumLiquidity *big.Int, isL2 bool, chainSelector uint64) (*LMCommon, error) {
func DefaultLMModule(chainClient blockchain.EVMClient, minimumLiquidity *big.Int, chainSelector uint64) (*LMCommon, error) {
return &LMCommon{
ChainClient: chainClient,
MinimumLiquidity: minimumLiquidity,
IsL2: isL2,
ChainSelectror: chainSelector,
}, nil
}
38 changes: 17 additions & 21 deletions integration-tests/ccip-tests/testsetups/lm_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,12 @@ func (o *LMTestSetupOutputs) CreateLMEnvironment(

func (o *LMTestSetupOutputs) DeployLMChainContracts(
lggr zerolog.Logger,
chainClient blockchain.EVMClient,
networkCfg blockchain.EVMNetwork,
chainSelectors []uint64,
lmCommon actions.LMCommon,
) error {
var k8Env *environment.Environment
ccipEnv := o.Env
chainClient := lmCommon.ChainClient
if ccipEnv != nil {
k8Env = ccipEnv.K8Env
}
Expand Down Expand Up @@ -310,7 +309,7 @@ func (o *LMTestSetupOutputs) DeployLMChainContracts(

// Deploy Liquidity Manager contract
lggr.Info().Msg("Deploying Liquidity Manager contract")
liquidityManager, err := cd.DeployLiquidityManager(*lmCommon.WrapperNative, chainSelectors[0], lmCommon.TokenPool.EthAddress, lmCommon.MinimumLiquidity)
liquidityManager, err := cd.DeployLiquidityManager(*lmCommon.WrapperNative, lmCommon.ChainSelectror, lmCommon.TokenPool.EthAddress, lmCommon.MinimumLiquidity)
if err != nil {
return errors.WithStack(fmt.Errorf("failed to deploy Liquidity Manager contract: %w", err))
}
Expand Down Expand Up @@ -339,23 +338,24 @@ func (o *LMTestSetupOutputs) DeployLMChainContracts(
return errors.WithStack(fmt.Errorf("onchainRebalancer doesn not match the deployed Liquidity Manager"))
}

// Deploy Bridge Adapter contracts
if lmCommon.IsL2 {
lggr.Info().Msg("Deploying Mock L2 Bridge Adapter contract")
l2bridgeAdapter, err := cd.DeployMockL2BridgeAdapter()
if err != nil {
return errors.WithStack(fmt.Errorf("failed to deploy Mock L2 Bridge Adapter contract: %w", err))
}
lggr.Info().Str("Address", l2bridgeAdapter.EthAddress.String()).Msg("Deployed Mock L2 Bridge Adapter contract")
lmCommon.BridgeAdapterAddr = l2bridgeAdapter.EthAddress
} else {
// Deploy Bridge Adapter contracts if simulated chain
switch lmCommon.ChainSelectror {
case chainselectors.GETH_TESTNET.Selector:
lggr.Info().Msg("Deploying Mock L1 Bridge Adapter contract")
l1bridgeAdapter, err := cd.DeployMockL1BridgeAdapter(*lmCommon.WrapperNative, true)
bridgeAdapter, err := cd.DeployMockL1BridgeAdapter(*lmCommon.WrapperNative, true)
if err != nil {
return errors.WithStack(fmt.Errorf("failed to deploy Mock L1 Bridge Adapter contract: %w", err))
}
lggr.Info().Str("Address", l1bridgeAdapter.EthAddress.String()).Msg("Deployed Mock L1 Bridge Adapter contract")
lmCommon.BridgeAdapterAddr = l1bridgeAdapter.EthAddress
lggr.Info().Str("Address", bridgeAdapter.EthAddress.String()).Msg("Deployed Mock L1 Bridge Adapter contract")
lmCommon.BridgeAdapterAddr = bridgeAdapter.EthAddress
case chainselectors.TEST_2337.Selector:
lggr.Info().Msg("Deploying Mock L2 Bridge Adapter contract")
bridgeAdapter, err := cd.DeployMockL2BridgeAdapter()
if err != nil {
return errors.WithStack(fmt.Errorf("failed to deploy Mock L2 Bridge Adapter contract: %w", err))
}
lggr.Info().Str("Address", bridgeAdapter.EthAddress.String()).Msg("Deployed Mock L2 Bridge Adapter contract")
lmCommon.BridgeAdapterAddr = bridgeAdapter.EthAddress
}

lggr.Debug().Interface("lmCommon", lmCommon).Msg("lmCommon")
Expand Down Expand Up @@ -659,8 +659,6 @@ func LMDefaultTestSetup(
}
}

//TODO: Refactor this to detect if the chain is L1 or L2 based on a config
i := 0
for _, net := range testConfig.AllNetworks {
chain := chainByChainID[net.ChainID]
net := net
Expand All @@ -675,14 +673,12 @@ func LMDefaultTestSetup(
lmCommon, err := actions.DefaultLMModule(
chain,
big.NewInt(0),
i == 1,
selectors[0],
)
require.NoError(t, err)
chainAddGrp.Go(func() error {
return setUpArgs.DeployLMChainContracts(lggr, chain, net, selectors, *lmCommon)
return setUpArgs.DeployLMChainContracts(lggr, net, *lmCommon)
})
i++
}
require.NoError(t, chainAddGrp.Wait(), "Deploying common contracts shouldn't fail")

Expand Down

0 comments on commit 998b818

Please sign in to comment.