Skip to content

Commit 78272ba

Browse files
committed
test: add Asset tests
1 parent 580546e commit 78272ba

File tree

6 files changed

+155
-14
lines changed

6 files changed

+155
-14
lines changed

src/Api/Asset.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public function show(string $id): array
2121
]);
2222
}
2323

24-
public function balance(string $address): array
24+
public function balance(string $address): float
2525
{
26-
return $this->get(self::API_PATH, [
26+
return (float) $this->get(self::API_PATH, [
2727
'q' => 'assetBalance',
2828
'account' => $address,
2929
]);

tests/Api/AssetTest.php

Lines changed: 145 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,151 @@
66

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

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

11-
it('can get a specific asset');
12+
$api->expects($this->once())
13+
->method('get')
14+
->with('/api.php', [
15+
'q' => 'assets',
16+
])
17+
->willReturn([
18+
[
19+
'id' => '26PZgwak3LscM3Mz8bfDBmbETSq9GvXhdom5HwoDMuaMvg9cekKX21hoNtJXixdrvvAwq2BoxKiUdQQnGWym1ZxT',
20+
'max_supply' => 0,
21+
'tradable' => 1,
22+
'price' => '0.00000000',
23+
'dividend_only' => 0,
24+
'auto_dividend' => 0,
25+
'allow_bid' => 1,
26+
'height' => 952581,
27+
'alias' => 'AUSDTHOUSAND',
28+
'balance' => '39.62500000',
29+
]
30+
]);
1231

13-
it('can get the asset balance for an account');
32+
/** @var Asset $api */
33+
expect(
34+
$api->all()
35+
)->toBe([
36+
[
37+
'id' => '26PZgwak3LscM3Mz8bfDBmbETSq9GvXhdom5HwoDMuaMvg9cekKX21hoNtJXixdrvvAwq2BoxKiUdQQnGWym1ZxT',
38+
'max_supply' => 0,
39+
'tradable' => 1,
40+
'price' => '0.00000000',
41+
'dividend_only' => 0,
42+
'auto_dividend' => 0,
43+
'allow_bid' => 1,
44+
'height' => 952581,
45+
'alias' => 'AUSDTHOUSAND',
46+
'balance' => '39.62500000',
47+
]
48+
]);
49+
});
1450

15-
it('can get the asset orders for an address');
51+
it('can get a specific asset', function () {
52+
$api = $this->getApiMock();
53+
54+
$api->expects($this->once())
55+
->method('get')
56+
->with('/api.php', [
57+
'q' => 'assets',
58+
'asset' => '26PZgwak3LscM3Mz8bfDBmbETSq9GvXhdom5HwoDMuaMvg9cekKX21hoNtJXixdrvvAwq2BoxKiUdQQnGWym1ZxT',
59+
])
60+
->willReturn([
61+
[
62+
'id' => '26PZgwak3LscM3Mz8bfDBmbETSq9GvXhdom5HwoDMuaMvg9cekKX21hoNtJXixdrvvAwq2BoxKiUdQQnGWym1ZxT',
63+
'max_supply' => 0,
64+
'tradable' => 1,
65+
'price' => '0.00000000',
66+
'dividend_only' => 0,
67+
'auto_dividend' => 0,
68+
'allow_bid' => 1,
69+
'height' => 952581,
70+
'alias' => 'AUSDTHOUSAND',
71+
'balance' => '39.62500000',
72+
]
73+
]);
74+
75+
/** @var Asset $api */
76+
expect(
77+
$api->show('26PZgwak3LscM3Mz8bfDBmbETSq9GvXhdom5HwoDMuaMvg9cekKX21hoNtJXixdrvvAwq2BoxKiUdQQnGWym1ZxT')
78+
)->toBe([
79+
[
80+
'id' => '26PZgwak3LscM3Mz8bfDBmbETSq9GvXhdom5HwoDMuaMvg9cekKX21hoNtJXixdrvvAwq2BoxKiUdQQnGWym1ZxT',
81+
'max_supply' => 0,
82+
'tradable' => 1,
83+
'price' => '0.00000000',
84+
'dividend_only' => 0,
85+
'auto_dividend' => 0,
86+
'allow_bid' => 1,
87+
'height' => 952581,
88+
'alias' => 'AUSDTHOUSAND',
89+
'balance' => '39.62500000',
90+
]
91+
]);
92+
});
93+
94+
it('can get the asset balance for an account', function () {
95+
$api = $this->getApiMock();
96+
97+
$api->expects($this->once())
98+
->method('get')
99+
->with('/api.php', [
100+
'q' => 'assetBalance',
101+
'account' => '2tR6BWvwpwrQLUWN8GpVP4b6srCxgR2PnrsXs7jYfdeBj3FimJ5Tjd4xzWcWe8y59ZtEBXgQJxe6Uibux1cCDfxL',
102+
])
103+
->willReturn('0');
104+
105+
/** @var Asset $api */
106+
expect(
107+
$api->balance('2tR6BWvwpwrQLUWN8GpVP4b6srCxgR2PnrsXs7jYfdeBj3FimJ5Tjd4xzWcWe8y59ZtEBXgQJxe6Uibux1cCDfxL')
108+
)->toBe(0.0);
109+
});
110+
111+
it('can get the asset orders for an address', function () {
112+
$api = $this->getApiMock();
113+
114+
$api->expects($this->once())
115+
->method('get')
116+
->with('/api.php', [
117+
'q' => 'asset-orders',
118+
'account' => '2tR6BWvwpwrQLUWN8GpVP4b6srCxgR2PnrsXs7jYfdeBj3FimJ5Tjd4xzWcWe8y59ZtEBXgQJxe6Uibux1cCDfxL',
119+
'asset' => '26PZgwak3LscM3Mz8bfDBmbETSq9GvXhdom5HwoDMuaMvg9cekKX21hoNtJXixdrvvAwq2BoxKiUdQQnGWym1ZxT',
120+
])
121+
->willReturn([
122+
[
123+
'id' => '39VSD1tTjSED41254241UJLutnF7Y9fJLFsWUqdtQzAwteGgEyropo8Z8Y1HDdKpAsx8TrpNJWDgFxeeZQZ96x',
124+
'account' => '2tR6BWvwpwrQLUWN8GpVP4b6srCxgR2PnrsXs7jYfdeBj3FimJ5Tjd4xzWcWe8y59ZtEBXgQJxe6Uibux1cCDfxL',
125+
'asset' => '26PZgwak3LscM3Mz8bfDBmbETSq9GvXhdom5HwoDMuaMvg9cekKX21hoNtJXixdrvvAwq2BoxKiUdQQnGWym1ZxT',
126+
'price' => '1.00000000',
127+
'date' => 1615802171,
128+
'status' => 0,
129+
'type' => 'bid',
130+
'val' => 1000,
131+
'val_done' => 0,
132+
'cancelable' => 1,
133+
]
134+
]);
135+
136+
/** @var Asset $api */
137+
expect(
138+
$api->orders(
139+
'2tR6BWvwpwrQLUWN8GpVP4b6srCxgR2PnrsXs7jYfdeBj3FimJ5Tjd4xzWcWe8y59ZtEBXgQJxe6Uibux1cCDfxL',
140+
'26PZgwak3LscM3Mz8bfDBmbETSq9GvXhdom5HwoDMuaMvg9cekKX21hoNtJXixdrvvAwq2BoxKiUdQQnGWym1ZxT'
141+
)
142+
)->toBe([
143+
[
144+
'id' => '39VSD1tTjSED41254241UJLutnF7Y9fJLFsWUqdtQzAwteGgEyropo8Z8Y1HDdKpAsx8TrpNJWDgFxeeZQZ96x',
145+
'account' => '2tR6BWvwpwrQLUWN8GpVP4b6srCxgR2PnrsXs7jYfdeBj3FimJ5Tjd4xzWcWe8y59ZtEBXgQJxe6Uibux1cCDfxL',
146+
'asset' => '26PZgwak3LscM3Mz8bfDBmbETSq9GvXhdom5HwoDMuaMvg9cekKX21hoNtJXixdrvvAwq2BoxKiUdQQnGWym1ZxT',
147+
'price' => '1.00000000',
148+
'date' => 1615802171,
149+
'status' => 0,
150+
'type' => 'bid',
151+
'val' => 1000,
152+
'val_done' => 0,
153+
'cancelable' => 1,
154+
]
155+
]);
156+
});

tests/Api/BlockTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
declare(strict_types=1);
44

5-
use OwenVoke\Arionum\Api\Asset;
5+
use OwenVoke\Arionum\Api\Block;
66

7-
beforeEach(fn () => $this->apiClass = Asset::class);
7+
beforeEach(fn () => $this->apiClass = Block::class);
88

99
it('can get the current block');
1010

tests/Api/NodeTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
declare(strict_types=1);
44

5-
use OwenVoke\Arionum\Api\Asset;
5+
use OwenVoke\Arionum\Api\Node;
66

7-
beforeEach(fn () => $this->apiClass = Asset::class);
7+
beforeEach(fn () => $this->apiClass = Node::class);
88

99
it('can get the version of the current node');
1010

tests/Api/OtherTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
declare(strict_types=1);
44

5-
use OwenVoke\Arionum\Api\Asset;
5+
use OwenVoke\Arionum\Api\Other;
66

7-
beforeEach(fn () => $this->apiClass = Asset::class);
7+
beforeEach(fn () => $this->apiClass = Other::class);
88

99
it('can get a random number');
1010

tests/Api/TransactionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
declare(strict_types=1);
44

5-
use OwenVoke\Arionum\Api\Asset;
5+
use OwenVoke\Arionum\Api\Transaction;
66
use OwenVoke\Arionum\Enums\TransactionVersion;
77

8-
beforeEach(fn () => $this->apiClass = Asset::class);
8+
beforeEach(fn () => $this->apiClass = Transaction::class);
99

1010
it('can get the transactions for an address');
1111

0 commit comments

Comments
 (0)