Skip to content

Commit

Permalink
Exclude fee on start always
Browse files Browse the repository at this point in the history
  • Loading branch information
zgrguric committed Aug 12, 2023
1 parent 0bebe79 commit 30ed4c4
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/TxMutationParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,11 @@ public function __construct(string $reference_account, \stdClass $tx)
'account' => $this->tx->Account,
'mutation' => $this->significantBalanceChange(
$_balanceChanges,
(
$this->tx->Account === $this->account ||
(isset($this->tx->Destination) && $this->tx->Destination === $this->account)
) ? $fee : null
//(
// $this->tx->Account === $this->account ||
// (isset($this->tx->Destination) && $this->tx->Destination === $this->account)
//) ? $fee : null
$fee
)
];
if($eventFlow['start']['mutation'] === [])
Expand Down Expand Up @@ -353,7 +354,7 @@ private function significantBalanceChange(array $balanceChanges, ?string $fee):
* this will keep fee display consistant.
*/
$fallback = $balanceChanges[0];

if(
$fallback['currency'] === 'XRP' &&
( !isset($fallback['counterparty']) || (isset($fallback['counterparty']) && $fallback['counterparty'] === '') ) &&
Expand Down
2 changes: 1 addition & 1 deletion tests/Tx13Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function testTx13_PartialPaymentSender()
'account' => 'rwietsevLFg8XSmG3bEZzFein1g8RBqWDZ',
'mutation' => [
'currency' => 'XRP',
'value' => '-3.000012'
'value' => '-3'
]
],$parsedTransaction['eventFlow']['start']);

Expand Down
105 changes: 105 additions & 0 deletions tests/Tx19Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php declare(strict_types=1);

namespace XRPLWin\XRPLTxMutatationParser\Tests;

use PHPUnit\Framework\TestCase;
use XRPLWin\XRPLTxMutatationParser\TxMutationParser;

