From 4f8f009b953a0eff0a0af847a3b5d49fb840ccc5 Mon Sep 17 00:00:00 2001 From: dev Date: Mon, 5 Oct 2026 22:21:31 +0200 Subject: [PATCH] Tests: note.json, the data of each public note and its result Each of the 16 notes of testdata/vectors/note.json, the cases of the list of v0.11 of spec section 64, gives the result and the detail of the reference through checkNoteData, and a reader shows it as publicNote only when it is ok; otherwise unusableNote says so and StandardExtensions reports it unusable with ERR_EXTENSION_DATA_INVALID, never the capsule. Co-Authored-By: Claude Opus 5.5 --- test/open_note_test.dart | 41 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/test/open_note_test.dart b/test/open_note_test.dart index 11f9c62..69705b1 100644 --- a/test/open_note_test.dart +++ b/test/open_note_test.dart @@ -1,6 +1,7 @@ // The public note of spec §24.1 against Go: test/vectors/open_notes.json, // which tool/open_go_vectors.go writes with extension.CheckNote, Note, -// Header.UnusableNote and extension.Standard of the reference. +// Header.UnusableNote and extension.Standard of the reference; and +// testdata/vectors/note.json, the cases of the list of v0.11 of spec §64. @TestOn('vm') library; @@ -28,6 +29,44 @@ void main() { ); }); + test('note.json: the data of each note and the result of its rules', () { + final f = readJson('testdata/vectors/note.json'); + expect(f['spec'], specVersion); + final notes = (f['notes']! as List).cast(); + expect(notes, hasLength(16)); + expect(notes.where((c) => c['result'] == 'ok'), hasLength(4)); + for (final c in notes) { + final data = fromHex(c['data']! as String); + final reason = c['name'] as String?; + // detail is the text of the rule, without the code. + final want = c['result'] == 'ok' + ? ['ok', ''] + : [c['result'], '${c['detail']}: ${c['result']}']; + String? text; + expect(outcomeOf(() => text = checkNoteData(data)), want, reason: reason); + // A reader shows the note only when it is ok, and otherwise treats it + // as unusable, never the capsule (spec §54). + final exts = [Extension(noteExtensionId, 1, data.isEmpty ? null : data)]; + expect( + [publicNote(exts), unusableNote(exts)], + c['result'] == 'ok' ? [text, false] : [null, true], + reason: reason, + ); + expect( + [ + for (final u in checkNoncritical( + exts, + const StandardExtensions(), + ExtensionObject.publicHeader, + )) + u.error.code.code, + ], + c['result'] == 'ok' ? isEmpty : [c['result']], + reason: reason, + ); + } + }); + test('the note of a header, as PublicNote and UnusableNote of Go', () { final r = jsonDecode( File('testdata/fixtures/time_only_extensions.json').readAsStringSync(),