Skip to content

Commit

Permalink
updates for reorg test
Browse files Browse the repository at this point in the history
  • Loading branch information
shileiwill committed Jul 18, 2024
1 parent aaf73cf commit ac20d5d
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 73 deletions.
82 changes: 36 additions & 46 deletions integration-tests/actions/automation_ocr_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/pkg/errors"
"github.com/smartcontractkit/seth"

"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/i_automation_registry_master_wrapper_2_3"

"github.com/ethereum/go-ethereum/common"
"github.com/lib/pq"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -41,8 +43,12 @@ func BuildAutoOCR2ConfigVars(
deltaStage time.Duration,
chainModuleAddress common.Address,
reorgProtectionEnabled bool,
linkToken contracts.LinkToken,
wethToken contracts.WETHToken,
ethUSDFeed contracts.MockETHUSDFeed,

) (contracts.OCRv2Config, error) {
return BuildAutoOCR2ConfigVarsWithKeyIndex(t, chainlinkNodes, registryConfig, registrar, deltaStage, 0, common.Address{}, chainModuleAddress, reorgProtectionEnabled)
return BuildAutoOCR2ConfigVarsWithKeyIndex(t, chainlinkNodes, registryConfig, registrar, deltaStage, 0, common.Address{}, chainModuleAddress, reorgProtectionEnabled, linkToken, wethToken, ethUSDFeed)
}

