diff --git a/deployment/ccip/changeset/test_helpers.go b/deployment/ccip/changeset/test_helpers.go index ac14a720035..9c225213c7a 100644 --- a/deployment/ccip/changeset/test_helpers.go +++ b/deployment/ccip/changeset/test_helpers.go @@ -697,53 +697,54 @@ func DeployTransferableToken( lggr logger.Logger, chains map[uint64]deployment.Chain, src, dst uint64, + srcActor, dstActor *bind.TransactOpts, state CCIPOnChainState, addresses deployment.AddressBook, token string, ) (*burn_mint_erc677.BurnMintERC677, *burn_mint_token_pool.BurnMintTokenPool, *burn_mint_erc677.BurnMintERC677, *burn_mint_token_pool.BurnMintTokenPool, error) { // Deploy token and pools - srcToken, srcPool, err := deployTransferTokenOneEnd(lggr, chains[src], addresses, token) + srcToken, srcPool, err := deployTransferTokenOneEnd(lggr, chains[src], srcActor, addresses, token) if err != nil { return nil, nil, nil, nil, err } - dstToken, dstPool, err := deployTransferTokenOneEnd(lggr, chains[dst], addresses, token) + dstToken, dstPool, err := deployTransferTokenOneEnd(lggr, chains[dst], dstActor, addresses, token) if err != nil { return nil, nil, nil, nil, err } // Attach token pools to registry - if err := attachTokenToTheRegistry(chains[src], state.Chains[src], chains[src].DeployerKey, srcToken.Address(), srcPool.Address()); err != nil { + if err := attachTokenToTheRegistry(chains[src], state.Chains[src], srcActor, srcToken.Address(), srcPool.Address()); err != nil { return nil, nil, nil, nil, err } - if err := attachTokenToTheRegistry(chains[dst], state.Chains[dst], chains[dst].DeployerKey, dstToken.Address(), dstPool.Address()); err != nil { + if err := attachTokenToTheRegistry(chains[dst], state.Chains[dst], dstActor, dstToken.Address(), dstPool.Address()); err != nil { return nil, nil, nil, nil, err } // Connect pool to each other - if err := setTokenPoolCounterPart(chains[src], srcPool, dst, dstToken.Address(), dstPool.Address()); err != nil { + if err := setTokenPoolCounterPart(chains[src], srcPool, srcActor, dst, dstToken.Address(), dstPool.Address()); err != nil { return nil, nil, nil, nil, err } - if err := setTokenPoolCounterPart(chains[dst], dstPool, src, srcToken.Address(), srcPool.Address()); err != nil { + if err := setTokenPoolCounterPart(chains[dst], dstPool, dstActor, src, srcToken.Address(), srcPool.Address()); err != nil { return nil, nil, nil, nil, err } // Add burn/mint permissions - if err := grantMintBurnPermissions(lggr, chains[src], srcToken, srcPool.Address()); err != nil { + if err := grantMintBurnPermissions(lggr, chains[src], srcToken, srcActor, srcPool.Address()); err != nil { return nil, nil, nil, nil, err } - if err := grantMintBurnPermissions(lggr, chains[dst], dstToken, dstPool.Address()); err != nil { + if err := grantMintBurnPermissions(lggr, chains[dst], dstToken, dstActor, dstPool.Address()); err != nil { return nil, nil, nil, nil, err } return srcToken, srcPool, dstToken, dstPool, nil } -func grantMintBurnPermissions(lggr logger.Logger, chain deployment.Chain, token *burn_mint_erc677.BurnMintERC677, address common.Address) error { +func grantMintBurnPermissions(lggr logger.Logger, chain deployment.Chain, token *burn_mint_erc677.BurnMintERC677, actor *bind.TransactOpts, address common.Address) error { lggr.Infow("Granting burn permissions", "token", token.Address(), "burner", address) - tx, err := token.GrantBurnRole(chain.DeployerKey, address) + tx, err := token.GrantBurnRole(actor, address) if err != nil { return err } @@ -753,7 +754,7 @@ func grantMintBurnPermissions(lggr logger.Logger, chain deployment.Chain, token } lggr.Infow("Granting mint permissions", "token", token.Address(), "minter", address) - tx, err = token.GrantMintRole(chain.DeployerKey, address) + tx, err = token.GrantMintRole(actor, address) if err != nil { return err } @@ -797,18 +798,12 @@ func setUSDCTokenPoolCounterPart( return err } - return setTokenPoolCounterPart(chain, pool, destChainSelector, destTokenAddress, destTokenPoolAddress) + return setTokenPoolCounterPart(chain, pool, nil, destChainSelector, destTokenAddress, destTokenPoolAddress) } -func setTokenPoolCounterPart( - chain deployment.Chain, - tokenPool *burn_mint_token_pool.BurnMintTokenPool, - destChainSelector uint64, - destTokenAddress common.Address, - destTokenPoolAddress common.Address, -) error { +func setTokenPoolCounterPart(chain deployment.Chain, tokenPool *burn_mint_token_pool.BurnMintTokenPool, actor *bind.TransactOpts, destChainSelector uint64, destTokenAddress common.Address, destTokenPoolAddress common.Address) error { tx, err := tokenPool.ApplyChainUpdates( - chain.DeployerKey, + actor, []burn_mint_token_pool.TokenPoolChainUpdate{ { RemoteChainSelector: destChainSelector, @@ -838,7 +833,7 @@ func setTokenPoolCounterPart( } tx, err = tokenPool.SetRemotePool( - chain.DeployerKey, + actor, destChainSelector, destTokenPoolAddress.Bytes(), ) @@ -898,6 +893,7 @@ func attachTokenToTheRegistry( func deployTransferTokenOneEnd( lggr logger.Logger, chain deployment.Chain, + deployer *bind.TransactOpts, addressBook deployment.AddressBook, tokenSymbol string, ) (*burn_mint_erc677.BurnMintERC677, *burn_mint_token_pool.BurnMintTokenPool, error) { @@ -921,7 +917,7 @@ func deployTransferTokenOneEnd( tokenContract, err := deployment.DeployContract(lggr, chain, addressBook, func(chain deployment.Chain) deployment.ContractDeploy[*burn_mint_erc677.BurnMintERC677] { USDCTokenAddr, tx, token, err2 := burn_mint_erc677.DeployBurnMintERC677( - chain.DeployerKey, + deployer, chain.Client, tokenSymbol, tokenSymbol, @@ -937,7 +933,7 @@ func deployTransferTokenOneEnd( return nil, nil, err } - tx, err := tokenContract.Contract.GrantMintRole(chain.DeployerKey, chain.DeployerKey.From) + tx, err := tokenContract.Contract.GrantMintRole(deployer, deployer.From) if err != nil { return nil, nil, err } @@ -949,7 +945,7 @@ func deployTransferTokenOneEnd( tokenPool, err := deployment.DeployContract(lggr, chain, addressBook, func(chain deployment.Chain) deployment.ContractDeploy[*burn_mint_token_pool.BurnMintTokenPool] { tokenPoolAddress, tx, tokenPoolContract, err2 := burn_mint_token_pool.DeployBurnMintTokenPool( - chain.DeployerKey, + deployer, chain.Client, tokenContract.Address, []common.Address{}, diff --git a/deployment/ccip/changeset/test_usdc_helpers.go b/deployment/ccip/changeset/test_usdc_helpers.go index 4a39f4e7ba1..ffdd2949b56 100644 --- a/deployment/ccip/changeset/test_usdc_helpers.go +++ b/deployment/ccip/changeset/test_usdc_helpers.go @@ -55,7 +55,7 @@ func ConfigureUSDCTokenPools( state.Chains[src].MockUSDCTokenMessenger.Address(), state.Chains[src].MockUSDCTransmitter.Address(), } { - if err := grantMintBurnPermissions(lggr, chains[src], srcToken, addr); err != nil { + if err := grantMintBurnPermissions(lggr, chains[src], srcToken, nil, addr); err != nil { lggr.Errorw("Failed to grant mint/burn permissions", "err", err, "token", srcToken.Address(), "minter", addr) return nil, nil, err } @@ -67,7 +67,7 @@ func ConfigureUSDCTokenPools( state.Chains[dst].MockUSDCTokenMessenger.Address(), state.Chains[dst].MockUSDCTransmitter.Address(), } { - if err := grantMintBurnPermissions(lggr, chains[dst], dstToken, addr); err != nil { + if err := grantMintBurnPermissions(lggr, chains[dst], dstToken, nil, addr); err != nil { lggr.Errorw("Failed to grant mint/burn permissions", "err", err, "token", dstToken.Address(), "minter", addr) return nil, nil, err } diff --git a/integration-tests/smoke/ccip/ccip_test.go b/integration-tests/smoke/ccip/ccip_test.go index 2d8e573b8fd..5eb5803d693 100644 --- a/integration-tests/smoke/ccip/ccip_test.go +++ b/integration-tests/smoke/ccip/ccip_test.go @@ -1,6 +1,11 @@ package smoke import ( + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" + "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" + "github.com/smartcontractkit/chainlink/deployment" "math/big" "testing" @@ -82,12 +87,10 @@ func TestInitialDeployOnLocal(t *testing.T) { func TestTokenTransfer(t *testing.T) { lggr := logger.TestLogger(t) config := &changeset.TestConfigs{} - tenv, _, _ := testsetups.NewLocalDevEnvironmentWithDefaultPrice(t, lggr, config) + //tenv, _, _ := testsetups.NewLocalDevEnvironmentWithDefaultPrice(t, lggr, config) - /* - * use this if you are testing locally in memory - * tenv := changeset.NewMemoryEnvironmentWithJobsAndContracts(t, lggr, 3, 4, config) - */ + //* use this if you are testing locally in memory + tenv := changeset.NewMemoryEnvironmentWithJobsAndContracts(t, lggr, 2, 4, config) e := tenv.Env state, err := changeset.LoadOnchainState(e) @@ -97,11 +100,16 @@ func TestTokenTransfer(t *testing.T) { sourceChain := allChainSelectors[0] destChain := allChainSelectors[1] + sourceActor := createAndFundSelfServeActor(t, e.Chains[sourceChain].DeployerKey, e.Chains[sourceChain]) + destActor := createAndFundSelfServeActor(t, e.Chains[destChain].DeployerKey, e.Chains[destChain]) + srcToken1, _, destToken1, _, err := changeset.DeployTransferableToken( lggr, tenv.Env.Chains, sourceChain, destChain, + sourceActor, + destActor, state, e.ExistingAddresses, "MY_TOKEN_1", @@ -113,6 +121,8 @@ func TestTokenTransfer(t *testing.T) { tenv.Env.Chains, sourceChain, destChain, + sourceActor, + destActor, state, e.ExistingAddresses, "MY_TOKEN_2", @@ -122,10 +132,18 @@ func TestTokenTransfer(t *testing.T) { // Add all lanes. require.NoError(t, changeset.AddLanesForAll(e, state)) - mintAndAllow(t, e, state, map[uint64][]*burn_mint_erc677.BurnMintERC677{ - sourceChain: {srcToken1, srcToken2}, - destChain: {destToken1, destToken2}, - }) + mintAndAllow( + t, + e, + state, + map[uint64]*bind.TransactOpts{ + sourceChain: sourceActor, + destChain: destActor, + }, + map[uint64][]*burn_mint_erc677.BurnMintERC677{ + sourceChain: {srcToken1, srcToken2}, + destChain: {destToken1, destToken2}, + }) tinyOneCoin := new(big.Int).SetUint64(1) @@ -250,3 +268,40 @@ func TestTokenTransfer(t *testing.T) { }) } } + +func createAndFundSelfServeActor( + t *testing.T, + deployer *bind.TransactOpts, + chain deployment.Chain, +) *bind.TransactOpts { + key, err := crypto.GenerateKey() + require.NoError(t, err) + + actor, err := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337)) + + nonce, err := chain.Client.PendingNonceAt(tests.Context(t), deployer.From) + require.NoError(t, err) + + gasPrice, err := chain.Client.SuggestGasPrice(tests.Context(t)) + require.NoError(t, err) + + tx := types.NewTx(&types.LegacyTx{ + Nonce: nonce, + To: &actor.From, + Value: new(big.Int).SetUint64(1e18), + Gas: uint64(21000), + GasPrice: gasPrice, + Data: nil, + }) + + signedTx, err := deployer.Signer(deployer.From, tx) + require.NoError(t, err) + + err = chain.Client.SendTransaction(tests.Context(t), signedTx) + require.NoError(t, err) + + _, err = chain.Confirm(signedTx) + require.NoError(t, err) + + return actor +} diff --git a/integration-tests/smoke/ccip/ccip_usdc_test.go b/integration-tests/smoke/ccip/ccip_usdc_test.go index f2c2a45df86..e81c0e82812 100644 --- a/integration-tests/smoke/ccip/ccip_usdc_test.go +++ b/integration-tests/smoke/ccip/ccip_usdc_test.go @@ -60,6 +60,8 @@ func TestUSDCTokenTransfer(t *testing.T) { tenv.Env.Chains, chainA, chainC, + nil, + nil, state, e.ExistingAddresses, "MY_TOKEN", @@ -69,7 +71,7 @@ func TestUSDCTokenTransfer(t *testing.T) { // Add all lanes require.NoError(t, changeset.AddLanesForAll(e, state)) - mintAndAllow(t, e, state, map[uint64][]*burn_mint_erc677.BurnMintERC677{ + mintAndAllow(t, e, state, nil, map[uint64][]*burn_mint_erc677.BurnMintERC677{ chainA: {aChainUSDC, aChainToken}, chainB: {bChainUSDC}, chainC: {cChainUSDC, cChainToken}, @@ -252,14 +254,18 @@ func mintAndAllow( t *testing.T, e deployment.Environment, state changeset.CCIPOnChainState, + owners map[uint64]*bind.TransactOpts, tkMap map[uint64][]*burn_mint_erc677.BurnMintERC677, ) { for chain, tokens := range tkMap { for _, token := range tokens { twoCoins := new(big.Int).Mul(big.NewInt(1e18), big.NewInt(2)) + owner, ok := owners[chain] + require.True(t, ok) + tx, err := token.Mint( - e.Chains[chain].DeployerKey, + owner, e.Chains[chain].DeployerKey.From, new(big.Int).Mul(twoCoins, big.NewInt(10)), )