Skip to content

Commit

Permalink
Yolo
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz-sekara committed Nov 27, 2024
1 parent e2182dd commit 1bc99b3
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 37 deletions.
44 changes: 20 additions & 24 deletions deployment/ccip/changeset/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -838,7 +833,7 @@ func setTokenPoolCounterPart(
}

tx, err = tokenPool.SetRemotePool(
chain.DeployerKey,
actor,
destChainSelector,
destTokenPoolAddress.Bytes(),
)
Expand Down Expand Up @@ -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) {
Expand All @@ -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,
Expand All @@ -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
}
Expand All @@ -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{},
Expand Down
4 changes: 2 additions & 2 deletions deployment/ccip/changeset/test_usdc_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
73 changes: 64 additions & 9 deletions integration-tests/smoke/ccip/ccip_test.go
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -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)
Expand All @@ -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",
Expand All @@ -113,6 +121,8 @@ func TestTokenTransfer(t *testing.T) {
tenv.Env.Chains,
sourceChain,
destChain,
sourceActor,
destActor,
state,
e.ExistingAddresses,
"MY_TOKEN_2",
Expand All @@ -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)

Expand Down Expand Up @@ -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))

Check failure on line 280 in integration-tests/smoke/ccip/ccip_test.go

View workflow job for this annotation

GitHub Actions / Lint integration-tests

ineffectual assignment to err (ineffassign)

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
}
10 changes: 8 additions & 2 deletions integration-tests/smoke/ccip/ccip_usdc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ func TestUSDCTokenTransfer(t *testing.T) {
tenv.Env.Chains,
chainA,
chainC,
nil,
nil,
state,
e.ExistingAddresses,
"MY_TOKEN",
Expand All @@ -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},
Expand Down Expand Up @@ -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)),
)
Expand Down

0 comments on commit 1bc99b3

Please sign in to comment.