mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 04:05:52 +00:00
fix(tests): more unit tests
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import requests from '../../fixtures/requests'
|
||||
import responses from '../../fixtures/responses'
|
||||
import {assertResultMatch, TestSuite} from '../../utils'
|
||||
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
|
||||
|
||||
/**
|
||||
* Every test suite exports their tests in the default object.
|
||||
@@ -8,11 +9,25 @@ import {assertResultMatch, TestSuite} from '../../utils'
|
||||
* - Check out "test/api/index.ts" for more information about the test runner.
|
||||
*/
|
||||
export default <TestSuite>{
|
||||
prepareCheckCancel: async (api, address) => {
|
||||
'prepareCheckCancel': async (api, address) => {
|
||||
const result = await api.prepareCheckCancel(
|
||||
address,
|
||||
requests.prepareCheckCancel.normal
|
||||
)
|
||||
assertResultMatch(result, responses.prepareCheckCancel.normal, 'prepare')
|
||||
},
|
||||
|
||||
'with ticket': async (api, address) => {
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
ticketSequence: 23
|
||||
}
|
||||
const result = await api.prepareCheckCancel(
|
||||
address,
|
||||
requests.prepareCheckCancel.normal,
|
||||
localInstructions
|
||||
)
|
||||
assertResultMatch(result, responses.prepareCheckCancel.ticket, 'prepare')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import requests from '../../fixtures/requests'
|
||||
import responses from '../../fixtures/responses'
|
||||
import {assertResultMatch, TestSuite} from '../../utils'
|
||||
const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
|
||||
|
||||
/**
|
||||
* Every test suite exports their tests in the default object.
|
||||
@@ -22,5 +23,19 @@ export default <TestSuite>{
|
||||
requests.prepareCheckCash.deliverMin
|
||||
)
|
||||
assertResultMatch(result, responses.prepareCheckCash.deliverMin, 'prepare')
|
||||
}
|
||||
},
|
||||
|
||||
'with ticket': async (api, address) => {
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
ticketSequence: 23
|
||||
}
|
||||
const result = await api.prepareCheckCash(
|
||||
address,
|
||||
requests.prepareCheckCash.amount,
|
||||
localInstructions
|
||||
)
|
||||
assertResultMatch(result, responses.prepareCheckCash.ticket, 'prepare')
|
||||
},
|
||||
}
|
||||
|
||||
@@ -28,5 +28,19 @@ export default <TestSuite>{
|
||||
requests.prepareCheckCreate.full
|
||||
)
|
||||
assertResultMatch(result, responses.prepareCheckCreate.full, 'prepare')
|
||||
},
|
||||
|
||||
'prepareCheckCreate with ticket': async (api, address) => {
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
ticketSequence: 23
|
||||
}
|
||||
const result = await api.prepareCheckCreate(
|
||||
address,
|
||||
requests.prepareCheckCreate.normal,
|
||||
localInstructions
|
||||
)
|
||||
assertResultMatch(result, responses.prepareCheckCreate.ticket, 'prepare')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,5 +32,23 @@ export default <TestSuite>{
|
||||
responses.prepareEscrowCancellation.memos,
|
||||
'prepare'
|
||||
)
|
||||
}
|
||||
},
|
||||
|
||||
'with ticket': async (api, address) => {
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
ticketSequence: 23
|
||||
}
|
||||
const result = await api.prepareEscrowCancellation(
|
||||
address,
|
||||
requests.prepareEscrowCancellation.normal,
|
||||
localInstructions
|
||||
)
|
||||
assertResultMatch(
|
||||
result,
|
||||
responses.prepareEscrowCancellation.ticket,
|
||||
'prepare'
|
||||
)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -45,5 +45,19 @@ export default <TestSuite>{
|
||||
api.errors.ValidationError,
|
||||
'instance.escrowCreation requires property "amount"'
|
||||
)
|
||||
}
|
||||
},
|
||||
|
||||
'with ticket': async (api, address) => {
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000396',
|
||||
ticketSequence: 23
|
||||
}
|
||||
const result = await api.prepareEscrowCreation(
|
||||
address,
|
||||
requests.prepareEscrowCreation.normal,
|
||||
localInstructions
|
||||
)
|
||||
assertResultMatch(result, responses.prepareEscrowCreation.ticket, 'prepare')
|
||||
},
|
||||
}
|
||||
|
||||
@@ -56,5 +56,23 @@ export default <TestSuite>{
|
||||
api.errors.ValidationError,
|
||||
'"condition" and "fulfillment" fields on EscrowFinish must only be specified together.'
|
||||
)
|
||||
}
|
||||
},
|
||||
|
||||
'with ticket': async (api, address) => {
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000396',
|
||||
ticketSequence: 23
|
||||
}
|
||||
const result = await api.prepareEscrowExecution(
|
||||
address,
|
||||
requests.prepareEscrowExecution.normal,
|
||||
localInstructions
|
||||
)
|
||||
assertResultMatch(
|
||||
result,
|
||||
responses.prepareEscrowExecution.ticket,
|
||||
'prepare'
|
||||
)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -48,5 +48,20 @@ export default <TestSuite>{
|
||||
api.errors.ValidationError,
|
||||
'instance.order requires property "direction"'
|
||||
)
|
||||
}
|
||||
},
|
||||
|
||||
'with ticket': async (api, address) => {
|
||||
const request = requests.prepareOrder.sell
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
ticketSequence: 23
|
||||
}
|
||||
const result = await api.prepareOrder(
|
||||
address,
|
||||
request,
|
||||
localInstructions
|
||||
)
|
||||
assertResultMatch(result, responses.prepareOrder.ticket, 'prepare')
|
||||
},
|
||||
}
|
||||
|
||||
@@ -55,5 +55,24 @@ export default <TestSuite>{
|
||||
api.errors.ValidationError,
|
||||
'instance.orderCancellation requires property "orderSequence"'
|
||||
)
|
||||
}
|
||||
},
|
||||
|
||||
'with ticket': async (api, address) => {
|
||||
const request = requests.prepareOrderCancellation.simple
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
ticketSequence: 23
|
||||
}
|
||||
const result = await api.prepareOrderCancellation(
|
||||
address,
|
||||
request,
|
||||
localInstructions
|
||||
)
|
||||
assertResultMatch(
|
||||
result,
|
||||
responses.prepareOrderCancellation.ticket,
|
||||
'prepare'
|
||||
)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -51,6 +51,20 @@ export default <TestSuite>{
|
||||
assertResultMatch(response, RESPONSE_FIXTURES.close, 'prepare')
|
||||
},
|
||||
|
||||
'with ticket': async (api, address) => {
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
ticketSequence: 23
|
||||
}
|
||||
const response = await api.preparePaymentChannelClaim(
|
||||
address,
|
||||
REQUEST_FIXTURES.normal,
|
||||
localInstructions
|
||||
)
|
||||
assertResultMatch(response, RESPONSE_FIXTURES.ticket, 'prepare')
|
||||
},
|
||||
|
||||
'rejects Promise on preparePaymentChannelClaim with renew and close': async (
|
||||
api,
|
||||
address
|
||||
|
||||
@@ -43,5 +43,23 @@ export default <TestSuite>{
|
||||
responses.preparePaymentChannelCreate.full,
|
||||
'prepare'
|
||||
)
|
||||
},
|
||||
|
||||
'preparePaymentChannelCreate with ticket': async (api, address) => {
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
ticketSequence: 23
|
||||
}
|
||||
const result = await api.preparePaymentChannelCreate(
|
||||
address,
|
||||
requests.preparePaymentChannelCreate.normal,
|
||||
localInstructions
|
||||
)
|
||||
assertResultMatch(
|
||||
result,
|
||||
responses.preparePaymentChannelCreate.ticket,
|
||||
'prepare'
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,5 +36,23 @@ export default <TestSuite>{
|
||||
responses.preparePaymentChannelFund.full,
|
||||
'prepare'
|
||||
)
|
||||
},
|
||||
|
||||
'with ticket': async (api, address) => {
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
ticketSequence: 23
|
||||
}
|
||||
const result = await api.preparePaymentChannelFund(
|
||||
address,
|
||||
requests.preparePaymentChannelFund.normal,
|
||||
localInstructions
|
||||
)
|
||||
assertResultMatch(
|
||||
result,
|
||||
responses.preparePaymentChannelFund.ticket,
|
||||
'prepare'
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,5 +251,18 @@ export default <TestSuite>{
|
||||
api.sign(result.txJSON, secret),
|
||||
responses.prepareSettings.signed
|
||||
)
|
||||
}
|
||||
},
|
||||
'prepare settings with ticket': async (api, address) => {
|
||||
const instructions = {
|
||||
ticketSequence: 23,
|
||||
maxLedgerVersion: 8820051,
|
||||
fee: '0.000012'
|
||||
}
|
||||
const response = await api.prepareSettings(
|
||||
address,
|
||||
requests.prepareSettings.domain,
|
||||
instructions
|
||||
)
|
||||
assertResultMatch(response, responses.prepareSettings.ticket, 'prepare')
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1240,5 +1240,61 @@ export default <TestSuite>{
|
||||
responses.preparePaymentChannelClaim.close,
|
||||
'prepare'
|
||||
)
|
||||
},
|
||||
|
||||
'rejects Promise if both sequence and ticketSecuence are set': async (
|
||||
api,
|
||||
address
|
||||
) => {
|
||||
const localInstructions = {
|
||||
ticketSequence: 23,
|
||||
sequence: 23
|
||||
}
|
||||
const txJSON = {
|
||||
TransactionType: 'DepositPreauth',
|
||||
Account: address,
|
||||
Authorize: 'rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo',
|
||||
Fee: '16'
|
||||
}
|
||||
await assertRejects(
|
||||
api.prepareTransaction(txJSON, localInstructions),
|
||||
ValidationError,
|
||||
'instance is of prohibited type [object Object]'
|
||||
)
|
||||
},
|
||||
|
||||
'sets sequence to 0 if a ticketSequence is passed': async (
|
||||
api,
|
||||
address
|
||||
) => {
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
ticketSequence: 23
|
||||
}
|
||||
|
||||
const txJSON = {
|
||||
TransactionType: 'Payment',
|
||||
Account: address,
|
||||
Destination: 'rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo',
|
||||
Amount: {
|
||||
currency: 'USD',
|
||||
issuer: 'rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM',
|
||||
value: '0.01'
|
||||
},
|
||||
SendMax: {
|
||||
currency: 'USD',
|
||||
issuer: 'rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM',
|
||||
value: '0.01'
|
||||
},
|
||||
Flags: 0
|
||||
}
|
||||
|
||||
const response = await api.prepareTransaction(txJSON, localInstructions)
|
||||
assertResultMatch(
|
||||
response,
|
||||
responses.preparePayment.ticket,
|
||||
'prepare'
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,5 +48,19 @@ export default <TestSuite>{
|
||||
api.errors.ValidationError,
|
||||
'instance.trustline requires property "limit"'
|
||||
)
|
||||
}
|
||||
},
|
||||
|
||||
'with ticket': async (api, address) => {
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
ticketSequence: 23
|
||||
}
|
||||
const result = await api.prepareTrustline(
|
||||
address,
|
||||
requests.prepareTrustline.simple,
|
||||
localInstructions
|
||||
)
|
||||
assertResultMatch(result, responses.prepareTrustline.ticket, 'prepare')
|
||||
},
|
||||
}
|
||||
|
||||
@@ -330,5 +330,12 @@ export default <TestSuite>{
|
||||
|
||||
assert.deepEqual(result, expectedResponse)
|
||||
schemaValidator.schemaValidate('sign', result)
|
||||
}
|
||||
},
|
||||
|
||||
'sign with ticket': async (api, address) => {
|
||||
const secret = 'sn7n5R1cR5Y3fRFkuWXA94Ts1frVJ'
|
||||
const result = api.sign(REQUEST_FIXTURES.ticket.txJSON, secret)
|
||||
assert.deepEqual(result, RESPONSE_FIXTURES.ticket)
|
||||
schemaValidator.schemaValidate('sign', result)
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user