Skip to content

Commit

Permalink
Update Test Vector Readme With Example (#80)
Browse files Browse the repository at this point in the history
* update readme with example

* updates

* update lint

* Update web5-test-vectors/README.md

Co-authored-by: Andres Uribe <[email protected]>

* Update web5-test-vectors/README.md

Co-authored-by: Andres Uribe <[email protected]>

* Update web5-test-vectors/README.md

Co-authored-by: Andres Uribe <[email protected]>

* Update web5-test-vectors/README.md

Co-authored-by: Andres Uribe <[email protected]>

* Update web5-test-vectors/README.md

Co-authored-by: Andres Uribe <[email protected]>

* Update web5-test-vectors/README.md

Co-authored-by: Andres Uribe <[email protected]>

* Update web5-test-vectors/README.md

Co-authored-by: Andres Uribe <[email protected]>

* Update web5-test-vectors/README.md

Co-authored-by: Andres Uribe <[email protected]>

* Update web5-test-vectors/README.md

Co-authored-by: Andres Uribe <[email protected]>

* Update web5-test-vectors/README.md

Co-authored-by: Andres Uribe <[email protected]>

---------

Co-authored-by: Andres Uribe <[email protected]>
  • Loading branch information
nitro-neal and andresuribe87 authored Dec 19, 2023
1 parent 3b5efbd commit 93b85ee
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions web5-test-vectors/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,89 @@ The structure of a `vector` object is designed to fulfill two conditions:
* In Rust, the error handling would pivot on matching `Result.Err` rather than `Result.Ok`.

Should `errors` be set to `true`, the `output` field may optionally be used to include expected error messages.

## Creating New Test Vector Full Walkthrough

### Step 1: Create New Test Vector

1. Navigate to the GitHub repository: sdk-development[https://github.com/TBD54566975/sdk-development/tree/main/web5-test-vectors]

2. Create a new folder and JSON file with the structure example_feature/hello_world.json.

3. Populate the JSON file as follows. Note that adherence to the [json schema](./vectors.schema.json) is enforced by CI.

```json
{
"description": "vector example",
"vectors": [
{
"description": "this is an example",
"input": "hello world",
"output": "hello world",
"errors" : false
}
]
}
```

### Step 2: Copy JSON to Local Test-Vectors Directory

1. Copy the `hello_world.json` file from `example_feature` directory.

1. Place the copied file into the top level `test-vectors` directory of both `web5-kt` and `web5-js` projects.

### Step 3: Create Unit Test in web5-kt

1. In the `web5-kt` project, create a new unit test class.

1. Name the class following the given pattern:

* Prefix: `Web5TestVectors`

* Middle: Convert `example_feature` to `ExampleFeature` (capitalize words and remove underscores)

* Combined Output: `Web5TestVectorsExampleFeature`

1. Implement the class and test method as follows:

```kt
class Web5TestVectorsExampleFeature {
@Test
fun hello_world() {
val testVectors = mapper.readValue(File("../test-vectors/example_feature/hello_world.json"), typeRef)
assertEquals(testVectors.vectors[0].input, testVectors.vectors[0].output)
}
}
```

### Step 4: Create Unit Test in web5-js

1. In the `web5-js` project, create a new unit test class.

1. Name the class following the given pattern:

* Prefix: `Web5TestVectors`

* Middle: Convert `example_feature` to `ExampleFeature` (capitalize words and remove underscores)

* Combined Output: `Web5TestVectorsExampleFeature`

1. Implement the class and test method as follows:

```javascript
import ExampleFeatureHelloWorldSpecJson from '../../../test-vectors/example_feature/hello_world.json' assert { type: 'json' };

describe('Web5TestVectorsExampleFeature', () => {
it('hello_world', async () => {
const vectors = ExampleFeatureHelloWorldSpecJson.vectors;
expect(vectors[0].input).to.equal(vectors[0].output)
});
});
```

### Step 5: Completion

* Once the above steps are completed, the `sdk-development` repository will automatically detect the new test vectors by consuming artifacts generated by a github action (No action by you required)
* The system will indicate whether the test passes or fails with a checkmark or an 'x'.

Your new test vector system is now set up and ready for use!

0 comments on commit 93b85ee

Please sign in to comment.