|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @author Russell Michell 2018 <[email protected]> |
|
5
|
|
|
* @package silverstripe-verifiable |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace PhpTek\Verifiable\Test; |
|
9
|
|
|
|
|
10
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
11
|
|
|
use PhpTek\Verifiable\ORM\FieldType\ChainpointProof; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* |
|
15
|
|
|
*/ |
|
16
|
|
|
class ChainpointProofTest extends SapphireTest |
|
17
|
|
|
{ |
|
18
|
|
|
|
|
19
|
|
|
public function testGetHashIdNode() |
|
20
|
|
|
{ |
|
21
|
|
|
// Valid JSON proof |
|
22
|
|
|
$proofValid = file_get_contents(realpath(__DIR__) . '/../fixture/proof-valid.json'); |
|
23
|
|
|
$proofField = ChainpointProof::create()->setValue($proofValid); |
|
24
|
|
|
|
|
25
|
|
|
$this->assertEquals('bd469a90-7922-11e8-91f0-01201f800553', $proofField->getHashIdNode()); |
|
26
|
|
|
|
|
27
|
|
|
// Invalid: Missing hash_id_node |
|
28
|
|
|
$proofInValid = file_get_contents(realpath(__DIR__) . '/../fixture/proof-invalid-no-hashid.json'); |
|
29
|
|
|
$proofField = ChainpointProof::create()->setValue($proofInValid); |
|
30
|
|
|
|
|
31
|
|
|
$this->assertEquals('', $proofField->getHashIdNode()); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testGetHash() |
|
35
|
|
|
{ |
|
36
|
|
|
// Valid JSON proof |
|
37
|
|
|
$proofValid = file_get_contents(realpath(__DIR__) . '/../fixture/proof-valid.json'); |
|
38
|
|
|
$proofField = ChainpointProof::create()->setValue($proofValid); |
|
39
|
|
|
|
|
40
|
|
|
$this->assertEquals('611d8759d9de000cd7fd4abef8d95ee9f2571bc8b953f8efbba21b110e1bbf0e', $proofField->getHash()); |
|
41
|
|
|
|
|
42
|
|
|
// Invalid: Missing hash |
|
43
|
|
|
$proofInValid = file_get_contents(realpath(__DIR__) . '/../fixture/proof-invalid-no-hash.json'); |
|
44
|
|
|
$proofField = ChainpointProof::create()->setValue($proofInValid); |
|
45
|
|
|
|
|
46
|
|
|
$this->assertEquals('', $proofField->getHash()); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testMatch() |
|
50
|
|
|
{ |
|
51
|
|
|
// Valid JSON proof |
|
52
|
|
|
$proofValid = file_get_contents(realpath(__DIR__) . '/../fixture/proof-valid.json'); |
|
53
|
|
|
$proofField = ChainpointProof::create()->setValue($proofValid); |
|
54
|
|
|
|
|
55
|
|
|
$this->assertTrue($proofField->match('611d8759d9de000cd7fd4abef8d95ee9f2571bc8b953f8efbba21b110e1bbf0e')); |
|
56
|
|
|
|
|
57
|
|
|
// Invalid: Mismatched hash passed |
|
58
|
|
|
$proofValid = file_get_contents(realpath(__DIR__) . '/../fixture/proof-valid.json'); |
|
59
|
|
|
$proofField = ChainpointProof::create()->setValue($proofValid); |
|
60
|
|
|
|
|
61
|
|
|
$this->assertFalse($proofField->match('61d8759d9de000cd7fd4abef8d95ee9f2571bc8b953f8efbba21b110e1bbf0e')); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|