Skip to content

Commit a1a5bc0

Browse files
committed
Adding unit tests
Updating the documentation
1 parent 094f760 commit a1a5bc0

File tree

10 files changed

+113
-5
lines changed

10 files changed

+113
-5
lines changed

docs/advanced/bundlers.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Bundlers
2+
3+
Like many other blockchain, also the ardor blockchain suffers from a major issue. Sending transactions costs. While other blockchains does not have a proper solution to resolve that issue, ardor offers you muliple ways of solve that issue.
4+
5+
[Bundling](https://ardordocs.jelurida.com/Bundling) transactions provides you the possibilities to fund or pay the transaction fees of others. While the "native" approach must be written in java and run as part of a ardor node, this package provides you - lets call it "easy" - approach to solve that within your laravel application.
6+
7+
## PHP Bundlers
8+
9+
### How to create a bundler
10+
11+
```bash
12+
php artisan ardor:make {name} --type=bundler
13+
```
14+
15+
Define your bundler in the ardor config file.
16+
17+
```php
18+
...
19+
'bundlers' => [
20+
\AMBERSIVE\Ardor\Bundlers\DefaultTransactionBundler::class
21+
],
22+
...
23+
```
24+
25+
Modify your bundler logic. Every bundler has a **run** function which needs to return a boolean value.
26+
27+
```php
28+
/**
29+
* Main entry point for the bundler
30+
*
31+
* @param mixed $transaction
32+
* @return bool
33+
*/
34+
public function run(ArdorTransactionJson $transaction):bool {
35+
if (in_array($transaction->senderRS, data_get($this->config, 'accounts', []))){
36+
return $this->ardorBundler->bundleTransactions($transaction->fullHash, $transaction->chain);
37+
}
38+
return false;
39+
}
40+
```
41+
42+
### How can i run the bundler?
43+
44+
To run the bundlers just run the following command in your command line:
45+
46+
```bash
47+
php artisan ardor:run-bundler
48+
```
49+
50+
Every transaction will only be processed once within a timeframe of 15 minutes, cause resolving the transation data triggers multiple cals in the api which might cause performance problems.
51+
52+
If a transactin was bundled the bundling process for this specific bundler will stop.
53+

docs/overview.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ Not implemented yet
5252
- [calculateFee](transactions/calculateFee.md)
5353
- [calculateFeeByTransactionsBytes](transactions/calculateFeeByTransactionsBytes.md)
5454
- [getUnconfirmedTransactions](transactions/getUnconfirmedTransactions.md)
55-
- [getTransactionBytes](transations/getTransactionBytes.md)
56-
- [getTransaction](transations/getTransaction.md)
55+
- [getTransactionBytes](transactions/getTransactionBytes.md)
56+
- [getTransaction](transactions/getTransaction.md)
5757

5858
## Voting System
5959
Not implemented yet
@@ -69,3 +69,6 @@ Not implemented yet
6969

7070
## Add-ons
7171
Not implemented yet
72+
73+
## Advanced topics
74+
- [PHP Bundlers](advanced/bundlers.md)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Get unconfirmed transactions
2+
3+
Getting unconfirmed transactions is a every useful endpoint. Cause our custom bundler implementation is based on this information. This implementation is part of the ArdorBlockchain Class.
4+
5+
```php
6+
$chain = 2; // = IGNIS
7+
$blockchain = new ArdorBlockchain();
8+
$result = $blockchain->getUnconfirmedTransactions($chain);
9+
```
10+
11+
This request will return a instance of [ArdorTransactionCollection](../../src/Models/ArdorTransactionCollection.php).
12+
13+
---
14+
Return to the [overview](../overview.md) page for all topics.

docs/transations/getUnconfirmedTransactions.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/Models/ArdorTransactionCollection.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public function __construct(object $data){
2424
return new ArdorTransactionJson($item);
2525
});
2626

27-
//$this->transactionJSON = isset($data->transactionJSON) ? new ArdorTransactionJson($data->transactionJSON) : new ArdorTransactionJson((object) []);
2827
}
2928

3029
}

