Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions database/dynamodb/test/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package test

import (
"context"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"

"github.com/ory/dockertest/v3"
"github.com/ory/dockertest/v3/docker"

"github.com/pkg/errors"

"github.com/code-payments/ocp-server/retry"
"github.com/code-payments/ocp-server/retry/backoff"
)

const (
containerRepository = "amazon/dynamodb-local"
containerVersion = "2.5.2"
containerAutoKill = 120 // seconds

port = "8000"

region = "us-east-1"
accessKey = "dummy"
secretKey = "dummy"
)

// TestEnv is a running dynamodb-local container with a connected client.
type TestEnv struct {
Pool *dockertest.Pool
Client *dynamodb.Client
Endpoint string
}

// NewTestEnv starts a dynamodb-local Docker container and returns a connected
// client. It mirrors the postgres test harness.
func NewTestEnv() (*TestEnv, error) {
pool, err := dockertest.NewPool("")
if err != nil {
return nil, errors.Wrap(err, "could not connect to docker")
}

resource, err := pool.RunWithOptions(&dockertest.RunOptions{
Repository: containerRepository,
Tag: containerVersion,
Cmd: []string{"-jar", "DynamoDBLocal.jar", "-inMemory"},
}, func(config *docker.HostConfig) {
config.AutoRemove = true
config.RestartPolicy = docker.RestartPolicy{Name: "no"}
})
if err != nil {
return nil, errors.Wrap(err, "could not start resource")
}
resource.Expire(containerAutoKill)

endpoint := "http://" + resource.GetHostPort(port+"/tcp")
client := NewClient(endpoint)

// Wait for the container to accept connections.
_, err = retry.Retry(
func() error {
_, err := client.ListTables(context.Background(), &dynamodb.ListTablesInput{})
return err
},
retry.Limit(60),
retry.Backoff(backoff.Constant(500*time.Millisecond), 500*time.Millisecond),
)
if err != nil {
return nil, errors.Wrap(err, "timed out waiting for dynamodb-local to become available")
}

return &TestEnv{Pool: pool, Client: client, Endpoint: endpoint}, nil
}

