From 50a3225bf458e27f676566c1db43966c4772bfed Mon Sep 17 00:00:00 2001 From: George Kudrayvtsev Date: Thu, 14 Sep 2023 09:08:18 -0700 Subject: [PATCH] Make schema an optional pointer so that it's omitted when empty --- Makefile | 10 +++++----- .../internal/methods/simulate_transaction.go | 8 ++++---- .../internal/test/simulate_transaction_test.go | 3 ++- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 000b2aef5..adc7ec567 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ endif # Both cases should fallback to default of getting the version from git tag. ifeq ($(strip $(REPOSITORY_VERSION)),) override REPOSITORY_VERSION = "$(shell git describe --tags --always --abbrev=0 --match='v[0-9]*.[0-9]*.[0-9]*' 2> /dev/null | sed 's/^.//')" -endif +endif REPOSITORY_BRANCH := "$(shell git rev-parse --abbrev-ref HEAD)" BUILD_TIMESTAMP ?= $(shell date '+%Y-%m-%dT%H:%M:%S') GOLDFLAGS := -X 'github.com/stellar/soroban-tools/cmd/soroban-rpc/internal/config.Version=${REPOSITORY_VERSION}' \ @@ -62,12 +62,12 @@ build-libpreflight: Cargo.lock cd cmd/soroban-rpc/lib/preflight && cargo build --target $(CARGO_BUILD_TARGET) --profile release-with-panic-unwind build-test-wasms: Cargo.lock - cargo build --package 'test_*' --profile test-wasms --target wasm32-unknown-unknown + cargo build --package 'test_*' --profile test-wasms --target wasm32-unknown-unknown --jobs 4 build-test: build-test-wasms install_rust test: build-test - cargo test + cargo test e2e-test: cargo test --test it -- --ignored @@ -88,7 +88,7 @@ clean: publish: cargo workspaces publish --all --force '*' --from-git --yes -# the build-soroban-rpc build target is an optimized build target used by +# the build-soroban-rpc build target is an optimized build target used by # https://github.com/stellar/pipelines/stellar-horizon/Jenkinsfile-soroban-rpc-package-builder # as part of the package building. build-soroban-rpc: build-libpreflight @@ -101,7 +101,7 @@ lint: golangci-lint run ./... typescript-bindings-fixtures: build-test-wasms - cargo run -- contract bindings typescript \ + cargo run --jobs 4 -- contract bindings typescript \ --wasm ./target/wasm32-unknown-unknown/test-wasms/test_custom_types.wasm \ --contract-id CBYMYMSDF6FBDNCFJCRC7KMO4REYFPOH2U4N7FXI3GJO6YXNCQ43CDSK \ --network futurenet \ diff --git a/cmd/soroban-rpc/internal/methods/simulate_transaction.go b/cmd/soroban-rpc/internal/methods/simulate_transaction.go index 7d3d0a7c9..638a6a7b5 100644 --- a/cmd/soroban-rpc/internal/methods/simulate_transaction.go +++ b/cmd/soroban-rpc/internal/methods/simulate_transaction.go @@ -42,7 +42,7 @@ type SimulateTransactionResponse struct { Events []string `json:"events,omitempty"` // DiagnosticEvent XDR in base64 Results []SimulateHostFunctionResult `json:"results,omitempty"` // an array of the individual host function call results Cost SimulateTransactionCost `json:"cost,omitempty"` // the effective cpu and memory cost of the invoked transaction execution. - RestorePreamble RestorePreamble `json:"restorePreamble,omitempty"` // If present, it indicates that a prior RestoreFootprint is required + RestorePreamble *RestorePreamble `json:"restorePreamble,omitempty"` // If present, it indicates that a prior RestoreFootprint is required LatestLedger int64 `json:"latestLedger,string"` } @@ -136,9 +136,9 @@ func NewSimulateTransactionHandler(logger *log.Entry, ledgerEntryReader db.Ledge Auth: base64EncodeSlice(result.Auth), }) } - restorePreable := RestorePreamble{} + var restorePreamble *RestorePreamble = nil if len(result.PreRestoreTransactionData) != 0 { - restorePreable = RestorePreamble{ + restorePreamble = &RestorePreamble{ TransactionData: base64.StdEncoding.EncodeToString(result.PreRestoreTransactionData), MinResourceFee: result.PreRestoreMinFee, } @@ -155,7 +155,7 @@ func NewSimulateTransactionHandler(logger *log.Entry, ledgerEntryReader db.Ledge MemoryBytes: result.MemoryBytes, }, LatestLedger: int64(latestLedger), - RestorePreamble: restorePreable, + RestorePreamble: restorePreamble, } }) } diff --git a/cmd/soroban-rpc/internal/test/simulate_transaction_test.go b/cmd/soroban-rpc/internal/test/simulate_transaction_test.go index ecf57fad8..ffab2c9e3 100644 --- a/cmd/soroban-rpc/internal/test/simulate_transaction_test.go +++ b/cmd/soroban-rpc/internal/test/simulate_transaction_test.go @@ -184,7 +184,7 @@ func preflightTransactionParamsLocally(t *testing.T, params txnbuild.Transaction func preflightTransactionParams(t *testing.T, client *jrpc2.Client, params txnbuild.TransactionParams) txnbuild.TransactionParams { response := simulateTransactionFromTxParams(t, client, params) // The preamble should be zero except for the special restore case - assert.Zero(t, response.RestorePreamble) + assert.Nil(t, response.RestorePreamble) return preflightTransactionParamsLocally(t, params, response) } @@ -858,6 +858,7 @@ func TestSimulateTransactionBumpAndRestoreFootprint(t *testing.T) { waitForExpiration() simulationResult := simulateTransactionFromTxParams(t, client, invokeIncPresistentEntryParams) + require.NotNil(t, simulationResult.RestorePreamble) assert.NotZero(t, simulationResult.RestorePreamble) params = preflightTransactionParamsLocally(t,