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.
dateKeys-dart/test/open_note_test.dart

56 lines
1.8 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.
@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('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]);
});
}

Powered by TurnKey Linux.