]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/hashcash/hashcash-tests.factor
hashcash: improvements by Zoltán Kéri.
[factor.git] / extra / hashcash / hashcash-tests.factor
index 1f2ccd5dd948b3b8b4a3898e69a6aec065b7113d..a248ece31f610da650ecf8f49e57115932b9e3a5 100644 (file)
@@ -1,15 +1,56 @@
-USING: accessors sequences tools.test hashcash ;
+! Copyright (C) 2022 Zoltán Kéri.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors calendar hashcash hashcash.private kernel
+literals namespaces sequences splitting tools.test ;
+IN: hashcash.tests
 
-{ t } [ "foo@bar.com" mint check-stamp ] unit-test
+! We do not want to generate it multiple times. It would be too slow.
+CONSTANT: generated-mint $[ "foo@bar.com" mint ]
+
+{ t } [ generated-mint dup ":" split third valid-date? swap drop ] unit-test
+
+{ f } [
+    [ -1 expiry-days set
+      generated-mint valid-stamp?
+    ] with-scope
+] unit-test
+
+{ t } [
+    [ 0 expiry-days set
+      generated-mint valid-stamp?
+    ] with-scope
+] unit-test
+
+{ t } [ generated-mint valid-stamp? ] unit-test
 
 { t } [
-    <hashcash>
-        "foo@bar.com" >>resource
-        16 >>bits
-    mint* check-stamp ] unit-test
+    <hashcash> "foo@bar.com" >>resource 16 >>bits
+    mint* valid-stamp?
+] unit-test
 
 { t } [
-    "1:20:040927:mertz@gnosis.cx::odVZhQMP:7ca28" check-stamp
+    [ 9999 expiry-days set
+      "1:20:220403:foo@bar.com::fAY*-p!s:23472" valid-stamp?
+    ] with-scope
 ] unit-test
 
-{ 8 } [ 8 salt length ] unit-test
+{ f } [
+    [ -1 expiry-days set
+      now-gmt-yymmdd valid-date?
+    ] with-scope
+] unit-test
+
+{ t } [
+    [ 0 expiry-days set
+      now-gmt-yymmdd valid-date?
+    ] with-scope
+] unit-test
+
+{ t } [ now-gmt-yymmdd valid-date? ] unit-test
+
+{  30 } [ "220131" "220101" yymmdd-gmt-diff ] unit-test
+{ -30 } [ "220101" "220131" yymmdd-gmt-diff ] unit-test
+
+{ t } [ now-gmt 1 days time- timestamp>yymmdd on-or-before-today? nip ] unit-test
+{ t } [ now-gmt timestamp>yymmdd on-or-before-today? nip ] unit-test
+{ f } [ now-gmt 1 days time+ timestamp>yymmdd on-or-before-today? nip ] unit-test