Skip to content
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

Update Test Vector Readme With Example #80

Merged
merged 14 commits into from
Dec 19, 2023
Merged

Conversation

nitro-neal
Copy link
Contributor

@nitro-neal nitro-neal commented Dec 14, 2023

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:

  • 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:
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:

  • 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:
  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!

web5-test-vectors/README.md Show resolved Hide resolved
Copy link
Contributor

@andresuribe87 andresuribe87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small suggestions.

web5-test-vectors/README.md Outdated Show resolved Hide resolved
web5-test-vectors/README.md Outdated Show resolved Hide resolved
web5-test-vectors/README.md Outdated Show resolved Hide resolved
web5-test-vectors/README.md Outdated Show resolved Hide resolved
web5-test-vectors/README.md Outdated Show resolved Hide resolved
web5-test-vectors/README.md Outdated Show resolved Hide resolved
web5-test-vectors/README.md Outdated Show resolved Hide resolved
web5-test-vectors/README.md Outdated Show resolved Hide resolved
web5-test-vectors/README.md Outdated Show resolved Hide resolved
web5-test-vectors/README.md Outdated Show resolved Hide resolved
@nitro-neal nitro-neal merged commit 93b85ee into main Dec 19, 2023
4 of 6 checks passed
@nitro-neal nitro-neal deleted the update-test-vector-readme branch December 19, 2023 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants