Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polkadot-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
Mirrored projects
polkadot-sdk
Commits
e2c97a36
Commit
e2c97a36
authored
7 years ago
by
Tomasz Drwięga
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for invalid cases.
parent
a08fda16
Branches
Branches containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
substrate/primitives/src/hash.rs
+10
-0
10 additions, 0 deletions
substrate/primitives/src/hash.rs
substrate/primitives/src/uint.rs
+19
-1
19 additions, 1 deletion
substrate/primitives/src/uint.rs
substrate/serializer/src/lib.rs
+1
-1
1 addition, 1 deletion
substrate/serializer/src/lib.rs
with
30 additions
and
2 deletions
substrate/primitives/src/hash.rs
+
10
−
0
View file @
e2c97a36
...
...
@@ -112,4 +112,14 @@ mod tests {
assert_eq!
(
number
,
ser
::
from_str
(
&
format!
(
"{:?}"
,
expected
))
.unwrap
());
}
}
#[test]
fn
test_invalid
()
{
assert!
(
ser
::
from_str
::
<
H256
>
(
"
\"
0x000000000000000000000000000000000000000000000000000000000000000
\"
"
)
.unwrap_err
()
.is_data
());
assert!
(
ser
::
from_str
::
<
H256
>
(
"
\"
0x000000000000000000000000000000000000000000000000000000000000000g
\"
"
)
.unwrap_err
()
.is_data
());
assert!
(
ser
::
from_str
::
<
H256
>
(
"
\"
0x00000000000000000000000000000000000000000000000000000000000000000
\"
"
)
.unwrap_err
()
.is_data
());
assert!
(
ser
::
from_str
::
<
H256
>
(
"
\"\"
"
)
.unwrap_err
()
.is_data
());
assert!
(
ser
::
from_str
::
<
H256
>
(
"
\"
0
\"
"
)
.unwrap_err
()
.is_data
());
assert!
(
ser
::
from_str
::
<
H256
>
(
"
\"
10
\"
"
)
.unwrap_err
()
.is_data
());
}
}
This diff is collapsed.
Click to expand it.
substrate/primitives/src/uint.rs
+
19
−
1
View file @
e2c97a36
...
...
@@ -45,7 +45,7 @@ macro_rules! impl_serde {
}
fn
visit_str
<
E
:
de
::
Error
>
(
self
,
v
:
&
str
)
->
Result
<
Self
::
Value
,
E
>
{
if
v
.len
()
<
2
||
&
v
[
0
..
2
]
!=
"0x"
{
if
v
.len
()
<
3
||
&
v
[
0
..
2
]
!=
"0x"
{
return
Err
(
E
::
custom
(
"prefix is missing"
))
}
...
...
@@ -104,10 +104,28 @@ mod tests {
assert_eq!
(
format!
(
"{:?}"
,
expected
),
ser
::
to_string_pretty
(
&
number
));
assert_eq!
(
number
,
ser
::
from_str
(
&
format!
(
"{:?}"
,
expected
))
.unwrap
());
}
// Invalid examples
assert!
(
ser
::
from_str
::
<
$name
>
(
"
\"
0x
\"
"
)
.unwrap_err
()
.is_data
());
assert!
(
ser
::
from_str
::
<
$name
>
(
"
\"
0xg
\"
"
)
.unwrap_err
()
.is_data
());
assert!
(
ser
::
from_str
::
<
$name
>
(
"
\"\"
"
)
.unwrap_err
()
.is_data
());
assert!
(
ser
::
from_str
::
<
$name
>
(
"
\"
10
\"
"
)
.unwrap_err
()
.is_data
());
assert!
(
ser
::
from_str
::
<
$name
>
(
"
\"
0
\"
"
)
.unwrap_err
()
.is_data
());
}
}
}
test!
(
U256
,
test_u256
);
test!
(
U512
,
test_u512
);
#[test]
fn
test_large_values
()
{
assert_eq!
(
ser
::
to_string_pretty
(
&!
U256
::
zero
()),
"
\"
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
\"
"
);
assert!
(
ser
::
from_str
::
<
U256
>
(
"
\"
0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
\"
"
)
.unwrap_err
()
.is_data
()
);
}
}
This diff is collapsed.
Click to expand it.
substrate/serializer/src/lib.rs
+
1
−
1
View file @
e2c97a36
...
...
@@ -24,7 +24,7 @@
extern
crate
serde
;
extern
crate
serde_json
;
pub
use
serde_json
::{
from_str
,
from_slice
,
from_reader
,
Result
};
pub
use
serde_json
::{
from_str
,
from_slice
,
from_reader
,
Result
,
Error
};
const
PROOF
:
&
str
=
"Serializers are infallible; qed"
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment