Make sure frame examples compile for wasm (#5332)

* Make sure frame examples compile for wasm

This makes sure that `frame-example` and `frame-example-offchain-worker`
compile for wasm.

This also fixes compilation for these crates. The offchain worker
example doesn't use serde-json anymore as that is too heavy and breaks
`no_std` compilation.

* Apply suggestions from code review

Co-Authored-By: Nikolay Volf <nikvolf@gmail.com>

Co-authored-by: Nikolay Volf <nikvolf@gmail.com>
This commit is contained in:
Bastian Köcher
2020-03-20 16:57:39 +01:00
committed by GitHub
parent 57af4facbd
commit 46458f4082
6 changed files with 93 additions and 32 deletions
@@ -132,7 +132,7 @@ fn should_make_http_call_and_parse_result() {
// when
let price = Example::fetch_price().unwrap();
// then
assert_eq!(price, 15522);
assert_eq!(price, 15523);
});
}
@@ -164,7 +164,7 @@ fn should_submit_signed_transaction_on_chain() {
assert!(pool_state.read().transactions.is_empty());
let tx = Extrinsic::decode(&mut &*tx).unwrap();
assert_eq!(tx.signature.unwrap().0, 0);
assert_eq!(tx.call, Call::submit_price(15522));
assert_eq!(tx.call, Call::submit_price(15523));
});
}
@@ -186,7 +186,7 @@ fn should_submit_unsigned_transaction_on_chain() {
assert!(pool_state.read().transactions.is_empty());
let tx = Extrinsic::decode(&mut &*tx).unwrap();
assert_eq!(tx.signature, None);
assert_eq!(tx.call, Call::submit_price_unsigned(1, 15522));
assert_eq!(tx.call, Call::submit_price_unsigned(1, 15523));
});
}
@@ -208,3 +208,19 @@ fn price_oracle_response(state: &mut testing::OffchainState) {
..Default::default()
});
}
#[test]
fn parse_price_works() {
let test_data = vec![
("{\"USD\":6536.92}", Some(653692)),
("{\"USD\":65.92}", Some(6592)),
("{\"USD\":6536.924565}", Some(653692)),
("{\"USD\":6536}", Some(653600)),
("{\"USD2\":6536}", None),
("{\"USD\":\"6432\"}", None),
];
for (json, expected) in test_data {
assert_eq!(expected, Example::parse_price(json));
}
}