Skip to content

Commit 2da05b0

Browse files
committed
refactor: address CodeRabbit review feedback
- Fix JSDoc on Ledger.transactions and LedgerV1.transactions to accurately describe the expanded transaction format instead of referencing hash strings - Move LedgerTransactionExpanded type tests to dedicated test file (test/models/LedgerTransactionExpanded.test.ts) for better test organization
1 parent 8cb0b7d commit 2da05b0

File tree

3 files changed

+78
-78
lines changed

3 files changed

+78
-78
lines changed

packages/xrpl/src/models/ledger/Ledger.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,9 @@ export interface Ledger extends BaseLedger {
9292
*/
9393
ledger_index: number
9494
/**
95-
* Transactions applied in this ledger version. By default, members are the
96-
* transactions' identifying Hash strings. If the request specified expand as
97-
* true, members are full representations of the transactions instead, in
98-
* either JSON or binary depending on whether the request specified binary
99-
* as true.
95+
* Transactions applied in this ledger version. When expanded, members are
96+
* full representations of the transactions as flat objects with the
97+
* transaction fields directly on the object, plus `hash` and `metaData`.
10098
*/
10199
transactions?: Array<LedgerTransactionExpanded>
102100
}
@@ -115,10 +113,9 @@ export interface LedgerV1 extends BaseLedger {
115113
*/
116114
ledger_index: string
117115
/**
118-
* Transactions applied in this ledger version. By default, members are the
119-
* transactions' identifying Hash strings. If the request specified expand as
120-
* true, members are full representations of the transactions instead,
121-
* wrapped in objects with `tx_json` and `meta` fields.
116+
* Transactions applied in this ledger version. When expanded, members are
117+
* full representations of the transactions wrapped in objects with
118+
* `tx_json` and `meta` fields.
122119
*/
123120
transactions?: Array<LedgerTransactionExpandedV1>
124121
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { assert } from 'chai'
2+
3+
import {
4+
Ledger,
5+
LedgerV1,
6+
LedgerTransactionExpanded,
7+
LedgerTransactionExpandedV1,
8+
} from '../../src/models/ledger/Ledger'
9+
10+
describe('LedgerTransactionExpanded types', function () {
11+
it('Ledger (v2) transactions use flat format with metaData', function () {
12+
const tx: LedgerTransactionExpanded = {
13+
Account: 'rPrioTXJgZJF8bpdXq2X73PcVPfvYqjVKd',
14+
TransactionType: 'Payment',
15+
Fee: '11',
16+
Sequence: 1,
17+
Flags: 0,
18+
SigningPubKey: '',
19+
TxnSignature: '',
20+
hash: '044314FE34236A262DA692789CE5B48CA1A3CEC078B1A4ECCD65F4B61A9EB0A7',
21+
metaData: {
22+
AffectedNodes: [],
23+
TransactionIndex: 0,
24+
TransactionResult: 'tesSUCCESS',
25+
},
26+
}
27+
28+
// Verify v2 expanded transactions are assignable to Ledger.transactions
29+
const ledgerV2: Pick<Ledger, 'transactions'> = {
30+
transactions: [tx],
31+
}
32+
33+
assert.isArray(ledgerV2.transactions)
34+
assert.strictEqual(ledgerV2.transactions![0].hash, tx.hash)
35+
assert.isDefined(ledgerV2.transactions![0].metaData)
36+
})
37+
38+
it('LedgerV1 transactions use wrapped format with tx_json and meta', function () {
39+
const tx: LedgerTransactionExpandedV1 = {
40+
tx_json: {
41+
Account: 'rPrioTXJgZJF8bpdXq2X73PcVPfvYqjVKd',
42+
TransactionType: 'Payment',
43+
Fee: '11',
44+
Sequence: 1,
45+
Flags: 0,
46+
SigningPubKey: '',
47+
TxnSignature: '',
48+
},
49+
meta: {
50+
AffectedNodes: [],
51+
TransactionIndex: 0,
52+
TransactionResult: 'tesSUCCESS',
53+
},
54+
hash: '044314FE34236A262DA692789CE5B48CA1A3CEC078B1A4ECCD65F4B61A9EB0A7',
55+
validated: true,
56+
ledger_index: 93637993,
57+
close_time_iso: '2025-01-22T21:13:50Z',
58+
ledger_hash:
59+
'058FDA696458896EC515AC19C3EDC8CD0E163A3620CA6B314165E5BAED70846A',
60+
}
61+
62+
// Verify v1 expanded transactions are assignable to LedgerV1.transactions
63+
const ledgerV1: Pick<LedgerV1, 'transactions'> = {
64+
transactions: [tx],
65+
}
66+
67+
assert.isArray(ledgerV1.transactions)
68+
assert.strictEqual(ledgerV1.transactions![0].hash, tx.hash)
69+
assert.isDefined(ledgerV1.transactions![0].tx_json)
70+
assert.isDefined(ledgerV1.transactions![0].meta)
71+
})
72+
})

packages/xrpl/test/utils/hashLedger.test.ts

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import { assert } from 'chai'
22

33
import { ValidationError, XrplError } from '../../src'
4-
import {
5-
Ledger,
6-
LedgerV1,
7-
LedgerTransactionExpanded,
8-
LedgerTransactionExpandedV1,
9-
} from '../../src/models/ledger/Ledger'
104
import { hashes } from '../../src/utils'
115
import requests from '../fixtures/requests'
126
import responses from '../fixtures/responses'
@@ -157,67 +151,4 @@ describe('hashLedger', function () {
157151
)
158152
})
159153

