Commit 1308aab5 authored by Gav Wood's avatar Gav Wood Committed by asynchronous rob
Browse files

Optional storage entries (#75)

* Block builder (substrate)

* Fix wasm build

* Bulid on any block

* Test for block builder.

* Block import tests for client.

* Tidy ups

* Repotted client

* Avoid pointless work

* All backend stuff now manages optional storage.

Also simplified a lot of the backend.

* Native runtime-io now supports empty storage items.

* Finish up the API transition.

* Build fix.

* Fix tests.

* Remerge in changes to client.

* Final fixes.

* Unrevert typos

* Remove accidentally committed change

* Bring back zero copy

* Fix merge.
parent ea520707
......@@ -73,9 +73,9 @@ mod tests {
#[test]
fn panic_execution_with_foreign_code_gives_error() {
let one = Keyring::One.to_raw_public();
let mut t = TestExternalities { storage: map![
let mut t: TestExternalities = map![
twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![68u8, 0, 0, 0, 0, 0, 0, 0]
], };
];
let r = Executor::new().call(&mut t, BLOATY_CODE, "execute_transaction", &vec![].and(&Header::from_block_number(1u64)).and(&tx()));
assert!(r.is_err());
......@@ -84,9 +84,9 @@ mod tests {
#[test]
fn panic_execution_with_native_equivalent_code_gives_error() {
let one = Keyring::One.to_raw_public();
let mut t = TestExternalities { storage: map![
let mut t: TestExternalities = map![
twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![68u8, 0, 0, 0, 0, 0, 0, 0]
], };
];
let r = Executor::new().call(&mut t, COMPACT_CODE, "execute_transaction", &vec![].and(&Header::from_block_number(1u64)).and(&tx()));
assert!(r.is_err());
......@@ -97,9 +97,9 @@ mod tests {
let one = Keyring::One.to_raw_public();
let two = Keyring::Two.to_raw_public();
let mut t = TestExternalities { storage: map![
let mut t: TestExternalities = map![
twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0]
], };
];
let r = Executor::new().call(&mut t, COMPACT_CODE, "execute_transaction", &vec![].and(&Header::from_block_number(1u64)).and(&tx()));
assert!(r.is_ok());
......@@ -115,9 +115,9 @@ mod tests {
let one = Keyring::One.to_raw_public();
let two = Keyring::Two.to_raw_public();
let mut t = TestExternalities { storage: map![
let mut t: TestExternalities = map![
twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0]
], };
];
let r = Executor::new().call(&mut t, BLOATY_CODE, "execute_transaction", &vec![].and(&Header::from_block_number(1u64)).and(&tx()));
assert!(r.is_ok());
......@@ -133,7 +133,7 @@ mod tests {
let two = Keyring::Two.to_raw_public();
let three = [3u8; 32];
TestExternalities { storage: map![
map![
twox_128(&0u64.to_keyed_vec(b"sys:old:")).to_vec() => [69u8; 32].encode(),
twox_128(b"gov:apr").to_vec() => vec![].and(&667u32),
twox_128(b"ses:len").to_vec() => vec![].and(&2u64),
......@@ -149,7 +149,7 @@ mod tests {
twox_128(b"sta:vac").to_vec() => vec![].and(&3u64),
twox_128(b"sta:era").to_vec() => vec![].and(&0u64),
twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0]
], }
]
}
fn construct_block(number: BlockNumber, parent_hash: Hash, state_root: Hash, txs: Vec<Transaction>) -> (Vec<u8>, Hash) {
......@@ -250,9 +250,9 @@ mod tests {
#[test]
fn panic_execution_gives_error() {
let one = Keyring::One.to_raw_public();
let mut t = TestExternalities { storage: map![
let mut t: TestExternalities = map![
twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![68u8, 0, 0, 0, 0, 0, 0, 0]
], };
];
let foreign_code = include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.wasm");
let r = WasmExecutor.call(&mut t, &foreign_code[..], "execute_transaction", &vec![].and(&Header::from_block_number(1u64)).and(&tx()));
......@@ -264,9 +264,9 @@ mod tests {
let one = Keyring::One.to_raw_public();
let two = Keyring::Two.to_raw_public();
let mut t = TestExternalities { storage: map![
let mut t: TestExternalities = map![
twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0]
], };
];
let foreign_code = include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm");
let r = WasmExecutor.call(&mut t, &foreign_code[..], "execute_transaction", &vec![].and(&Header::from_block_number(1u64)).and(&tx()));
......
......@@ -157,7 +157,7 @@ mod tests {
let two = Keyring::Two.to_raw_public();
let three = [3u8; 32];
TestExternalities { storage: map![
map![
twox_128(APPROVALS_REQUIRED).to_vec() => vec![].and(&667u32),
twox_128(b"ses:len").to_vec() => vec![].and(&1u64),
twox_128(b"ses:val:len").to_vec() => vec![].and(&3u32),
......@@ -171,7 +171,7 @@ mod tests {
twox_128(b"sta:spe").to_vec() => vec![].and(&1u64),
twox_128(b"sta:vac").to_vec() => vec![].and(&3u64),
twox_128(b"sta:era").to_vec() => vec![].and(&1u64)
], }
]
}
#[test]
......
......@@ -83,10 +83,10 @@ mod tests {
use runtime::{consensus, session};
fn simple_setup() -> TestExternalities {
TestExternalities { storage: map![
map![
twox_128(b"ses:val:len").to_vec() => vec![].and(&8u32),
twox_128(b"par:cou").to_vec() => vec![].and(&2u32)
], }
]
}
#[test]
......
......@@ -145,7 +145,7 @@ mod tests {
use runtime::{consensus, session};
fn simple_setup() -> TestExternalities {
TestExternalities { storage: map![
map![
twox_128(SESSION_LENGTH).to_vec() => vec![].and(&2u64),
// the validators (10, 20, ...)
twox_128(b"ses:val:len").to_vec() => vec![].and(&2u32),
......@@ -155,7 +155,7 @@ mod tests {
b":auth:len".to_vec() => vec![].and(&2u32),
0u32.to_keyed_vec(b":auth:") => vec![11; 32],
1u32.to_keyed_vec(b":auth:") => vec![21; 32]
], }
]
}
#[test]
......
......@@ -227,7 +227,7 @@ mod tests {
let three = [3u8; 32];
let four = [4u8; 32];
let mut t = TestExternalities { storage: map![
let mut t: TestExternalities = map![
twox_128(b"ses:len").to_vec() => vec![].and(&1u64),
twox_128(b"ses:val:len").to_vec() => vec![].and(&2u32),
twox_128(&0u32.to_keyed_vec(b"ses:val:")).to_vec() => vec![10; 32],
......@@ -239,7 +239,7 @@ mod tests {
twox_128(&two.to_keyed_vec(BALANCE_OF)).to_vec() => vec![].and(&20u64),
twox_128(&three.to_keyed_vec(BALANCE_OF)).to_vec() => vec![].and(&30u64),
twox_128(&four.to_keyed_vec(BALANCE_OF)).to_vec() => vec![].and(&40u64)
], };
];
with_externalities(&mut t, || {
assert_eq!(era_length(), 2u64);
......@@ -296,10 +296,10 @@ mod tests {
#[test]
fn staking_eras_work() {
let mut t = TestExternalities { storage: map![
let mut t: TestExternalities = map![
twox_128(b"ses:len").to_vec() => vec![].and(&1u64),
twox_128(SESSIONS_PER_ERA).to_vec() => vec![].and(&2u64)
], };
];
with_externalities(&mut t, || {
assert_eq!(era_length(), 2u64);
assert_eq!(sessions_per_era(), 2u64);
......@@ -363,9 +363,9 @@ mod tests {
let one = Keyring::One.to_raw_public();
let two = Keyring::Two.to_raw_public();
let mut t = TestExternalities { storage: map![
let mut t: TestExternalities = map![
twox_128(&one.to_keyed_vec(BALANCE_OF)).to_vec() => vec![].and(&42u64)
], };
];
with_externalities(&mut t, || {
assert_eq!(balance(&one), 42);
......@@ -378,9 +378,9 @@ mod tests {
let one = Keyring::One.to_raw_public();
let two = Keyring::Two.to_raw_public();
let mut t = TestExternalities { storage: map![
let mut t: TestExternalities = map![
twox_128(&one.to_keyed_vec(BALANCE_OF)).to_vec() => vec![].and(&111u64)
], };
];
with_externalities(&mut t, || {
transfer(&one, &two, 69);
......@@ -395,9 +395,9 @@ mod tests {
let one = Keyring::One.to_raw_public();
let two = Keyring::Two.to_raw_public();
let mut t = TestExternalities { storage: map![
let mut t: TestExternalities = map![
twox_128(&one.to_keyed_vec(BALANCE_OF)).to_vec() => vec![].and(&111u64)
], };
];
with_externalities(&mut t, || {
stake(&one);
......
......@@ -247,9 +247,9 @@ mod tests {
let one = Keyring::One.to_raw_public();
let two = Keyring::Two.to_raw_public();
let mut t = TestExternalities { storage: map![
let mut t: TestExternalities = map![
twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0]
], };
];
let tx = UncheckedTransaction {
transaction: Transaction {
......@@ -272,7 +272,7 @@ mod tests {
let two = Keyring::Two.to_raw_public();
let three = [3u8; 32];
TestExternalities { storage: map![
map![
twox_128(&0u64.to_keyed_vec(b"sys:old:")).to_vec() => [69u8; 32].encode(),
twox_128(b"gov:apr").to_vec() => vec![].and(&667u32),
twox_128(b"ses:len").to_vec() => vec![].and(&2u64),
......@@ -288,7 +288,7 @@ mod tests {
twox_128(b"sta:vac").to_vec() => vec![].and(&3u64),
twox_128(b"sta:era").to_vec() => vec![].and(&0u64),
twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0]
], }
]
}
#[test]
......
......@@ -47,9 +47,9 @@ mod tests {
#[test]
fn timestamp_works() {
let mut t = TestExternalities { storage: map![
let mut t: TestExternalities = map![
twox_128(CURRENT_TIMESTAMP).to_vec() => vec![].and(&42u64)
], };
];
with_externalities(&mut t, || {
assert_eq!(get(), 42);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment