From a18f35ab86f5667ab528fcda46342c561ca9d9e7 Mon Sep 17 00:00:00 2001 From: Alfonso Bribiesca Date: Wed, 11 Mar 2026 11:41:45 -0600 Subject: [PATCH] refactor: use query array for endpoint params --- src/API/Node.php | 6 +++--- src/API/Transactions.php | 6 ++++-- src/API/Wallets.php | 6 ++++-- tests/API/NodeTest.php | 6 ++++++ tests/API/TransactionsTest.php | 11 +++++++++++ tests/API/WalletsTest.php | 36 ++++++++++++++++++++++++++++++++++ 6 files changed, 64 insertions(+), 7 deletions(-) diff --git a/src/API/Node.php b/src/API/Node.php index 05dd9db..b8d3caf 100644 --- a/src/API/Node.php +++ b/src/API/Node.php @@ -49,12 +49,12 @@ public function crypto(): ?array /** * Get the node fee statistics. * - * @param int|null $days + * @param array $query * * @return array */ - public function fees(?int $days = null): ?array + public function fees(array $query = []): ?array { - return $this->requestGet('node/fees', ['days' => $days]); + return $this->requestGet('node/fees', $query); } } diff --git a/src/API/Transactions.php b/src/API/Transactions.php index a4d4038..8487ed5 100644 --- a/src/API/Transactions.php +++ b/src/API/Transactions.php @@ -45,11 +45,13 @@ public function get(string $id): ?array /** * Get all unconfirmed transactions. * + * @param array $query + * * @return array */ - public function allUnconfirmed(): ?array + public function allUnconfirmed(array $query = []): ?array { - return $this->withApi('transactions')->requestGet('transactions/unconfirmed'); + return $this->withApi('transactions')->requestGet('transactions/unconfirmed', $query); } /** diff --git a/src/API/Wallets.php b/src/API/Wallets.php index ab2d3dd..d18df0f 100644 --- a/src/API/Wallets.php +++ b/src/API/Wallets.php @@ -85,11 +85,13 @@ public function votes(string $id, array $query = []): ?array /** * Get all wallets sorted by balance in descending order. * + * @param array $query + * * @return array */ - public function top(): ?array + public function top(array $query = []): ?array { - return $this->requestGet('wallets/top'); + return $this->requestGet('wallets/top', $query); } /** diff --git a/tests/API/NodeTest.php b/tests/API/NodeTest.php index cc06608..784b162 100644 --- a/tests/API/NodeTest.php +++ b/tests/API/NodeTest.php @@ -35,3 +35,9 @@ return $client->node()->fees(); }); }); + +it('calls the correct url for fees with query', function () { + $this->assertResponse('GET', 'node/fees?days=7', function (ArkClient $client) { + return $client->node()->fees(['days' => 7]); + }); +}); diff --git a/tests/API/TransactionsTest.php b/tests/API/TransactionsTest.php index 761c25e..a78e84b 100644 --- a/tests/API/TransactionsTest.php +++ b/tests/API/TransactionsTest.php @@ -40,6 +40,17 @@ ); }); +it('calls correct url for all unconfirmed with query', function () { + $this->assertResponse( + method: 'GET', + path: 'transactions/unconfirmed?limit=50', + callback: function (ArkClient $client) { + return $client->transactions()->allUnconfirmed(['limit' => 50]); + }, + expectedApi: 'transactions' + ); +}); + it('calls correct url for get unconfirmed', function () { $this->assertResponse( method: 'GET', diff --git a/tests/API/WalletsTest.php b/tests/API/WalletsTest.php index bbd8849..c7dd567 100644 --- a/tests/API/WalletsTest.php +++ b/tests/API/WalletsTest.php @@ -18,6 +18,12 @@ }); }); +it('calls correct url for top with query', function () { + $this->assertResponse('GET', 'wallets/top?limit=10', function (ArkClient $client) { + return $client->wallets()->top(['limit' => 10]); + }); +}); + it('calls correct url for get', function () { $this->assertResponse('GET', 'wallets/dummy', function (ArkClient $client) { return $client->wallets()->get('dummy'); @@ -75,3 +81,33 @@ ]); }); }); + +it('calls correct url for a wallet tokens with whitelist', function () { + $this->assertResponse( + 'POST', + 'wallets/dummy/tokens', + function (ArkClient $client) { + return $client->wallets()->tokensFor('dummy', [ + 'whitelist' => ['0x1234567890abcdef1234567890abcdef12345678'], + ]); + }, + expectedRequestBody: [ + 'whitelist' => ['0x1234567890abcdef1234567890abcdef12345678'], + ] + ); +}); + +it('calls correct url for all wallet tokens with whitelist', function () { + $this->assertResponse( + 'POST', + 'wallets/tokens', + function (ArkClient $client) { + return $client->wallets()->tokens([ + 'whitelist' => ['0x1234567890abcdef1234567890abcdef12345678'], + ]); + }, + expectedRequestBody: [ + 'whitelist' => ['0x1234567890abcdef1234567890abcdef12345678'], + ] + ); +});