160-
describe('LedgerTransactionExpanded types', function () {
161-
it('Ledger (v2) transactions use flat format with metaData', function () {
162-
const tx: LedgerTransactionExpanded = {
163-
Account: 'rPrioTXJgZJF8bpdXq2X73PcVPfvYqjVKd',
164-
TransactionType: 'Payment',
165-
Fee: '11',
166-
Sequence: 1,
167-
Flags: 0,
168-
SigningPubKey: '',
169-
TxnSignature: '',
170-
hash: '044314FE34236A262DA692789CE5B48CA1A3CEC078B1A4ECCD65F4B61A9EB0A7',
171-
metaData: {
172-
AffectedNodes: [],
173-
TransactionIndex: 0,
174-
TransactionResult: 'tesSUCCESS',
175-
},
176-
}
177-
178-
// Verify v2 expanded transactions are assignable to Ledger.transactions
179-
const ledgerV2: Pick<Ledger, 'transactions'> = {
180-
transactions: [tx],
181-
}
182-
183-
assert.isArray(ledgerV2.transactions)
184-
assert.strictEqual(ledgerV2.transactions![0].hash, tx.hash)
185-
assert.isDefined(ledgerV2.transactions![0].metaData)
186-
})
187-
188-
it('LedgerV1 transactions use wrapped format with tx_json and meta', function () {
189-
const tx: LedgerTransactionExpandedV1 = {
190-
tx_json: {
191-
Account: 'rPrioTXJgZJF8bpdXq2X73PcVPfvYqjVKd',
192-
TransactionType: 'Payment',
193-
Fee: '11',
194-
Sequence: 1,
195-
Flags: 0,
196-
SigningPubKey: '',
197-
TxnSignature: '',
198-
},
199-
meta: {
200-
AffectedNodes: [],
201-
TransactionIndex: 0,
202-
TransactionResult: 'tesSUCCESS',
203-
},
204-
hash: '044314FE34236A262DA692789CE5B48CA1A3CEC078B1A4ECCD65F4B61A9EB0A7',
205-
validated: true,
206-
ledger_index: 93637993,
207-
close_time_iso: '2025-01-22T21:13:50Z',
208-
ledger_hash:
209-
'058FDA696458896EC515AC19C3EDC8CD0E163A3620CA6B314165E5BAED70846A',
210-
}
211-
212-
// Verify v1 expanded transactions are assignable to LedgerV1.transactions
213-
const ledgerV1: Pick<LedgerV1, 'transactions'> = {
214-
transactions: [tx],
215-
}
216-
217-
assert.isArray(ledgerV1.transactions)
218-
assert.strictEqual(ledgerV1.transactions![0].hash, tx.hash)
219-
assert.isDefined(ledgerV1.transactions![0].tx_json)
220-
assert.isDefined(ledgerV1.transactions![0].meta)
221-
})
222-
})
223154
})

0 commit comments

Comments
 (0)