fix(tests): more unit tests

This commit is contained in:
Javi
2020-11-06 10:44:46 +01:00
parent c7e08378ac
commit fd0f64fe54
35 changed files with 429 additions and 22 deletions

View File

@@ -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')
}
}

View File

@@ -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')
},
}

View File

@@ -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')
}
}

View File

@@ -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'
)
},
}

View File

@@ -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')
},
}

View File

@@ -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'
)
},
}

View File

@@ -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')
},
}

View File

@@ -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'
)
},
}

View File

@@ -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

View File

@@ -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'
)
}
}

View File

@@ -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'
)
}
}

View File

@@ -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')
},
}

View File

@@ -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'
)
}
}

View File

@@ -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')
},
}

View File

@@ -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)
},
}