You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
3.2 KiB
95 lines
3.2 KiB
// 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; and
|
|
// testdata/vectors/note.json, the cases of the list of v0.11 of spec §64.
|
|
@TestOn('vm')
|
|
library;
|
|
|
|
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:datekeys/datekeys.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import 'open_vectors_support.dart';
|
|
|
|
Json readJson(String path) => jsonDecode(File(path).readAsStringSync()) as Json;
|
|
|
|
void main() {
|
|
test('open_notes.json: every note as in Go', () {
|
|
final f = readJson('test/vectors/open_notes.json');
|
|
expect(f['spec'], specVersion);
|
|
final check = (f['check']! as List).cast<Json>();
|
|
expect(check, hasLength(greaterThan(300)));
|
|
expect(check.where((c) => c['result'] == 'ok'), hasLength(greaterThan(10)));
|
|
checkNoteCases(
|
|
check,
|
|
(f['note']! as List).cast<Json>(),
|
|
(f['standard']! as List).cast<Json>(),
|
|
);
|
|
});
|
|
|
|
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<Json>();
|
|
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(),
|
|
) as Json;
|
|
final h = decodeHeader(fromHex(r['public_header']! as String));
|
|
expect([h.publicNote, h.unusableNote], [null, false]);
|
|
final noted = Header(
|
|
capsuleId: h.capsuleId,
|
|
dateKey: h.dateKey,
|
|
policy: h.policy,
|
|
noncritical: [newNote('Cartas del viaje a Lisboa'), ...h.noncritical],
|
|
);
|
|
expect(
|
|
[noted.publicNote, noted.unusableNote],
|
|
['Cartas del viaje a Lisboa', false],
|
|
);
|
|
final bad = Header(
|
|
capsuleId: h.capsuleId,
|
|
dateKey: h.dateKey,
|
|
policy: h.policy,
|
|
noncritical: [Extension(noteExtensionId, 1, fromHex('610962'))],
|
|
);
|
|
expect([bad.publicNote, bad.unusableNote], [null, true]);
|
|
});
|
|
}
|