memoriesadrift / tuw-cryptocurrencies-blockchain

Blockchain created for the Cryptocurrencies course at TU Wien
0 stars 0 forks source link

Message Encoding & Decoding #10

Closed memoriesadrift closed 1 year ago

memoriesadrift commented 1 year ago

Closes #3

This one is big, go commit by commit in review.

Features

  1. Canonical JSON stringify/parse I tried to hold to the contract of the JSON global as well as the canonical JSON spec. If you have good ideas on how to test this feel free to suggest / add. Right now I'm not testing it against the RFC but I think we can just test it's working right when we implement hashing.

  2. Message type definitions This one is pretty big, but I tried to leverage JSON.parse() in conjunction with runtypes to make the checking smooth and as low overhead as possible.
    There is one annoying thing about runtypes though, it doesn't support exact shape matching, so I had to get that extension from an issue I've linked to in the relevant part of the codebase. Hopefully the LV Leitung will understand this shameless copy paste :)

  3. Test runner I just wrote my own in the end, it was quick work, done it before and avoided this mess 🥴 telegram-cloud-photo-size-4-5882075819633917643-x You can see how I intended tests to be written from the example test and fixture files.