mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-20 11:41:02 +00:00
Test improvements,
This commit is contained in:
@@ -24,6 +24,7 @@ use support::{Hashable, storage, with_env};
|
|||||||
use primitives::{Block, BlockNumber, Hash, UncheckedTransaction, TxOrder};
|
use primitives::{Block, BlockNumber, Hash, UncheckedTransaction, TxOrder};
|
||||||
use runtime::{staking, session};
|
use runtime::{staking, session};
|
||||||
|
|
||||||
|
const NONCE_OF: &[u8] = b"sys:non:";
|
||||||
const BLOCK_HASH_AT: &[u8] = b"sys:old:";
|
const BLOCK_HASH_AT: &[u8] = b"sys:old:";
|
||||||
const CODE: &[u8] = b"sys:cod";
|
const CODE: &[u8] = b"sys:cod";
|
||||||
|
|
||||||
@@ -110,8 +111,8 @@ pub mod internal {
|
|||||||
let ref tx = utx.transaction;
|
let ref tx = utx.transaction;
|
||||||
|
|
||||||
// check nonce
|
// check nonce
|
||||||
let nonce_key = tx.signed.to_keyed_vec(b"sys:non:");
|
let nonce_key = tx.signed.to_keyed_vec(NONCE_OF);
|
||||||
let expected_nonce: TxOrder = storage::get_or_default(&nonce_key);
|
let expected_nonce: TxOrder = storage::get_or(&nonce_key, 0);
|
||||||
assert!(tx.nonce == expected_nonce, "All transactions should have the correct nonce");
|
assert!(tx.nonce == expected_nonce, "All transactions should have the correct nonce");
|
||||||
|
|
||||||
// increment nonce in storage
|
// increment nonce in storage
|
||||||
@@ -265,7 +266,47 @@ mod tests {
|
|||||||
parent_hash: [69u8; 32],
|
parent_hash: [69u8; 32],
|
||||||
number: 1,
|
number: 1,
|
||||||
state_root: [0u8; 32],
|
state_root: [0u8; 32],
|
||||||
transaction_root: [0u8; 32], // Unchecked currently.
|
transaction_root: hex!("91fab88ad8c30a6d05ad8e0cf9ab139bf1b8cdddc69abd51cdfa6d2699038af1"),
|
||||||
|
digest: Digest { logs: vec![], },
|
||||||
|
};
|
||||||
|
|
||||||
|
let b = Block {
|
||||||
|
header: h,
|
||||||
|
transactions: vec![tx],
|
||||||
|
};
|
||||||
|
|
||||||
|
with_externalities(&mut t, || {
|
||||||
|
execute_block(b);
|
||||||
|
assert_eq!(staking::balance(&one), 42);
|
||||||
|
assert_eq!(staking::balance(&two), 69);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic]
|
||||||
|
fn block_import_of_bad_transaction_root_fails() {
|
||||||
|
let one = one();
|
||||||
|
let two = two();
|
||||||
|
|
||||||
|
let mut t = new_test_ext();
|
||||||
|
|
||||||
|
let tx = UncheckedTransaction {
|
||||||
|
transaction: Transaction {
|
||||||
|
signed: one.clone(),
|
||||||
|
nonce: 0,
|
||||||
|
function: Function::StakingTransfer,
|
||||||
|
input_data: vec![].join(&two).join(&69u64),
|
||||||
|
},
|
||||||
|
signature: "679fcf0a846b4224c84ecad7d91a26241c46d00cb53d6480a363274e8965ee34b0b80b4b2e3836d3d8f8f12c0c1aef7350af587d9aee3883561d11726068ac0a".convert(),
|
||||||
|
};
|
||||||
|
// tx: 2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee00000000000000000228000000d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a4500000000000000
|
||||||
|
// sig: 679fcf0a846b4224c84ecad7d91a26241c46d00cb53d6480a363274e8965ee34b0b80b4b2e3836d3d8f8f12c0c1aef7350af587d9aee3883561d11726068ac0a
|
||||||
|
|
||||||
|
let h = Header {
|
||||||
|
parent_hash: [69u8; 32],
|
||||||
|
number: 1,
|
||||||
|
state_root: hex!("2481853da20b9f4322f34650fea5f240dcbfb266d02db94bfa0153c31f4a29db"),
|
||||||
|
transaction_root: [0u8; 32],
|
||||||
digest: Digest { logs: vec![], },
|
digest: Digest { logs: vec![], },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user