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
506ca48d
Commit
506ca48d
authored
3 years ago
by
Bastian Köcher
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Offchain testing: Fix reading response (#10294)
parent
f0376517
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
substrate/primitives/core/src/offchain/testing.rs
+1
-1
1 addition, 1 deletion
substrate/primitives/core/src/offchain/testing.rs
substrate/primitives/runtime/src/offchain/http.rs
+32
-0
32 additions, 0 deletions
substrate/primitives/runtime/src/offchain/http.rs
with
33 additions
and
1 deletion
substrate/primitives/core/src/offchain/testing.rs
+
1
−
1
View file @
506ca48d
...
...
@@ -341,7 +341,7 @@ impl offchain::Externalities for TestOffchainExt {
Ok
(
0
)
}
else
{
let
read
=
std
::
cmp
::
min
(
buffer
.len
(),
response
[
req
.read
..
]
.len
());
buffer
[
0
..
read
]
.copy_from_slice
(
&
response
[
req
.read
..
read
]);
buffer
[
0
..
read
]
.copy_from_slice
(
&
response
[
req
.read
..
req
.read
+
read
]);
req
.read
+=
read
;
Ok
(
read
)
}
...
...
This diff is collapsed.
Click to expand it.
substrate/primitives/runtime/src/offchain/http.rs
+
32
−
0
View file @
506ca48d
...
...
@@ -535,6 +535,38 @@ mod tests {
})
}
#[test]
fn
should_send_huge_response
()
{
let
(
offchain
,
state
)
=
testing
::
TestOffchainExt
::
new
();
let
mut
t
=
TestExternalities
::
default
();
t
.register_extension
(
OffchainWorkerExt
::
new
(
offchain
));
t
.execute_with
(||
{
let
request
:
Request
=
Request
::
get
(
"http://localhost:1234"
);
let
pending
=
request
.add_header
(
"X-Auth"
,
"hunter2"
)
.send
()
.unwrap
();
// make sure it's sent correctly
state
.write
()
.fulfill_pending_request
(
0
,
testing
::
PendingRequest
{
method
:
"GET"
.into
(),
uri
:
"http://localhost:1234"
.into
(),
headers
:
vec!
[(
"X-Auth"
.into
(),
"hunter2"
.into
())],
sent
:
true
,
..
Default
::
default
()
},
vec!
[
0
;
5923
],
None
,
);
// wait
let
response
=
pending
.wait
()
.unwrap
();
let
body
=
response
.body
();
assert_eq!
(
body
.clone
()
.collect
::
<
Vec
<
_
>>
(),
vec!
[
0
;
5923
]);
assert_eq!
(
body
.error
(),
&
None
);
})
}
#[test]
fn
should_send_a_post_request
()
{
let
(
offchain
,
state
)
=
testing
::
TestOffchainExt
::
new
();
...
...
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