Skip to content

Commit

Permalink
update Smoke Test TestAutomationBasic to load pre-deployed contracts …
Browse files Browse the repository at this point in the history
…if given (#14537)
  • Loading branch information
anirudhwarrier authored Sep 24, 2024
1 parent 0e32c07 commit ae53758
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 12 deletions.
2 changes: 1 addition & 1 deletion integration-tests/actions/automation_ocr_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func DeployConsumers(t *testing.T, chainClient *seth.Client, registry contracts.
require.NoError(t, err, "Sending link funds to deployment addresses shouldn't fail")
}

upkeeps := DeployKeeperConsumers(t, chainClient, numberOfUpkeeps, isLogTrigger, isMercury)
upkeeps := SetupKeeperConsumers(t, chainClient, numberOfUpkeeps, isLogTrigger, isMercury, config)
require.Equal(t, numberOfUpkeeps, len(upkeeps), "Number of upkeeps should match")
var upkeepsAddresses []string
for _, upkeep := range upkeeps {
Expand Down
29 changes: 29 additions & 0 deletions 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"

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

"github.com/ethereum/go-ethereum/core/types"
"github.com/google/uuid"
"github.com/pkg/errors"
Expand Down Expand Up @@ -456,6 +458,33 @@ func DeployKeeperConsumers(t *testing.T, client *seth.Client, numberOfContracts
return results
}

// SetupKeeperConsumers concurrently loads or deploys keeper consumer contracts. It requires at least 1 ephemeral key to be present in Seth config.
func SetupKeeperConsumers(t *testing.T, client *seth.Client, numberOfContracts int, isLogTrigger bool, isMercury bool, config tt.AutomationTestConfig) []contracts.KeeperConsumer {
l := logging.GetTestLogger(t)

var results []contracts.KeeperConsumer

if config.GetAutomationConfig().UseExistingUpkeepContracts() {
contractsLoaded, err := config.GetAutomationConfig().UpkeepContractAddresses()
require.NoError(t, err, "Failed to get upkeep contract addresses")
require.Equal(t, numberOfContracts, len(contractsLoaded), "Incorrect number of Keeper Consumer Contracts loaded")
l.Info().Int("Number of Contracts", numberOfContracts).Msg("Loading upkeep contracts from config")
// Load existing contracts
for i := 0; i < numberOfContracts; i++ {
require.NoError(t, err, "Failed to get upkeep contract addresses")
contract, err := contracts.LoadKeeperConsumer(client, contractsLoaded[i])
require.NoError(t, err, "Failed to load keeper consumer contract")
l.Info().Str("Contract Address", contract.Address()).Int("Number", i+1).Int("Out Of", numberOfContracts).Msg("Loaded Keeper Consumer Contract")
results = append(results, contract)
}
} else {
// Deploy new contracts
return DeployKeeperConsumers(t, client, numberOfContracts, isLogTrigger, isMercury)
}

return results
}

// DeployKeeperConsumersPerformance sequentially deploys keeper performance consumer contracts.
func DeployKeeperConsumersPerformance(
t *testing.T,
Expand Down
51 changes: 40 additions & 11 deletions integration-tests/contracts/ethereum_contracts_automation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2265,6 +2265,42 @@ func LoadKeeperRegistrar(client *seth.Client, address common.Address, registryVe
return &EthereumKeeperRegistrar{}, fmt.Errorf("unsupported registry version: %v", registryVersion)
}

type EthereumAutomationKeeperConsumer struct {
client *seth.Client
consumer *log_upkeep_counter_wrapper.LogUpkeepCounter
address *common.Address
}

func (e EthereumAutomationKeeperConsumer) Address() string {
return e.address.Hex()
}

func (e EthereumAutomationKeeperConsumer) Counter(ctx context.Context) (*big.Int, error) {
return e.consumer.Counter(&bind.CallOpts{
From: e.client.MustGetRootKeyAddress(),
Context: ctx,
})
}

func (e EthereumAutomationKeeperConsumer) Start() error {
_, err := e.client.Decode(e.consumer.Start(e.client.NewTXOpts()))
return err
}

func LoadKeeperConsumer(client *seth.Client, address common.Address) (*EthereumAutomationKeeperConsumer, error) {
loader := seth.NewContractLoader[log_upkeep_counter_wrapper.LogUpkeepCounter](client)
instance, err := loader.LoadContract("KeeperConsumer", address, log_upkeep_counter_wrapper.LogUpkeepCounterMetaData.GetAbi, log_upkeep_counter_wrapper.NewLogUpkeepCounter)
if err != nil {
return &EthereumAutomationKeeperConsumer{}, fmt.Errorf("failed to load KeeperConsumerMetaData instance: %w", err)
}

return &EthereumAutomationKeeperConsumer{
client: client,
consumer: instance,
address: &address,
}, nil
}

type EthereumAutomationLogTriggeredStreamsLookupUpkeepConsumer struct {
client *seth.Client
consumer *log_triggered_streams_lookup_wrapper.LogTriggeredStreamsLookup
Expand Down Expand Up @@ -2723,22 +2759,15 @@ func DeployAutomationConsumerBenchmark(client *seth.Client) (AutomationConsumerB
}

func LoadAutomationConsumerBenchmark(client *seth.Client, address common.Address) (*EthereumAutomationConsumerBenchmark, error) {
abi, err := automation_consumer_benchmark.AutomationConsumerBenchmarkMetaData.GetAbi()
loader := seth.NewContractLoader[automation_consumer_benchmark.AutomationConsumerBenchmark](client)
instance, err := loader.LoadContract("AutomationConsumerBenchmark", address, automation_consumer_benchmark.AutomationConsumerBenchmarkMetaData.GetAbi, automation_consumer_benchmark.NewAutomationConsumerBenchmark)
if err != nil {
return &EthereumAutomationConsumerBenchmark{}, fmt.Errorf("failed to get AutomationConsumerBenchmark token ABI: %w", err)
}

client.ContractStore.AddABI("AutomationConsumerBenchmark", *abi)
client.ContractStore.AddBIN("AutomationConsumerBenchmark", common.FromHex(automation_consumer_benchmark.AutomationConsumerBenchmarkMetaData.Bin))

consumer, err := automation_consumer_benchmark.NewAutomationConsumerBenchmark(address, wrappers.MustNewWrappedContractBackend(nil, client))
if err != nil {
return &EthereumAutomationConsumerBenchmark{}, fmt.Errorf("failed to instantiate EthereumAutomationConsumerBenchmark instance: %w", err)
return &EthereumAutomationConsumerBenchmark{}, fmt.Errorf("failed to load AutomationConsumerBenchmark instance: %w", err)
}

return &EthereumAutomationConsumerBenchmark{
client: client,
consumer: consumer,
consumer: instance,
address: &address,
}, nil
}
Expand Down

0 comments on commit ae53758

Please sign in to comment.