Refactor frontend/middleware types (#194)
* unify fe/be NativeOp and NativePred * remove Origin in favour of PodId * Combine string and hash in Key * use middleware::AnchoredKey in frontend * merge frontend/middleware types * refactor custom predicates * clean up a bit * fix middleware custom tests * clean up * clean up 2 * add acronyms in typos list
This commit is contained in:
parent
9e860ef262
commit
c232c8dae5
33 changed files with 1985 additions and 2800 deletions
|
|
@ -1,3 +1,4 @@
|
|||
/*
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
|
||||
use schemars::{JsonSchema, Schema};
|
||||
|
|
@ -5,14 +6,14 @@ use serde::{Deserialize, Serialize, Serializer};
|
|||
|
||||
use crate::{
|
||||
backends::plonky2::mock::{mainpod::MockMainPod, signedpod::MockSignedPod},
|
||||
frontend::{containers::Dictionary, MainPod, SignedPod, Statement, Value},
|
||||
frontend::{containers::Dictionary, MainPod, SignedPod, Statement, TypedValue},
|
||||
middleware::PodId,
|
||||
};
|
||||
|
||||
#[derive(Serialize, Deserialize, JsonSchema)]
|
||||
#[schemars(title = "SignedPod")]
|
||||
pub struct SignedPodHelper {
|
||||
entries: HashMap<String, Value>,
|
||||
entries: HashMap<String, TypedValue>,
|
||||
proof: String,
|
||||
pod_class: String,
|
||||
pod_type: String,
|
||||
|
|
@ -169,30 +170,34 @@ mod tests {
|
|||
fn test_value_serialization() {
|
||||
// Pairs of values and their expected serialized representations
|
||||
let values = vec![
|
||||
(Value::String("hello".to_string()), "\"hello\""),
|
||||
(Value::Int(42), "{\"Int\":\"42\"}"),
|
||||
(Value::Bool(true), "true"),
|
||||
(TypedValue::String("hello".to_string()), "\"hello\""),
|
||||
(TypedValue::Int(42), "{\"Int\":\"42\"}"),
|
||||
(TypedValue::Bool(true), "true"),
|
||||
(
|
||||
Value::Array(
|
||||
Array::new(vec![Value::String("foo".to_string()), Value::Bool(false)]).unwrap(),
|
||||
TypedValue::Array(
|
||||
Array::new(vec![
|
||||
TypedValue::String("foo".to_string()),
|
||||
TypedValue::Bool(false),
|
||||
])
|
||||
.unwrap(),
|
||||
),
|
||||
"[\"foo\",false]",
|
||||
),
|
||||
(
|
||||
Value::Dictionary(
|
||||
TypedValue::Dictionary(
|
||||
Dictionary::new(HashMap::from([
|
||||
("foo".to_string(), Value::Int(123)),
|
||||
("bar".to_string(), Value::String("baz".to_string())),
|
||||
("foo".to_string(), TypedValue::Int(123)),
|
||||
("bar".to_string(), TypedValue::String("baz".to_string())),
|
||||
]))
|
||||
.unwrap(),
|
||||
),
|
||||
"{\"Dictionary\":{\"bar\":\"baz\",\"foo\":{\"Int\":\"123\"}}}",
|
||||
),
|
||||
(
|
||||
Value::Set(
|
||||
TypedValue::Set(
|
||||
Set::new(vec![
|
||||
Value::String("foo".to_string()),
|
||||
Value::String("bar".to_string()),
|
||||
TypedValue::String("foo".to_string()),
|
||||
TypedValue::String("bar".to_string()),
|
||||
])
|
||||
.unwrap(),
|
||||
),
|
||||
|
|
@ -203,9 +208,9 @@ mod tests {
|
|||
for (value, expected) in values {
|
||||
let serialized = serde_json::to_string(&value).unwrap();
|
||||
assert_eq!(serialized, expected);
|
||||
let deserialized: Value = serde_json::from_str(&serialized).unwrap();
|
||||
let deserialized: TypedValue = serde_json::from_str(&serialized).unwrap();
|
||||
assert_eq!(value, deserialized);
|
||||
let expected_deserialized: Value = serde_json::from_str(&expected).unwrap();
|
||||
let expected_deserialized: TypedValue = serde_json::from_str(&expected).unwrap();
|
||||
assert_eq!(value, expected_deserialized);
|
||||
}
|
||||
}
|
||||
|
|
@ -219,27 +224,32 @@ mod tests {
|
|||
builder.insert("very_large_int", 1152921504606846976);
|
||||
builder.insert(
|
||||
"a_dict_containing_one_key",
|
||||
Value::Dictionary(
|
||||
TypedValue::Dictionary(
|
||||
Dictionary::new(HashMap::from([
|
||||
("foo".to_string(), Value::Int(123)),
|
||||
("foo".to_string(), TypedValue::Int(123)),
|
||||
(
|
||||
"an_array_containing_three_ints".to_string(),
|
||||
Value::Array(
|
||||
Array::new(vec![Value::Int(1), Value::Int(2), Value::Int(3)]).unwrap(),
|
||||
TypedValue::Array(
|
||||
Array::new(vec![
|
||||
TypedValue::Int(1),
|
||||
TypedValue::Int(2),
|
||||
TypedValue::Int(3),
|
||||
])
|
||||
.unwrap(),
|
||||
),
|
||||
),
|
||||
(
|
||||
"a_set_containing_two_strings".to_string(),
|
||||
Value::Set(
|
||||
TypedValue::Set(
|
||||
Set::new(vec![
|
||||
Value::Array(
|
||||
TypedValue::Array(
|
||||
Array::new(vec![
|
||||
Value::String("foo".to_string()),
|
||||
Value::String("bar".to_string()),
|
||||
TypedValue::String("foo".to_string()),
|
||||
TypedValue::String("bar".to_string()),
|
||||
])
|
||||
.unwrap(),
|
||||
),
|
||||
Value::String("baz".to_string()),
|
||||
TypedValue::String("baz".to_string()),
|
||||
])
|
||||
.unwrap(),
|
||||
),
|
||||
|
|
@ -256,7 +266,6 @@ mod tests {
|
|||
let deserialized: SignedPod = serde_json::from_str(&serialized).unwrap();
|
||||
|
||||
assert_eq!(pod.kvs, deserialized.kvs);
|
||||
assert_eq!(pod.origin(), deserialized.origin());
|
||||
assert_eq!(pod.verify().is_ok(), deserialized.verify().is_ok());
|
||||
assert_eq!(pod.id(), deserialized.id())
|
||||
}
|
||||
|
|
@ -265,7 +274,7 @@ mod tests {
|
|||
fn test_main_pod_serialization() -> Result<()> {
|
||||
let params = middleware::Params::default();
|
||||
let sanctions_values = vec!["A343434340".into()];
|
||||
let sanction_set = Value::Set(Set::new(sanctions_values)?);
|
||||
let sanction_set = TypedValue::Set(Set::new(sanctions_values)?);
|
||||
|
||||
let (gov_id_builder, pay_stub_builder, sanction_list_builder) =
|
||||
zu_kyc_sign_pod_builders(¶ms, &sanction_set);
|
||||
|
|
@ -311,3 +320,4 @@ mod tests {
|
|||
);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue