]> gitweb.factorcode.org Git - factor.git/blob - extra/hashcash/hashcash-tests.factor
hashcash: improvements by Zoltán Kéri.
[factor.git] / extra / hashcash / hashcash-tests.factor
1 ! Copyright (C) 2022 Zoltán Kéri.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors calendar hashcash hashcash.private kernel
4 literals namespaces sequences splitting tools.test ;
5 IN: hashcash.tests
6
7 ! We do not want to generate it multiple times. It would be too slow.
8 CONSTANT: generated-mint $[ "foo@bar.com" mint ]
9
10 { t } [ generated-mint dup ":" split third valid-date? swap drop ] unit-test
11
12 { f } [
13     [ -1 expiry-days set
14       generated-mint valid-stamp?
15     ] with-scope
16 ] unit-test
17
18 { t } [
19     [ 0 expiry-days set
20       generated-mint valid-stamp?
21     ] with-scope
22 ] unit-test
23
24 { t } [ generated-mint valid-stamp? ] unit-test
25
26 { t } [
27     <hashcash> "foo@bar.com" >>resource 16 >>bits
28     mint* valid-stamp?
29 ] unit-test
30
31 { t } [
32     [ 9999 expiry-days set
33       "1:20:220403:foo@bar.com::fAY*-p!s:23472" valid-stamp?
34     ] with-scope
35 ] unit-test
36
37 { f } [
38     [ -1 expiry-days set
39       now-gmt-yymmdd valid-date?
40     ] with-scope
41 ] unit-test
42
43 { t } [
44     [ 0 expiry-days set
45       now-gmt-yymmdd valid-date?
46     ] with-scope
47 ] unit-test
48
49 { t } [ now-gmt-yymmdd valid-date? ] unit-test
50
51 {  30 } [ "220131" "220101" yymmdd-gmt-diff ] unit-test
52 { -30 } [ "220101" "220131" yymmdd-gmt-diff ] unit-test
53
54 { t } [ now-gmt 1 days time- timestamp>yymmdd on-or-before-today? nip ] unit-test
55 { t } [ now-gmt timestamp>yymmdd on-or-before-today? nip ] unit-test
56 { f } [ now-gmt 1 days time+ timestamp>yymmdd on-or-before-today? nip ] unit-test