fix tests

This commit is contained in:
John Smith
2023-06-16 14:18:34 -04:00
parent f3a3d5322c
commit 9ffcc0da87
13 changed files with 73 additions and 51 deletions

View File

@@ -212,10 +212,6 @@ pub fn fix_veilidvaluechange() -> VeilidValueChange {
key: fix_typedkey(),
subkeys: vec![1, 2, 3, 4],
count: 5,
value: ValueData {
seq: 23,
data: b"ValueData".to_vec(),
writer: fix_cryptokey(),
},
value: ValueData::new_with_seq(23, b"ValueData".to_vec(), fix_cryptokey()),
}
}

View File

@@ -13,21 +13,18 @@ pub async fn test_alignedu64() {
// app_messsage_call
pub async fn test_veilidappmessage() {
let orig = VeilidAppMessage {
sender: Some(fix_typedkey()),
message: b"Hi there!".to_vec(),
};
let orig = VeilidAppMessage::new(Some(fix_typedkey()), b"Hi there!".to_vec());
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
pub async fn test_veilidappcall() {
let orig = VeilidAppCall {
sender: Some(fix_typedkey()),
message: b"Well, hello!".to_vec(),
call_id: AlignedU64::from(123),
};
let orig = VeilidAppCall::new(
Some(fix_typedkey()),
b"Well, hello!".to_vec(),
AlignedU64::from(123),
);
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);

View File

@@ -5,12 +5,12 @@ use range_set_blaze::*;
// dht_record_descriptors
pub async fn test_dhtrecorddescriptor() {
let orig = DHTRecordDescriptor {
key: fix_typedkey(),
owner: fix_cryptokey(),
owner_secret: Some(fix_cryptokey()),
schema: DHTSchema::DFLT(DHTSchemaDFLT { o_cnt: 4321 }),
};
let orig = DHTRecordDescriptor::new(
fix_typedkey(),
fix_cryptokey(),
Some(fix_cryptokey()),
DHTSchema::DFLT(DHTSchemaDFLT { o_cnt: 4321 }),
);
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
@@ -19,11 +19,7 @@ pub async fn test_dhtrecorddescriptor() {
// value_data
pub async fn test_valuedata() {
let orig = ValueData {
seq: 42,
data: b"Brent Spiner".to_vec(),
writer: fix_cryptokey(),
};
let orig = ValueData::new_with_seq(42, b"Brent Spiner".to_vec(), fix_cryptokey());
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
@@ -32,9 +28,7 @@ pub async fn test_valuedata() {
// value_subkey_range_set
pub async fn test_valuesubkeyrangeset() {
let orig = ValueSubkeyRangeSet {
data: RangeSetBlaze::from_iter([20..=30]),
};
let orig = ValueSubkeyRangeSet::new_with_data(RangeSetBlaze::from_iter([20..=30]));
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);

View File

@@ -57,17 +57,17 @@ pub struct VeilidAppCall {
/// Some(sender) if the request was sent directly, None if received via a private/safety route
#[serde(with = "opt_json_as_string")]
#[schemars(with = "Option<String>")]
pub sender: Option<TypedKey>,
sender: Option<TypedKey>,
/// The content of the request to deliver to the application
#[serde(with = "json_as_base64")]
#[schemars(with = "String")]
pub message: Vec<u8>,
message: Vec<u8>,
/// The id to reply to
#[serde(with = "json_as_string")]
#[schemars(with = "String")]
pub call_id: OperationId,
call_id: OperationId,
}
impl VeilidAppCall {

View File

@@ -19,16 +19,16 @@ use super::*;
pub struct DHTRecordDescriptor {
/// DHT Key = Hash(ownerKeyKind) of: [ ownerKeyValue, schema ]
#[schemars(with = "String")]
pub key: TypedKey,
key: TypedKey,
/// The public key of the owner
#[schemars(with = "String")]
pub owner: PublicKey,
owner: PublicKey,
/// If this key is being created: Some(the secret key of the owner)
/// If this key is just being opened: None
#[schemars(with = "Option<String>")]
pub owner_secret: Option<SecretKey>,
owner_secret: Option<SecretKey>,
/// The schema in use associated with the key
pub schema: DHTSchema,
schema: DHTSchema,
}
impl DHTRecordDescriptor {

View File

@@ -18,16 +18,16 @@ use super::*;
#[archive_attr(repr(C), derive(CheckBytes))]
pub struct ValueData {
/// An increasing sequence number to time-order the DHT record changes
pub seq: ValueSeqNum,
seq: ValueSeqNum,
/// The contents of a DHT Record
#[serde(with = "json_as_base64")]
#[schemars(with = "String")]
pub data: Vec<u8>,
data: Vec<u8>,
/// The public identity key of the writer of the data
#[schemars(with = "String")]
pub writer: PublicKey,
writer: PublicKey,
}
impl ValueData {
pub const MAX_LEN: usize = 32768;

View File

@@ -23,7 +23,7 @@ pub struct ValueSubkeyRangeSet {
#[with(RkyvRangeSetBlaze)]
#[serde(with = "serialize_range_set_blaze")]
#[schemars(with = "Vec<(u32,u32)>")]
pub data: RangeSetBlaze<ValueSubkey>,
data: RangeSetBlaze<ValueSubkey>,
}
impl ValueSubkeyRangeSet {
@@ -32,6 +32,9 @@ impl ValueSubkeyRangeSet {
data: Default::default(),
}
}
pub fn new_with_data(data: RangeSetBlaze<ValueSubkey>) -> Self {
Self { data }
}
pub fn single(value: ValueSubkey) -> Self {
let mut data = RangeSetBlaze::new();
data.insert(value);