|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Bip70\Test\Protobuf\Proto; |
|
6
|
|
|
|
|
7
|
|
|
use Bip70\Protobuf\Proto\Output; |
|
8
|
|
|
use Bip70\Protobuf\Proto\Payment; |
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
|
|
11
|
|
|
class PaymentTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
public function testRefundTo() |
|
14
|
|
|
{ |
|
15
|
|
|
$output = new Output(); |
|
16
|
|
|
$output->setAmount(123123); |
|
17
|
|
|
$output->setScript(hex2bin("76a914536ffa992491508dca0354e52f32a3a7a679a53a88ac")); |
|
18
|
|
|
|
|
19
|
|
|
$payment = new Payment(); |
|
20
|
|
|
|
|
21
|
|
|
$this->assertFalse($payment->hasRefundTo()); |
|
22
|
|
|
$payment->setRefundTo($output, 0); |
|
23
|
|
|
$this->assertTrue($payment->hasRefundTo()); |
|
24
|
|
|
|
|
25
|
|
|
$serialized = $payment->serialize(); |
|
26
|
|
|
$p1 = new Payment(); |
|
27
|
|
|
$p1->parse($serialized); |
|
28
|
|
|
|
|
29
|
|
|
$this->assertEquals(1, count($p1->getRefundToList())); |
|
30
|
|
|
$this->assertEquals($output->getAmount(), $p1->getRefundTo(0)->getAmount()); |
|
31
|
|
|
$this->assertEquals($output->getScript(), $p1->getRefundTo(0)->getScript()); |
|
32
|
|
|
|
|
33
|
|
|
$payment->clearRefundTo(); |
|
34
|
|
|
$this->assertEquals(0, count($payment->getRefundToList())); |
|
35
|
|
|
|
|
36
|
|
|
$payment->addRefundTo($output); |
|
37
|
|
|
$this->assertTrue($payment->hasRefundTo()); |
|
38
|
|
|
|
|
39
|
|
|
$this->assertEquals(1, count($p1->getRefundToList())); |
|
40
|
|
|
$this->assertEquals($output->getAmount(), $p1->getRefundTo(0)->getAmount()); |
|
41
|
|
|
$this->assertEquals($output->getScript(), $p1->getRefundTo(0)->getScript()); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testTransactions() |
|
45
|
|
|
{ |
|
46
|
|
|
$tx1 = hex2bin("02000000019c2e2676241c5291f627efb7730039d60c77211e170590490282329db50a0901010000006b483045022100a839e79124f24795a7d73c655e104ad086dfa5939c39e8e5dc4a2a199eb8587d02204f5349dde69d51a858db163c8dc5ec45ddc5f8ff1e61cd1b96c153c08bc15c3201210350f333bee5c1effa176f5af10ab543ff24c61154f4a187dc65b7fc448fefa4ebffffffff021af25400000000001976a914b64124373f1406cf641330b7f7fd193f73a212c088acc5243003000000001976a9148cb1c9b6ae120fab9785cb17cff15d6c79651a0588ac00000000"); |
|
47
|
|
|
$tx2 = hex2bin("02000000000101afe1370451607754c99ed336dd1590f92ab901598036f490c47029ebb3214fdb0000000017160014f893cb68bf16d5dbd9cf7d4c9d5b020030b32697feffffff02117fa3000000000017a914245f980e8c56ba2104090b0fb4aece1ebe7b0f378776dd1900000000001976a9144511abad64398e34b0f8abf003112d69d45c40d088ac02473044022039ec1b761f926a9d850928c651a248f79189ae4d706057e90678ec5dc5b62455022063e64eb6be0236c217ca59df22dd89503af7fcc14a180630550aa7c3e8d6b9f0012103b4197036263319d0d61f7e208345277e94392078560084aeb92de90baf86c34e00000000"); |
|
48
|
|
|
$payment = new Payment(); |
|
49
|
|
|
$this->assertFalse($payment->hasTransactions()); |
|
50
|
|
|
$payment->setTransactions($tx1, 0); |
|
51
|
|
|
$this->assertTrue($payment->hasTransactions()); |
|
52
|
|
|
|
|
53
|
|
|
$serialized = $payment->serialize(); |
|
54
|
|
|
$p1 = new Payment(); |
|
55
|
|
|
$p1->parse($serialized); |
|
56
|
|
|
|
|
57
|
|
|
$this->assertEquals(1, count($p1->getTransactionsList())); |
|
58
|
|
|
$this->assertEquals($tx1, $p1->getTransactions(0)); |
|
59
|
|
|
|
|
60
|
|
|
$payment->setTransactions($tx2, 1); |
|
61
|
|
|
|
|
62
|
|
|
$serialized = $payment->serialize(); |
|
63
|
|
|
$p1 = new Payment(); |
|
64
|
|
|
$p1->parse($serialized); |
|
65
|
|
|
|
|
66
|
|
|
$this->assertEquals(2, count($p1->getTransactionsList())); |
|
67
|
|
|
$this->assertEquals($tx1, $p1->getTransactions(0)); |
|
68
|
|
|
$this->assertEquals($tx2, $p1->getTransactions(1)); |
|
69
|
|
|
|
|
70
|
|
|
$payment->clearTransactions(); |
|
71
|
|
|
$this->assertFalse($payment->hasTransactions()); |
|
72
|
|
|
|
|
73
|
|
|
$payment->addTransactions($tx1); |
|
74
|
|
|
$payment->addTransactions($tx2); |
|
75
|
|
|
|
|
76
|
|
|
$this->assertEquals($tx1, $p1->getTransactions(0)); |
|
77
|
|
|
$this->assertEquals($tx2, $p1->getTransactions(1)); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function testMerchantData() |
|
81
|
|
|
{ |
|
82
|
|
|
$blob = json_encode([ |
|
83
|
|
|
"some_merchant" => "abcd1234", |
|
84
|
|
|
"invoice" => "1234abcd" |
|
85
|
|
|
]); |
|
86
|
|
|
|
|
87
|
|
|
$payment = new Payment(); |
|
88
|
|
|
|
|
89
|
|
|
$this->assertFalse($payment->hasMerchantData()); |
|
90
|
|
|
$payment->setMerchantData($blob); |
|
91
|
|
|
$this->assertTrue($payment->hasMerchantData()); |
|
92
|
|
|
|
|
93
|
|
|
$serialized = $payment->serialize(); |
|
94
|
|
|
$p1 = new Payment(); |
|
95
|
|
|
$p1->parse($serialized); |
|
96
|
|
|
|
|
97
|
|
|
$this->assertEquals($blob, $p1->getMerchantData()); |
|
98
|
|
|
|
|
99
|
|
|
$p1->clearMerchantData(); |
|
100
|
|
|
$this->assertFalse($p1->hasMerchantData()); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function testMemo() |
|
104
|
|
|
{ |
|
105
|
|
|
$blob = "So long, and thanks for all the pizza!"; |
|
106
|
|
|
|
|
107
|
|
|
$payment = new Payment(); |
|
108
|
|
|
|
|
109
|
|
|
$this->assertFalse($payment->hasMemo()); |
|
110
|
|
|
$payment->setMemo($blob); |
|
111
|
|
|
$this->assertTrue($payment->hasMemo()); |
|
112
|
|
|
|
|
113
|
|
|
$serialized = $payment->serialize(); |
|
114
|
|
|
$p1 = new Payment(); |
|
115
|
|
|
$p1->parse($serialized); |
|
116
|
|
|
|
|
117
|
|
|
$this->assertEquals($blob, $p1->getMemo()); |
|
118
|
|
|
|
|
119
|
|
|
$p1->clearMemo(); |
|
120
|
|
|
$this->assertFalse($p1->hasMemo()); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|