Skip to content

Commit 100061d

Browse files
committed
Merge branch 'main' into protocol22
2 parents d055688 + b17d430 commit 100061d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1497
-1233
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
### Breaking Change
66
- Remove `GetLedgerEntry` endpoint. This endpoint was already deprecated earlier in favor of `GetLedgerEntries` and is completely removed in this release.
77

8+
## [v21.5.1](https://github.com/stellar/soroban-rpc/compare/v21.5.0...v21.5.1)
9+
10+
### Fixed
11+
* Preserve field omission behavior of `simulateTransaction` ([#291](https://github.com/stellar/soroban-rpc/pull/291)).
12+
13+
## [v21.5.0](https://github.com/stellar/soroban-rpc/compare/v21.4.1...v21.5.0)
14+
815
### Added
916

1017
- Add `EndLedger` in `GetEventsRequest`. This provides finer control and clarity on the range of ledgers being queried.

RELEASING.md

Lines changed: 0 additions & 58 deletions
This file was deleted.

cmd/soroban-rpc/internal/config/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/spf13/pflag"
1111
)
1212

13-
// Init adds the CLI flags to the command. This lets the command output the
13+
// AddFlags Init adds the CLI flags to the command. This lets the command output the
1414
// flags as part of the --help output.
1515
func (cfg *Config) AddFlags(cmd *cobra.Command) error {
1616
cfg.flagset = cmd.PersistentFlags()

cmd/soroban-rpc/internal/config/main_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ func TestLoadConfigPathPrecedence(t *testing.T) {
3434
}))
3535
require.NoError(t, cfg.Validate())
3636

37-
assert.Equal(t, "/opt/stellar/soroban-rpc/etc/stellar-captive-core.cfg", cfg.CaptiveCoreConfigPath, "should read values from the config path file")
37+
assert.Equal(t, "/opt/stellar/soroban-rpc/etc/stellar-captive-core.cfg", cfg.CaptiveCoreConfigPath,
38+
"should read values from the config path file")
3839
assert.Equal(t, "CLI test passphrase", cfg.NetworkPassphrase, "cli flags should override --config-path values")
39-
assert.Equal(t, "/usr/overridden/stellar-core", cfg.StellarCoreBinaryPath, "cli flags should override --config-path values and env vars")
40+
assert.Equal(t, "/usr/overridden/stellar-core", cfg.StellarCoreBinaryPath,
41+
"cli flags should override --config-path values and env vars")
4042
assert.Equal(t, "/env/overridden/db", cfg.SQLiteDBPath, "env var should override config file")
4143
assert.Equal(t, 2*time.Second, cfg.CoreRequestTimeout, "default value should be used, if not set anywhere else")
4244
}

cmd/soroban-rpc/internal/config/option_test.go

Lines changed: 98 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package config
22

33
import (
4-
"fmt"
54
"math"
65
"testing"
76
"time"
@@ -51,15 +50,15 @@ func TestValidateRequired(t *testing.T) {
5150
}
5251

5352
// unset
54-
assert.ErrorContains(t, o.Validate(o), "required-option is required")
53+
require.ErrorContains(t, o.Validate(o), "required-option is required")
5554

5655
// set with blank value
5756
require.NoError(t, o.setValue(""))
58-
assert.ErrorContains(t, o.Validate(o), "required-option is required")
57+
require.ErrorContains(t, o.Validate(o), "required-option is required")
5958

6059
// set with valid value
6160
require.NoError(t, o.setValue("not-blank"))
62-
assert.NoError(t, o.Validate(o))
61+
require.NoError(t, o.Validate(o))
6362
}
6463

6564
func TestValidatePositiveUint32(t *testing.T) {
@@ -71,15 +70,15 @@ func TestValidatePositiveUint32(t *testing.T) {
7170
}
7271

7372
// unset
74-
assert.ErrorContains(t, o.Validate(o), "positive-option must be positive")
73+
require.ErrorContains(t, o.Validate(o), "positive-option must be positive")
7574

7675
// set with 0 value
7776
require.NoError(t, o.setValue(uint32(0)))
78-
assert.ErrorContains(t, o.Validate(o), "positive-option must be positive")
77+
require.ErrorContains(t, o.Validate(o), "positive-option must be positive")
7978

8079
// set with valid value
8180
require.NoError(t, o.setValue(uint32(1)))
82-
assert.NoError(t, o.Validate(o))
81+
require.NoError(t, o.Validate(o))
8382
}
8483

