Fix tests.

This commit is contained in:
Gav
2018-01-19 21:20:44 +01:00
parent ecb504e467
commit 768cb3bca2
4 changed files with 26 additions and 4 deletions
+1 -1
View File
@@ -97,7 +97,7 @@ mod tests {
"candidates": [ "candidates": [
{ {
"parachainIndex": 10, "parachainIndex": 10,
"collatorSignature": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "collatorSignature": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"unprocessedIngress": [], "unprocessedIngress": [],
"block": "0x01030508" "block": "0x01030508"
} }
+1 -1
View File
@@ -118,7 +118,7 @@ mod tests {
block: BlockData(vec![1, 2, 3]), block: BlockData(vec![1, 2, 3]),
}), r#"{ }), r#"{
"parachainIndex": 5, "parachainIndex": 5,
"collatorSignature": "0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a", "collatorSignature": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a",
"unprocessedIngress": [ "unprocessedIngress": [
[ [
1, 1,
+2 -2
View File
@@ -259,11 +259,11 @@ mod tests {
ext.set_storage(b"con:aut:len".to_vec(), vec![1u8, 0, 0, 0]); ext.set_storage(b"con:aut:len".to_vec(), vec![1u8, 0, 0, 0]);
assert_eq!(ext.authorities(), Ok(vec![&[][..]])); 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"[..]])); 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: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"[..]])); assert_eq!(ext.authorities(), Ok(vec![&b"first"[..], &b"second"[..]]));
} }
} }
@@ -14,6 +14,7 @@ pub fn with_env<T, F: FnOnce(&mut Environment) -> T>(f: F) -> T {
f(&mut *eb) f(&mut *eb)
} }
#[cfg(not(test))]
pub fn env() -> Rc<RefCell<Environment>> { pub fn env() -> Rc<RefCell<Environment>> {
// Initialize it to a null value // Initialize it to a null value
static mut SINGLETON: *const Rc<RefCell<Environment>> = 0 as *const Rc<RefCell<Environment>>; static mut SINGLETON: *const Rc<RefCell<Environment>> = 0 as *const Rc<RefCell<Environment>>;
@@ -31,3 +32,24 @@ pub fn env() -> Rc<RefCell<Environment>> {
(*SINGLETON).clone() (*SINGLETON).clone()
} }
} }
#[cfg(test)]
pub fn env() -> Rc<RefCell<Environment>> {
// Initialize it to a null value
thread_local!{
static SINGLETON: RefCell<*const Rc<RefCell<Environment>>> = RefCell::new(0 as *const Rc<RefCell<Environment>>);
}
SINGLETON.with(|s| unsafe {
if *s.borrow() == 0 as *const Rc<RefCell<Environment>> {
// Make it
let singleton: Rc<RefCell<Environment>> = 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()
})
}