Skip to content

Commit

Permalink
integration test with bigger Proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
zarkone committed Jul 18, 2024
1 parent 5ab22bb commit 39b4013
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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![];
Expand All @@ -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::<u8>::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];
Expand Down
Binary file added tests/support/buffer-overflow-proposal.bin
Binary file not shown.

0 comments on commit 39b4013

Please sign in to comment.