Change over to new FromJson API.
This commit is contained in:
@@ -170,24 +170,19 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
|
||||
test.find("pre").map(|pre| for (addr, s) in pre.as_object().unwrap() {
|
||||
let address = Address::from(addr.as_ref());
|
||||
let balance = xjson!(&s["balance"]);
|
||||
let code = bytes_from_json(&s["code"]);
|
||||
let code = xjson!(&s["code"]);
|
||||
let _nonce: U256 = xjson!(&s["nonce"]);
|
||||
|
||||
state.new_contract(&address);
|
||||
state.add_balance(&address, &balance);
|
||||
state.init_code(&address, code);
|
||||
|
||||
for (k, v) in s["storage"].as_object().unwrap() {
|
||||
let key = H256::from(&u256_from_str(k));
|
||||
let val = H256::from(&U256::from_json(v));
|
||||
state.set_storage(&address, key, val);
|
||||
}
|
||||
BTreeMap::from_json(&s["storage"]).into_iter().foreach(|(k, v)| state.set_storage(&address, k, v));
|
||||
});
|
||||
|
||||
let mut info = EnvInfo::new();
|
||||
|
||||
test.find("env").map(|env| {
|
||||
info.author = address_from_json(&env["currentCoinbase"]);
|
||||
info.author = xjson!(&env["currentCoinbase"]);
|
||||
info.difficulty = xjson!(&env["currentDifficulty"]);
|
||||
info.gas_limit = xjson!(&env["currentGasLimit"]);
|
||||
info.number = xjson!(&env["currentNumber"]);
|
||||
@@ -199,11 +194,11 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
|
||||
// params
|
||||
let mut params = ActionParams::new();
|
||||
test.find("exec").map(|exec| {
|
||||
params.address = address_from_json(&exec["address"]);
|
||||
params.sender = address_from_json(&exec["caller"]);
|
||||
params.origin = address_from_json(&exec["origin"]);
|
||||
params.code = bytes_from_json(&exec["code"]);
|
||||
params.data = bytes_from_json(&exec["data"]);
|
||||
params.address = xjson!(&exec["address"]);
|
||||
params.sender = xjson!(&exec["caller"]);
|
||||
params.origin = xjson!(&exec["origin"]);
|
||||
params.code = xjson!(&exec["code"]);
|
||||
params.data = xjson!(&exec["data"]);
|
||||
params.gas = xjson!(&exec["gas"]);
|
||||
params.gas_price = xjson!(&exec["gasPrice"]);
|
||||
params.value = xjson!(&exec["value"]);
|
||||
@@ -231,23 +226,16 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
|
||||
//println!("name: {}, gas_left : {:?}, expected: {:?}", name, gas_left, U256::from(&test["gas"]));
|
||||
fail_unless(!out_of_gas, "expected to run out of gas.");
|
||||
fail_unless(gas_left == xjson!(&test["gas"]), "gas_left is incorrect");
|
||||
fail_unless(output == bytes_from_json(&test["out"]), "output is incorrect");
|
||||
fail_unless(output == Bytes::from_json(&test["out"]), "output is incorrect");
|
||||
|
||||
|
||||
test.find("post").map(|pre| for (addr, s) in pre.as_object().unwrap() {
|
||||
let address = Address::from(addr.as_ref());
|
||||
//let balance = U256::from(&s["balance"]);
|
||||
|
||||
fail_unless(state.code(&address).unwrap_or(vec![]) == bytes_from_json(&s["code"]), "code is incorrect");
|
||||
fail_unless(state.code(&address).unwrap_or(vec![]) == Bytes::from_json(&s["code"]), "code is incorrect");
|
||||
fail_unless(state.balance(&address) == xjson!(&s["balance"]), "balance is incorrect");
|
||||
fail_unless(state.nonce(&address) == xjson!(&s["nonce"]), "nonce is incorrect");
|
||||
|
||||
for (k, v) in s["storage"].as_object().unwrap() {
|
||||
let key = H256::from(&u256_from_str(k));
|
||||
let val = H256::from(&U256::from_json(v));
|
||||
|
||||
fail_unless(state.storage_at(&address, &key) == val, "storage is incorrect");
|
||||
}
|
||||
BTreeMap::from_json(&s["storage"]).iter().foreach(|(k, v)| fail_unless(&state.storage_at(&address, &k) == v, "storage is incorrect"));
|
||||
});
|
||||
|
||||
let cc = test["callcreates"].as_array().unwrap();
|
||||
@@ -255,8 +243,8 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
|
||||
for i in 0..cc.len() {
|
||||
let is = &callcreates[i];
|
||||
let expected = &cc[i];
|
||||
fail_unless(is.data == bytes_from_json(&expected["data"]), "callcreates data is incorrect");
|
||||
fail_unless(is.destination == address_from_json(&expected["destination"]), "callcreates destination is incorrect");
|
||||
fail_unless(is.data == Bytes::from_json(&expected["data"]), "callcreates data is incorrect");
|
||||
fail_unless(is.destination == xjson!(&expected["destination"]), "callcreates destination is incorrect");
|
||||
fail_unless(is.value == xjson!(&expected["value"]), "callcreates value is incorrect");
|
||||
|
||||
// TODO: call_gas is calculated in externalities and is not exposed to TestExt.
|
||||
|
||||
@@ -16,8 +16,8 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
|
||||
|
||||
let t = Transaction::from_json(&test["transaction"]);
|
||||
let env = EnvInfo::from_json(&test["env"]);
|
||||
let _out = bytes_from_json(&test["out"]);
|
||||
let post_state_root = h256_from_json(&test["postStateRoot"]);
|
||||
let _out = Bytes::from_json(&test["out"]);
|
||||
let post_state_root = xjson!(&test["postStateRoot"]);
|
||||
let pre = PodState::from_json(&test["pre"]);
|
||||
let post = PodState::from_json(&test["post"]);
|
||||
let logs: Vec<_> = test["logs"].as_array().unwrap().iter().map(&LogEntry::from_json).collect();
|
||||
|
||||
@@ -14,23 +14,23 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
|
||||
.and_then(|j| j.as_string())
|
||||
.and_then(|s| BlockNumber::from_str(s).ok())
|
||||
.unwrap_or(0) { x if x < 900000 => &old_schedule, _ => &new_schedule };
|
||||
let rlp = bytes_from_json(&test["rlp"]);
|
||||
let rlp = Bytes::from_json(&test["rlp"]);
|
||||
let res = UntrustedRlp::new(&rlp).as_val().map_err(|e| From::from(e)).and_then(|t: Transaction| t.validate(schedule, schedule.have_delegate_call));
|
||||
fail_unless(test.find("transaction").is_none() == res.is_err());
|
||||
if let (Some(&Json::Object(ref tx)), Some(&Json::String(ref expect_sender))) = (test.find("transaction"), test.find("sender")) {
|
||||
let t = res.unwrap();
|
||||
fail_unless(t.sender().unwrap() == address_from_hex(clean(expect_sender)));
|
||||
fail_unless(t.data == bytes_from_json(&tx["data"]));
|
||||
fail_unless(t.data == Bytes::from_json(&tx["data"]));
|
||||
fail_unless(t.gas == xjson!(&tx["gasLimit"]));
|
||||
fail_unless(t.gas_price == xjson!(&tx["gasPrice"]));
|
||||
fail_unless(t.nonce == xjson!(&tx["nonce"]));
|
||||
fail_unless(t.value == xjson!(&tx["value"]));
|
||||
if let Action::Call(ref to) = t.action {
|
||||
*ot.borrow_mut() = t.clone();
|
||||
fail_unless(to == &address_from_json(&tx["to"]));
|
||||
fail_unless(to == &xjson!(&tx["to"]));
|
||||
} else {
|
||||
*ot.borrow_mut() = t.clone();
|
||||
fail_unless(bytes_from_json(&tx["to"]).len() == 0);
|
||||
fail_unless(Bytes::from_json(&tx["to"]).len() == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user