diff --git a/pkg/solana/client/test_helpers.go b/pkg/solana/client/test_helpers.go index a9d031098..e763607df 100644 --- a/pkg/solana/client/test_helpers.go +++ b/pkg/solana/client/test_helpers.go @@ -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()) @@ -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 } diff --git a/pkg/solana/client/test_helpers_test.go b/pkg/solana/client/test_helpers_test.go new file mode 100644 index 000000000..c303888f0 --- /dev/null +++ b/pkg/solana/client/test_helpers_test.go @@ -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) +}