Skip to content

Commit 4fd8d9a

Browse files
feat(solana): auto deploy programs
By using `--upgradeable-program` , we can auto deploy programs detected in the mounted path `/programs`, this reduces the need for consumer of this library to have to deploy the programs themselves, especially with go sdk where deploying a program is not straightforward and involves a decent amount of code, the alternative is to ssh into the docker container and run `solana deploy ...` but this involves an extra step. JIRA: https://smartcontract-it.atlassian.net/browse/DPA-1458
1 parent 67350e9 commit 4fd8d9a

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

book/src/framework/components/blockchains/solana.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ arm64 f4hrenh9it/solana:latest - used locally
1616
contracts_dir = "."
1717
# optional, in case you need some custom image
1818
# image = "solanalabs/solana:v1.18.26"
19+
20+
# optional, in case you need to deploy some programs
21+
# this example assumes there is a mcm.so in the mounted contracts_dir directory
22+
# value is the program id to set for the deployed program instead of auto generating
23+
# useful for deterministic testing
24+
[blockchain_a.solana_programs]
25+
mcm = "6UmMZr5MEqiKWD5jqTJd1WCR5kT8oZuFYBLJFi1o6GQX"
26+
1927
```
2028

2129
## Usage

framework/components/blockchain/blockchain.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ type Input struct {
2121
// publickey to mint when solana-test-validator starts
2222
PublicKey string `toml:"public_key"`
2323
ContractsDir string `toml:"contracts_dir"`
24+
// programs to deploy on solana-test-validator start
25+
// a map of program name to program id
26+
SolanaPrograms map[string]string `toml:"solana_programs"`
2427
}
2528

2629
// Output is a blockchain network output, ChainID and one or more nodes that forms the network

framework/components/blockchain/solana.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"path/filepath"
88
"strconv"
9+
"strings"
910
"time"
1011

1112
"github.com/docker/docker/api/types/container"
@@ -80,6 +81,16 @@ func newSolana(in *Input) (*Output, error) {
8081
return nil, err
8182
}
8283

84+
flags := []string{}
85+
for k, v := range in.SolanaPrograms {
86+
flags = append(flags, "--upgradeable-program", v, filepath.Join("/programs", k+".so"), in.PublicKey)
87+
}
88+
args := append([]string{
89+
"--reset",
90+
"--rpc-port", in.Port,
91+
"--mint", in.PublicKey,
92+
}, flags...)
93+
8394
req := testcontainers.ContainerRequest{
8495
AlwaysPullImage: in.PullImage,
8596
Image: in.Image,
@@ -127,7 +138,7 @@ func newSolana(in *Input) (*Output, error) {
127138
FileMode: 0644,
128139
},
129140
},
130-
Entrypoint: []string{"sh", "-c", fmt.Sprintf("mkdir -p /root/.config/solana/cli && solana-test-validator --rpc-port %s --mint %s", in.Port, in.PublicKey)},
141+
Entrypoint: []string{"sh", "-c", fmt.Sprintf("mkdir -p /root/.config/solana/cli && solana-test-validator %s", strings.Join(args, " "))},
131142
}
132143

133144
c, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{

framework/examples/myproject/smoke_solana.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33
type = "solana"
44
public_key = "9n1pyVGGo6V4mpiSDMVay5As9NurEkY283wwRk1Kto2C"
55
contracts_dir = "."
6-
image = "solanalabs/solana:v1.18.26"
6+
image = "solanalabs/solana:v1.18.26"
7+
8+
[blockchain_a.solana_programs]
9+
mcm = "6UmMZr5MEqiKWD5jqTJd1WCR5kT8oZuFYBLJFi1o6GQX"

0 commit comments

Comments
 (0)