Skip to content

Commit

Permalink
add multicall contract in pre-deployed contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
anirudhwarrier committed Sep 20, 2024
1 parent b2b40c3 commit fd9e98a
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 120 deletions.
53 changes: 49 additions & 4 deletions integration-tests/actions/automation_ocr_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (
"math/big"
"testing"

"github.com/ethereum/go-ethereum/common"

tt "github.com/smartcontractkit/chainlink/integration-tests/types"

"github.com/pkg/errors"

"github.com/smartcontractkit/chainlink-testing-framework/seth"
Expand Down Expand Up @@ -34,10 +38,10 @@ func DeployAutoOCRRegistryAndRegistrar(

// DeployConsumers deploys and registers keeper consumers. If ephemeral addresses are enabled, it will deploy and register the consumers from ephemeral addresses, but each upkpeep will be registered with root key address as the admin. Which means
// that functions like setting upkeep configuration, pausing, unpausing, etc. will be done by the root key address. It deploys multicall contract and sends link funds to each deployment address.
func DeployConsumers(t *testing.T, chainClient *seth.Client, registry contracts.KeeperRegistry, registrar contracts.KeeperRegistrar, linkToken contracts.LinkToken, numberOfUpkeeps int, linkFundsForEachUpkeep *big.Int, upkeepGasLimit uint32, isLogTrigger bool, isMercury bool, isBillingTokenNative bool, wethToken contracts.WETHToken) ([]contracts.KeeperConsumer, []*big.Int) {
func DeployConsumers(t *testing.T, chainClient *seth.Client, registry contracts.KeeperRegistry, registrar contracts.KeeperRegistrar, linkToken contracts.LinkToken, numberOfUpkeeps int, linkFundsForEachUpkeep *big.Int, upkeepGasLimit uint32, isLogTrigger bool, isMercury bool, isBillingTokenNative bool, wethToken contracts.WETHToken, config tt.AutomationTestConfig) ([]contracts.KeeperConsumer, []*big.Int) {
// Fund deployers with LINK, no need to do this for Native token
if !isBillingTokenNative {
err := DeployMultiCallAndFundDeploymentAddresses(chainClient, linkToken, numberOfUpkeeps, linkFundsForEachUpkeep)
err := SetupMultiCallAndFundDeploymentAddresses(chainClient, linkToken, numberOfUpkeeps, linkFundsForEachUpkeep, config)
require.NoError(t, err, "Sending link funds to deployment addresses shouldn't fail")
}

Expand Down Expand Up @@ -69,12 +73,13 @@ func DeployPerformanceConsumers(
blockInterval, // Interval of blocks that upkeeps are expected to be performed
checkGasToBurn, // How much gas should be burned on checkUpkeep() calls
performGasToBurn int64, // How much gas should be burned on performUpkeep() calls
config tt.AutomationTestConfig,
) ([]contracts.KeeperConsumerPerformance, []*big.Int) {
upkeeps := DeployKeeperConsumersPerformance(
t, chainClient, numberOfUpkeeps, blockRange, blockInterval, checkGasToBurn, performGasToBurn,
)

err := DeployMultiCallAndFundDeploymentAddresses(chainClient, linkToken, numberOfUpkeeps, linkFundsForEachUpkeep)
err := SetupMultiCallAndFundDeploymentAddresses(chainClient, linkToken, numberOfUpkeeps, linkFundsForEachUpkeep, config)
require.NoError(t, err, "Sending link funds to deployment addresses shouldn't fail")

var upkeepsAddresses []string
Expand All @@ -97,10 +102,11 @@ func DeployPerformDataCheckerConsumers(
linkFundsForEachUpkeep *big.Int,
upkeepGasLimit uint32,
expectedData []byte,
config tt.AutomationTestConfig,
) ([]contracts.KeeperPerformDataChecker, []*big.Int) {
upkeeps := DeployPerformDataChecker(t, chainClient, numberOfUpkeeps, expectedData)

err := DeployMultiCallAndFundDeploymentAddresses(chainClient, linkToken, numberOfUpkeeps, linkFundsForEachUpkeep)
err := SetupMultiCallAndFundDeploymentAddresses(chainClient, linkToken, numberOfUpkeeps, linkFundsForEachUpkeep, config)
require.NoError(t, err, "Sending link funds to deployment addresses shouldn't fail")

var upkeepsAddresses []string
Expand All @@ -111,6 +117,45 @@ func DeployPerformDataCheckerConsumers(
return upkeeps, upkeepIds
}

func SetupMultiCallAddress(chainClient *seth.Client, testConfig tt.AutomationTestConfig) (common.Address, error) {
if testConfig.GetAutomationConfig().UseExistingMultiCallContract() {
multiCallAddress, err := testConfig.GetAutomationConfig().MultiCallContractAddress()
if err != nil {
return common.Address{}, errors.Wrap(err, "Error getting existing multicall contract address")
}
return multiCallAddress, nil
}

multicallAddress, err := contracts.DeployMultiCallContract(chainClient)
if err != nil {
return common.Address{}, errors.Wrap(err, "Error deploying multicall contract")
}
return multicallAddress, nil
}

// SetupMultiCallAndFundDeploymentAddresses setups multicall contract and sends link funds to each deployment address
func SetupMultiCallAndFundDeploymentAddresses(
chainClient *seth.Client,
linkToken contracts.LinkToken,
numberOfUpkeeps int,
linkFundsForEachUpkeep *big.Int,
testConfig tt.AutomationTestConfig,
) error {
concurrency, err := GetAndAssertCorrectConcurrency(chainClient, 1)
if err != nil {
return err
}

operationsPerAddress := numberOfUpkeeps / concurrency

multicallAddress, err := SetupMultiCallAddress(chainClient, testConfig)
if err != nil {
return errors.Wrap(err, "Error deploying multicall contract")
}

return SendLinkFundsToDeploymentAddresses(chainClient, concurrency, numberOfUpkeeps, operationsPerAddress, multicallAddress, linkFundsForEachUpkeep, linkToken)
}

// DeployMultiCallAndFundDeploymentAddresses deploys multicall contract and sends link funds to each deployment address
func DeployMultiCallAndFundDeploymentAddresses(
chainClient *seth.Client,
Expand Down
4 changes: 3 additions & 1 deletion integration-tests/actions/keeper_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"strconv"
"testing"

"github.com/smartcontractkit/chainlink/integration-tests/testconfig"

"github.com/ethereum/go-ethereum/core/types"
"github.com/google/uuid"
"github.com/pkg/errors"
Expand Down Expand Up @@ -117,7 +119,7 @@ func DeployKeeperContracts(
}

registrar := DeployKeeperRegistrar(t, client, registryVersion, linkToken, registrarSettings, registry)
upkeeps, upkeepIds := DeployConsumers(t, client, registry, registrar, linkToken, numberOfUpkeeps, linkFundsForEachUpkeep, upkeepGasLimit, false, false, false, nil)
upkeeps, upkeepIds := DeployConsumers(t, client, registry, registrar, linkToken, numberOfUpkeeps, linkFundsForEachUpkeep, upkeepGasLimit, false, false, false, nil, &testconfig.TestConfig{})

return registry, registrar, upkeeps, upkeepIds
}
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 @@ -259,11 +259,11 @@ func TestAutomationChaos(t *testing.T) {

var consumersLogTrigger, consumersConditional []contracts.KeeperConsumer
var upkeepidsConditional, upkeepidsLogTrigger []*big.Int
consumersConditional, upkeepidsConditional = actions.DeployConsumers(t, a.ChainClient, a.Registry, a.Registrar, a.LinkToken, numberOfUpkeeps, big.NewInt(defaultLinkFunds), defaultUpkeepGasLimit, false, false, false, nil)
consumersConditional, upkeepidsConditional = actions.DeployConsumers(t, a.ChainClient, a.Registry, a.Registrar, a.LinkToken, numberOfUpkeeps, big.NewInt(defaultLinkFunds), defaultUpkeepGasLimit, false, false, false, nil, &config)
consumers := consumersConditional
upkeepIDs := upkeepidsConditional
if rv >= eth_contracts.RegistryVersion_2_1 {
consumersLogTrigger, upkeepidsLogTrigger = actions.DeployConsumers(t, a.ChainClient, a.Registry, a.Registrar, a.LinkToken, numberOfUpkeeps, big.NewInt(defaultLinkFunds), defaultUpkeepGasLimit, true, false, false, nil)
consumersLogTrigger, upkeepidsLogTrigger = actions.DeployConsumers(t, a.ChainClient, a.Registry, a.Registrar, a.LinkToken, numberOfUpkeeps, big.NewInt(defaultLinkFunds), defaultUpkeepGasLimit, true, false, false, nil, &config)

consumers = append(consumersConditional, consumersLogTrigger...)
upkeepIDs = append(upkeepidsConditional, upkeepidsLogTrigger...)
Expand Down
1 change: 1 addition & 0 deletions integration-tests/reorg/automation_reorg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ func TestAutomationReorg(t *testing.T) {
false,
false,
a.WETHToken,
&config,
)

if isLogTrigger {
Expand Down
109 changes: 11 additions & 98 deletions integration-tests/smoke/automation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func SetupAutomationBasic(t *testing.T, nodeUpgrade bool) {
isMercury,
isBillingTokenNative,
a.WETHToken,
&cfg,
)

// Do it in two separate loops, so we don't end up setting up one upkeep, but starting the consumer for another one
Expand Down Expand Up @@ -268,20 +269,7 @@ func TestSetUpkeepTriggerConfig(t *testing.T) {
sb, err := a.ChainClient.Client.BlockNumber(context.Background())
require.NoError(t, err, "Failed to get start block")

consumers, upkeepIDs := actions.DeployConsumers(
t,
a.ChainClient,
a.Registry,
a.Registrar,
a.LinkToken,
defaultAmountOfUpkeeps,
big.NewInt(automationDefaultLinkFunds),
automationDefaultUpkeepGasLimit,
true,
false,
false,
nil,
)
consumers, upkeepIDs := actions.DeployConsumers(t, a.ChainClient, a.Registry, a.Registrar, a.LinkToken, defaultAmountOfUpkeeps, big.NewInt(automationDefaultLinkFunds), automationDefaultUpkeepGasLimit, true, false, false, nil, &config)

// Start log trigger based upkeeps for all consumers
for i := 0; i < len(consumers); i++ {
Expand Down Expand Up @@ -451,20 +439,7 @@ func TestAutomationAddFunds(t *testing.T) {
sb, err := a.ChainClient.Client.BlockNumber(context.Background())
require.NoError(t, err, "Failed to get start block")

consumers, upkeepIDs := actions.DeployConsumers(
t,
a.ChainClient,
a.Registry,
a.Registrar,
a.LinkToken,
defaultAmountOfUpkeeps,
big.NewInt(1),
automationDefaultUpkeepGasLimit,
false,
false,
false,
nil,
)
consumers, upkeepIDs := actions.DeployConsumers(t, a.ChainClient, a.Registry, a.Registrar, a.LinkToken, defaultAmountOfUpkeeps, big.NewInt(1), automationDefaultUpkeepGasLimit, false, false, false, nil, &config)

t.Cleanup(func() {
actions.GetStalenessReportCleanupFn(t, a.Logger, a.ChainClient, sb, a.Registry, registryVersion)()
Expand Down Expand Up @@ -531,20 +506,7 @@ func TestAutomationPauseUnPause(t *testing.T) {
sb, err := a.ChainClient.Client.BlockNumber(context.Background())
require.NoError(t, err, "Failed to get start block")

consumers, upkeepIDs := actions.DeployConsumers(
t,
a.ChainClient,
a.Registry,
a.Registrar,
a.LinkToken,
defaultAmountOfUpkeeps,
big.NewInt(automationDefaultLinkFunds),
automationDefaultUpkeepGasLimit,
false,
false,
false,
nil,
)
consumers, upkeepIDs := actions.DeployConsumers(t, a.ChainClient, a.Registry, a.Registrar, a.LinkToken, defaultAmountOfUpkeeps, big.NewInt(automationDefaultLinkFunds), automationDefaultUpkeepGasLimit, false, false, false, nil, &config)

t.Cleanup(func() {
actions.GetStalenessReportCleanupFn(t, a.Logger, a.ChainClient, sb, a.Registry, registryVersion)()
Expand Down Expand Up @@ -632,20 +594,7 @@ func TestAutomationRegisterUpkeep(t *testing.T) {
sb, err := a.ChainClient.Client.BlockNumber(context.Background())
require.NoError(t, err, "Failed to get start block")

consumers, upkeepIDs := actions.DeployConsumers(
t,
a.ChainClient,
a.Registry,
a.Registrar,
a.LinkToken,
defaultAmountOfUpkeeps,
big.NewInt(automationDefaultLinkFunds),
automationDefaultUpkeepGasLimit,
false,
false,
false,
nil,
)
consumers, upkeepIDs := actions.DeployConsumers(t, a.ChainClient, a.Registry, a.Registrar, a.LinkToken, defaultAmountOfUpkeeps, big.NewInt(automationDefaultLinkFunds), automationDefaultUpkeepGasLimit, false, false, false, nil, &config)

t.Cleanup(func() {
actions.GetStalenessReportCleanupFn(t, a.Logger, a.ChainClient, sb, a.Registry, registryVersion)()
Expand Down Expand Up @@ -728,20 +677,7 @@ func TestAutomationPauseRegistry(t *testing.T) {
sb, err := a.ChainClient.Client.BlockNumber(context.Background())
require.NoError(t, err, "Failed to get start block")

consumers, upkeepIDs := actions.DeployConsumers(
t,
a.ChainClient,
a.Registry,
a.Registrar,
a.LinkToken,
defaultAmountOfUpkeeps,
big.NewInt(automationDefaultLinkFunds),
automationDefaultUpkeepGasLimit,
false,
false,
false,
nil,
)
consumers, upkeepIDs := actions.DeployConsumers(t, a.ChainClient, a.Registry, a.Registrar, a.LinkToken, defaultAmountOfUpkeeps, big.NewInt(automationDefaultLinkFunds), automationDefaultUpkeepGasLimit, false, false, false, nil, &config)

t.Cleanup(func() {
actions.GetStalenessReportCleanupFn(t, a.Logger, a.ChainClient, sb, a.Registry, registryVersion)()
Expand Down Expand Up @@ -808,20 +744,7 @@ func TestAutomationKeeperNodesDown(t *testing.T) {
sb, err := a.ChainClient.Client.BlockNumber(context.Background())
require.NoError(t, err, "Failed to get start block")

consumers, upkeepIDs := actions.DeployConsumers(
t,
a.ChainClient,
a.Registry,
a.Registrar,
a.LinkToken,
defaultAmountOfUpkeeps,
big.NewInt(automationDefaultLinkFunds),
automationDefaultUpkeepGasLimit,
false,
false,
false,
nil,
)
consumers, upkeepIDs := actions.DeployConsumers(t, a.ChainClient, a.Registry, a.Registrar, a.LinkToken, defaultAmountOfUpkeeps, big.NewInt(automationDefaultLinkFunds), automationDefaultUpkeepGasLimit, false, false, false, nil, &config)

t.Cleanup(func() {
actions.GetStalenessReportCleanupFn(t, a.Logger, a.ChainClient, sb, a.Registry, registryVersion)()
Expand Down Expand Up @@ -929,6 +852,7 @@ func TestAutomationPerformSimulation(t *testing.T) {
5, // Interval of blocks that upkeeps are expected to be performed
100000, // How much gas should be burned on checkUpkeep() calls
4000000, // How much gas should be burned on performUpkeep() calls. Initially set higher than defaultUpkeepGasLimit
&config,
)

t.Cleanup(func() {
Expand Down Expand Up @@ -1000,6 +924,7 @@ func TestAutomationCheckPerformGasLimit(t *testing.T) {
5, // Interval of blocks that upkeeps are expected to be performed
100000, // How much gas should be burned on checkUpkeep() calls
4000000, // How much gas should be burned on performUpkeep() calls. Initially set higher than defaultUpkeepGasLimit
&config,
)

t.Cleanup(func() {
Expand Down Expand Up @@ -1152,6 +1077,7 @@ func TestUpdateCheckData(t *testing.T) {
big.NewInt(automationDefaultLinkFunds),
automationDefaultUpkeepGasLimit,
[]byte(automationExpectedData),
&config,
)

t.Cleanup(func() {
Expand Down Expand Up @@ -1223,20 +1149,7 @@ func TestSetOffchainConfigWithMaxGasPrice(t *testing.T) {
sb, err := a.ChainClient.Client.BlockNumber(context.Background())
require.NoError(t, err, "Failed to get start block")

consumers, upkeepIDs := actions.DeployConsumers(
t,
a.ChainClient,
a.Registry,
a.Registrar,
a.LinkToken,
defaultAmountOfUpkeeps,
big.NewInt(automationDefaultLinkFunds),
automationDefaultUpkeepGasLimit,
false,
false,
false,
nil,
)
consumers, upkeepIDs := actions.DeployConsumers(t, a.ChainClient, a.Registry, a.Registrar, a.LinkToken, defaultAmountOfUpkeeps, big.NewInt(automationDefaultLinkFunds), automationDefaultUpkeepGasLimit, false, false, false, nil, &config)

t.Cleanup(func() {
actions.GetStalenessReportCleanupFn(t, a.Logger, a.ChainClient, sb, a.Registry, registryVersion)()
Expand Down
15 changes: 1 addition & 14 deletions integration-tests/smoke/log_poller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,20 +306,7 @@ func prepareEnvironment(l zerolog.Logger, t *testing.T, testConfig *tc.TestConfi
logScannerSettings,
)

_, upkeepIDs := actions.DeployConsumers(
t,
chainClient,
registry,
registrar,
linkToken,
upKeepsNeeded,
big.NewInt(int64(9e18)),
uint32(2500000),
true,
false,
false,
nil,
)
_, upkeepIDs := actions.DeployConsumers(t, chainClient, registry, registrar, linkToken, upKeepsNeeded, big.NewInt(int64(9e18)), uint32(2500000), true, false, false, nil, &tc.TestConfig{})

err = logpoller.AssertUpkeepIdsUniqueness(upkeepIDs)
require.NoError(t, err, "Error asserting upkeep ids uniqueness")
Expand Down
Loading

0 comments on commit fd9e98a

Please sign in to comment.