Skip to content

Commit

Permalink
Add smoke test for check pipeline with Mercury Server enabled (#10766)
Browse files Browse the repository at this point in the history
* add mercury smoke test: this includes setting privilege config etc

* debug Endpoint in secrets config

* set secrets config after env.build

* add enough eth to cl nodes

* rebase and prep to fix some testing infra changes

* swap mock server with mock adapter and cleanup cl node to be cl cluster (#10971)

---------

Co-authored-by: Tate <[email protected]>
  • Loading branch information
shileiwill and tateexon authored Oct 17, 2023
1 parent edaefc6 commit 464de96
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 71 deletions.
16 changes: 9 additions & 7 deletions integration-tests/actions/automation_ocr_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ import (

"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
"github.com/smartcontractkit/chainlink-testing-framework/logging"
"github.com/smartcontractkit/chainlink/v2/core/services/job"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/chaintype"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
ocr2 "github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper"
ocr3 "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3confighelper"
"github.com/smartcontractkit/libocr/offchainreporting2plus/types"
ocr2keepers20config "github.com/smartcontractkit/ocr2keepers/pkg/v2/config"
ocr2keepers30config "github.com/smartcontractkit/ocr2keepers/pkg/v3/config"

"github.com/smartcontractkit/chainlink/v2/core/services/job"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/chaintype"
"github.com/smartcontractkit/chainlink/v2/core/store/models"

"github.com/smartcontractkit/chainlink/integration-tests/client"
"github.com/smartcontractkit/chainlink/integration-tests/contracts"
"github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum"
Expand All @@ -37,7 +38,7 @@ func BuildAutoOCR2ConfigVars(
registrar string,
deltaStage time.Duration,
) (contracts.OCRv2Config, error) {
return BuildAutoOCR2ConfigVarsWithKeyIndex(t, chainlinkNodes, registryConfig, registrar, deltaStage, 0)
return BuildAutoOCR2ConfigVarsWithKeyIndex(t, chainlinkNodes, registryConfig, registrar, deltaStage, 0, common.Address{})
}

func BuildAutoOCR2ConfigVarsWithKeyIndex(
Expand All @@ -47,6 +48,7 @@ func BuildAutoOCR2ConfigVarsWithKeyIndex(
registrar string,
deltaStage time.Duration,
keyIndex int,
registryOwnerAddress common.Address,
) (contracts.OCRv2Config, error) {
l := logging.GetTestLogger(t)
S, oracleIdentities, err := GetOracleIdentitiesWithKeyIndex(chainlinkNodes, keyIndex)
Expand Down Expand Up @@ -147,7 +149,7 @@ func BuildAutoOCR2ConfigVarsWithKeyIndex(
transmitters = append(transmitters, common.HexToAddress(string(transmitter)))
}

onchainConfig, err := registryConfig.EncodeOnChainConfig(registrar)
onchainConfig, err := registryConfig.EncodeOnChainConfig(registrar, registryOwnerAddress)
if err != nil {
return contracts.OCRv2Config{}, err
}
Expand Down Expand Up @@ -259,8 +261,8 @@ func DeployAutoOCRRegistryAndRegistrar(
return registry, registrar
}

func DeployConsumers(t *testing.T, registry contracts.KeeperRegistry, registrar contracts.KeeperRegistrar, linkToken contracts.LinkToken, contractDeployer contracts.ContractDeployer, client blockchain.EVMClient, numberOfUpkeeps int, linkFundsForEachUpkeep *big.Int, upkeepGasLimit uint32, isLogTrigger bool) ([]contracts.KeeperConsumer, []*big.Int) {
upkeeps := DeployKeeperConsumers(t, contractDeployer, client, numberOfUpkeeps, isLogTrigger)
func DeployConsumers(t *testing.T, registry contracts.KeeperRegistry, registrar contracts.KeeperRegistrar, linkToken contracts.LinkToken, contractDeployer contracts.ContractDeployer, client blockchain.EVMClient, numberOfUpkeeps int, linkFundsForEachUpkeep *big.Int, upkeepGasLimit uint32, isLogTrigger bool, isMercury bool) ([]contracts.KeeperConsumer, []*big.Int) {
upkeeps := DeployKeeperConsumers(t, contractDeployer, client, numberOfUpkeeps, isLogTrigger, isMercury)
var upkeepsAddresses []string
for _, upkeep := range upkeeps {
upkeepsAddresses = append(upkeepsAddresses, upkeep.Address())
Expand Down
16 changes: 9 additions & 7 deletions integration-tests/actions/automation_ocr_helpers_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import (
"github.com/lib/pq"
"github.com/pkg/errors"
"github.com/rs/zerolog"
"gopkg.in/guregu/null.v4"

"github.com/smartcontractkit/chainlink/v2/core/services/job"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/chaintype"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
ocr2 "github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper"
ocr3 "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3confighelper"
"github.com/smartcontractkit/libocr/offchainreporting2plus/types"
ocr2keepers20config "github.com/smartcontractkit/ocr2keepers/pkg/v2/config"
ocr2keepers30config "github.com/smartcontractkit/ocr2keepers/pkg/v3/config"
"gopkg.in/guregu/null.v4"

"github.com/smartcontractkit/chainlink/v2/core/services/job"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/chaintype"
"github.com/smartcontractkit/chainlink/v2/core/store/models"

"github.com/smartcontractkit/chainlink/integration-tests/client"
"github.com/smartcontractkit/chainlink/integration-tests/contracts"
Expand All @@ -32,8 +32,9 @@ func BuildAutoOCR2ConfigVarsLocal(
registryConfig contracts.KeeperRegistrySettings,
registrar string,
deltaStage time.Duration,
registryOwnerAddress common.Address,
) (contracts.OCRv2Config, error) {
return BuildAutoOCR2ConfigVarsWithKeyIndexLocal(l, chainlinkNodes, registryConfig, registrar, deltaStage, 0)
return BuildAutoOCR2ConfigVarsWithKeyIndexLocal(l, chainlinkNodes, registryConfig, registrar, deltaStage, 0, registryOwnerAddress)
}

func BuildAutoOCR2ConfigVarsWithKeyIndexLocal(
Expand All @@ -43,6 +44,7 @@ func BuildAutoOCR2ConfigVarsWithKeyIndexLocal(
registrar string,
deltaStage time.Duration,
keyIndex int,
registryOwnerAddress common.Address,
) (contracts.OCRv2Config, error) {
S, oracleIdentities, err := GetOracleIdentitiesWithKeyIndexLocal(chainlinkNodes, keyIndex)
if err != nil {
Expand Down Expand Up @@ -146,7 +148,7 @@ func BuildAutoOCR2ConfigVarsWithKeyIndexLocal(
transmitters = append(transmitters, common.HexToAddress(string(transmitter)))
}

onchainConfig, err := registryConfig.EncodeOnChainConfig(registrar)
onchainConfig, err := registryConfig.EncodeOnChainConfig(registrar, registryOwnerAddress)
if err != nil {
return contracts.OCRv2Config{}, err
}
Expand Down
10 changes: 6 additions & 4 deletions integration-tests/actions/keeper_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func DeployKeeperContracts(
}
registrar := DeployKeeperRegistrar(t, registryVersion, linkToken, registrarSettings, contractDeployer, client, registry)

upkeeps := DeployKeeperConsumers(t, contractDeployer, client, numberOfUpkeeps, false)
upkeeps := DeployKeeperConsumers(t, contractDeployer, client, numberOfUpkeeps, false, false)
var upkeepsAddresses []string
for _, upkeep := range upkeeps {
upkeepsAddresses = append(upkeepsAddresses, upkeep.Address())
Expand Down Expand Up @@ -397,7 +397,7 @@ func RegisterUpkeepContractsWithCheckData(t *testing.T, linkToken contracts.Link
return upkeepIds
}

func DeployKeeperConsumers(t *testing.T, contractDeployer contracts.ContractDeployer, client blockchain.EVMClient, numberOfContracts int, isLogTrigger bool) []contracts.KeeperConsumer {
func DeployKeeperConsumers(t *testing.T, contractDeployer contracts.ContractDeployer, client blockchain.EVMClient, numberOfContracts int, isLogTrigger bool, isMercury bool) []contracts.KeeperConsumer {
l := logging.GetTestLogger(t)
keeperConsumerContracts := make([]contracts.KeeperConsumer, 0)

Expand All @@ -406,7 +406,9 @@ func DeployKeeperConsumers(t *testing.T, contractDeployer contracts.ContractDepl
var keeperConsumerInstance contracts.KeeperConsumer
var err error

if isLogTrigger {
if isMercury {
keeperConsumerInstance, err = contractDeployer.DeployAutomationStreamsLookupUpkeepConsumer(big.NewInt(1000), big.NewInt(5), false, true, false) // 1000 block test range
} else if isLogTrigger {
keeperConsumerInstance, err = contractDeployer.DeployAutomationLogTriggerConsumer(big.NewInt(1000)) // 1000 block test range
} else {
keeperConsumerInstance, err = contractDeployer.DeployKeeperConsumer(big.NewInt(5))
Expand Down Expand Up @@ -581,7 +583,7 @@ func RegisterNewUpkeeps(
upkeepGasLimit uint32,
numberOfNewUpkeeps int,
) ([]contracts.KeeperConsumer, []*big.Int) {
newlyDeployedUpkeeps := DeployKeeperConsumers(t, contractDeployer, client, numberOfNewUpkeeps, false)
newlyDeployedUpkeeps := DeployKeeperConsumers(t, contractDeployer, client, numberOfNewUpkeeps, false, false)

var addressesOfNewUpkeeps []string
for _, upkeep := range newlyDeployedUpkeeps {
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/chaos/automation_chaos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ func TestAutomationChaos(t *testing.T) {
require.NoError(t, err, "Registry config should be be set successfully")
require.NoError(t, chainClient.WaitForEvents(), "Waiting for config to be set")

consumers_conditional, upkeepIDs_conditional := actions.DeployConsumers(t, registry, registrar, linkToken, contractDeployer, chainClient, numberOfUpkeeps, big.NewInt(defaultLinkFunds), defaultUpkeepGasLimit, false)
consumers_logtrigger, upkeepIDs_logtrigger := actions.DeployConsumers(t, registry, registrar, linkToken, contractDeployer, chainClient, numberOfUpkeeps, big.NewInt(defaultLinkFunds), defaultUpkeepGasLimit, true)
consumers_conditional, upkeepIDs_conditional := actions.DeployConsumers(t, registry, registrar, linkToken, contractDeployer, chainClient, numberOfUpkeeps, big.NewInt(defaultLinkFunds), defaultUpkeepGasLimit, false, false)
consumers_logtrigger, upkeepIDs_logtrigger := actions.DeployConsumers(t, registry, registrar, linkToken, contractDeployer, chainClient, numberOfUpkeeps, big.NewInt(defaultLinkFunds), defaultUpkeepGasLimit, true, false)

consumers := append(consumers_conditional, consumers_logtrigger...)
upkeepIDs := append(upkeepIDs_conditional, upkeepIDs_logtrigger...)
Expand Down
21 changes: 21 additions & 0 deletions integration-tests/contracts/contract_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/mock_gas_aggregator_wrapper"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/operator_factory"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/oracle_wrapper"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/streams_lookup_upkeep_wrapper"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/test_api_consumer_wrapper"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/upkeep_transcoder"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/llo-feeds/generated/fee_manager"
Expand Down Expand Up @@ -82,6 +83,7 @@ type ContractDeployer interface {
LoadKeeperRegistry(address common.Address, registryVersion eth_contracts.KeeperRegistryVersion) (KeeperRegistry, error)
DeployKeeperConsumer(updateInterval *big.Int) (KeeperConsumer, error)
DeployAutomationLogTriggerConsumer(testInterval *big.Int) (KeeperConsumer, error)
DeployAutomationStreamsLookupUpkeepConsumer(testRange *big.Int, interval *big.Int, useArbBlock bool, staging bool, verify bool) (KeeperConsumer, error)
DeployKeeperConsumerPerformance(
testBlockRange,
averageCadence,
Expand Down Expand Up @@ -1246,6 +1248,25 @@ func (e *EthereumContractDeployer) DeployAutomationLogTriggerConsumer(testInterv
}, err
}

func (e *EthereumContractDeployer) DeployAutomationStreamsLookupUpkeepConsumer(testRange *big.Int, interval *big.Int, useArbBlock bool, staging bool, verify bool) (KeeperConsumer, error) {
address, _, instance, err := e.client.DeployContract("StreamsLookupUpkeep", func(
auth *bind.TransactOpts,
backend bind.ContractBackend,
) (common.Address, *types.Transaction, interface{}, error) {
return streams_lookup_upkeep_wrapper.DeployStreamsLookupUpkeep(
auth, backend, testRange, interval, useArbBlock, staging, verify,
)
})
if err != nil {
return nil, err
}
return &EthereumAutomationStreamsLookupUpkeepConsumer{
client: e.client,
consumer: instance.(*streams_lookup_upkeep_wrapper.StreamsLookupUpkeep),
address: address,
}, err
}

func (e *EthereumContractDeployer) DeployUpkeepCounter(testRange *big.Int, interval *big.Int) (UpkeepCounter, error) {
address, _, instance, err := e.client.DeployContract("UpkeepCounter", func(
auth *bind.TransactOpts,
Expand Down
75 changes: 73 additions & 2 deletions integration-tests/contracts/ethereum_keeper_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/keeper_registry_wrapper2_0"
registry21 "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/keeper_registry_wrapper_2_1"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/log_upkeep_counter_wrapper"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/streams_lookup_upkeep_wrapper"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/upkeep_transcoder"
"github.com/smartcontractkit/chainlink/v2/core/utils"

Expand Down Expand Up @@ -76,6 +77,8 @@ type KeeperRegistry interface {
UnpauseUpkeep(id *big.Int) error
UpdateCheckData(id *big.Int, newCheckData []byte) error
SetUpkeepTriggerConfig(id *big.Int, triggerConfig []byte) error
SetUpkeepPrivilegeConfig(id *big.Int, privilegeConfig []byte) error
RegistryOwnerAddress() common.Address
}

type KeeperConsumer interface {
Expand Down Expand Up @@ -218,7 +221,7 @@ func (v *EthereumKeeperRegistry) Fund(ethAmount *big.Float) error {
return v.client.Fund(v.address.Hex(), ethAmount, gasEstimates)
}

func (rcs *KeeperRegistrySettings) EncodeOnChainConfig(registrar string) ([]byte, error) {
func (rcs *KeeperRegistrySettings) EncodeOnChainConfig(registrar string, registryOwnerAddress common.Address) ([]byte, error) {
if rcs.RegistryVersion == ethereum.RegistryVersion_2_1 {
onchainConfigStruct := registry21.KeeperRegistryBase21OnchainConfig{
PaymentPremiumPPB: rcs.PaymentPremiumPPB,
Expand All @@ -235,7 +238,7 @@ func (rcs *KeeperRegistrySettings) EncodeOnChainConfig(registrar string) ([]byte
FallbackLinkPrice: rcs.FallbackLinkPrice,
Transcoder: common.Address{},
Registrars: []common.Address{common.HexToAddress(registrar)},
UpkeepPrivilegeManager: common.Address{},
UpkeepPrivilegeManager: registryOwnerAddress,
}
encodedOnchainConfig, err := utilsABI.Methods["_onChainConfig"].Inputs.Pack(&onchainConfigStruct)

Expand All @@ -261,6 +264,10 @@ func (rcs *KeeperRegistrySettings) EncodeOnChainConfig(registrar string) ([]byte
}
}

func (v *EthereumKeeperRegistry) RegistryOwnerAddress() common.Address {
return common.HexToAddress(v.client.GetDefaultWallet().Address())
}

func (v *EthereumKeeperRegistry) SetConfig(config KeeperRegistrySettings, ocrConfig OCRv2Config) error {
txOpts, err := v.client.TransactionOpts(v.client.GetDefaultWallet())
if err != nil {
Expand Down Expand Up @@ -924,6 +931,26 @@ func (v *EthereumKeeperRegistry) SetUpkeepTriggerConfig(id *big.Int, triggerConf
}
}

// SetUpkeepPrivilegeConfig sets the privilege config of an upkeep (only for version 2.1)
func (v *EthereumKeeperRegistry) SetUpkeepPrivilegeConfig(id *big.Int, privilegeConfig []byte) error {

switch v.version {
case ethereum.RegistryVersion_2_1:
opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet())
if err != nil {
return err
}

tx, err := v.registry2_1.SetUpkeepPrivilegeConfig(opts, id, privilegeConfig)
if err != nil {
return err
}
return v.client.ProcessTransaction(tx)
default:
return fmt.Errorf("SetUpkeepPrivilegeConfig is not supported by keeper registry version %d", v.version)
}
}

// PauseUpkeep stops an upkeep from an upkeep
func (v *EthereumKeeperRegistry) PauseUpkeep(id *big.Int) error {
switch v.version {
Expand Down Expand Up @@ -1665,6 +1692,50 @@ func (v *EthereumKeeperConsumer) Counter(ctx context.Context) (*big.Int, error)
return cnt, nil
}

type EthereumAutomationStreamsLookupUpkeepConsumer struct {
client blockchain.EVMClient
consumer *streams_lookup_upkeep_wrapper.StreamsLookupUpkeep
address *common.Address
}

func (v *EthereumAutomationStreamsLookupUpkeepConsumer) Address() string {
return v.address.Hex()
}

func (v *EthereumAutomationStreamsLookupUpkeepConsumer) Start() error {
// For this consumer upkeep, we use this Start() function to set ParamKeys so as to run mercury v0.2
txOpts, err := v.client.TransactionOpts(v.client.GetDefaultWallet())
if err != nil {
return err
}

tx, err := v.consumer.SetParamKeys(txOpts, "feedIdHex", "blockNumber")
if err != nil {
return err
}
return v.client.ProcessTransaction(tx)
}

func (v *EthereumAutomationStreamsLookupUpkeepConsumer) Fund(ethAmount *big.Float) error {
gasEstimates, err := v.client.EstimateGas(geth.CallMsg{})
if err != nil {
return err
}
return v.client.Fund(v.address.Hex(), ethAmount, gasEstimates)
}

func (v *EthereumAutomationStreamsLookupUpkeepConsumer) Counter(ctx context.Context) (*big.Int, error) {
opts := &bind.CallOpts{
From: common.HexToAddress(v.client.GetDefaultWallet().Address()),
Context: ctx,
}
cnt, err := v.consumer.Counter(opts)
if err != nil {
return nil, err
}
return cnt, nil
}

type EthereumAutomationLogCounterConsumer struct {
client blockchain.EVMClient
consumer *log_upkeep_counter_wrapper.LogUpkeepCounter
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/reorg/automation_reorg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func TestAutomationReorg(t *testing.T) {

// Use the name to determine if this is a log trigger or not
isLogTrigger := name == "registry_2_1_logtrigger"
consumers, upkeepIDs := actions.DeployConsumers(t, registry, registrar, linkToken, contractDeployer, chainClient, numberOfUpkeeps, big.NewInt(defaultLinkFunds), defaultUpkeepGasLimit, isLogTrigger)
consumers, upkeepIDs := actions.DeployConsumers(t, registry, registrar, linkToken, contractDeployer, chainClient, numberOfUpkeeps, big.NewInt(defaultLinkFunds), defaultUpkeepGasLimit, isLogTrigger, false)

l.Info().Msg("Waiting for all upkeeps to be performed")

Expand Down
Loading

0 comments on commit 464de96

Please sign in to comment.