Skip to content

Commit

Permalink
add chaos and reorg tests for v23
Browse files Browse the repository at this point in the history
  • Loading branch information
shileiwill committed Jul 16, 2024
1 parent 68a6a66 commit aaf73cf
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changeset/angry-wolves-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

add chaos and reorg tests #added
77 changes: 65 additions & 12 deletions integration-tests/actions/automation_ocr_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func BuildAutoOCR2ConfigVarsWithKeyIndex(
var offchainConfigVersion uint64
var offchainConfig []byte

if registryConfig.RegistryVersion == ethereum.RegistryVersion_2_1 || registryConfig.RegistryVersion == ethereum.RegistryVersion_2_2 {
if registryConfig.RegistryVersion == ethereum.RegistryVersion_2_1 || registryConfig.RegistryVersion == ethereum.RegistryVersion_2_2 || registryConfig.RegistryVersion == ethereum.RegistryVersion_2_3 {
offC, err = json.Marshal(ocr2keepers30config.OffchainConfig{
TargetProbability: "0.999",
TargetInRounds: 1,
Expand Down Expand Up @@ -169,6 +169,9 @@ func BuildAutoOCR2ConfigVarsWithKeyIndex(
ocrConfig.TypedOnchainConfig21 = registryConfig.Create21OnchainConfig(registrar, registryOwnerAddress)
} 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)
}

l.Info().Msg("Done building OCR config")
Expand All @@ -191,14 +194,14 @@ func CreateOCRKeeperJobs(
bootstrapP2PId := bootstrapP2PIds.Data[0].Attributes.PeerID

var contractVersion string
if registryVersion == ethereum.RegistryVersion_2_2 {
if registryVersion == ethereum.RegistryVersion_2_2 || registryVersion == ethereum.RegistryVersion_2_3 {
contractVersion = "v2.1+"
} else if registryVersion == ethereum.RegistryVersion_2_1 {
contractVersion = "v2.1"
} else if registryVersion == ethereum.RegistryVersion_2_0 {
contractVersion = "v2.0"
} else {
require.FailNow(t, fmt.Sprintf("v2.0, v2.1, and v2.2 are the only supported versions, but got something else: %v (iota)", registryVersion))
require.FailNow(t, fmt.Sprintf("v2.0, v2.1, v2.2 and v2.3 are the only supported versions, but got something else: %v (iota)", registryVersion))
}

bootstrapSpec := &client.OCR2TaskJobSpec{
Expand Down Expand Up @@ -265,9 +268,10 @@ func DeployAutoOCRRegistryAndRegistrar(
registryVersion ethereum.KeeperRegistryVersion,
registrySettings contracts.KeeperRegistrySettings,
linkToken contracts.LinkToken,
wethToken contracts.WETHToken,
) (contracts.KeeperRegistry, contracts.KeeperRegistrar) {
registry := deployRegistry(t, client, registryVersion, registrySettings, linkToken)
registrar := deployRegistrar(t, client, registryVersion, registry, linkToken)
registry := deployRegistry(t, client, registryVersion, registrySettings, linkToken, wethToken)
registrar := deployRegistrar(t, client, registryVersion, registry, linkToken, wethToken)

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

// TODO reorg
func deployRegistrar(
t *testing.T,
client *seth.Client,
registryVersion ethereum.KeeperRegistryVersion,
registry contracts.KeeperRegistry,
linkToken contracts.LinkToken,
wethToken contracts.WETHToken,
) contracts.KeeperRegistrar {
registrarSettings := contracts.KeeperRegistrarSettings{
AutoApproveConfigType: 2,
AutoApproveMaxAllowed: math.MaxUint16,
RegistryAddr: registry.Address(),
MinLinkJuels: big.NewInt(0),
WETHTokenAddr: wethToken.Address(),
}
registrar, err := contracts.DeployKeeperRegistrar(client, registryVersion, linkToken.Address(), registrarSettings)
require.NoError(t, err, "Deploying KeeperRegistrar contract shouldn't fail")
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,
) 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")

registry, err := contracts.DeployKeeperRegistry(
client,
&contracts.KeeperRegistryOpts{
RegistryVersion: registryVersion,
LinkAddr: linkToken.Address(),
ETHFeedAddr: ef.Address(),
GasFeedAddr: gf.Address(),
TranscoderAddr: transcoder.Address(),
RegistrarAddr: ZeroAddress.Hex(),
Settings: registrySettings,
RegistryVersion: registryVersion,
LinkAddr: linkToken.Address(),
ETHFeedAddr: ef.Address(),
GasFeedAddr: gf.Address(),
TranscoderAddr: transcoder.Address(),
RegistrarAddr: ZeroAddress.Hex(),
Settings: registrySettings,
LinkUSDFeedAddr: ethUSDFeed.Address(),
NativeUSDFeedAddr: ethUSDFeed.Address(),
WrappedNativeAddr: wethToken.Address(),
},
)
require.NoError(t, err, "Deploying KeeperRegistry contract shouldn't fail")
Expand Down
1 change: 1 addition & 0 deletions integration-tests/actions/automationv2/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ 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: 8 additions & 1 deletion integration-tests/actions/keeper_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,16 @@ 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
5 changes: 5 additions & 0 deletions integration-tests/chaos/automation_chaos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ 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 @@ -261,12 +262,16 @@ func TestAutomationChaos(t *testing.T) {
linkToken, err := contracts.DeployLinkTokenContract(l, chainClient)
require.NoError(t, err, "Error deploying LINK token")

wethToken, err := contracts.DeployWETHTokenContract(l, chainClient)
require.NoError(t, err, "Error deploying weth token contract")

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

// Fund the registry with LINK
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")
Msg("Transferring and Calling LINK@@ yes")
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
2 changes: 1 addition & 1 deletion integration-tests/contracts/ethereum_keeper_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (rcs *KeeperRegistrySettings) Create23OnchainConfig(registrar string, regis
ChainModule: chainModuleAddress,
ReorgProtectionEnabled: reorgProtectionEnabled,
FinanceAdmin: registryOwnerAddress,
FallbackNativePrice: big.NewInt(1),
FallbackNativePrice: rcs.FallbackLinkPrice, // Just use the LINK price
}
}

Expand Down
24 changes: 16 additions & 8 deletions integration-tests/reorg/automation_reorg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"math/big"
"regexp"
"strconv"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -114,11 +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,
}

for n, rv := range registryVersions {
Expand Down Expand Up @@ -192,12 +195,17 @@ func TestAutomationReorg(t *testing.T) {
linkToken, err := contracts.DeployLinkTokenContract(l, chainClient)
require.NoError(t, err, "Error deploying LINK token")

wethToken, err := contracts.DeployWETHTokenContract(l, chainClient)
require.NoError(t, err, "Error deploying weth token contract")

defaultOCRRegistryConfig.RegistryVersion = registryVersion
registry, registrar := actions.DeployAutoOCRRegistryAndRegistrar(
t,
chainClient,
registryVersion,
defaultOCRRegistryConfig,
linkToken,
wethToken,
)

// Fund the registry with LINK
Expand All @@ -206,18 +214,18 @@ func TestAutomationReorg(t *testing.T) {

actions.CreateOCRKeeperJobs(t, chainlinkNodes, registry.Address(), network.ChainID, 0, registryVersion)
nodesWithoutBootstrap := chainlinkNodes[1:]
defaultOCRRegistryConfig.RegistryVersion = registryVersion

ocrConfig, err := actions.BuildAutoOCR2ConfigVars(t, nodesWithoutBootstrap, defaultOCRRegistryConfig, registrar.Address(), 5*time.Second, registry.ChainModuleAddress(), registry.ReorgProtectionEnabled())
require.NoError(t, err, "OCR2 config should be built successfully")
if registryVersion == ethereum.RegistryVersion_2_0 {
err = registry.SetConfig(defaultOCRRegistryConfig, ocrConfig)
} else {
err = registry.SetConfigTypeSafe(ocrConfig)
}
require.NoError(t, err, "Registry config should be be set successfully")
require.NoError(t, err, "Registry config should be set successfully")

// Use the name to determine if this is a log trigger or not
isLogTrigger := name == "registry_2_1_logtrigger" || name == "registry_2_2_logtrigger"
isLogTrigger := strings.Contains(name, "logtrigger")
consumers, upkeepIDs := actions.DeployConsumers(
t,
chainClient,
Expand All @@ -230,7 +238,7 @@ func TestAutomationReorg(t *testing.T) {
isLogTrigger,
false,
false,
nil,
wethToken,
)

if isLogTrigger {
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/testsetups/keeper_benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ 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,
k.t, k.chainClient, registryVersion, *k.Inputs.KeeperRegistrySettings, k.linkToken, nil,
)

// Fund the registry with LINK
Expand Down
4 changes: 4 additions & 0 deletions integration-tests/universal/log_poller/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,9 @@ func SetupLogPollerTestDocker(
linkToken, err := contracts.DeployLinkTokenContract(l, chainClient)
require.NoError(t, err, "Error deploying LINK token")

wethToken, err := contracts.DeployWETHTokenContract(l, chainClient)
require.NoError(t, err, "Error deploying weth token contract")

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

Expand All @@ -1088,6 +1091,7 @@ func SetupLogPollerTestDocker(
registryVersion,
registryConfig,
linkToken,
wethToken,
)

// Fund the registry with LINK
Expand Down

0 comments on commit aaf73cf

Please sign in to comment.