Skip to content

Commit 9429588

Browse files
rebase cleanup
1 parent 55b8411 commit 9429588

File tree

4 files changed

+95
-52
lines changed

4 files changed

+95
-52
lines changed

framework/components/dockercompose/billing_platform_service/billing_platform_service.go

Lines changed: 67 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"os"
7+
"strconv"
78
"strings"
89
"time"
910

@@ -16,6 +17,7 @@ import (
1617

1718
"github.com/smartcontractkit/chainlink-testing-framework/framework"
1819
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/dockercompose/utils"
20+
"github.com/smartcontractkit/freeport"
1921
)
2022

2123
const DefaultPostgresDSN = "postgres://postgres:postgres@postgres:5432/billing_platform"
@@ -26,23 +28,29 @@ type Output struct {
2628
}
2729

2830
type BillingPlatformServiceOutput struct {
29-
BillingGRPCInternalURL string
30-
BillingGRPCExternalURL string
31-
CreditGRPCInternalURL string
32-
CreditGRPCExternalURL string
33-
OwnershipGRPCInternalURL string
34-
OwnershipGRPCExternalURL string
31+
BillingGRPCInternalURL string
32+
BillingGRPCExternalURL string
33+
CreditGRPCInternalURL string
34+
CreditGRPCExternalURL string
3535
}
3636

3737
type PostgresOutput struct {
3838
DSN string
3939
}
4040

4141
type Input struct {
42-
ComposeFile string `toml:"compose_file"`
43-
ExtraDockerNetworks []string `toml:"extra_docker_networks"`
44-
Output *Output `toml:"output"`
45-
UseCache bool `toml:"use_cache"`
42+
ComposeFile string `toml:"compose_file"`
43+
ExtraDockerNetworks []string `toml:"extra_docker_networks"`
44+
Output *Output `toml:"output"`
45+
UseCache bool `toml:"use_cache"`
46+
ChainSelector uint64 `toml:"chain_selector"`
47+
StreamsAPIURL string `toml:"streams_api_url"`
48+
StreamsAPIKey string `toml:"streams_api_key"`
49+
StreamsAPISecret string `toml:"streams_api_secret"`
50+
RPCURL string `toml:"rpc_url"`
51+
WorkflowRegistryAddress string `toml:"workflow_registry_address"`
52+
CapabilitiesRegistryAddress string `toml:"capabilities_registry_address"`
53+
WorkflowOwners []string `toml:"workflow_owners"`
4654
}
4755

