test for eth_getTransactionReceipt
This commit is contained in:
parent
52e9801721
commit
068c0f3782
@ -20,7 +20,7 @@ use util::hash::H256;
|
|||||||
use header::BlockNumber;
|
use header::BlockNumber;
|
||||||
|
|
||||||
/// Uniquely identifies block.
|
/// Uniquely identifies block.
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone, Hash, Eq)]
|
||||||
pub enum BlockId {
|
pub enum BlockId {
|
||||||
/// Block's sha3.
|
/// Block's sha3.
|
||||||
/// Querying by hash is always faster.
|
/// Querying by hash is always faster.
|
||||||
@ -34,7 +34,7 @@ pub enum BlockId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Uniquely identifies transaction.
|
/// Uniquely identifies transaction.
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone, Hash, Eq)]
|
||||||
pub enum TransactionId {
|
pub enum TransactionId {
|
||||||
/// Transaction's sha3.
|
/// Transaction's sha3.
|
||||||
Hash(H256),
|
Hash(H256),
|
||||||
|
@ -52,6 +52,8 @@ pub struct TestBlockChainClient {
|
|||||||
pub code: RwLock<HashMap<Address, Bytes>>,
|
pub code: RwLock<HashMap<Address, Bytes>>,
|
||||||
/// Execution result.
|
/// Execution result.
|
||||||
pub execution_result: RwLock<Option<Executed>>,
|
pub execution_result: RwLock<Option<Executed>>,
|
||||||
|
/// Transaction receipts.
|
||||||
|
pub receipts: RwLock<HashMap<TransactionId, LocalizedReceipt>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -87,12 +89,18 @@ impl TestBlockChainClient {
|
|||||||
storage: RwLock::new(HashMap::new()),
|
storage: RwLock::new(HashMap::new()),
|
||||||
code: RwLock::new(HashMap::new()),
|
code: RwLock::new(HashMap::new()),
|
||||||
execution_result: RwLock::new(None),
|
execution_result: RwLock::new(None),
|
||||||
|
receipts: RwLock::new(HashMap::new()),
|
||||||
};
|
};
|
||||||
client.add_blocks(1, EachBlockWith::Nothing); // add genesis block
|
client.add_blocks(1, EachBlockWith::Nothing); // add genesis block
|
||||||
client.genesis_hash = client.last_hash.read().unwrap().clone();
|
client.genesis_hash = client.last_hash.read().unwrap().clone();
|
||||||
client
|
client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set the transaction receipt result
|
||||||
|
pub fn set_transaction_receipt(&self, id: TransactionId, receipt: LocalizedReceipt) {
|
||||||
|
self.receipts.write().unwrap().insert(id, receipt);
|
||||||
|
}
|
||||||
|
|
||||||
/// Set the execution result.
|
/// Set the execution result.
|
||||||
pub fn set_execution_result(&self, result: Executed) {
|
pub fn set_execution_result(&self, result: Executed) {
|
||||||
*self.execution_result.write().unwrap() = Some(result);
|
*self.execution_result.write().unwrap() = Some(result);
|
||||||
@ -224,8 +232,8 @@ impl BlockChainClient for TestBlockChainClient {
|
|||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn transaction_receipt(&self, _id: TransactionId) -> Option<LocalizedReceipt> {
|
fn transaction_receipt(&self, id: TransactionId) -> Option<LocalizedReceipt> {
|
||||||
unimplemented!();
|
self.receipts.read().unwrap().get(&id).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn blocks_with_bloom(&self, _bloom: &H2048, _from_block: BlockId, _to_block: BlockId) -> Option<Vec<BlockNumber>> {
|
fn blocks_with_bloom(&self, _bloom: &H2048, _from_block: BlockId, _to_block: BlockId) -> Option<Vec<BlockNumber>> {
|
||||||
|
@ -78,7 +78,7 @@ impl FromJson for LogEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Log localized in a blockchain.
|
/// Log localized in a blockchain.
|
||||||
#[derive(Default, Debug, PartialEq)]
|
#[derive(Default, Debug, PartialEq, Clone)]
|
||||||
pub struct LocalizedLogEntry {
|
pub struct LocalizedLogEntry {
|
||||||
/// Plain log entry.
|
/// Plain log entry.
|
||||||
pub entry: LogEntry,
|
pub entry: LogEntry,
|
||||||
|
@ -76,6 +76,7 @@ impl HeapSizeOf for Receipt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Receipt with additional info.
|
/// Receipt with additional info.
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct LocalizedReceipt {
|
pub struct LocalizedReceipt {
|
||||||
/// Transaction hash.
|
/// Transaction hash.
|
||||||
pub transaction_hash: H256,
|
pub transaction_hash: H256,
|
||||||
|
@ -14,12 +14,15 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
use std::str::FromStr;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
use jsonrpc_core::IoHandler;
|
use jsonrpc_core::IoHandler;
|
||||||
use util::hash::{Address, H256};
|
use util::hash::{Address, H256, FixedHash};
|
||||||
use util::numbers::{Uint, U256};
|
use util::numbers::{Uint, U256};
|
||||||
use ethcore::client::{TestBlockChainClient, EachBlockWith, Executed};
|
use ethcore::client::{TestBlockChainClient, EachBlockWith, Executed, TransactionId};
|
||||||
|
use ethcore::log_entry::{LocalizedLogEntry, LogEntry};
|
||||||
|
use ethcore::receipt::LocalizedReceipt;
|
||||||
use v1::{Eth, EthClient};
|
use v1::{Eth, EthClient};
|
||||||
use v1::tests::helpers::{TestAccount, TestAccountProvider, TestSyncProvider, Config, TestMinerService, TestExternalMiner};
|
use v1::tests::helpers::{TestAccount, TestAccountProvider, TestSyncProvider, Config, TestMinerService, TestExternalMiner};
|
||||||
|
|
||||||
@ -382,6 +385,63 @@ fn rpc_eth_sign() {
|
|||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rpc_eth_transaction_receipt() {
|
||||||
|
let receipt = LocalizedReceipt {
|
||||||
|
transaction_hash: H256::zero(),
|
||||||
|
transaction_index: 0,
|
||||||
|
block_hash: H256::from_str("ed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5").unwrap(),
|
||||||
|
block_number: 0x4510c,
|
||||||
|
cumulative_gas_used: U256::from(0x20),
|
||||||
|
gas_used: U256::from(0x10),
|
||||||
|
contract_address: None,
|
||||||
|
logs: vec![LocalizedLogEntry {
|
||||||
|
entry: LogEntry {
|
||||||
|
address: Address::from_str("33990122638b9132ca29c723bdf037f1a891a70c").unwrap(),
|
||||||
|
topics: vec![
|
||||||
|
H256::from_str("a6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc").unwrap(),
|
||||||
|
H256::from_str("4861736852656700000000000000000000000000000000000000000000000000").unwrap()
|
||||||
|
],
|
||||||
|
data: vec![],
|
||||||
|
},
|
||||||
|
block_hash: H256::from_str("ed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5").unwrap(),
|
||||||
|
block_number: 0x4510c,
|
||||||
|
transaction_hash: H256::new(),
|
||||||
|
transaction_index: 0,
|
||||||
|
log_index: 1,
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
|
||||||
|
let hash = H256::from_str("b903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238").unwrap();
|
||||||
|
let tester = EthTester::default();
|
||||||
|
tester.client.set_transaction_receipt(TransactionId::Hash(hash), receipt);
|
||||||
|
|
||||||
|
let request = r#"{
|
||||||
|
"jsonrpc": "2.0",
|
||||||
|
"method": "eth_getTransactionReceipt",
|
||||||
|
"params": ["0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"],
|
||||||
|
"id": 1
|
||||||
|
}"#;
|
||||||
|
let response = r#"{"jsonrpc":"2.0","result":{"blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x04510c","contractAddress":null,"cumulativeGasUsed":"0x20","gasUsed":"0x10","logs":[{"address":"0x33990122638b9132ca29c723bdf037f1a891a70c","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x04510c","data":"0x","logIndex":"0x01","topics":["0xa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc","0x4861736852656700000000000000000000000000000000000000000000000000"],"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x00"}],"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x00"},"id":1}"#;
|
||||||
|
|
||||||
|
assert_eq!(tester.io.handle_request(request), Some(response.to_owned()));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rpc_eth_transaction_receipt_null() {
|
||||||
|
let tester = EthTester::default();
|
||||||
|
|
||||||
|
let request = r#"{
|
||||||
|
"jsonrpc": "2.0",
|
||||||
|
"method": "eth_getTransactionReceipt",
|
||||||
|
"params": ["0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"],
|
||||||
|
"id": 1
|
||||||
|
}"#;
|
||||||
|
let response = r#"{"jsonrpc":"2.0","result":null,"id":1}"#;
|
||||||
|
|
||||||
|
assert_eq!(tester.io.handle_request(request), Some(response.to_owned()));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn rpc_eth_compilers() {
|
fn rpc_eth_compilers() {
|
||||||
let request = r#"{"jsonrpc": "2.0", "method": "eth_getCompilers", "params": [], "id": 1}"#;
|
let request = r#"{"jsonrpc": "2.0", "method": "eth_getCompilers", "params": [], "id": 1}"#;
|
||||||
|
@ -20,19 +20,19 @@ use v1::types::Bytes;
|
|||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
pub struct Log {
|
pub struct Log {
|
||||||
address: Address,
|
pub address: Address,
|
||||||
topics: Vec<H256>,
|
pub topics: Vec<H256>,
|
||||||
data: Bytes,
|
pub data: Bytes,
|
||||||
#[serde(rename="blockHash")]
|
#[serde(rename="blockHash")]
|
||||||
block_hash: H256,
|
pub block_hash: H256,
|
||||||
#[serde(rename="blockNumber")]
|
#[serde(rename="blockNumber")]
|
||||||
block_number: U256,
|
pub block_number: U256,
|
||||||
#[serde(rename="transactionHash")]
|
#[serde(rename="transactionHash")]
|
||||||
transaction_hash: H256,
|
pub transaction_hash: H256,
|
||||||
#[serde(rename="transactionIndex")]
|
#[serde(rename="transactionIndex")]
|
||||||
transaction_index: U256,
|
pub transaction_index: U256,
|
||||||
#[serde(rename="logIndex")]
|
#[serde(rename="logIndex")]
|
||||||
log_index: U256,
|
pub log_index: U256,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<LocalizedLogEntry> for Log {
|
impl From<LocalizedLogEntry> for Log {
|
||||||
|
@ -53,4 +53,42 @@ impl From<LocalizedReceipt> for Receipt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use serde_json;
|
||||||
|
use std::str::FromStr;
|
||||||
|
use util::numbers::*;
|
||||||
|
use v1::types::{Bytes, Log, Receipt};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn receipt_serialization() {
|
||||||
|
let s = r#"{"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x00","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x04510c","cumulativeGasUsed":"0x20","gasUsed":"0x10","contractAddress":null,"logs":[{"address":"0x33990122638b9132ca29c723bdf037f1a891a70c","topics":["0xa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc","0x4861736852656700000000000000000000000000000000000000000000000000"],"data":"0x","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x04510c","transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x00","logIndex":"0x01"}]}"#;
|
||||||
|
|
||||||
|
let receipt = Receipt {
|
||||||
|
transaction_hash: H256::zero(),
|
||||||
|
transaction_index: U256::zero(),
|
||||||
|
block_hash: H256::from_str("ed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5").unwrap(),
|
||||||
|
block_number: U256::from(0x4510c),
|
||||||
|
cumulative_gas_used: U256::from(0x20),
|
||||||
|
gas_used: U256::from(0x10),
|
||||||
|
contract_address: None,
|
||||||
|
logs: vec![Log {
|
||||||
|
address: Address::from_str("33990122638b9132ca29c723bdf037f1a891a70c").unwrap(),
|
||||||
|
topics: vec![
|
||||||
|
H256::from_str("a6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc").unwrap(),
|
||||||
|
H256::from_str("4861736852656700000000000000000000000000000000000000000000000000").unwrap()
|
||||||
|
],
|
||||||
|
data: Bytes::new(vec![]),
|
||||||
|
block_hash: H256::from_str("ed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5").unwrap(),
|
||||||
|
block_number: U256::from(0x4510c),
|
||||||
|
transaction_hash: H256::new(),
|
||||||
|
transaction_index: U256::zero(),
|
||||||
|
log_index: U256::one()
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
|
||||||
|
let serialized = serde_json::to_string(&receipt).unwrap();
|
||||||
|
assert_eq!(serialized, s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user