Skip to content

Commit 285143a

Browse files
committed
basic example, get slot
1 parent 5e7ab4b commit 285143a

File tree

4 files changed

+32
-39
lines changed

4 files changed

+32
-39
lines changed

framework/components/blockchain/solana.go

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,19 @@ func defaultSolana(in *Input) {
3737
if in.Port == "" {
3838
in.Port = "8545"
3939
}
40-
if in.WSPort == "" {
41-
in.WSPort = "8546"
42-
}
4340
}
4441

4542
func newSolana(in *Input) (*Output, error) {
4643
defaultSolana(in)
4744
ctx := context.Background()
48-
//wsPortNumberStr, err := wsPort(in.Port)
49-
//if err != nil {
50-
// return nil, err
51-
//}
52-
framework.L.Info().Msg("Creating solana container")
45+
containerName := framework.DefaultTCName("blockchain-node")
46+
// Solana do not allow to set ws port, it just uses --rpc-port=N and sets WS as N+1 automatically
5347
bindPort := fmt.Sprintf("%s/tcp", in.Port)
54-
containerName := framework.DefaultTCName("blockchain-solana-node")
48+
pp, err := strconv.Atoi(in.Port)
49+
if err != nil {
50+
return nil, fmt.Errorf("in.Port is not a number")
51+
}
52+
in.WSPort = strconv.Itoa(pp + 1)
5553
wsBindPort := fmt.Sprintf("%s/tcp", in.WSPort)
5654

5755
configYml, err := os.CreateTemp("", "config.yml")
@@ -78,7 +76,6 @@ func newSolana(in *Input) (*Output, error) {
7876
return nil, err
7977
}
8078

81-
framework.L.Info().Any("Port", in.Port).Any("WSPort", in.WSPort).Send()
8279
req := testcontainers.ContainerRequest{
8380
AlwaysPullImage: in.PullImage,
8481
Image: in.Image,
@@ -117,16 +114,16 @@ func newSolana(in *Input) (*Output, error) {
117114
Files: []testcontainers.ContainerFile{
118115
{
119116
HostFilePath: configYml.Name(),
120-
ContainerFilePath: "/data/config.yml",
117+
ContainerFilePath: "/root/.config/solana/cli/config.yml",
121118
FileMode: 0644,
122119
},
123120
{
124121
HostFilePath: idJSON.Name(),
125-
ContainerFilePath: "/data/id.json",
122+
ContainerFilePath: "/root/.config/solana/cli/id.json",
126123
FileMode: 0644,
127124
},
128125
},
129-
Entrypoint: []string{"sh", "-c", "solana-test-validator -C /data/config.yml --bind-address=0.0.0.0 --mint=" + in.PublicKey},
126+
Entrypoint: []string{"sh", "-c", fmt.Sprintf("mkdir -p /root/.config/solana/cli && solana-test-validator --rpc-port %s --mint %s", in.Port, in.PublicKey)},
130127
}
131128

132129
c, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
@@ -140,39 +137,18 @@ func newSolana(in *Input) (*Output, error) {
140137
if err != nil {
141138
return nil, err
142139
}
143-
//mp, err := c.MappedPort(ctx, nat.Port(bindPort))
144-
//if err != nil {
145-
// return nil, err
146-
//}
147-
//wsmp, err := c.MappedPort(ctx, nat.Port(wsBindPort))
148-
//if err != nil {
149-
// return nil, err
150-
//}
151-
152-
framework.L.Info().Msg("Started Solana container")
153140

154141
return &Output{
155142
UseCache: true,
156-
Family: "non-evm",
157-
ChainID: in.ChainID,
143+
Family: "solana",
158144
ContainerName: containerName,
159145
Nodes: []*Node{
160146
{
161-
HostWSUrl: fmt.Sprintf("ws://%s:%s", host, in.Port),
162-
HostHTTPUrl: fmt.Sprintf("http://%s:%s", host, in.WSPort),
147+
HostWSUrl: fmt.Sprintf("ws://%s:%s", host, in.WSPort),
148+
HostHTTPUrl: fmt.Sprintf("http://%s:%s", host, in.Port),
163149
DockerInternalWSUrl: fmt.Sprintf("ws://%s:%s", containerName, in.WSPort),
164150
DockerInternalHTTPUrl: fmt.Sprintf("http://%s:%s", containerName, in.Port),
165151
},
166152
},
167153
}, nil
168154
}
169-
170-
func wsPort(rpcPort string) (string, error) {
171-
wsPortNumber, err := strconv.Atoi(rpcPort)
172-
if err != nil {
173-
return "", fmt.Errorf("failed to convert port to integer: %w", err)
174-
}
175-
wsPortNumber += 1 // Increment by 1
176-
wsPortNumberStr := strconv.Itoa(wsPortNumber)
177-
return wsPortNumberStr, nil
178-
}

framework/examples/myproject/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ replace (
1010
)
1111

1212
require (
13+
github.com/blocto/solana-go-sdk v1.30.0
1314
github.com/ethereum/go-ethereum v1.14.11
1415
github.com/go-resty/resty/v2 v2.15.3
1516
github.com/smartcontractkit/chainlink-testing-framework/framework v0.0.0-00010101000000-000000000000
@@ -21,6 +22,7 @@ require (
2122

2223
require (
2324
dario.cat/mergo v1.0.1 // indirect
25+
filippo.io/edwards25519 v1.0.0-rc.1 // indirect
2426
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.1 // indirect
2527
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.1 // indirect
2628
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.1 // indirect
@@ -180,6 +182,7 @@ require (
180182
github.com/modern-go/reflect2 v1.0.2 // indirect
181183
github.com/montanaflynn/stats v0.7.1 // indirect
182184
github.com/morikuni/aec v1.0.0 // indirect
185+
github.com/mr-tron/base58 v1.2.0 // indirect
183186
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
184187
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
185188
github.com/oklog/ulid v1.3.1 // indirect

framework/examples/myproject/go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
3333
dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
3434
dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
3535
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
36+
filippo.io/edwards25519 v1.0.0-rc.1 h1:m0VOOB23frXZvAOK44usCgLWvtsxIoMCTBGJZlpmGfU=
37+
filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
3638
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9vkmnHYOMsOr4WLk+Vo07yKIzd94sVoIqshQ4bU=
3739
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8=
3840
github.com/Azure/azure-sdk-for-go v65.0.0+incompatible h1:HzKLt3kIwMm4KeJYTdx9EbjRYTySD/t8i1Ee/W5EGXw=
@@ -155,6 +157,8 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r
155157
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
156158
github.com/bits-and-blooms/bitset v1.13.0 h1:bAQ9OPNFYbGHV6Nez0tmNI0RiEu7/hxlYJRUA0wFAVE=
157159
github.com/bits-and-blooms/bitset v1.13.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8=
160+
github.com/blocto/solana-go-sdk v1.30.0 h1:GEh4GDjYk1lMhV/hqJDCyuDeCuc5dianbN33yxL88NU=
161+
github.com/blocto/solana-go-sdk v1.30.0/go.mod h1:Xoyhhb3hrGpEQ5rJps5a3OgMwDpmEhrd9bgzFKkkwMs=
158162
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
159163
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
160164
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U=
@@ -718,6 +722,8 @@ github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8
718722
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
719723
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
720724
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
725+
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
726+
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
721727
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
722728
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
723729
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=

framework/examples/myproject/smoke_solana_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package examples
22

33
import (
4+
"context"
5+
"fmt"
46
"github.com/smartcontractkit/chainlink-testing-framework/framework"
57
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain"
68
ns "github.com/smartcontractkit/chainlink-testing-framework/framework/components/simple_node_set"
79
"github.com/stretchr/testify/require"
810
"testing"
11+
"time"
12+
13+
"github.com/blocto/solana-go-sdk/client"
914
)
1015

1116
type CfgSolana struct {
@@ -21,7 +26,10 @@ func TestSmokeSolana(t *testing.T) {
2126
require.NoError(t, err)
2227

2328
t.Run("test something", func(t *testing.T) {
24-
_ = bc
25-
// ...
29+
time.Sleep(2 * time.Second)
30+
c := client.NewClient(bc.Nodes[0].HostHTTPUrl)
31+
latestSlot, err := c.GetSlotWithConfig(context.Background(), client.GetSlotConfig{Commitment: "processed"})
32+
require.NoError(t, err)
33+
fmt.Printf("Latest slot: %v\n", latestSlot)
2634
})
2735
}

0 commit comments

Comments
 (0)