Skip to content

Commit 8cb0b7d

Browse files
committed
test: add type-check tests for v1/v2 LedgerTransactionExpanded types
Verify that: - LedgerTransactionExpanded (v2) uses flat format with metaData - LedgerTransactionExpandedV1 (v1) uses wrapped format with tx_json/meta - Both are correctly assignable to their respective Ledger types
1 parent 162a0da commit 8cb0b7d

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
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'
410
import { hashes } from '../../src/utils'
511
import requests from '../fixtures/requests'
612
import responses from '../fixtures/responses'
@@ -150,4 +156,68 @@ describe('hashLedger', function () {
150156
'transactionHash in header does not match computed hash of transactions',
151157
)
152158
})
159+
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+
})
153223
})

0 commit comments

Comments
 (0)