func BuildAutoOCR2ConfigVarsWithKeyIndex(
Expand All @@ -55,6 +61,9 @@ func BuildAutoOCR2ConfigVarsWithKeyIndex(
registryOwnerAddress common.Address,
chainModuleAddress common.Address,
reorgProtectionEnabled bool,
linkToken contracts.LinkToken,
wethToken contracts.WETHToken,
ethUSDFeed contracts.MockETHUSDFeed,
) (contracts.OCRv2Config, error) {
l := logging.GetTestLogger(t)
S, oracleIdentities, err := GetOracleIdentitiesWithKeyIndex(chainlinkNodes, keyIndex)
Expand Down Expand Up @@ -170,8 +179,30 @@ func BuildAutoOCR2ConfigVarsWithKeyIndex(
} else if registryConfig.RegistryVersion == ethereum.RegistryVersion_2_2 {
ocrConfig.TypedOnchainConfig22 = registryConfig.Create22OnchainConfig(registrar, registryOwnerAddress, chainModuleAddress, reorgProtectionEnabled)
} else if registryConfig.RegistryVersion == ethereum.RegistryVersion_2_3 {
l.Info().Msg("=====================Done building OCR v23 config")
ocrConfig.TypedOnchainConfig23 = registryConfig.Create23OnchainConfig(registrar, registryOwnerAddress, chainModuleAddress, reorgProtectionEnabled)
ocrConfig.BillingTokens = []common.Address{
common.HexToAddress(linkToken.Address()),
common.HexToAddress(wethToken.Address()),
}

ocrConfig.BillingConfigs = []i_automation_registry_master_wrapper_2_3.AutomationRegistryBase23BillingConfig{
{
GasFeePPB: 100,
FlatFeeMilliCents: big.NewInt(500),
PriceFeed: common.HexToAddress(ethUSDFeed.Address()), // ETH/USD feed and LINK/USD feed are the same
Decimals: 18,
FallbackPrice: big.NewInt(1000),
MinSpend: big.NewInt(200),
},
{
GasFeePPB: 100,
FlatFeeMilliCents: big.NewInt(500),
PriceFeed: common.HexToAddress(ethUSDFeed.Address()), // ETH/USD feed and LINK/USD feed are the same
Decimals: 18,
FallbackPrice: big.NewInt(1000),
MinSpend: big.NewInt(200),
},
}
}

l.Info().Msg("Done building OCR config")
Expand Down Expand Up @@ -269,8 +300,9 @@ func DeployAutoOCRRegistryAndRegistrar(
registrySettings contracts.KeeperRegistrySettings,
linkToken contracts.LinkToken,
wethToken contracts.WETHToken,
ethUSDFeed contracts.MockETHUSDFeed,
) (contracts.KeeperRegistry, contracts.KeeperRegistrar) {
registry := deployRegistry(t, client, registryVersion, registrySettings, linkToken, wethToken)
registry := deployRegistry(t, client, registryVersion, registrySettings, linkToken, wethToken, ethUSDFeed)
registrar := deployRegistrar(t, client, registryVersion, registry, linkToken, wethToken)

return registry, registrar
Expand Down Expand Up @@ -377,7 +409,6 @@ func DeployMultiCallAndFundDeploymentAddresses(
return SendLinkFundsToDeploymentAddresses(chainClient, concurrency, numberOfUpkeeps, operationsPerAddress, multicallAddress, linkFundsForEachUpkeep, linkToken)
}

// TODO reorg
func deployRegistrar(
t *testing.T,
client *seth.Client,
Expand All @@ -398,61 +429,20 @@ func deployRegistrar(
return registrar
}

//func (a *AutomationTest) DeployRegistrar() error {
// if a.Registry == nil {
// return fmt.Errorf("registry must be deployed or loaded before registrar")
// }
// a.RegistrarSettings.RegistryAddr = a.Registry.Address()
// a.RegistrarSettings.WETHTokenAddr = a.WETHToken.Address()
// registrar, err := contracts.DeployKeeperRegistrar(a.ChainClient, a.RegistrySettings.RegistryVersion, a.LinkToken.Address(), a.RegistrarSettings)
// if err != nil {
// return err
// }
// a.Registrar = registrar
// return nil
//}

// TODO remove
//func (a *AutomationTest) DeployRegistry() error {
// registryOpts := &contracts.KeeperRegistryOpts{
// RegistryVersion: a.RegistrySettings.RegistryVersion,
// LinkAddr: a.LinkToken.Address(),
// ETHFeedAddr: a.EthLinkFeed.Address(),
// GasFeedAddr: a.GasFeed.Address(),
// TranscoderAddr: a.Transcoder.Address(),
// RegistrarAddr: utils.ZeroAddress.Hex(),
// Settings: a.RegistrySettings,
// LinkUSDFeedAddr: a.EthUSDFeed.Address(),
// NativeUSDFeedAddr: a.EthUSDFeed.Address(),
// WrappedNativeAddr: a.WETHToken.Address(),
// }
// registry, err := contracts.DeployKeeperRegistry(a.ChainClient, registryOpts)
// if err != nil {
// return err
// }
// a.Registry = registry
// return nil
//}

// TODO
func deployRegistry(
t *testing.T,
client *seth.Client,
registryVersion ethereum.KeeperRegistryVersion,
registrySettings contracts.KeeperRegistrySettings,
linkToken contracts.LinkToken,
wethToken contracts.WETHToken,
ethUSDFeed contracts.MockETHUSDFeed,
) contracts.KeeperRegistry {
ef, err := contracts.DeployMockETHLINKFeed(client, big.NewInt(2e18))
require.NoError(t, err, "Deploying mock ETH-Link feed shouldn't fail")
gf, err := contracts.DeployMockGASFeed(client, big.NewInt(2e11))
require.NoError(t, err, "Deploying mock gas feed shouldn't fail")

//l := logging.GetTestLogger(t)
// This feed is used for both eth/usd and link/usd
ethUSDFeed, err := contracts.DeployMockETHUSDFeed(client, registrySettings.FallbackLinkPrice)
require.NoError(t, err, "Error deploying eth usd feed contract")

// Deploy the transcoder here, and then set it to the registry
transcoder, err := contracts.DeployUpkeepTranscoder(client)
require.NoError(t, err, "Deploying upkeep transcoder shouldn't fail")
Expand Down
1 change: 0 additions & 1 deletion integration-tests/actions/automationv2/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,6 @@ func (r registrationResult) GetResult() common.Hash {
}

func (a *AutomationTest) RegisterUpkeeps(upkeepConfigs []UpkeepConfig, maxConcurrency int) ([]common.Hash, error) {
a.Logger.Info().Msg("=======do you ever come to this RegisterUpkeeps in actions.go, no")
concurrency, err := actions.GetAndAssertCorrectConcurrency(a.ChainClient, 1)
if err != nil {
return nil, err
Expand Down
9 changes: 1 addition & 8 deletions integration-tests/actions/keeper_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,16 +356,9 @@ func RegisterUpkeepContractsWithCheckData(t *testing.T, client *seth.Client, lin
return
}

l.Info().
Str("registrar.Address()", registrar.Address()).
Str("fundsForEachUpkeep", fundsForEachUpkeep.String()).
Msg("Found upkeepId in tx hash")
l.Info().Msg("=======do you ever come to this keeper_helpers.go,yes")

tx, err = linkToken.TransferAndCallFromKey(registrar.Address(), fundsForEachUpkeep, req, keyNum)
// TODO this is the error
if err != nil {
errorCh <- errors.Wrapf(err, "[id: %s] Failed to register upkeep at@@ %s", id, config.address)
errorCh <- errors.Wrapf(err, "[id: %s] Failed to register upkeep at %s", id, config.address)
return
}
}
Expand Down
8 changes: 6 additions & 2 deletions integration-tests/chaos/automation_chaos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ func TestAutomationChaos(t *testing.T) {
"registry_2_0": eth_contracts.RegistryVersion_2_0,
"registry_2_1": eth_contracts.RegistryVersion_2_1,
"registry_2_2": eth_contracts.RegistryVersion_2_2,
"registry_2_3": eth_contracts.RegistryVersion_2_3,
}

for name, registryVersion := range registryVersions {
Expand Down Expand Up @@ -265,13 +264,18 @@ func TestAutomationChaos(t *testing.T) {
wethToken, err := contracts.DeployWETHTokenContract(l, chainClient)
require.NoError(t, err, "Error deploying weth token contract")

// This feed is used for both eth/usd and link/usd
ethUSDFeed, err := contracts.DeployMockETHUSDFeed(chainClient, defaultOCRRegistryConfig.FallbackLinkPrice)
require.NoError(t, err, "Error deploying eth usd feed contract")

registry, registrar := actions.DeployAutoOCRRegistryAndRegistrar(
t,
chainClient,
rv,
defaultOCRRegistryConfig,
linkToken,
wethToken,
ethUSDFeed,
)

// Fund the registry with LINK
Expand All @@ -281,7 +285,7 @@ func TestAutomationChaos(t *testing.T) {
actions.CreateOCRKeeperJobs(t, chainlinkNodes, registry.Address(), network.ChainID, 0, rv)
nodesWithoutBootstrap := chainlinkNodes[1:]
defaultOCRRegistryConfig.RegistryVersion = rv
ocrConfig, err := actions.BuildAutoOCR2ConfigVars(t, nodesWithoutBootstrap, defaultOCRRegistryConfig, registrar.Address(), 30*time.Second, registry.ChainModuleAddress(), registry.ReorgProtectionEnabled())
ocrConfig, err := actions.BuildAutoOCR2ConfigVars(t, nodesWithoutBootstrap, defaultOCRRegistryConfig, registrar.Address(), 30*time.Second, registry.ChainModuleAddress(), registry.ReorgProtectionEnabled(), linkToken, wethToken, ethUSDFeed)
require.NoError(t, err, "Error building OCR config vars")

if rv == eth_contracts.RegistryVersion_2_0 {
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/contracts/ethereum_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ func (l *EthereumLinkToken) TransferAndCallFromKey(to string, amount *big.Int, d
Str("From", l.client.Addresses[keyNum].Hex()).
Str("To", to).
Str("Amount", amount.String()).
Msg("Transferring and Calling LINK@@ yes")
Msg("Transferring and Calling LINK")
decodedTx, err := l.client.Decode(l.instance.TransferAndCall(l.client.NewTXKeyOpts(keyNum), common.HexToAddress(to), amount, data))
if err != nil {
return nil, err
Expand Down
19 changes: 12 additions & 7 deletions integration-tests/reorg/automation_reorg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ func TestAutomationReorg(t *testing.T) {
l := logging.GetTestLogger(t)

registryVersions := map[string]ethereum.KeeperRegistryVersion{
//"registry_2_0": ethereum.RegistryVersion_2_0,
//"registry_2_1_conditional": ethereum.RegistryVersion_2_1,
//"registry_2_1_logtrigger": ethereum.RegistryVersion_2_1,
"registry_2_0": ethereum.RegistryVersion_2_0,
"registry_2_1_conditional": ethereum.RegistryVersion_2_1,
"registry_2_1_logtrigger": ethereum.RegistryVersion_2_1,
"registry_2_2_conditional": ethereum.RegistryVersion_2_2, // Works only on Chainlink Node v2.10.0 or greater
//"registry_2_2_logtrigger": ethereum.RegistryVersion_2_2, // Works only on Chainlink Node v2.10.0 or greater
"registry_2_2_logtrigger": ethereum.RegistryVersion_2_2, // Works only on Chainlink Node v2.10.0 or greater
"registry_2_3_conditional": ethereum.RegistryVersion_2_3,
//"registry_2_3_logtrigger": ethereum.RegistryVersion_2_3,
"registry_2_3_logtrigger": ethereum.RegistryVersion_2_3,
}

for n, rv := range registryVersions {
Expand Down Expand Up @@ -198,6 +198,10 @@ func TestAutomationReorg(t *testing.T) {
wethToken, err := contracts.DeployWETHTokenContract(l, chainClient)
require.NoError(t, err, "Error deploying weth token contract")

// This feed is used for both eth/usd and link/usd
ethUSDFeed, err := contracts.DeployMockETHUSDFeed(chainClient, defaultOCRRegistryConfig.FallbackLinkPrice)
require.NoError(t, err, "Error deploying eth usd feed contract")

defaultOCRRegistryConfig.RegistryVersion = registryVersion
registry, registrar := actions.DeployAutoOCRRegistryAndRegistrar(
t,
Expand All @@ -206,6 +210,7 @@ func TestAutomationReorg(t *testing.T) {
defaultOCRRegistryConfig,
linkToken,
wethToken,
ethUSDFeed,
)

// Fund the registry with LINK
Expand All @@ -215,7 +220,7 @@ func TestAutomationReorg(t *testing.T) {
actions.CreateOCRKeeperJobs(t, chainlinkNodes, registry.Address(), network.ChainID, 0, registryVersion)
nodesWithoutBootstrap := chainlinkNodes[1:]

ocrConfig, err := actions.BuildAutoOCR2ConfigVars(t, nodesWithoutBootstrap, defaultOCRRegistryConfig, registrar.Address(), 5*time.Second, registry.ChainModuleAddress(), registry.ReorgProtectionEnabled())
ocrConfig, err := actions.BuildAutoOCR2ConfigVars(t, nodesWithoutBootstrap, defaultOCRRegistryConfig, registrar.Address(), 5*time.Second, registry.ChainModuleAddress(), registry.ReorgProtectionEnabled(), linkToken, wethToken, ethUSDFeed)
require.NoError(t, err, "OCR2 config should be built successfully")
if registryVersion == ethereum.RegistryVersion_2_0 {
err = registry.SetConfig(defaultOCRRegistryConfig, ocrConfig)
Expand Down Expand Up @@ -289,7 +294,7 @@ func TestAutomationReorg(t *testing.T) {
g.Expect(counter.Int64()).Should(gomega.BeNumerically(">=", int64(expect)),
"Expected consumer counter to be greater than %d, but got %d", expect, counter.Int64())
}
}, "5m", "1s").Should(gomega.Succeed())
}, "7m", "1s").Should(gomega.Succeed())
})
}
}
7 changes: 4 additions & 3 deletions integration-tests/testsetups/keeper_benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,9 @@ func (k *KeeperBenchmarkTest) Run() {
txKeyId = 0
}
kr := k.keeperRegistries[rIndex]
// TODO: need to add the LINK, WETH and WETH/USD feed to support v23
ocrConfig, err := actions.BuildAutoOCR2ConfigVarsWithKeyIndex(
k.t, nodesWithoutBootstrap, *inputs.KeeperRegistrySettings, kr.Address(), k.Inputs.DeltaStage, txKeyId, common.Address{}, kr.ChainModuleAddress(), kr.ReorgProtectionEnabled(),
k.t, nodesWithoutBootstrap, *inputs.KeeperRegistrySettings, kr.Address(), k.Inputs.DeltaStage, txKeyId, common.Address{}, kr.ChainModuleAddress(), kr.ReorgProtectionEnabled(), nil, nil, nil,
)
require.NoError(k.t, err, "Building OCR config shouldn't fail")

Expand Down Expand Up @@ -730,13 +731,13 @@ func (k *KeeperBenchmarkTest) DeployBenchmarkKeeperContracts(index int) {
require.NoError(k.t, err, "Funding keeper registrar contract shouldn't fail")
} else { // OCR automation - v2.X
registry, registrar = actions.DeployAutoOCRRegistryAndRegistrar(
k.t, k.chainClient, registryVersion, *k.Inputs.KeeperRegistrySettings, k.linkToken, nil,
k.t, k.chainClient, registryVersion, *k.Inputs.KeeperRegistrySettings, k.linkToken, nil, nil,
)

// Fund the registry with LINK
err := k.linkToken.Transfer(registry.Address(), big.NewInt(0).Mul(big.NewInt(1e18), big.NewInt(int64(k.Inputs.Upkeeps.NumberOfUpkeeps))))
require.NoError(k.t, err, "Funding keeper registry contract shouldn't fail")
ocrConfig, err := actions.BuildAutoOCR2ConfigVars(k.t, k.chainlinkNodes[1:], *k.Inputs.KeeperRegistrySettings, registrar.Address(), k.Inputs.DeltaStage, registry.ChainModuleAddress(), registry.ReorgProtectionEnabled())
ocrConfig, err := actions.BuildAutoOCR2ConfigVars(k.t, k.chainlinkNodes[1:], *k.Inputs.KeeperRegistrySettings, registrar.Address(), k.Inputs.DeltaStage, registry.ChainModuleAddress(), registry.ReorgProtectionEnabled(), nil, nil, nil)
require.NoError(k.t, err, "Building OCR config shouldn't fail")
k.log.Debug().Interface("KeeperRegistrySettings", *k.Inputs.KeeperRegistrySettings).Interface("OCRConfig", ocrConfig).Msg("Config")
require.NoError(k.t, err, "Error building OCR config vars")
Expand Down
14 changes: 9 additions & 5 deletions integration-tests/universal/log_poller/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,24 @@ import (
"testing"
"time"

"github.com/jmoiron/sqlx"
"github.com/smartcontractkit/seth"
"github.com/smartcontractkit/wasp"

geth "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
geth_types "github.com/ethereum/go-ethereum/core/types"
"github.com/jmoiron/sqlx"
"github.com/rs/zerolog"
"github.com/scylladb/go-reflectx"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/seth"
"github.com/smartcontractkit/wasp"

"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
ctf_concurrency "github.com/smartcontractkit/chainlink-testing-framework/concurrency"
ctf_test_env "github.com/smartcontractkit/chainlink-testing-framework/docker/test_env"
"github.com/smartcontractkit/chainlink-testing-framework/logging"
"github.com/smartcontractkit/chainlink-testing-framework/networks"
seth_utils "github.com/smartcontractkit/chainlink-testing-framework/utils/seth"

"github.com/smartcontractkit/chainlink/integration-tests/actions"
"github.com/smartcontractkit/chainlink/integration-tests/client"
"github.com/smartcontractkit/chainlink/integration-tests/contracts"
Expand Down Expand Up @@ -1075,6 +1074,10 @@ func SetupLogPollerTestDocker(
wethToken, err := contracts.DeployWETHTokenContract(l, chainClient)
require.NoError(t, err, "Error deploying weth token contract")

// This feed is used for both eth/usd and link/usd
ethUSDFeed, err := contracts.DeployMockETHUSDFeed(chainClient, registryConfig.FallbackLinkPrice)
require.NoError(t, err, "Error deploying eth usd feed contract")

linkBalance, err := linkToken.BalanceOf(context.Background(), chainClient.MustGetRootKeyAddress().Hex())
require.NoError(t, err, "Error getting LINK balance")

Expand All @@ -1092,6 +1095,7 @@ func SetupLogPollerTestDocker(
registryConfig,
linkToken,
wethToken,
ethUSDFeed,
)

// Fund the registry with LINK
Expand Down

0 comments on commit ac20d5d

Please sign in to comment.