generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add reusable test vectors #130
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c4a3b6d
Add reusable test vector code
KendallWeihe 26ff1c4
Add doc comments, add print descriptions
KendallWeihe 2861b54
Add test vector for vcjwt decode
KendallWeihe e77f69b
Remove failing didjwk vector test
KendallWeihe fc153eb
Fix decode test
KendallWeihe e832728
Change package name to web5, change function name to load
KendallWeihe d5fc9d0
Rename file to match go convention
KendallWeihe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package web5go | ||
KendallWeihe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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[T, U any] struct { | ||
Description string `json:"description"` | ||
Input T `json:"input"` | ||
Output U `json:"output"` | ||
Errors bool `json:"errors"` | ||
} | ||
|
||
// ReadTestVector is for reading the vector at the given path | ||
func ReadTestVector[T, U any](path string) (TestVectors[T, U], error) { | ||
KendallWeihe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
data, err := os.ReadFile(path) | ||
if err != nil { | ||
return TestVectors[T, U]{}, err | ||
} | ||
|
||
var testVectors TestVectors[T, U] | ||
err = json.Unmarshal(data, &testVectors) | ||
if err != nil { | ||
return TestVectors[T, U]{}, err | ||
} | ||
|
||
return testVectors, nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
he done it! he used the dashes! the thing everyone wants to do but shys away bc presumed go convention. thoughts on just
testvectors.go
? are you thinking we may end up adding moar vector loaders? if so, addingweb5-spec
def makes sense as prefix. alternatively, could use this file for loading all sorts of vectors and change the function name toLoadWeb5SpecVectors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oop, been in rust hacking land so forgetting golang conventions, change the filename!
thought about making the function specific to web5, but that data structure may be a standard or reusable across different vector sets, so leaving as-is for now
a bit annoying we have the relative file path in the test file but I can't think of an obvious better alternative