4856
func defaultBillingPlatformService(in *Input) *Input {
@@ -55,10 +63,11 @@ func defaultBillingPlatformService(in *Input) *Input {
5563
const (
5664
DEFAULT_STACK_NAME = "billing-platform-service"
5765

58-
DEFAULT_BILLING_PLATFORM_SERVICE_BILLING_GRPC_PORT = "2222"
59-
DEFAULT_BILLING_PLATFORM_SERVICE_CREDIT_GRPC_PORT = "2223"
60-
DEFAULT_BILLING_PLATFORM_SERVICE_OWNERSHIP_GRPC_PORT = "2257"
61-
DEFAULT_BILLING_PLATFORM_SERVICE_SERVICE_NAME = "billing-platform-service"
66+
DEFAULT_BILLING_PLATFORM_SERVICE_BILLING_GRPC_PORT = "2222"
67+
DEFAULT_BILLING_PLATFORM_SERVICE_CREDIT_GRPC_PORT = "2223"
68+
DEFAULT_POSTGRES_PORT = "5432"
69+
DEFAULT_BILLING_PLATFORM_SERVICE_SERVICE_NAME = "billing-platform-service"
70+
DEFAULT_POSTGRES_SERVICE_NAME = "postgres"
6271
)
6372

6473
func New(in *Input) (*Output, error) {
@@ -96,31 +105,31 @@ func New(in *Input) (*Output, error) {
96105
// set development defaults for necessary environment variables and allow them to be overridden by the host process
97106
envVars := make(map[string]string)
98107

99-
envVars["MAINNET_WORKFLOW_REGISTRY_CHAIN_SELECTOR"] = "7759470850252068959" // Anvil Devnet
100-
envVars["MAINNET_WORKFLOW_REGISTRY_CONTRACT_ADDRESS"] = "0xA15BB66138824a1c7167f5E85b957d04Dd34E468" // Deployed via Linking integration tests
101-
envVars["MAINNET_WORKFLOW_REGISTRY_RPC_URL"] = "http://anvil:8545" // Anvil inside Docker
102-
envVars["MAINNET_WORKFLOW_REGISTRY_FINALITY_DEPTH"] = "0" // Instant finality on devnet
103-
envVars["TESTNET_WORKFLOW_REGISTRY_CHAIN_SELECTOR"] = "10344971235874465080" // Base Sepolia
104-
envVars["TESTNET_WORKFLOW_REGISTRY_CONTRACT_ADDRESS"] = "0xED1D0d87706a466151d67A6a06d69534C97BE66F" // Used for Billing integration tests
105-
envVars["TESTNET_WORKFLOW_REGISTRY_RPC_URL"] = "http://anvil:8545" // Anvil inside Docker
106-
envVars["TESTNET_WORKFLOW_REGISTRY_FINALITY_DEPTH"] = "10" // Arbitrary value, adjust as needed
107-
envVars["KMS_PROOF_SIGNING_KEY_ID"] = "00000000-0000-0000-0000-000000000001" // provisioned via LocalStack
108-
envVars["VERIFIER_INITIAL_INTERVAL"] = "0s" // reduced to force verifier to start immediately in integration tests
109-
envVars["VERIFIER_MAXIMUM_INTERVAL"] = "1s" // reduced to force verifier to start immediately in integration tests
110-
envVars["LINKING_REQUEST_COOLDOWN"] = "0s" // reduced to force consequtive linking requests to be processed immediately in integration tests
111-
112-
envVars["MAINNET_CAPABILITIES_REGISTRY_CHAIN_SELECTOR"] = "10344971235874465080" // Base Sepolia
113-
envVars["MAINNET_CAPABILITIES_REGISTRY_CONTRACT_ADDRESS"] = "0x4c0a7d8f1b2e3c5f6a9b8e2d3c4f5e6b7a8b9c0d" // dummy address
114-
envVars["MAINNET_CAPABILITIES_REGISTRY_RPC_URL"] = "http://anvil:8545" // Anvil RPC URL
115-
envVars["MAINNET_CAPABILITIES_REGISTRY_FINALITY_DEPTH"] = "10" // Arbitrary value, adjust as needed
116-
envVars["TESTNET_CAPABILITIES_REGISTRY_CHAIN_SELECTOR"] = "10344971235874465080" // Base Sepolia
117-
envVars["TESTNET_CAPABILITIES_REGISTRY_CONTRACT_ADDRESS"] = "0x4c0a7d8f1b2e3c5f6a9b8e2d3c4f5e6b7a8b9c0d" // dummy address
118-
envVars["TESTNET_CAPABILITIES_REGISTRY_RPC_URL"] = "http://anvil:8545" // Anvil RPC URL
119-
envVars["TESTNET_CAPABILITIES_REGISTRY_FINALITY_DEPTH"] = "10" // Arbitrary value, adjust as needed
120-
121-
envVars["STREAMS_API_URL"] = ""
122-
envVars["STREAMS_API_KEY"] = ""
123-
envVars["STREAMS_API_SECRET"] = ""
108+
envVars["MAINNET_WORKFLOW_REGISTRY_CHAIN_SELECTOR"] = strconv.FormatUint(in.ChainSelector, 10)
109+
envVars["MAINNET_WORKFLOW_REGISTRY_CONTRACT_ADDRESS"] = in.WorkflowRegistryAddress
110+
envVars["MAINNET_WORKFLOW_REGISTRY_RPC_URL"] = in.RPCURL
111+
envVars["MAINNET_WORKFLOW_REGISTRY_FINALITY_DEPTH"] = "0" // Instant finality on devnet
112+
envVars["KMS_PROOF_SIGNING_KEY_ID"] = "00000000-0000-0000-0000-000000000001" // provisioned via LocalStack
113+
envVars["VERIFIER_INITIAL_INTERVAL"] = "0s" // reduced to force verifier to start immediately in integration tests
114+
envVars["VERIFIER_MAXIMUM_INTERVAL"] = "1s" // reduced to force verifier to start immediately in integration tests
115+
envVars["LINKING_REQUEST_COOLDOWN"] = "0s" // reduced to force consequtive linking requests to be processed immediately in integration tests
116+
117+
envVars["MAINNET_CAPABILITIES_REGISTRY_CHAIN_SELECTOR"] = strconv.FormatUint(in.ChainSelector, 10)
118+
envVars["MAINNET_CAPABILITIES_REGISTRY_CONTRACT_ADDRESS"] = in.CapabilitiesRegistryAddress
119+
envVars["MAINNET_CAPABILITIES_REGISTRY_RPC_URL"] = in.RPCURL
120+
envVars["MAINNET_CAPABILITIES_REGISTRY_FINALITY_DEPTH"] = "10" // Arbitrary value, adjust as needed
121+
122+
envVars["TEST_OWNERS"] = strings.Join(in.WorkflowOwners, ",")
123+
envVars["STREAMS_API_URL"] = in.StreamsAPIURL
124+
envVars["STREAMS_API_KEY"] = in.StreamsAPIKey
125+
envVars["STREAMS_API_SECRET"] = in.StreamsAPISecret
126+
127+
port, err := freeport.Take(1)
128+
if err != nil {
129+
return nil, errors.Wrap(err, "failed to get free port for Billing Platform Service postgres")
130+
}
131+
132+
envVars["POSTGRES_PORT"] = strconv.FormatInt(int64(port[0]), 10)
124133

125134
for _, env := range os.Environ() {
126135
pair := strings.SplitN(env, "=", 2)
@@ -142,7 +151,6 @@ func New(in *Input) (*Output, error) {
142151
wait.ForLog("GRPC server is live").WithPollInterval(200*time.Millisecond),
143152
wait.ForListeningPort(DEFAULT_BILLING_PLATFORM_SERVICE_BILLING_GRPC_PORT),
144153
wait.ForListeningPort(DEFAULT_BILLING_PLATFORM_SERVICE_CREDIT_GRPC_PORT),
145-
wait.ForListeningPort(DEFAULT_BILLING_PLATFORM_SERVICE_OWNERSHIP_GRPC_PORT),
146154
).WithDeadline(1*time.Minute),
147155
)
148156

@@ -151,6 +159,11 @@ func New(in *Input) (*Output, error) {
151159
return nil, errors.Wrap(billingErr, "failed to get billing-platform-service container")
152160
}
153161

162+
postgresContainer, postgresErr := stack.ServiceContainer(ctx, DEFAULT_POSTGRES_SERVICE_NAME)
163+
if postgresErr != nil {
164+
return nil, errors.Wrap(postgresErr, "failed to get postgres container")
165+
}
166+
154167
cli, cliErr := client.NewClientWithOpts(
155168
client.FromEnv,
156169
client.WithAPIVersionNegotiation(),
@@ -193,16 +206,27 @@ func New(in *Input) (*Output, error) {
193206
return nil, errors.Wrap(billingExternalHostErr, "failed to get host for Billing Platform Service")
194207
}
195208

209+
// get hosts for billing platform service
210+
postgresExternalHost, postgresExternalHostErr := utils.GetContainerHost(ctx, postgresContainer)
211+
if postgresExternalHostErr != nil {
212+
return nil, errors.Wrap(postgresExternalHostErr, "failed to get host for postgres")
213+
}
214+
196215
// get mapped ports for billing platform service
197216
serviceOutput, err := getExternalPorts(ctx, billingExternalHost, billingContainer)
198217
if err != nil {
199218
return nil, errors.Wrap(err, "failed to get mapped port for Billing Platform Service")
200219
}
201220

221+
externalPostgresPort, err := utils.FindMappedPort(ctx, 20*time.Second, postgresContainer, nat.Port(DEFAULT_POSTGRES_PORT+"/tcp"))
222+
if err != nil {
223+
return nil, errors.Wrap(err, "failed to get mapped port for postgres")
224+
}
225+
202226
output := &Output{
203227
BillingPlatformService: serviceOutput,
204228
Postgres: &PostgresOutput{
205-
DSN: DefaultPostgresDSN,
229+
DSN: fmt.Sprintf("postgres://postgres:postgres@%s:%s/billing_platform", postgresExternalHost, externalPostgresPort.Port()),
206230
},
207231
}
208232

@@ -213,9 +237,8 @@ func New(in *Input) (*Output, error) {
213237

214238
func getExternalPorts(ctx context.Context, billingExternalHost string, billingContainer *testcontainers.DockerContainer) (*BillingPlatformServiceOutput, error) {
215239
ports := map[string]nat.Port{
216-
"billing": DEFAULT_BILLING_PLATFORM_SERVICE_BILLING_GRPC_PORT,
217-
"credit": DEFAULT_BILLING_PLATFORM_SERVICE_CREDIT_GRPC_PORT,
218-
"ownership": DEFAULT_BILLING_PLATFORM_SERVICE_OWNERSHIP_GRPC_PORT,
240+
"billing": DEFAULT_BILLING_PLATFORM_SERVICE_BILLING_GRPC_PORT,
241+
"credit": DEFAULT_BILLING_PLATFORM_SERVICE_CREDIT_GRPC_PORT,
219242
}
220243

221244
output := BillingPlatformServiceOutput{}
@@ -236,9 +259,6 @@ func getExternalPorts(ctx context.Context, billingExternalHost string, billingCo
236259
case "credit":
237260
output.CreditGRPCInternalURL = internal
238261
output.CreditGRPCExternalURL = external
239-
case "ownership":
240-
output.OwnershipGRPCInternalURL = internal
241-
output.OwnershipGRPCExternalURL = external
242262
}
243263
}
244264

framework/components/dockercompose/billing_platform_service/docker-compose.yml

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,31 @@ services:
1010
condition: service_started
1111
restart: on-failure
1212
tty: true
13-
command: ["grpc-service"]
13+
command: ["grpc", "billing", "reserve"]
1414
environment:
15+
DISABLE_AUTH: true
1516
PROMETHEUS_PORT: 2112
1617
BILLING_SERVER_PORT: 2222
1718
CREDIT_RESERVATION_SERVER_PORT: 2223
18-
WORKFLOW_OWNERSHIP_PROOF_SERVER_PORT: 2257
1919
WORKFLOW_OWNERSHIP_PROOF_SERVER_HOST: 0.0.0.0
20+
MAINNET_WORKFLOW_REGISTRY_CHAIN_SELECTOR: ${MAINNET_WORKFLOW_REGISTRY_CHAIN_SELECTOR:-}
21+
TESTNET_WORKFLOW_REGISTRY_CHAIN_SELECTOR: ${MAINNET_WORKFLOW_REGISTRY_CHAIN_SELECTOR:-}
22+
MAINNET_WORKFLOW_REGISTRY_CONTRACT_ADDRESS: ${MAINNET_WORKFLOW_REGISTRY_CONTRACT_ADDRESS:-}
23+
TESTNET_WORKFLOW_REGISTRY_CONTRACT_ADDRESS: ${MAINNET_WORKFLOW_REGISTRY_CONTRACT_ADDRESS:-}
24+
MAINNET_WORKFLOW_REGISTRY_RPC_URL: ${MAINNET_WORKFLOW_REGISTRY_RPC_URL:-}
25+
TESTNET_WORKFLOW_REGISTRY_RPC_URL: ${MAINNET_WORKFLOW_REGISTRY_RPC_URL:-}
26+
MAINNET_WORKFLOW_REGISTRY_FINALITY_DEPTH: ${MAINNET_WORKFLOW_REGISTRY_FINALITY_DEPTH:-}
27+
KMS_PROOF_SIGNING_KEY_ID: ${KMS_PROOF_SIGNING_KEY_ID:-}
28+
VERIFIER_INITIAL_INTERVAL: ${VERIFIER_INITIAL_INTERVAL:-}
29+
VERIFIER_MAXIMUM_INTERVAL: ${VERIFIER_MAXIMUM_INTERVAL:-}
30+
LINKING_REQUEST_COOLDOWN: ${LINKING_REQUEST_COOLDOWN:-}
31+
MAINNET_CAPABILITIES_REGISTRY_CHAIN_SELECTOR: ${MAINNET_CAPABILITIES_REGISTRY_CHAIN_SELECTOR:-}
32+
TESTNET_CAPABILITIES_REGISTRY_CHAIN_SELECTOR: ${MAINNET_CAPABILITIES_REGISTRY_CHAIN_SELECTOR:-}
33+
MAINNET_CAPABILITIES_REGISTRY_CONTRACT_ADDRESS: ${MAINNET_CAPABILITIES_REGISTRY_CONTRACT_ADDRESS:-}
34+
MAINNET_CAPABILITIES_REGISTRY_RPC_URL: ${MAINNET_CAPABILITIES_REGISTRY_RPC_URL:-}
35+
TESTNET_CAPABILITIES_REGISTRY_RPC_URL: ${MAINNET_CAPABILITIES_REGISTRY_RPC_URL:-}
36+
MAINNET_CAPABILITIES_REGISTRY_FINALITY_DEPTH: ${MAINNET_CAPABILITIES_REGISTRY_FINALITY_DEPTH:-}
37+
TEST_OWNERS: ${TEST_OWNERS:-}
2038
STREAMS_API_URL: ${STREAMS_API_URL:-}
2139
STREAMS_API_KEY: ${STREAMS_API_KEY:-}
2240
STREAMS_API_SECRET: ${STREAMS_API_SECRET:-}
@@ -29,7 +47,6 @@ services:
2947
- "2112:2112"
3048
- "2222:2222"
3149
- "2223:2223"
32-
- "2257:2257"
3350
healthcheck:
3451
test: ["CMD", "grpc_health_probe", "-addr=localhost:2222"]
3552
interval: 200ms
@@ -47,7 +64,7 @@ services:
4764
POSTGRES_USER: postgres
4865
POSTGRES_PASSWORD: postgres
4966
ports:
50-
- "5432:5432"
67+
- "${POSTGRES_PORT:-5432}:5432"
5168
healthcheck:
5269
test: ["CMD","pg_isready","-U","${POSTGRES_USER}","-d","${POSTGRES_DB}","-h","${POSTGRES_HOST}"]
5370
interval: 5s
@@ -70,4 +87,7 @@ services:
7087
billing-platform-service:
7188
condition: service_started
7289
restart: on-failure
73-
command: ["db", "populate-data", "--environment=local"]
90+
command: ["db", "populate-data", "--environment=local", "--billing-client-url=billing-platform-service:2222", "--simple-linking", "--dsn=postgres://postgres:postgres@postgres:5432/billing_platform?sslmode=disable"]
91+
environment:
92+
TEST_OWNERS: ${TEST_OWNERS:-}
93+
MAINNET_CAPABILITIES_REGISTRY_CHAIN_SELECTOR: ${MAINNET_CAPABILITIES_REGISTRY_CHAIN_SELECTOR:-}

framework/components/dockercompose/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ require (
1212
github.com/google/go-github/v72 v72.0.0
1313
github.com/pkg/errors v0.9.1
1414
github.com/smartcontractkit/chainlink-testing-framework/framework v0.0.0-00010101000000-000000000000
15+
github.com/smartcontractkit/freeport v0.1.2
1516
github.com/testcontainers/testcontainers-go v0.37.0
1617
github.com/testcontainers/testcontainers-go/modules/compose v0.37.0
1718
golang.org/x/oauth2 v0.25.0

framework/components/dockercompose/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,8 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ
567567
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
568568
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 h1:JIAuq3EEf9cgbU6AtGPK4CTG3Zf6CKMNqf0MHTggAUA=
569569
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog=
570+
github.com/smartcontractkit/freeport v0.1.2 h1:xMZ0UFHmjfB4MwbDANae3RS7UKt7OJ0JVqhjPSXdKVk=
571+
github.com/smartcontractkit/freeport v0.1.2/go.mod h1:T4zH9R8R8lVWKfU7tUvYz2o2jMv1OpGCdpY2j2QZXzU=
570572
github.com/spdx/tools-golang v0.5.3 h1:ialnHeEYUC4+hkm5vJm4qz2x+oEJbS0mAMFrNXdQraY=
571573
github.com/spdx/tools-golang v0.5.3/go.mod h1:/ETOahiAo96Ob0/RAIBmFZw6XN0yTnyr/uFZm2NTMhI=
572574
github.com/spf13/cast v0.0.0-20150508191742-4d07383ffe94 h1:JmfC365KywYwHB946TTiQWEb8kqPY+pybPLoGE9GgVk=

0 commit comments

Comments
 (0)