Skip to content

Commit 3bfcec3

Browse files
committed
tests: add Other tests
1 parent 0c87018 commit 3bfcec3

3 files changed

Lines changed: 71 additions & 13 deletions

File tree

src/Api/Other.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66

77
class Other extends AbstractApi
88
{
9-
public function base58(string $data): array
9+
public function base58(string $data): string
1010
{
1111
return $this->get(self::API_PATH, [
1212
'q' => 'base58',
1313
'data' => $data,
1414
]);
1515
}
1616

17-
public function randomNumber(int $height, int $minimum, int $maximum, ?string $seed = null): array
17+
public function randomNumber(int $height, int $minimum, int $maximum, ?string $seed = null): int
1818
{
19-
return $this->get(self::API_PATH, [
19+
return (int) $this->get(self::API_PATH, [
2020
'q' => 'randomNumber',
2121
'height' => $height,
2222
'min' => $minimum,
@@ -25,13 +25,13 @@ public function randomNumber(int $height, int $minimum, int $maximum, ?string $s
2525
]);
2626
}
2727

28-
public function checkSignature(string $signature, string $data, string $publicKey): array
28+
public function checkSignature(string $signature, string $data, string $publicKey): bool
2929
{
30-
return $this->get(self::API_PATH, [
30+
return ((string) $this->get(self::API_PATH, [
3131
'q' => 'checkSignature',
3232
'signature' => $signature,
3333
'data' => $data,
3434
'public_key' => $publicKey,
35-
]);
35+
])) === 'true';
3636
}
3737
}

tests/Api/NodeTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@
9292
'hash' => 'c7d66b357c05d0908623a09afd387dd3',
9393
'masternodes' => [
9494
[
95-
'public_key' => "PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCvNFCyZbpNpLVwg4Sk8Pe46dyKrqR4GacBGtaeJ9CAXQTc41jYrW2gy91XUkBgMkkAjqsojSVMJ1iasdbcmFdx7wy",
95+
'public_key' => 'PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCvNFCyZbpNpLVwg4Sk8Pe46dyKrqR4GacBGtaeJ9CAXQTc41jYrW2gy91XUkBgMkkAjqsojSVMJ1iasdbcmFdx7wy',
9696
'height' => 104148,
97-
'ip' => "35.237.72.244",
97+
'ip' => '35.237.72.244',
9898
'last_won' => 137074,
9999
'blacklist' => 0,
100100
'fails' => 0,
@@ -113,9 +113,9 @@
113113
'hash' => 'c7d66b357c05d0908623a09afd387dd3',
114114
'masternodes' => [
115115
[
116-
'public_key' => "PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCvNFCyZbpNpLVwg4Sk8Pe46dyKrqR4GacBGtaeJ9CAXQTc41jYrW2gy91XUkBgMkkAjqsojSVMJ1iasdbcmFdx7wy",
116+
'public_key' => 'PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCvNFCyZbpNpLVwg4Sk8Pe46dyKrqR4GacBGtaeJ9CAXQTc41jYrW2gy91XUkBgMkkAjqsojSVMJ1iasdbcmFdx7wy',
117117
'height' => 104148,
118-
'ip' => "35.237.72.244",
118+
'ip' => '35.237.72.244',
119119
'last_won' => 137074,
120120
'blacklist' => 0,
121121
'fails' => 0,

tests/Api/OtherTest.php

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,66 @@
66

77
beforeEach(fn () => $this->apiClass = Other::class);
88

9-
it('can get a random number');
9+
it('can get a random number', function () {
10+
$api = $this->getApiMock();
1011

11-
it('can get the Base58 encoded version of a string');
12+
$api->expects($this->once())
13+
->method('get')
14+
->with('/api.php', [
15+
'q' => 'randomNumber',
16+
'height' => 100000,
17+
'min' => 10,
18+
'max' => 20,
19+
'seed' => null,
20+
])
21+
->willReturn('20');
1222

13-
it('can check a signature is valid');
23+
/** @var Other $api */
24+
expect(
25+
$api->randomNumber(
26+
height: 100000,
27+
minimum: 10,
28+
maximum: 20
29+
)
30+
)->toBe(20);
31+
});
32+
33+
it('can get the Base58 encoded version of a string', function () {
34+
$api = $this->getApiMock();
35+
36+
$api->expects($this->once())
37+
->method('get')
38+
->with('/api.php', [
39+
'q' => 'base58',
40+
'data' => 'Test',
41+
])
42+
->willReturn('3A836b');
43+
44+
/** @var Other $api */
45+
expect(
46+
$api->base58('Test')
47+
)->toBe('3A836b');
48+
});
49+
50+
it('can check a signature is valid', function () {
51+
$api = $this->getApiMock();
52+
53+
$api->expects($this->once())
54+
->method('get')
55+
->with('/api.php', [
56+
'q' => 'checkSignature',
57+
'signature' => 'AN1rKroKawax5azYrLbasV7VycYAvQXFKrJ69TFYEfmanXwVRrUQTCx5gQ1eVNMgEVzrEz3VzLsfrVVpUYqgB5eT2qsFtaSsw',
58+
'data' => '1.00000000-0.00250000-PXGAMER--2-PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCyk7aKeBJ6LL44w5JGSFp82Wb1Drqicuznv1qmRVQMvbmF64AeczjMtV72acGLR9RsiQ2JccemNrSPkKi8KDk72t4-1533911370',
59+
'public_key' => 'PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCyk7aKeBJ6LL44w5JGSFp82Wb1Drqicuznv1qmRVQMvbmF64AeczjMtV72acGLR9RsiQ2JccemNrSPkKi8KDk72t4',
60+
])
61+
->willReturn('true');
62+
63+
/** @var Other $api */
64+
expect(
65+
$api->checkSignature(
66+
signature: 'AN1rKroKawax5azYrLbasV7VycYAvQXFKrJ69TFYEfmanXwVRrUQTCx5gQ1eVNMgEVzrEz3VzLsfrVVpUYqgB5eT2qsFtaSsw',
67+
data: '1.00000000-0.00250000-PXGAMER--2-PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCyk7aKeBJ6LL44w5JGSFp82Wb1Drqicuznv1qmRVQMvbmF64AeczjMtV72acGLR9RsiQ2JccemNrSPkKi8KDk72t4-1533911370',
68+
publicKey: 'PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCyk7aKeBJ6LL44w5JGSFp82Wb1Drqicuznv1qmRVQMvbmF64AeczjMtV72acGLR9RsiQ2JccemNrSPkKi8KDk72t4',
69+
)
70+
)->toBe(true);
71+
});

0 commit comments

Comments
 (0)