diff --git a/substrate/primitives/src/block.rs b/substrate/primitives/src/block.rs index 740b0c4cda..8cd077fd78 100644 --- a/substrate/primitives/src/block.rs +++ b/substrate/primitives/src/block.rs @@ -97,7 +97,7 @@ mod tests { "candidates": [ { "parachainIndex": 10, - "collatorSignature": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "collatorSignature": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "unprocessedIngress": [], "block": "0x01030508" } diff --git a/substrate/primitives/src/parachain.rs b/substrate/primitives/src/parachain.rs index 1d64f3c824..ed44134ce2 100644 --- a/substrate/primitives/src/parachain.rs +++ b/substrate/primitives/src/parachain.rs @@ -118,7 +118,7 @@ mod tests { block: BlockData(vec![1, 2, 3]), }), r#"{ "parachainIndex": 5, - "collatorSignature": "0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a", + "collatorSignature": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a", "unprocessedIngress": [ [ 1, diff --git a/substrate/state_machine/src/lib.rs b/substrate/state_machine/src/lib.rs index d1357592d4..cd25cdcb90 100644 --- a/substrate/state_machine/src/lib.rs +++ b/substrate/state_machine/src/lib.rs @@ -259,11 +259,11 @@ mod tests { ext.set_storage(b"con:aut:len".to_vec(), vec![1u8, 0, 0, 0]); assert_eq!(ext.authorities(), Ok(vec![&[][..]])); - ext.set_storage(b"con:aut:::::".to_vec(), b"first".to_vec()); + ext.set_storage(b"con:aut:\0\0\0\0".to_vec(), b"first".to_vec()); assert_eq!(ext.authorities(), Ok(vec![&b"first"[..]])); ext.set_storage(b"con:aut:len".to_vec(), vec![2u8, 0, 0, 0]); - ext.set_storage(b"con:aut:\x01:::".to_vec(), b"second".to_vec()); + ext.set_storage(b"con:aut:\x01\0\0\0".to_vec(), b"second".to_vec()); assert_eq!(ext.authorities(), Ok(vec![&b"first"[..], &b"second"[..]])); } } diff --git a/substrate/wasm-runtime/polkadot/src/support/environment.rs b/substrate/wasm-runtime/polkadot/src/support/environment.rs index 4d8ac354a8..da2e9b18ec 100644 --- a/substrate/wasm-runtime/polkadot/src/support/environment.rs +++ b/substrate/wasm-runtime/polkadot/src/support/environment.rs @@ -14,6 +14,7 @@ pub fn with_env T>(f: F) -> T { f(&mut *eb) } +#[cfg(not(test))] pub fn env() -> Rc> { // Initialize it to a null value static mut SINGLETON: *const Rc> = 0 as *const Rc>; @@ -31,3 +32,24 @@ pub fn env() -> Rc> { (*SINGLETON).clone() } } + +#[cfg(test)] +pub fn env() -> Rc> { + // Initialize it to a null value + thread_local!{ + static SINGLETON: RefCell<*const Rc>> = RefCell::new(0 as *const Rc>); + } + + SINGLETON.with(|s| unsafe { + if *s.borrow() == 0 as *const Rc> { + // Make it + let singleton: Rc> = Rc::new(RefCell::new(Default::default())); + + // Put it in the heap so it can outlive this call + *s.borrow_mut() = transmute(Box::new(singleton)); + } + + // Now we give out a copy of the data that is safe to use concurrently. + (**s.borrow()).clone() + }) +}