-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathMessageTest.php
More file actions
90 lines (62 loc) · 2.86 KB
/
MessageTest.php
File metadata and controls
90 lines (62 loc) · 2.86 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
<?php
declare(strict_types=1);
use ArkEcosystem\Crypto\Utils\Message;
test('it should sign a valid message', function () {
$fixture = $this->getFixture('message-sign');
$message = Message::sign($fixture['message'], $this->passphrase);
expect($message->publicKey)->toBe($fixture['publicKey']);
expect($message->signature)->toBe(substr($fixture['signature'], 2));
expect($message->message)->toBe($fixture['message']);
});
test('it should create a message from an object', function () {
$fixture = json_decode(json_encode($this->getFixture('message-sign')));
$message = Message::new($fixture);
expect($message->publicKey)->toBe($fixture->publicKey);
expect($message->signature)->toBe($fixture->signature);
expect($message->message)->toBe($fixture->message);
});
test('it should create a message from an array', function () {
$fixture = $this->getFixture('message-sign');
$message = Message::new($fixture);
expect($message->publicKey)->toBe($fixture['publicKey']);
expect($message->signature)->toBe($fixture['signature']);
expect($message->message)->toBe($fixture['message']);
});
test('it should throw if no public key is provided', function () {
$fixture = $this->getFixture('message-sign');
unset($fixture['publicKey']);
Message::new($fixture);
})->throws(InvalidArgumentException::class, 'The given message did not contain a valid public key.');
test('it should create a message from a string', function () {
$fixture = $this->getFixture('message-sign');
$message = Message::new(json_encode($fixture));
expect($message->publicKey)->toBe($fixture['publicKey']);
expect($message->signature)->toBe($fixture['signature']);
expect($message->message)->toBe($fixture['message']);
});
test('it should not create a message from an invalid Type', function () {
expect(fn () => Message::new(false))
->toThrow(InvalidArgumentException::class);
});
test('it should sign a message', function () {
$message = Message::sign('Hello World', 'passphrase');
expect($message)->toBeInstanceOf(Message::class);
});
test('it should verify a message', function () {
$fixture = $this->getFixture('message-sign');
$fixture['signature'] = substr($fixture['signature'], 2);
$message = Message::new($fixture);
expect($message->verify())->toBeTrue();
});
test('it should turn a message into an array', function () {
$message = Message::new($this->getFixture('message-sign'));
expect($message->toArray())->toBeArray();
});
test('it should turn a message into json', function () {
$message = Message::new($this->getFixture('message-sign'));
expect($message->toJSON())->toBeString();
});
test('it should turn a message into a string', function () {
$message = Message::new($this->getFixture('message-sign'));
expect((string) $message)->toBeString();
});