Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/metadata/src/specs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ impl<S> ConstructorSpecBuilder<S> {
{
let mut this = self;
debug_assert!(this.spec.docs.is_empty());
this.spec.docs = docs.into_iter().collect::<Vec<_>>();
this.spec.docs = docs.into_iter().map(str::trim).collect::<Vec<_>>();
this
}
}
Expand Down
29 changes: 29 additions & 0 deletions crates/metadata/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,32 @@ fn spec_contract_json() {
})
)
}

#[test]
fn trim_docs() {
// given
let name = "foo";
let cs = ConstructorSpec::from_name(name)
.selector(123_456_789u32.to_be_bytes())
.docs(vec![" foobar "])
Copy link
Collaborator

@ascjones ascjones Dec 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this would be better if there was an inner space e.g. " foo bar ", because this test would also pass with just removing all spaces.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, I'll include this change in another PR.

.done();
let mut registry = Registry::new();
let compact_spec = cs.into_compact(&mut registry);

// when
let json = serde_json::to_value(&compact_spec).unwrap();
let deserialized: ConstructorSpec<CompactForm> =
serde_json::from_value(json.clone()).unwrap();

// then
assert_eq!(
json,
json!({
"name": ["foo"],
"selector": "0x075bcd15",
"args": [],
"docs": ["foobar"]
})
);
assert_eq!(deserialized, compact_spec);
}