Skip to content

Commit

Permalink
Merge branch 'main' into tsachi/lower-max-request-size
Browse files Browse the repository at this point in the history
  • Loading branch information
tsachiherman authored Sep 12, 2023
2 parents 3dd5744 + 3cd84b5 commit fc107cd
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 37 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/soroban-rpc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: |
Expand Down
9 changes: 7 additions & 2 deletions cmd/soroban-cli/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -662,7 +662,12 @@ soroban config identity fund {address} --helper-url <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
Expand Down
68 changes: 43 additions & 25 deletions cmd/soroban-rpc/internal/test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-rpc/internal/test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ 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
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
)

require (
Expand All @@ -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
Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -186,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=
Expand Down Expand Up @@ -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=

0 comments on commit fc107cd

Please sign in to comment.