Skip to content

Commit 6f6f31a

Browse files
committed
wallet endpoints
1 parent a2bc09e commit 6f6f31a

3 files changed

Lines changed: 61 additions & 4 deletions

File tree

‎src/API/Wallets.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ public function top(): ?array
102102
*/
103103
public function tokensFor(string $id, array $query = []): ?array
104104
{
105+
if (isset($query['whitelist'])) {
106+
return $this->requestPost("wallets/{$id}/tokens", $query);
107+
}
108+
105109
return $this->requestGet("wallets/{$id}/tokens", $query);
106110
}
107111

@@ -114,6 +118,10 @@ public function tokensFor(string $id, array $query = []): ?array
114118
*/
115119
public function tokens(array $query = []): ?array
116120
{
121+
if (isset($query['whitelist'])) {
122+
return $this->requestPost("wallets/tokens", $query);
123+
}
124+
117125
return $this->requestGet('wallets/tokens', $query);
118126
}
119127
}

‎tests/API/TokensTest.php‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,46 @@
1313
});
1414

1515
it('calls correct url for all with whitelist', function () {
16-
$this->assertResponse('POST', 'tokens', function (ArkClient $client) {
17-
return $client->tokens()->all([
16+
$this->assertResponse(
17+
'POST',
18+
'tokens',
19+
function (ArkClient $client) {
20+
return $client->tokens()->all([
21+
'whitelist' => ['0x1234567890abcdef1234567890abcdef12345678'],
22+
]);
23+
},
24+
expectedRequestBody: [
1825
'whitelist' => ['0x1234567890abcdef1234567890abcdef12345678'],
26+
]
27+
);
28+
});
29+
30+
it('sends all whitelist values in the request body', function () {
31+
$this->assertResponse(
32+
'POST',
33+
'tokens',
34+
function (ArkClient $client) {
35+
return $client->tokens()->all([
36+
'whitelist' => [
37+
'0x1234567890abcdef1234567890abcdef12345678',
38+
'0xabcdef1234567890abcdef1234567890abcdef12',
39+
],
40+
]);
41+
},
42+
expectedRequestBody: [
43+
'whitelist' => [
44+
'0x1234567890abcdef1234567890abcdef12345678',
45+
'0xabcdef1234567890abcdef1234567890abcdef12',
46+
],
47+
]
48+
);
49+
});
50+
51+
it('calls correct url for whitelist with query', function () {
52+
$this->assertResponse('GET', 'tokens/whitelist?page=2&limit=10', function (ArkClient $client) {
53+
return $client->tokens()->whitelist([
54+
'page' => 2,
55+
'limit' => 10,
1956
]);
2057
});
2158
});

‎tests/TestCase.php‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,15 @@ abstract class TestCase extends BaseTestCase
2828
* @param callable $callback
2929
* @param array|null $expectedBody
3030
*/
31-
protected function assertResponse(string $method, string $path, callable $callback, array $expectedBody = [], string $expectedApi = 'api', array $response = []): void
31+
protected function assertResponse(
32+
string $method,
33+
string $path,
34+
callable $callback,
35+
array $expectedBody = [],
36+
string $expectedApi = 'api',
37+
array $response = [],
38+
?array $expectedRequestBody = null
39+
): void
3240
{
3341
$hosts = [
3442
'api' => 'https://dwallets-evm.mainsailhq.com/api',
@@ -37,10 +45,14 @@ protected function assertResponse(string $method, string $path, callable $callba
3745
];
3846

3947
$mockHandler = new MockHandler([
40-
function (Request $request) use ($method, $path, $response, $hosts, $expectedApi) {
48+
function (Request $request) use ($method, $path, $response, $hosts, $expectedApi, $expectedRequestBody) {
4149
$this->assertSame($method, $request->getMethod());
4250
$this->assertSame($hosts[$expectedApi].'/'.$path, $request->getUri()->__toString());
4351

52+
if ($expectedRequestBody !== null) {
53+
$this->assertSame($expectedRequestBody, json_decode($request->getBody()->getContents(), true));
54+
}
55+
4456
return new Response(200, [], json_encode($response));
4557
},
4658
]);

0 commit comments

Comments
 (0)