ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Digest-Hashcash/t/00_load.t
Revision: 1.3
Committed: Wed Jul 22 12:09:48 2015 UTC (11 years, 2 months ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +2 -2 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 BEGIN { $| = 1; print "1..174\n"; }
2 END {print "not ok 1\n" unless $loaded;}
3 use Digest::Hashcash;
4 $loaded = 1;
5 print "ok 1\n";
6
7 $c = new Digest::Hashcash
8 size => 16,
9 uid => "pcg\@goof.com";
10
11 $token = $c->hash ("proprietary\@is.evil");
12
13 print $token =~ /pcg\@goof.com/ ? "ok 2\n" : "not ok 2\n";
14 print $token =~ /proprietary\@is.evil/ ? "ok 3\n" : "not ok 3\n";
15 print $c->verify ($token) ? "ok 4\n" : "not ok 4\n";
16
17 print $c->resource ($token) eq "proprietary\@is.evil" ? "ok 5\n" : "not ok 5\n";
18
19 $t = $c->timestamp ($token);
20
21 print $t <= time ? "ok 6\n" : "not ok 6\n";
22 print $t > time - 3600 ? "ok 7\n" : "not ok 7\n";
23
24 $m = Digest::Hashcash::estimate_time 30;
25 print $m > 2 ? "ok 8\n" : "not ok 8 # $m\n";
26 $m = Digest::Hashcash::estimate_size $m, 29;
27 print $m == 30 ? "ok 9\n" : "not ok 9 # $m\n";
28
29 print $c->verify ("0:020814:foo:4333957e84db47f6") == 33 ? "ok 10\n" : "not ok 10\n";
30 print $c->verify ("0:030907:taz:663c4027c724de49") == 16 ? "ok 11\n" : "not ok 11\n";
31 print $c->verify ("0:030907:taz:3e0374e8cb3d95a7") == 20 ? "ok 12\n" : "not ok 12\n";
32 print $c->verify ("0:030907:tazhashcashhashcashhashcashhashcashhashcashhashcashhashcashhashcashhashcashhashcashhashcashhashcashhashcash:89e748cf94ef1871") == 20 ? "ok 13\n" : "not ok 13\n";
33
34 $c = new Digest::Hashcash size => 50;
35 $t = 14;
36
37 for (0 .. 160) {
38 my $token = $c->hash ("x" x $_, extrarand => $_ / 4, size => 10);
39 $c->verify ($token, size => 10) or print "not ";
40 print "ok $t\n";
41 $t++;
42 }