Skip to content

Commit

Permalink
Move tt tests to a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz-sekara committed Nov 28, 2024
1 parent f829199 commit eee7c93
Show file tree
Hide file tree
Showing 3 changed files with 293 additions and 269 deletions.
19 changes: 16 additions & 3 deletions .github/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,19 @@ runner-test-matrix:

# START: CCIPv1.6 tests

- id: smoke/ccip/ccip_test.go:*
path: integration-tests/smoke/ccip/ccip_test.go
test_env_type: docker
runs_on: ubuntu-latest
triggers:
- PR E2E Core Tests
- Nightly E2E Tests
test_cmd: cd integration-tests/smoke/ccip && go test ccip_test.go -timeout 12m -test.parallel=2 -count=1 -json
pyroscope_env: ci-smoke-ccipv1_6-evm-simulated
test_env_vars:
E2E_TEST_SELECTED_NETWORK: SIMULATED_1,SIMULATED_2
E2E_JD_VERSION: 0.6.0

- id: smoke/ccip/ccip_test.go:*
path: integration-tests/smoke/ccip/ccip_test.go
test_env_type: docker
Expand All @@ -948,14 +961,14 @@ runner-test-matrix:
E2E_TEST_SELECTED_NETWORK: SIMULATED_1,SIMULATED_2
E2E_JD_VERSION: 0.6.0

- id: smoke/ccip/ccip_batching_test.go:*
path: integration-tests/smoke/ccip/ccip_batching_test.go
- id: smoke/ccip/ccip_token_transfer_test.go:*
path: integration-tests/smoke/ccip/ccip_token_transfer_test.go
test_env_type: docker
runs_on: ubuntu-latest
triggers:
- PR E2E Core Tests
- Nightly E2E Tests
test_cmd: cd integration-tests/ && go test smoke/ccip/ccip_batching_test.go -timeout 12m -test.parallel=1 -count=1 -json
test_cmd: cd integration-tests/ && go test smoke/ccip/ccip_token_transfer_test.go -timeout 16m -test.parallel=1 -count=1 -json
pyroscope_env: ci-smoke-ccipv1_6-evm-simulated
test_env_vars:
E2E_TEST_SELECTED_NETWORK: SIMULATED_1,SIMULATED_2,SIMULATED_3
Expand Down
267 changes: 1 addition & 266 deletions integration-tests/smoke/ccip/ccip_test.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
package smoke

import (
"math/big"
"testing"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/require"
"golang.org/x/exp/maps"

chainselectors "github.com/smartcontractkit/chain-selectors"

"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
"github.com/smartcontractkit/chainlink-testing-framework/lib/networks"
"github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext"
"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset"
testsetups "github.com/smartcontractkit/chainlink/integration-tests/testsetups/ccip"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/shared/generated/burn_mint_erc677"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/stretchr/testify/require"
)

