forked from CodeChain-io/codechain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.rs
62 lines (54 loc) · 1.98 KB
/
helpers.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2018-2019 Kodebox, Inc.
// This file is part of CodeChain.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use cstate::StateDB;
use ctypes::Header;
use primitives::{Bytes, H256, U256};
use rlp::{self, RlpStream};
use crate::scheme::Scheme;
use crate::transaction::SignedTransaction;
pub fn create_test_block(header: &Header) -> Bytes {
let mut rlp = RlpStream::new_list(2);
rlp.append(header);
rlp.append_raw(&rlp::EMPTY_LIST_RLP, 1);
rlp.out()
}
#[allow(dead_code)]
pub fn create_test_block_with_data(header: &Header, txs: &[SignedTransaction], uncles: &[Header]) -> Bytes {
let mut rlp = RlpStream::new_list(3);
rlp.append(header);
rlp.begin_list(txs.len());
for t in txs {
rlp.append_raw(&rlp::encode(t).into_vec(), 1);
}
rlp.append_list(&uncles);
rlp.out()
}
pub fn get_good_dummy_block() -> Bytes {
let (_, bytes) = get_good_dummy_block_hash();
bytes
}
pub fn get_good_dummy_block_hash() -> (H256, Bytes) {
let mut block_header = Header::new();
let test_scheme = Scheme::new_test();
block_header.set_score(U256::from(0x20000));
block_header.set_timestamp(40);
block_header.set_number(1);
block_header.set_parent_hash(test_scheme.genesis_header().hash());
(block_header.hash(), create_test_block(&block_header))
}
pub fn get_temp_state_db() -> StateDB {
StateDB::new_with_memorydb()
}