generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtestvectors.go
36 lines (30 loc) · 902 Bytes
/
testvectors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package web5
import (
"encoding/json"
"os"
)
// TestVectors are JSON files which are tested against to ensure interop with the specification
type TestVectors[T, U any] struct {
Description string `json:"description"`
Vectors []TestVector[T, U] `json:"vectors"`
}
// TestVector is an individual test vector case
type TestVector[I, O any] struct {
Description string `json:"description"`
Input I `json:"input"`
Output O `json:"output"`
Errors bool `json:"errors"`
}
// LoadTestVectors is for reading the vector at the given path
func LoadTestVectors[I, O any](path string) (TestVectors[I, O], error) {
data, err := os.ReadFile(path)
if err != nil {
return TestVectors[I, O]{}, err
}
var testVectors TestVectors[I, O]
err = json.Unmarshal(data, &testVectors)
if err != nil {
return TestVectors[I, O]{}, err
}
return testVectors, nil
}