Passed
Push — master ( 2d3b7c...d344a1 )
by Russell
13:57
created

ChainpointProofTest::testGetHashIdNode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
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