Skip to content

Commit

Permalink
feat(solana): auto deploy programs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
graham-chainlink committed Dec 30, 2024
1 parent 67350e9 commit bf0560e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions framework/components/blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ type Input struct {
// publickey to mint when solana-test-validator starts
PublicKey string `toml:"public_key"`
ContractsDir string `toml:"contracts_dir"`
// programs to deploy on solana-test-validator start
// a map of program name to program id
SolanaPrograms map[string]string `toml:"solana_programs"`
}

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

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

flags := []string{}
for k, v := range in.SolanaPrograms {
flags = append(flags, "--upgradeable-program", v, filepath.Join("/programs", k+".so"), in.PublicKey)
}
args := append([]string{
"--reset",
"--rpc-port", in.Port,
"--mint", in.PublicKey,
}, flags...)

req := testcontainers.ContainerRequest{
AlwaysPullImage: in.PullImage,
Image: in.Image,
Expand Down Expand Up @@ -127,7 +138,7 @@ func newSolana(in *Input) (*Output, error) {
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", fmt.Sprintf("mkdir -p /root/.config/solana/cli && solana-test-validator %s", strings.Join(args, " "))},
}

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

0 comments on commit bf0560e

Please sign in to comment.