Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

feat: add test vectors #29

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ schemas:
#!/bin/bash
dart run generate_schemas.dart

vectors:
#!/bin/bash
dart run generate_vectors.dart

get:
@dart pub get

Expand Down
55 changes: 55 additions & 0 deletions generate_vectors.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import 'dart:io';
import 'package:path/path.dart' as p;

void main() {
final vectorsPath =
p.join('tbdex', 'hosted', 'test-vectors', 'protocol', 'vectors');
final outputDir = Directory('test/protocol/test_vectors')
..createSync(recursive: true);

Directory(vectorsPath)
.listSync()
.whereType<File>()
.where((file) => file.path.endsWith('.json'))
.forEach((file) {
final json = file.readAsStringSync();
final dartCode = _generateCode(file.path, json);

File(p.join(outputDir.path, '${_getFileName(file.path)}.dart'))
.writeAsStringSync(dartCode);
});
}

String _generateCode(String filePath, String jsonString) => '''
class ${_getClassName(filePath)} {
static const String vector = r\'\'\'
$jsonString\'\'\';
}''';

String _getFileName(String filePath) {
var segments = p.split(filePath);
final index = segments.indexOf('vectors');
print(segments);
final baseName = segments[index + 1].split('.').first;

return _toSnakeCase(baseName);
}

String _getClassName(String filePath) {
var segments = p.split(filePath);
final index = segments.indexOf('vectors');
final baseName = segments[index + 1].split('.').first;

return _toCamelCase(baseName);
}

String _toSnakeCase(String input) => input.replaceAll('-', '_').toLowerCase();