src/Tests/Units/Classes/ArdorBlockchainTest.php

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ class ArdorBlockchainTest extends TestArdorCase
2121
*/
2222
public function testArdorBlockchainGetTransaction():void {
2323

24+
// Prepare
25+
$responseMessage = new ArdorMockResponse(200, ["fullHash" => "68df1c0eb56059cae1dbaa57efe161762d57e996e38b844abcad7fd1c017b33d"]);
26+
27+
// Test
2428
$blockchain = new ArdorBlockchain();
2529
$result = $blockchain
30+
->setClient($this->createApiMock([$responseMessage]))
2631
->getTransaction("68df1c0eb56059cae1dbaa57efe161762d57e996e38b844abcad7fd1c017b33d", 2);
2732

2833
$this->assertNotNull($result);
@@ -35,8 +40,13 @@ public function testArdorBlockchainGetTransaction():void {
3540
*/
3641
public function testArdorBlockchainGetTransactionWonTFailsDueIncorrectChain():void {
3742

43+
// Prepare
44+
$responseMessage = new ArdorMockResponse(200, ["fullHash" => "68df1c0eb56059cae1dbaa57efe161762d57e996e38b844abcad7fd1c017b33d"]);
45+
46+
// Test
3847
$blockchain = new ArdorBlockchain();
3948
$result = $blockchain
49+
->setClient($this->createApiMock([$responseMessage]))
4050
->getTransaction("68df1c0eb56059cae1dbaa57efe161762d57e996e38b844abcad7fd1c017b33d", 1);
4151

4252
$this->assertNotNull($result);
@@ -62,8 +72,17 @@ public function testArdorBlockchainGetTransactionFailsDueIncorrectChain():void {
6272
*/
6373
public function testArdorBlockchainGetTransactionBytes():void {
6474

75+
// Prepare
76+
$responseMessage = new ArdorMockResponse(200, [
77+
"unsignedTransactionBytes" => "020000000100010f04b4040f00850ec0aeeadd6c71804128f422cb621b89072805fa228be4369fe0e9d25d1309f0a335f1de518c6300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008d3d4c009e95d1ccdb70f744010000000101040074657374000000000000000000000000000000000000000000000000000000000000000000000000",
78+
"requestProcessingTime" => 0,
79+
"transactionBytes" => "020000000100010f04b4040f00850ec0aeeadd6c71804128f422cb621b89072805fa228be4369fe0e9d25d1309f0a335f1de518c6300000000000000000000000000000000e3bd3f9542a9419f3cd99365828089ff06a6b0094734bdce6bb8dc41115f1b02190327eaed5c25bec826009b2f31e039bd16ac6d301c3c739f4d0ac24a9decd68d3d4c009e95d1ccdb70f744010000000101040074657374000000000000000000000000000000000000000000000000000000000000000000000000"
80+
]);
81+
82+
// Test
6583
$blockchain = new ArdorBlockchain();
6684
$result = $blockchain
85+
->setClient($this->createApiMock([$responseMessage]))
6786
->getTransactionBytes("68df1c0eb56059cae1dbaa57efe161762d57e996e38b844abcad7fd1c017b33d", 1);
6887

6988
$this->assertNotNull($result);
@@ -73,7 +92,28 @@ public function testArdorBlockchainGetTransactionBytes():void {
7392
$this->assertNotNull($result->unsignedTransactionBytes);
7493
$this->assertNotNull($result->transactionBytes);
7594

76-
dd($result);
95+
}
96+
97+
/**
98+
* Test if the getUnconfirmedTransactions returns a ArdorTransactionCollection
99+
*/
100+
public function testArdorBlockchainGetUnconfirmedTransactions():void {
101+
102+
// Prepare
103+
104+
$messenger = new ArdorMessenger();
105+
$resultMessage = $messenger
106+
->setFee(1)
107+
->sendMessage("ARDOR-DAZJ-VVSM-552M-8K459", "test", false, ['broadcast' => true, 'broadcasted' => true]);
108+
109+
// Test
110+
$blockchain = new ArdorBlockchain();
111+
$result = $blockchain->getUnconfirmedTransactions(2);
112+
113+
$this->assertNotNull($result);
114+
$this->assertTrue(isset($result->transactions));
115+
$this->assertTrue($result->transactions->count() > 0);
116+
$this->assertTrue($result instanceof \AMBERSIVE\Ardor\Models\ArdorTransactionCollection);
77117
}
78118

79119
}

0 commit comments

Comments
 (0)