Skip to content

Commit

Permalink
solana changes
Browse files Browse the repository at this point in the history
  • Loading branch information
skudasov committed Dec 23, 2024
1 parent bae283a commit 5e7ab4b
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 143 deletions.
7 changes: 4 additions & 3 deletions framework/components/blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

// Input is a blockchain network configuration params
type Input struct {
// Common EVM fields
Type string `toml:"type" validate:"required,oneof=anvil geth besu solana" envconfig:"net_type"`
Image string `toml:"image"`
PullImage bool `toml:"pull_image"`
Expand All @@ -16,10 +17,10 @@ type Input struct {
DockerCmdParamsOverrides []string `toml:"docker_cmd_params"`
Out *Output `toml:"out"`

// solana only fields
// Solana fields
// publickey to mint when solana-test-validator starts
PublicKey string `toml:"public_key"`
ContractsDir string `toml:"contracts_dir"`
PublicKey string `toml:"public_key" validate:"required"`
ContractsDir string `toml:"contracts_dir" validate:"required"`
}

// Output is a blockchain network output, ChainID and one or more nodes that forms the network
Expand Down
89 changes: 52 additions & 37 deletions framework/components/blockchain/solana.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"path/filepath"
"strconv"
"time"

Expand Down Expand Up @@ -31,30 +32,33 @@ var idJSONRaw = `

func defaultSolana(in *Input) {
if in.Image == "" {
in.Image = "solanalabs/solana:v1.18.26"
in.Image = "f4hrenh9it/solana"
}
if in.Port == "" {
in.Port = "8899"
in.Port = "8545"
}
if in.WSPort == "" {
in.WSPort = "8546"
}
}

func newSolana(in *Input) (*Output, error) {
defaultSolana(in)
ctx := context.Background()
wsPortNumberStr, err := wsPort(in.Port)
if err != nil {
return nil, err
}
//wsPortNumberStr, err := wsPort(in.Port)
//if err != nil {
// return nil, err
//}
framework.L.Info().Msg("Creating solana container")
bindPort := fmt.Sprintf("%s/tcp", in.Port)
containerName := framework.DefaultTCName("blockchain-solana-node")
wsBindPort := fmt.Sprintf("%s/tcp", wsPortNumberStr)
wsBindPort := fmt.Sprintf("%s/tcp", in.WSPort)

configYml, err := os.CreateTemp("", "config.yml")
if err != nil {
return nil, err
}
configYmlRaw = fmt.Sprintf(configYmlRaw, in.Port, wsPortNumberStr)
configYmlRaw = fmt.Sprintf(configYmlRaw, in.Port, in.WSPort)
_, err = configYml.WriteString(configYmlRaw)
if err != nil {
return nil, err
Expand All @@ -69,6 +73,12 @@ func newSolana(in *Input) (*Output, error) {
return nil, err
}

contractsDir, err := filepath.Abs(in.ContractsDir)
if err != nil {
return nil, err
}

framework.L.Info().Any("Port", in.Port).Any("WSPort", in.WSPort).Send()
req := testcontainers.ContainerRequest{
AlwaysPullImage: in.PullImage,
Image: in.Image,
Expand All @@ -83,35 +93,40 @@ func newSolana(in *Input) (*Output, error) {
WithStartupTimeout(30 * time.Second).
WithPollInterval(100 * time.Millisecond),
HostConfigModifier: func(h *container.HostConfig) {
h.PortBindings = framework.MapTheSamePort(bindPort)
h.PortBindings[nat.Port(wsBindPort)] = []nat.PortBinding{
{
HostIP: "0.0.0.0",
HostPort: wsBindPort,
h.PortBindings = nat.PortMap{
nat.Port(bindPort): []nat.PortBinding{
{
HostIP: "0.0.0.0",
HostPort: bindPort,
},
},
nat.Port(wsBindPort): []nat.PortBinding{
{
HostIP: "0.0.0.0",
HostPort: wsBindPort,
},
},
}
h.Mounts = append(h.Mounts, mount.Mount{
Type: mount.TypeBind,
Source: in.ContractsDir,
Source: contractsDir,
Target: "/programs",
ReadOnly: false,
})
},
LifecycleHooks: []testcontainers.ContainerLifecycleHooks{
Files: []testcontainers.ContainerFile{
{
PostStarts: []testcontainers.ContainerHook{
func(ctx context.Context, container testcontainers.Container) error {
err = container.CopyFileToContainer(ctx, configYml.Name(), "/root/.config/solana/cli/config.yml", 0644)
if err != nil {
return err
}
err = container.CopyFileToContainer(ctx, idJSON.Name(), "/root/.config/solana/cli/id.json", 0644)
return err
},
},
HostFilePath: configYml.Name(),
ContainerFilePath: "/data/config.yml",
FileMode: 0644,
},
{
HostFilePath: idJSON.Name(),
ContainerFilePath: "/data/id.json",
FileMode: 0644,
},
},
Entrypoint: []string{"sh", "-c", fmt.Sprintf("mkdir -p /root/.config/solana/cli && solana-test-validator --rpc-port %s --mint %s", in.Port, in.PublicKey)},
Entrypoint: []string{"sh", "-c", "solana-test-validator -C /data/config.yml --bind-address=0.0.0.0 --mint=" + in.PublicKey},
}

c, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
Expand All @@ -125,14 +140,14 @@ func newSolana(in *Input) (*Output, error) {
if err != nil {
return nil, err
}
mp, err := c.MappedPort(ctx, nat.Port(bindPort))
if err != nil {
return nil, err
}
wsmp, err := c.MappedPort(ctx, nat.Port(wsBindPort))
if err != nil {
return nil, err
}
//mp, err := c.MappedPort(ctx, nat.Port(bindPort))
//if err != nil {
// return nil, err
//}
//wsmp, err := c.MappedPort(ctx, nat.Port(wsBindPort))
//if err != nil {
// return nil, err
//}

framework.L.Info().Msg("Started Solana container")

Expand All @@ -143,9 +158,9 @@ func newSolana(in *Input) (*Output, error) {
ContainerName: containerName,
Nodes: []*Node{
{
HostWSUrl: fmt.Sprintf("ws://%s:%s", host, wsmp.Port()),
HostHTTPUrl: fmt.Sprintf("http://%s:%s", host, mp.Port()),
DockerInternalWSUrl: fmt.Sprintf("ws://%s:%s", containerName, wsPortNumberStr),
HostWSUrl: fmt.Sprintf("ws://%s:%s", host, in.Port),
HostHTTPUrl: fmt.Sprintf("http://%s:%s", host, in.WSPort),
DockerInternalWSUrl: fmt.Sprintf("ws://%s:%s", containerName, in.WSPort),
DockerInternalHTTPUrl: fmt.Sprintf("http://%s:%s", containerName, in.Port),
},
},
Expand Down
27 changes: 0 additions & 27 deletions framework/examples/myproject/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ require (
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/avast/retry-go v3.0.0+incompatible // indirect
github.com/awalterschulze/gographviz v2.0.3+incompatible // indirect
github.com/aws/aws-sdk-go v1.45.25 // indirect
Expand All @@ -51,7 +50,6 @@ require (
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.4 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.33.0 // indirect
github.com/aws/smithy-go v1.22.1 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.13.0 // indirect
Expand All @@ -60,19 +58,9 @@ require (
github.com/bytedance/sonic v1.12.3 // indirect
github.com/bytedance/sonic/loader v0.2.0 // indirect
github.com/c2h5oh/datasize v0.0.0-20220606134207-859f65c6625b // indirect
github.com/c9s/goprocinfo v0.0.0-20210130143923-c95fcf8c64a8 // indirect
github.com/catppuccin/go v0.2.0 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/charmbracelet/bubbles v0.20.0 // indirect
github.com/charmbracelet/bubbletea v1.1.1 // indirect
github.com/charmbracelet/huh v0.6.0 // indirect
github.com/charmbracelet/huh/spinner v0.0.0-20241028115900-20a4d21717a8 // indirect
github.com/charmbracelet/lipgloss v0.13.0 // indirect
github.com/charmbracelet/x/ansi v0.2.3 // indirect
github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0 // indirect
github.com/charmbracelet/x/term v0.2.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/coder/websocket v1.8.12 // indirect
Expand All @@ -83,7 +71,6 @@ require (
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cpuguy83/dockercfg v0.3.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c // indirect
github.com/crate-crypto/go-kzg-4844 v1.0.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
Expand All @@ -98,7 +85,6 @@ require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/edsrzf/mmap-go v1.1.0 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/ethereum/c-kzg-4844 v1.0.0 // indirect
github.com/ethereum/go-verkle v0.1.1-0.20240829091221-dffa7562dbe9 // indirect
github.com/facette/natsort v0.0.0-20181210072756-2cd4dd1e2dcb // indirect
Expand Down Expand Up @@ -173,18 +159,14 @@ require (
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/miekg/dns v1.1.56 // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.1 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
Expand All @@ -198,9 +180,6 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/oklog/ulid v1.3.1 // indirect
Expand All @@ -209,8 +188,6 @@ require (
github.com/opentracing-contrib/go-grpc v0.0.0-20210225150812-73cb765af46e // indirect
github.com/opentracing-contrib/go-stdlib v1.0.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
Expand All @@ -225,10 +202,8 @@ require (
github.com/prometheus/exporter-toolkit v0.10.1-0.20230714054209-2f4150c63f97 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/prometheus/prometheus v0.47.2-0.20231010075449-4b9c19fe5510 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/rs/zerolog v1.33.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
github.com/sercand/kuberesolver/v5 v5.1.1 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
Expand All @@ -249,9 +224,7 @@ require (
github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/urfave/cli/v2 v2.27.5 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.etcd.io/etcd/api/v3 v3.5.14 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.14 // indirect
Expand Down
Loading

0 comments on commit 5e7ab4b

Please sign in to comment.