@@ -149,19 +149,7 @@ fn kernel_check_command(args: &[String]) -> Result<()> {
149149
150150 match options. format {
151151 OutputFormat :: Json => {
152- let report = json ! ( {
153- "schema_version" : "kaspascript.cli.kernel.check.v0" ,
154- "contract" : package. kernel. readiness. contract,
155- "target" : package. package_target,
156- "artifact" : & package. artifact,
157- "readiness" : & package. kernel. readiness,
158- "capabilities" : & package. kernel. capabilities,
159- "fee_estimate" : & package. fee_estimate,
160- "next_commands" : [
161- format!( "kaspascript kernel preview {path} --target {}" , package. package_target) ,
162- format!( "kaspascript kernel package {path} --target {} --compute-grams {} --tx-bytes {}" , package. package_target, package. fee_estimate. compute_grams, package. fee_estimate. transaction_bytes)
163- ]
164- } ) ;
152+ let report = kernel_check_report ( path, & package) ;
165153 println ! ( "{}" , serde_json:: to_string_pretty( & report) ?) ;
166154 }
167155 OutputFormat :: Human => print_kernel_check_human ( path, & package) ,
@@ -195,12 +183,7 @@ fn kernel_preview_command(args: &[String]) -> Result<()> {
195183
196184 match options. format {
197185 OutputFormat :: Json => {
198- let report = json ! ( {
199- "schema_version" : "kaspascript.cli.kernel.preview.v0" ,
200- "contract" : package. kernel. readiness. contract,
201- "target" : package. package_target,
202- "previews" : previews,
203- } ) ;
186+ let report = kernel_preview_report ( & package, & previews) ;
204187 println ! ( "{}" , serde_json:: to_string_pretty( & report) ?) ;
205188 }
206189 OutputFormat :: Human => print_kernel_preview_human ( & package, & previews) ,
@@ -276,10 +259,7 @@ fn toccata_targets_command(args: &[String]) -> Result<()> {
276259 let targets = target_matrix ( ) ;
277260 match format {
278261 OutputFormat :: Json => {
279- let report = json ! ( {
280- "schema_version" : "kaspascript.cli.toccata.targets.v0" ,
281- "targets" : targets,
282- } ) ;
262+ let report = toccata_targets_report ( targets) ;
283263 println ! ( "{}" , serde_json:: to_string_pretty( & report) ?) ;
284264 }
285265 OutputFormat :: Human => print_target_matrix_human ( & targets) ,
@@ -299,11 +279,7 @@ fn toccata_fee_command(args: &[String]) -> Result<()> {
299279
300280 match options. format {
301281 OutputFormat :: Json => {
302- let report = json ! ( {
303- "schema_version" : "kaspascript.cli.toccata.fee.v0" ,
304- "fee_estimate" : estimate,
305- "formula" : "max(compute_grams, tx_bytes * 2) * 100 sompi" ,
306- } ) ;
282+ let report = toccata_fee_report ( & estimate) ;
307283 println ! ( "{}" , serde_json:: to_string_pretty( & report) ?) ;
308284 }
309285 OutputFormat :: Human => {
@@ -593,6 +569,49 @@ fn parse_u64_option(option: &str, value: &str) -> Result<u64> {
593569 . with_context ( || format ! ( "{option} must be a non-negative integer" ) )
594570}
595571
572+ fn kernel_check_report ( path : & str , package : & CompiledKernelPackage ) -> Value {
573+ json ! ( {
574+ "schema_version" : "kaspascript.cli.kernel.check.v0" ,
575+ "contract" : package. kernel. readiness. contract,
576+ "target" : package. package_target,
577+ "artifact" : & package. artifact,
578+ "readiness" : & package. kernel. readiness,
579+ "capabilities" : & package. kernel. capabilities,
580+ "fee_estimate" : & package. fee_estimate,
581+ "next_commands" : [
582+ format!( "kaspascript kernel preview {path} --target {}" , package. package_target) ,
583+ format!( "kaspascript kernel package {path} --target {} --compute-grams {} --tx-bytes {}" , package. package_target, package. fee_estimate. compute_grams, package. fee_estimate. transaction_bytes)
584+ ]
585+ } )
586+ }
587+
588+ fn kernel_preview_report (
589+ package : & CompiledKernelPackage ,
590+ previews : & [ & kaspascript_kernel:: WalletPreview ] ,
591+ ) -> Value {
592+ json ! ( {
593+ "schema_version" : "kaspascript.cli.kernel.preview.v0" ,
594+ "contract" : package. kernel. readiness. contract,
595+ "target" : package. package_target,
596+ "previews" : previews,
597+ } )
598+ }
599+
600+ fn toccata_targets_report ( targets : Vec < Value > ) -> Value {
601+ json ! ( {
602+ "schema_version" : "kaspascript.cli.toccata.targets.v0" ,
603+ "targets" : targets,
604+ } )
605+ }
606+
607+ fn toccata_fee_report ( estimate : & kaspascript_kernel:: FeeEstimate ) -> Value {
608+ json ! ( {
609+ "schema_version" : "kaspascript.cli.toccata.fee.v0" ,
610+ "fee_estimate" : estimate,
611+ "formula" : "max(compute_grams, tx_bytes * 2) * 100 sompi" ,
612+ } )
613+ }
614+
596615fn toccata_status_report ( ) -> Value {
597616 json ! ( {
598617 "schema_version" : "kaspascript.cli.toccata.status.v0" ,
@@ -1256,6 +1275,34 @@ mod tests {
12561275 ) ,
12571276 ] ;
12581277
1278+ const CLI_REPORT_SCHEMAS : & [ ( & str , & str , & str ) ] = & [
1279+ (
1280+ "kaspascript.cli.toccata.status.v0" ,
1281+ include_str ! ( "../../docs/schemas/kaspascript.cli.toccata.status.v0.schema.json" ) ,
1282+ include_str ! ( "../../tests/golden/cli/toccata.status.json" ) ,
1283+ ) ,
1284+ (
1285+ "kaspascript.cli.toccata.targets.v0" ,
1286+ include_str ! ( "../../docs/schemas/kaspascript.cli.toccata.targets.v0.schema.json" ) ,
1287+ include_str ! ( "../../tests/golden/cli/toccata.targets.json" ) ,
1288+ ) ,
1289+ (
1290+ "kaspascript.cli.toccata.fee.v0" ,
1291+ include_str ! ( "../../docs/schemas/kaspascript.cli.toccata.fee.v0.schema.json" ) ,
1292+ include_str ! ( "../../tests/golden/cli/toccata.fee.json" ) ,
1293+ ) ,
1294+ (
1295+ "kaspascript.cli.kernel.check.v0" ,
1296+ include_str ! ( "../../docs/schemas/kaspascript.cli.kernel.check.v0.schema.json" ) ,
1297+ include_str ! ( "../../tests/golden/cli/kernel.check.escrow.verified-tn12.json" ) ,
1298+ ) ,
1299+ (
1300+ "kaspascript.cli.kernel.preview.v0" ,
1301+ include_str ! ( "../../docs/schemas/kaspascript.cli.kernel.preview.v0.schema.json" ) ,
1302+ include_str ! ( "../../tests/golden/cli/kernel.preview.escrow.release.verified-tn12.json" ) ,
1303+ ) ,
1304+ ] ;
1305+
12591306 #[ test]
12601307 fn kernel_package_command_writes_combined_artifact ( ) {
12611308 let dir =
@@ -1443,6 +1490,73 @@ mod tests {
14431490 assert ! ( ToccataFeeOptions :: parse( & [ "--tx-bytes" . to_owned( ) , "400" . to_owned( ) ] ) . is_err( ) ) ;
14441491 }
14451492
1493+ #[ test]
1494+ fn cli_report_schema_files_are_valid_json ( ) {
1495+ for ( schema_version, schema, golden) in CLI_REPORT_SCHEMAS {
1496+ let schema_json: Value = serde_json:: from_str ( schema) . expect ( "schema json" ) ;
1497+ let golden_json: Value = serde_json:: from_str ( golden) . expect ( "golden json" ) ;
1498+
1499+ assert_eq ! (
1500+ schema_json[ "properties" ] [ "schema_version" ] [ "const" ] ,
1501+ Value :: String ( ( * schema_version) . to_owned( ) ) ,
1502+ "{schema_version}"
1503+ ) ;
1504+ assert_eq ! (
1505+ golden_json[ "schema_version" ] ,
1506+ Value :: String ( ( * schema_version) . to_owned( ) ) ,
1507+ "{schema_version}"
1508+ ) ;
1509+ assert_eq ! (
1510+ schema_json[ "$schema" ] ,
1511+ Value :: String ( "https://json-schema.org/draft/2020-12/schema" . to_owned( ) ) ,
1512+ "{schema_version}"
1513+ ) ;
1514+ }
1515+ }
1516+
1517+ #[ test]
1518+ fn cli_report_golden_snapshots_match ( ) {
1519+ assert_report_snapshot (
1520+ "toccata.status" ,
1521+ toccata_status_report ( ) ,
1522+ include_str ! ( "../../tests/golden/cli/toccata.status.json" ) ,
1523+ ) ;
1524+
1525+ assert_report_snapshot (
1526+ "toccata.targets" ,
1527+ toccata_targets_report ( target_matrix ( ) ) ,
1528+ include_str ! ( "../../tests/golden/cli/toccata.targets.json" ) ,
1529+ ) ;
1530+
1531+ let fee = ToccataFeePolicy :: default ( )
1532+ . estimate ( 1000 , 400 , "caller-provided Toccata fee estimate inputs" )
1533+ . expect ( "fee estimate" ) ;
1534+ assert_report_snapshot (
1535+ "toccata.fee" ,
1536+ toccata_fee_report ( & fee) ,
1537+ include_str ! ( "../../tests/golden/cli/toccata.fee.json" ) ,
1538+ ) ;
1539+
1540+ let package = escrow_kernel_package ( ) ;
1541+ assert_report_snapshot (
1542+ "kernel.check.escrow.verified-tn12" ,
1543+ kernel_check_report ( "tests/contracts/escrow.ks" , & package) ,
1544+ include_str ! ( "../../tests/golden/cli/kernel.check.escrow.verified-tn12.json" ) ,
1545+ ) ;
1546+
1547+ let previews = package
1548+ . kernel
1549+ . wallet_previews
1550+ . iter ( )
1551+ . filter ( |preview| preview. transition == "release" )
1552+ . collect :: < Vec < _ > > ( ) ;
1553+ assert_report_snapshot (
1554+ "kernel.preview.escrow.release.verified-tn12" ,
1555+ kernel_preview_report ( & package, & previews) ,
1556+ include_str ! ( "../../tests/golden/cli/kernel.preview.escrow.release.verified-tn12.json" ) ,
1557+ ) ;
1558+ }
1559+
14461560 #[ test]
14471561 fn kernel_package_golden_snapshots_match ( ) {
14481562 for ( source_path, source, golden) in KERNEL_GOLDENS {
@@ -1496,4 +1610,24 @@ mod tests {
14961610 ) ;
14971611 assert ! ( !blocked_package. kernel. readiness. ready) ;
14981612 }
1613+
1614+ fn escrow_kernel_package ( ) -> CompiledKernelPackage {
1615+ let options = KernelPackageOptions {
1616+ output : None ,
1617+ compute_grams : 1000 ,
1618+ tx_bytes : Some ( 400 ) ,
1619+ target : Target :: VerifiedTn12 ,
1620+ } ;
1621+ build_kernel_package (
1622+ "tests/contracts/escrow.ks" ,
1623+ include_str ! ( "../../tests/contracts/escrow.ks" ) ,
1624+ & options,
1625+ )
1626+ . expect ( "escrow package" )
1627+ }
1628+
1629+ fn assert_report_snapshot ( name : & str , actual : Value , golden : & str ) {
1630+ let expected: Value = serde_json:: from_str ( golden) . expect ( "golden json" ) ;
1631+ assert_eq ! ( actual, expected, "{name}" ) ;
1632+ }
14991633}
0 commit comments