From d83052522fe709f89775153b747b02fac5577320 Mon Sep 17 00:00:00 2001 From: Adam Hamrick Date: Tue, 30 Nov 2021 11:51:35 -0500 Subject: [PATCH] Enables dynamic placement of logs folder --- actions/actions.go | 8 ++++---- suite/smoke/cron_test.go | 3 ++- suite/smoke/flux_test.go | 3 ++- suite/smoke/keeper_test.go | 3 ++- suite/smoke/ocr_test.go | 4 +++- suite/smoke/runlog_test.go | 5 ++--- suite/smoke/vrf_test.go | 26 +++++++++++++++++++++----- 7 files changed, 36 insertions(+), 16 deletions(-) diff --git a/actions/actions.go b/actions/actions.go index 3445faac4..099aa2f0d 100644 --- a/actions/actions.go +++ b/actions/actions.go @@ -11,7 +11,6 @@ import ( "github.com/onsi/ginkgo/v2" "github.com/smartcontractkit/helmenv/environment" - "github.com/smartcontractkit/integrations-framework/utils" "github.com/smartcontractkit/integrations-framework/contracts" @@ -151,12 +150,13 @@ func GetMockserverInitializerDataForOTPE( return initializers, nil } -// TeardownSuite tears down networks/clients and environment -func TeardownSuite(env *environment.Environment, nets *client.Networks) error { +// TeardownSuite tears down networks/clients and environment and creates a logs folder for failed tests in the +// specified path +func TeardownSuite(env *environment.Environment, nets *client.Networks, logsFolderPath string) error { if ginkgo.CurrentSpecReport().Failed() { testFilename := strings.Split(ginkgo.CurrentSpecReport().FileName(), ".")[0] _, testName := filepath.Split(testFilename) - logsPath := filepath.Join(utils.ProjectRoot, DefaultArtifactsDir, fmt.Sprintf("%s-%d", testName, time.Now().Unix())) + logsPath := filepath.Join(logsFolderPath, DefaultArtifactsDir, fmt.Sprintf("%s-%d", testName, time.Now().Unix())) if err := env.Artifacts.DumpTestResult(logsPath, "chainlink"); err != nil { return err } diff --git a/suite/smoke/cron_test.go b/suite/smoke/cron_test.go index cb39f62b9..5c3a9b53a 100644 --- a/suite/smoke/cron_test.go +++ b/suite/smoke/cron_test.go @@ -10,6 +10,7 @@ import ( "github.com/smartcontractkit/helmenv/tools" "github.com/smartcontractkit/integrations-framework/actions" "github.com/smartcontractkit/integrations-framework/client" + "github.com/smartcontractkit/integrations-framework/utils" ) var _ = Describe("Cronjob suite @cron", func() { @@ -76,7 +77,7 @@ var _ = Describe("Cronjob suite @cron", func() { AfterEach(func() { By("Tearing down the environment", func() { - err = actions.TeardownSuite(e, nil) + err = actions.TeardownSuite(e, nil, utils.ProjectRoot) Expect(err).ShouldNot(HaveOccurred()) }) }) diff --git a/suite/smoke/flux_test.go b/suite/smoke/flux_test.go index 9d3c2a9fb..dfdb41636 100644 --- a/suite/smoke/flux_test.go +++ b/suite/smoke/flux_test.go @@ -12,6 +12,7 @@ import ( "github.com/smartcontractkit/helmenv/environment" "github.com/smartcontractkit/helmenv/tools" "github.com/smartcontractkit/integrations-framework/actions" + "github.com/smartcontractkit/integrations-framework/utils" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -172,7 +173,7 @@ var _ = Describe("Flux monitor suite @flux", func() { nets.Default.GasStats().PrintStats() }) By("Tearing down the environment", func() { - err = actions.TeardownSuite(e, nets) + err = actions.TeardownSuite(e, nets, utils.ProjectRoot) Expect(err).ShouldNot(HaveOccurred()) }) }) diff --git a/suite/smoke/keeper_test.go b/suite/smoke/keeper_test.go index d67cedaea..091401a40 100644 --- a/suite/smoke/keeper_test.go +++ b/suite/smoke/keeper_test.go @@ -13,6 +13,7 @@ import ( "github.com/smartcontractkit/integrations-framework/actions" "github.com/smartcontractkit/integrations-framework/client" "github.com/smartcontractkit/integrations-framework/contracts" + "github.com/smartcontractkit/integrations-framework/utils" ) var _ = Describe("Keeper suite @keeper", func() { @@ -170,7 +171,7 @@ var _ = Describe("Keeper suite @keeper", func() { nets.Default.GasStats().PrintStats() }) By("Tearing down the environment", func() { - err = actions.TeardownSuite(e, nets) + err = actions.TeardownSuite(e, nets, utils.ProjectRoot) Expect(err).ShouldNot(HaveOccurred()) }) }) diff --git a/suite/smoke/ocr_test.go b/suite/smoke/ocr_test.go index a0b28bfb7..2f8bbeb67 100644 --- a/suite/smoke/ocr_test.go +++ b/suite/smoke/ocr_test.go @@ -2,6 +2,7 @@ package smoke import ( "context" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/smartcontractkit/helmenv/environment" @@ -9,6 +10,7 @@ import ( "github.com/smartcontractkit/integrations-framework/actions" "github.com/smartcontractkit/integrations-framework/client" "github.com/smartcontractkit/integrations-framework/contracts" + "github.com/smartcontractkit/integrations-framework/utils" ) var _ = Describe("OCR Feed @ocr", func() { @@ -79,7 +81,7 @@ var _ = Describe("OCR Feed @ocr", func() { networks.Default.GasStats().PrintStats() }) By("Tearing down the environment", func() { - err = actions.TeardownSuite(env, networks) + err = actions.TeardownSuite(env, networks, utils.ProjectRoot) Expect(err).ShouldNot(HaveOccurred()) }) }) diff --git a/suite/smoke/runlog_test.go b/suite/smoke/runlog_test.go index f5e9275aa..250323505 100644 --- a/suite/smoke/runlog_test.go +++ b/suite/smoke/runlog_test.go @@ -15,6 +15,7 @@ import ( "github.com/smartcontractkit/integrations-framework/actions" "github.com/smartcontractkit/integrations-framework/client" "github.com/smartcontractkit/integrations-framework/contracts" + "github.com/smartcontractkit/integrations-framework/utils" ) var _ = Describe("Direct request suite @runlog", func() { @@ -125,10 +126,8 @@ var _ = Describe("Direct request suite @runlog", func() { AfterEach(func() { By("Tearing down the environment", func() { nets.Default.GasStats().PrintStats() - err = actions.TeardownSuite(e, nets) + err = actions.TeardownSuite(e, nets, utils.ProjectRoot) Expect(err).ShouldNot(HaveOccurred()) - //err = e.Disconnect() - //Expect(err).ShouldNot(HaveOccurred()) }) }) }) diff --git a/suite/smoke/vrf_test.go b/suite/smoke/vrf_test.go index fd775bbeb..9236a2d0d 100644 --- a/suite/smoke/vrf_test.go +++ b/suite/smoke/vrf_test.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "math/big" + "time" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -14,6 +15,7 @@ import ( "github.com/smartcontractkit/integrations-framework/actions" "github.com/smartcontractkit/integrations-framework/client" "github.com/smartcontractkit/integrations-framework/contracts" + "github.com/smartcontractkit/integrations-framework/utils" ) var _ = Describe("VRF suite @vrf", func() { @@ -27,6 +29,7 @@ var _ = Describe("VRF suite @vrf", func() { lt contracts.LinkToken cls []client.Chainlink e *environment.Environment + job *client.Job ) BeforeEach(func() { @@ -52,7 +55,7 @@ var _ = Describe("VRF suite @vrf", func() { }) By("Funding Chainlink nodes", func() { - txCost, err := nets.Default.EstimateCostForChainlinkOperations(4) + txCost, err := nets.Default.EstimateCostForChainlinkOperations(1) Expect(err).ShouldNot(HaveOccurred()) err = actions.FundChainlinkNodes(cls, nets.Default, txCost) Expect(err).ShouldNot(HaveOccurred()) @@ -87,7 +90,7 @@ var _ = Describe("VRF suite @vrf", func() { } ost, err := os.String() Expect(err).ShouldNot(HaveOccurred()) - _, err = n.CreateJob(&client.VRFJobSpec{ + job, err = n.CreateJob(&client.VRFJobSpec{ Name: fmt.Sprintf("vrf-%s", jobUUID), CoordinatorAddress: coordinator.Address(), PublicKey: pubKeyCompressed, @@ -120,12 +123,25 @@ var _ = Describe("VRF suite @vrf", func() { err = consumer.RequestRandomness(requestHash, big.NewInt(1)) Expect(err).ShouldNot(HaveOccurred()) + timeout := time.Minute * 2 + Eventually(func(g Gomega) { + jobRuns, err := cls[0].ReadRunsByJob(job.Data.ID) + g.Expect(err).ShouldNot(HaveOccurred()) + out, err := consumer.RandomnessOutput(context.Background()) g.Expect(err).ShouldNot(HaveOccurred()) - g.Expect(out.Uint64()).Should(Not(BeNumerically("==", 0))) + // Checks that the job has actually run + g.Expect(len(jobRuns.Data)).Should(BeNumerically(">=", 1), + fmt.Sprintf("Expected the VRF job to run once or more after %s", timeout)) + + // TODO: This is an imperfect check, given it's a random number, it CAN be 0, but chances are unlikely. + // So we're just checking that the answer has changed to something other than the default (0) + // There's a better formula to ensure that VRF response is as expected, detailed under Technical Walkthrough. + // https://blog.chain.link/chainlink-vrf-on-chain-verifiable-randomness/ + g.Expect(out.Uint64()).Should(Not(BeNumerically("==", 0)), "Expected the VRF job give an answer other than 0") log.Debug().Uint64("Output", out.Uint64()).Msg("Randomness fulfilled") - }, "2m", "1s").Should(Succeed()) + }, timeout, "1s").Should(Succeed()) }) }) @@ -134,7 +150,7 @@ var _ = Describe("VRF suite @vrf", func() { nets.Default.GasStats().PrintStats() }) By("Tearing down the environment", func() { - err = actions.TeardownSuite(e, nets) + err = actions.TeardownSuite(e, nets, utils.ProjectRoot) Expect(err).ShouldNot(HaveOccurred()) }) })