From f9ec220c7452578bdbc0187b0a4d96a0f56c0784 Mon Sep 17 00:00:00 2001 From: hopeyen Date: Fri, 13 Dec 2024 18:49:45 -0800 Subject: [PATCH] test: add dynamodb to test suite --- core/indexer/indexer_suite_test.go | 2 +- core/thegraph/state_integration_test.go | 2 +- inabox/bin.sh | 2 +- inabox/deploy/localstack.go | 65 ++++++++++++++++++++++++- inabox/tests/integration_suite_test.go | 17 ++++--- inabox/tests/integration_v2_test.go | 25 +++++++++- node/plugin/tests/plugin_test.go | 2 +- operators/churner/tests/churner_test.go | 2 +- 8 files changed, 103 insertions(+), 14 deletions(-) diff --git a/core/indexer/indexer_suite_test.go b/core/indexer/indexer_suite_test.go index 1867c73aac..d24fb462f0 100644 --- a/core/indexer/indexer_suite_test.go +++ b/core/indexer/indexer_suite_test.go @@ -45,7 +45,7 @@ var _ = BeforeSuite(func() { testConfig.Deployers[0].DeploySubgraphs = false if testConfig.Environment.IsLocal() { - fmt.Println("Starting anvil") + fmt.Println("Starting anvil core indexer indexer_suite_test") testConfig.StartAnvil() fmt.Println("Deploying experiment") diff --git a/core/thegraph/state_integration_test.go b/core/thegraph/state_integration_test.go index f7326d22be..76a14071dd 100644 --- a/core/thegraph/state_integration_test.go +++ b/core/thegraph/state_integration_test.go @@ -50,7 +50,7 @@ func setup() { testConfig = deploy.NewTestConfig(testName, rootPath) testConfig.Deployers[0].DeploySubgraphs = true - fmt.Println("Starting anvil") + fmt.Println("Starting anvil ---------- core thegraph state_integration_test") testConfig.StartAnvil() fmt.Println("Starting graph node") diff --git a/inabox/bin.sh b/inabox/bin.sh index e77bc581e8..1a92ec66d8 100755 --- a/inabox/bin.sh +++ b/inabox/bin.sh @@ -236,7 +236,7 @@ function stop_detached { function start_anvil { - echo "Starting anvil server ....." + echo "Starting anvil server .... inabox bin.sh." anvil --host 0.0.0.0 > /dev/null & anvil_pid=$! echo "Anvil server started ....." diff --git a/inabox/deploy/localstack.go b/inabox/deploy/localstack.go index 07658d0740..29299db52b 100644 --- a/inabox/deploy/localstack.go +++ b/inabox/deploy/localstack.go @@ -143,18 +143,21 @@ func DeployResources( return err } - fmt.Println("Creating payment related tables") + fmt.Println("Creating payment related tables ---- in localstack") // create payment related tables err = meterer.CreateReservationTable(cfg, v2MetadataTableName+"_reservation") if err != nil { + fmt.Println("err", err) return err } err = meterer.CreateOnDemandTable(cfg, v2MetadataTableName+"_ondemand") if err != nil { + fmt.Println("err", err) return err } err = meterer.CreateGlobalReservationTable(cfg, v2MetadataTableName+"_global_reservation") if err != nil { + fmt.Println("err", err) return err } } @@ -163,6 +166,66 @@ func DeployResources( } +func DeployPaymentRelatedTables( + pool *dockertest.Pool, + localStackPort string, +) error { + + if pool == nil { + var err error + pool, err = dockertest.NewPool("") + if err != nil { + fmt.Println("Could not construct pool: %w", err) + return err + } + } + + // exponential backoff-retry, because the application in + // the container might not be ready to accept connections yet + pool.MaxWait = 10 * time.Second + _, b, _, _ := runtime.Caller(0) + rootPath := filepath.Join(filepath.Dir(b), "../..") + changeDirectory(filepath.Join(rootPath, "inabox")) + if err := pool.Retry(func() error { + fmt.Println("Creating S3 bucket") + return execCmd("./create-s3-bucket.sh", []string{}, []string{fmt.Sprintf("AWS_URL=http://0.0.0.0:%s", localStackPort)}) + }); err != nil { + fmt.Println("Might be connected already:", err) + // return err + } + + cfg := aws.ClientConfig{ + Region: "us-east-1", + AccessKey: "localstack", + SecretAccessKey: "localstack", + EndpointURL: fmt.Sprintf("http://0.0.0.0:%s", localStackPort), + } + + fmt.Println("Creating v2 tables deploy hleper") + + v2TableName := "test_v2" + fmt.Println("Creating payment related tables") + // create payment related tables + err := meterer.CreateReservationTable(cfg, v2TableName+"_reservation") + if err != nil { + fmt.Println("err", err) + return err + } + err = meterer.CreateOnDemandTable(cfg, v2TableName+"_ondemand") + if err != nil { + fmt.Println("err", err) + return err + } + err = meterer.CreateGlobalReservationTable(cfg, v2TableName+"_global_reservation") + if err != nil { + fmt.Println("err", err) + return err + } + + return err + +} + func PurgeDockertestResources(pool *dockertest.Pool, resource *dockertest.Resource) { fmt.Println("Stopping Dockertest resources") if resource != nil { diff --git a/inabox/tests/integration_suite_test.go b/inabox/tests/integration_suite_test.go index a5bf379a1b..34d881c5f0 100644 --- a/inabox/tests/integration_suite_test.go +++ b/inabox/tests/integration_suite_test.go @@ -84,23 +84,28 @@ var _ = BeforeSuite(func() { } } + fmt.Println("Starting localstack!!!!!!!!!!!!!!!!!!!!!!!!!!!") + + localStackPort = "4570" + pool, resource, err := deploy.StartDockertestWithLocalstackContainer(localStackPort) + Expect(err).To(BeNil()) + dockertestPool = pool + dockertestResource = resource testConfig = deploy.NewTestConfig(testName, rootPath) if testConfig.Environment.IsLocal() { if !inMemoryBlobStore { fmt.Println("Using shared Blob Store") - localStackPort = "4570" - pool, resource, err := deploy.StartDockertestWithLocalstackContainer(localStackPort) - Expect(err).To(BeNil()) - dockertestPool = pool - dockertestResource = resource err = deploy.DeployResources(pool, localStackPort, metadataTableName, bucketTableName, metadataTableNameV2) Expect(err).To(BeNil()) } else { fmt.Println("Using in-memory Blob Store") } + fmt.Println("Making payment related tables....") + err = deploy.DeployPaymentRelatedTables(pool, localStackPort) + Expect(err).To(BeNil()) - fmt.Println("Starting anvil") + fmt.Println("Starting anvil inabox/tests/integration_suite_test.go") testConfig.StartAnvil() if deployer, ok := testConfig.GetDeployer(testConfig.EigenDA.Deployer); ok && deployer.DeploySubgraphs { diff --git a/inabox/tests/integration_v2_test.go b/inabox/tests/integration_v2_test.go index 26fe1a1b4f..a39948983e 100644 --- a/inabox/tests/integration_v2_test.go +++ b/inabox/tests/integration_v2_test.go @@ -3,12 +3,15 @@ package integration_test import ( "context" "crypto/rand" + "fmt" "time" "github.com/Layr-Labs/eigenda/api/clients" disperserpb "github.com/Layr-Labs/eigenda/api/grpc/disperser/v2" + "github.com/Layr-Labs/eigenda/common/aws" "github.com/Layr-Labs/eigenda/core" auth "github.com/Layr-Labs/eigenda/core/auth/v2" + "github.com/Layr-Labs/eigenda/core/meterer" corev2 "github.com/Layr-Labs/eigenda/core/v2" dispv2 "github.com/Layr-Labs/eigenda/disperser/common/v2" "github.com/Layr-Labs/eigenda/encoding/utils/codec" @@ -23,11 +26,29 @@ var _ = Describe("Inabox v2 Integration", func() { ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) defer cancel() + cfg := aws.ClientConfig{ + Region: "us-east-1", + AccessKey: "localstack", + SecretAccessKey: "localstack", + EndpointURL: fmt.Sprintf("http://0.0.0.0:%s", localStackPort), + } + fmt.Println("Creating v2 tables IN integration_v2_test.go") + + fmt.Println("Creating payment related tables v2") + // create payment related tables + err := meterer.CreateReservationTable(cfg, "e2e_v2_reservation") + fmt.Println("err", err) + Expect(err).To(BeNil()) + err = meterer.CreateOnDemandTable(cfg, "e2e_v2_ondemand") + fmt.Println("err", err) + Expect(err).To(BeNil()) + err = meterer.CreateGlobalReservationTable(cfg, "e2e_v2_global_reservation") + fmt.Println("err", err) + Expect(err).To(BeNil()) + privateKeyHex := "0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcded" signer := auth.NewLocalBlobRequestSigner(privateKeyHex) - // deploy payment dynamodb tables - disp, err := clients.NewDisperserClientV2(&clients.DisperserClientV2Config{ Hostname: "localhost", Port: "32005", diff --git a/node/plugin/tests/plugin_test.go b/node/plugin/tests/plugin_test.go index b01daf2df5..db01c1e1f9 100644 --- a/node/plugin/tests/plugin_test.go +++ b/node/plugin/tests/plugin_test.go @@ -58,7 +58,7 @@ func setup(m *testing.M) { return } - fmt.Println("Starting anvil") + fmt.Println("Starting anvil node plugin tests plugin_test.go") testConfig.StartAnvil() fmt.Println("Deploying experiment") diff --git a/operators/churner/tests/churner_test.go b/operators/churner/tests/churner_test.go index ba9f11c522..ec01983f72 100644 --- a/operators/churner/tests/churner_test.go +++ b/operators/churner/tests/churner_test.go @@ -75,7 +75,7 @@ func setup(m *testing.M) { return } - fmt.Println("Starting anvil") + fmt.Println("Starting anvil operators churner tests churner_test.go") testConfig.StartAnvil() fmt.Println("Deploying experiment")