From bf0560eb096d8ca1cd71f4413b5221b01c2b11fd Mon Sep 17 00:00:00 2001 From: Graham Goh Date: Mon, 30 Dec 2024 14:51:23 +1100 Subject: [PATCH] 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 --- framework/components/blockchain/blockchain.go | 3 +++ framework/components/blockchain/solana.go | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/framework/components/blockchain/blockchain.go b/framework/components/blockchain/blockchain.go index c97c971c0..142ddd31d 100644 --- a/framework/components/blockchain/blockchain.go +++ b/framework/components/blockchain/blockchain.go @@ -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 diff --git a/framework/components/blockchain/solana.go b/framework/components/blockchain/solana.go index 050b0090e..91fc6f409 100644 --- a/framework/components/blockchain/solana.go +++ b/framework/components/blockchain/solana.go @@ -6,6 +6,7 @@ import ( "os" "path/filepath" "strconv" + "strings" "time" "github.com/docker/docker/api/types/container" @@ -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, @@ -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{