@@ -15,6 +15,7 @@ import (
1515 "os"
1616 "path/filepath"
1717 "regexp"
18+ "sort"
1819 "strconv"
1920 "strings"
2021 "sync"
@@ -31,7 +32,8 @@ import (
3132
3233const (
3334 // DefaultTestRoot is the default path to test data for token transfer verification
34- DefaultTestRoot = "../../token/core/zkatdlog/nogh/v1/validator/regression/testdata/32-BLS12_381_BBS_GURVY/transfers_i2_o2"
35+ DefaultTestRoot = "../../token/core/zkatdlog/nogh/v1/regression/testdata/zero/32-BLS12_381_BBS_GURVY"
36+ defaultCasePrefix = "transfers_i2_o2_"
3537)
3638
3739var (
@@ -102,55 +104,51 @@ func NewTokenValidationParamsSlice(TestRootPath string) ([]*transferServiceParam
102104 if TestRootPath == "" {
103105 return nil , errors .New ("TestRootPath cannot be empty" )
104106 }
105- paramsTxt := filepath .Join (filepath .Dir (TestRootPath ), "params.txt" )
106107
107- paramsRaw , err := os .ReadFile (paramsTxt )
108+ testdataPath := filepath .Join (TestRootPath , "testdata.json" )
109+ testdataRaw , err := os .ReadFile (testdataPath )
108110 if err != nil {
109- return nil , fmt .Errorf ("failed to read params file %s: %w" , paramsTxt , err )
111+ return nil , fmt .Errorf ("failed to read testdata file %s: %w" , testdataPath , err )
110112 }
111113
112- ppRaw , err := base64 . StdEncoding . DecodeString ( strings . TrimSpace ( string ( paramsRaw )))
113- if err != nil {
114- return nil , fmt . Errorf ( "failed to base64-decode params.txt: %w" , err )
114+ var allCases map [ string ] struct {
115+ ReqRaw string `json:"req_raw"`
116+ TXID string `json:"txid"`
115117 }
116-
117- outPaths , err := os .ReadDir (TestRootPath )
118- if err != nil {
119- return nil , fmt .Errorf ("failed to read directory %s: %w" , TestRootPath , err )
118+ if err := json .Unmarshal (testdataRaw , & allCases ); err != nil {
119+ return nil , fmt .Errorf ("failed to unmarshal testdata file: %w" , err )
120120 }
121- ret := make ([] * transferServiceParams , len ( outPaths ))
122- for i , outPath := range outPaths {
123- params , err := newTokenValidationParams ( filepath . Join ( TestRootPath , outPath . Name ()), ppRaw )
124- if err != nil {
125- return nil , fmt . Errorf ( "failed to create params for %s: %w" , outPath . Name (), err )
121+
122+ keys := make ([] string , 0 , len ( allCases ))
123+ for key := range allCases {
124+ if strings . HasPrefix ( key , defaultCasePrefix ) {
125+ keys = append ( keys , key )
126126 }
127- ret [i ] = params
128127 }
129-
130- return ret , nil
131- }
132-
133- func newTokenValidationParams (outputPath string , ppRaw []byte ) (* transferServiceParams , error ) {
134- outputRaw , err := os .ReadFile (outputPath )
135- if err != nil {
136- return nil , fmt .Errorf ("failed to read %s: %w" , outputPath , err )
128+ if len (keys ) == 0 {
129+ return nil , fmt .Errorf ("no test cases with prefix %q found in %s" , defaultCasePrefix , testdataPath )
137130 }
131+ sort .Strings (keys )
138132
139- var tokenData struct {
140- ReqRaw []byte `json:"req_raw"`
141- TXID string `json:"txid"`
142- }
143- if err := json .Unmarshal (outputRaw , & tokenData ); err != nil {
144- return nil , fmt .Errorf ("failed to unmarshal output file: %w" , err )
133+ caseFamily := strings .TrimSuffix (defaultCasePrefix , "_" )
134+ ret := make ([]* transferServiceParams , 0 , len (keys ))
135+ for _ , key := range keys {
136+ tokenCase := allCases [key ]
137+ reqRaw , err := base64 .StdEncoding .DecodeString (tokenCase .ReqRaw )
138+ if err != nil {
139+ return nil , fmt .Errorf ("failed to base64-decode req_raw for %s: %w" , key , err )
140+ }
141+ ret = append (ret , & transferServiceParams {
142+ // Synthetic path: <configDir>/<caseFamily>/<idx> for path-based helpers.
143+ OutputPath : filepath .Join (TestRootPath , caseFamily , strings .TrimPrefix (key , defaultCasePrefix )),
144+ TokenData : & TokenData {
145+ TokenRequestRaw : reqRaw ,
146+ TxID : tokenCase .TXID ,
147+ },
148+ })
145149 }
146150
147- return & transferServiceParams {
148- OutputPath : outputPath ,
149- TokenData : & TokenData {
150- TokenRequestRaw : tokenData .ReqRaw ,
151- TxID : tokenData .TXID ,
152- },
153- }, nil
151+ return ret , nil
154152}
155153
156154type fakeLedger struct {}
0 commit comments