mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 00:42:42 +00:00
Finish adding tests
This commit is contained in:
@@ -69,7 +69,7 @@ pub trait EngineApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
#[serde(rename = "SCREAMING_SNAKE_CASE")]
|
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
|
||||||
pub enum ExecutePayloadResponse {
|
pub enum ExecutePayloadResponse {
|
||||||
Valid,
|
Valid,
|
||||||
Invalid,
|
Invalid,
|
||||||
@@ -77,7 +77,7 @@ pub enum ExecutePayloadResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
#[serde(rename = "SCREAMING_SNAKE_CASE")]
|
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
|
||||||
pub enum ConsensusStatus {
|
pub enum ConsensusStatus {
|
||||||
Valid,
|
Valid,
|
||||||
Invalid,
|
Invalid,
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ impl EngineApi for HttpJsonRpc {
|
|||||||
fee_recipient
|
fee_recipient
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
let response: JsonPreparePayloadResponse = self
|
let response: JsonPayloadId = self
|
||||||
.rpc_request(
|
.rpc_request(
|
||||||
ENGINE_PREPARE_PAYLOAD,
|
ENGINE_PREPARE_PAYLOAD,
|
||||||
params,
|
params,
|
||||||
@@ -145,7 +145,7 @@ impl EngineApi for HttpJsonRpc {
|
|||||||
&self,
|
&self,
|
||||||
payload_id: PayloadId,
|
payload_id: PayloadId,
|
||||||
) -> Result<ExecutionPayload<T>, Error> {
|
) -> Result<ExecutionPayload<T>, Error> {
|
||||||
let params = json!([payload_id]);
|
let params = json!([JsonPayloadId { payload_id }]);
|
||||||
|
|
||||||
self.rpc_request(ENGINE_GET_PAYLOAD, params, ENGINE_GET_PAYLOAD_TIMEOUT)
|
self.rpc_request(ENGINE_GET_PAYLOAD, params, ENGINE_GET_PAYLOAD_TIMEOUT)
|
||||||
.await
|
.await
|
||||||
@@ -215,13 +215,13 @@ struct JsonPreparePayloadRequest {
|
|||||||
|
|
||||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
#[serde(transparent, rename_all = "camelCase")]
|
#[serde(transparent, rename_all = "camelCase")]
|
||||||
struct JsonPreparePayloadResponse {
|
struct JsonPayloadId {
|
||||||
#[serde(with = "eth2_serde_utils::u64_hex_be")]
|
#[serde(with = "eth2_serde_utils::u64_hex_be")]
|
||||||
payload_id: u64,
|
payload_id: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
#[serde(bound = "T: EthSpec")]
|
#[serde(bound = "T: EthSpec", rename_all = "camelCase")]
|
||||||
pub struct JsonExecutionPayload<T: EthSpec> {
|
pub struct JsonExecutionPayload<T: EthSpec> {
|
||||||
pub parent_hash: Hash256,
|
pub parent_hash: Hash256,
|
||||||
pub coinbase: Address,
|
pub coinbase: Address,
|
||||||
@@ -239,6 +239,7 @@ pub struct JsonExecutionPayload<T: EthSpec> {
|
|||||||
#[serde(with = "eth2_serde_utils::u64_hex_be")]
|
#[serde(with = "eth2_serde_utils::u64_hex_be")]
|
||||||
pub timestamp: u64,
|
pub timestamp: u64,
|
||||||
pub base_fee_per_gas: Hash256,
|
pub base_fee_per_gas: Hash256,
|
||||||
|
// FIXME(paul): add extraData
|
||||||
pub block_hash: Hash256,
|
pub block_hash: Hash256,
|
||||||
// FIXME(paul): add transaction parsing.
|
// FIXME(paul): add transaction parsing.
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
@@ -351,6 +352,143 @@ mod test {
|
|||||||
const HASH_00: &str = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
const HASH_00: &str = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
||||||
const HASH_01: &str = "0x0101010101010101010101010101010101010101010101010101010101010101";
|
const HASH_01: &str = "0x0101010101010101010101010101010101010101010101010101010101010101";
|
||||||
|
|
||||||
|
const ADDRESS_00: &str = "0x0000000000000000000000000000000000000000";
|
||||||
|
const ADDRESS_01: &str = "0x0101010101010101010101010101010101010101";
|
||||||
|
|
||||||
|
const LOGS_BLOOM_01: &str = "0x01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101";
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn prepare_payload_request() {
|
||||||
|
Tester::new()
|
||||||
|
.assert_request_equals(
|
||||||
|
|client| async move {
|
||||||
|
let _ = client
|
||||||
|
.prepare_payload(
|
||||||
|
Hash256::repeat_byte(0),
|
||||||
|
42,
|
||||||
|
Hash256::repeat_byte(1),
|
||||||
|
Address::repeat_byte(0),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
},
|
||||||
|
json!({
|
||||||
|
"id": STATIC_ID,
|
||||||
|
"jsonrpc": JSONRPC_VERSION,
|
||||||
|
"method": ENGINE_PREPARE_PAYLOAD,
|
||||||
|
"params": [{
|
||||||
|
"parentHash": HASH_00,
|
||||||
|
"timestamp": "0x2a",
|
||||||
|
"random": HASH_01,
|
||||||
|
"feeRecipient": ADDRESS_00,
|
||||||
|
}]
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn get_payload_request() {
|
||||||
|
Tester::new()
|
||||||
|
.assert_request_equals(
|
||||||
|
|client| async move {
|
||||||
|
let _ = client.get_payload::<MainnetEthSpec>(42).await;
|
||||||
|
},
|
||||||
|
json!({
|
||||||
|
"id": STATIC_ID,
|
||||||
|
"jsonrpc": JSONRPC_VERSION,
|
||||||
|
"method": ENGINE_GET_PAYLOAD,
|
||||||
|
"params": ["0x2a"]
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn execute_payload_request() {
|
||||||
|
Tester::new()
|
||||||
|
.assert_request_equals(
|
||||||
|
|client| async move {
|
||||||
|
let _ = client
|
||||||
|
.execute_payload::<MainnetEthSpec>(ExecutionPayload {
|
||||||
|
parent_hash: Hash256::repeat_byte(0),
|
||||||
|
coinbase: Address::repeat_byte(1),
|
||||||
|
state_root: Hash256::repeat_byte(1),
|
||||||
|
receipt_root: Hash256::repeat_byte(0),
|
||||||
|
logs_bloom: vec![01; 256].into(),
|
||||||
|
random: Hash256::repeat_byte(1),
|
||||||
|
block_number: 0,
|
||||||
|
gas_limit: 1,
|
||||||
|
gas_used: 2,
|
||||||
|
timestamp: 42,
|
||||||
|
base_fee_per_gas: Hash256::repeat_byte(0),
|
||||||
|
block_hash: Hash256::repeat_byte(1),
|
||||||
|
transactions: vec![].into(),
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
},
|
||||||
|
json!({
|
||||||
|
"id": STATIC_ID,
|
||||||
|
"jsonrpc": JSONRPC_VERSION,
|
||||||
|
"method": ENGINE_EXECUTE_PAYLOAD,
|
||||||
|
"params": [{
|
||||||
|
"parentHash": HASH_00,
|
||||||
|
"coinbase": ADDRESS_01,
|
||||||
|
"stateRoot": HASH_01,
|
||||||
|
"receiptRoot": HASH_00,
|
||||||
|
"logsBloom": LOGS_BLOOM_01,
|
||||||
|
"random": HASH_01,
|
||||||
|
"blockNumber": "0x0",
|
||||||
|
"gasLimit": "0x1",
|
||||||
|
"gasUsed": "0x2",
|
||||||
|
"timestamp": "0x2a",
|
||||||
|
"baseFeePerGas": HASH_00,
|
||||||
|
"blockHash": HASH_01,
|
||||||
|
"transactions": [],
|
||||||
|
}]
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn consensus_validated_request() {
|
||||||
|
Tester::new()
|
||||||
|
.assert_request_equals(
|
||||||
|
|client| async move {
|
||||||
|
let _ = client
|
||||||
|
.consensus_validated(Hash256::repeat_byte(0), ConsensusStatus::Valid)
|
||||||
|
.await;
|
||||||
|
},
|
||||||
|
json!({
|
||||||
|
"id": STATIC_ID,
|
||||||
|
"jsonrpc": JSONRPC_VERSION,
|
||||||
|
"method": ENGINE_CONSENSUS_VALIDATED,
|
||||||
|
"params": [{
|
||||||
|
"blockHash": HASH_00,
|
||||||
|
"status": "VALID",
|
||||||
|
}]
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.assert_request_equals(
|
||||||
|
|client| async move {
|
||||||
|
let _ = client
|
||||||
|
.consensus_validated(Hash256::repeat_byte(1), ConsensusStatus::Invalid)
|
||||||
|
.await;
|
||||||
|
},
|
||||||
|
json!({
|
||||||
|
"id": STATIC_ID,
|
||||||
|
"jsonrpc": JSONRPC_VERSION,
|
||||||
|
"method": ENGINE_CONSENSUS_VALIDATED,
|
||||||
|
"params": [{
|
||||||
|
"blockHash": HASH_01,
|
||||||
|
"status": "INVALID",
|
||||||
|
}]
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn forkchoice_updated_request() {
|
async fn forkchoice_updated_request() {
|
||||||
Tester::new()
|
Tester::new()
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ pub mod signed_voluntary_exit;
|
|||||||
pub mod signing_data;
|
pub mod signing_data;
|
||||||
pub mod sync_committee_subscription;
|
pub mod sync_committee_subscription;
|
||||||
pub mod sync_duty;
|
pub mod sync_duty;
|
||||||
pub mod transition_store;
|
// pub mod transition_store;
|
||||||
pub mod validator;
|
pub mod validator;
|
||||||
pub mod validator_subscription;
|
pub mod validator_subscription;
|
||||||
pub mod voluntary_exit;
|
pub mod voluntary_exit;
|
||||||
@@ -153,7 +153,7 @@ pub use crate::sync_committee_subscription::SyncCommitteeSubscription;
|
|||||||
pub use crate::sync_duty::SyncDuty;
|
pub use crate::sync_duty::SyncDuty;
|
||||||
pub use crate::sync_selection_proof::SyncSelectionProof;
|
pub use crate::sync_selection_proof::SyncSelectionProof;
|
||||||
pub use crate::sync_subnet_id::SyncSubnetId;
|
pub use crate::sync_subnet_id::SyncSubnetId;
|
||||||
pub use crate::transition_store::TransitionStore;
|
// pub use crate::transition_store::TransitionStore;
|
||||||
pub use crate::validator::Validator;
|
pub use crate::validator::Validator;
|
||||||
pub use crate::validator_subscription::ValidatorSubscription;
|
pub use crate::validator_subscription::ValidatorSubscription;
|
||||||
pub use crate::voluntary_exit::VoluntaryExit;
|
pub use crate::voluntary_exit::VoluntaryExit;
|
||||||
|
|||||||
Reference in New Issue
Block a user