1- import { ensureBigInt } from "@fleet-sdk/common" ;
2- import { hex , randomBytes } from "@fleet-sdk/crypto" ;
1+ import { type Box , ensureBigInt } from "@fleet-sdk/common" ;
2+ import { hex } from "@fleet-sdk/crypto" ;
33import { describe , expect , it , test } from "vitest" ;
44import {
55 bigintVectors ,
@@ -9,14 +9,15 @@ import {
99 groupElementVectors ,
1010 intVectors ,
1111 longVectors ,
12+ sBoxVectors ,
1213 shortVectors ,
1314 sigmaPropVectors ,
1415 tupleTestVectors
1516} from "./_test-vectors/constantVectors" ;
1617import { SigmaByteWriter } from "./coders" ;
1718import { dataSerializer } from "./serializers" ;
1819import { decode , parse , SConstant , stypeof } from "./sigmaConstant" ;
19- import type { SGroupElementType } from "./types" ;
20+ import type { SGroupElementType , SPrimitiveType } from "./types" ;
2021import {
2122 SBigInt ,
2223 SBool ,
@@ -30,7 +31,7 @@ import {
3031 STupleType ,
3132 SUnit
3233} from "./types/" ;
33- import { STuple } from "./types/constructors" ;
34+ import { SBox , STuple } from "./types/constructors" ;
3435import { Value$ } from "sigmastate-js/main" ;
3536import fc from "fast-check" ;
3637import {
@@ -45,6 +46,7 @@ import {
4546 MIN_I64 ,
4647 MIN_I8
4748} from "./coders/numRanges" ;
49+ import { SPair } from "../dist" ;
4850
4951describe ( "Primitive types serialization and parsing" , ( ) => {
5052 it . each ( boolVectors ) ( "Should road-trip SBool($value)" , ( tv ) => {
@@ -277,6 +279,25 @@ describe("Not implemented types", () => {
277279 } ) ;
278280} ) ;
279281
282+ describe ( "SBox serialization" , ( ) => {
283+ test . each ( sBoxVectors ) ( "SBox serialization bytes" , ( tv ) => {
284+ const sconst = SBox ( tv . value ) ;
285+ expect ( sconst . toHex ( ) ) . to . be . equal ( tv . hex ) ;
286+ expect ( sconst . type . toString ( ) ) . to . be . equal ( "SBox" ) ;
287+ } ) ;
288+
289+ test . each ( sBoxVectors ) ( "SBox roundtrip" , ( tv ) => {
290+ expect ( SBox ( SConstant . from < Box > ( tv . hex ) . data ) . toHex ( ) ) . to . be . equal ( tv . hex ) ;
291+ } ) ;
292+
293+ it ( "Should not embed SBox" , ( ) => {
294+ // @ts -expect-error SBox is not compatible with SColl
295+ expect ( ( ) => SColl ( SBox , [ sBoxVectors [ 0 ] . value ] ) ) . toThrow ( ) ;
296+ // @ts -expect-error SBox is not compatible with SPair
297+ expect ( ( ) => SPair ( SBox ( sBoxVectors [ 0 ] . value ) , SBox ( sBoxVectors [ 1 ] ) ) ) . toThrow ( ) ;
298+ } ) ;
299+ } ) ;
300+
280301describe ( "Tuple serialization" , ( ) => {
281302 it . each ( tupleTestVectors ) ( "Should road-trip $name" , ( tv ) => {
282303 expect ( tv . sconst . toHex ( ) ) . to . be . equal ( tv . hex ) ;
0 commit comments