String _toCamelCase(String input) => input
.split(RegExp('[_-]'))
.map(
(str) => str.isEmpty
? ''
: str[0].toUpperCase() + str.substring(1).toLowerCase(),
)
.join();
22 changes: 22 additions & 0 deletions test/protocol/test_vectors/parse_balance.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class ParseBalance {
static const String vector = r'''
{
"description": "Balance parses from string",
"input": "{\"metadata\":{\"from\":\"did:dht:3whftgpbdjihx9ze9tdn575zqzm4qwccetnf1ybiibuzad7rrmyy\",\"kind\":\"balance\",\"id\":\"balance_01hw25hn2pej6rdnd5qnh96wxj\",\"createdAt\":\"2024-04-22T05:48:01.494Z\",\"protocol\":\"1.0\"},\"data\":{\"currencyCode\":\"USD\",\"available\":\"400.00\"},\"signature\":\"eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDpkaHQ6M3doZnRncGJkamloeDl6ZTl0ZG41NzV6cXptNHF3Y2NldG5mMXliaWlidXphZDdycm15eSMwIn0..v6cJEJuEOjCes3-7UJvkyMgPRUk9dD3h_COfjSEQJiNMpQ7DOMTnFAVd-g_gsO4Y5FBqnKT8B9N86pFPoebNCQ\"}",
"output": {
"metadata": {
"from": "did:dht:3whftgpbdjihx9ze9tdn575zqzm4qwccetnf1ybiibuzad7rrmyy",
"kind": "balance",
"id": "balance_01hw25hn2pej6rdnd5qnh96wxj",
"createdAt": "2024-04-22T05:48:01.494Z",
"protocol": "1.0"
},
"data": {
"currencyCode": "USD",
"available": "400.00"
},
"signature": "eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDpkaHQ6M3doZnRncGJkamloeDl6ZTl0ZG41NzV6cXptNHF3Y2NldG5mMXliaWlidXphZDdycm15eSMwIn0..v6cJEJuEOjCes3-7UJvkyMgPRUk9dD3h_COfjSEQJiNMpQ7DOMTnFAVd-g_gsO4Y5FBqnKT8B9N86pFPoebNCQ"
},
"error": false
}''';
}
24 changes: 24 additions & 0 deletions test/protocol/test_vectors/parse_close.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class ParseClose {
static const String vector = r'''
{
"description": "Close parses from string",
"input": "{\"metadata\":{\"from\":\"did:dht:3whftgpbdjihx9ze9tdn575zqzm4qwccetnf1ybiibuzad7rrmyy\",\"to\":\"did:dht:qyac4pru9ykcxbrutpaaxkmususxh4wtc4ctt19813zrie8uyy5y\",\"exchangeId\":\"rfq_01hw25hn2xffnv99m4rb9r8rth\",\"protocol\":\"1.0\",\"kind\":\"close\",\"id\":\"close_01hw25hn2xffnv99m4rehcmj53\",\"createdAt\":\"2024-04-22T05:48:01.501Z\"},\"data\":{\"reason\":\"The reason for closing the exchange\",\"success\":true},\"signature\":\"eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDpkaHQ6M3doZnRncGJkamloeDl6ZTl0ZG41NzV6cXptNHF3Y2NldG5mMXliaWlidXphZDdycm15eSMwIn0..ZvoVDuSrqqdXsSXgqB-U26tAU1WqUqqU_KpD1KvdYocIcmTsshjUASEwM_lUz1UnGglqkWeCIrHqrm9NNGDqBw\"}",
"output": {
"metadata": {
"from": "did:dht:3whftgpbdjihx9ze9tdn575zqzm4qwccetnf1ybiibuzad7rrmyy",
"to": "did:dht:qyac4pru9ykcxbrutpaaxkmususxh4wtc4ctt19813zrie8uyy5y",
"exchangeId": "rfq_01hw25hn2xffnv99m4rb9r8rth",
"protocol": "1.0",
"kind": "close",
"id": "close_01hw25hn2xffnv99m4rehcmj53",
"createdAt": "2024-04-22T05:48:01.501Z"
},
"data": {
"reason": "The reason for closing the exchange",
"success": true
},
"signature": "eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDpkaHQ6M3doZnRncGJkamloeDl6ZTl0ZG41NzV6cXptNHF3Y2NldG5mMXliaWlidXphZDdycm15eSMwIn0..ZvoVDuSrqqdXsSXgqB-U26tAU1WqUqqU_KpD1KvdYocIcmTsshjUASEwM_lUz1UnGglqkWeCIrHqrm9NNGDqBw"
},
"error": false
}''';
}
111 changes: 111 additions & 0 deletions test/protocol/test_vectors/parse_offering.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
class ParseOffering {
static const String vector = r'''
{
"description": "Offering parses from string",
"input": "{\"metadata\":{\"from\":\"did:dht:c765ni81pupn5zc646xskdsufgokstbsgfwhae8hudsrjushhruy\",\"kind\":\"offering\",\"id\":\"offering_01hwcg100gf8btevp8x3pea75b\",\"createdAt\":\"2024-04-26T06:03:34.289Z\",\"protocol\":\"1.0\"},\"data\":{\"description\":\"Selling BTC for USD\",\"payin\":{\"currencyCode\":\"USD\",\"min\":\"0.0\",\"max\":\"999999.99\",\"methods\":[{\"kind\":\"DEBIT_CARD\",\"requiredPaymentDetails\":{\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"type\":\"object\",\"properties\":{\"cardNumber\":{\"type\":\"string\",\"description\":\"The 16-digit debit card number\",\"minLength\":16,\"maxLength\":16},\"expiryDate\":{\"type\":\"string\",\"description\":\"The expiry date of the card in MM/YY format\",\"pattern\":\"^(0[1-9]|1[0-2])\\\\/([0-9]{2})$\"},\"cardHolderName\":{\"type\":\"string\",\"description\":\"Name of the cardholder as it appears on the card\"},\"cvv\":{\"type\":\"string\",\"description\":\"The 3-digit CVV code\",\"minLength\":3,\"maxLength\":3}},\"required\":[\"cardNumber\",\"expiryDate\",\"cardHolderName\",\"cvv\"],\"additionalProperties\":false}}]},\"payout\":{\"currencyCode\":\"BTC\",\"max\":\"999526.11\",\"methods\":[{\"kind\":\"BTC_ADDRESS\",\"requiredPaymentDetails\":{\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"type\":\"object\",\"properties\":{\"btcAddress\":{\"type\":\"string\",\"description\":\"your Bitcoin wallet address\"}},\"required\":[\"btcAddress\"],\"additionalProperties\":false},\"estimatedSettlementTime\":10}]},\"payoutUnitsPerPayinUnit\":\"0.00003826\",\"requiredClaims\":{\"id\":\"7ce4004c-3c38-4853-968b-e411bafcd945\",\"input_descriptors\":[{\"id\":\"bbdb9b7c-5754-4f46-b63b-590bada959e0\",\"constraints\":{\"fields\":[{\"path\":[\"$.type[*]\"],\"filter\":{\"type\":\"string\",\"pattern\":\"^YoloCredential$\"}}]}}]}},\"signature\":\"eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDpkaHQ6Yzc2NW5pODFwdXBuNXpjNjQ2eHNrZHN1Zmdva3N0YnNnZndoYWU4aHVkc3JqdXNoaHJ1eSMwIn0..ciWPR5RGHxfQZJUKw3Z2np6EtVJ0wQMZBsNoFjJ-W11x1NmmZCfSkbRAES0eoGlu0Wlyf4waHKvN0UdunakgCw\"}",
"output": {
"metadata": {
"from": "did:dht:c765ni81pupn5zc646xskdsufgokstbsgfwhae8hudsrjushhruy",
"kind": "offering",
"id": "offering_01hwcg100gf8btevp8x3pea75b",
"createdAt": "2024-04-26T06:03:34.289Z",
"protocol": "1.0"
},
"data": {
"description": "Selling BTC for USD",
"payin": {
"currencyCode": "USD",
"min": "0.0",
"max": "999999.99",
"methods": [
{
"kind": "DEBIT_CARD",
"requiredPaymentDetails": {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"cardNumber": {
"type": "string",
"description": "The 16-digit debit card number",
"minLength": 16,
"maxLength": 16
},
"expiryDate": {
"type": "string",
"description": "The expiry date of the card in MM/YY format",
"pattern": "^(0[1-9]|1[0-2])\\/([0-9]{2})$"
},
"cardHolderName": {
"type": "string",
"description": "Name of the cardholder as it appears on the card"
},
"cvv": {
"type": "string",
"description": "The 3-digit CVV code",
"minLength": 3,
"maxLength": 3
}
},
"required": [
"cardNumber",
"expiryDate",
"cardHolderName",
"cvv"
],
"additionalProperties": false
}
}
]
},
"payout": {
"currencyCode": "BTC",
"max": "999526.11",
"methods": [
{
"kind": "BTC_ADDRESS",
"requiredPaymentDetails": {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"btcAddress": {
"type": "string",
"description": "your Bitcoin wallet address"
}
},
"required": [
"btcAddress"
],
"additionalProperties": false
},
"estimatedSettlementTime": 10
}
]
},
"payoutUnitsPerPayinUnit": "0.00003826",
"requiredClaims": {
"id": "7ce4004c-3c38-4853-968b-e411bafcd945",
"input_descriptors": [
{
"id": "bbdb9b7c-5754-4f46-b63b-590bada959e0",
"constraints": {
"fields": [
{
"path": [
"$.type[*]"
],
"filter": {
"type": "string",
"pattern": "^YoloCredential$"
}
}
]
}
}
]
}
},
"signature": "eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDpkaHQ6Yzc2NW5pODFwdXBuNXpjNjQ2eHNrZHN1Zmdva3N0YnNnZndoYWU4aHVkc3JqdXNoaHJ1eSMwIn0..ciWPR5RGHxfQZJUKw3Z2np6EtVJ0wQMZBsNoFjJ-W11x1NmmZCfSkbRAES0eoGlu0Wlyf4waHKvN0UdunakgCw"
},
"error": false
}''';
}
22 changes: 22 additions & 0 deletions test/protocol/test_vectors/parse_order.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class ParseOrder {
static const String vector = r'''
{
"description": "Order parses from string",
"input": "{\"metadata\":{\"from\":\"did:dht:qyac4pru9ykcxbrutpaaxkmususxh4wtc4ctt19813zrie8uyy5y\",\"to\":\"did:dht:3whftgpbdjihx9ze9tdn575zqzm4qwccetnf1ybiibuzad7rrmyy\",\"exchangeId\":\"rfq_01hw25hn38fg8sz07yn8dknvjy\",\"externalId\":\"ext_1234\",\"protocol\":\"1.0\",\"kind\":\"order\",\"id\":\"order_01hw25hn38fg8sz07ynfn8vwmb\",\"createdAt\":\"2024-04-22T05:48:01.512Z\"},\"data\":{},\"signature\":\"eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDpkaHQ6cXlhYzRwcnU5eWtjeGJydXRwYWF4a211c3VzeGg0d3RjNGN0dDE5ODEzenJpZTh1eXk1eSMwIn0..dwoJjm0Ixh6GnwSOhx1AOo9dSHOWNMC_mqM4s-dDhJR0HQI47vD1uemqFSgSZaB9qNUqZawoCcqbhv4fSlO5Ag\"}",
"output": {
"metadata": {
"from": "did:dht:qyac4pru9ykcxbrutpaaxkmususxh4wtc4ctt19813zrie8uyy5y",
"to": "did:dht:3whftgpbdjihx9ze9tdn575zqzm4qwccetnf1ybiibuzad7rrmyy",
"exchangeId": "rfq_01hw25hn38fg8sz07yn8dknvjy",
"externalId": "ext_1234",
"protocol": "1.0",
"kind": "order",
"id": "order_01hw25hn38fg8sz07ynfn8vwmb",
"createdAt": "2024-04-22T05:48:01.512Z"
},
"data": {},
"signature": "eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDpkaHQ6cXlhYzRwcnU5eWtjeGJydXRwYWF4a211c3VzeGg0d3RjNGN0dDE5ODEzenJpZTh1eXk1eSMwIn0..dwoJjm0Ixh6GnwSOhx1AOo9dSHOWNMC_mqM4s-dDhJR0HQI47vD1uemqFSgSZaB9qNUqZawoCcqbhv4fSlO5Ag"
},
"error": false
}''';
}
23 changes: 23 additions & 0 deletions test/protocol/test_vectors/parse_orderstatus.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class ParseOrderstatus {
static const String vector = r'''
{
"description": "Order Status parses from string",
"input": "{\"metadata\":{\"from\":\"did:dht:3whftgpbdjihx9ze9tdn575zqzm4qwccetnf1ybiibuzad7rrmyy\",\"to\":\"did:dht:qyac4pru9ykcxbrutpaaxkmususxh4wtc4ctt19813zrie8uyy5y\",\"exchangeId\":\"rfq_01hw25hn39ermsmftw3a3rb1ph\",\"protocol\":\"1.0\",\"kind\":\"orderstatus\",\"id\":\"orderstatus_01hw25hn39ermsmftw3d1efc2f\",\"createdAt\":\"2024-04-22T05:48:01.513Z\"},\"data\":{\"orderStatus\":\"wee\"},\"signature\":\"eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDpkaHQ6M3doZnRncGJkamloeDl6ZTl0ZG41NzV6cXptNHF3Y2NldG5mMXliaWlidXphZDdycm15eSMwIn0..alR9hfgjKSbSEmuXi1fpA7Puh5JNp22uDqk2b5zGcbvbgUsDCkChBQ47SWjAV5BchmfZ0yaDLPQPTxiH918jBQ\"}",
"output": {
"metadata": {
"from": "did:dht:3whftgpbdjihx9ze9tdn575zqzm4qwccetnf1ybiibuzad7rrmyy",
"to": "did:dht:qyac4pru9ykcxbrutpaaxkmususxh4wtc4ctt19813zrie8uyy5y",
"exchangeId": "rfq_01hw25hn39ermsmftw3a3rb1ph",
"protocol": "1.0",
"kind": "orderstatus",
"id": "orderstatus_01hw25hn39ermsmftw3d1efc2f",
"createdAt": "2024-04-22T05:48:01.513Z"
},
"data": {
"orderStatus": "wee"
},
"signature": "eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDpkaHQ6M3doZnRncGJkamloeDl6ZTl0ZG41NzV6cXptNHF3Y2NldG5mMXliaWlidXphZDdycm15eSMwIn0..alR9hfgjKSbSEmuXi1fpA7Puh5JNp22uDqk2b5zGcbvbgUsDCkChBQ47SWjAV5BchmfZ0yaDLPQPTxiH918jBQ"
},
"error": false
}''';
}
40 changes: 40 additions & 0 deletions test/protocol/test_vectors/parse_quote.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class ParseQuote {
static const String vector = r'''
{
"description": "Quote parses from string",
"input": "{\"metadata\":{\"exchangeId\":\"rfq_01hw25hn2te5rt4c6fnkb877xg\",\"from\":\"did:dht:3whftgpbdjihx9ze9tdn575zqzm4qwccetnf1ybiibuzad7rrmyy\",\"to\":\"did:dht:qyac4pru9ykcxbrutpaaxkmususxh4wtc4ctt19813zrie8uyy5y\",\"protocol\":\"1.0\",\"kind\":\"quote\",\"id\":\"quote_01hw25hn2vfd0944t9xp7jbx0t\",\"createdAt\":\"2024-04-22T05:48:01.499Z\"},\"data\":{\"expiresAt\":\"2024-04-22T05:48:01.499Z\",\"payin\":{\"currencyCode\":\"BTC\",\"amount\":\"0.01\",\"fee\":\"0.0001\",\"paymentInstruction\":{\"link\":\"tbdex.io/example\",\"instruction\":\"Fake instruction\"}},\"payout\":{\"currencyCode\":\"USD\",\"amount\":\"1000.00\",\"paymentInstruction\":{\"link\":\"tbdex.io/example\",\"instruction\":\"Fake instruction\"}}},\"signature\":\"eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDpkaHQ6M3doZnRncGJkamloeDl6ZTl0ZG41NzV6cXptNHF3Y2NldG5mMXliaWlidXphZDdycm15eSMwIn0..sHQBr_s8EEx81hf4I8-qaY_ya4wWtE_wN93YY5-y22bG9RyiX4PAnwJUQJewa8STrK-M38yVNQDaBnqs1O9WAQ\"}",
"output": {
"metadata": {
"exchangeId": "rfq_01hw25hn2te5rt4c6fnkb877xg",
"from": "did:dht:3whftgpbdjihx9ze9tdn575zqzm4qwccetnf1ybiibuzad7rrmyy",
"to": "did:dht:qyac4pru9ykcxbrutpaaxkmususxh4wtc4ctt19813zrie8uyy5y",
"protocol": "1.0",
"kind": "quote",
"id": "quote_01hw25hn2vfd0944t9xp7jbx0t",
"createdAt": "2024-04-22T05:48:01.499Z"
},
"data": {
"expiresAt": "2024-04-22T05:48:01.499Z",
"payin": {
"currencyCode": "BTC",
"amount": "0.01",
"fee": "0.0001",
"paymentInstruction": {
"link": "tbdex.io/example",
"instruction": "Fake instruction"
}
},
"payout": {
"currencyCode": "USD",
"amount": "1000.00",
"paymentInstruction": {
"link": "tbdex.io/example",
"instruction": "Fake instruction"
}
}
},
"signature": "eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDpkaHQ6M3doZnRncGJkamloeDl6ZTl0ZG41NzV6cXptNHF3Y2NldG5mMXliaWlidXphZDdycm15eSMwIn0..sHQBr_s8EEx81hf4I8-qaY_ya4wWtE_wN93YY5-y22bG9RyiX4PAnwJUQJewa8STrK-M38yVNQDaBnqs1O9WAQ"
},
"error": false
}''';
}
Loading
Loading