From c910e0054e9146d0e32c730f0b53ba182270b8cd Mon Sep 17 00:00:00 2001 From: rvcas Date: Tue, 7 Nov 2023 16:02:20 -0500 Subject: [PATCH] test(bls): constant parsing tests --- .../src/parser/definition/constant.rs | 25 +++++ .../snapshots/g1_element_constant.snap | 54 +++++++++++ .../snapshots/g2_element_constant.snap | 96 +++++++++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 crates/aiken-lang/src/parser/definition/snapshots/g1_element_constant.snap create mode 100644 crates/aiken-lang/src/parser/definition/snapshots/g2_element_constant.snap diff --git a/crates/aiken-lang/src/parser/definition/constant.rs b/crates/aiken-lang/src/parser/definition/constant.rs index f7c28acb..469f1abc 100644 --- a/crates/aiken-lang/src/parser/definition/constant.rs +++ b/crates/aiken-lang/src/parser/definition/constant.rs @@ -84,3 +84,28 @@ pub fn value() -> impl Parser { constant_bytearray_parser, )) } + +#[cfg(test)] +mod tests { + use crate::assert_definition; + + #[test] + fn g1_element_constant() { + assert_definition!( + r#" + pub const point = + #"950dfd33da2682260c76038dfb8bad6e84ae9d599a3c151815945ac1e6ef6b1027cd917f3907479d20d636ce437a41f5" + "# + ); + } + + #[test] + fn g2_element_constant() { + assert_definition!( + r#" + pub const point = + #"b0629fa1158c2d23a10413fe91d381a84d25e31d041cd0377d25828498fd02011b35893938ced97535395e4815201e67108bcd4665e0db25d602d76fa791fab706c54abf5e1a9e44b4ac1e6badf3d2ac0328f5e30be341677c8bac5dda7682f1" + "# + ); + } +} diff --git a/crates/aiken-lang/src/parser/definition/snapshots/g1_element_constant.snap b/crates/aiken-lang/src/parser/definition/snapshots/g1_element_constant.snap new file mode 100644 index 00000000..4a009447 --- /dev/null +++ b/crates/aiken-lang/src/parser/definition/snapshots/g1_element_constant.snap @@ -0,0 +1,54 @@ +--- +source: crates/aiken-lang/src/parser/definition/constant.rs +description: "Code:\n\npub const point =\n #\"950dfd33da2682260c76038dfb8bad6e84ae9d599a3c151815945ac1e6ef6b1027cd917f3907479d20d636ce437a41f5\"\n" +--- +ModuleConstant( + ModuleConstant { + doc: None, + location: 0..134, + public: true, + name: "point", + annotation: None, + value: CurvePoint { + location: 20..134, + point: Bls12_381( + G1( + blst_p1 { + x: blst_fp { + l: [ + 6044239372598254900, + 11111890802926526657, + 302563157772145122, + 17359147598889707489, + 6255098506247414666, + 1773881592225990778, + ], + }, + y: blst_fp { + l: [ + 9961536754182800925, + 16512912018612749997, + 10822258563185590636, + 17742512098199848220, + 16542676355910829810, + 1246663995533626329, + ], + }, + z: blst_fp { + l: [ + 8505329371266088957, + 17002214543764226050, + 6865905132761471162, + 8632934651105793861, + 6631298214892334189, + 1582556514881692819, + ], + }, + }, + ), + ), + preferred_format: HexadecimalString, + }, + tipo: (), + }, +) diff --git a/crates/aiken-lang/src/parser/definition/snapshots/g2_element_constant.snap b/crates/aiken-lang/src/parser/definition/snapshots/g2_element_constant.snap new file mode 100644 index 00000000..060b55a0 --- /dev/null +++ b/crates/aiken-lang/src/parser/definition/snapshots/g2_element_constant.snap @@ -0,0 +1,96 @@ +--- +source: crates/aiken-lang/src/parser/definition/constant.rs +description: "Code:\n\npub const point =\n #\"b0629fa1158c2d23a10413fe91d381a84d25e31d041cd0377d25828498fd02011b35893938ced97535395e4815201e67108bcd4665e0db25d602d76fa791fab706c54abf5e1a9e44b4ac1e6badf3d2ac0328f5e30be341677c8bac5dda7682f1\"\n" +--- +ModuleConstant( + ModuleConstant { + doc: None, + location: 0..230, + public: true, + name: "point", + annotation: None, + value: CurvePoint { + location: 20..230, + point: Bls12_381( + G2( + blst_p2 { + x: blst_fp2 { + fp: [ + blst_fp { + l: [ + 17730081354175209597, + 14393386882433024580, + 15392237588654399813, + 13132804324748058634, + 437180824693959563, + 1209861931331675905, + ], + }, + blst_fp { + l: [ + 16640134302799489459, + 13200372101402265278, + 3491868243815184488, + 15749231165976205625, + 10700844509881097270, + 978652262052845623, + ], + }, + ], + }, + y: blst_fp2 { + fp: [ + blst_fp { + l: [ + 15138882304466955413, + 4159460337006967255, + 16059739792181277381, + 4673287545394659101, + 6265740687822174786, + 1492317236631555918, + ], + }, + blst_fp { + l: [ + 7482650483077279660, + 1528034342759119680, + 1732030343867801117, + 8394128533480400141, + 6497663211870147931, + 683724859415636652, + ], + }, + ], + }, + z: blst_fp2 { + fp: [ + blst_fp { + l: [ + 8505329371266088957, + 17002214543764226050, + 6865905132761471162, + 8632934651105793861, + 6631298214892334189, + 1582556514881692819, + ], + }, + blst_fp { + l: [ + 0, + 0, + 0, + 0, + 0, + 0, + ], + }, + ], + }, + }, + ), + ), + preferred_format: HexadecimalString, + }, + tipo: (), + }, +)