Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes + test case for running simultaneous solana-test-validator #402

Merged
merged 1 commit into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/solana/client/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ import (
// SetupLocalSolNode sets up a local solana node via solana cli, and returns the url
func SetupLocalSolNode(t *testing.T) string {
port := utils.MustRandomPort(t)
faucetPort := utils.MustRandomPort(t)
url := "http://127.0.0.1:" + port
cmd := exec.Command("solana-test-validator",
"--reset",
"--rpc-port", port,
"--faucet-port", faucetPort,
)
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())
Expand All @@ -47,6 +51,9 @@ func SetupLocalSolNode(t *testing.T) string {
ready = true
break
}
if !ready {
t.Logf("Cmd output: %s\nCmd error: %s\n", stdOut.String(), stdErr.String())
}
require.True(t, ready)
return url
}
Expand Down
49 changes: 49 additions & 0 deletions pkg/solana/client/test_helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package client

import (
"testing"
"time"

"github.com/gagliardetto/solana-go"
"github.com/smartcontractkit/chainlink-relay/pkg/logger"
"github.com/smartcontractkit/chainlink-solana/pkg/solana/config"
"github.com/smartcontractkit/chainlink-solana/pkg/solana/db"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestSetupLocalSolNode_SimultaneousNetworks(t *testing.T) {
// run two networks
network0 := SetupLocalSolNode(t)
network1 := SetupLocalSolNode(t)

account := solana.NewWallet()
pubkey := account.PublicKey()

// client configs
requestTimeout := 5 * time.Second
lggr := logger.Test(t)
cfg := config.NewConfig(db.ChainCfg{}, lggr)

// check & fund address
checkFunded := func(t *testing.T, url string) {
// create client
c, err := NewClient(url, cfg, requestTimeout, lggr)
require.NoError(t, err)

// check init balance
bal, err := c.Balance(pubkey)
assert.NoError(t, err)
assert.Equal(t, uint64(0), bal)

FundTestAccounts(t, []solana.PublicKey{pubkey}, url)

// check end balance
bal, err = c.Balance(pubkey)
assert.NoError(t, err)
assert.Equal(t, uint64(100_000_000_000), bal) // once funds get sent to the system program it should be unrecoverable (so this number should remain > 0)
}

checkFunded(t, network0)
checkFunded(t, network1)
}