/***
* @see https://hash.xrp.fans/27F76F0DA13975E19F45A9B2E841545E11CAE295D8873B944A9200B1A84F1CDE/json
* Conversion payment by using paths.
*/
final class Tx19Test extends TestCase
{
public function testPaymentInitiator()
{
$transaction = file_get_contents(__DIR__.'/fixtures/tx19.json');
$transaction = \json_decode($transaction);
$account = "rNwUcrxYiTZ5cRAuEQVuQGDb7miaPRBVAd";
$TxMutationParser = new TxMutationParser($account, $transaction->result);
$parsedTransaction = $TxMutationParser->result();
//dd($parsedTransaction);
//Self (own account) must be $account
$this->assertEquals($account,$parsedTransaction['self']['account']);

# Basic info

//Own account: one balance change
$this->assertEquals(1,count($parsedTransaction['self']['balanceChanges']));

//Transaction type SET
$this->assertEquals(TxMutationParser::MUTATIONTYPE_SENT,$parsedTransaction['type']);

$this->assertTrue($parsedTransaction['self']['feePayer']);

# Event list

//does contain `primary` entry
$this->assertArrayHasKey('primary',$parsedTransaction['eventList']);
$this->assertEquals([
'currency' => 'XRP',
'value' => '-21.95924'
],$parsedTransaction['eventList']['primary']);

//does not contain `secondary` entry
$this->assertArrayNotHasKey('secondary',$parsedTransaction['eventList']);

# Event flow
//does not contain `intermediate` entry
$this->assertArrayNotHasKey('intermediate',$parsedTransaction['eventFlow']);

//does contain `start` entry
$this->assertArrayHasKey('start',$parsedTransaction['eventFlow']);
$this->assertEquals([
'account' => $account,
'mutation' => [
'currency' => "XRP",
'value' => "-21.95924",//excluding fee
]
],$parsedTransaction['eventFlow']['start']);

//does contain `end` entry
$this->assertArrayHasKey('end',$parsedTransaction['eventFlow']);

$this->assertEquals([
'account' => 'rNFugeoj3ZN8Wv6xhuLegUBBPXKCyWLRkB',
'mutation' => [
'currency' => "XRP",
'value' => "21.95924",
]
],$parsedTransaction['eventFlow']['end']);

}

public function testEndIncludingFeeFromRegularkeysignerPerspective()
{
$transaction = file_get_contents(__DIR__.'/fixtures/tx19.json');
$transaction = \json_decode($transaction);
$account = "rMgptxL3EiPTj35eWSpJDGyon8SSn4ELiH";
$TxMutationParser = new TxMutationParser($account, $transaction->result);
$parsedTransaction = $TxMutationParser->result();


//does contain `start` entry
$this->assertArrayHasKey('start',$parsedTransaction['eventFlow']);
$this->assertEquals([
'account' => 'rNwUcrxYiTZ5cRAuEQVuQGDb7miaPRBVAd',
'mutation' => [
'currency' => "XRP",
'value' => "-21.95924",//excluding fee, this is viewed from regularkeysigners perspective
]
],$parsedTransaction['eventFlow']['start']);

//does contain `end` entry
$this->assertArrayHasKey('end',$parsedTransaction['eventFlow']);
$this->assertEquals([
'account' => 'rNFugeoj3ZN8Wv6xhuLegUBBPXKCyWLRkB',
'mutation' => [
'currency' => "XRP",
'value' => "21.95924",//excluding fee
]
],$parsedTransaction['eventFlow']['end']);
}


}
84 changes: 84 additions & 0 deletions tests/fixtures/tx19.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"id": 1,
"result": {
"Account": "rNwUcrxYiTZ5cRAuEQVuQGDb7miaPRBVAd",
"Amount": "21959240",
"Destination": "rNFugeoj3ZN8Wv6xhuLegUBBPXKCyWLRkB",
"DestinationTag": 1933938194,
"Fee": "10",
"Flags": 2147483648,
"LastLedgerSequence": 81773159,
"Sequence": 78746746,
"SigningPubKey": "02F7AC06942015820728D00FD094E46F13DB8C58215F9236D073884CED26F1FDF8",
"TransactionType": "Payment",
"TxnSignature": "3045022100C1DF1D5FF821972F2EF585C9A230D8F976E633AAAEB28A75337FB72D7771C1CE022010D9C3FABF3B60B9D366275CF7D6637B966A8818DA2A0F4750213A9609AC1C21",
"date": 745093090,
"hash": "F468A9B7702FB1546C3B2F4DCCCEDD8F0AC95BD9F7403CA09A3B662A00279394",
"inLedger": 81773157,
"ledger_index": 81773157,
"meta": {
"AffectedNodes": [
{
"ModifiedNode": {
"FinalFields": {
"Account": "rNwUcrxYiTZ5cRAuEQVuQGDb7miaPRBVAd",
"Balance": "146764324036",
"Flags": 131072,
"OwnerCount": 1,
"RegularKey": "rMgptxL3EiPTj35eWSpJDGyon8SSn4ELiH",
"Sequence": 78746747
},
"LedgerEntryType": "AccountRoot",
"LedgerIndex": "655E797CF6256C24343952382CCA0EFEFC9CC1431DFE3EA39B44A087B92C79D6",
"PreviousFields": {
"Balance": "146786283286",
"Sequence": 78746746
},
"PreviousTxnID": "0DC001355DE0C638648308748949201BC3EEA34284E2FC8D52A35A743DAA1D01",
"PreviousTxnLgrSeq": 81773092
}
},
{
"ModifiedNode": {
"FinalFields": {
"Account": "rNFugeoj3ZN8Wv6xhuLegUBBPXKCyWLRkB",
"Balance": "11747817307",
"Flags": 131072,
"OwnerCount": 0,
"Sequence": 59059736
},
"LedgerEntryType": "AccountRoot",
"LedgerIndex": "6F94B5486DBA5021658BF814570177F012A1680FD1973735094F71957DCFFF9F",
"PreviousFields": {
"Balance": "11725858067"
},
"PreviousTxnID": "8D7299403B90B0A3FD448FDB54BB037DC0846770A54DC3803237167C7CEC6E50",
"PreviousTxnLgrSeq": 81773156
}
}
],
"TransactionIndex": 11,
"TransactionResult": "tesSUCCESS",
"delivered_amount": "21959240"
},
"validated": true
},
"resolvedBy": "generator",
"host": "wss://xrpl.ws",
"balanceChanges": {
"rNwUcrxYiTZ5cRAuEQVuQGDb7miaPRBVAd": [
{
"counterparty": "",
"currency": "XRP",
"value": "-21.95925"
}
],
"rNFugeoj3ZN8Wv6xhuLegUBBPXKCyWLRkB": [
{
"counterparty": "",
"currency": "XRP",
"value": "21.95924"
}
]
}
}

0 comments on commit 30ed4c4

Please sign in to comment.