Skip to content

Commit

Permalink
[CCIP-2155] Smoke Tests Deploy Tokens from non CCIP-Owner Address (#968)
Browse files Browse the repository at this point in the history
## Motivation

Our E2E tests currently deploy and configure all contracts from a single
address, `main`. The introduction of Self-Serve Token Pools makes this
especially unrealistic.

## Solution

* Create a new account, `tokenDeployer` to deploy tokens and pools from
by default. The funding for this account is messy, and fixes are tracked
by CCIP-2471.
* This account can be disabled if certain contract version requirements
are not met, or by toggling the `TokenConfig.CCIPOwnerTokens` config
option.
* The account is created in the form of a new client to handle
concurrent contract deployments gracefully.
* Each token and pool now has a `OwnerAddress` and `OwnerWallet` field
so that they can make `onlyOwner` calls from this wallet. This is by
default and for now cannot be modified.
* Fund return now also checks for other wallet balances
  • Loading branch information
kalverra authored Jun 13, 2024
1 parent 12b7c43 commit a6ff1e9
Show file tree
Hide file tree
Showing 15 changed files with 451 additions and 259 deletions.
5 changes: 5 additions & 0 deletions .changeset/soft-cars-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ccip": patch
---

#internal Expands the CCIP revert reason script with more ABIs
4 changes: 4 additions & 0 deletions core/scripts/ccip/revert-reason/handler/reason.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/token_admin_registry"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/usdc_token_pool"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/usdc_token_pool_1_4_0"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/burn_mint_erc677"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/erc20"
)

// RevertReasonFromErrorCodeString attempts to decode an error code string
Expand Down Expand Up @@ -132,6 +134,8 @@ func getAllABIs() []string {
lock_release_token_pool_1_4_0.LockReleaseTokenPoolABI,
burn_mint_token_pool_1_2_0.BurnMintTokenPoolABI,
usdc_token_pool_1_4_0.USDCTokenPoolABI,
burn_mint_erc677.BurnMintERC677ABI,
erc20.ERC20ABI,
lock_release_token_pool.LockReleaseTokenPoolABI,
burn_mint_token_pool.BurnMintTokenPoolABI,
usdc_token_pool.USDCTokenPoolABI,
Expand Down
52 changes: 46 additions & 6 deletions integration-tests/actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package actions
import (
"context"
"crypto/ecdsa"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -362,8 +363,9 @@ func DeleteAllJobs(chainlinkNodes []*client.ChainlinkK8sClient) error {
return nil
}

// ReturnFunds attempts to return all the funds from the chainlink nodes to the network's default address
// all from a remote, k8s style environment
// ReturnFunds attempts to return all the funds from the chainlink nodes and other wallets to the network's default wallet,
// which will always be the first wallet in the list of wallets. If errors are encountered, it will keep trying other wallets
// and return all errors encountered.
func ReturnFunds(chainlinkNodes []*client.ChainlinkK8sClient, blockchainClient blockchain.EVMClient) error {
if blockchainClient == nil {
return fmt.Errorf("blockchain client is nil, unable to return funds from chainlink nodes")
Expand All @@ -374,30 +376,68 @@ func ReturnFunds(chainlinkNodes []*client.ChainlinkK8sClient, blockchainClient b
Msg("Network is a simulated network. Skipping fund return.")
return nil
}
// If we fail to return funds from some addresses, we still want to try to return funds from the rest
encounteredErrors := []error{}

if len(blockchainClient.GetWallets()) > 1 {
if err := blockchainClient.SetDefaultWallet(0); err != nil {
encounteredErrors = append(encounteredErrors, err)
} else {
for walletIndex := 1; walletIndex < len(blockchainClient.GetWallets()); walletIndex++ {
decodedKey, err := hex.DecodeString(blockchainClient.GetWallets()[walletIndex].PrivateKey())
if err != nil {
encounteredErrors = append(encounteredErrors, err)
continue
}
privKey, err := crypto.ToECDSA(decodedKey)
if err != nil {
encounteredErrors = append(encounteredErrors, err)
continue
}

err = blockchainClient.ReturnFunds(privKey)
if err != nil {
encounteredErrors = append(encounteredErrors, err)
continue
}
}
}
}

for _, chainlinkNode := range chainlinkNodes {
fundedKeys, err := chainlinkNode.ExportEVMKeysForChain(blockchainClient.GetChainID().String())
if err != nil {
return err
encounteredErrors = append(encounteredErrors, err)
continue
}
for _, key := range fundedKeys {
keyToDecrypt, err := json.Marshal(key)
if err != nil {
return err
encounteredErrors = append(encounteredErrors, err)
continue
}
// This can take up a good bit of RAM and time. When running on the remote-test-runner, this can lead to OOM
// issues. So we avoid running in parallel; slower, but safer.
decryptedKey, err := keystore.DecryptKey(keyToDecrypt, client.ChainlinkKeyPassword)
if err != nil {
return err
encounteredErrors = append(encounteredErrors, err)
continue
}
err = blockchainClient.ReturnFunds(decryptedKey.PrivateKey)
if err != nil {
encounteredErrors = append(encounteredErrors, err)
log.Error().Err(err).Str("Address", fundedKeys[0].Address).Msg("Error returning funds from Chainlink node")
continue
}
}
}
return blockchainClient.WaitForEvents()
if err := blockchainClient.WaitForEvents(); err != nil {
encounteredErrors = append(encounteredErrors, err)
}
if len(encounteredErrors) > 0 {
return fmt.Errorf("encountered errors while returning funds: %v", encounteredErrors)
}
return nil
}

// FundAddresses will fund a list of addresses with an amount of native currency
Expand Down
Loading

0 comments on commit a6ff1e9

Please sign in to comment.