mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 15:41:02 +00:00
Introduce tests which demonstrate bad wasm compiler.
This commit is contained in:
@@ -38,12 +38,6 @@ use runtime_support::prelude::*;
|
||||
use slicable::Slicable;
|
||||
use primitives::{Block, UncheckedTransaction};
|
||||
|
||||
/// A simple test.
|
||||
pub fn simple_test(input: &[u8]) -> Vec<u8> {
|
||||
println!("Executing block");
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
/// Execute a block, with `input` being the canonical serialisation of the block. Returns the
|
||||
/// empty vector.
|
||||
pub fn execute_block(input: &[u8]) -> Vec<u8> {
|
||||
@@ -53,11 +47,12 @@ pub fn execute_block(input: &[u8]) -> Vec<u8> {
|
||||
|
||||
/// Execute a given, serialised, transaction. Returns the empty vector.
|
||||
pub fn execute_transaction(input: &[u8]) -> Vec<u8> {
|
||||
println!("Deserialising... {:?}", input);
|
||||
if input.len() == 0 {
|
||||
panic!("no transaction data given!");
|
||||
}
|
||||
let utx = UncheckedTransaction::from_slice(input).unwrap();
|
||||
println!("Forwarding... {:?}", utx);
|
||||
runtime::system::execute_transaction(&utx);
|
||||
Vec::new()
|
||||
input.to_vec()//Vec::new()
|
||||
}
|
||||
|
||||
impl_stubs!(execute_block, execute_transaction);
|
||||
|
||||
@@ -84,7 +84,6 @@ pub fn execute_block(mut block: Block) {
|
||||
|
||||
/// Execute a given transaction.
|
||||
pub fn execute_transaction(utx: &UncheckedTransaction) {
|
||||
println!("Executing...");
|
||||
// Verify the signature is good.
|
||||
assert!(utx.ed25519_verify(), "All transactions should be properly signed");
|
||||
|
||||
@@ -98,8 +97,6 @@ pub fn execute_transaction(utx: &UncheckedTransaction) {
|
||||
// increment nonce in storage
|
||||
(expected_nonce + 1).store(&nonce_key);
|
||||
|
||||
println!("Dispatching...");
|
||||
|
||||
// decode parameters and dispatch
|
||||
tx.function.dispatch(&tx.signed, &tx.input_data);
|
||||
}
|
||||
|
||||
@@ -144,7 +144,13 @@ macro_rules! impl_stubs {
|
||||
};
|
||||
|
||||
let output = super::$name(&input[..]);
|
||||
&output[0] as *const u8 as u64 + ((output.len() as u64) << 32)
|
||||
// things break if we try to take the address of an unallocated vec, so we
|
||||
// shortcircuit the empty output case.
|
||||
if output.len() > 0 {
|
||||
&output[0] as *const u8 as u64 + ((output.len() as u64) << 32)
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
)*
|
||||
}
|
||||
|
||||
BIN
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
@@ -43,4 +43,22 @@ fn test_data_in(input: &[u8]) -> Vec<u8> {
|
||||
b"all ok!".to_vec()
|
||||
}
|
||||
|
||||
impl_stubs!(test_data_in, test_blake2_256, test_twox_256, test_twox_128, test_ed25519_verify);
|
||||
fn test_empty_return(_input: &[u8]) -> Vec<u8> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
fn test_panic(_input: &[u8]) -> Vec<u8> {
|
||||
panic!("test panic");
|
||||
}
|
||||
|
||||
fn test_conditional_panic(input: &[u8]) -> Vec<u8> {
|
||||
if input.len() > 0 {
|
||||
panic!("test panic");
|
||||
} else {
|
||||
assert!(input.len() > 0);
|
||||
}
|
||||
input.to_vec()
|
||||
}
|
||||
|
||||
impl_stubs!(test_data_in, test_empty_return, test_panic, test_conditional_panic,
|
||||
test_blake2_256, test_twox_256, test_twox_128, test_ed25519_verify);
|
||||
|
||||
Reference in New Issue
Block a user