TBD54566975 / web5-spec

Web5 Spec
https://tbd54566975.github.io/web5-spec/
Apache License 2.0
7 stars 5 forks source link

Update Test Vector Readme With Example #80

Closed nitro-neal closed 9 months ago

nitro-neal commented 9 months ago

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:

{
  "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.

  2. 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.

  2. Name the class following the given pattern:

  1. Implement the class and test method as follows:
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.

  2. Name the class following the given pattern:

  1. Implement the class and test method as follows:
  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

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