// NewClient builds a DynamoDB client pointed at the given local endpoint with
// dummy static credentials.
func NewClient(endpoint string) *dynamodb.Client {
return dynamodb.New(dynamodb.Options{
Region: region,
BaseEndpoint: aws.String(endpoint),
Credentials: credentials.NewStaticCredentialsProvider(accessKey, secretKey, ""),
})
}
13 changes: 8 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ require (
filippo.io/edwards25519 v1.1.0
github.com/anyproto/go-slip10 v1.0.1
github.com/aws/aws-sdk-go-v2 v1.42.0
github.com/aws/aws-sdk-go-v2/credentials v1.19.24
github.com/aws/aws-sdk-go-v2/feature/rds/auth v1.6.25
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.59.0
github.com/aws/aws-sdk-go-v2/service/s3 v1.102.2
github.com/code-payments/code-vm-indexer v1.2.0
github.com/code-payments/ocp-protobuf-api v1.13.2-0.20260610171241-de46af911053
Expand Down Expand Up @@ -44,12 +46,13 @@ require (
github.com/Microsoft/go-winio v0.4.14 // indirect
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.11 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.25 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.25 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.26 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.10 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.29 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.29 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.30 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.12 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.18 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.25 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.12.6 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.29 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.25 // indirect
github.com/aws/smithy-go v1.27.1 // indirect
github.com/cenkalti/backoff/v4 v4.1.0 // indirect
Expand Down
26 changes: 16 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,26 @@ github.com/aws/aws-sdk-go-v2 v1.42.0 h1:XvXMJTkFQtpBKIWZnmr9ZEOc2InWM2yldjXEJ/by
github.com/aws/aws-sdk-go-v2 v1.42.0/go.mod h1:27+ACypSLljLAEKsCYOmrjKh83vuTRkuAe9Uv/3A4bg=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.11 h1:h5+3VT69KUBK24grGuuA5saDJTj2IIjLb9au668Fo5I=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.11/go.mod h1:dnakxebH6UwFvcvujL0LVggYQ8nEvBGjU4G/V79Nv94=
github.com/aws/aws-sdk-go-v2/credentials v1.19.24 h1:2hQqYCV9yqyePQ9o6dCrZc/zO8U3TwPr9mIKlZnPu/I=
github.com/aws/aws-sdk-go-v2/credentials v1.19.24/go.mod h1:IDwpACtwqHLISdzfwUUNq4P9DsB/h5BLg4FwJPNfqFY=
github.com/aws/aws-sdk-go-v2/feature/rds/auth v1.6.25 h1:EeK30mZmhopHcNmKykyGF0LwmFB1ZwQNr+FeyRjcN0U=
github.com/aws/aws-sdk-go-v2/feature/rds/auth v1.6.25/go.mod h1:tudVnwAJyXgCh4N6ABYdzUM+i+PXsx8700FOyhMn+4k=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.25 h1:Uii3frf9ztec/ABM2/FSH9/z7PLzxfpG8h4RpkUFflQ=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.25/go.mod h1:G6kntsA2GorAxDPbap6xgB2F+amSLUF8GJTi7PUoX44=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.25 h1:r1+/l6m+WaUJF9HISEsNOLHSNj5EXYQxK8VX6Cz9NlA=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.25/go.mod h1:cKf+D+NMDK1LndD7BowHbBZPgR9V0/5HubH0PFWvA+c=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.26 h1:A1PmWU2zfkIm9EyFlJncFXL4W4phML+h8KjltUsCvNQ=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.26/go.mod h1:dY4MRzXEizrD4hqtpKvWVGPX7QleSGGVY+EBolo1RmM=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.10 h1:d5/908OJ4bXg8lyjeMPvXetEKqoDoLi5Owy1zNue3yg=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.10/go.mod h1:a57l7Hwh+FWI+we50g5NPJHYUKeJKfXbc4w8SyXu8Ig=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.29 h1:f3vKqSo13fhTYb+JEcXwXefZQE26I1FB5eTSniU67ko=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.29/go.mod h1:MzoLFUArKGpGD+ukmPiTPG1X5x4o6M2kq4v2dr1FiEc=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.29 h1:RdwIf/CuUsvJX3RgJagbOyotl/cxoLY4xviKuE7p2GY=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.29/go.mod h1:71wt8W2EgswdZy9Mf9KNnzxZ3TiZlv4caKghPktDOkA=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.30 h1:VTGy885W5DKBxWRUJbym9hytNaYzsyaPkCHGRRMAOhU=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.30/go.mod h1:AS0HycUvJRFvTt613AYDOgO2jzw+00cVSMny8XB3yMY=
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.59.0 h1:S1qETDbdXKZMYVveuxACCKuRqnAt2NlnmYnlq5SeuMY=
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.59.0/go.mod h1:jLkDwIDBkCIpiENQhAOjAR2L9jwj56mZgVEvuro4gUE=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.12 h1:ZD2+BSw9vFsNlKYIasSNt3uDbjqqXIBcM13UJv/Lx2k=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.12/go.mod h1:Ms4zlcVBbXbiP7EVLhl+lgjvA/a7YphqQ3Ih3174EmI=
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.18 h1:W/EyPFl9A5rXrtoilfwHYEvzHER+K4SpBPtMXi24Mos=
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.18/go.mod h1:UG50K+pvd/uy6xExbobg0rjqFBFZe6I3l75EPDZw4tg=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.25 h1:dD3dhHNglpd98gs72my22Ndqi1hqQGllFFg1F+twfxg=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.25/go.mod h1:0yAbjPfd64gG7mj85RW+fMEYdfBgCRZw8g/oWcL1pjc=
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.12.6 h1:Bs2OwYq0HBgHYwfGmUwYIPtTNaGMGAHkRje4jmW2VoI=
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.12.6/go.mod h1:OTctu4cW8t7/TRlTKPLT6akzyOkfceMWhtEHqtYDIQQ=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.29 h1:DRebniUGZ2MqiiIVmQJ04vIXr918hubdHMnarSLEWyU=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.29/go.mod h1:LfRkPCD8YHDM2E5eTkos2UpwYeZnBcVarTa8L59bJHA=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.25 h1:2pQEbwf+/6EDbiit/GcBE2K4IUpMZymaA0kOz3xK978=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.25/go.mod h1:KvT6NCcQ0EZ+ZkVRrlBMt04Po3ok23YELEp7WimhLhM=
github.com/aws/aws-sdk-go-v2/service/s3 v1.102.2 h1:ie4ElCmUKS26pzrZcIk/lmt4yWjAqLLcawstyQCh298=
Expand Down
24 changes: 0 additions & 24 deletions ocp/data/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"sync"
"time"

"github.com/google/uuid"
"github.com/jmoiron/sqlx"

"github.com/code-payments/ocp-server/cache"
Expand All @@ -27,7 +26,6 @@ import (
"github.com/code-payments/ocp-server/ocp/data/deposit"
"github.com/code-payments/ocp-server/ocp/data/fulfillment"
"github.com/code-payments/ocp-server/ocp/data/intent"
"github.com/code-payments/ocp-server/ocp/data/messaging"
"github.com/code-payments/ocp-server/ocp/data/nonce"
"github.com/code-payments/ocp-server/ocp/data/rendezvous"
"github.com/code-payments/ocp-server/ocp/data/swap"
Expand All @@ -46,7 +44,6 @@ import (
deposit_memory_client "github.com/code-payments/ocp-server/ocp/data/deposit/memory"
fulfillment_memory_client "github.com/code-payments/ocp-server/ocp/data/fulfillment/memory"
intent_memory_client "github.com/code-payments/ocp-server/ocp/data/intent/memory"
messaging_memory_client "github.com/code-payments/ocp-server/ocp/data/messaging/memory"
nonce_memory_client "github.com/code-payments/ocp-server/ocp/data/nonce/memory"
rendezvous_memory_client "github.com/code-payments/ocp-server/ocp/data/rendezvous/memory"
swap_memory_client "github.com/code-payments/ocp-server/ocp/data/swap/memory"
Expand All @@ -65,7 +62,6 @@ import (
deposit_postgres_client "github.com/code-payments/ocp-server/ocp/data/deposit/postgres"
fulfillment_postgres_client "github.com/code-payments/ocp-server/ocp/data/fulfillment/postgres"
intent_postgres_client "github.com/code-payments/ocp-server/ocp/data/intent/postgres"
messaging_postgres_client "github.com/code-payments/ocp-server/ocp/data/messaging/postgres"
nonce_postgres_client "github.com/code-payments/ocp-server/ocp/data/nonce/postgres"
rendezvous_postgres_client "github.com/code-payments/ocp-server/ocp/data/rendezvous/postgres"
swap_postgres_client "github.com/code-payments/ocp-server/ocp/data/swap/postgres"
Expand Down Expand Up @@ -197,12 +193,6 @@ type DatabaseData interface {
GetUsdCostBasis(ctx context.Context, owner string, mint string) (float64, error)
GetUsdCostBasisBatch(ctx context.Context, mint string, owners ...string) (map[string]float64, error)

// Messaging
// --------------------------------------------------------------------------------
CreateMessage(ctx context.Context, record *messaging.Record) error
GetMessages(ctx context.Context, account string) ([]*messaging.Record, error)
DeleteMessage(ctx context.Context, account string, messageID uuid.UUID) error

// Nonces
// --------------------------------------------------------------------------------
GetNonce(ctx context.Context, address string) (*nonce.Record, error)
Expand Down Expand Up @@ -300,7 +290,6 @@ type DatabaseProvider struct {
deposits deposit.Store
fulfillments fulfillment.Store
intents intent.Store
messages messaging.Store
nonces nonce.Store
rendezvous rendezvous.Store
swaps swap.Store
Expand Down Expand Up @@ -347,7 +336,6 @@ func NewDatabaseProvider(dbConfig *pg.Config) (DatabaseData, error) {
deposits: deposit_postgres_client.New(db),
fulfillments: fulfillment_postgres_client.New(db),
intents: intent_postgres_client.New(db),
messages: messaging_postgres_client.New(db),
nonces: nonce_postgres_client.New(db),
rendezvous: rendezvous_postgres_client.New(db),
swaps: swap_postgres_client.New(db),
Expand Down Expand Up @@ -375,7 +363,6 @@ func NewTestDatabaseProvider() DatabaseData {
deposits: deposit_memory_client.New(),
fulfillments: fulfillment_memory_client.New(),
intents: intent_memory_client.New(),
messages: messaging_memory_client.New(),
nonces: nonce_memory_client.New(),
rendezvous: rendezvous_memory_client.New(),
swaps: swap_memory_client.New(),
Expand Down Expand Up @@ -740,17 +727,6 @@ func (dp *DatabaseProvider) GetUsdCostBasisBatch(ctx context.Context, mint strin
return dp.intents.GetUsdCostBasisBatch(ctx, mint, owners...)
}

// Messaging
// --------------------------------------------------------------------------------
func (dp *DatabaseProvider) CreateMessage(ctx context.Context, record *messaging.Record) error {
return dp.messages.Insert(ctx, record)
}
func (dp *DatabaseProvider) GetMessages(ctx context.Context, account string) ([]*messaging.Record, error) {
return dp.messages.Get(ctx, account)
}
func (dp *DatabaseProvider) DeleteMessage(ctx context.Context, account string, messageID uuid.UUID) error {
return dp.messages.Delete(ctx, account, messageID)
}

// Nonces
// --------------------------------------------------------------------------------
Expand Down
Loading
Loading