8584
func TestValidatePositiveInt(t *testing.T) {
@@ -91,19 +90,19 @@ func TestValidatePositiveInt(t *testing.T) {
9190
}
9291

9392
// unset
94-
assert.ErrorContains(t, o.Validate(o), "positive-option must be positive")
93+
require.ErrorContains(t, o.Validate(o), "positive-option must be positive")
9594

9695
// set with 0 value
9796
require.NoError(t, o.setValue(0))
98-
assert.ErrorContains(t, o.Validate(o), "positive-option must be positive")
97+
require.ErrorContains(t, o.Validate(o), "positive-option must be positive")
9998

10099
// set with negative value
101100
require.NoError(t, o.setValue(-1))
102-
assert.ErrorContains(t, o.Validate(o), "positive-option must be positive")
101+
require.ErrorContains(t, o.Validate(o), "positive-option must be positive")
103102

104103
// set with valid value
105104
require.NoError(t, o.setValue(1))
106-
assert.NoError(t, o.Validate(o))
105+
require.NoError(t, o.Validate(o))
107106
}
108107

109108
func TestUnassignableField(t *testing.T) {
@@ -126,143 +125,105 @@ func TestNoParserForFlag(t *testing.T) {
126125
require.Contains(t, err.Error(), "no parser for flag mykey")
127126
}
128127

129-
func TestSetValue(t *testing.T) {
128+
func TestSetValueBool(t *testing.T) {
130129
var b bool
130+
testCases := []struct {
131+
name string
132+
value interface{}
133+
err string
134+
}{
135+
{"valid-bool", true, ""},
136+
{"valid-bool-string", "true", ""},
137+
{"valid-bool-string-false", "false", ""},
138+
{"valid-bool-string-uppercase", "TRUE", ""},
139+
{"invalid-bool-string", "foobar", "invalid boolean value invalid-bool-string: foobar"},
140+
}
141+
runTestCases(t, &b, testCases)
142+
}
143+
144+
func TestSetValueInt(t *testing.T) {
131145
var i int
146+
testCases := []struct {
147+
name string
148+
value interface{}
149+
err string
150+
}{
151+
{"valid-int", 1, ""},
152+
{"valid-int-string", "1", ""},
153+
{"invalid-int-string", "abcd", "strconv.ParseInt: parsing \"abcd\": invalid syntax"},
154+
}
155+
runTestCases(t, &i, testCases)
156+
}
157+
158+
func TestSetValueUint32(t *testing.T) {
132159
var u32 uint32
160+
testCases := []struct {
161+
name string
162+
value interface{}
163+
err string
164+
}{
165+
{"valid-uint32", 1, ""},
166+
{"overflow-uint32", uint64(math.MaxUint32) + 1, "overflow-uint32 overflows uint32"},
167+
{"negative-uint32", -1, "negative-uint32 cannot be negative"},
168+
}
169+
runTestCases(t, &u32, testCases)
170+
}
171+
172+
func TestSetValueUint64(t *testing.T) {
133173
var u64 uint64
174+
testCases := []struct {
175+
name string
176+
value interface{}
177+
err string
178+
}{
179+
{"valid-uint", 1, ""},
180+
{"negative-uint", -1, "negative-uint cannot be negative"},
181+
}
182+
runTestCases(t, &u64, testCases)
183+
}
184+
185+
func TestSetValueFloat64(t *testing.T) {
134186
var f64 float64
135-
var s string
187+
testCases := []struct {
188+
name string
189+
value interface{}
190+
err string
191+
}{
192+
{"valid-float", 1.05, ""},
193+
{"valid-float-int", int64(1234), ""},
194+
{"valid-float-string", "1.05", ""},
195+
{"invalid-float-string", "foobar", "strconv.ParseFloat: parsing \"foobar\": invalid syntax"},
196+
}
197+
runTestCases(t, &f64, testCases)
198+
}
136199

137-
for _, scenario := range []struct {
200+
func TestSetValueString(t *testing.T) {
201+
var s string
202+
testCases := []struct {
138203
name string
139-
key interface{}
140204
value interface{}
141-
err error
205+
err string
142206
}{
143-
{
144-
name: "valid-bool",
145-
key: &b,
146-
value: true,
147-
err: nil,
148-
},
149-
{
150-
name: "valid-bool-string",
151-
key: &b,
152-
value: "true",
153-
err: nil,
154-
},
155-
{
156-
name: "valid-bool-string-false",
157-
key: &b,
158-
value: "false",
159-
err: nil,
160-
},
161-
{
162-
name: "valid-bool-string-uppercase",
163-
key: &b,
164-
value: "TRUE",
165-
err: nil,
166-
},
167-
{
168-
name: "invalid-bool-string",
169-
key: &b,
170-
value: "foobar",
171-
err: fmt.Errorf("invalid boolean value invalid-bool-string: foobar"),
172-
},
173-
{
174-
name: "invalid-bool-string",
175-
key: &b,
176-
value: "foobar",
177-
err: fmt.Errorf("invalid boolean value invalid-bool-string: foobar"),
178-
},
179-
{
180-
name: "valid-int",
181-
key: &i,
182-
value: 1,
183-
err: nil,
184-
},
185-
{
186-
name: "valid-int-string",
187-
key: &i,
188-
value: "1",
189-
err: nil,
190-
},
191-
{
192-
name: "invalid-int-string",
193-
key: &i,
194-
value: "abcd",
195-
err: fmt.Errorf("strconv.ParseInt: parsing \"abcd\": invalid syntax"),
196-
},
197-
{
198-
name: "valid-uint32",
199-
key: &u32,
200-
value: 1,
201-
err: nil,
202-
},
203-
{
204-
name: "overflow-uint32",
205-
key: &u32,
206-
value: uint64(math.MaxUint32) + 1,
207-
err: fmt.Errorf("overflow-uint32 overflows uint32"),
208-
},
209-
{
210-
name: "negative-uint32",
211-
key: &u32,
212-
value: -1,
213-
err: fmt.Errorf("negative-uint32 cannot be negative"),
214-
},
215-
{
216-
name: "valid-uint",
217-
key: &u64,
218-
value: 1,
219-
err: nil,
220-
},
221-
{
222-
name: "negative-uint",
223-
key: &u64,
224-
value: -1,
225-
err: fmt.Errorf("negative-uint cannot be negative"),
226-
},
227-
{
228-
name: "valid-float",
229-
key: &f64,
230-
value: 1.05,
231-
err: nil,
232-
},
233-
{
234-
name: "valid-float-int",
235-
key: &f64,
236-
value: int64(1234),
237-
err: nil,
238-
},
239-
{
240-
name: "valid-float-string",
241-
key: &f64,
242-
value: "1.05",
243-
err: nil,
244-
},
245-
{
246-
name: "invalid-float-string",
247-
key: &f64,
248-
value: "foobar",
249-
err: fmt.Errorf("strconv.ParseFloat: parsing \"foobar\": invalid syntax"),
250-
},
251-
{
252-
name: "valid-string",
253-
key: &s,
254-
value: "foobar",
255-
err: nil,
256-
},
257-
} {
258-
t.Run(scenario.name, func(t *testing.T) {
207+
{"valid-string", "foobar", ""},
208+
}
209+
runTestCases(t, &s, testCases)
210+
}
211+
212+
func runTestCases(t *testing.T, key interface{}, testCases []struct {
213+
name string
214+
value interface{}
215+
err string
216+
},
217+
) {
218+
for _, tc := range testCases {
219+
t.Run(tc.name, func(t *testing.T) {
259220
co := Option{
260-
Name: scenario.name,
261-
ConfigKey: scenario.key,
221+
Name: tc.name,
222+
ConfigKey: key,
262223
}
263-
err := co.setValue(scenario.value)
264-
if scenario.err != nil {
265-
require.EqualError(t, err, scenario.err.Error())
224+
err := co.setValue(tc.value)
225+
if tc.err != "" {
226+
require.EqualError(t, err, tc.err)
266227
} else {
267228
require.NoError(t, err)
268229
}

0 commit comments

Comments
 (0)