-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use transparent attribute for deriving SchemaType (#297)
* Add more test cases for smart contract related macros * Derive schema type when possible in concordium-cis2 * Bumb common * Address review comments * Use new transparent attribute when deriving schema type * Add derive schematype test with size_length field attribute
- Loading branch information
Showing
3 changed files
with
69 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
concordium-std/tests/derive-schema-type/success-transparent.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/// Test ensuring derivation works for newtype wrappers with transparent | ||
use concordium_std::*; | ||
|
||
/// Simple struct | ||
#[derive(SchemaType)] | ||
#[concordium(transparent)] | ||
struct MyStruct { | ||
field: u32, | ||
} | ||
|
||
/// Nested struct | ||
#[derive(SchemaType)] | ||
#[concordium(transparent)] | ||
struct MyOtherStruct { | ||
field: MyStruct, | ||
} | ||
|
||
/// With field attributes | ||
#[derive(SchemaType)] | ||
#[concordium(transparent)] | ||
struct MyCollection { | ||
#[concordium(size_length = 1)] | ||
field: Vec<u32>, | ||
} | ||
|
||
fn main() { | ||
{ | ||
let schema_type = <MyStruct as schema::SchemaType>::get_type(); | ||
assert_eq!(schema_type, schema::Type::U32); | ||
} | ||
|
||
{ | ||
let schema_type = <MyOtherStruct as schema::SchemaType>::get_type(); | ||
assert_eq!(schema_type, schema::Type::U32); | ||
} | ||
|
||
{ | ||
let schema_type = <MyCollection as schema::SchemaType>::get_type(); | ||
assert_eq!( | ||
schema_type, | ||
schema::Type::List(schema::SizeLength::U8, Box::new(schema::Type::U32)) | ||
); | ||
} | ||
} |