From c476fa8529ced3d3522aa2c51aa444315167a818 Mon Sep 17 00:00:00 2001 From: vla33 <104577198+vla33@users.noreply.github.com> Date: Thu, 16 Jun 2022 20:29:42 +0300 Subject: [PATCH] Implemented integration test which removes one keeper node (#6800) * Implemented the new test case * Addressed PR comments * Using %s for big ints instead of %d --- integration-tests/smoke/keeper_test.go | 48 ++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/integration-tests/smoke/keeper_test.go b/integration-tests/smoke/keeper_test.go index c37b8bb7c71..fa9457abbbe 100644 --- a/integration-tests/smoke/keeper_test.go +++ b/integration-tests/smoke/keeper_test.go @@ -5,6 +5,7 @@ import ( "context" "fmt" "math/big" + "strconv" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -28,6 +29,7 @@ const ( CheckPerformGasLimitTest RegisterUpkeepTest AddFundsToUpkeepTest + RemovingKeeperTest ) type KeeperConsumerContracts int32 @@ -49,6 +51,8 @@ var _ = Describe("Keeper v1.1 Register upkeep test @keeper", getKeeperSuite(ethe var _ = Describe("Keeper v1.2 Register upkeep test @keeper", getKeeperSuite(ethereum.RegistryVersion_1_2, defaultRegistryConfig, BasicCounter, RegisterUpkeepTest)) var _ = Describe("Keeper v1.1 Add funds to upkeep test @keeper", getKeeperSuite(ethereum.RegistryVersion_1_1, defaultRegistryConfig, BasicCounter, AddFundsToUpkeepTest)) var _ = Describe("Keeper v1.2 Add funds to upkeep test @keeper", getKeeperSuite(ethereum.RegistryVersion_1_2, defaultRegistryConfig, BasicCounter, AddFundsToUpkeepTest)) +var _ = Describe("Keeper v1.1 Removing one keeper test @keeper", getKeeperSuite(ethereum.RegistryVersion_1_1, defaultRegistryConfig, BasicCounter, RemovingKeeperTest)) +var _ = Describe("Keeper v1.2 Removing one keeper test @keeper", getKeeperSuite(ethereum.RegistryVersion_1_2, defaultRegistryConfig, BasicCounter, RemovingKeeperTest)) var defaultRegistryConfig = contracts.KeeperRegistrySettings{ PaymentPremiumPPB: uint32(200000000), @@ -507,6 +511,50 @@ func getKeeperSuite( }, "30s", "1s").Should(Succeed()) }) } + + if testToRun == RemovingKeeperTest { + It("removes one keeper and makes sure the upkeeps are not affected by this and still perform", func() { + var initialCounters = make([]*big.Int, len(upkeepIDs)) + // Make sure the upkeeps are running before we remove a keeper + Eventually(func(g Gomega) { + for upkeepID := 0; upkeepID < len(upkeepIDs); upkeepID++ { + counter, err := consumers[upkeepID].Counter(context.Background()) + initialCounters[upkeepID] = counter + g.Expect(err).ShouldNot(HaveOccurred(), "Failed to get counter for upkeep "+strconv.Itoa(upkeepID)) + g.Expect(counter.Cmp(big.NewInt(0)) == 1, "Expected consumer counter to be greater than 0, but got %s", counter) + } + }, "1m", "1s").Should(Succeed()) + + keepers, err := registry.GetKeeperList(context.Background()) + Expect(err).ShouldNot(HaveOccurred(), "Encountered error when getting the list of keepers") + + // Remove the first keeper from the list + newKeeperList := keepers[1:] + + // Construct the addresses of the payees required by the SetKeepers function + payees := make([]string, len(keepers)-1) + for i := 0; i < len(payees); i++ { + payees[i], err = chainlinkNodes[0].PrimaryEthAddress() + Expect(err).ShouldNot(HaveOccurred(), "Shouldn't encounter error when building the payee list") + } + + err = registry.SetKeepers(newKeeperList, payees) + Expect(err).ShouldNot(HaveOccurred(), "Encountered error when setting the new Keepers") + err = networks.Default.WaitForEvents() + Expect(err).ShouldNot(HaveOccurred(), "Failed to wait for events") + log.Info().Msg("Successfully removed keeper at address " + keepers[0] + " from the list of Keepers") + + // The upkeeps should still perform and their counters should have increased compared to the first check + Eventually(func(g Gomega) { + for i := 0; i < len(upkeepIDs); i++ { + counter, err := consumers[i].Counter(context.Background()) + g.Expect(err).ShouldNot(HaveOccurred(), "Failed to get counter for upkeep "+strconv.Itoa(i)) + g.Expect(counter.Cmp(initialCounters[i]) == 1, "Expected consumer counter to be greater "+ + "than initial counter which was %s, but got %s", initialCounters[i], counter) + } + }, "1m", "1s").Should(Succeed()) + }) + } }) AfterEach(func() {