feat(tickets): first commit, preparePayment and prepareTicket

This commit is contained in:
Javi
2020-11-05 12:41:54 +01:00
parent 382cf4cb1f
commit c7e08378ac
20 changed files with 249 additions and 10 deletions

View File

@@ -489,5 +489,44 @@ export default <TestSuite>{
instructionsWithMaxLedgerVersionOffset
)
assertResultMatch(response, expectedResponse, 'prepare')
}
},
// Tickets
'preparePayment with ticketSequence': async (api, address) => {
const version = await api.getLedgerVersion()
const localInstructions = {
maxLedgerVersion: version + 100,
fee: '0.000012',
ticketSequence: 23
}
const response = await api.preparePayment(
address,
REQUEST_FIXTURES.allOptions,
localInstructions
)
assertResultMatch(response, RESPONSE_FIXTURES.ticketSequence, 'prepare')
},
'throws when both sequence and ticketSequence are set': async (
api,
address
) => {
const version = await api.getLedgerVersion()
const localInstructions = {
maxLedgerVersion: version + 100,
fee: '0.000012',
ticketSequence: 23,
sequence: 12
}
return assertRejects(
api.preparePayment(
address,
REQUEST_FIXTURES.allOptions,
localInstructions
),
ValidationError,
'instance.instructions is of prohibited type [object Object]'
)
},
}

View File

@@ -0,0 +1,53 @@
import {assertResultMatch, TestSuite} from '../../utils'
// import responses from '../../fixtures/responses'
// import requests from '../../fixtures/requests'
// import {ValidationError} from 'ripple-api/common/errors'
// import binary from 'ripple-binary-codec'
// import assert from 'assert-diff'
// import {RippleAPI} from 'ripple-api'
// const {schemaValidator} = RippleAPI._PRIVATE
// const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
// const {preparePayment: REQUEST_FIXTURES} = requests
// const {preparePayment: RESPONSE_FIXTURES} = responses
// const ADDRESS = 'rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo'
/**
* Every test suite exports their tests in the default object.
* - Check out the "TestSuite" type for documentation on the interface.
* - Check out "test/api/index.ts" for more information about the test runner.
*/
export default <TestSuite>{
'creates a ticket successfully with a sequence number': async (api, address) => {
const expected = {
txJSON:
'{"TransactionType":"TicketCreate", "TicketCount": 2, "Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Flags":2147483648,"LastLedgerSequence":8819954,"Sequence":23,"Fee":"12"}',
instructions: {
maxLedgerVersion: 8819954,
sequence: 23,
fee: '0.000012'
}
}
const response = await api.prepareTicket(address, 2)
assertResultMatch(response, expected, 'prepare')
},
'creates a ticket successfully with another ticket': async (api, address) => {
const expected = {
txJSON:
'{"TransactionType":"TicketCreate", "TicketCount": 1, "Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Flags":2147483648,"LastLedgerSequence":8819954,"Sequence": 0,"TicketSequence":23,"Fee":"12"}',
instructions: {
maxLedgerVersion: 8819954,
ticketSequence: 23,
fee: '0.000012'
}
}
const instructions = {
maxLedgerVersion: 8819954,
ticketSequence: 23,
fee: '0.000012'
}
const response = await api.prepareTicket(address, 1, instructions)
assertResultMatch(response, expected, 'prepare')
}
}

View File

@@ -108,7 +108,8 @@ module.exports = {
minAmountXRPXRP: require('./prepare-payment-min-amount-xrp-xrp.json'),
allOptions: require('./prepare-payment-all-options.json'),
noCounterparty: require('./prepare-payment-no-counterparty.json'),
minAmount: require('./prepare-payment-min-amount.json')
minAmount: require('./prepare-payment-min-amount.json'),
ticketSequence: require('./prepare-payment-ticket-sequence.json')
},
prepareSettings: {
regularKey: require('./prepare-settings-regular-key.json'),

View File

@@ -0,0 +1,8 @@
{
"txJSON": "{\"Flags\":2147811328,\"TransactionType\":\"Payment\",\"Account\":\"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59\",\"Destination\":\"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo\",\"Amount\":\"10000\",\"InvoiceID\":\"A98FD36C17BE2B8511AD36DC335478E7E89F06262949F36EB88E2D683BBCC50A\",\"SourceTag\":14,\"DestinationTag\":58,\"Memos\":[{\"Memo\":{\"MemoType\":\"74657374\",\"MemoFormat\":\"746578742F706C61696E\",\"MemoData\":\"7465787465642064617461\"}}],\"LastLedgerSequence\":8820051,\"Fee\":\"12\",\"Sequence\":0,\"TicketSequence\":23}",
"instructions": {
"fee": "0.000012",
"ticketSequence": 23,
"maxLedgerVersion": 8820051
}
}

View File

@@ -348,6 +348,16 @@ describe('integration tests', function() {
})
})
it('ticket', function() {
return this.api.getLedgerVersion().then(ledgerVersion => {
return this.api
.prepareTicket(address, 1, instructions)
.then(prepared =>
testTransaction(this, 'ticket', ledgerVersion, prepared)
)
})
})
it('isConnected', function() {
assert(this.api.isConnected())
})