func TestInitialDeployOnLocal(t *testing.T) {
Expand Down Expand Up @@ -85,255 +72,3 @@ func TestInitialDeployOnLocal(t *testing.T) {

// TODO: Apply the proposal.
}

func TestTokenTransfer(t *testing.T) {
lggr := logger.TestLogger(t)
config := &changeset.TestConfigs{}
tenv, _, _ := testsetups.NewLocalDevEnvironmentWithDefaultPrice(t, lggr, 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)
require.NoError(t, err)

// Chain and account setup
allChainSelectors := maps.Keys(e.Chains)
sourceChain, destChain := allChainSelectors[0], allChainSelectors[1]
ownerSourceChain := e.Chains[sourceChain].DeployerKey
ownerDestChain := e.Chains[destChain].DeployerKey

// Deploy and fund self-serve actors (when using memory)
//selfServeSrcTokenPoolDeployer := createAndFundSelfServeActor(t, ownerSourceChain, e.Chains[sourceChain], big.NewInt(1e18))
//selfServeSrcTokenPoolDeployer := createAndFundSelfServeActor(t, ownerDestChain, e.Chains[destChain], big.NewInt(1e18))
selfServeSrcTokenPoolDeployer := createDeployerKeyFromSimulatedPrivateKey(t, sourceChain)
selfServeDestTokenPoolDeployer := createDeployerKeyFromSimulatedPrivateKey(t, destChain)

// Deploy tokens and pool by CCIP Owner
srcToken, _, destToken, _, err := changeset.DeployTransferableToken(
lggr,
tenv.Env.Chains,
sourceChain,
destChain,
ownerSourceChain,
ownerDestChain,
state,
e.ExistingAddresses,
"OWNER_TOKEN",
)
require.NoError(t, err)

// Deploy Self Serve tokens and pool
selfServeSrcToken, _, selfServeDestToken, _, err := changeset.DeployTransferableToken(
lggr,
tenv.Env.Chains,
sourceChain,
destChain,
selfServeSrcTokenPoolDeployer,
selfServeDestTokenPoolDeployer,
state,
e.ExistingAddresses,
"SELF_SERVE_TOKEN",
)
require.NoError(t, err)

// Add all lanes.
require.NoError(t, changeset.AddLanesForAll(e, state))

// Mint and allow tokens for the router
changeset.MintAndAllow(t, e, state, map[uint64]*bind.TransactOpts{
sourceChain: ownerSourceChain,
destChain: ownerDestChain,
}, map[uint64][]*burn_mint_erc677.BurnMintERC677{
sourceChain: {srcToken},
destChain: {destToken},
})
changeset.MintAndAllow(t, e, state, map[uint64]*bind.TransactOpts{
sourceChain: selfServeSrcTokenPoolDeployer,
destChain: selfServeDestTokenPoolDeployer,
}, map[uint64][]*burn_mint_erc677.BurnMintERC677{
sourceChain: {selfServeSrcToken},
destChain: {selfServeDestToken},
})

tinyOneCoin := new(big.Int).SetUint64(1)

// Test scenarios are defined here
scenarios := []struct {
name string
srcChain uint64
dstChain uint64
tokenAmounts []router.ClientEVMTokenAmount
receiver common.Address
data []byte
expectedTokenBalances map[common.Address]*big.Int
expectedExecutionState int
}{
{
name: "Send token to EOA",
srcChain: sourceChain,
dstChain: destChain,
tokenAmounts: []router.ClientEVMTokenAmount{
{
Token: srcToken.Address(),
Amount: tinyOneCoin,
},
},
receiver: utils.RandomAddress(),
expectedTokenBalances: map[common.Address]*big.Int{
destToken.Address(): tinyOneCoin,
},
expectedExecutionState: changeset.EXECUTION_STATE_SUCCESS,
},
{
name: "Send token to contract",
srcChain: sourceChain,
dstChain: destChain,
tokenAmounts: []router.ClientEVMTokenAmount{
{
Token: srcToken.Address(),
Amount: tinyOneCoin,
},
},
receiver: state.Chains[destChain].Receiver.Address(),
expectedTokenBalances: map[common.Address]*big.Int{
destToken.Address(): tinyOneCoin,
},
expectedExecutionState: changeset.EXECUTION_STATE_SUCCESS,
},
{
name: "Send 2 tokens to receiver",
srcChain: destChain,
dstChain: sourceChain,
tokenAmounts: []router.ClientEVMTokenAmount{
{
Token: destToken.Address(),
Amount: tinyOneCoin,
},
{
Token: selfServeDestToken.Address(),
Amount: tinyOneCoin,
},
},
receiver: e.Chains[sourceChain].DeployerKey.From,
expectedTokenBalances: map[common.Address]*big.Int{
srcToken.Address(): tinyOneCoin,
selfServeSrcToken.Address(): tinyOneCoin,
},
expectedExecutionState: changeset.EXECUTION_STATE_SUCCESS,
},
{
name: "Send N tokens to contract",
srcChain: destChain,
dstChain: sourceChain,
tokenAmounts: []router.ClientEVMTokenAmount{
{
Token: selfServeDestToken.Address(),
Amount: tinyOneCoin,
},
{
Token: destToken.Address(),
Amount: tinyOneCoin,
},
{
Token: selfServeDestToken.Address(),
Amount: tinyOneCoin,
},
},
receiver: state.Chains[sourceChain].Receiver.Address(),
expectedTokenBalances: map[common.Address]*big.Int{
selfServeSrcToken.Address(): new(big.Int).SetUint64(2),
srcToken.Address(): tinyOneCoin,
},
expectedExecutionState: changeset.EXECUTION_STATE_SUCCESS,
},
}

for _, scenario := range scenarios {
scenario := scenario
t.Run(scenario.name, func(t *testing.T) {
initialBalances := map[common.Address]*big.Int{}
for token := range scenario.expectedTokenBalances {
initialBalance := changeset.GetTokenBalance(t, token, scenario.receiver, e.Chains[scenario.dstChain])
initialBalances[token] = initialBalance
}

changeset.TransferAndWaitForSuccess(
t,
e,
state,
scenario.srcChain,
scenario.dstChain,
scenario.tokenAmounts,
scenario.receiver,
scenario.data,
scenario.expectedExecutionState,
)

for token, balance := range scenario.expectedTokenBalances {
expected := new(big.Int).Add(initialBalances[token], balance)
changeset.WaitForTheTokenBalance(t, token, scenario.receiver, e.Chains[scenario.dstChain], expected)
}
})
}
}

// _createAndFundSelfServeActor is currently unused but retained for potential local testing.
// nolint:unused
func _createAndFundSelfServeActor(
t *testing.T,
deployer *bind.TransactOpts,
chain deployment.Chain,
amountToFund *big.Int,
) *bind.TransactOpts {
key, err := crypto.GenerateKey()
require.NoError(t, err)

actor, err := bind.NewKeyedTransactorWithChainID(key, getChainIdFromSelector(t, chain.Selector))
require.NoError(t, err)

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: amountToFund,
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
}

func getChainIdFromSelector(t *testing.T, selector uint64) *big.Int {
chainId, err := chainselectors.GetChainIDFromSelector(selector)
require.NoError(t, err)
//convert chainId from string to big.Int
chainIdBigInt := new(big.Int)
chainIdBigInt.SetString(chainId, 10)
return chainIdBigInt
}

func createDeployerKeyFromSimulatedPrivateKey(t *testing.T, selector uint64) *bind.TransactOpts {
key, err := crypto.HexToECDSA(networks.AdditionalSimulatedPvtKeys[0])
require.NoError(t, err)
chainId := getChainIdFromSelector(t, selector)
id, err := bind.NewKeyedTransactorWithChainID(key, chainId)
require.NoError(t, err)
return id
}
Loading

0 comments on commit eee7c93

Please sign in to comment.