Skip to content

Commit

Permalink
Adopting mock lbtc token pool contract in the test
Browse files Browse the repository at this point in the history
  • Loading branch information
b-gopalswami committed Dec 6, 2024
1 parent f72e393 commit 4f44dce
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 126 deletions.
9 changes: 4 additions & 5 deletions integration-tests/ccip-tests/actions/ccip_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ func GetUSDCDomain(networkName string, simulated bool) (uint32, error) {
if val, ok := lookup[networkName]; ok {
return val, nil
}

return 0, fmt.Errorf("USDC domain not found for chain %s", networkName)
}

Expand Down Expand Up @@ -931,7 +930,7 @@ func (ccipModule *CCIPCommon) DeployContracts(
if err != nil {
return fmt.Errorf("granting minter role to token transmitter shouldn't fail %w", err)
}
} else if ccipModule.IsLBTCDeployment() && i == 1 {
} else if ccipModule.IsLBTCDeployment() && i == 0 {
// if it's LBTC deployment, we deploy the burn mint token 677 with decimal 8 and cast it to ERC20Token
lbtcToken, err := ccipModule.tokenDeployer.DeployCustomBurnMintERC677Token("Lombard LBTC", "LBTC", uint8(18), new(big.Int).Mul(big.NewInt(1e6), big.NewInt(1e18)))
if err != nil {
Expand Down Expand Up @@ -1005,10 +1004,10 @@ func (ccipModule *CCIPCommon) DeployContracts(
}

ccipModule.BridgeTokenPools = append(ccipModule.BridgeTokenPools, usdcPool)
} else if ccipModule.IsLBTCDeployment() && i == 1 {
lbtcPool, err := ccipModule.tokenDeployer.DeployBurnAndMintTokenPoolContract(token.Address(), *ccipModule.RMNContract, ccipModule.Router.Instance.Address())
} else if ccipModule.IsLBTCDeployment() && i == 0 {
lbtcPool, err := ccipModule.tokenDeployer.DeployLBTCTokenPoolContract(token.Address(), *ccipModule.RMNContract, ccipModule.Router.Instance.Address())
if err != nil {
return fmt.Errorf("deploying burn and mint bridge Token pool(lbtc) shouldn't fail %w", err)
return fmt.Errorf("deploying mock lbtc bridge token pool shouldn't fail %w", err)
}

ccipModule.BridgeTokenPools = append(ccipModule.BridgeTokenPools, lbtcPool)
Expand Down
121 changes: 5 additions & 116 deletions integration-tests/ccip-tests/contracts/contract_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

"github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink-testing-framework/lib/blockchain"
burn_mint_token_pool "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/burn_mint_token_pool_1_4_0"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/mock_lbtc_token_pool"

"github.com/smartcontractkit/chainlink/integration-tests/client"
"github.com/smartcontractkit/chainlink/integration-tests/contracts"
Expand Down Expand Up @@ -526,7 +526,6 @@ func (e *CCIPContractsDeployer) DeployUSDCTokenPoolContract(tokenAddr string, to
}
}

// TODO: finish converting from USDC to LBTC
func (e *CCIPContractsDeployer) NewLBTCTokenPoolContract(addr common.Address) (
*TokenPool,
error,
Expand All @@ -535,7 +534,7 @@ func (e *CCIPContractsDeployer) NewLBTCTokenPoolContract(addr common.Address) (
e.logger.Info().Str("Version", version.String()).Msg("New LBTC Token Pool")
switch version {
case Latest:
pool, err := usdc_token_pool.NewUSDCTokenPool(addr, wrappers.MustNewWrappedContractBackend(e.evmClient, nil))
pool, err := mock_lbtc_token_pool.NewMockLBTCTokenPool(addr, wrappers.MustNewWrappedContractBackend(e.evmClient, nil))

if err != nil {
return nil, err
Expand All @@ -556,36 +555,7 @@ func (e *CCIPContractsDeployer) NewLBTCTokenPoolContract(addr common.Address) (
Instance: &TokenPoolWrapper{
Latest: &LatestPool{
PoolInterface: poolInterface,
USDCPool: pool,
},
},
EthAddress: addr,
OwnerAddress: common.HexToAddress(e.evmClient.GetDefaultWallet().Address()),
OwnerWallet: e.evmClient.GetDefaultWallet(),
}, err
case V1_4_0:
pool, err := usdc_token_pool_1_4_0.NewUSDCTokenPool(addr, wrappers.MustNewWrappedContractBackend(e.evmClient, nil))

if err != nil {
return nil, err
}
e.logger.Info().
Str("Contract Address", addr.Hex()).
Str("Contract Name", "USDC Token Pool").
Str("From", e.evmClient.GetDefaultWallet().Address()).
Str("Network Name", e.evmClient.GetNetworkConfig().Name).
Msg("New contract")
poolInterface, err := token_pool_1_4_0.NewTokenPool(addr, wrappers.MustNewWrappedContractBackend(e.evmClient, nil))
if err != nil {
return nil, err
}
return &TokenPool{
client: e.evmClient,
logger: e.logger,
Instance: &TokenPoolWrapper{
V1_4_0: &V1_4_0Pool{
PoolInterface: poolInterface,
USDCPool: pool,
MockLBTCPool: pool,
},
},
EthAddress: addr,
Expand All @@ -598,8 +568,7 @@ func (e *CCIPContractsDeployer) NewLBTCTokenPoolContract(addr common.Address) (

}

// TODO: finish converting from USDC to LBTC
func (e *CCIPContractsDeployer) DeployLBTCTokenPoolContract(tokenAddr string, tokenMessenger, rmnProxy common.Address, router common.Address) (
func (e *CCIPContractsDeployer) DeployLBTCTokenPoolContract(tokenAddr string, rmnProxy common.Address, router common.Address) (
*TokenPool,
error,
) {
Expand All @@ -612,30 +581,9 @@ func (e *CCIPContractsDeployer) DeployLBTCTokenPoolContract(tokenAddr string, to
auth *bind.TransactOpts,
_ bind.ContractBackend,
) (common.Address, *types.Transaction, interface{}, error) {
return usdc_token_pool.DeployUSDCTokenPool(
auth,
wrappers.MustNewWrappedContractBackend(e.evmClient, nil),
tokenMessenger,
token,
[]common.Address{},
rmnProxy,
router,
)
})

if err != nil {
return nil, err
}
return e.NewUSDCTokenPoolContract(*address)
case V1_4_0:
address, _, _, err := e.evmClient.DeployContract("USDC Token Pool", func(
auth *bind.TransactOpts,
_ bind.ContractBackend,
) (common.Address, *types.Transaction, interface{}, error) {
return usdc_token_pool_1_4_0.DeployUSDCTokenPool(
return mock_lbtc_token_pool.DeployMockLBTCTokenPool(
auth,
wrappers.MustNewWrappedContractBackend(e.evmClient, nil),
tokenMessenger,
token,
[]common.Address{},
rmnProxy,
Expand All @@ -652,65 +600,6 @@ func (e *CCIPContractsDeployer) DeployLBTCTokenPoolContract(tokenAddr string, to
}
}

func (e *CCIPContractsDeployer) DeployBurnAndMintTokenPoolContract(tokenAddr string, rmnProxy common.Address, router common.Address) (
*TokenPool,
error,
) {
version := VersionMap[TokenPoolContract]
e.logger.Debug().Str("Token", tokenAddr).Msg("Deploying Burn and Mint token pool")
token := common.HexToAddress(tokenAddr)
switch version {
case Latest:
address, _, _, err := e.evmClient.DeployContract("Burn and Mint Token Pool", func(
auth *bind.TransactOpts,
_ bind.ContractBackend,
) (common.Address, *types.Transaction, interface{}, error) {
return burn_mint_token_pool.DeployBurnMintTokenPool(
auth,
wrappers.MustNewWrappedContractBackend(e.evmClient, nil),
token,
[]common.Address{},
rmnProxy,
router,
)
})

if err != nil {
return nil, err
}
pool, err := burn_mint_token_pool.NewBurnMintTokenPool(*address, wrappers.MustNewWrappedContractBackend(e.evmClient, nil))

if err != nil {
return nil, err
}
e.logger.Info().
Str("Contract Address", address.Hex()).
Str("Contract Name", "USDC Token Pool").
Str("From", e.evmClient.GetDefaultWallet().Address()).
Str("Network Name", e.evmClient.GetNetworkConfig().Name).
Msg("New contract")
poolInterface, err := token_pool.NewTokenPool(*address, wrappers.MustNewWrappedContractBackend(e.evmClient, nil))
if err != nil {
return nil, err
}
return &TokenPool{
client: e.evmClient,
logger: e.logger,
Instance: &TokenPoolWrapper{
Latest: &LatestPool{
PoolInterface: poolInterface,
BurnAndMintTokenPool: pool,
},
},
EthAddress: *address,
OwnerAddress: common.HexToAddress(e.evmClient.GetDefaultWallet().Address()),
OwnerWallet: e.evmClient.GetDefaultWallet(),
}, err
default:
return nil, fmt.Errorf("version not supported: %s", version)
}
}

func (e *CCIPContractsDeployer) DeployLockReleaseTokenPoolContract(tokenAddr string, rmnProxy common.Address, router common.Address) (
*TokenPool,
error,
Expand Down
10 changes: 5 additions & 5 deletions integration-tests/ccip-tests/contracts/contract_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"golang.org/x/exp/rand"

"github.com/smartcontractkit/chainlink-testing-framework/lib/blockchain"
burn_mint_token_pool "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/burn_mint_token_pool_1_4_0"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/mock_lbtc_token_pool"

"github.com/smartcontractkit/chainlink/integration-tests/wrappers"

Expand Down Expand Up @@ -402,10 +402,10 @@ func (l *LinkToken) Transfer(to string, amount *big.Int) error {
}

type LatestPool struct {
PoolInterface *token_pool.TokenPool
BurnAndMintTokenPool *burn_mint_token_pool.BurnMintTokenPool
LockReleasePool *lock_release_token_pool.LockReleaseTokenPool
USDCPool *usdc_token_pool.USDCTokenPool
PoolInterface *token_pool.TokenPool
LockReleasePool *lock_release_token_pool.LockReleaseTokenPool
USDCPool *usdc_token_pool.USDCTokenPool
MockLBTCPool *mock_lbtc_token_pool.MockLBTCTokenPool
}

type V1_4_0Pool struct {
Expand Down

0 comments on commit 4f44dce

Please sign in to comment.