cleanup json crate (#11027)
* [json]: cleanup write something here.... * nit: commit new/moved files * nit: remove needless features * nits * fix(grumbles): use explicit import `DifficultyTest` * fix(grumbles): remove needless type hints * fix(grumble): docs `from -> used by` Co-Authored-By: David <dvdplm@gmail.com> * fix(grumbles): use explicit `imports` * fix(grumble): merge `tx` and `tx_with_signing_info` * fix(grumbles): resolve introduced `TODO's`
This commit is contained in:
@@ -79,7 +79,7 @@ engine = { path = "./engine", features = ["test-helpers"] }
|
||||
env_logger = "0.5"
|
||||
ethash = { path = "../ethash" }
|
||||
ethcore-accounts = { path = "../accounts" }
|
||||
ethjson = { path = "../json" }
|
||||
ethjson = { path = "../json", features = ["test-helpers"] }
|
||||
ethkey = { path = "../accounts/ethkey" }
|
||||
fetch = { path = "../util/fetch" }
|
||||
kvdb-memorydb = "0.1"
|
||||
@@ -89,7 +89,6 @@ machine = { path = "./machine", features = ["test-helpers"] }
|
||||
macros = { path = "../util/macros" }
|
||||
null-engine = { path = "./engines/null-engine" }
|
||||
parity-runtime = { path = "../util/runtime" }
|
||||
pod = { path = "pod" }
|
||||
rlp_compress = { path = "../util/rlp-compress" }
|
||||
rustc-hex = "1"
|
||||
serde_json = "1.0"
|
||||
|
||||
@@ -85,22 +85,6 @@ impl PodAccount {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ethjson::blockchain::Account> for PodAccount {
|
||||
fn from(a: ethjson::blockchain::Account) -> Self {
|
||||
PodAccount {
|
||||
balance: a.balance.into(),
|
||||
nonce: a.nonce.into(),
|
||||
code: Some(a.code.into()),
|
||||
storage: a.storage.into_iter().map(|(key, value)| {
|
||||
let key: U256 = key.into();
|
||||
let value: U256 = value.into();
|
||||
(BigEndianHash::from_uint(&key), BigEndianHash::from_uint(&value))
|
||||
}).collect(),
|
||||
version: a.version.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ethjson::spec::Account> for PodAccount {
|
||||
fn from(a: ethjson::spec::Account) -> Self {
|
||||
PodAccount {
|
||||
|
||||
@@ -46,13 +46,6 @@ impl PodState {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ethjson::blockchain::State> for PodState {
|
||||
fn from(s: ethjson::blockchain::State) -> PodState {
|
||||
let state = s.into_iter().map(|(addr, acc)| (addr.into(), PodAccount::from(acc))).collect();
|
||||
PodState(state)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ethjson::spec::State> for PodState {
|
||||
fn from(s: ethjson::spec::State) -> PodState {
|
||||
let state: BTreeMap<_,_> = s.into_iter()
|
||||
|
||||
@@ -44,7 +44,7 @@ fn skip_test(name: &String) -> bool {
|
||||
|
||||
pub fn json_chain_test<H: FnMut(&str, HookType)>(json_data: &[u8], start_stop_hook: &mut H) -> Vec<String> {
|
||||
let _ = ::env_logger::try_init();
|
||||
let tests = ethjson::blockchain::Test::load(json_data).unwrap();
|
||||
let tests = ethjson::test_helpers::blockchain::Test::load(json_data).unwrap();
|
||||
let mut failed = Vec::new();
|
||||
|
||||
for (name, blockchain) in tests.into_iter() {
|
||||
@@ -84,7 +84,7 @@ pub fn json_chain_test<H: FnMut(&str, HookType)>(json_data: &[u8], start_stop_ho
|
||||
{
|
||||
let db = test_helpers::new_db();
|
||||
let mut config = ClientConfig::default();
|
||||
if ethjson::blockchain::Engine::NoProof == blockchain.engine {
|
||||
if ethjson::test_helpers::blockchain::Engine::NoProof == blockchain.engine {
|
||||
config.verifier_type = VerifierType::CanonNoSeal;
|
||||
config.check_seal = false;
|
||||
}
|
||||
|
||||
@@ -14,16 +14,20 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use ethjson;
|
||||
use types::header::Header;
|
||||
use ethereum_types::U256;
|
||||
use ethjson::test_helpers::difficulty::DifficultyTest;
|
||||
use types::header::Header;
|
||||
use spec::Spec;
|
||||
|
||||
use super::HookType;
|
||||
|
||||
pub fn json_difficulty_test<H: FnMut(&str, HookType)>(json_data: &[u8], spec: Spec, start_stop_hook: &mut H) -> Vec<String> {
|
||||
let _ = ::env_logger::try_init();
|
||||
let tests = ethjson::test::DifficultyTest::load(json_data).unwrap();
|
||||
pub fn json_difficulty_test<H: FnMut(&str, HookType)>(
|
||||
json_data: &[u8],
|
||||
spec: Spec,
|
||||
start_stop_hook: &mut H
|
||||
) -> Vec<String> {
|
||||
let _ = env_logger::try_init();
|
||||
let tests = DifficultyTest::load(json_data).unwrap();
|
||||
let engine = &spec.engine;
|
||||
|
||||
for (name, test) in tests.into_iter() {
|
||||
|
||||
@@ -243,8 +243,12 @@ fn do_json_test<H: FnMut(&str, HookType)>(json_data: &[u8], h: &mut H) -> Vec<St
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn do_json_test_for<H: FnMut(&str, HookType)>(vm_type: &VMType, json_data: &[u8], start_stop_hook: &mut H) -> Vec<String> {
|
||||
let tests = ethjson::vm::Test::load(json_data).unwrap();
|
||||
fn do_json_test_for<H: FnMut(&str, HookType)>(
|
||||
vm_type: &VMType,
|
||||
json_data: &[u8],
|
||||
start_stop_hook: &mut H
|
||||
) -> Vec<String> {
|
||||
let tests = ethjson::test_helpers::vm::Test::load(json_data).unwrap();
|
||||
let mut failed = Vec::new();
|
||||
|
||||
for (name, vm) in tests.into_iter() {
|
||||
@@ -336,15 +340,15 @@ fn do_json_test_for<H: FnMut(&str, HookType)>(vm_type: &VMType, json_data: &[u8]
|
||||
|
||||
for (address, account) in vm.post_state.unwrap().into_iter() {
|
||||
let address = address.into();
|
||||
let code: Vec<u8> = account.code.into();
|
||||
let code: Vec<u8> = account.code.expect("code is missing from json; test should have code").into();
|
||||
let found_code = try_fail!(state.code(&address));
|
||||
let found_balance = try_fail!(state.balance(&address));
|
||||
let found_nonce = try_fail!(state.nonce(&address));
|
||||
|
||||
fail_unless(found_code.as_ref().map_or_else(|| code.is_empty(), |c| &**c == &code), "code is incorrect");
|
||||
fail_unless(found_balance == account.balance.into(), "balance is incorrect");
|
||||
fail_unless(found_nonce == account.nonce.into(), "nonce is incorrect");
|
||||
for (k, v) in account.storage {
|
||||
fail_unless(account.balance.as_ref().map_or(false, |b| b.0 == found_balance), "balance is incorrect");
|
||||
fail_unless(account.nonce.as_ref().map_or(false, |n| n.0 == found_nonce), "nonce is incorrect");
|
||||
for (k, v) in account.storage.expect("test should have storage") {
|
||||
let key: U256 = k.into();
|
||||
let value: U256 = v.into();
|
||||
let found_storage = try_fail!(state.storage_at(&address, &BigEndianHash::from_uint(&key)));
|
||||
|
||||
@@ -16,19 +16,19 @@
|
||||
|
||||
//! State tests to skip.
|
||||
|
||||
use ethjson;
|
||||
use ethjson::test_helpers::skip::SkipStates;
|
||||
|
||||
#[cfg(feature="ci-skip-tests")]
|
||||
lazy_static!{
|
||||
pub static ref SKIP_TEST_STATE: ethjson::test::SkipStates = {
|
||||
lazy_static! {
|
||||
pub static ref SKIP_TEST_STATE: SkipStates = {
|
||||
let skip_data = include_bytes!("../../res/ethereum/tests-issues/currents.json");
|
||||
ethjson::test::SkipStates::load(&skip_data[..]).expect("No invalid json allowed")
|
||||
SkipStates::load(&skip_data[..]).expect("No invalid json allowed")
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(not(feature="ci-skip-tests"))]
|
||||
lazy_static!{
|
||||
pub static ref SKIP_TEST_STATE: ethjson::test::SkipStates = {
|
||||
ethjson::test::SkipStates::empty()
|
||||
pub static ref SKIP_TEST_STATE: SkipStates = {
|
||||
SkipStates::empty()
|
||||
};
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ fn skip_test(subname: &str, chain: &String, number: usize) -> bool {
|
||||
|
||||
pub fn json_chain_test<H: FnMut(&str, HookType)>(json_data: &[u8], start_stop_hook: &mut H) -> Vec<String> {
|
||||
let _ = ::env_logger::try_init();
|
||||
let tests = ethjson::state::test::Test::load(json_data).unwrap();
|
||||
let tests = ethjson::test_helpers::state::Test::load(json_data).unwrap();
|
||||
let mut failed = Vec::new();
|
||||
|
||||
for (name, test) in tests.into_iter() {
|
||||
|
||||
@@ -41,7 +41,7 @@ pub fn run_test_file<H: FnMut(&str, HookType)>(p: &Path, h: &mut H) {
|
||||
const BLOCK_NUMBER: u64 = 0x6ffffffffffffe;
|
||||
|
||||
fn do_json_test<H: FnMut(&str, HookType)>(json_data: &[u8], start_stop_hook: &mut H) -> Vec<String> {
|
||||
let tests = ethjson::transaction::Test::load(json_data).unwrap();
|
||||
let tests = ethjson::test_helpers::transaction::Test::load(json_data).unwrap();
|
||||
let mut failed = Vec::new();
|
||||
for (name, test) in tests.into_iter() {
|
||||
start_stop_hook(&name, HookType::OnStart);
|
||||
|
||||
@@ -26,7 +26,7 @@ pub use self::secure::run_test_path as run_secure_test_path;
|
||||
pub use self::secure::run_test_file as run_secure_test_file;
|
||||
|
||||
fn test_trie<H: FnMut(&str, HookType)>(json: &[u8], trie: TrieSpec, start_stop_hook: &mut H) -> Vec<String> {
|
||||
let tests = ethjson::trie::Test::load(json).unwrap();
|
||||
let tests = ethjson::test_helpers::trie::Test::load(json).unwrap();
|
||||
let factory = TrieFactory::new(trie, ethtrie::Layout);
|
||||
let mut result = vec![];
|
||||
|
||||
|
||||
@@ -134,8 +134,8 @@ impl Transaction {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ethjson::state::Transaction> for SignedTransaction {
|
||||
fn from(t: ethjson::state::Transaction) -> Self {
|
||||
impl From<ethjson::transaction::Transaction> for SignedTransaction {
|
||||
fn from(t: ethjson::transaction::Transaction) -> Self {
|
||||
let to: Option<ethjson::hash::Address> = t.to.into();
|
||||
let secret = t.secret.map(|s| Secret::from(s.0));
|
||||
let tx = Transaction {
|
||||
|
||||
Reference in New Issue
Block a user