-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathDeserializerTest.php
More file actions
133 lines (95 loc) · 5.06 KB
/
DeserializerTest.php
File metadata and controls
133 lines (95 loc) · 5.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
declare(strict_types=1);
use ArkEcosystem\Crypto\Transactions\Deserializer;
use ArkEcosystem\Crypto\Transactions\Types\EvmCall;
use ArkEcosystem\Crypto\Transactions\Types\Multipayment;
use ArkEcosystem\Crypto\Transactions\Types\Transfer;
use ArkEcosystem\Crypto\Transactions\Types\Unvote;
use ArkEcosystem\Crypto\Transactions\Types\UsernameRegistration;
use ArkEcosystem\Crypto\Transactions\Types\UsernameResignation;
use ArkEcosystem\Crypto\Transactions\Types\ValidatorRegistration;
use ArkEcosystem\Crypto\Transactions\Types\ValidatorResignation;
use ArkEcosystem\Crypto\Transactions\Types\Vote;
/*
* @covers \ArkEcosystem\Crypto\Transactions\Deserializer
*/
it('should deserialize a transfer signed with a passphrase', function () {
$fixture = $this->getTransactionFixture('evm_call', 'transfer');
$transaction = $this->assertTransaction($fixture);
expect($transaction)->toBeInstanceOf(Transfer::class);
});
it('should deserialize a transfer signed with a passphrase with 0 value', function () {
$fixture = $this->getTransactionFixture('evm_call', 'transfer-0');
$transaction = $this->assertTransaction($fixture);
expect($transaction)->toBeInstanceOf(EvmCall::class);
});
it('should deserialize a vote signed with a passphrase', function () {
$fixture = $this->getTransactionFixture('evm_call', 'vote');
$transaction = $this->assertTransaction($fixture);
expect($transaction->data['vote'])->toEqual('0xC3bBE9B1CeE1ff85Ad72b87414B0E9B7F2366763');
expect($transaction->data['hash'])->toEqual($fixture['data']['hash']);
expect($transaction)->toBeInstanceOf(Vote::class);
});
it('should deserialize a unvote signed with a passphrase', function () {
$fixture = $this->getTransactionFixture('evm_call', 'unvote');
$transaction = $this->assertTransaction($fixture);
expect($transaction)->toBeInstanceOf(Unvote::class);
});
it('should deserialize a validator registration signed with a passphrase', function () {
$fixture = $this->getTransactionFixture('evm_call', 'validator-registration');
$transaction = $this->assertTransaction($fixture);
expect($transaction)->toBeInstanceOf(ValidatorRegistration::class);
});
it('should deserialize a validator resignation signed with a passphrase', function () {
$fixture = $this->getTransactionFixture('evm_call', 'validator-resignation');
$transaction = $this->assertTransaction($fixture);
expect($transaction)->toBeInstanceOf(ValidatorResignation::class);
});
it('should deserialize a username registration signed with a passphrase', function () {
$fixture = $this->getTransactionFixture('evm_call', 'username-registration');
$transaction = $this->assertTransaction($fixture);
expect($transaction)->toBeInstanceOf(UsernameRegistration::class);
});
it('should deserialize a username resignation signed with a passphrase', function () {
$fixture = $this->getTransactionFixture('evm_call', 'username-resignation');
$transaction = $this->assertTransaction($fixture);
expect($transaction)->toBeInstanceOf(UsernameResignation::class);
});
it('should deserialize a multipayment signed with a passphrase', function () {
$fixture = $this->getTransactionFixture('evm_call', 'multipayment');
$transaction = $this->assertTransaction($fixture);
expect($transaction)->toBeInstanceOf(Multipayment::class);
});
it('should use ByteBuffer::fromHex when there is no null-byte in the string', function () {
// The string does not contain a null-byte
$hexString = 'abcdef1234567890';
$deserializer = new Deserializer($hexString);
// Use reflection to access the private buffer property
$reflection = new ReflectionClass($deserializer);
$bufferProperty = $reflection->getProperty('buffer');
$bufferProperty->setAccessible(true);
$buffer = $bufferProperty->getValue($deserializer);
// The buffer should be an instance of ByteBuffer
expect($buffer)->toBeInstanceOf(ArkEcosystem\Crypto\ByteBuffer\ByteBuffer::class);
// The buffer should contain the hex string (converted to binary)
expect($buffer->toString('hex'))->toContain($hexString);
});
it('should use ByteBuffer::fromBinary when there is a null-byte in the string', function () {
// The string contains a null-byte
$binaryString = "abc\0def"; // hex: 61626300646566
$hexString = '61626300646566';
$deserializer = new Deserializer($binaryString);
// Use reflection to access the private buffer property
$reflection = new ReflectionClass($deserializer);
$bufferProperty = $reflection->getProperty('buffer');
$bufferProperty->setAccessible(true);
$buffer = $bufferProperty->getValue($deserializer);
// The buffer should be an instance of ByteBuffer
expect($buffer)->toBeInstanceOf(ArkEcosystem\Crypto\ByteBuffer\ByteBuffer::class);
// The buffer should contain the binary string
expect($buffer->toString('hex'))->toBe($hexString);
});
it('should return null if no data value in transaction data', function () {
expect(Deserializer::decodePayload([]))->toBeNull();
expect(Deserializer::decodePayload(['data' => '']))->toBeNull();
});