Skip to content

Commit

Permalink
Updated to GitHub Actions, updated to bech32m test specification, dis…
Browse files Browse the repository at this point in the history
…abled some non-functioning tests (#4)
  • Loading branch information
darkverbito authored May 14, 2024
1 parent be94fe7 commit d6dae73
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 170 deletions.
12 changes: 0 additions & 12 deletions .circleci/config.yml

This file was deleted.

37 changes: 37 additions & 0 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Dart

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

# Note: This workflow uses the latest stable version of the Dart SDK.
# You can specify other versions if desired, see documentation here:
# https://github.com/dart-lang/setup-dart/blob/main/README.md
# - uses: dart-lang/setup-dart@v1
- uses: dart-lang/setup-dart@9a04e6d73cca37bd455e0608d7e5092f881fd603

- name: Install dependencies
run: dart pub get

# Uncomment this step to verify the use of 'dart format' on each commit.
# - name: Verify formatting
# run: dart format --output=none --set-exit-if-changed .

# Consider passing '--fatal-infos' for slightly stricter analysis.
- name: Analyze project source
run: dart analyze

# Your project will need to have tests in test/ and a dependency on
# package:test for this step to succeed. Note that Flutter projects will
# want to change this to 'flutter test'.
- name: Run tests
run: dart test
1 change: 0 additions & 1 deletion lib/src/bech32m.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class Bech32mEncoder extends Converter<Bech32m, String>
var checksummed = data + _createChecksum(hrp, data);

if (hasOutOfBoundsChars(checksummed)) {
// TODO this could be more informative
throw OutOfBoundChars('<unknown>');
}

Expand Down
73 changes: 30 additions & 43 deletions test/bech32_test.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import 'package:bech32m_i/bech32m_i.dart';
import 'package:test/test.dart';

// tests cribbed from https://github.com/bitcoin/bips/blob/master/bip-0350.mediawiki#test-vectors-for-bech32m
void main() {
group('bech32 with', () {
group('bech32m with', () {
group('valid test vectors from specification', () {
[
'A12UEL5L',
'a12uel5l',
'an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1tt5tgs',
'abcdef1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw',
'11qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc8247j',
'split1checkupstagehandshakeupstreamerranterredcaperred2y9e3w',
'?1ezyfcl',
'A1LQFN3A',
'a1lqfn3a',
'an83characterlonghumanreadablepartthatcontainsthetheexcludedcharactersbioandnumber11sg7hg6',
'abcdef1l7aum6echk45nj3s0wdvt2fg8x9yrzpqzd3ryx',
'11llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllludsr8',
'split1checkupstagehandshakeupstreamerranterredcaperredlc445v',
'?1v759aa',
]
..forEach((vec) {
test('decode static vector: $vec', () {
Expand All @@ -23,30 +24,6 @@ void main() {
expect(bech32.encode(bech32.decode(vec)), vec.toLowerCase());
});
});

[
'lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaq8rkx3yf5tcsyz3d73gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ecky03ylcqca784w',
'lnbc2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpuaztrnwngzn3kdzw5hydlzf03qdgm2hdq27cqv3agm2awhz5se903vruatfhq77w3ls4evs3ch9zw97j25emudupq63nyw24cg27h2rspfj9srp',
'lnbc20m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqhp58yjmdan79s6qqdhdzgynm4zwqd5d7xmw5fk98klysy043l2ahrqscc6gd6ql3jrc5yzme8v4ntcewwz5cnw92tz0pc8qcuufvq7khhr8wpald05e92xw006sq94mg8v2ndf4sefvf9sygkshp5zfem29trqq2yxxz7',
'lntb20m1pvjluezhp58yjmdan79s6qqdhdzgynm4zwqd5d7xmw5fk98klysy043l2ahrqspp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqfpp3x9et2e20v6pu37c5d9vax37wxq72un98kmzzhznpurw9sgl2v0nklu2g4d0keph5t7tj9tcqd8rexnd07ux4uv2cjvcqwaxgj7v4uwn5wmypjd5n69z2xm3xgksg28nwht7f6zspwp3f9t',
'lnbc20m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqhp58yjmdan79s6qqdhdzgynm4zwqd5d7xmw5fk98klysy043l2ahrqsfpp3qjmp7lwpagxun9pygexvgpjdc4jdj85fr9yq20q82gphp2nflc7jtzrcazrra7wwgzxqc8u7754cdlpfrmccae92qgzqvzq2ps8pqqqqqqpqqqqq9qqqvpeuqafqxu92d8lr6fvg0r5gv0heeeqgcrqlnm6jhphu9y00rrhy4grqszsvpcgpy9qqqqqqgqqqqq7qqzqj9n4evl6mr5aj9f58zp6fyjzup6ywn3x6sk8akg5v4tgn2q8g4fhx05wf6juaxu9760yp46454gpg5mtzgerlzezqcqvjnhjh8z3g2qqdhhwkj',
'lnbc25m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5vdhkven9v5sxyetpdees9q4pqqqqqqqqqqqqqqqqqqszk3ed62snp73037h4py4gry05eltlp0uezm2w9ajnerhmxzhzhsu40g9mgyx5v3ad4aqwkmvyftzk4k9zenz90mhjcy9hcevc7r3lx2sphzfxz7',
]
..forEach((req) {
test('decode BOLT11 String: ${req.substring(0, 90)}...', () {
expect(bech32.decode(req, req.length), isNotNull);
});
})
..forEach((req) {
test('decode then encode BOLT11 String: ${req.substring(0, 90)}...',
() {
var l = req.length;
expect(
bech32.encode(bech32.decode(req, l), l),
req.toLowerCase(),
);
});
});
});

group('invalid test vectors from specification having', () {
Expand All @@ -68,47 +45,57 @@ void main() {
test('too long overall', () {
expect(
() => bech32.decode(
'an84characterslonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1569pvx'),
'an84characterslonghumanreadablepartthatcontainsthetheexcludedcharactersbioandnumber11d6pts4'),
throwsA(TypeMatcher<TooLong>()));
});

test('no separator', () {
expect(() => bech32.decode('pzry9x0s0muk'),
expect(() => bech32.decode('qyrz8wqd2c9m'),
throwsA(TypeMatcher<InvalidSeparator>()));
});

test('empty hpr', () {
expect(() => bech32.decode('1pzry9x0s0muk'),
expect(() => bech32.decode('1qyrz8wqd2c9m'),
throwsA(TypeMatcher<TooShortHrp>()));
});

test('invalid data character', () {
expect(() => bech32.decode('x1b4n0q5v'),
test('invalid data character, case one', () {
expect(() => bech32.decode('y1b0jsk6g'),
throwsA(TypeMatcher<OutOfBoundChars>()));
});

test('invalid data character, case two', () {
expect(() => bech32.decode('lt1igcx5c0'),
throwsA(TypeMatcher<OutOfBoundChars>()));
});

test('too short checksum', () {
expect(() => bech32.decode('li1dgmt3'),
expect(() => bech32.decode('in1muywd'),
throwsA(TypeMatcher<TooShortChecksum>()));
});

test('invalid checksum character', () {
expect(() => bech32.decode('de1lg7wt' '\xFF'),
test('invalid checksum character, case one', () {
expect(() => bech32.decode('mm1crxm3i' '\xFF'),
throwsA(TypeMatcher<OutOfBoundChars>()));
});

test('invalid checksum character, case two', () {
expect(() => bech32.decode('au1s5cgom' '\xFF'),
throwsA(TypeMatcher<OutOfBoundChars>()));
});

test('checksum calculated from upper case hpr', () {
expect(() => bech32.decode('A1G7SGD8'),
expect(() => bech32.decode('M1VUXWEZ'),
throwsA(TypeMatcher<InvalidChecksum>()));
});

test('empty hpr, case one', () {
expect(() => bech32.decode('10a06t8'),
expect(() => bech32.decode('16plkw9'),
throwsA(TypeMatcher<TooShortHrp>()));
});

test('empty hpr, case two', () {
expect(() => bech32.decode('1qzzfhee'),
expect(() => bech32.decode('1p2gdwpf'),
throwsA(TypeMatcher<TooShortHrp>()));
});
});
Expand Down
Loading

0 comments on commit d6dae73

Please sign in to comment.