From 38b5e245f5bf426b8038438b6d2d53230bccfdc6 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Mon, 11 Sep 2023 18:08:03 -0400 Subject: [PATCH 1/2] fix(rpc): actually use RPC in CLI tests; add icmd and assertCmd for better error reporting (#942) --------- Co-authored-by: Alfonso Acosta --- cmd/soroban-cli/src/rpc/mod.rs | 9 ++- cmd/soroban-rpc/internal/test/cli_test.go | 68 ++++++++++++++--------- go.mod | 5 +- go.sum | 5 ++ 4 files changed, 59 insertions(+), 28 deletions(-) diff --git a/cmd/soroban-cli/src/rpc/mod.rs b/cmd/soroban-cli/src/rpc/mod.rs index 0e9796482..e817b2a38 100644 --- a/cmd/soroban-cli/src/rpc/mod.rs +++ b/cmd/soroban-cli/src/rpc/mod.rs @@ -4,13 +4,13 @@ use jsonrpsee_core::params::ObjectParams; use jsonrpsee_core::{self, client::ClientT, rpc_params}; use jsonrpsee_http_client::{HeaderMap, HttpClient, HttpClientBuilder}; use serde_aux::prelude::{deserialize_default_from_null, deserialize_number_from_string}; -use soroban_env_host::xdr::DepthLimitedRead; use soroban_env_host::xdr::{ self, AccountEntry, AccountId, ContractDataEntry, DiagnosticEvent, Error as XdrError, LedgerEntryData, LedgerFootprint, LedgerKey, LedgerKeyAccount, PublicKey, ReadXdr, SorobanAuthorizationEntry, SorobanResources, Transaction, TransactionEnvelope, TransactionMeta, TransactionMetaV3, TransactionResult, TransactionV1Envelope, Uint256, VecM, WriteXdr, }; +use soroban_env_host::xdr::{DepthLimitedRead, SorobanAuthorizedFunction}; use soroban_sdk::token; use std::{ fmt::Display, @@ -662,7 +662,12 @@ soroban config identity fund {address} --helper-url "# sequence + 60, // ~5 minutes of ledgers network_passphrase, )?; - let (fee_ready_txn, events) = if signed_auth_entries.is_empty() { + let (fee_ready_txn, events) = if signed_auth_entries.is_empty() + || (signed_auth_entries.len() == 1 + && matches!( + signed_auth_entries[0].root_invocation.function, + SorobanAuthorizedFunction::CreateContractHostFn(_) + )) { (part_signed_tx, events) } else { // re-simulate to calculate the new fees diff --git a/cmd/soroban-rpc/internal/test/cli_test.go b/cmd/soroban-rpc/internal/test/cli_test.go index 307b2a674..88bb75a5a 100644 --- a/cmd/soroban-rpc/internal/test/cli_test.go +++ b/cmd/soroban-rpc/internal/test/cli_test.go @@ -4,63 +4,81 @@ import ( "crypto/sha256" "fmt" "os" - "os/exec" "strings" "testing" "github.com/creachadair/jrpc2" "github.com/creachadair/jrpc2/jhttp" + "github.com/google/shlex" "github.com/stellar/go/keypair" "github.com/stellar/go/txnbuild" "github.com/stellar/go/xdr" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "gotest.tools/v3/icmd" ) func TestCLIContractInstall(t *testing.T) { NewCLITest(t) - output, err := runCLICommand("contract install --wasm " + helloWorldContractPath) - assert.NoError(t, err) + output := runSuccessfulCLICmd(t, "contract install --wasm "+helloWorldContractPath) wasm := getHelloWorldContract(t) contractHash := xdr.Hash(sha256.Sum256(wasm)) require.Contains(t, output, contractHash.HexString()) } -func TestCLIContractDeploy(t *testing.T) { +func TestCLIContractInstallAndDeploy(t *testing.T) { NewCLITest(t) - output, err := runCLICommand("contract deploy --id 1 --wasm " + helloWorldContractPath) - assert.NoError(t, err) - require.Contains(t, output, "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM") + runSuccessfulCLICmd(t, "contract install --wasm "+helloWorldContractPath) + wasm := getHelloWorldContract(t) + contractHash := xdr.Hash(sha256.Sum256(wasm)) + output := runSuccessfulCLICmd(t, fmt.Sprintf("contract deploy --salt 0 --wasm-hash %s", contractHash.HexString())) + outputsContractIDInLastLine(t, output) +} + +func outputsContractIDInLastLine(t *testing.T, output string) { + lines := strings.Split(output, "\n") + nonEmptyLines := make([]string, 0, len(lines)) + for _, l := range lines { + if l != "" { + nonEmptyLines = append(nonEmptyLines, l) + } + } + require.GreaterOrEqual(t, len(nonEmptyLines), 1) + contractID := nonEmptyLines[len(nonEmptyLines)-1] + require.Len(t, contractID, 56) + require.Regexp(t, "^C", contractID) } -func TestCLIContractInvokeWithWasm(t *testing.T) { +func TestCLIContractDeploy(t *testing.T) { NewCLITest(t) - output, err := runCLICommand(fmt.Sprintf("contract invoke --id 1 --wasm %s -- hello --world=world", helloWorldContractPath)) - assert.NoError(t, err) - require.Contains(t, output, `["Hello","world"]`) + output := runSuccessfulCLICmd(t, "contract deploy --salt 0 --wasm "+helloWorldContractPath) + outputsContractIDInLastLine(t, output) } func TestCLIContractDeployAndInvoke(t *testing.T) { NewCLITest(t) - output, err := runCLICommand("contract deploy --id 1 --wasm " + helloWorldContractPath) - assert.NoError(t, err) + output := runSuccessfulCLICmd(t, "contract deploy --salt=0 --wasm "+helloWorldContractPath) contractID := strings.TrimSpace(output) - output, err = runCLICommand(fmt.Sprintf("contract invoke --id %s -- hello --world=world", contractID)) - assert.NoError(t, err) + output = runSuccessfulCLICmd(t, fmt.Sprintf("contract invoke --id %s -- hello --world=world", contractID)) require.Contains(t, output, `["Hello","world"]`) } -func runCLICommand(cmd string) (string, error) { - baseCmdArgs := []string{"run", "-q", "--", "--vv"} - args := strings.Split(cmd, " ") - args = append(baseCmdArgs, args...) - c := exec.Command("cargo", args...) +func runSuccessfulCLICmd(t *testing.T, cmd string) string { + res := runCLICommand(t, cmd) + require.NoError(t, res.Error, fmt.Sprintf("stderr:\n%s\nstdout:\n%s\n", res.Stderr(), res.Stdout())) + return res.Stdout() +} + +func runCLICommand(t *testing.T, cmd string) *icmd.Result { + args := []string{"run", "-q", "--", "--vv"} + parsedArgs, err := shlex.Split(cmd) + require.NoError(t, err, cmd) + args = append(args, parsedArgs...) + c := icmd.Command("cargo", args...) c.Env = append(os.Environ(), - fmt.Sprintf("RPC_URL=http://localhost:%d/", sorobanRPCPort), - fmt.Sprintf("NETWORK_PASPRHASE=%s", StandaloneNetworkPassphrase), + fmt.Sprintf("SOROBAN_RPC_URL=http://localhost:%d/", sorobanRPCPort), + fmt.Sprintf("SOROBAN_NETWORK_PASSPHRASE=%s", StandaloneNetworkPassphrase), ) - bin, err := c.CombinedOutput() - return string(bin), err + return icmd.RunCmd(c) } func NewCLITest(t *testing.T) *Test { diff --git a/go.mod b/go.mod index 73a1e6fb7..44ebb67bd 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,7 @@ require ( github.com/mattn/go-sqlite3 v1.14.17 github.com/pelletier/go-toml v1.9.5 github.com/prometheus/client_golang v1.16.0 + github.com/rs/cors v0.0.0-20160617231935-a62a804a8a00 github.com/rubenv/sql-migrate v1.5.2 github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.7.0 @@ -18,6 +19,7 @@ require ( github.com/stellar/go v0.0.0-20230905170723-6e18a2f2f583 github.com/stretchr/testify v1.8.4 golang.org/x/mod v0.12.0 + gotest.tools/v3 v3.5.0 ) require ( @@ -38,6 +40,8 @@ require ( github.com/go-git/go-billy/v5 v5.3.1 // indirect github.com/go-gorp/gorp/v3 v3.1.0 // indirect github.com/golang/protobuf v1.5.3 // indirect + github.com/google/go-cmp v0.5.9 // indirect + github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 github.com/hashicorp/hcl v1.0.0 // indirect github.com/imdario/mergo v0.3.13 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect @@ -57,7 +61,6 @@ require ( github.com/prometheus/client_model v0.3.0 // indirect github.com/prometheus/common v0.42.0 // indirect github.com/prometheus/procfs v0.10.1 // indirect - github.com/rs/cors v0.0.0-20160617231935-a62a804a8a00 // indirect github.com/rs/xhandler v0.0.0-20160618193221-ed27b6fd6521 // indirect github.com/segmentio/go-loggly v0.5.1-0.20171222203950-eb91657e62b2 // indirect github.com/sergi/go-diff v1.1.0 // indirect diff --git a/go.sum b/go.sum index cb4a932ff..688250854 100644 --- a/go.sum +++ b/go.sum @@ -79,7 +79,10 @@ github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-querystring v0.0.0-20160401233042-9235644dd9e5 h1:oERTZ1buOUYlpmKaqlO5fYmz8cZ1rYu5DieJzF4ZVmU= +github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= +github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= github.com/gorilla/schema v1.1.0 h1:CamqUDOFUBqzrvxuz2vEwo8+SUdwsluFh7IlzJh30LY= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= @@ -299,3 +302,5 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0/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/v3 v3.5.0 h1:Ljk6PdHdOhAb5aDMWXjDLMMhph+BpztA4v1QdqEW2eY= +gotest.tools/v3 v3.5.0/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= From 3cd84b5ceedae635dfad456776ce99002c11d355 Mon Sep 17 00:00:00 2001 From: Tsachi Herman <24438559+tsachiherman@users.noreply.github.com> Date: Tue, 12 Sep 2023 13:44:36 -0400 Subject: [PATCH 2/2] update (#951) --- .github/workflows/soroban-rpc.yml | 10 +++++----- cmd/soroban-rpc/internal/test/docker-compose.yml | 2 +- go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/soroban-rpc.yml b/.github/workflows/soroban-rpc.yml index 78d25ba91..5afe44b52 100644 --- a/.github/workflows/soroban-rpc.yml +++ b/.github/workflows/soroban-rpc.yml @@ -109,7 +109,7 @@ jobs: env: SOROBAN_RPC_INTEGRATION_TESTS_ENABLED: true SOROBAN_RPC_INTEGRATION_TESTS_CAPTIVE_CORE_BIN: /usr/bin/stellar-core - PROTOCOL_20_CORE_DEBIAN_PKG_VERSION: 19.13.1-1469.76fed6ead.focal~soroban + PROTOCOL_20_CORE_DEBIAN_PKG_VERSION: 19.13.1-1481.3acf6dd26.focal runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 @@ -126,10 +126,10 @@ jobs: - name: Build soroban contract fixtures run: | - rustup update - rustup target add wasm32-unknown-unknown - make build_rust - make build-test-wasms + rustup update + rustup target add wasm32-unknown-unknown + make build_rust + make build-test-wasms - name: Install Captive Core run: | diff --git a/cmd/soroban-rpc/internal/test/docker-compose.yml b/cmd/soroban-rpc/internal/test/docker-compose.yml index a76ee07ae..7d8fd89ea 100644 --- a/cmd/soroban-rpc/internal/test/docker-compose.yml +++ b/cmd/soroban-rpc/internal/test/docker-compose.yml @@ -15,7 +15,7 @@ services: # Note: Please keep the image pinned to an immutable tag matching the Captive Core version. # This avoids implicit updates which break compatibility between # the Core container and captive core. - image: ${CORE_IMAGE:-stellar/unsafe-stellar-core-next:19.13.1-1469.76fed6ead.focal-soroban} + image: ${CORE_IMAGE:-stellar/stellar-core:19.13.1-1481.3acf6dd26.focal} depends_on: - core-postgres restart: on-failure diff --git a/go.mod b/go.mod index 44ebb67bd..6cee54593 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.7.0 github.com/spf13/pflag v1.0.5 - github.com/stellar/go v0.0.0-20230905170723-6e18a2f2f583 + github.com/stellar/go v0.0.0-20230912144159-176a6f499a49 github.com/stretchr/testify v1.8.4 golang.org/x/mod v0.12.0 gotest.tools/v3 v3.5.0 diff --git a/go.sum b/go.sum index 688250854..238b122d8 100644 --- a/go.sum +++ b/go.sum @@ -189,8 +189,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.3.2 h1:VUFqw5KcqRf7i70GOzW7N+Q7+gxVBkSSqiXB12+JQ4M= github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= -github.com/stellar/go v0.0.0-20230905170723-6e18a2f2f583 h1:oC7naR8IBqtWV/b+G91gTOe+jR52+GpkXhCxEyYawYY= -github.com/stellar/go v0.0.0-20230905170723-6e18a2f2f583/go.mod h1:5/qoLl0pexA5OPi0BZvDsOc3532CJlHuRg1dnBxbsGg= +github.com/stellar/go v0.0.0-20230912144159-176a6f499a49 h1:7Tp/Kt+wHsaWHTEOfbMDhbvKhPCjyqG7typ2CUFLHdk= +github.com/stellar/go v0.0.0-20230912144159-176a6f499a49/go.mod h1:5/qoLl0pexA5OPi0BZvDsOc3532CJlHuRg1dnBxbsGg= github.com/stellar/go-xdr v0.0.0-20211103144802-8017fc4bdfee h1:fbVs0xmXpBvVS4GBeiRmAE3Le70ofAqFMch1GTiq/e8= github.com/stellar/go-xdr v0.0.0-20211103144802-8017fc4bdfee/go.mod h1:yoxyU/M8nl9LKeWIoBrbDPQ7Cy+4jxRcWcOayZ4BMps= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=