-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CCIP-4160 Token Transfer Tests #15278
Merged
mateusz-sekara
merged 36 commits into
develop
from
CCIP-4160_Implement_token_transfer_tests
Nov 29, 2024
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
3bfac63
CCIP-4160 test refactoring
0xsuryansh 4617621
resolving imports and using local dev env
0xsuryansh 24dd4f6
comments fix
0xsuryansh 8bae382
comments fix
0xsuryansh b4a4a98
Merge branch 'develop' into CCIP-4160_Implement_token_transfer_tests
0xsuryansh 25c1b15
Merge branch 'develop' into CCIP-4160_Implement_token_transfer_tests
0xsuryansh 94a2527
test update with common methods
0xsuryansh 9be1966
import fix for lint
0xsuryansh 18f5f2e
Merge branch 'develop' into CCIP-4160_Implement_token_transfer_tests
0xsuryansh 7f8fd25
Merge branch 'develop' into CCIP-4160_Implement_token_transfer_tests
0xsuryansh 3d969d6
refactor: updated test with new setup
0xsuryansh e2182dd
fix: lint (imports)
0xsuryansh 8273eac
Merge branch 'develop' into CCIP-4160_Implement_token_transfer_tests
0xsuryansh 1bc99b3
Yolo
mateusz-sekara e1a80af
Merge branch 'develop' into CCIP-4160_Implement_token_transfer_tests
0xsuryansh 691300c
Merge remote-tracking branch 'origin/ms/self-serve-addr-test' into CC…
0xsuryansh 8f4d4c5
feat: self serve pool test + ability to add custom deployer for token…
0xsuryansh 36df2f6
fix : Use LocalDevEnvironment
0xsuryansh faca5a5
temp: trying out with AdditionalSimulatedPvtKeys
0xsuryansh 211e668
Merge branch 'develop' into CCIP-4160_Implement_token_transfer_tests
0xsuryansh c53e872
fix: lints and unused function
0xsuryansh 1a03b58
Merge branch 'develop' into CCIP-4160_Implement_token_transfer_tests
0xsuryansh 9037d57
fix: lints and unused function
0xsuryansh f829199
fix: imports for lint
0xsuryansh eee7c93
Move tt tests to a separate file
mateusz-sekara 947b68d
Move tt tests to a separate file
mateusz-sekara eedb8fa
Fix
mateusz-sekara 8308df9
Fix
mateusz-sekara 6b726d7
Merge remote-tracking branch 'origin/develop' into CCIP-4160_Implemen…
mateusz-sekara 20a017e
Fix
mateusz-sekara 97c74df
Fix
mateusz-sekara 7f3fb4f
Fix
mateusz-sekara b870f35
Fix
mateusz-sekara be9e925
Fix
mateusz-sekara c7d3987
Merge remote-tracking branch 'origin/develop' into CCIP-4160_Implemen…
mateusz-sekara d2fa64a
Fix
mateusz-sekara File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ import ( | |
|
||
"github.com/smartcontractkit/chainlink-common/pkg/logger" | ||
commonutils "github.com/smartcontractkit/chainlink-common/pkg/utils" | ||
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests" | ||
|
||
"github.com/smartcontractkit/chainlink/deployment" | ||
"github.com/smartcontractkit/chainlink/deployment/environment/devenv" | ||
|
@@ -743,53 +744,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 | ||
} | ||
|
@@ -799,7 +801,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 | ||
} | ||
|
@@ -811,6 +813,7 @@ func setUSDCTokenPoolCounterPart( | |
chain deployment.Chain, | ||
tokenPool *usdc_token_pool.USDCTokenPool, | ||
destChainSelector uint64, | ||
actor *bind.TransactOpts, | ||
destTokenAddress common.Address, | ||
destTokenPoolAddress common.Address, | ||
) error { | ||
|
@@ -843,18 +846,12 @@ func setUSDCTokenPoolCounterPart( | |
return err | ||
} | ||
|
||
return setTokenPoolCounterPart(chain, pool, destChainSelector, destTokenAddress, destTokenPoolAddress) | ||
return setTokenPoolCounterPart(chain, pool, actor, 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, | ||
[]uint64{}, | ||
[]burn_mint_token_pool.TokenPoolChainUpdate{ | ||
{ | ||
|
@@ -884,7 +881,7 @@ func setTokenPoolCounterPart( | |
} | ||
|
||
tx, err = tokenPool.AddRemotePool( | ||
chain.DeployerKey, | ||
actor, | ||
destChainSelector, | ||
destTokenPoolAddress.Bytes(), | ||
) | ||
|
@@ -944,6 +941,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) { | ||
|
@@ -969,7 +967,7 @@ func deployTransferTokenOneEnd( | |
tokenContract, err := deployment.DeployContract(lggr, chain, addressBook, | ||
func(chain deployment.Chain) deployment.ContractDeploy[*burn_mint_erc677.BurnMintERC677] { | ||
tokenAddress, tx, token, err2 := burn_mint_erc677.DeployBurnMintERC677( | ||
chain.DeployerKey, | ||
deployer, | ||
chain.Client, | ||
tokenSymbol, | ||
tokenSymbol, | ||
|
@@ -985,7 +983,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 | ||
} | ||
|
@@ -997,7 +995,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, | ||
tokenDecimals, | ||
|
@@ -1016,3 +1014,127 @@ func deployTransferTokenOneEnd( | |
|
||
return tokenContract.Contract, tokenPool.Contract, nil | ||
} | ||
|
||
// MintAndAllow mints tokens for deployers and allow router to spend them | ||
func MintAndAllow( | ||
t *testing.T, | ||
e deployment.Environment, | ||
state CCIPOnChainState, | ||
owners map[uint64]*bind.TransactOpts, | ||
tkMap map[uint64][]*burn_mint_erc677.BurnMintERC677, | ||
) { | ||
tenCoins := new(big.Int).Mul(big.NewInt(1e18), big.NewInt(10)) | ||
|
||
for chain, tokens := range tkMap { | ||
owner, ok := owners[chain] | ||
require.True(t, ok) | ||
|
||
for _, token := range tokens { | ||
tx, err := token.Mint( | ||
owner, | ||
e.Chains[chain].DeployerKey.From, | ||
new(big.Int).Mul(tenCoins, big.NewInt(10)), | ||
) | ||
require.NoError(t, err) | ||
_, err = e.Chains[chain].Confirm(tx) | ||
require.NoError(t, err) | ||
|
||
tx, err = token.Approve(e.Chains[chain].DeployerKey, state.Chains[chain].Router.Address(), tenCoins) | ||
require.NoError(t, err) | ||
_, err = e.Chains[chain].Confirm(tx) | ||
require.NoError(t, err) | ||
} | ||
} | ||
} | ||
|
||
// TransferAndWaitForSuccess sends a message from sourceChain to destChain and waits for it to be executed | ||
func TransferAndWaitForSuccess( | ||
ctx context.Context, | ||
t *testing.T, | ||
env deployment.Environment, | ||
state CCIPOnChainState, | ||
sourceChain, destChain uint64, | ||
tokens []router.ClientEVMTokenAmount, | ||
receiver common.Address, | ||
data []byte, | ||
expectedStatus int, | ||
) { | ||
identifier := SourceDestPair{ | ||
SourceChainSelector: sourceChain, | ||
DestChainSelector: destChain, | ||
} | ||
|
||
startBlocks := make(map[uint64]*uint64) | ||
expectedSeqNum := make(map[SourceDestPair]uint64) | ||
expectedSeqNumExec := make(map[SourceDestPair][]uint64) | ||
|
||
latesthdr, err := env.Chains[destChain].Client.HeaderByNumber(ctx, nil) | ||
require.NoError(t, err) | ||
block := latesthdr.Number.Uint64() | ||
startBlocks[destChain] = &block | ||
|
||
msgSentEvent := TestSendRequest(t, env, state, sourceChain, destChain, false, router.ClientEVM2AnyMessage{ | ||
Receiver: common.LeftPadBytes(receiver.Bytes(), 32), | ||
Data: data, | ||
TokenAmounts: tokens, | ||
FeeToken: common.HexToAddress("0x0"), | ||
ExtraArgs: nil, | ||
}) | ||
expectedSeqNum[identifier] = msgSentEvent.SequenceNumber | ||
expectedSeqNumExec[identifier] = []uint64{msgSentEvent.SequenceNumber} | ||
|
||
// Wait for all commit reports to land. | ||
ConfirmCommitForAllWithExpectedSeqNums(t, env, state, expectedSeqNum, startBlocks) | ||
|
||
// Wait for all exec reports to land | ||
states := ConfirmExecWithSeqNrsForAll(t, env, state, expectedSeqNumExec, startBlocks) | ||
require.Equal(t, expectedStatus, states[identifier][msgSentEvent.SequenceNumber]) | ||
} | ||
|
||
func WaitForTheTokenBalance( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
ctx context.Context, | ||
t *testing.T, | ||
token common.Address, | ||
receiver common.Address, | ||
chain deployment.Chain, | ||
expected *big.Int, | ||
) { | ||
tokenContract, err := burn_mint_erc677.NewBurnMintERC677(token, chain.Client) | ||
require.NoError(t, err) | ||
|
||
require.Eventually(t, func() bool { | ||
actualBalance, err := tokenContract.BalanceOf(&bind.CallOpts{Context: ctx}, receiver) | ||
require.NoError(t, err) | ||
|
||
t.Log("Waiting for the token balance", | ||
"expected", expected, | ||
"actual", actualBalance, | ||
"token", token, | ||
"receiver", receiver, | ||
) | ||
|
||
return actualBalance.Cmp(expected) == 0 | ||
}, tests.WaitTimeout(t), 100*time.Millisecond) | ||
} | ||
|
||
func GetTokenBalance( | ||
ctx context.Context, | ||
t *testing.T, | ||
token common.Address, | ||
receiver common.Address, | ||
chain deployment.Chain, | ||
) *big.Int { | ||
tokenContract, err := burn_mint_erc677.NewBurnMintERC677(token, chain.Client) | ||
require.NoError(t, err) | ||
|
||
balance, err := tokenContract.BalanceOf(&bind.CallOpts{Context: ctx}, receiver) | ||
require.NoError(t, err) | ||
|
||
t.Log("Getting token balance", | ||
"actual", balance, | ||
"token", token, | ||
"receiver", receiver, | ||
) | ||
|
||
return balance | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need a ticket to move all these funcs out of
changeset
and into acciptesthelpers
package or something,changeset
is supposed to be the public API and shouldn't have these kinda funcs.