|
1 | 1 | import { assert } from 'chai' |
2 | 2 |
|
3 | 3 | import { ValidationError, XrplError } from '../../src' |
| 4 | +import { |
| 5 | + Ledger, |
| 6 | + LedgerV1, |
| 7 | + LedgerTransactionExpanded, |
| 8 | + LedgerTransactionExpandedV1, |
| 9 | +} from '../../src/models/ledger/Ledger' |
4 | 10 | import { hashes } from '../../src/utils' |
5 | 11 | import requests from '../fixtures/requests' |
6 | 12 | import responses from '../fixtures/responses' |
@@ -150,4 +156,68 @@ describe('hashLedger', function () { |
150 | 156 | 'transactionHash in header does not match computed hash of transactions', |
151 | 157 | ) |
152 | 158 | }) |
| 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 | + }) |
153 | 223 | }) |
0 commit comments