Skip to content

Commit 5b13f4c

Browse files
Update assertion to expect null on an undefined option (#2268)
- fixes a failing test where the option fn was returning `null` instead of the expected `undefined`. This PR just changes it to expect `null` instead. -clippy-related changes to use `clone` over `to_string` for Strings.
1 parent a41f513 commit 5b13f4c

File tree

15 files changed

+97
-107
lines changed

15 files changed

+97
-107
lines changed

cmd/crates/soroban-spec-json/src/lib.rs

Lines changed: 72 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ pub fn generate_from_wasm(wasm: &[u8]) -> Result<String, FromWasmError> {
5959
///
6060
/// If `serde_json::to_string_pretty` fails to serialize the spec entries.
6161
pub fn generate(spec: &[ScSpecEntry]) -> String {
62-
let collected: Vec<_> = spec.iter().map(Entry::from).collect();
62+
let mut collected: Vec<_> = spec.iter().map(Entry::from).collect();
63+
collected.sort();
6364
serde_json::to_string_pretty(&collected).expect("serialization of the spec entries should not have any failure cases as all keys are strings and the serialize implementations are derived")
6465
}
6566

@@ -82,61 +83,61 @@ mod test {
8283
json,
8384
r#"[
8485
{
85-
"type": "enum",
86+
"type": "function",
8687
"doc": "",
87-
"name": "UdtEnum2",
88-
"cases": [
88+
"name": "add",
89+
"inputs": [
8990
{
9091
"doc": "",
91-
"name": "A",
92-
"value": 10
92+
"name": "a",
93+
"value": {
94+
"type": "custom",
95+
"name": "UdtEnum"
96+
}
9397
},
9498
{
9599
"doc": "",
96-
"name": "B",
97-
"value": 15
100+
"name": "b",
101+
"value": {
102+
"type": "custom",
103+
"name": "UdtEnum"
104+
}
105+
}
106+
],
107+
"outputs": [
108+
{
109+
"type": "i64"
98110
}
99111
]
100112
},
101113
{
102-
"type": "union",
114+
"type": "struct",
103115
"doc": "",
104-
"name": "UdtEnum",
105-
"cases": [
106-
{
107-
"doc": "",
108-
"name": "UdtA",
109-
"values": []
110-
},
116+
"name": "UdtStruct",
117+
"fields": [
111118
{
112119
"doc": "",
113-
"name": "UdtB",
114-
"values": [
115-
{
116-
"type": "custom",
117-
"name": "UdtStruct"
118-
}
119-
]
120+
"name": "a",
121+
"value": {
122+
"type": "i64"
123+
}
120124
},
121125
{
122126
"doc": "",
123-
"name": "UdtC",
124-
"values": [
125-
{
126-
"type": "custom",
127-
"name": "UdtEnum2"
128-
}
129-
]
127+
"name": "b",
128+
"value": {
129+
"type": "i64"
130+
}
130131
},
131132
{
132133
"doc": "",
133-
"name": "UdtD",
134-
"values": [
135-
{
136-
"type": "custom",
137-
"name": "UdtTuple"
134+
"name": "c",
135+
"value": {
136+
"type": "vec",
137+
"element": {
138+
"type": "i64"
138139
}
139-
]
140+
}
140141
}
141142
]
142143
},
@@ -165,61 +166,61 @@ mod test {
165166
]
166167
},
167168
{
168-
"type": "struct",
169+
"type": "union",
169170
"doc": "",
170-
"name": "UdtStruct",
171-
"fields": [
171+
"name": "UdtEnum",
172+
"cases": [
172173
{
173174
"doc": "",
174-
"name": "a",
175-
"value": {
176-
"type": "i64"
177-
}
175+
"name": "UdtA",
176+
"values": []
178177
},
179178
{
180179
"doc": "",
181-
"name": "b",
182-
"value": {
183-
"type": "i64"
184-
}
180+
"name": "UdtB",
181+
"values": [
182+
{
183+
"type": "custom",
184+
"name": "UdtStruct"
185+
}
186+
]
185187
},
186188
{
187189
"doc": "",
188-
"name": "c",
189-
"value": {
190-
"type": "vec",
191-
"element": {
192-
"type": "i64"
190+
"name": "UdtC",
191+
"values": [
192+
{
193+
"type": "custom",
194+
"name": "UdtEnum2"
193195
}
194-
}
196+
]
197+
},
198+
{
199+
"doc": "",
200+
"name": "UdtD",
201+
"values": [
202+
{
203+
"type": "custom",
204+
"name": "UdtTuple"
205+
}
206+
]
195207
}
196208
]
197209
},
198210
{
199-
"type": "function",
211+
"type": "enum",
200212
"doc": "",
201-
"name": "add",
202-
"inputs": [
213+
"name": "UdtEnum2",
214+
"cases": [
203215
{
204216
"doc": "",
205-
"name": "a",
206-
"value": {
207-
"type": "custom",
208-
"name": "UdtEnum"
209-
}
217+
"name": "A",
218+
"value": 10
210219
},
211220
{
212221
"doc": "",
213-
"name": "b",
214-
"value": {
215-
"type": "custom",
216-
"name": "UdtEnum"
217-
}
218-
}
219-
],
220-
"outputs": [
221-
{
222-
"type": "i64"
222+
"name": "B",
223+
"value": 15
223224
}
224225
]
225226
}

cmd/crates/soroban-spec-tools/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,7 @@ impl Spec {
434434
};
435435
enum_case == &name.to_utf8_string_lossy()
436436
})
437-
.ok_or_else(|| {
438-
Error::EnumCase(enum_case.to_string(), union.name.to_utf8_string_lossy())
439-
})?;
437+
.ok_or_else(|| Error::EnumCase(enum_case.clone(), union.name.to_utf8_string_lossy()))?;
440438

441439
let mut res = vec![ScVal::Symbol(ScSymbol(
442440
enum_case.try_into().map_err(Error::Xdr)?,

cmd/crates/soroban-spec-typescript/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ pub fn entry_to_method_type(entry: &Entry) -> String {
277277
let name = if name == "Error" {
278278
format!("{name}s")
279279
} else {
280-
name.to_string()
280+
name.clone()
281281
};
282282
format!(
283283
r"{doc}export enum {name} {{
@@ -292,7 +292,7 @@ pub fn entry_to_method_type(entry: &Entry) -> String {
292292
let name = if name == "Error" {
293293
format!("{name}s")
294294
} else {
295-
name.to_string()
295+
name.clone()
296296
};
297297
format!(
298298
r"{doc}export const {name} = {{
@@ -340,14 +340,14 @@ pub fn func_input_to_ts(input: &types::FunctionInput) -> String {
340340

341341
pub fn func_input_to_arg_name(input: &types::FunctionInput) -> String {
342342
let types::FunctionInput { name, .. } = input;
343-
name.to_string()
343+
name.clone()
344344
}
345345

346346
pub fn parse_arg_to_scval(input: &types::FunctionInput) -> String {
347347
let types::FunctionInput { name, value, .. } = input;
348348
match value {
349349
types::Type::Address => format!("{name}: new Address({name})"),
350-
_ => name.to_string(),
350+
_ => name.clone(),
351351
}
352352
}
353353

cmd/crates/soroban-spec-typescript/ts-tests/src/test-custom-types.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,9 @@ test('tuple', async t => {
162162
})
163163

164164
test('option', async t => {
165-
// this makes sense
166165
t.deepEqual((await contract.option({ option: 1 })).result, 1)
167166

168-
// this passes but shouldn't
169-
t.deepEqual((await contract.option({ option: undefined })).result, undefined)
167+
t.deepEqual((await contract.option({ option: undefined })).result, null)
170168

171169
// this is the behavior we probably want, but fails
172170
// t.deepEqual(await contract.option(), undefined) // typing and implementation require the object

cmd/soroban-cli/src/commands/container/shared.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ impl Args {
7777
Docker::connect_with_named_pipe(&h, DEFAULT_TIMEOUT, API_DEFAULT_VERSION)
7878
}
7979
_ => {
80-
return Err(Error::UnsupportedURISchemeError {
81-
uri: host.to_string(),
82-
});
80+
return Err(Error::UnsupportedURISchemeError { uri: host.clone() });
8381
}
8482
}?;
8583

@@ -136,7 +134,7 @@ impl Name {
136134
}
137135

138136
pub fn get_external_container_name(&self) -> String {
139-
self.0.to_string()
137+
self.0.clone()
140138
}
141139
}
142140

cmd/soroban-cli/src/commands/contract/alias/add.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ impl Cmd {
5959
if let Some(contract) = contract {
6060
if contract != self.contract_id && !self.overwrite {
6161
return Err(Error::AlreadyExist {
62-
alias: alias.to_string(),
63-
network_passphrase: network_passphrase.to_string(),
62+
alias: alias.clone(),
63+
network_passphrase: network_passphrase.clone(),
6464
contract,
6565
});
6666
}

cmd/soroban-cli/src/commands/contract/alias/ls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl Cmd {
7373
let data: alias::Data = serde_json::from_str(&content).unwrap_or_default();
7474

7575
for network_passphrase in data.ids.keys() {
76-
let network_passphrase = network_passphrase.to_string();
76+
let network_passphrase = network_passphrase.clone();
7777
let contract = data
7878
.ids
7979
.get(&network_passphrase)

cmd/soroban-cli/src/commands/contract/deploy/wasm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl NetworkRunnable for Cmd {
220220
self.wasm_hash
221221
.as_ref()
222222
.ok_or(Error::WasmNotProvided)?
223-
.to_string()
223+
.clone()
224224
};
225225

226226
let wasm_hash = Hash(

cmd/soroban-cli/src/commands/events.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,14 @@ impl Cmd {
140140
for (i, segment) in topic.split(',').enumerate() {
141141
if i > 4 {
142142
return Err(Error::InvalidTopicFilter {
143-
topic: topic.to_string(),
143+
topic: topic.clone(),
144144
});
145145
}
146146

147147
if segment != "*" {
148148
if let Err(e) = xdr::ScVal::from_xdr_base64(segment, Limits::none()) {
149149
return Err(Error::InvalidSegment {
150-
topic: topic.to_string(),
150+
topic: topic.clone(),
151151
segment: segment.to_string(),
152152
error: e,
153153
});

cmd/soroban-cli/src/commands/plugin/search.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl Cmd {
5959
writeln!(&mut stdout, " {description}")?;
6060
}
6161

62-
print.blankln(item.html_url.to_string());
62+
print.blankln(item.html_url.clone());
6363
}
6464
Ok(())
6565
}

0 commit comments

Comments
 (0)