Skip to content

Commit

Permalink
support benchmark test 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 fc8e283 commit 9e0b552
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 25 deletions.
53 changes: 37 additions & 16 deletions integration-tests/contracts/ethereum_contracts_automation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2702,21 +2702,42 @@ func (v *EthereumAutomationConsumerBenchmark) GetUpkeepCount(ctx context.Context
}, id)
}

// DeployKeeperConsumerBenchmark deploys a keeper consumer benchmark contract with a standard contract backend
func DeployKeeperConsumerBenchmark(client *seth.Client) (AutomationConsumerBenchmark, error) {
return deployKeeperConsumerBenchmarkWithWrapperFn(client, func(client *seth.Client) *wrappers.WrappedContractBackend {
// DeployAutomationConsumerBenchmark deploys a keeper consumer benchmark contract with a standard contract backend
func DeployAutomationConsumerBenchmark(client *seth.Client) (AutomationConsumerBenchmark, error) {
return deployAutomationConsumerBenchmarkWithWrapperFn(client, func(client *seth.Client) *wrappers.WrappedContractBackend {
return wrappers.MustNewWrappedContractBackend(nil, client)
})
}

// DeployKeeperConsumerBenchmarkWithRetry deploys a keeper consumer benchmark contract with a read-only operations retrying contract backend
func DeployKeeperConsumerBenchmarkWithRetry(client *seth.Client, logger zerolog.Logger, maxAttempts uint, retryDelay time.Duration) (AutomationConsumerBenchmark, error) {
return deployKeeperConsumerBenchmarkWithWrapperFn(client, func(client *seth.Client) *wrappers.WrappedContractBackend {
func LoadAutomationConsumerBenchmark(client *seth.Client, address common.Address) (*EthereumAutomationConsumerBenchmark, error) {
abi, err := automation_consumer_benchmark.AutomationConsumerBenchmarkMetaData.GetAbi()
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{
client: client,
consumer: consumer,
address: &address,
}, nil
}

// DeployAutomationConsumerBenchmarkWithRetry deploys a keeper consumer benchmark contract with a read-only operations retrying contract backend
func DeployAutomationConsumerBenchmarkWithRetry(client *seth.Client, logger zerolog.Logger, maxAttempts uint, retryDelay time.Duration) (AutomationConsumerBenchmark, error) {
return deployAutomationConsumerBenchmarkWithWrapperFn(client, func(client *seth.Client) *wrappers.WrappedContractBackend {
return wrappers.MustNewRetryingWrappedContractBackend(client, logger, maxAttempts, retryDelay)
})
}

func deployKeeperConsumerBenchmarkWithWrapperFn(client *seth.Client, wrapperConstrFn func(client *seth.Client) *wrappers.WrappedContractBackend) (AutomationConsumerBenchmark, error) {
func deployAutomationConsumerBenchmarkWithWrapperFn(client *seth.Client, wrapperConstrFn func(client *seth.Client) *wrappers.WrappedContractBackend) (AutomationConsumerBenchmark, error) {
abi, err := automation_consumer_benchmark.AutomationConsumerBenchmarkMetaData.GetAbi()
if err != nil {
return &EthereumAutomationConsumerBenchmark{}, fmt.Errorf("failed to get AutomationConsumerBenchmark ABI: %w", err)
Expand All @@ -2738,8 +2759,8 @@ func deployKeeperConsumerBenchmarkWithWrapperFn(client *seth.Client, wrapperCons
}, nil
}

// KeeperConsumerBenchmarkUpkeepObserver is a header subscription that awaits for a round of upkeeps
type KeeperConsumerBenchmarkUpkeepObserver struct {
// AutomationConsumerBenchmarkUpkeepObserver is a header subscription that awaits for a round of upkeeps
type AutomationConsumerBenchmarkUpkeepObserver struct {
instance AutomationConsumerBenchmark
registry KeeperRegistry
upkeepID *big.Int
Expand All @@ -2763,9 +2784,9 @@ type KeeperConsumerBenchmarkUpkeepObserver struct {
l zerolog.Logger
}

// NewKeeperConsumerBenchmarkUpkeepObserver provides a new instance of a NewKeeperConsumerBenchmarkUpkeepObserver
// NewAutomationConsumerBenchmarkUpkeepObserver provides a new instance of a NewAutomationConsumerBenchmarkUpkeepObserver
// Used to track and log benchmark test results for keepers
func NewKeeperConsumerBenchmarkUpkeepObserver(
func NewAutomationConsumerBenchmarkUpkeepObserver(
contract AutomationConsumerBenchmark,
registry KeeperRegistry,
upkeepID *big.Int,
Expand All @@ -2775,8 +2796,8 @@ func NewKeeperConsumerBenchmarkUpkeepObserver(
upkeepIndex int64,
firstEligibleBuffer int64,
logger zerolog.Logger,
) *KeeperConsumerBenchmarkUpkeepObserver {
return &KeeperConsumerBenchmarkUpkeepObserver{
) *AutomationConsumerBenchmarkUpkeepObserver {
return &AutomationConsumerBenchmarkUpkeepObserver{
instance: contract,
registry: registry,
upkeepID: upkeepID,
Expand All @@ -2798,7 +2819,7 @@ func NewKeeperConsumerBenchmarkUpkeepObserver(

// ReceiveHeader will query the latest Keeper round and check to see whether upkeep was performed, it returns
// true when observation has finished.
func (o *KeeperConsumerBenchmarkUpkeepObserver) ReceiveHeader(receivedHeader *blockchain.SafeEVMHeader) (bool, error) {
func (o *AutomationConsumerBenchmarkUpkeepObserver) ReceiveHeader(receivedHeader *blockchain.SafeEVMHeader) (bool, error) {
if receivedHeader.Number.Uint64() <= o.lastBlockNum { // Uncle / reorg we won't count
return false, nil
}
Expand Down Expand Up @@ -2901,12 +2922,12 @@ func (o *KeeperConsumerBenchmarkUpkeepObserver) ReceiveHeader(receivedHeader *bl
}

// Complete returns whether watching for upkeeps has completed
func (o *KeeperConsumerBenchmarkUpkeepObserver) Complete() bool {
func (o *AutomationConsumerBenchmarkUpkeepObserver) Complete() bool {
return o.complete
}

// LogDetails logs the results of the benchmark test to testreporter
func (o *KeeperConsumerBenchmarkUpkeepObserver) LogDetails() {
func (o *AutomationConsumerBenchmarkUpkeepObserver) LogDetails() {
report := testreporters.KeeperBenchmarkTestReport{
ContractAddress: o.instance.Address(),
TotalEligibleCount: o.countEligible,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (k *KeeperBenchmarkTest) Setup(env *environment.Environment, config testcon
a.SetupAutomationDeploymentWithoutJobs(k.t)
err = a.SetConfigOnRegistry()
require.NoError(k.t, err, "Setting initial config on registry shouldn't fail")
k.DeployBenchmarkKeeperContracts(index, a)
k.SetupBenchmarkKeeperContracts(index, a)
}

var keysToFund = inputs.RegistryVersions
Expand Down Expand Up @@ -303,7 +303,7 @@ func (k *KeeperBenchmarkTest) Run() {
startedObservations.Add(1)
k.log.Info().Int("Channel index", chIndex).Str("UpkeepID", upkeepIDCopy.String()).Msg("Starting upkeep observation")

confirmer := contracts.NewKeeperConsumerBenchmarkUpkeepObserver(
confirmer := contracts.NewAutomationConsumerBenchmarkUpkeepObserver(
k.keeperConsumerContracts[registryIndex],
k.keeperRegistries[registryIndex],
upkeepIDCopy,
Expand Down Expand Up @@ -652,16 +652,24 @@ func (k *KeeperBenchmarkTest) SendSlackNotification(slackClient *slack.Client, c
return err
}

// DeployBenchmarkKeeperContracts deploys a set amount of keeper Benchmark contracts registered to a single registry
func (k *KeeperBenchmarkTest) DeployBenchmarkKeeperContracts(index int, a *automationv2.AutomationTest) {
// SetupBenchmarkKeeperContracts deploys a set amount of keeper Benchmark contracts registered to a single registry
func (k *KeeperBenchmarkTest) SetupBenchmarkKeeperContracts(index int, a *automationv2.AutomationTest) {
registryVersion := k.Inputs.RegistryVersions[index]
k.Inputs.KeeperRegistrySettings.RegistryVersion = registryVersion
upkeep := k.Inputs.Upkeeps
var (
err error
)

consumer := k.DeployKeeperConsumersBenchmark()
var consumer contracts.AutomationConsumerBenchmark
if a.TestConfig.GetAutomationConfig().UseExistingUpkeepContracts() {
benchmarkAddresses, err := a.TestConfig.GetAutomationConfig().UpkeepContractAddresses()
require.NoError(k.t, err, "Getting upkeep contract addresses shouldn't fail")
consumer, err = contracts.LoadAutomationConsumerBenchmark(k.chainClient, benchmarkAddresses[0])
require.NoError(k.t, err, "Loading KeeperConsumerBenchmark shouldn't fail")
} else {
consumer = k.DeployKeeperConsumersBenchmark()
}

var upkeepAddresses []string

Expand Down Expand Up @@ -731,17 +739,17 @@ func (k *KeeperBenchmarkTest) DeployKeeperConsumersBenchmark() contracts.Automat
if *k.testConfig.GetAutomationConfig().Resiliency.ContractCallLimit != 0 && k.testConfig.GetAutomationConfig().Resiliency.ContractCallInterval.Duration != 0 {
maxRetryAttempts := *k.testConfig.GetAutomationConfig().Resiliency.ContractCallLimit
callRetryDelay := k.testConfig.GetAutomationConfig().Resiliency.ContractCallInterval.Duration
keeperConsumerInstance, err = contracts.DeployKeeperConsumerBenchmarkWithRetry(k.chainClient, k.log, maxRetryAttempts, callRetryDelay)
keeperConsumerInstance, err = contracts.DeployAutomationConsumerBenchmarkWithRetry(k.chainClient, k.log, maxRetryAttempts, callRetryDelay)
if err != nil {
k.log.Error().Err(err).Msg("Deploying AutomationConsumerBenchmark instance shouldn't fail")
keeperConsumerInstance, err = contracts.DeployKeeperConsumerBenchmarkWithRetry(k.chainClient, k.log, maxRetryAttempts, callRetryDelay)
keeperConsumerInstance, err = contracts.DeployAutomationConsumerBenchmarkWithRetry(k.chainClient, k.log, maxRetryAttempts, callRetryDelay)
require.NoError(k.t, err, "Error deploying AutomationConsumerBenchmark")
}
} else {
keeperConsumerInstance, err = contracts.DeployKeeperConsumerBenchmark(k.chainClient)
keeperConsumerInstance, err = contracts.DeployAutomationConsumerBenchmark(k.chainClient)
if err != nil {
k.log.Error().Err(err).Msg("Deploying AutomationConsumerBenchmark instance %d shouldn't fail")
keeperConsumerInstance, err = contracts.DeployKeeperConsumerBenchmark(k.chainClient)
keeperConsumerInstance, err = contracts.DeployAutomationConsumerBenchmark(k.chainClient)
require.NoError(k.t, err, "Error deploying AutomationConsumerBenchmark")
}
}
Expand Down

0 comments on commit 9e0b552

Please sign in to comment.