Skip to content

Commit

Permalink
Add test for the proto capability
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed Sep 7, 2024
1 parent 084d353 commit c933b46
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
3 changes: 3 additions & 0 deletions nekoton-proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ ton_block = { git = "https://github.com/broxus/ton-labs-block.git" }
ton_types = { git = "https://github.com/broxus/ton-labs-types" }

nekoton-abi = { path = "../nekoton-abi"}

[dev-dependencies]
base64 = "0.13"
49 changes: 49 additions & 0 deletions nekoton-proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,52 @@ pub mod protos;
pub mod utils;

pub use prost;

#[cfg(test)]
mod tests {
use prost::Message;

use super::protos;

#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct OldGetBlockchainConfig {
#[prost(int32, tag = "1")]
pub global_id: i32,
#[prost(bytes = "bytes", tag = "2")]
pub config: ::prost::bytes::Bytes,
}

#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct NewqGetBlockchainConfig {
#[prost(int32, tag = "1")]
pub global_id: i32,
#[prost(bytes = "bytes", tag = "2")]
pub config: ::prost::bytes::Bytes,
#[prost(uint32, tag = "3")]
pub seqno: u32,
}

#[test]
fn test() {
let old = OldGetBlockchainConfig {
global_id: 1,
config: vec![1, 2, 3].into(),
};

let old_data = old.encode_to_vec();
let new = NewqGetBlockchainConfig::decode(old_data.as_slice()).unwrap();

assert_eq!(old.global_id, new.global_id);
assert_eq!(old.config, new.config);
assert_eq!(new.seqno, 0);
}

#[test]
fn decode_error() {
let data = base64::decode("CKeB/v///////wESGE1ldGhvZCBgb3RoZXJgIG5vdCBmb3VuZA==").unwrap();
let res = protos::rpc::Error::decode(data.as_slice()).unwrap();
println!("{res:?}");
}
}
6 changes: 3 additions & 3 deletions nekoton-proto/src/protos/rpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ message Response {
}

message GetBlockchainConfig {
int32 global_id = 1;
bytes config = 2;
uint32 seqno = 3;
int32 global_id = 1;
bytes config = 2;
uint32 seqno = 3;
}

message GetAccountsByCodeHash {
Expand Down

0 comments on commit c933b46

Please sign in to comment.