Skip to content

Commit

Permalink
Fix all compiler warnings
Browse files Browse the repository at this point in the history
Summary: Fix all warnings of unused variables, unused imports and others.

Reviewers: sorpaas

Reviewed By: sorpaas

Subscribers: jenkins

Differential Revision: https://source.that.world/D50
  • Loading branch information
sorpaas committed Feb 7, 2018
1 parent 679623d commit 8ce6d08
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 92 deletions.
6 changes: 3 additions & 3 deletions cli/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use std::fs::File;
use profiler::Profiler;
use bigint::{Gas, Address, U256, M256, H256};
use hexutil::read_hex;
use sputnikvm::{HeaderParams, Context, SeqTransactionVM, ValidTransaction, VM, Log, Patch,
AccountCommitment, AccountChange, RequireError, TransactionAction, VMStatus,
use sputnikvm::{HeaderParams, Context, SeqTransactionVM, ValidTransaction, VM,
AccountCommitment, RequireError, TransactionAction, VMStatus,
SeqContextVM};
use sputnikvm_network_classic::{MainnetFrontierPatch, MainnetHomesteadPatch, MainnetEIP150Patch, MainnetEIP160Patch};
use gethrpc::{GethRPCClient, NormalGethRPCClient, RPCBlock};
Expand All @@ -30,7 +30,7 @@ fn from_rpc_block(block: &RPCBlock) -> HeaderParams {
timestamp: U256::from_str(&block.timestamp).unwrap().as_u64(),
number: U256::from_str(&block.number).unwrap(),
difficulty: U256::from_str(&block.difficulty).unwrap(),
gas_limit: Gas::from_str(&block.gasLimit).unwrap(),
gas_limit: Gas::from_str(&block.gas_limit).unwrap(),
}
}

