Skip to content
Draft
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
11 changes: 10 additions & 1 deletion framework/components/blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (
TypeSui = "sui"
TypeTron = "tron"
TypeTon = "ton"
TypeCanton = "canton"
)

// Blockchain node family
Expand All @@ -30,12 +31,13 @@ const (
FamilySui = "sui"
FamilyTron = "tron"
FamilyTon = "ton"
FamilyCanton = "canton"
)

// Input is a blockchain network configuration params
type Input struct {
// Common EVM fields
Type string `toml:"type" validate:"required,oneof=anvil geth besu solana aptos tron sui ton" envconfig:"net_type"`
Type string `toml:"type" validate:"required,oneof=anvil geth besu solana aptos tron sui ton canton" envconfig:"net_type"`
Image string `toml:"image"`
PullImage bool `toml:"pull_image"`
Port string `toml:"port"`
Expand All @@ -60,6 +62,9 @@ type Input struct {
// Sui specific: faucet port for funding accounts
FaucetPort string `toml:"faucet_port"`

// Canton specific
NumberOfCantonValidators int `toml:"number_of_canton_validators"`

// GAPv2 specific params
HostNetworkMode bool `toml:"host_network_mode"`
CertificatesPath string `toml:"certificates_path"`
Expand Down Expand Up @@ -122,6 +127,8 @@ func NewWithContext(ctx context.Context, in *Input) (*Output, error) {
out, err = newAnvilZksync(ctx, in)
case TypeTon:
out, err = newTon(ctx, in)
case TypeCanton:
out, err = newCanton(ctx, in)
default:
return nil, fmt.Errorf("blockchain type is not supported or empty, must be 'anvil' or 'geth'")
}
Expand All @@ -148,6 +155,8 @@ func TypeToFamily(t string) (ChainFamily, error) {
return ChainFamily(FamilyTron), nil
case TypeTon:
return ChainFamily(FamilyTon), nil
case TypeCanton:
return ChainFamily(FamilyCanton), nil
default:
return "", fmt.Errorf("blockchain type is not supported or empty: %s", t)
}
Expand Down
95 changes: 95 additions & 0 deletions framework/components/blockchain/canton.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package blockchain

import (
"context"
"fmt"

"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/network"

"github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain/canton"
)

func newCanton(ctx context.Context, in *Input) (*Output, error) {
if in.NumberOfCantonValidators >= 100 {
return nil, fmt.Errorf("number of validators too high: %d, max is 99", in.NumberOfCantonValidators)
}

// TODO - remove debug prints
fmt.Println("Starting Canton blockchain node...")
fmt.Println("Creating network...")
dockerNetwork, err := network.New(ctx, network.WithAttachable())
if err != nil {
return nil, err
}
fmt.Println("Network created:", dockerNetwork.Name)

// Set up Postgres container
postgresReq := canton.PostgresContainerRequest(in.NumberOfCantonValidators, dockerNetwork.Name)
fmt.Printf("Starting postgres container %s...\n", postgresReq.Name)
c, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: postgresReq,
Started: true,
})
if err != nil {
return nil, err
}
_ = c

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do _, err := ... on line 30 to avoid doing this

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly for other lines

fmt.Println("Postgres container started")

// Set up Canton container
cantonReq := canton.CantonContainerRequest(dockerNetwork.Name, in.NumberOfCantonValidators, in.Image)
fmt.Printf("Starting canton container %s...\n", cantonReq.Name)
cantonContainer, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: cantonReq,
Started: true,
})
if err != nil {
return nil, err
}
_ = cantonContainer
fmt.Println("Canton container started")

// Set up Splice container
spliceReq := canton.SpliceContainerRequest(dockerNetwork.Name, in.NumberOfCantonValidators, in.Image)
fmt.Printf("Starting splice container %s...\n", spliceReq.Name)
spliceContainer, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: spliceReq,
Started: true,
})
if err != nil {
return nil, err
}
_ = spliceContainer
fmt.Println("Splice container started")

// Set up Nginx container
nginxReq := canton.NginxContainerRequest(dockerNetwork.Name, in.NumberOfCantonValidators, in.Port)
fmt.Printf("Starting nginx container %s...\n", nginxReq.Name)
nginxContainer, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: nginxReq,
Started: true,
})
if err != nil {
return nil, err
}
fmt.Println("Nginx container started")

host, err := nginxContainer.Host(ctx)
if err != nil {
return nil, err
}

return &Output{
UseCache: false,
Type: in.Type,
Family: FamilyCanton,
ContainerName: nginxReq.Name,
Nodes: []*Node{
{
ExternalHTTPUrl: fmt.Sprintf("http://%s:%s", host, in.Port),
InternalHTTPUrl: fmt.Sprintf("http://%s:%s", nginxReq.Name, in.Port), // TODO - should be docker-internal port instead?
},
},
}, nil
}
Loading
Loading