Skip to content

Commit

Permalink
[TT-653] More integration-test lib migration to chainlink-testing-fra…
Browse files Browse the repository at this point in the history
…mework (#11317)

* [TT-653] Migrate more integration-test libs to chainlink-testing-framework

* testing

* merge conflict fix

* bump ctf version
  • Loading branch information
tateexon authored Nov 16, 2023
1 parent 96498b6 commit a9d81ae
Show file tree
Hide file tree
Showing 46 changed files with 368 additions and 447 deletions.
4 changes: 2 additions & 2 deletions integration-tests/actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/smartcontractkit/chainlink-testing-framework/k8s/environment"
"github.com/smartcontractkit/chainlink-testing-framework/logging"
"github.com/smartcontractkit/chainlink-testing-framework/testreporters"
"github.com/smartcontractkit/chainlink-testing-framework/utils"
"github.com/smartcontractkit/chainlink-testing-framework/utils/conversions"

"github.com/smartcontractkit/chainlink/integration-tests/client"
"github.com/smartcontractkit/chainlink/integration-tests/contracts"
Expand All @@ -48,7 +48,7 @@ func FundChainlinkNodes(
msg := ethereum.CallMsg{
From: common.HexToAddress(client.GetDefaultWallet().Address()),
To: &recipient,
Value: utils.EtherToWei(amount),
Value: conversions.EtherToWei(amount),
}
gasEstimates, err := client.EstimateGas(msg)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/actions/ocr2vrf_actions/ocr2vrf_steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
"github.com/smartcontractkit/chainlink-testing-framework/logging"
"github.com/smartcontractkit/chainlink-testing-framework/utils/testcontext"

"github.com/smartcontractkit/chainlink/v2/core/services/keystore/chaintype"
chainlinkutils "github.com/smartcontractkit/chainlink/v2/core/utils"
Expand All @@ -22,7 +23,6 @@ import (
"github.com/smartcontractkit/chainlink/integration-tests/actions/ocr2vrf_actions/ocr2vrf_constants"
"github.com/smartcontractkit/chainlink/integration-tests/client"
"github.com/smartcontractkit/chainlink/integration-tests/contracts"
"github.com/smartcontractkit/chainlink/integration-tests/utils"
)

func SetAndWaitForVRFBeaconProcessToFinish(t *testing.T, ocr2VRFPluginConfig *OCR2VRFPluginConfig, vrfBeacon contracts.VRFBeacon) {
Expand Down Expand Up @@ -273,14 +273,14 @@ func RequestRandomnessFulfillmentAndWaitForFulfilment(
}

func getRequestId(t *testing.T, consumer contracts.VRFBeaconConsumer, receipt *types.Receipt, confirmationDelay *big.Int) *big.Int {
periodBlocks, err := consumer.IBeaconPeriodBlocks(utils.TestContext(t))
periodBlocks, err := consumer.IBeaconPeriodBlocks(testcontext.Get(t))
require.NoError(t, err, "Error getting Beacon Period block count")

blockNumber := receipt.BlockNumber
periodOffset := new(big.Int).Mod(blockNumber, periodBlocks)
nextBeaconOutputHeight := new(big.Int).Sub(new(big.Int).Add(blockNumber, periodBlocks), periodOffset)

requestID, err := consumer.GetRequestIdsBy(utils.TestContext(t), nextBeaconOutputHeight, confirmationDelay)
requestID, err := consumer.GetRequestIdsBy(testcontext.Get(t), nextBeaconOutputHeight, confirmationDelay)
require.NoError(t, err, "Error getting requestID from consumer contract")

return requestID
Expand Down
12 changes: 6 additions & 6 deletions integration-tests/actions/operator_forwarder_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (

"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
"github.com/smartcontractkit/chainlink-testing-framework/logging"
"github.com/smartcontractkit/chainlink-testing-framework/utils/testcontext"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/operator_factory"

"github.com/smartcontractkit/chainlink/integration-tests/client"
"github.com/smartcontractkit/chainlink/integration-tests/contracts"
"github.com/smartcontractkit/chainlink/integration-tests/utils"
)

func DeployForwarderContracts(
Expand Down Expand Up @@ -67,15 +67,15 @@ func AcceptAuthorizedReceiversOperator(
err = chainClient.WaitForEvents()
require.NoError(t, err, "Waiting for events in nodes shouldn't fail")

senders, err := forwarderInstance.GetAuthorizedSenders(utils.TestContext(t))
senders, err := forwarderInstance.GetAuthorizedSenders(testcontext.Get(t))
require.NoError(t, err, "Getting authorized senders shouldn't fail")
var nodesAddrs []string
for _, o := range nodeAddresses {
nodesAddrs = append(nodesAddrs, o.Hex())
}
require.Equal(t, nodesAddrs, senders, "Senders addresses should match node addresses")

owner, err := forwarderInstance.Owner(utils.TestContext(t))
owner, err := forwarderInstance.Owner(testcontext.Get(t))
require.NoError(t, err, "Getting authorized forwarder owner shouldn't fail")
require.Equal(t, operator.Hex(), owner, "Forwarder owner should match operator")
}
Expand Down Expand Up @@ -139,15 +139,15 @@ func SubscribeOperatorFactoryEvents(
l := logging.GetTestLogger(t)
contractABI, err := operator_factory.OperatorFactoryMetaData.GetAbi()
require.NoError(t, err, "Getting contract abi for OperatorFactory shouldn't fail")
latestBlockNum, err := chainClient.LatestBlockNumber(utils.TestContext(t))
latestBlockNum, err := chainClient.LatestBlockNumber(testcontext.Get(t))
require.NoError(t, err, "Subscribing to contract event log for OperatorFactory instance shouldn't fail")
query := geth.FilterQuery{
FromBlock: big.NewInt(0).SetUint64(latestBlockNum),
Addresses: []common.Address{common.HexToAddress(operatorFactoryInstance.Address())},
}

eventLogs := make(chan types.Log)
sub, err := chainClient.SubscribeFilterLogs(utils.TestContext(t), query, eventLogs)
sub, err := chainClient.SubscribeFilterLogs(testcontext.Get(t), query, eventLogs)
require.NoError(t, err, "Subscribing to contract event log for OperatorFactory instance shouldn't fail")
go func() {
defer sub.Unsubscribe()
Expand All @@ -158,7 +158,7 @@ func SubscribeOperatorFactoryEvents(
l.Error().Err(err).Msg("Error while watching for new contract events. Retrying Subscription")
sub.Unsubscribe()

sub, err = chainClient.SubscribeFilterLogs(utils.TestContext(t), query, eventLogs)
sub, err = chainClient.SubscribeFilterLogs(testcontext.Get(t), query, eventLogs)
require.NoError(t, err, "Subscribing to contract event log for OperatorFactory instance shouldn't fail")
case vLog := <-eventLogs:
eventDetails, err := contractABI.EventByID(vLog.Topics[0])
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/actions/vrfv2plus/vrfv2plus_steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"sync"
"time"

"github.com/smartcontractkit/chainlink-testing-framework/utils"
"github.com/smartcontractkit/chainlink-testing-framework/utils/conversions"

relayassets "github.com/smartcontractkit/chainlink-relay/pkg/assets"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
Expand Down Expand Up @@ -599,7 +599,7 @@ func FundSubscriptions(
) error {
for _, subID := range subIDs {
//Native Billing
amountWei := utils.EtherToWei(big.NewFloat(vrfv2PlusConfig.SubscriptionFundingAmountNative))
amountWei := conversions.EtherToWei(big.NewFloat(vrfv2PlusConfig.SubscriptionFundingAmountNative))
err := coordinator.FundSubscriptionWithNative(
subID,
amountWei,
Expand All @@ -608,7 +608,7 @@ func FundSubscriptions(
return fmt.Errorf("%s, err %w", ErrFundSubWithNativeToken, err)
}
//Link Billing
amountJuels := utils.EtherToWei(big.NewFloat(vrfv2PlusConfig.SubscriptionFundingAmountLink))
amountJuels := conversions.EtherToWei(big.NewFloat(vrfv2PlusConfig.SubscriptionFundingAmountLink))
err = FundVRFCoordinatorV2_5Subscription(linkAddress, coordinator, env.EVMClient, subID, amountJuels)
if err != nil {
return fmt.Errorf("%s, err %w", ErrFundSubWithLinkToken, err)
Expand Down
3 changes: 1 addition & 2 deletions integration-tests/benchmark/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/smartcontractkit/chainlink-testing-framework/networks"

"github.com/smartcontractkit/chainlink/integration-tests/actions"
"github.com/smartcontractkit/chainlink/integration-tests/client"
"github.com/smartcontractkit/chainlink/integration-tests/contracts"
eth_contracts "github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum"
"github.com/smartcontractkit/chainlink/integration-tests/testsetups"
Expand Down Expand Up @@ -434,7 +433,7 @@ func SetupAutomationBenchmarkEnv(t *testing.T) (*environment.Environment, blockc
testNetwork.HTTPURLs = []string{internalHttpURLs[i]}
testNetwork.URLs = []string{internalWsURLs[i]}
testEnvironment.AddHelm(chainlink.New(i, map[string]any{
"toml": client.AddNetworkDetailedConfig(keeperBenchmarkBaseTOML, networkDetailTOML, testNetwork),
"toml": networks.AddNetworkDetailedConfig(keeperBenchmarkBaseTOML, networkDetailTOML, testNetwork),
"chainlink": chainlinkResources,
"db": dbResources,
}))
Expand Down
26 changes: 13 additions & 13 deletions integration-tests/chaos/automation_chaos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import (
"github.com/smartcontractkit/chainlink-testing-framework/k8s/pkg/helm/ethereum"
"github.com/smartcontractkit/chainlink-testing-framework/logging"
"github.com/smartcontractkit/chainlink-testing-framework/networks"
"github.com/smartcontractkit/chainlink-testing-framework/utils"
"github.com/smartcontractkit/chainlink-testing-framework/utils/ptr"
"github.com/smartcontractkit/chainlink-testing-framework/utils/testcontext"

"github.com/smartcontractkit/chainlink/integration-tests/actions"
"github.com/smartcontractkit/chainlink/integration-tests/client"
"github.com/smartcontractkit/chainlink/integration-tests/contracts"
eth_contracts "github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum"
it_utils "github.com/smartcontractkit/chainlink/integration-tests/utils"
)

var (
Expand All @@ -41,7 +41,7 @@ ListenAddresses = ["0.0.0.0:6690"]`

defaultAutomationSettings = map[string]interface{}{
"replicas": 6,
"toml": client.AddNetworksConfig(baseTOML, networks.MustGetSelectedNetworksFromEnv()[0]),
"toml": networks.AddNetworksConfig(baseTOML, networks.MustGetSelectedNetworksFromEnv()[0]),
"db": map[string]interface{}{
"stateful": true,
"capacity": "1Gi",
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestAutomationChaos(t *testing.T) {
chainlink.New(0, defaultAutomationSettings),
chaos.NewFailPods,
&chaos.Props{
LabelsSelector: &map[string]*string{ChaosGroupMinority: utils.Ptr("1")},
LabelsSelector: &map[string]*string{ChaosGroupMinority: ptr.Ptr("1")},
DurationStr: "1m",
},
},
Expand All @@ -141,7 +141,7 @@ func TestAutomationChaos(t *testing.T) {
chainlink.New(0, defaultAutomationSettings),
chaos.NewFailPods,
&chaos.Props{
LabelsSelector: &map[string]*string{ChaosGroupMajority: utils.Ptr("1")},
LabelsSelector: &map[string]*string{ChaosGroupMajority: ptr.Ptr("1")},
DurationStr: "1m",
},
},
Expand All @@ -150,18 +150,18 @@ func TestAutomationChaos(t *testing.T) {
chainlink.New(0, defaultAutomationSettings),
chaos.NewFailPods,
&chaos.Props{
LabelsSelector: &map[string]*string{ChaosGroupMajority: utils.Ptr("1")},
LabelsSelector: &map[string]*string{ChaosGroupMajority: ptr.Ptr("1")},
DurationStr: "1m",
ContainerNames: &[]*string{utils.Ptr("chainlink-db")},
ContainerNames: &[]*string{ptr.Ptr("chainlink-db")},
},
},
NetworkChaosFailMajorityNetwork: {
ethereum.New(defaultEthereumSettings),
chainlink.New(0, defaultAutomationSettings),
chaos.NewNetworkPartition,
&chaos.Props{
FromLabels: &map[string]*string{ChaosGroupMajority: utils.Ptr("1")},
ToLabels: &map[string]*string{ChaosGroupMinority: utils.Ptr("1")},
FromLabels: &map[string]*string{ChaosGroupMajority: ptr.Ptr("1")},
ToLabels: &map[string]*string{ChaosGroupMinority: ptr.Ptr("1")},
DurationStr: "1m",
},
},
Expand All @@ -170,8 +170,8 @@ func TestAutomationChaos(t *testing.T) {
chainlink.New(0, defaultAutomationSettings),
chaos.NewNetworkPartition,
&chaos.Props{
FromLabels: &map[string]*string{"app": utils.Ptr("geth")},
ToLabels: &map[string]*string{ChaosGroupMajorityPlus: utils.Ptr("1")},
FromLabels: &map[string]*string{"app": ptr.Ptr("geth")},
ToLabels: &map[string]*string{ChaosGroupMajorityPlus: ptr.Ptr("1")},
DurationStr: "1m",
},
},
Expand Down Expand Up @@ -269,7 +269,7 @@ func TestAutomationChaos(t *testing.T) {
gom.Eventually(func(g gomega.Gomega) {
// Check if the upkeeps are performing multiple times by analyzing their counters and checking they are greater than 10
for i := 0; i < len(upkeepIDs); i++ {
counter, err := consumers[i].Counter(it_utils.TestContext(t))
counter, err := consumers[i].Counter(testcontext.Get(t))
require.NoError(t, err, "Failed to retrieve consumer counter for upkeep at index %d", i)
expect := 5
l.Info().Int64("Upkeeps Performed", counter.Int64()).Int("Upkeep ID", i).Msg("Number of upkeeps performed")
Expand All @@ -284,7 +284,7 @@ func TestAutomationChaos(t *testing.T) {
gom.Eventually(func(g gomega.Gomega) {
// Check if the upkeeps are performing multiple times by analyzing their counters and checking they are greater than 10
for i := 0; i < len(upkeepIDs); i++ {
counter, err := consumers[i].Counter(it_utils.TestContext(t))
counter, err := consumers[i].Counter(testcontext.Get(t))
require.NoError(t, err, "Failed to retrieve consumer counter for upkeep at index %d", i)
expect := 10
l.Info().Int64("Upkeeps Performed", counter.Int64()).Int("Upkeep ID", i).Msg("Number of upkeeps performed")
Expand Down
26 changes: 13 additions & 13 deletions integration-tests/chaos/ocr2vrf_chaos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import (
"github.com/smartcontractkit/chainlink-testing-framework/k8s/pkg/helm/ethereum"
"github.com/smartcontractkit/chainlink-testing-framework/logging"
"github.com/smartcontractkit/chainlink-testing-framework/networks"
"github.com/smartcontractkit/chainlink-testing-framework/utils"
"github.com/smartcontractkit/chainlink-testing-framework/utils/ptr"
"github.com/smartcontractkit/chainlink-testing-framework/utils/testcontext"

"github.com/smartcontractkit/chainlink/integration-tests/actions"
"github.com/smartcontractkit/chainlink/integration-tests/actions/ocr2vrf_actions"
"github.com/smartcontractkit/chainlink/integration-tests/actions/ocr2vrf_actions/ocr2vrf_constants"
"github.com/smartcontractkit/chainlink/integration-tests/client"
"github.com/smartcontractkit/chainlink/integration-tests/config"
"github.com/smartcontractkit/chainlink/integration-tests/contracts"
it_utils "github.com/smartcontractkit/chainlink/integration-tests/utils"
)

func TestOCR2VRFChaos(t *testing.T) {
Expand All @@ -35,7 +35,7 @@ func TestOCR2VRFChaos(t *testing.T) {

defaultOCR2VRFSettings := map[string]interface{}{
"replicas": 6,
"toml": client.AddNetworkDetailedConfig(
"toml": networks.AddNetworkDetailedConfig(
config.BaseOCR2Config,
config.DefaultOCR2VRFNetworkDetailTomlConfig,
loadedNetwork,
Expand Down Expand Up @@ -68,7 +68,7 @@ func TestOCR2VRFChaos(t *testing.T) {
chainlink.New(0, defaultOCR2VRFSettings),
chaos.NewFailPods,
&chaos.Props{
LabelsSelector: &map[string]*string{ChaosGroupMinority: utils.Ptr("1")},
LabelsSelector: &map[string]*string{ChaosGroupMinority: ptr.Ptr("1")},
DurationStr: "1m",
},
},
Expand All @@ -78,7 +78,7 @@ func TestOCR2VRFChaos(t *testing.T) {
// chainlink.New(0, defaultOCR2VRFSettings),
// chaos.NewFailPods,
// &chaos.Props{
// LabelsSelector: &map[string]*string{ChaosGroupMajority: utils.Ptr("1")},
// LabelsSelector: &map[string]*string{ChaosGroupMajority: ptr.Ptr("1")},
// DurationStr: "1m",
// },
//},
Expand All @@ -88,18 +88,18 @@ func TestOCR2VRFChaos(t *testing.T) {
// chainlink.New(0, defaultOCR2VRFSettings),
// chaos.NewFailPods,
// &chaos.Props{
// LabelsSelector: &map[string]*string{ChaosGroupMajority: utils.Ptr("1")},
// LabelsSelector: &map[string]*string{ChaosGroupMajority: ptr.Ptr("1")},
// DurationStr: "1m",
// ContainerNames: &[]*string{utils.Ptr("chainlink-db")},
// ContainerNames: &[]*string{ptr.Ptr("chainlink-db")},
// },
//},
//NetworkChaosFailMajorityNetwork: {
// ethereum.New(defaultOCR2VRFEthereumSettings),
// chainlink.New(0, defaultOCR2VRFSettings),
// chaos.NewNetworkPartition,
// &chaos.Props{
// FromLabels: &map[string]*string{ChaosGroupMajority: utils.Ptr("1")},
// ToLabels: &map[string]*string{ChaosGroupMinority: utils.Ptr("1")},
// FromLabels: &map[string]*string{ChaosGroupMajority: ptr.Ptr("1")},
// ToLabels: &map[string]*string{ChaosGroupMinority: ptr.Ptr("1")},
// DurationStr: "1m",
// },
//},
Expand All @@ -108,8 +108,8 @@ func TestOCR2VRFChaos(t *testing.T) {
// chainlink.New(0, defaultOCR2VRFSettings),
// chaos.NewNetworkPartition,
// &chaos.Props{
// FromLabels: &map[string]*string{"app": utils.Ptr("geth")},
// ToLabels: &map[string]*string{ChaosGroupMajority: utils.Ptr("1")},
// FromLabels: &map[string]*string{"app": ptr.Ptr("geth")},
// ToLabels: &map[string]*string{ChaosGroupMajority: ptr.Ptr("1")},
// DurationStr: "1m",
// },
//},
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestOCR2VRFChaos(t *testing.T) {
)

for i := uint16(0); i < ocr2vrf_constants.NumberOfRandomWordsToRequest; i++ {
randomness, err := consumerContract.GetRandomnessByRequestId(it_utils.TestContext(t), requestID, big.NewInt(int64(i)))
randomness, err := consumerContract.GetRandomnessByRequestId(testcontext.Get(t), requestID, big.NewInt(int64(i)))
require.NoError(t, err)
l.Info().Interface("Random Number", randomness).Interface("Randomness Number Index", i).Msg("Randomness retrieved from Consumer contract")
require.NotEqual(t, 0, randomness.Uint64(), "Randomness retrieved from Consumer contract give an answer other than 0")
Expand All @@ -213,7 +213,7 @@ func TestOCR2VRFChaos(t *testing.T) {
)

for i := uint16(0); i < ocr2vrf_constants.NumberOfRandomWordsToRequest; i++ {
randomness, err := consumerContract.GetRandomnessByRequestId(it_utils.TestContext(t), requestID, big.NewInt(int64(i)))
randomness, err := consumerContract.GetRandomnessByRequestId(testcontext.Get(t), requestID, big.NewInt(int64(i)))
require.NoError(t, err, "Error getting Randomness result from Consumer Contract")
l.Info().Interface("Random Number", randomness).Interface("Randomness Number Index", i).Msg("Randomness retrieved from Consumer contract")
require.NotEqual(t, 0, randomness.Uint64(), "Randomness retrieved from Consumer contract give an answer other than 0")
Expand Down
Loading

0 comments on commit a9d81ae

Please sign in to comment.