Expand Down
3 changes: 1 addition & 2 deletions cli/src/bin/profiler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use sputnikvm::Opcode;
use std::collections::{HashMap, hash_map};
use std::cmp::Ordering;
use flame::Span;
Expand Down Expand Up @@ -33,7 +32,7 @@ impl Profiler {
pub fn print_stats(&self) {
println!("--- Profiler Stats ---");
let mut occs: Vec<_> = self.occurances.iter().collect();
occs.sort_by(|&(k1, v1), &(k2, v2)| {
occs.sort_by(|&(_k1, v1), &(_k2, v2)| {
match v1.1.partial_cmp(&v2.1) {
Some(val) => val,
None => Ordering::Equal,
Expand Down
73 changes: 39 additions & 34 deletions gethrpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ mod record;

pub use record::{RecordGethRPCClient, CachedGethRPCClient};

use std::process::Command;
use std::io::Read;
use hyper::header::ContentType;
use hyper::Client;
use hyper::net::HttpsConnector;
use hyper_native_tls::NativeTlsClient;
use serde_json::Value;

#[derive(Serialize, Deserialize)]
struct RPCRequest {
Expand All @@ -42,47 +40,50 @@ struct RPCObjectResponse<T> {
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct RPCTransaction {
pub hash: String,
pub nonce: String,
pub blockHash: String,
pub blockNumber: String,
pub transactionIndex: String,
pub block_hash: String,
pub block_number: String,
pub transaction_index: String,
pub from: String,
pub to: String,
pub value: String,
pub gas: String,
pub gasPrice: String,
pub gas_price: String,
pub input: String,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct RPCCall {
pub from: String,
pub to: String,
pub gas: String,
pub gasPrice: String,
pub gas_price: String,
pub value: String,
pub data: String,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct RPCBlock {
pub number: String,
pub hash: String,
pub parentHash: String,
pub parent_hash: String,
pub nonce: String,
pub sha3Uncles: String,
pub logsBloom: String,
pub transactionsRoot: String,
pub stateRoot: String,
pub sha3_uncles: String,
pub logs_bloom: String,
pub transactions_root: String,
pub state_root: String,
pub miner: String,
pub difficulty: String,
pub totalDifficulty: String,
pub extraData: String,
pub total_difficulty: String,
pub extra_data: String,
pub size: String,
pub gasLimit: String,
pub gasUsed: String,
pub gas_limit: String,
pub gas_used: String,
pub timestamp: String,
#[serde(default)]
pub transactions: Vec<String>,
Expand All @@ -91,43 +92,47 @@ pub struct RPCBlock {

#[derive(Serialize, Deserialize, Debug)]
#[serde(untagged)]
#[serde(rename_all = "camelCase")]
pub enum RPCSyncStatus {
NotSync(bool),
Sync {
startingBlock: String,
currentBlock: String,
highestBlock: String,
starting_block: String,
current_block: String,
highest_block: String,
},
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct RPCTransactionReceipt {
pub transactionHash: String,
pub transactionIndex: String,
pub blockHash: String,
pub blockNumber: String,
pub cumulativeGasUsed: String,
pub gasUsed: String,
pub contractAddress: String,
pub transaction_hash: String,
pub transaction_index: String,
pub block_hash: String,
pub block_number: String,
pub cumulative_gas_used: String,
pub gas_used: String,
pub contract_address: String,
pub logs: Vec<RPCLog>,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct RPCLog {
pub logIndex: String,
pub transactionIndex: String,
pub transactionHash: String,
pub blockHash: String,
pub blockNumber: String,
pub log_index: String,
pub transaction_index: String,
pub transaction_hash: String,
pub block_hash: String,
pub block_number: String,
pub address: String,
pub data: String,
pub topics: Vec<String>,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct RPCFilter {
pub fromBlock: String,
pub toBlock: String,
pub from_block: String,
pub to_block: String,
pub address: String,
pub topics: Vec<String>,
}
Expand Down Expand Up @@ -156,7 +161,7 @@ pub trait GethRPCClient {
self.rpc_request::<String>("net_peerCount", vec![])
}
fn sha3(&mut self, data: &str) -> String {
self.rpc_request::<String>("web3_sha3", vec![])
self.rpc_request::<String>("web3_sha3", vec![data.to_string()])
}
fn protocol_version(&mut self) -> String {
self.rpc_request::<String>("eth_protocolVersion", vec![])
Expand Down
1 change: 0 additions & 1 deletion gethrpc/src/record.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use serde_json::Value;
use super::{GethRPCClient, RPCObjectRequest, RPCObjectResponse};

use serde;
Expand Down
14 changes: 7 additions & 7 deletions jsontests/src/blockchain.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bigint::{Gas, M256, U256, H256, Address};
use hexutil::*;
use sputnikvm::{Machine, Log, Context,
AccountChange, Storage, AccountCommitment,
use sputnikvm::{Log, Context,
AccountChange, AccountCommitment,
HeaderParams};

use serde_json::Value;
Expand Down Expand Up @@ -78,11 +78,11 @@ impl JSONBlock {
pub fn apply_account(&mut self, account: AccountChange) {
match account {
AccountChange::Full {
address: address,
balance: balance,
changing_storage: changing_storage,
code: code,
nonce: nonce,
address,
balance,
changing_storage,
code,
nonce,
} => {
self.set_balance(address, balance);
self.set_account_code(address, code.as_slice());
Expand Down
16 changes: 8 additions & 8 deletions jsontests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ use std::sync::{Arc, Mutex};
use bigint::{Gas, M256, U256, H256, Address};
use hexutil::*;
use sputnikvm::errors::RequireError;
use sputnikvm::{VM, SeqContextVM, AccountCommitment, Context, AccountChange, Storage, Patch, VMStatus, VMTestPatch};
use sputnikvm::{VM, SeqContextVM, Context, VMStatus, VMTestPatch};

pub fn fire_with_block(machine: &mut SeqContextVM<VMTestPatch>, block: &JSONBlock) {
loop {
match machine.fire() {
Err(RequireError::Account(address)) => {
let account = block.request_account(address);
machine.commit_account(account);
machine.commit_account(account).unwrap();
},
Err(RequireError::AccountCode(address)) => {
let account = block.request_account_code(address);
machine.commit_account(account);
machine.commit_account(account).unwrap();
},
Err(RequireError::AccountStorage(address, index)) => {
let account = block.request_account_storage(address, index);
machine.commit_account(account);
machine.commit_account(account).unwrap();
},
Err(RequireError::Blockhash(number)) => {
// The test JSON file doesn't expose any block
Expand All @@ -48,7 +48,7 @@ pub fn fire_with_block(machine: &mut SeqContextVM<VMTestPatch>, block: &JSONBloc
panic!();
};

machine.commit_blockhash(number, hash);
machine.commit_blockhash(number, hash).unwrap();
},
Ok(()) => return,
}
Expand Down Expand Up @@ -252,10 +252,10 @@ fn is_ok(status: VMStatus) -> bool {
}
}

pub fn test_transaction(name: &str, v: &Value, debug: bool) -> bool {
pub fn test_transaction(_name: &str, v: &Value, debug: bool) -> bool {
let mut block = create_block(v);
let mut history: Arc<Mutex<Vec<Context>>> = Arc::new(Mutex::new(Vec::new()));
let mut history_closure = history.clone();
let history: Arc<Mutex<Vec<Context>>> = Arc::new(Mutex::new(Vec::new()));
let history_closure = history.clone();
let mut machine = create_machine(v, &block);
machine.add_context_history_hook(move |context| {
history_closure.lock().unwrap().push(context.clone());
Expand Down
2 changes: 1 addition & 1 deletion precompiled/bn128/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::rc::Rc;
use bigint::{Gas, U256};

use sputnikvm::Precompiled;
use sputnikvm::errors::{OnChainError, RuntimeError, NotSupportedError};
use sputnikvm::errors::{OnChainError, RuntimeError};

pub static BN128_ADD_PRECOMPILED: Bn128AddPrecompiled = Bn128AddPrecompiled;

Expand Down
9 changes: 4 additions & 5 deletions precompiled/modexp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,20 @@ impl Precompiled for ModexpPrecompiled {
#[cfg(test)]
mod tests {
use ::*;
use bigint::*;
use hexutil::*;

#[test]
fn spec_test1() {
let input = read_hex("00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002003fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2efffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f").unwrap();
let (gas, output) = MODEXP_PRECOMPILED.gas_and_step(&input, Gas::from(10000000usize)).unwrap();
let (_, output) = MODEXP_PRECOMPILED.gas_and_step(&input, Gas::from(10000000usize)).unwrap();
let expected = read_hex("0000000000000000000000000000000000000000000000000000000000000001").unwrap();
assert_eq!(expected, Rc::try_unwrap(output).unwrap());
}

#[test]
fn spec_test2() {
let input = read_hex("000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2efffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f").unwrap();
let (gas, output) = MODEXP_PRECOMPILED.gas_and_step(&input, Gas::from(10000000usize)).unwrap();
let (_, output) = MODEXP_PRECOMPILED.gas_and_step(&input, Gas::from(10000000usize)).unwrap();
let expected = read_hex("0000000000000000000000000000000000000000000000000000000000000000").unwrap();
assert_eq!(expected, Rc::try_unwrap(output).unwrap());
}
Expand All @@ -163,15 +162,15 @@ mod tests {
#[test]
fn spec_test4() {
let input = read_hex("00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000002003ffff800000000000000000000000000000000000000000000000000000000000000007").unwrap();
let (gas, output) = MODEXP_PRECOMPILED.gas_and_step(&input, Gas::from(10000000usize)).unwrap();
let (_, output) = MODEXP_PRECOMPILED.gas_and_step(&input, Gas::from(10000000usize)).unwrap();
let expected = read_hex("3b01b01ac41f2d6e917c6d6a221ce793802469026d9ab7578fa2e79e4da6aaab").unwrap();
assert_eq!(expected, Rc::try_unwrap(output).unwrap());
}

#[test]
fn sepc_test5() {
let input = read_hex("00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000002003ffff80").unwrap();
let (gas, output) = MODEXP_PRECOMPILED.gas_and_step(&input, Gas::from(10000000usize)).unwrap();
let (_, output) = MODEXP_PRECOMPILED.gas_and_step(&input, Gas::from(10000000usize)).unwrap();
let expected = read_hex("3b01b01ac41f2d6e917c6d6a221ce793802469026d9ab7578fa2e79e4da6aaab").unwrap();
assert_eq!(expected, Rc::try_unwrap(output).unwrap());
}
Expand Down
24 changes: 10 additions & 14 deletions regtests/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,28 @@ extern crate block;
extern crate bigint;
extern crate hexutil;

use serde_json::{Value};
use std::process;
use std::fs::File;
use std::path::Path;
use std::io::{BufReader};
use std::str::FromStr;
use std::rc::Rc;
use std::collections::{HashMap, HashSet};
use std::collections::HashMap;

use block::TransactionAction;
use bigint::{Gas, Address, U256, M256, H256};
use hexutil::*;
use sputnikvm::{HeaderParams, Context, SeqTransactionVM, ValidTransaction, VM, Log, Patch,
AccountCommitment, AccountChange};
use sputnikvm::{HeaderParams, SeqTransactionVM, ValidTransaction, VM, Log, Patch,
AccountCommitment, AccountChange};
use sputnikvm_network_classic::{MainnetFrontierPatch, MainnetHomesteadPatch,
MainnetEIP150Patch, MainnetEIP160Patch};
MainnetEIP150Patch, MainnetEIP160Patch};
use sputnikvm::errors::RequireError;
use gethrpc::{GethRPCClient, NormalGethRPCClient, RecordGethRPCClient, CachedGethRPCClient, RPCCall, RPCBlock, RPCTransaction, RPCLog};
use gethrpc::{GethRPCClient, NormalGethRPCClient, RecordGethRPCClient, CachedGethRPCClient, RPCBlock, RPCTransaction, RPCLog};

fn from_rpc_block(block: &RPCBlock) -> HeaderParams {
HeaderParams {
beneficiary: Address::from_str(&block.miner).unwrap(),
timestamp: U256::from_str(&block.timestamp).unwrap().into(),
number: U256::from_str(&block.number).unwrap(),
difficulty: U256::from_str(&block.difficulty).unwrap(),
gas_limit: Gas::from_str(&block.gasLimit).unwrap(),
gas_limit: Gas::from_str(&block.gas_limit).unwrap(),
}
}

Expand All @@ -47,7 +43,7 @@ fn from_rpc_transaction(transaction: &RPCTransaction) -> ValidTransaction {
},
value: U256::from_str(&transaction.value).unwrap(),
gas_limit: Gas::from_str(&transaction.gas).unwrap(),
gas_price: Gas::from_str(&transaction.gasPrice).unwrap(),
gas_price: Gas::from_str(&transaction.gas_price).unwrap(),
input: Rc::new(read_hex(&transaction.input).unwrap()),
nonce: U256::from_str(&transaction.nonce).unwrap(),
}
Expand Down Expand Up @@ -116,7 +112,7 @@ fn handle_fire<T: GethRPCClient, P: Patch>(client: &mut T, vm: &mut SeqTransacti
println!("Feeding blockhash with number 0x{:x} ...", number);
let hash = H256::from_str(&client.get_block_by_number(&format!("0x{:x}", number))
.hash).unwrap();
vm.commit_blockhash(number, hash);
vm.commit_blockhash(number, hash).unwrap();
},
}
}
Expand Down Expand Up @@ -165,7 +161,7 @@ fn test_block<T: GethRPCClient, P: Patch>(client: &mut T, number: usize) {

handle_fire(client, &mut vm, last_id);

assert!(Gas::from_str(&receipt.gasUsed).unwrap() == vm.used_gas());
assert!(Gas::from_str(&receipt.gas_used).unwrap() == vm.used_gas());
assert!(receipt.logs.len() == vm.logs().len());
for i in 0..receipt.logs.len() {
assert!(from_rpc_log(&receipt.logs[i]) == vm.logs()[i]);
Expand Down Expand Up @@ -301,7 +297,7 @@ fn main() {
let mut file = File::create(val).unwrap();
let mut client = RecordGethRPCClient::new(address);
test_blocks_patch(&mut client, number, patch);
serde_json::to_writer(&mut file, &client.to_value());
serde_json::to_writer(&mut file, &client.to_value()).unwrap();
},
None => {
let mut client = NormalGethRPCClient::new(address);
Expand Down
Loading

0 comments on commit 8ce6d08

Please sign in to comment.