-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc536f0
commit 79c2961
Showing
4 changed files
with
227 additions
and
1 deletion.
There are no files selected for viewing
183 changes: 183 additions & 0 deletions
183
deployment/common/changeset/deploy_link_token_sol_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
package changeset_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"bytes" | ||
"fmt" | ||
"os/exec" | ||
|
||
// "github.com/stretchr/testify/require" | ||
// "go.uber.org/zap/zapcore" | ||
// "github.com/smartcontractkit/chainlink/deployment/common/changeset" | ||
// "github.com/smartcontractkit/chainlink/deployment/environment/memory" | ||
// "github.com/smartcontractkit/chainlink/v2/core/logger" | ||
"github.com/gagliardetto/solana-go" | ||
"github.com/gagliardetto/solana-go/rpc" | ||
"github.com/smartcontractkit/chainlink-ccip/chains/solana/contracts/tests/config" | ||
"github.com/smartcontractkit/chainlink-ccip/chains/solana/contracts/tests/utils" | ||
"github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings/external_program_cpi_stub" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var ( | ||
DefaultCommitment = rpc.CommitmentConfirmed | ||
) | ||
|
||
// deployProgram deploys a Solana program using the Solana CLI. | ||
func deployProgram(programFile string, keypairPath string) (string, error) { | ||
|
||
programKeyPair := "/Users/yashvardhan/chainlink-internal-integrations/solana/contracts/target/deploy/external_program_cpi_stub-keypair.json" | ||
// Construct the CLI command: solana program deploy | ||
cmd := exec.Command("solana", "program", "deploy", programFile, "--keypair", keypairPath, "--program-id", programKeyPair) | ||
|
||
// Capture the command output | ||
var stdout, stderr bytes.Buffer | ||
cmd.Stdout = &stdout | ||
cmd.Stderr = &stderr | ||
|
||
// Run the command | ||
if err := cmd.Run(); err != nil { | ||
return "", fmt.Errorf("error deploying program: %s: %s", err.Error(), stderr.String()) | ||
} | ||
|
||
// Parse and return the program ID | ||
output := stdout.String() | ||
return parseProgramID(output) | ||
} | ||
|
||
// parseProgramID parses the program ID from the deploy output. | ||
func parseProgramID(output string) (string, error) { | ||
// Look for the program ID in the CLI output | ||
// Example output: "Program Id: <PROGRAM_ID>" | ||
const prefix = "Program Id: " | ||
startIdx := bytes.Index([]byte(output), []byte(prefix)) | ||
if startIdx == -1 { | ||
return "", fmt.Errorf("failed to find program ID in output") | ||
} | ||
startIdx += len(prefix) | ||
endIdx := bytes.Index([]byte(output[startIdx:]), []byte("\n")) | ||
if endIdx == -1 { | ||
endIdx = len(output) | ||
} | ||
return output[startIdx : startIdx+endIdx], nil | ||
} | ||
|
||
// TestDeployProgram is a test for deploying the Solana program. | ||
func TestDeployProgram(t *testing.T) { | ||
// Path to your .so file and keypair file | ||
programFile := "/Users/yashvardhan/chainlink-internal-integrations/solana/contracts/target/deploy/external_program_cpi_stub.so" | ||
keypairPath := "/Users/yashvardhan/.config/solana/id.json" //wallet | ||
// keypairPath := "/Users/yashvardhan/chainlink-internal-integrations/solana/contracts/target/deploy/external_program_cpi_stub-keypair.json" | ||
|
||
// Deploy the program | ||
programID, err := deployProgram(programFile, keypairPath) | ||
if err != nil { | ||
t.Fatalf("Failed to deploy program: %v", err) | ||
} | ||
|
||
// // Verify the program ID (simple check for non-empty string) | ||
if programID == "" { | ||
t.Fatalf("Program ID is empty") | ||
} | ||
|
||
t.Logf("programID %s", programID) | ||
|
||
ExternalCpiStubProgram := solana.MustPublicKeyFromBase58("EQPCTRibpsPcQNb464QVBkS1PkFfuK8kYdpd5Y17HaGh") | ||
StubAccountPDA, _, _ := solana.FindProgramAddress([][]byte{[]byte("u8_value")}, ExternalCpiStubProgram) | ||
t.Logf("StubAccountPDA %s", StubAccountPDA) | ||
privateKey, _ := solana.PrivateKeyFromSolanaKeygenFile(keypairPath) | ||
publicKey := privateKey.PublicKey() | ||
t.Logf("publicKey from private key %s", publicKey) | ||
solanaGoClient := rpc.New("http://127.0.0.1:8899") | ||
|
||
external_program_cpi_stub.SetProgramID(ExternalCpiStubProgram) | ||
|
||
ix, err := external_program_cpi_stub.NewInitializeInstruction( | ||
StubAccountPDA, | ||
publicKey, | ||
solana.SystemProgramID, // 1111111 | ||
).ValidateAndBuild() | ||
|
||
// utils.SendAndConfirm(context.Background(), t, solanaGoClient, []solana.Instruction{ix}, privateKey, config.DefaultCommitment) | ||
|
||
// ix, _ := external_program_cpi_stub.NewEmptyInstruction().ValidateAndBuild() | ||
require.NoError(t, err) | ||
utils.SendAndConfirm(context.Background(), t, solanaGoClient, []solana.Instruction{ix}, privateKey, config.DefaultCommitment) | ||
|
||
t.Logf("Program deployed successfully with ID: %s", programID) | ||
} | ||
|
||
// func spinUpDevNet(t *testing.T) (string, string) { | ||
// t.Helper() | ||
// port := "8899" | ||
// portInt, _ := strconv.Atoi(port) | ||
|
||
// faucetPort := "8877" | ||
// url := "http://127.0.0.1:" + port | ||
// wsURL := "ws://127.0.0.1:" + strconv.Itoa(portInt+1) | ||
|
||
// args := []string{ | ||
// "--reset", | ||
// "--rpc-port", port, | ||
// "--faucet-port", faucetPort, | ||
// "--ledger", t.TempDir(), | ||
// } | ||
|
||
// cmd := exec.Command("solana-test-validator", args...) | ||
|
||
// var stdErr bytes.Buffer | ||
// cmd.Stderr = &stdErr | ||
// var stdOut bytes.Buffer | ||
// cmd.Stdout = &stdOut | ||
// require.NoError(t, cmd.Start()) | ||
// t.Cleanup(func() { | ||
// assert.NoError(t, cmd.Process.Kill()) | ||
// if err2 := cmd.Wait(); assert.Error(t, err2) { | ||
// if !assert.Contains(t, err2.Error(), "signal: killed", cmd.ProcessState.String()) { | ||
// t.Logf("solana-test-validator\n stdout: %s\n stderr: %s", stdOut.String(), stdErr.String()) | ||
// } | ||
// } | ||
// }) | ||
|
||
// // Wait for api server to boot | ||
// var ready bool | ||
// for i := 0; i < 30; i++ { | ||
// time.Sleep(time.Second) | ||
// client := rpc.New(url) | ||
// out, err := client.GetHealth(tests.Context(t)) | ||
// if err != nil || out != rpc.HealthOk { | ||
// t.Logf("API server not ready yet (attempt %d)\n", i+1) | ||
// continue | ||
// } | ||
// ready = true | ||
// break | ||
// } | ||
// if !ready { | ||
// t.Logf("Cmd output: %s\nCmd error: %s\n", stdOut.String(), stdErr.String()) | ||
// } | ||
// require.True(t, ready) | ||
|
||
// return url, wsURL | ||
// } | ||
|
||
// func getRpcClient(t *testing.T) *rpc.Client { | ||
// url, _ := spinUpDevNet(t) | ||
// return rpc.New(url) | ||
// } | ||
|
||
// func TestTokenDeploy(t *testing.T) { | ||
// keypairPath := "/Users/yashvardhan/.config/solana/id.json" //wallet | ||
// adminPrivateKey, _ := solana.PrivateKeyFromSolanaKeygenFile(keypairPath) | ||
// adminPublicKey := adminPrivateKey.PublicKey() | ||
// decimals := uint8(0) | ||
// // amount := uint64(1000) | ||
// solanaGoClient := rpc.New("http://127.0.0.1:8899") | ||
// // solanaGoClient := getRpcClient(t) | ||
// mint, _ := solana.NewRandomPrivateKey() | ||
// mintPublicKey := mint.PublicKey() | ||
// instructions, err := utils.CreateToken(context.Background(), config.Token2022Program, mintPublicKey, adminPublicKey, decimals, solanaGoClient, DefaultCommitment) | ||
// utils.SendAndConfirm(context.Background(), t, solanaGoClient, instructions, adminPrivateKey, DefaultCommitment, utils.AddSigners(mint)) | ||
// require.NoError(t, err) | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters