#[serde_test]Expand description
This macro is used to generate round-trip serialization tests.
By appending serde_test to a struct or enum definition, you automatically derive
serialization tests that employ Serde for round-trip testing. The procedure in the generated
tests is:
- Instantiate the type being tested
- Serialize the instance, ensuring the operation’s success
- Deserialize the serialized data, comparing the resulting instance with the original one
The type being tested must meet the following requirements:
- Implementations of
DebugandPartialEqtraits - Implementation of
Arbitrarytrait - Implementations of
SerializeandDeserializeOwnedtraits
When using the binary_serde annotation, the type must also implement the
Serializable and Deserializable traits from miden-crypto (which provide
to_bytes() and read_from_bytes() methods).
§Configuration Attributes
The macro supports configuration attributes to control test generation:
| Attribute | Type | Default | Purpose | Features Required |
|---|---|---|---|---|
serde_test | bool | true | Generate standard Serde (JSON) round-trip tests | arbitrary, serde, test |
binary_serde | bool | false | Generate binary serialization round-trip tests | arbitrary, test |
types(...) | - | none | Specify type parameters for generics | - |
§Usage Examples
Default (Serde tests only):
#[serde_test]
#[derive(Debug, PartialEq, Arbitrary, Serialize, Deserialize)]
struct Simple {
value: u64,
}Binary serialization tests only:
#[serde_test(binary_serde(true), serde_test(false))]
#[derive(Debug, PartialEq, Arbitrary)]
struct BinaryTest {
data: [u8; 32],
}Both test types:
#[serde_test(binary_serde(true))]
#[derive(Debug, PartialEq, Arbitrary, Serialize, Deserialize)]
struct DualTest {
name: u32,
value: u64,
}Generic types:
#[serde_test(types(u64, "Vec<u64>"), types(u32, bool))]
#[derive(Debug, PartialEq, Arbitrary, Serialize, Deserialize)]
struct Generic<T1, T2> {
t1: T1,
t2: T2,
}§Generated Test Names
- Serde tests:
test_serde_roundtrip_{struct_name}_{index} - Binary tests:
test_binary_serde_roundtrip_{struct_name}_{index}