This repository has been archived by the owner on Dec 12, 2024. It is now read-only.
generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Compile test vectors into one file * Dont compile test vectors into one big file * Replace hosted/ with tbdex-interop-suite submodule * Revert "Replace hosted/ with tbdex-interop-suite submodule" This reverts commit c3e3327. * Update test-vector README
- Loading branch information
Diane Huxley
authored
Jan 9, 2024
1 parent
f7ab5ad
commit 4540cec
Showing
13 changed files
with
400 additions
and
249 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,21 @@ | ||
## Protocol Test Vectors | ||
This directory contains test vectors containing a collection of valid and invalid TBDex Messages and Resources. Implementations can use these vectors to ensure that they **accept valid messages** and **reject invalid messages**. | ||
|
||
### Using Test Vectors | ||
It is recommended to add this repo as a git submodule to your implementation repo. See [this PR](https://github.com/TBD54566975/tbdex-js/pull/129) in `tbdex-js` for an example. | ||
|
||
### Test Vector Structure | ||
Each vector file must follow the schema in `vectors.json.schema`. | ||
1. `description` : A human readable description of the scenario being tested. | ||
2. `input` : A stringified JSON TBDex object | ||
3. `output` : If the input contains a valid TBDex object: A JSON object of the the expected parsed input. Otherwise, omit. | ||
4. `error` : boolean. True if an error is expected, false if not. | ||
|
||
### Generating Test Vectors | ||
1. Create a new test vector file in `hosted/test-vectors/protocol/vectors/` | ||
2. Use an implementation of TBDex that supports the desired scenario to create the `input`, `output`, and `error`. | ||
3. Validate the test vector structure. | ||
a. Set up with `cd hosted/test-vectors/protocol & npm install`. | ||
b. Run with `npm run validate-vectors`. | ||
4. Test the updated vectors against an implmentation of TBDex. | ||
5. Once you are confident that your test vector works as desired, open a PR against `tbdex`. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,8 @@ | ||
{ | ||
"scripts": { | ||
"validate-vectors": "node validate-vectors.js" | ||
}, | ||
"dependencies": { | ||
"ajv": "^8.0.1" | ||
} | ||
} |
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,51 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const Ajv = require('ajv'); | ||
|
||
const testVectorsDirectoryPath = path.join(__dirname, 'vectors'); | ||
const schemaFilePath = path.join(__dirname, 'vector.schema.json'); | ||
|
||
function readJsonFile(filePath) { | ||
try { | ||
const fileContent = fs.readFileSync(filePath, 'utf8'); | ||
return JSON.parse(fileContent); | ||
} catch (error) { | ||
console.error(`Error reading JSON file at ${filePath}: ${error.message}`); | ||
return null; | ||
} | ||
} | ||
|
||
function validateTestVectors() { | ||
// Load the JSON schema | ||
const schema = readJsonFile(schemaFilePath); | ||
|
||
if (!schema) { | ||
console.error('Unable to load JSON schema. Exiting.'); | ||
process.exit(1); | ||
} | ||
|
||
const ajv = new Ajv(); | ||
const validate = ajv.compile(schema); | ||
|
||
// Read and validate JSON schema of each test vector file | ||
const success = true | ||
fs.readdirSync(testVectorsDirectoryPath) | ||
.filter(file => file.endsWith('.json')) | ||
.map(file => path.join(testVectorsDirectoryPath, file)) | ||
.map(filePath => { | ||
const testVectorJson = readJsonFile(filePath) | ||
if (!testVectorJson || !validate(testVectorJson)) { | ||
console.error(`Error validating JSON Schema of test vector at path ${filePath}: `, validate.errors) | ||
success = false | ||
} | ||
}) | ||
|
||
if (success) { | ||
console.log('SUCCESS: All test vectors are valid') | ||
} else { | ||
console.log('FAIL: There were errors validating test vectors') | ||
} | ||
} | ||
|
||
// Compile the valid JSON files into an array | ||
validateTestVectors(); |
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,20 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "object", | ||
"properties": { | ||
"description": { | ||
"type": "string" | ||
}, | ||
"input": { | ||
"type": "string" | ||
}, | ||
"output": { | ||
"type": "object", | ||
"additionalProperties": true | ||
}, | ||
"error": { | ||
"type": "boolean" | ||
} | ||
}, | ||
"required": ["description", "input", "error"] | ||
} |
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,19 @@ | ||
{ | ||
"description": "Close parses from string", | ||
"input": "{\"metadata\":{\"kind\":\"close\",\"to\":\"did:key:zQ3shizfQYEiB8dqac96P6SHYtUCCsY7gSci4Qeaebgsfz1VC\",\"from\":\"did:key:zQ3shhwZ18aebLvYzCDdkkUH78z6RXec843BQc9hybsMRSoxg\",\"id\":\"close_7zzzzzzpvqf2480048h0001jm6\",\"exchangeId\":\"rfq_01hdh7fqvpevq8003pxr001a45\",\"createdAt\":\"2023-10-24T16:15:04.037Z\"},\"data\":{\"reason\":\"test reason\"},\"signature\":\"eyJraWQiOiJkaWQ6a2V5OnpRM3NoaHdaMThhZWJMdll6Q0Rka2tVSDc4ejZSWGVjODQzQlFjOWh5YnNNUlNveGcjelEzc2hod1oxOGFlYkx2WXpDRGRra1VINzh6NlJYZWM4NDNCUWM5aHlic01SU294ZyIsImFsZyI6IkVTMjU2SyJ9..TDtaxXdl1Bljuft8bZlvxTXTK472fKOia12kG_mQA7UhGTVIfwO9cuDCS_86EZHPMhkAvYdOnIiUodouZVba_A\"}", | ||
"output": { | ||
"metadata": { | ||
"kind": "close", | ||
"to": "did:key:zQ3shizfQYEiB8dqac96P6SHYtUCCsY7gSci4Qeaebgsfz1VC", | ||
"from": "did:key:zQ3shhwZ18aebLvYzCDdkkUH78z6RXec843BQc9hybsMRSoxg", | ||
"id": "close_7zzzzzzpvqf2480048h0001jm6", | ||
"exchangeId": "rfq_01hdh7fqvpevq8003pxr001a45", | ||
"createdAt": "2023-10-24T16:15:04.037Z" | ||
}, | ||
"data": { | ||
"reason": "test reason" | ||
}, | ||
"signature": "eyJraWQiOiJkaWQ6a2V5OnpRM3NoaHdaMThhZWJMdll6Q0Rka2tVSDc4ejZSWGVjODQzQlFjOWh5YnNNUlNveGcjelEzc2hod1oxOGFlYkx2WXpDRGRra1VINzh6NlJYZWM4NDNCUWM5aHlic01SU294ZyIsImFsZyI6IkVTMjU2SyJ9..TDtaxXdl1Bljuft8bZlvxTXTK472fKOia12kG_mQA7UhGTVIfwO9cuDCS_86EZHPMhkAvYdOnIiUodouZVba_A" | ||
}, | ||
"error": false | ||
} |
Oops, something went wrong.