Skip to content

Commit

Permalink
Solana sanity check
Browse files Browse the repository at this point in the history
  • Loading branch information
connorwstein committed Aug 6, 2024
1 parent 75916f8 commit 5c38c83
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 4 deletions.
21 changes: 21 additions & 0 deletions core/capabilities/ccip/deployment/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/token_admin_registry"
)

type Proposal struct {
}

func (p Proposal) String() string {
return ""
}

func GenerateAcceptOwnershipProposal(e environment.Environment, state CCIPOnChainState) Proposal {
return Proposal{}
}

// TODO: pull up to environment pkg
func deployContract(
lggr logger.Logger,
Expand All @@ -36,6 +47,16 @@ func deployContract(
return contractAddr, nil
}

type CCIPSpec struct{}

func (s CCIPSpec) String() string {
return ""
}

func GenerateJobSpecs(capReg common.Address) CCIPSpec {
return CCIPSpec{}
}

// TODO: Likely we'll want to further parameterize the deployment
// For example a list of contracts to skip deploying if they already exist.
// Or mock vs real RMN.
Expand Down
101 changes: 101 additions & 0 deletions core/capabilities/ccip/deployment/deploy_solana_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
//go:build solana
// +build solana

package deployment

import (
"context"
"fmt"
"testing"
"time"

"github.com/gagliardetto/solana-go"
"github.com/gagliardetto/solana-go/programs/system"
"github.com/gagliardetto/solana-go/rpc"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func confirmTx(c *rpc.Client, ctx context.Context, sig solana.Signature) error {
var confirmed bool
for i := 0; i < 30; i++ {
block, err := c.GetConfirmedTransactionWithOpts(ctx, sig, &rpc.GetTransactionOpts{
// Must be finalized for state to actually change.
Commitment: rpc.CommitmentConfirmed,
})
if err != nil {
fmt.Println(err)
time.Sleep(1 * time.Second)
continue
}
fmt.Println("Confirmed!", block)
confirmed = true
break
}
if !confirmed {
return fmt.Errorf("transaction not confirmed")
}
return nil
}

func TestSolanaCreateAccount(t *testing.T) {
t.Skip()
// Note that uploading a program is fairly complex:
// 2 options
// - Replicate https://github.com/solana-labs/solana/blob/7409d9d2687fba21078a745842c25df805cdf105/cli/src/program.rs#L2086
// using solana-go. Not particularly difficult but a little bit of work.
// - Shell out to solana go for deployment.
ctx := context.Background()

// solana-test-validator
client := rpc.New("http://127.0.0.1:8899")

// Fund a deployer
deployer := solana.NewWallet()
airdrop, err := client.RequestAirdrop(ctx, deployer.PublicKey(), 10*solana.LAMPORTS_PER_SOL, rpc.CommitmentConfirmed)
require.NoError(t, err)
require.NoError(t, confirmTx(client, ctx, airdrop))
b, err := client.GetBalance(ctx, deployer.PublicKey(), rpc.CommitmentFinalized)
require.NoError(t, err)
assert.Equal(t, 10*solana.LAMPORTS_PER_SOL, b.Value)

// Create
programAccount := solana.NewWallet()
createInst, err := system.NewCreateAccountInstruction(
solana.LAMPORTS_PER_SOL, // If you don't fund the account it won't exist
9,
solana.SystemProgramID,
deployer.PublicKey(),
programAccount.PublicKey()).ValidateAndBuild()
require.NoError(t, err)

bh, err := client.GetRecentBlockhash(ctx, rpc.CommitmentFinalized)
require.NoError(t, err)
programAccountTx, err := solana.NewTransaction(
[]solana.Instruction{
createInst, // Create the program account
},
bh.Value.Blockhash,
)
require.NoError(t, err)
fmt.Println(programAccountTx)
sig, err := programAccountTx.Sign(func(key solana.PublicKey) *solana.PrivateKey {
if key.Equals(deployer.PublicKey()) {
return &deployer.PrivateKey
} else if key.Equals(programAccount.PublicKey()) {
return &programAccount.PrivateKey
}
panic("unauthorized sign")
})
require.NoError(t, err)
programAccountTx.Signatures = sig
require.NoError(t, programAccountTx.VerifySignatures())
txSig, err := client.SendTransaction(ctx, programAccountTx)
require.NoError(t, err)
fmt.Printf("Program deployment transaction signature: %s\n", txSig.String())
// Program account will not exist without this
require.NoError(t, confirmTx(client, ctx, txSig))
acct, err := client.GetAccountInfo(ctx, programAccount.PublicKey())
require.NoError(t, err)
fmt.Println(acct.Value.Data)
}
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ require (
github.com/cometbft/cometbft v0.37.5
github.com/cosmos/cosmos-sdk v0.47.11
github.com/danielkov/gin-helmet v0.0.0-20171108135313-1387e224435e
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/deckarep/golang-set/v2 v2.6.0
github.com/dominikbraun/graph v0.23.0
github.com/esote/minmaxheap v1.0.0
github.com/ethereum/go-ethereum v1.13.8
github.com/fatih/color v1.16.0
github.com/fxamacker/cbor/v2 v2.5.0
github.com/gagliardetto/binary v0.7.7
github.com/gagliardetto/gofuzz v1.2.2
github.com/gagliardetto/solana-go v1.8.4
github.com/gagliardetto/treeout v0.1.4
github.com/getsentry/sentry-go v0.23.0
github.com/gin-contrib/cors v1.5.0
github.com/gin-contrib/expvar v0.0.1
Expand Down Expand Up @@ -116,6 +120,7 @@ require (
google.golang.org/protobuf v1.34.2
gopkg.in/guregu/null.v4 v4.0.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
gotest.tools/v3 v3.5.1
k8s.io/utils v0.0.0-20230711102312-30195339c3c7
)

Expand Down Expand Up @@ -181,7 +186,6 @@ require (
github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 // indirect
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/dfuse-io/logging v0.0.0-20210109005628-b97a57253f70 // indirect
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
Expand All @@ -193,8 +197,6 @@ require (
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gagliardetto/binary v0.7.7 // indirect
github.com/gagliardetto/treeout v0.1.4 // indirect
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 // indirect
github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 // indirect
github.com/gedex/inflector v0.0.0-20170307190818-16278e9db813 // indirect
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1674,7 +1674,6 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU=
gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down

0 comments on commit 5c38c83

Please sign in to comment.