From 39b4013bf6feb3dc71eadc9400bbae3903440f8a Mon Sep 17 00:00:00 2001 From: Anatolii Smolianinov Date: Thu, 18 Jul 2024 10:46:22 +0200 Subject: [PATCH] integration test with bigger Proposal --- tests/integration.rs | 24 +++++++++++++++++++++ tests/support/buffer-overflow-proposal.bin | Bin 0 -> 1894 bytes 2 files changed, 24 insertions(+) create mode 100644 tests/support/buffer-overflow-proposal.bin diff --git a/tests/integration.rs b/tests/integration.rs index 5d24a4d4..eda8b7f7 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -5,6 +5,7 @@ use chrono::{DateTime, Utc}; use prost::Message; use rand::Rng; use signature::Verifier; +use std::fs::File; use std::{ fs, io::{self, Cursor, Read, Write}, @@ -617,6 +618,20 @@ fn test_handle_and_sign_ping_pong() { }); } +#[test] +fn test_buffer_underflow_sign_proposal() { + let key_type = KeyType::Consensus; + ProtocolTester::apply(&key_type, |mut pt| { + send_buffer_underflow_request(&mut pt); + let response: Result<(), ()> = match read_response(&mut pt) { + proto::privval::message::Sum::SignedProposalResponse(_) => Ok(()), + other => panic!("unexpected message type in response: {other:?}"), + }; + + assert!(response.is_ok()); + }); +} + /// Encode request as a Protobuf message fn send_request(request: proto::privval::message::Sum, pt: &mut ProtocolTester) { let mut buf = vec![]; @@ -627,6 +642,15 @@ fn send_request(request: proto::privval::message::Sum, pt: &mut ProtocolTester) pt.write_all(&buf).unwrap(); } +/// Opens a binary file with big proposal (> 1024 bytes, from Sei network) +/// and sends via protocol tester +fn send_buffer_underflow_request(pt: &mut ProtocolTester) { + let mut file = File::open("tests/support/buffer-underflow-proposal.bin").unwrap(); + let mut buf = Vec::::new(); + file.read_to_end(&mut buf).unwrap(); + pt.write_all(&buf).unwrap(); +} + /// Read the response as a Protobuf message fn read_response(pt: &mut ProtocolTester) -> proto::privval::message::Sum { let mut resp_buf = vec![0u8; 4096]; diff --git a/tests/support/buffer-overflow-proposal.bin b/tests/support/buffer-overflow-proposal.bin new file mode 100644 index 0000000000000000000000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