Skip to content

Commit fb70961

Browse files
[DPA-1458]: feat(solana): auto deploy programs (#1519)
* 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 * 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. Inspired from https://github.com/smartcontractkit/chainlink-ccip/blob/609f7b0c9734b3cfc1d1a1aea0fd1ddf4c90bd0c/chains/solana/contracts/tests/testutils/anchor.go#L72-L72 JIRA: https://smartcontract-it.atlassian.net/browse/DPA-1458
1 parent 67350e9 commit fb70961

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ 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
21+
# To deploy a solana program, we can provide a mapping of program name to program id.
22+
# The program name has to match the name of the .so file in the contracts_dir directory.
23+
# This example assumes there is a mcm.so in the mounted contracts_dir directory
24+
# value is the program_id to set for the deployed program, any valid public key can be used here.
25+
# this allows lookup via program_id during testing.
26+
# Alternative, we can use `solana deploy` instead of this field to deploy a program, but
27+
# program_id will be auto generated.
28+
[blockchain_a.solana_programs]
29+
mcm = "6UmMZr5MEqiKWD5jqTJd1WCR5kT8oZuFYBLJFi1o6GQX"
30+
1931
```
2032

2133
## Usage

framework/components/blockchain/blockchain.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ 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+
// there needs to be a matching .so file in contracts_dir
27+
SolanaPrograms map[string]string `toml:"solana_programs"`
2428
}
2529

2630
// 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)