mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 07:31:08 +00:00
Move Externalities into its own crate (#3775)
* Move `Externalities` into `substrate-externalities` - `Externalities` now support generic extensions - Split of `primtives-storage` for storage primitive types * Move the externalities scoping into `substrate-externalities` * Fix compilation * Review feedback * Adds macro for declaring extensions * Fix benchmarks * Introduce `ExtensionStore` trait * Last review comments * Implement it for `ExtensionStore`
This commit is contained in:
@@ -16,6 +16,7 @@ runtime_io = { package = "sr-io", path = "../sr-io", default-features = false }
|
||||
log = { version = "0.4.8", optional = true }
|
||||
paste = "0.1.6"
|
||||
rand = { version = "0.7.2", optional = true }
|
||||
externalities = { package = "substrate-externalities", path = "../externalities", optional = true }
|
||||
impl-trait-for-tuples = "0.1.2"
|
||||
|
||||
[dev-dependencies]
|
||||
@@ -36,4 +37,5 @@ std = [
|
||||
"primitives/std",
|
||||
"app-crypto/std",
|
||||
"rand",
|
||||
"externalities",
|
||||
]
|
||||
|
||||
@@ -67,6 +67,9 @@ pub use sr_arithmetic::{
|
||||
/// Re-export 128 bit helpers from sr_arithmetic
|
||||
pub use sr_arithmetic::helpers_128bit;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub use externalities::set_and_run_with_externalities;
|
||||
|
||||
/// An abstraction over justification for a block's validity under a consensus algorithm.
|
||||
///
|
||||
/// Essentially a finality proof. The exact formulation will vary between consensus
|
||||
|
||||
@@ -512,16 +512,18 @@ impl<'a> HeadersIterator<'a> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use runtime_io::{TestExternalities, with_externalities};
|
||||
use crate::set_and_run_with_externalities;
|
||||
use runtime_io::TestExternalities;
|
||||
use substrate_offchain::testing;
|
||||
use primitives::offchain::OffchainExt;
|
||||
|
||||
#[test]
|
||||
fn should_send_a_basic_request_and_get_response() {
|
||||
let (offchain, state) = testing::TestOffchainExt::new();
|
||||
let mut t = TestExternalities::default();
|
||||
t.set_offchain_externalities(offchain);
|
||||
t.register_extension(OffchainExt::new(offchain));
|
||||
|
||||
with_externalities(&mut t, || {
|
||||
set_and_run_with_externalities(&mut t, || {
|
||||
let request: Request = Request::get("http://localhost:1234");
|
||||
let pending = request
|
||||
.add_header("X-Auth", "hunter2")
|
||||
@@ -560,9 +562,9 @@ mod tests {
|
||||
fn should_send_a_post_request() {
|
||||
let (offchain, state) = testing::TestOffchainExt::new();
|
||||
let mut t = TestExternalities::default();
|
||||
t.set_offchain_externalities(offchain);
|
||||
t.register_extension(OffchainExt::new(offchain));
|
||||
|
||||
with_externalities(&mut t, || {
|
||||
set_and_run_with_externalities(&mut t, || {
|
||||
let pending = Request::default()
|
||||
.method(Method::Post)
|
||||
.url("http://localhost:1234")
|
||||
|
||||
Reference in New Issue
Block a user