|
1 | 1 | import { assert } from 'chai' |
2 | 2 |
|
3 | | -import { LedgerEntryRequest, LedgerEntryResponse } from '../../../src' |
| 3 | +import { |
| 4 | + LedgerEntryRequest, |
| 5 | + LedgerEntryResponse, |
| 6 | + TicketCreate, |
| 7 | +} from '../../../src' |
| 8 | +import Ticket from '../../../src/models/ledger/Ticket' |
4 | 9 | import serverUrl from '../serverUrl' |
5 | 10 | import { |
6 | 11 | setupClient, |
7 | 12 | teardownClient, |
8 | 13 | type XrplIntegrationTestContext, |
9 | 14 | } from '../setup' |
| 15 | +import { testTransaction } from '../utils' |
10 | 16 |
|
11 | 17 | // how long before each test case times out |
12 | 18 | const TIMEOUT = 20000 |
@@ -55,4 +61,46 @@ describe('ledger_entry', function () { |
55 | 61 | }, |
56 | 62 | TIMEOUT, |
57 | 63 | ) |
| 64 | + |
| 65 | + it( |
| 66 | + 'fetches a Ticket object', |
| 67 | + async () => { |
| 68 | + // Step 1: Get the current account sequence |
| 69 | + const accountInfoResponse = await testContext.client.request({ |
| 70 | + command: 'account_info', |
| 71 | + account: testContext.wallet.classicAddress, |
| 72 | + }) |
| 73 | + const accSeq = accountInfoResponse.result.account_data.Sequence |
| 74 | + const ticketSeq = accSeq + 1 |
| 75 | + // Step 2: Create a Ticket |
| 76 | + const ticketCreate: TicketCreate = { |
| 77 | + TransactionType: 'TicketCreate', |
| 78 | + Account: testContext.wallet.classicAddress, |
| 79 | + TicketCount: 1, |
| 80 | + Sequence: accSeq, |
| 81 | + } |
| 82 | + await testTransaction(testContext.client, ticketCreate, testContext.wallet) |
| 83 | + // Step 3: Fetch the Ticket via ledger_entry using account + ticket_seq |
| 84 | + const ledgerEntryRequest: LedgerEntryRequest = { |
| 85 | + command: 'ledger_entry', |
| 86 | + ticket: { |
| 87 | + account: testContext.wallet.classicAddress, |
| 88 | + ticket_seq: ticketSeq, |
| 89 | + }, |
| 90 | + } |
| 91 | + const ledgerEntryResponse: LedgerEntryResponse<Ticket> = |
| 92 | + await testContext.client.request(ledgerEntryRequest) |
| 93 | + assert.equal(ledgerEntryResponse.type, 'response') |
| 94 | + assert.equal(ledgerEntryResponse.result.node?.LedgerEntryType, 'Ticket') |
| 95 | + assert.equal( |
| 96 | + ledgerEntryResponse.result.node?.Account, |
| 97 | + testContext.wallet.classicAddress, |
| 98 | + ) |
| 99 | + assert.equal( |
| 100 | + ledgerEntryResponse.result.node?.TicketSequence, |
| 101 | + ticketSeq, |
| 102 | + ) |
| 103 | + }, |
| 104 | + TIMEOUT, |
| 105 | + ) |
58 | 106 | }) |
0 commit comments