diff --git a/README.md b/README.md index 55f70397..5afd9b4f 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Quick overview of the current status, providing implementation progress and test | [![conf_007](https://img.shields.io/badge/007-██████████-red) ](SPEC.md#ZG-CONFORMANCE-007)| :warning: Need to confirm expected behaviour with zcash. | [![conf_008](https://img.shields.io/badge/008-████░░░░░░-red) ](SPEC.md#ZG-CONFORMANCE-008)| :warning: Need to confirm expected behaviour with zcash. | [![conf_009](https://img.shields.io/badge/009-██████░░░░-green) ](SPEC.md#ZG-CONFORMANCE-009)| -| [![conf_010](https://img.shields.io/badge/010-░░░░░░░░░░-inactive)](SPEC.md#ZG-CONFORMANCE-010)| +| [![conf_010](https://img.shields.io/badge/010-██████████-red) ](SPEC.md#ZG-CONFORMANCE-010)| | [![conf_011](https://img.shields.io/badge/011-░░░░░░░░░░-inactive)](SPEC.md#ZG-CONFORMANCE-011)| | [![conf_012](https://img.shields.io/badge/012-██████████-red) ](SPEC.md#ZG-CONFORMANCE-012)| :warning: Zcashd node config requires investigation. | [![conf_013](https://img.shields.io/badge/013-██████████-red) ](SPEC.md#ZG-CONFORMANCE-013)| :warning: Need to confirm expected behaviour with zcash. @@ -80,5 +80,5 @@ Quick overview of the current status, providing implementation progress and test | [![resis_002](https://img.shields.io/badge/002-████████░░-red)](SPEC.md#ZG-RESISTANCE-002)| :warning: Need to confirm expected behaviour with zcash. Message specific fuzzing isn't implemented for all messages yet. | [![resis_003](https://img.shields.io/badge/003-░░░░░░░░░░-inactive)](SPEC.md#ZG-RESISTANCE-003)| | [![resis_004](https://img.shields.io/badge/004-░░░░░░░░░░-inactive)](SPEC.md#ZG-RESISTANCE-004)| -| [![resis_005](https://img.shields.io/badge/005-████████░░-red)](SPEC.md#ZG-RESISTANCE-005)| :warning: Need to confirm expected behaviour with zcash. Message specific fuzzing isn't implemented for all messages yet. +| [![resis_005](https://img.shields.io/badge/005-████████░░-red)](SPEC.md#ZG-RESISTANCE-005)| :warning: Need to confirm expected behaviour with zcash. Message specific fuzzing isn't implemented for all messages yet. | [![resis_006](https://img.shields.io/badge/006-░░░░░░░░░░-inactive)](SPEC.md#ZG-RESISTANCE-006)| diff --git a/src/tests/conformance/messages.rs b/src/tests/conformance/messages.rs index cf6a04a6..52e6870f 100644 --- a/src/tests/conformance/messages.rs +++ b/src/tests/conformance/messages.rs @@ -1,4 +1,5 @@ use crate::{ + assert_variant, helpers::{initiate_handshake, respond_to_handshake}, protocol::{ message::{Message, MessageFilter}, @@ -187,6 +188,95 @@ async fn ignores_unsolicited_responses() { node.stop().await; } +#[tokio::test] +async fn basic_query_response() { + // ZG-CONFORMANCE-010 + // + // The node responds with the correct messages. Message correctness is naively verified through successful encoding/decoding. + // + // `Ping` expects `Pong`. + // `GetAddr` expects `Addr`. + // `Mempool` expects `Inv`. + // `Getblocks` expects `Inv`. + // `GetData(tx_hash)` expects `Tx`. + // `GetData(block_hash)` expects `Blocks`. + // `GetHeaders` expects `Headers`. + // + // The test currently fails for zcashd; zebra tbd. + // + // Current behaviour: + // + // zcashd: Ignores the following messages + // - GetAddr + // - MemPool + // - GetBlocks + // - GetData(block) + // + // GetData(tx) returns NotFound (which is correct), + // because we currently can't seed a mempool. + // + // zebra: tbd + + let mut node: Node = Default::default(); + node.initial_action(Action::WaitForConnection(new_local_addr())) + .log_to_stdout(true) + .start() + .await; + + let mut stream = initiate_handshake(node.addr()).await.unwrap(); + let filter = MessageFilter::with_all_auto_reply(); + let genesis_block = Block::testnet_genesis(); + + Message::Ping(Nonce::default()) + .write_to_stream(&mut stream) + .await + .unwrap(); + let reply = filter.read_from_stream(&mut stream).await.unwrap(); + assert_variant!(reply, Message::Pong(..)); + + Message::GetAddr.write_to_stream(&mut stream).await.unwrap(); + let reply = filter.read_from_stream(&mut stream).await.unwrap(); + assert_variant!(reply, Message::Addr(..)); + + Message::MemPool.write_to_stream(&mut stream).await.unwrap(); + let reply = filter.read_from_stream(&mut stream).await.unwrap(); + assert_variant!(reply, Message::Inv(..)); + + Message::GetBlocks(LocatorHashes::new( + vec![genesis_block.double_sha256().unwrap()], + Hash::zeroed(), + )) + .write_to_stream(&mut stream) + .await + .unwrap(); + let reply = filter.read_from_stream(&mut stream).await.unwrap(); + assert_variant!(reply, Message::Inv(..)); + + Message::GetData(Inv::new(vec![genesis_block.txs[0].inv_hash()])) + .write_to_stream(&mut stream) + .await + .unwrap(); + let reply = filter.read_from_stream(&mut stream).await.unwrap(); + assert_variant!(reply, Message::Tx(..)); + + Message::GetData(Inv::new(vec![Block::testnet_2().inv_hash()])) + .write_to_stream(&mut stream) + .await + .unwrap(); + let reply = filter.read_from_stream(&mut stream).await.unwrap(); + assert_variant!(reply, Message::Block(..)); + + Message::GetHeaders(LocatorHashes::new( + vec![genesis_block.double_sha256().unwrap()], + Hash::zeroed(), + )) + .write_to_stream(&mut stream) + .await + .unwrap(); + let reply = filter.read_from_stream(&mut stream).await.unwrap(); + assert_variant!(reply, Message::Headers(..)); +} + #[tokio::test] async fn eagerly_crawls_network_for_peers() { // ZG-CONFORMANCE-012