mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-19 19:55:51 +00:00
Removes all prepare methods (#1605)
* deprecate and alias prepareTransaction * delete prepareTransaction and replace methods in check-cancel * WIP update check-cash * remove all prepares * remove prepares from client * fix ts issues * remove tests * fix tests * additional cleanup * fix integration tests * remove console statement * re-add helper function * fix imports * fix more issues with integration tests Co-authored-by: Omar Khan <khancodegt@gmail.com>
This commit is contained in:
@@ -1,60 +0,0 @@
|
||||
import requests from '../fixtures/requests'
|
||||
import responses from '../fixtures/responses'
|
||||
import rippled from '../fixtures/rippled'
|
||||
import { setupClient, teardownClient } from '../setupClient'
|
||||
import { assertResultMatch, addressTests } from '../testUtils'
|
||||
|
||||
const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 }
|
||||
|
||||
describe('client.prepareCheckCancel', function () {
|
||||
beforeEach(setupClient)
|
||||
afterEach(teardownClient)
|
||||
|
||||
addressTests.forEach(function (test) {
|
||||
describe(test.type, function () {
|
||||
it('prepareCheckCancel', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const result = await this.client.prepareCheckCancel(
|
||||
test.address,
|
||||
requests.prepareCheckCancel.normal,
|
||||
)
|
||||
assertResultMatch(
|
||||
result,
|
||||
responses.prepareCheckCancel.normal,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
|
||||
it('with ticket', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
ticketSequence: 23,
|
||||
}
|
||||
const result = await this.client.prepareCheckCancel(
|
||||
test.address,
|
||||
requests.prepareCheckCancel.normal,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(
|
||||
result,
|
||||
responses.prepareCheckCancel.ticket,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,71 +0,0 @@
|
||||
import requests from '../fixtures/requests'
|
||||
import responses from '../fixtures/responses'
|
||||
import rippled from '../fixtures/rippled'
|
||||
import { setupClient, teardownClient } from '../setupClient'
|
||||
import { assertResultMatch, addressTests } from '../testUtils'
|
||||
|
||||
const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 }
|
||||
|
||||
describe('client.prepareCheckCash', function () {
|
||||
beforeEach(setupClient)
|
||||
afterEach(teardownClient)
|
||||
|
||||
addressTests.forEach(function (test) {
|
||||
describe(test.type, function () {
|
||||
it('prepareCheckCash amount', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const result = await this.client.prepareCheckCash(
|
||||
test.address,
|
||||
requests.prepareCheckCash.amount,
|
||||
)
|
||||
assertResultMatch(result, responses.prepareCheckCash.amount, 'prepare')
|
||||
})
|
||||
|
||||
it('prepareCheckCash deliverMin', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const result = await this.client.prepareCheckCash(
|
||||
test.address,
|
||||
requests.prepareCheckCash.deliverMin,
|
||||
)
|
||||
assertResultMatch(
|
||||
result,
|
||||
responses.prepareCheckCash.deliverMin,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
|
||||
it('with ticket', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
ticketSequence: 23,
|
||||
}
|
||||
const result = await this.client.prepareCheckCash(
|
||||
test.address,
|
||||
requests.prepareCheckCash.amount,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(result, responses.prepareCheckCash.ticket, 'prepare')
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,80 +0,0 @@
|
||||
import requests from '../fixtures/requests'
|
||||
import responses from '../fixtures/responses'
|
||||
import rippled from '../fixtures/rippled'
|
||||
import { setupClient, teardownClient } from '../setupClient'
|
||||
import { assertResultMatch, addressTests } from '../testUtils'
|
||||
|
||||
const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 }
|
||||
|
||||
describe('client.prepareCheckCreate', function () {
|
||||
beforeEach(setupClient)
|
||||
afterEach(teardownClient)
|
||||
|
||||
addressTests.forEach(function (test) {
|
||||
describe(test.type, function () {
|
||||
it('prepareCheckCreate', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
}
|
||||
const result = await this.client.prepareCheckCreate(
|
||||
test.address,
|
||||
requests.prepareCheckCreate.normal,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(
|
||||
result,
|
||||
responses.prepareCheckCreate.normal,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
|
||||
it('prepareCheckCreate full', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const result = await this.client.prepareCheckCreate(
|
||||
test.address,
|
||||
requests.prepareCheckCreate.full,
|
||||
)
|
||||
assertResultMatch(result, responses.prepareCheckCreate.full, 'prepare')
|
||||
})
|
||||
|
||||
it('prepareCheckCreate with ticket', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
ticketSequence: 23,
|
||||
}
|
||||
const result = await this.client.prepareCheckCreate(
|
||||
test.address,
|
||||
requests.prepareCheckCreate.normal,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(
|
||||
result,
|
||||
responses.prepareCheckCreate.ticket,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,80 +0,0 @@
|
||||
import requests from '../fixtures/requests'
|
||||
import responses from '../fixtures/responses'
|
||||
import rippled from '../fixtures/rippled'
|
||||
import { setupClient, teardownClient } from '../setupClient'
|
||||
import { assertResultMatch, addressTests } from '../testUtils'
|
||||
|
||||
const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 }
|
||||
|
||||
describe('client.prepareEscrowCancellation', function () {
|
||||
beforeEach(setupClient)
|
||||
afterEach(teardownClient)
|
||||
|
||||
addressTests.forEach(function (test) {
|
||||
describe(test.type, function () {
|
||||
it('prepareEscrowCancellation', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const result = await this.client.prepareEscrowCancellation(
|
||||
test.address,
|
||||
requests.prepareEscrowCancellation.normal,
|
||||
instructionsWithMaxLedgerVersionOffset,
|
||||
)
|
||||
assertResultMatch(
|
||||
result,
|
||||
responses.prepareEscrowCancellation.normal,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
|
||||
it('prepareEscrowCancellation with memos', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const result = await this.client.prepareEscrowCancellation(
|
||||
test.address,
|
||||
requests.prepareEscrowCancellation.memos,
|
||||
)
|
||||
assertResultMatch(
|
||||
result,
|
||||
responses.prepareEscrowCancellation.memos,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
|
||||
it('with ticket', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
ticketSequence: 23,
|
||||
}
|
||||
const result = await this.client.prepareEscrowCancellation(
|
||||
test.address,
|
||||
requests.prepareEscrowCancellation.normal,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(
|
||||
result,
|
||||
responses.prepareEscrowCancellation.ticket,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,74 +0,0 @@
|
||||
import addresses from '../fixtures/addresses.json'
|
||||
import requests from '../fixtures/requests'
|
||||
import responses from '../fixtures/responses'
|
||||
import rippled from '../fixtures/rippled'
|
||||
import { setupClient, teardownClient } from '../setupClient'
|
||||
import { assertResultMatch } from '../testUtils'
|
||||
|
||||
const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 }
|
||||
|
||||
describe('client.prepareEscrowCreation', function () {
|
||||
beforeEach(setupClient)
|
||||
afterEach(teardownClient)
|
||||
|
||||
it('prepareEscrowCreation', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse('account_info', rippled.account_info.normal)
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
}
|
||||
const result = await this.client.prepareEscrowCreation(
|
||||
addresses.ACCOUNT,
|
||||
requests.prepareEscrowCreation.normal,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(result, responses.prepareEscrowCreation.normal, 'prepare')
|
||||
})
|
||||
|
||||
it('prepareEscrowCreation full', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse('account_info', rippled.account_info.normal)
|
||||
const result = await this.client.prepareEscrowCreation(
|
||||
addresses.ACCOUNT,
|
||||
requests.prepareEscrowCreation.full,
|
||||
)
|
||||
assertResultMatch(result, responses.prepareEscrowCreation.full, 'prepare')
|
||||
})
|
||||
|
||||
// it("prepareEscrowCreation - invalid", async function () {
|
||||
// this.mockRippled.addResponse("server_info", rippled.server_info.normal);
|
||||
// this.mockRippled.addResponse("fee", rippled.fee);
|
||||
// this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
|
||||
// this.mockRippled.addResponse("account_info", rippled.account_info.normal);
|
||||
// const escrow = { ...requests.prepareEscrowCreation.full };
|
||||
// delete escrow.amount; // Make invalid
|
||||
// await assertRejects(
|
||||
// this.client.prepareEscrowCreation(addresses.ACCOUNT, escrow),
|
||||
// this.client.errors.ValidationError,
|
||||
// 'instance.escrowCreation requires property "amount"'
|
||||
// );
|
||||
// });
|
||||
|
||||
it('with ticket', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse('account_info', rippled.account_info.normal)
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000396',
|
||||
ticketSequence: 23,
|
||||
}
|
||||
const result = await this.client.prepareEscrowCreation(
|
||||
addresses.ACCOUNT,
|
||||
requests.prepareEscrowCreation.normal,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(result, responses.prepareEscrowCreation.ticket, 'prepare')
|
||||
})
|
||||
})
|
||||
@@ -1,118 +0,0 @@
|
||||
import requests from '../fixtures/requests'
|
||||
import responses from '../fixtures/responses'
|
||||
import rippled from '../fixtures/rippled'
|
||||
import { setupClient, teardownClient } from '../setupClient'
|
||||
import { addressTests, assertRejects, assertResultMatch } from '../testUtils'
|
||||
|
||||
const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 }
|
||||
|
||||
describe('client.prepareEscrowExecution', function () {
|
||||
beforeEach(setupClient)
|
||||
afterEach(teardownClient)
|
||||
|
||||
addressTests.forEach(function (test) {
|
||||
describe(test.type, function () {
|
||||
it('prepareEscrowExecution', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const result = await this.client.prepareEscrowExecution(
|
||||
test.address,
|
||||
requests.prepareEscrowExecution.normal,
|
||||
instructionsWithMaxLedgerVersionOffset,
|
||||
)
|
||||
assertResultMatch(
|
||||
result,
|
||||
responses.prepareEscrowExecution.normal,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
|
||||
it('prepareEscrowExecution - simple', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const result = await this.client.prepareEscrowExecution(
|
||||
test.address,
|
||||
requests.prepareEscrowExecution.simple,
|
||||
)
|
||||
assertResultMatch(
|
||||
result,
|
||||
responses.prepareEscrowExecution.simple,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
|
||||
it('prepareEscrowExecution - no condition', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
await assertRejects(
|
||||
this.client.prepareEscrowExecution(
|
||||
test.address,
|
||||
requests.prepareEscrowExecution.noCondition,
|
||||
instructionsWithMaxLedgerVersionOffset,
|
||||
),
|
||||
this.client.errors.ValidationError,
|
||||
'"condition" and "fulfillment" fields on EscrowFinish must only be specified together.',
|
||||
)
|
||||
})
|
||||
|
||||
it('prepareEscrowExecution - no fulfillment', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
await assertRejects(
|
||||
this.client.prepareEscrowExecution(
|
||||
test.address,
|
||||
requests.prepareEscrowExecution.noFulfillment,
|
||||
instructionsWithMaxLedgerVersionOffset,
|
||||
),
|
||||
this.client.errors.ValidationError,
|
||||
'"condition" and "fulfillment" fields on EscrowFinish must only be specified together.',
|
||||
)
|
||||
})
|
||||
|
||||
it('with ticket', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000396',
|
||||
ticketSequence: 23,
|
||||
}
|
||||
const result = await this.client.prepareEscrowExecution(
|
||||
test.address,
|
||||
requests.prepareEscrowExecution.normal,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(
|
||||
result,
|
||||
responses.prepareEscrowExecution.ticket,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,107 +0,0 @@
|
||||
import requests from '../fixtures/requests'
|
||||
import responses from '../fixtures/responses'
|
||||
import rippled from '../fixtures/rippled'
|
||||
import { setupClient, teardownClient } from '../setupClient'
|
||||
import { assertResultMatch, addressTests } from '../testUtils'
|
||||
|
||||
const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 }
|
||||
|
||||
describe('client.prepareOrder', function () {
|
||||
beforeEach(setupClient)
|
||||
afterEach(teardownClient)
|
||||
|
||||
addressTests.forEach(function (test) {
|
||||
describe(test.type, function () {
|
||||
it('buy order', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const request = requests.prepareOrder.buy
|
||||
const result = await this.client.prepareOrder(test.address, request)
|
||||
assertResultMatch(result, responses.prepareOrder.buy, 'prepare')
|
||||
})
|
||||
|
||||
it('buy order with expiration', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const request = requests.prepareOrder.expiration
|
||||
const response = responses.prepareOrder.expiration
|
||||
const result = await this.client.prepareOrder(
|
||||
test.address,
|
||||
request,
|
||||
instructionsWithMaxLedgerVersionOffset,
|
||||
)
|
||||
assertResultMatch(result, response, 'prepare')
|
||||
})
|
||||
|
||||
it('sell order', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const request = requests.prepareOrder.sell
|
||||
const result = await this.client.prepareOrder(
|
||||
test.address,
|
||||
request,
|
||||
instructionsWithMaxLedgerVersionOffset,
|
||||
)
|
||||
assertResultMatch(result, responses.prepareOrder.sell, 'prepare')
|
||||
})
|
||||
|
||||
// it("invalid", async function () {
|
||||
// this.mockRippled.addResponse("server_info", rippled.server_info.normal);
|
||||
// this.mockRippled.addResponse("fee", rippled.fee);
|
||||
// this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
|
||||
// this.mockRippled.addResponse(
|
||||
// "account_info",
|
||||
// rippled.account_info.normal
|
||||
// );
|
||||
// const request = { ...requests.prepareOrder.sell };
|
||||
// delete request.direction; // Make invalid
|
||||
// await assertRejects(
|
||||
// this.client.prepareOrder(
|
||||
// test.address,
|
||||
// request,
|
||||
// instructionsWithMaxLedgerVersionOffset
|
||||
// ),
|
||||
// this.client.errors.ValidationError,
|
||||
// 'instance.order requires property "direction"'
|
||||
// );
|
||||
// });
|
||||
|
||||
it('with ticket', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const request = requests.prepareOrder.sell
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
ticketSequence: 23,
|
||||
}
|
||||
const result = await this.client.prepareOrder(
|
||||
test.address,
|
||||
request,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(result, responses.prepareOrder.ticket, 'prepare')
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,123 +0,0 @@
|
||||
import requests from '../fixtures/requests'
|
||||
import responses from '../fixtures/responses'
|
||||
import rippled from '../fixtures/rippled'
|
||||
import { setupClient, teardownClient } from '../setupClient'
|
||||
import { assertResultMatch, addressTests } from '../testUtils'
|
||||
|
||||
const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 }
|
||||
|
||||
describe('client.prepareOrderCancellation', function () {
|
||||
beforeEach(setupClient)
|
||||
afterEach(teardownClient)
|
||||
|
||||
addressTests.forEach(function (test) {
|
||||
describe(test.type, function () {
|
||||
it('prepareOrderCancellation', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const request = requests.prepareOrderCancellation.simple
|
||||
const result = await this.client.prepareOrderCancellation(
|
||||
test.address,
|
||||
request,
|
||||
instructionsWithMaxLedgerVersionOffset,
|
||||
)
|
||||
assertResultMatch(
|
||||
result,
|
||||
responses.prepareOrderCancellation.normal,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
|
||||
it('no instructions', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const request = requests.prepareOrderCancellation.simple
|
||||
const result = await this.client.prepareOrderCancellation(
|
||||
test.address,
|
||||
request,
|
||||
)
|
||||
assertResultMatch(
|
||||
result,
|
||||
responses.prepareOrderCancellation.noInstructions,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
|
||||
it('with memos', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const request = requests.prepareOrderCancellation.withMemos
|
||||
const result = await this.client.prepareOrderCancellation(
|
||||
test.address,
|
||||
request,
|
||||
)
|
||||
assertResultMatch(
|
||||
result,
|
||||
responses.prepareOrderCancellation.withMemos,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
|
||||
// it("invalid", async function () {
|
||||
// this.mockRippled.addResponse("server_info", rippled.server_info.normal);
|
||||
// this.mockRippled.addResponse("fee", rippled.fee);
|
||||
// this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
|
||||
// this.mockRippled.addResponse(
|
||||
// "account_info",
|
||||
// rippled.account_info.normal
|
||||
// );
|
||||
// const request = {
|
||||
// ...requests.prepareOrderCancellation.withMemos,
|
||||
// };
|
||||
// delete request.orderSequence; // Make invalid
|
||||
|
||||
// await assertRejects(
|
||||
// this.client.prepareOrderCancellation(test.address, request),
|
||||
// this.client.errors.ValidationError,
|
||||
// 'instance.orderCancellation requires property "orderSequence"'
|
||||
// );
|
||||
// });
|
||||
|
||||
it('with ticket', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const request = requests.prepareOrderCancellation.simple
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
ticketSequence: 23,
|
||||
}
|
||||
const result = await this.client.prepareOrderCancellation(
|
||||
test.address,
|
||||
request,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(
|
||||
result,
|
||||
responses.prepareOrderCancellation.ticket,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,663 +0,0 @@
|
||||
import { ValidationError } from 'xrpl-local/common/errors'
|
||||
|
||||
import requests from '../fixtures/requests'
|
||||
import responses from '../fixtures/responses'
|
||||
import rippled from '../fixtures/rippled'
|
||||
import { setupClient, teardownClient } from '../setupClient'
|
||||
import { assertResultMatch, addressTests, assertRejects } from '../testUtils'
|
||||
|
||||
const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 }
|
||||
const { preparePayment: REQUEST_FIXTURES } = requests
|
||||
const { preparePayment: RESPONSE_FIXTURES } = responses
|
||||
const RECIPIENT_ADDRESS = 'rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo'
|
||||
|
||||
describe('client.preparePayment', function () {
|
||||
beforeEach(setupClient)
|
||||
afterEach(teardownClient)
|
||||
|
||||
addressTests.forEach(function (test) {
|
||||
describe(test.type, function () {
|
||||
it('normal', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
}
|
||||
const response = await this.client.preparePayment(
|
||||
test.address,
|
||||
REQUEST_FIXTURES.normal,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(response, RESPONSE_FIXTURES.normal, 'prepare')
|
||||
})
|
||||
|
||||
it('min amount xrp', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
}
|
||||
const response = await this.client.preparePayment(
|
||||
test.address,
|
||||
REQUEST_FIXTURES.minAmountXRP,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(response, RESPONSE_FIXTURES.minAmountXRP, 'prepare')
|
||||
})
|
||||
|
||||
it('min amount xrp2xrp', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const response = await this.client.preparePayment(
|
||||
test.address,
|
||||
REQUEST_FIXTURES.minAmount,
|
||||
instructionsWithMaxLedgerVersionOffset,
|
||||
)
|
||||
assertResultMatch(
|
||||
response,
|
||||
RESPONSE_FIXTURES.minAmountXRPXRP,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
|
||||
it('XRP to XRP', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const payment = {
|
||||
source: {
|
||||
address: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
|
||||
maxAmount: { value: '1', currency: 'XRP' },
|
||||
},
|
||||
destination: {
|
||||
address: 'rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo',
|
||||
amount: { value: '1', currency: 'XRP' },
|
||||
},
|
||||
}
|
||||
const expected = {
|
||||
txJSON:
|
||||
'{"TransactionType":"Payment","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Destination":"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo","Amount":"1000000","Flags":2147483648,"LastLedgerSequence":8820051,"Sequence":23,"Fee":"12"}',
|
||||
instructions: {
|
||||
fee: '0.000012',
|
||||
sequence: 23,
|
||||
maxLedgerVersion: 8820051,
|
||||
},
|
||||
}
|
||||
const response = await this.client.preparePayment(
|
||||
test.address,
|
||||
payment,
|
||||
instructionsWithMaxLedgerVersionOffset,
|
||||
)
|
||||
assertResultMatch(response, expected, 'prepare')
|
||||
})
|
||||
|
||||
it('XRP drops to XRP drops', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const payment = {
|
||||
source: {
|
||||
address: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
|
||||
maxAmount: { value: '1000000', currency: 'drops' },
|
||||
},
|
||||
destination: {
|
||||
address: 'rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo',
|
||||
amount: { value: '1000000', currency: 'drops' },
|
||||
},
|
||||
}
|
||||
const expected = {
|
||||
txJSON:
|
||||
'{"TransactionType":"Payment","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Destination":"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo","Amount":"1000000","Flags":2147483648,"LastLedgerSequence":8820051,"Sequence":23,"Fee":"12"}',
|
||||
instructions: {
|
||||
fee: '0.000012',
|
||||
sequence: 23,
|
||||
maxLedgerVersion: 8820051,
|
||||
},
|
||||
}
|
||||
const response = await this.client.preparePayment(
|
||||
test.address,
|
||||
payment,
|
||||
instructionsWithMaxLedgerVersionOffset,
|
||||
)
|
||||
assertResultMatch(response, expected, 'prepare')
|
||||
})
|
||||
|
||||
it('XRP drops to XRP', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const payment = {
|
||||
source: {
|
||||
address: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
|
||||
maxAmount: { value: '1000000', currency: 'drops' },
|
||||
},
|
||||
destination: {
|
||||
address: 'rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo',
|
||||
amount: { value: '1', currency: 'XRP' },
|
||||
},
|
||||
}
|
||||
const expected = {
|
||||
txJSON:
|
||||
'{"TransactionType":"Payment","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Destination":"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo","Amount":"1000000","Flags":2147483648,"LastLedgerSequence":8820051,"Sequence":23,"Fee":"12"}',
|
||||
instructions: {
|
||||
fee: '0.000012',
|
||||
sequence: 23,
|
||||
maxLedgerVersion: 8820051,
|
||||
},
|
||||
}
|
||||
const response = await this.client.preparePayment(
|
||||
test.address,
|
||||
payment,
|
||||
instructionsWithMaxLedgerVersionOffset,
|
||||
)
|
||||
assertResultMatch(response, expected, 'prepare')
|
||||
})
|
||||
|
||||
it('XRP to XRP drops', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const payment = {
|
||||
source: {
|
||||
address: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
|
||||
maxAmount: { value: '1', currency: 'XRP' },
|
||||
},
|
||||
destination: {
|
||||
address: 'rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo',
|
||||
amount: { value: '1000000', currency: 'drops' },
|
||||
},
|
||||
}
|
||||
const expected = {
|
||||
txJSON:
|
||||
'{"TransactionType":"Payment","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Destination":"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo","Amount":"1000000","Flags":2147483648,"LastLedgerSequence":8820051,"Sequence":23,"Fee":"12"}',
|
||||
instructions: {
|
||||
fee: '0.000012',
|
||||
sequence: 23,
|
||||
maxLedgerVersion: 8820051,
|
||||
},
|
||||
}
|
||||
const response = await this.client.preparePayment(
|
||||
test.address,
|
||||
payment,
|
||||
instructionsWithMaxLedgerVersionOffset,
|
||||
)
|
||||
assertResultMatch(response, expected, 'prepare')
|
||||
})
|
||||
|
||||
// Errors
|
||||
it('rejects promise and does not throw when payment object is invalid', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const payment = {
|
||||
source: {
|
||||
address: test.address,
|
||||
// instead of `maxAmount`
|
||||
amount: { value: '1000', currency: 'drops' },
|
||||
},
|
||||
destination: {
|
||||
address: RECIPIENT_ADDRESS,
|
||||
amount: { value: '1000', currency: 'drops' },
|
||||
},
|
||||
}
|
||||
|
||||
return assertRejects(
|
||||
this.client.preparePayment(test.address, payment),
|
||||
ValidationError,
|
||||
'payment must specify either (source.maxAmount and destination.amount) or (source.amount and destination.minAmount)',
|
||||
)
|
||||
})
|
||||
|
||||
// it("rejects promise and does not throw when field is missing", async function () {
|
||||
// this.mockRippled.addResponse("server_info", rippled.server_info.normal);
|
||||
// this.mockRippled.addResponse("fee", rippled.fee);
|
||||
// this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
|
||||
// this.mockRippled.addResponse(
|
||||
// "account_info",
|
||||
// rippled.account_info.normal
|
||||
// );
|
||||
// // Marking as "any" to get around the fact that TS won't allow this.
|
||||
// const payment: any = {
|
||||
// source: { address: test.address },
|
||||
// destination: {
|
||||
// address: RECIPIENT_ADDRESS,
|
||||
// amount: { value: "1000", currency: "drops" },
|
||||
// },
|
||||
// };
|
||||
|
||||
// return assertRejects(
|
||||
// this.client.preparePayment(test.address, payment),
|
||||
// ValidationError,
|
||||
// "instance.payment.source is not exactly one from <sourceExactAdjustment>,<maxAdjustment>"
|
||||
// );
|
||||
// });
|
||||
|
||||
it('rejects promise and does not throw when fee exceeds maxFeeXRP', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const payment = {
|
||||
source: {
|
||||
address: test.address,
|
||||
maxAmount: { value: '1000', currency: 'drops' },
|
||||
},
|
||||
destination: {
|
||||
address: RECIPIENT_ADDRESS,
|
||||
amount: { value: '1000', currency: 'drops' },
|
||||
},
|
||||
}
|
||||
return assertRejects(
|
||||
this.client.preparePayment(test.address, payment, { fee: '3' }),
|
||||
ValidationError,
|
||||
'Fee of 3 XRP exceeds max of 2 XRP. To use this fee, increase `maxFeeXRP` in the Client constructor.',
|
||||
)
|
||||
})
|
||||
|
||||
it('XRP to XRP no partial', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
return assertRejects(
|
||||
this.client.preparePayment(
|
||||
test.address,
|
||||
REQUEST_FIXTURES.wrongPartial,
|
||||
),
|
||||
ValidationError,
|
||||
'XRP to XRP payments cannot be partial payments',
|
||||
)
|
||||
})
|
||||
|
||||
it('address must match payment.source.address', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
return assertRejects(
|
||||
this.client.preparePayment(
|
||||
test.address,
|
||||
REQUEST_FIXTURES.wrongAddress,
|
||||
),
|
||||
ValidationError,
|
||||
'address must match payment.source.address',
|
||||
)
|
||||
})
|
||||
|
||||
it('wrong amount', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
return assertRejects(
|
||||
this.client.preparePayment(
|
||||
test.address,
|
||||
REQUEST_FIXTURES.wrongAmount,
|
||||
),
|
||||
ValidationError,
|
||||
'payment must specify either (source.maxAmount and destination.amount) or (source.amount and destination.minAmount)',
|
||||
)
|
||||
})
|
||||
|
||||
it('throws when fee exceeds 2 XRP', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
fee: '2.1',
|
||||
}
|
||||
return assertRejects(
|
||||
this.client.preparePayment(
|
||||
test.address,
|
||||
REQUEST_FIXTURES.normal,
|
||||
localInstructions,
|
||||
),
|
||||
ValidationError,
|
||||
'Fee of 2.1 XRP exceeds max of 2 XRP. To use this fee, increase `maxFeeXRP` in the Client constructor.',
|
||||
)
|
||||
})
|
||||
|
||||
// 'preparePayment with all options specified': async (client, test.address) => {
|
||||
// const ledgerResponse = await this.client.request({command: 'ledger', ledger_index: 'validated'})
|
||||
// const version = ledgerResponse.result.ledger_index
|
||||
// const localInstructions = {
|
||||
// maxLedgerVersion: version + 100,
|
||||
// fee: '0.000012'
|
||||
// }
|
||||
// const response = await this.client.preparePayment(
|
||||
// test.address,
|
||||
// REQUEST_FIXTURES.allOptions,
|
||||
// localInstructions
|
||||
// )
|
||||
// assertResultMatch(response, RESPONSE_FIXTURES.allOptions, 'prepare')
|
||||
// },
|
||||
|
||||
it('preparePayment without counterparty set', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
sequence: 23,
|
||||
}
|
||||
const response = await this.client.preparePayment(
|
||||
test.address,
|
||||
REQUEST_FIXTURES.noCounterparty,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(response, RESPONSE_FIXTURES.noCounterparty, 'prepare')
|
||||
})
|
||||
|
||||
it('preparePayment with source.amount/destination.minAmount can be signed', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
// See also: 'sign succeeds with source.amount/destination.minAmount'
|
||||
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
sequence: 23,
|
||||
}
|
||||
const response = await this.client.preparePayment(
|
||||
test.address,
|
||||
REQUEST_FIXTURES.noCounterparty,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(response, RESPONSE_FIXTURES.noCounterparty, 'prepare')
|
||||
})
|
||||
|
||||
it('destination.minAmount', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const response = await this.client.preparePayment(
|
||||
test.address,
|
||||
responses.getPaths.sendAll[0],
|
||||
instructionsWithMaxLedgerVersionOffset,
|
||||
)
|
||||
assertResultMatch(response, RESPONSE_FIXTURES.minAmount, 'prepare')
|
||||
})
|
||||
|
||||
it('caps fee at 2 XRP by default', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
this.client.feeCushion = 1000000
|
||||
const expectedResponse = {
|
||||
txJSON:
|
||||
'{"Flags":2147483648,"TransactionType":"Payment","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Destination":"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo","Amount":{"value":"0.01","currency":"USD","issuer":"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"},"SendMax":{"value":"0.01","currency":"USD","issuer":"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"},"LastLedgerSequence":8820051,"Fee":"2000000","Sequence":23}',
|
||||
instructions: {
|
||||
fee: '2',
|
||||
sequence: 23,
|
||||
maxLedgerVersion: 8820051,
|
||||
},
|
||||
}
|
||||
const response = await this.client.preparePayment(
|
||||
test.address,
|
||||
REQUEST_FIXTURES.normal,
|
||||
instructionsWithMaxLedgerVersionOffset,
|
||||
)
|
||||
assertResultMatch(response, expectedResponse, 'prepare')
|
||||
})
|
||||
|
||||
it('allows fee exceeding 2 XRP when maxFeeXRP is higher', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
this.client.maxFeeXRP = '2.2'
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
fee: '2.1',
|
||||
}
|
||||
const expectedResponse = {
|
||||
txJSON:
|
||||
'{"Flags":2147483648,"TransactionType":"Payment","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Destination":"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo","Amount":{"value":"0.01","currency":"USD","issuer":"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"},"SendMax":{"value":"0.01","currency":"USD","issuer":"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"},"LastLedgerSequence":8820051,"Fee":"2100000","Sequence":23}',
|
||||
instructions: {
|
||||
fee: '2.1',
|
||||
sequence: 23,
|
||||
maxLedgerVersion: 8820051,
|
||||
},
|
||||
}
|
||||
const response = await this.client.preparePayment(
|
||||
test.address,
|
||||
REQUEST_FIXTURES.normal,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(response, expectedResponse, 'prepare')
|
||||
})
|
||||
|
||||
it('fee - default maxFee of 2 XRP', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
this.client.feeCushion = 1000000
|
||||
const expectedResponse = {
|
||||
txJSON:
|
||||
'{"Flags":2147483648,"TransactionType":"Payment","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Destination":"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo","Amount":{"value":"0.01","currency":"USD","issuer":"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"},"SendMax":{"value":"0.01","currency":"USD","issuer":"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"},"LastLedgerSequence":8820051,"Fee":"2000000","Sequence":23}',
|
||||
instructions: {
|
||||
fee: '2',
|
||||
sequence: 23,
|
||||
maxLedgerVersion: 8820051,
|
||||
},
|
||||
}
|
||||
const response = await this.client.preparePayment(
|
||||
test.address,
|
||||
requests.preparePayment.normal,
|
||||
instructionsWithMaxLedgerVersionOffset,
|
||||
)
|
||||
assertResultMatch(response, expectedResponse, 'prepare')
|
||||
})
|
||||
|
||||
it('fee - capped to maxFeeXRP when maxFee exceeds maxFeeXRP', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
this.client.feeCushion = 1000000
|
||||
this.client.maxFeeXRP = '3'
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '4',
|
||||
}
|
||||
const expectedResponse = {
|
||||
txJSON:
|
||||
'{"Flags":2147483648,"TransactionType":"Payment","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Destination":"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo","Amount":{"value":"0.01","currency":"USD","issuer":"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"},"SendMax":{"value":"0.01","currency":"USD","issuer":"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"},"LastLedgerSequence":8820051,"Fee":"3000000","Sequence":23}',
|
||||
instructions: {
|
||||
fee: '3',
|
||||
sequence: 23,
|
||||
maxLedgerVersion: 8820051,
|
||||
},
|
||||
}
|
||||
const response = await this.client.preparePayment(
|
||||
test.address,
|
||||
requests.preparePayment.normal,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(response, expectedResponse, 'prepare')
|
||||
})
|
||||
|
||||
it('fee - capped to maxFee', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
this.client.feeCushion = 1000000
|
||||
this.client.maxFeeXRP = '5'
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '4',
|
||||
}
|
||||
const expectedResponse = {
|
||||
txJSON:
|
||||
'{"Flags":2147483648,"TransactionType":"Payment","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Destination":"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo","Amount":{"value":"0.01","currency":"USD","issuer":"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"},"SendMax":{"value":"0.01","currency":"USD","issuer":"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"},"LastLedgerSequence":8820051,"Fee":"4000000","Sequence":23}',
|
||||
instructions: {
|
||||
fee: '4',
|
||||
sequence: 23,
|
||||
maxLedgerVersion: 8820051,
|
||||
},
|
||||
}
|
||||
const response = await this.client.preparePayment(
|
||||
test.address,
|
||||
requests.preparePayment.normal,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(response, expectedResponse, 'prepare')
|
||||
})
|
||||
|
||||
// 'fee - calculated fee does not use more than 6 decimal places': async (
|
||||
// client,
|
||||
// test.address
|
||||
// ) => {
|
||||
// this.client.connection.request({
|
||||
// command: 'config',
|
||||
// data: {loadFactor: 5407.96875}
|
||||
// })
|
||||
// const expectedResponse = {
|
||||
// txJSON:
|
||||
// '{"Flags":2147483648,"TransactionType":"Payment","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Destination":"rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo","Amount":{"value":"0.01","currency":"USD","issuer":"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"},"SendMax":{"value":"0.01","currency":"USD","issuer":"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"},"LastLedgerSequence":8820051,"Fee":"64896","Sequence":23}',
|
||||
// instructions: {
|
||||
// fee: '0.064896',
|
||||
// sequence: 23,
|
||||
// maxLedgerVersion: 8820051
|
||||
// }
|
||||
// }
|
||||
// const response = await this.client.preparePayment(
|
||||
// test.address,
|
||||
// requests.preparePayment.normal,
|
||||
// instructionsWithMaxLedgerVersionOffset
|
||||
// )
|
||||
// assertResultMatch(response, expectedResponse, 'prepare')
|
||||
// },
|
||||
|
||||
// Tickets
|
||||
// 'preparePayment with ticketSequence': async (client, test.address) => {
|
||||
// const ledgerResponse = await this.client.request({
|
||||
// command: 'ledger',
|
||||
// ledger_index: 'validated'
|
||||
// })
|
||||
// const version = ledgerResponse.result.ledger_index
|
||||
// const localInstructions = {
|
||||
// maxLedgerVersion: version + 100,
|
||||
// fee: '0.000012',
|
||||
// ticketSequence: 23
|
||||
// }
|
||||
// const response = await this.client.preparePayment(
|
||||
// test.address,
|
||||
// REQUEST_FIXTURES.allOptions,
|
||||
// localInstructions
|
||||
// )
|
||||
// assertResultMatch(response, RESPONSE_FIXTURES.ticketSequence, 'prepare')
|
||||
// },
|
||||
|
||||
// 'throws when both sequence and ticketSequence are set': async (
|
||||
// client,
|
||||
// test.address
|
||||
// ) => {
|
||||
// const ledgerResponse = await this.client.request({
|
||||
// command: 'ledger',
|
||||
// ledger_index: 'validated'
|
||||
// })
|
||||
// const version = ledgerResponse.result.ledger_index
|
||||
// const localInstructions = {
|
||||
// maxLedgerVersion: version + 100,
|
||||
// fee: '0.000012',
|
||||
// ticketSequence: 23,
|
||||
// sequence: 12
|
||||
// }
|
||||
// return assertRejects(
|
||||
// this.client.preparePayment(
|
||||
// test.address,
|
||||
// REQUEST_FIXTURES.allOptions,
|
||||
// localInstructions
|
||||
// ),
|
||||
// ValidationError,
|
||||
// 'instance.instructions is of prohibited type [object Object]'
|
||||
// )
|
||||
// }
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,155 +0,0 @@
|
||||
import { assert } from 'chai'
|
||||
|
||||
import requests from '../fixtures/requests'
|
||||
import responses from '../fixtures/responses'
|
||||
import rippled from '../fixtures/rippled'
|
||||
import { setupClient, teardownClient } from '../setupClient'
|
||||
import { assertResultMatch, addressTests } from '../testUtils'
|
||||
|
||||
const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 }
|
||||
const { preparePaymentChannelClaim: REQUEST_FIXTURES } = requests
|
||||
const { preparePaymentChannelClaim: RESPONSE_FIXTURES } = responses
|
||||
|
||||
describe('client.preparePaymentChannelClaim', function () {
|
||||
beforeEach(setupClient)
|
||||
afterEach(teardownClient)
|
||||
|
||||
addressTests.forEach(function (test) {
|
||||
describe(test.type, function () {
|
||||
it('default', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
}
|
||||
const response = await this.client.preparePaymentChannelClaim(
|
||||
test.address,
|
||||
REQUEST_FIXTURES.normal,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(response, RESPONSE_FIXTURES.normal, 'prepare')
|
||||
})
|
||||
|
||||
it('with renew', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
}
|
||||
const response = await this.client.preparePaymentChannelClaim(
|
||||
test.address,
|
||||
REQUEST_FIXTURES.renew,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(response, RESPONSE_FIXTURES.renew, 'prepare')
|
||||
})
|
||||
|
||||
it('with close', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
}
|
||||
const response = await this.client.preparePaymentChannelClaim(
|
||||
test.address,
|
||||
REQUEST_FIXTURES.close,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(response, RESPONSE_FIXTURES.close, 'prepare')
|
||||
})
|
||||
|
||||
it('with ticket', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
ticketSequence: 23,
|
||||
}
|
||||
const response = await this.client.preparePaymentChannelClaim(
|
||||
test.address,
|
||||
REQUEST_FIXTURES.normal,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(response, RESPONSE_FIXTURES.ticket, 'prepare')
|
||||
})
|
||||
|
||||
it('rejects Promise on preparePaymentChannelClaim with renew and close', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
try {
|
||||
const prepared = await this.client.preparePaymentChannelClaim(
|
||||
test.address,
|
||||
REQUEST_FIXTURES.full,
|
||||
)
|
||||
throw new Error(
|
||||
`Expected method to reject. Prepared transaction: ${JSON.stringify(
|
||||
prepared,
|
||||
)}`,
|
||||
)
|
||||
} catch (err) {
|
||||
assert.strictEqual(err.name, 'ValidationError')
|
||||
assert.strictEqual(
|
||||
err.message,
|
||||
'"renew" and "close" flags on PaymentChannelClaim are mutually exclusive',
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it('rejects Promise on preparePaymentChannelClaim with no signature', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
try {
|
||||
const prepared = await this.client.preparePaymentChannelClaim(
|
||||
test.address,
|
||||
REQUEST_FIXTURES.noSignature,
|
||||
)
|
||||
throw new Error(
|
||||
`Expected method to reject. Prepared transaction: ${JSON.stringify(
|
||||
prepared,
|
||||
)}`,
|
||||
)
|
||||
} catch (err) {
|
||||
assert.strictEqual(err.name, 'ValidationError')
|
||||
assert.strictEqual(
|
||||
err.message,
|
||||
'"signature" and "publicKey" fields on PaymentChannelClaim must only be specified together.',
|
||||
)
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,72 +0,0 @@
|
||||
import addresses from '../fixtures/addresses.json'
|
||||
import requests from '../fixtures/requests'
|
||||
import responses from '../fixtures/responses'
|
||||
import rippled from '../fixtures/rippled'
|
||||
import { setupClient, teardownClient } from '../setupClient'
|
||||
import { assertResultMatch } from '../testUtils'
|
||||
|
||||
const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 }
|
||||
|
||||
describe('client.preparePaymentChannelCreate', function () {
|
||||
beforeEach(setupClient)
|
||||
afterEach(teardownClient)
|
||||
|
||||
it('preparePaymentChannelCreate', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse('account_info', rippled.account_info.normal)
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
}
|
||||
const result = await this.client.preparePaymentChannelCreate(
|
||||
addresses.ACCOUNT,
|
||||
requests.preparePaymentChannelCreate.normal,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(
|
||||
result,
|
||||
responses.preparePaymentChannelCreate.normal,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
|
||||
it('preparePaymentChannelCreate full', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse('account_info', rippled.account_info.normal)
|
||||
const result = await this.client.preparePaymentChannelCreate(
|
||||
addresses.ACCOUNT,
|
||||
requests.preparePaymentChannelCreate.full,
|
||||
)
|
||||
assertResultMatch(
|
||||
result,
|
||||
responses.preparePaymentChannelCreate.full,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
|
||||
it('preparePaymentChannelCreate with ticket', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse('account_info', rippled.account_info.normal)
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
ticketSequence: 23,
|
||||
}
|
||||
const result = await this.client.preparePaymentChannelCreate(
|
||||
addresses.ACCOUNT,
|
||||
requests.preparePaymentChannelCreate.normal,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(
|
||||
result,
|
||||
responses.preparePaymentChannelCreate.ticket,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -1,84 +0,0 @@
|
||||
import requests from '../fixtures/requests'
|
||||
import responses from '../fixtures/responses'
|
||||
import rippled from '../fixtures/rippled'
|
||||
import { setupClient, teardownClient } from '../setupClient'
|
||||
import { assertResultMatch, addressTests } from '../testUtils'
|
||||
|
||||
const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 }
|
||||
|
||||
describe('client.preparePaymentChannelFund', function () {
|
||||
beforeEach(setupClient)
|
||||
afterEach(teardownClient)
|
||||
|
||||
addressTests.forEach(function (test) {
|
||||
describe(test.type, function () {
|
||||
it('preparePaymentChannelFund', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
}
|
||||
const result = await this.client.preparePaymentChannelFund(
|
||||
test.address,
|
||||
requests.preparePaymentChannelFund.normal,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(
|
||||
result,
|
||||
responses.preparePaymentChannelFund.normal,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
|
||||
it('preparePaymentChannelFund full', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const result = await this.client.preparePaymentChannelFund(
|
||||
test.address,
|
||||
requests.preparePaymentChannelFund.full,
|
||||
)
|
||||
assertResultMatch(
|
||||
result,
|
||||
responses.preparePaymentChannelFund.full,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
|
||||
it('with ticket', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
ticketSequence: 23,
|
||||
}
|
||||
const result = await this.client.preparePaymentChannelFund(
|
||||
test.address,
|
||||
requests.preparePaymentChannelFund.normal,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(
|
||||
result,
|
||||
responses.preparePaymentChannelFund.ticket,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,431 +0,0 @@
|
||||
import { assert } from 'chai'
|
||||
|
||||
import { FormattedSettings } from '../../src/common/types/objects'
|
||||
import requests from '../fixtures/requests'
|
||||
import responses from '../fixtures/responses'
|
||||
import rippled from '../fixtures/rippled'
|
||||
import { setupClient, teardownClient } from '../setupClient'
|
||||
import { assertResultMatch, addressTests } from '../testUtils'
|
||||
|
||||
const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 }
|
||||
|
||||
describe('client.prepareSettings', function () {
|
||||
beforeEach(setupClient)
|
||||
afterEach(teardownClient)
|
||||
|
||||
addressTests.forEach(function (test) {
|
||||
describe(test.type, function () {
|
||||
it('simple test', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const response = await this.client.prepareSettings(
|
||||
test.address,
|
||||
requests.prepareSettings.domain,
|
||||
instructionsWithMaxLedgerVersionOffset,
|
||||
)
|
||||
assertResultMatch(response, responses.prepareSettings.flags, 'prepare')
|
||||
})
|
||||
it('no maxLedgerVersion', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const response = await this.client.prepareSettings(
|
||||
test.address,
|
||||
requests.prepareSettings.domain,
|
||||
{
|
||||
maxLedgerVersion: null as unknown as undefined,
|
||||
},
|
||||
)
|
||||
assertResultMatch(
|
||||
response,
|
||||
responses.prepareSettings.noMaxLedgerVersion,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
it('no instructions', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const response = await this.client.prepareSettings(
|
||||
test.address,
|
||||
requests.prepareSettings.domain,
|
||||
)
|
||||
assertResultMatch(
|
||||
response,
|
||||
responses.prepareSettings.noInstructions,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
it('regularKey', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const regularKey = { regularKey: 'rAR8rR8sUkBoCZFawhkWzY4Y5YoyuznwD' }
|
||||
const response = await this.client.prepareSettings(
|
||||
test.address,
|
||||
regularKey,
|
||||
instructionsWithMaxLedgerVersionOffset,
|
||||
)
|
||||
assertResultMatch(
|
||||
response,
|
||||
responses.prepareSettings.regularKey,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
it('remove regularKey', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const regularKey = { regularKey: null }
|
||||
const response = await this.client.prepareSettings(
|
||||
test.address,
|
||||
regularKey as unknown as FormattedSettings,
|
||||
instructionsWithMaxLedgerVersionOffset,
|
||||
)
|
||||
assertResultMatch(
|
||||
response,
|
||||
responses.prepareSettings.removeRegularKey,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
it('flag set', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const settings = { requireDestinationTag: true }
|
||||
const response = await this.client.prepareSettings(
|
||||
test.address,
|
||||
settings,
|
||||
instructionsWithMaxLedgerVersionOffset,
|
||||
)
|
||||
assertResultMatch(
|
||||
response,
|
||||
responses.prepareSettings.flagSet,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
it('flag clear', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const settings = { requireDestinationTag: false }
|
||||
const response = await this.client.prepareSettings(
|
||||
test.address,
|
||||
settings,
|
||||
instructionsWithMaxLedgerVersionOffset,
|
||||
)
|
||||
assertResultMatch(
|
||||
response,
|
||||
responses.prepareSettings.flagClear,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
it('set depositAuth flag', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const settings = { depositAuth: true }
|
||||
const response = await this.client.prepareSettings(
|
||||
test.address,
|
||||
settings,
|
||||
instructionsWithMaxLedgerVersionOffset,
|
||||
)
|
||||
assertResultMatch(
|
||||
response,
|
||||
responses.prepareSettings.flagSetDepositAuth,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
it('clear depositAuth flag', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const settings = { depositAuth: false }
|
||||
const response = await this.client.prepareSettings(
|
||||
test.address,
|
||||
settings,
|
||||
instructionsWithMaxLedgerVersionOffset,
|
||||
)
|
||||
assertResultMatch(
|
||||
response,
|
||||
responses.prepareSettings.flagClearDepositAuth,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
it('integer field clear', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const settings = { transferRate: null }
|
||||
const response = await this.client.prepareSettings(
|
||||
test.address,
|
||||
settings,
|
||||
instructionsWithMaxLedgerVersionOffset,
|
||||
)
|
||||
assert(response)
|
||||
assert.strictEqual(JSON.parse(response.txJSON).TransferRate, 0)
|
||||
})
|
||||
it('set transferRate', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const settings = { transferRate: 1 }
|
||||
const response = await this.client.prepareSettings(
|
||||
test.address,
|
||||
settings,
|
||||
instructionsWithMaxLedgerVersionOffset,
|
||||
)
|
||||
assertResultMatch(
|
||||
response,
|
||||
responses.prepareSettings.setTransferRate,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
it('set signers', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const settings = requests.prepareSettings.signers.normal
|
||||
const response = await this.client.prepareSettings(
|
||||
test.address,
|
||||
settings,
|
||||
instructionsWithMaxLedgerVersionOffset,
|
||||
)
|
||||
assertResultMatch(
|
||||
response,
|
||||
responses.prepareSettings.signers,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
// it("signers no threshold", async function () {
|
||||
// this.mockRippled.addResponse("server_info", rippled.server_info.normal);
|
||||
// this.mockRippled.addResponse("fee", rippled.fee);
|
||||
// this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
|
||||
// this.mockRippled.addResponse(
|
||||
// "account_info",
|
||||
// rippled.account_info.normal
|
||||
// );
|
||||
// const settings = requests.prepareSettings.signers.noThreshold;
|
||||
// try {
|
||||
// const response = await this.client.prepareSettings(
|
||||
// test.address,
|
||||
// settings,
|
||||
// instructionsWithMaxLedgerVersionOffset
|
||||
// );
|
||||
// throw new Error(
|
||||
// `Expected method to reject. Prepared transaction: ${JSON.stringify(
|
||||
// response
|
||||
// )}`
|
||||
// );
|
||||
// } catch (err) {
|
||||
// assert.strictEqual(
|
||||
// err.message,
|
||||
// 'instance.settings.signers requires property "threshold"'
|
||||
// );
|
||||
// assert.strictEqual(err.name, "ValidationError");
|
||||
// }
|
||||
// });
|
||||
it('signers no weights', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const settings = requests.prepareSettings.signers.noWeights
|
||||
const localInstructions = {
|
||||
signersCount: 1,
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
}
|
||||
const response = await this.client.prepareSettings(
|
||||
test.address,
|
||||
settings,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(
|
||||
response,
|
||||
responses.prepareSettings.noWeights,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
it('fee for multisign', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const localInstructions = {
|
||||
signersCount: 4,
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
}
|
||||
const response = await this.client.prepareSettings(
|
||||
test.address,
|
||||
requests.prepareSettings.domain,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(
|
||||
response,
|
||||
responses.prepareSettings.flagsMultisign,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
it('no signer list', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const settings = requests.prepareSettings.noSignerEntries
|
||||
const localInstructions = {
|
||||
signersCount: 1,
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
}
|
||||
const response = await this.client.prepareSettings(
|
||||
test.address,
|
||||
settings,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(
|
||||
response,
|
||||
responses.prepareSettings.noSignerList,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
// it("invalid", async function () {
|
||||
// this.mockRippled.addResponse("server_info", rippled.server_info.normal);
|
||||
// this.mockRippled.addResponse("fee", rippled.fee);
|
||||
// this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
|
||||
// this.mockRippled.addResponse(
|
||||
// "account_info",
|
||||
// rippled.account_info.normal
|
||||
// );
|
||||
// // domain must be a string
|
||||
// const settings = { ...requests.prepareSettings.domain, domain: 123 };
|
||||
// const localInstructions = {
|
||||
// signersCount: 4,
|
||||
// ...instructionsWithMaxLedgerVersionOffset,
|
||||
// };
|
||||
|
||||
// try {
|
||||
// const response = await this.client.prepareSettings(
|
||||
// test.address,
|
||||
// settings,
|
||||
// localInstructions
|
||||
// );
|
||||
// throw new Error(
|
||||
// `Expected method to reject. Prepared transaction: ${JSON.stringify(
|
||||
// response
|
||||
// )}`
|
||||
// );
|
||||
// } catch (err) {
|
||||
// assert.strictEqual(
|
||||
// err.message,
|
||||
// "instance.settings.domain is not of a type(s) string"
|
||||
// );
|
||||
// assert.strictEqual(err.name, "ValidationError");
|
||||
// }
|
||||
// });
|
||||
it('offline', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const secret = 'shsWGZcmZz6YsWWmcnpfr6fLTdtFV'
|
||||
|
||||
const settings = requests.prepareSettings.domain
|
||||
const instructions = {
|
||||
sequence: 23,
|
||||
maxLedgerVersion: 8820051,
|
||||
fee: '0.000012',
|
||||
}
|
||||
const result = await this.client.prepareSettings(
|
||||
test.address,
|
||||
settings,
|
||||
instructions,
|
||||
)
|
||||
assertResultMatch(result, responses.prepareSettings.flags, 'prepare')
|
||||
assert.deepEqual(
|
||||
this.client.sign(result.txJSON, secret),
|
||||
responses.prepareSettings.signed,
|
||||
)
|
||||
})
|
||||
it('prepare settings with ticket', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const instructions = {
|
||||
ticketSequence: 23,
|
||||
maxLedgerVersion: 8820051,
|
||||
fee: '0.000012',
|
||||
}
|
||||
const response = await this.client.prepareSettings(
|
||||
test.address,
|
||||
requests.prepareSettings.domain,
|
||||
instructions,
|
||||
)
|
||||
assertResultMatch(response, responses.prepareSettings.ticket, 'prepare')
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,75 +0,0 @@
|
||||
import rippled from '../fixtures/rippled'
|
||||
import { setupClient, teardownClient } from '../setupClient'
|
||||
import { assertResultMatch, addressTests } from '../testUtils'
|
||||
// import responses from '../fixtures/responses'
|
||||
// import requests from '../fixtures/requests'
|
||||
// import {ValidationError} from 'xrpl-local/common/errors'
|
||||
// import binary from 'ripple-binary-codec'
|
||||
// import {assert} from 'chai'
|
||||
// import {Client} from 'xrpl-local'
|
||||
// import * as schemaValidator from 'xrpl-local/common/schema-validator'
|
||||
|
||||
// const instructionsWithMaxLedgerVersionOffset = {maxLedgerVersionOffset: 100}
|
||||
// const {preparePayment: REQUEST_FIXTURES} = requests
|
||||
// const {preparePayment: RESPONSE_FIXTURES} = responses
|
||||
// const ADDRESS = 'rpZc4mVfWUif9CRoHRKKcmhu1nx2xktxBo'
|
||||
|
||||
describe('client.prepareTicket', function () {
|
||||
beforeEach(setupClient)
|
||||
afterEach(teardownClient)
|
||||
|
||||
addressTests.forEach(function (test) {
|
||||
describe(test.type, function () {
|
||||
it('creates a ticket successfully with a sequence number', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
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 this.client.prepareTicketCreate(test.address, 2)
|
||||
assertResultMatch(response, expected, 'prepare')
|
||||
})
|
||||
|
||||
it('creates a ticket successfully with another ticket', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
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 this.client.prepareTicketCreate(
|
||||
test.address,
|
||||
1,
|
||||
instructions,
|
||||
)
|
||||
assertResultMatch(response, expected, 'prepare')
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,126 +0,0 @@
|
||||
import requests from '../fixtures/requests'
|
||||
import responses from '../fixtures/responses'
|
||||
import rippled from '../fixtures/rippled'
|
||||
import { setupClient, teardownClient } from '../setupClient'
|
||||
import { assertResultMatch, addressTests } from '../testUtils'
|
||||
|
||||
const instructionsWithMaxLedgerVersionOffset = { maxLedgerVersionOffset: 100 }
|
||||
|
||||
describe('client.prepareTrustline', function () {
|
||||
beforeEach(setupClient)
|
||||
afterEach(teardownClient)
|
||||
|
||||
addressTests.forEach(function (test) {
|
||||
describe(test.type, function () {
|
||||
it('simple', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const result = await this.client.prepareTrustline(
|
||||
test.address,
|
||||
requests.prepareTrustline.simple,
|
||||
instructionsWithMaxLedgerVersionOffset,
|
||||
)
|
||||
assertResultMatch(result, responses.prepareTrustline.simple, 'prepare')
|
||||
})
|
||||
|
||||
it('frozen', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const result = await this.client.prepareTrustline(
|
||||
test.address,
|
||||
requests.prepareTrustline.frozen,
|
||||
)
|
||||
assertResultMatch(result, responses.prepareTrustline.frozen, 'prepare')
|
||||
})
|
||||
|
||||
it('complex', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const result = await this.client.prepareTrustline(
|
||||
test.address,
|
||||
requests.prepareTrustline.complex,
|
||||
instructionsWithMaxLedgerVersionOffset,
|
||||
)
|
||||
assertResultMatch(result, responses.prepareTrustline.complex, 'prepare')
|
||||
})
|
||||
|
||||
// it("invalid", async function () {
|
||||
// this.mockRippled.addResponse("server_info", rippled.server_info.normal);
|
||||
// this.mockRippled.addResponse("fee", rippled.fee);
|
||||
// this.mockRippled.addResponse("ledger_current", rippled.ledger_current);
|
||||
// this.mockRippled.addResponse(
|
||||
// "account_info",
|
||||
// rippled.account_info.normal
|
||||
// );
|
||||
// const trustline = { ...requests.prepareTrustline.complex };
|
||||
// delete trustline.limit; // Make invalid
|
||||
|
||||
// await assertRejects(
|
||||
// this.client.prepareTrustline(
|
||||
// test.address,
|
||||
// trustline,
|
||||
// instructionsWithMaxLedgerVersionOffset
|
||||
// ),
|
||||
// this.client.errors.ValidationError,
|
||||
// 'instance.trustline requires property "limit"'
|
||||
// );
|
||||
// });
|
||||
|
||||
it('xtest.address-issuer', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const result = await this.client.prepareTrustline(
|
||||
test.address,
|
||||
requests.prepareTrustline.issuedXAddress,
|
||||
instructionsWithMaxLedgerVersionOffset,
|
||||
)
|
||||
assertResultMatch(
|
||||
result,
|
||||
responses.prepareTrustline.issuedXAddress,
|
||||
'prepare',
|
||||
)
|
||||
})
|
||||
|
||||
it('with ticket', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const localInstructions = {
|
||||
...instructionsWithMaxLedgerVersionOffset,
|
||||
maxFee: '0.000012',
|
||||
ticketSequence: 23,
|
||||
}
|
||||
const result = await this.client.prepareTrustline(
|
||||
test.address,
|
||||
requests.prepareTrustline.simple,
|
||||
localInstructions,
|
||||
)
|
||||
assertResultMatch(result, responses.prepareTrustline.ticket, 'prepare')
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -3,9 +3,7 @@ import binary from 'ripple-binary-codec'
|
||||
|
||||
import requests from '../fixtures/requests'
|
||||
import responses from '../fixtures/responses'
|
||||
import rippled from '../fixtures/rippled'
|
||||
import { setupClient, teardownClient } from '../setupClient'
|
||||
import { addressTests } from '../testUtils'
|
||||
|
||||
const { sign: REQUEST_FIXTURES } = requests
|
||||
const { sign: RESPONSE_FIXTURES } = responses
|
||||
@@ -228,188 +226,143 @@ describe('client.sign', function () {
|
||||
assert.deepEqual(result, RESPONSE_FIXTURES.ticket)
|
||||
})
|
||||
|
||||
addressTests.forEach(function (test) {
|
||||
describe(test.type, function () {
|
||||
it('throws when Fee exceeds maxFeeXRP (in drops)', async function () {
|
||||
const secret = 'shsWGZcmZz6YsWWmcnpfr6fLTdtFV'
|
||||
const request = {
|
||||
txJSON: `{"Flags":2147483648,"TransactionType":"AccountSet","Account":"${test.address}","Domain":"6578616D706C652E636F6D","LastLedgerSequence":8820051,"Fee":"2010000","Sequence":23,"SigningPubKey":"02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8"}`,
|
||||
instructions: {
|
||||
fee: '2.01',
|
||||
sequence: 23,
|
||||
maxLedgerVersion: 8820051,
|
||||
},
|
||||
}
|
||||
it('throws when Fee exceeds maxFeeXRP (in drops)', async function () {
|
||||
const secret = 'shsWGZcmZz6YsWWmcnpfr6fLTdtFV'
|
||||
const request = {
|
||||
txJSON: `{"Flags":2147483648,"TransactionType":"AccountSet","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Domain":"6578616D706C652E636F6D","LastLedgerSequence":8820051,"Fee":"2010000","Sequence":23,"SigningPubKey":"02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8"}`,
|
||||
instructions: {
|
||||
fee: '2.01',
|
||||
sequence: 23,
|
||||
maxLedgerVersion: 8820051,
|
||||
},
|
||||
}
|
||||
|
||||
assert.throws(() => {
|
||||
this.client.sign(request.txJSON, secret)
|
||||
}, /Fee" should not exceed "2000000"\. To use a higher fee, set `maxFeeXRP` in the Client constructor\./)
|
||||
})
|
||||
assert.throws(() => {
|
||||
this.client.sign(request.txJSON, secret)
|
||||
}, /Fee" should not exceed "2000000"\. To use a higher fee, set `maxFeeXRP` in the Client constructor\./)
|
||||
})
|
||||
|
||||
it('throws when Fee exceeds maxFeeXRP (in drops) - custom maxFeeXRP', async function () {
|
||||
this.client.maxFeeXRP = '1.9'
|
||||
const secret = 'shsWGZcmZz6YsWWmcnpfr6fLTdtFV'
|
||||
const request = {
|
||||
txJSON: `{"Flags":2147483648,"TransactionType":"AccountSet","Account":"${test.address}","Domain":"6578616D706C652E636F6D","LastLedgerSequence":8820051,"Fee":"2010000","Sequence":23,"SigningPubKey":"02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8"}`,
|
||||
instructions: {
|
||||
fee: '2.01',
|
||||
sequence: 23,
|
||||
maxLedgerVersion: 8820051,
|
||||
},
|
||||
}
|
||||
it('throws when Fee exceeds maxFeeXRP (in drops) - custom maxFeeXRP', async function () {
|
||||
this.client.maxFeeXRP = '1.9'
|
||||
const secret = 'shsWGZcmZz6YsWWmcnpfr6fLTdtFV'
|
||||
const request = {
|
||||
txJSON: `{"Flags":2147483648,"TransactionType":"AccountSet","Account":"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59","Domain":"6578616D706C652E636F6D","LastLedgerSequence":8820051,"Fee":"2010000","Sequence":23,"SigningPubKey":"02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8"}`,
|
||||
instructions: {
|
||||
fee: '2.01',
|
||||
sequence: 23,
|
||||
maxLedgerVersion: 8820051,
|
||||
},
|
||||
}
|
||||
|
||||
assert.throws(() => {
|
||||
this.client.sign(request.txJSON, secret)
|
||||
}, /Fee" should not exceed "1900000"\. To use a higher fee, set `maxFeeXRP` in the Client constructor\./)
|
||||
})
|
||||
assert.throws(() => {
|
||||
this.client.sign(request.txJSON, secret)
|
||||
}, /Fee" should not exceed "1900000"\. To use a higher fee, set `maxFeeXRP` in the Client constructor\./)
|
||||
})
|
||||
|
||||
it('sign with paths', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const secret = 'shsWGZcmZz6YsWWmcnpfr6fLTdtFV'
|
||||
const payment = {
|
||||
source: {
|
||||
address: test.address,
|
||||
amount: {
|
||||
currency: 'drops',
|
||||
value: '100',
|
||||
},
|
||||
},
|
||||
destination: {
|
||||
address: 'rKT4JX4cCof6LcDYRz8o3rGRu7qxzZ2Zwj',
|
||||
minAmount: {
|
||||
currency: 'USD',
|
||||
value: '0.00004579644712312366',
|
||||
counterparty: 'rVnYNK9yuxBz4uP8zC8LEFokM2nqH3poc',
|
||||
},
|
||||
},
|
||||
// eslint-disable-next-line no-useless-escape
|
||||
paths:
|
||||
'[[{"currency":"USD","issuer":"rVnYNK9yuxBz4uP8zC8LEFokM2nqH3poc"}]]',
|
||||
}
|
||||
const ret = await this.client.preparePayment(test.address, payment, {
|
||||
sequence: 1,
|
||||
maxLedgerVersion: 15696358,
|
||||
})
|
||||
const result = this.client.sign(ret.txJSON, secret)
|
||||
assert.deepEqual(result, {
|
||||
signedTransaction:
|
||||
'12000022800200002400000001201B00EF81E661EC6386F26FC0FFFF0000000000000000000000005553440000000000054F6F784A58F9EFB0A9EB90B83464F9D166461968400000000000000C6940000000000000646AD3504529A0465E2E0000000000000000000000005553440000000000054F6F784A58F9EFB0A9EB90B83464F9D1664619732102F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D87446304402200A693FB5CA6B21250EBDFD8CFF526EE0DF7C9E4E31EB0660692E75E6A93BF5F802203CC39463DDA21386898CA31E18AD1A6828647D65741DD637BAD71BC83E29DB9481145E7B112523F68D2F5E879DB4EAC51C6698A693048314CA6EDC7A28252DAEA6F2045B24F4D7C333E146170112300000000000000000000000005553440000000000054F6F784A58F9EFB0A9EB90B83464F9D166461900',
|
||||
id: '78874FE5F5299FEE3EA85D3CF6C1FB1F1D46BB08F716662A3E3D1F0ADE4EF796',
|
||||
})
|
||||
})
|
||||
|
||||
it('succeeds - prepared payment', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const payment = await this.client.preparePayment(test.address, {
|
||||
source: {
|
||||
address: test.address,
|
||||
maxAmount: {
|
||||
value: '1',
|
||||
currency: 'drops',
|
||||
},
|
||||
},
|
||||
destination: {
|
||||
address: 'rQ3PTWGLCbPz8ZCicV5tCX3xuymojTng5r',
|
||||
amount: {
|
||||
value: '1',
|
||||
currency: 'drops',
|
||||
},
|
||||
},
|
||||
})
|
||||
const secret = 'shsWGZcmZz6YsWWmcnpfr6fLTdtFV'
|
||||
const result = this.client.sign(payment.txJSON, secret)
|
||||
const expectedResult = {
|
||||
signedTransaction:
|
||||
'12000022800000002400000017201B008694F261400000000000000168400000000000000C732102F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D874473045022100A9C91D4CFAE45686146EE0B56D4C53A2E7C2D672FB834D43E0BE2D2E9106519A022075DDA2F92DE552B0C45D83D4E6D35889B3FBF51BFBBD9B25EBF70DE3C96D0D6681145E7B112523F68D2F5E879DB4EAC51C6698A693048314FDB08D07AAA0EB711793A3027304D688E10C3648',
|
||||
id: '88D6B913C66279EA31ADC25C5806C48B2D4E5680261666790A736E1961217700',
|
||||
}
|
||||
assert.deepEqual(result, expectedResult)
|
||||
})
|
||||
|
||||
it('throws when encoded tx does not match decoded tx - prepared payment', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const payment = await this.client.preparePayment(test.address, {
|
||||
source: {
|
||||
address: test.address,
|
||||
maxAmount: {
|
||||
value: '1.1234567',
|
||||
currency: 'drops',
|
||||
},
|
||||
},
|
||||
destination: {
|
||||
address: 'rQ3PTWGLCbPz8ZCicV5tCX3xuymojTng5r',
|
||||
amount: {
|
||||
value: '1.1234567',
|
||||
currency: 'drops',
|
||||
},
|
||||
},
|
||||
})
|
||||
const secret = 'shsWGZcmZz6YsWWmcnpfr6fLTdtFV'
|
||||
assert.throws(() => {
|
||||
this.client.sign(payment.txJSON, secret)
|
||||
}, /^1.1234567 is an illegal amount/)
|
||||
})
|
||||
|
||||
it('throws when encoded tx does not match decoded tx - prepared order', async function () {
|
||||
this.mockRippled.addResponse('server_info', rippled.server_info.normal)
|
||||
this.mockRippled.addResponse('fee', rippled.fee)
|
||||
this.mockRippled.addResponse('ledger_current', rippled.ledger_current)
|
||||
this.mockRippled.addResponse(
|
||||
'account_info',
|
||||
rippled.account_info.normal,
|
||||
)
|
||||
const order = {
|
||||
direction: 'sell',
|
||||
quantity: {
|
||||
currency: 'USD',
|
||||
counterparty: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
|
||||
value: '3.140000',
|
||||
},
|
||||
totalPrice: {
|
||||
currency: 'XRP',
|
||||
value: '31415',
|
||||
},
|
||||
}
|
||||
const prepared = await this.client.prepareOrder(test.address, order, {
|
||||
sequence: 123,
|
||||
})
|
||||
const secret = 'shsWGZcmZz6YsWWmcnpfr6fLTdtFV'
|
||||
try {
|
||||
this.client.sign(prepared.txJSON, secret)
|
||||
return await Promise.reject(
|
||||
new Error('this.client.sign should have thrown'),
|
||||
)
|
||||
} catch (error) {
|
||||
assert.equal(error.name, 'ValidationError')
|
||||
assert.equal(
|
||||
error.message,
|
||||
'Serialized transaction does not match original txJSON. See `error.data`',
|
||||
)
|
||||
assert.deepEqual(error.data.diff, {
|
||||
TakerGets: {
|
||||
value: '3.14',
|
||||
},
|
||||
})
|
||||
}
|
||||
})
|
||||
it('sign with paths', async function () {
|
||||
const secret = 'shsWGZcmZz6YsWWmcnpfr6fLTdtFV'
|
||||
const payment = {
|
||||
TransactionType: 'Payment',
|
||||
Account: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
|
||||
Destination: 'rKT4JX4cCof6LcDYRz8o3rGRu7qxzZ2Zwj',
|
||||
Amount: {
|
||||
currency: 'USD',
|
||||
issuer: 'rVnYNK9yuxBz4uP8zC8LEFokM2nqH3poc',
|
||||
value:
|
||||
'999999999999999900000000000000000000000000000000000000000000000000000000000000000000000000000000',
|
||||
},
|
||||
Flags: 2147614720,
|
||||
SendMax: '100',
|
||||
DeliverMin: {
|
||||
currency: 'USD',
|
||||
issuer: 'rVnYNK9yuxBz4uP8zC8LEFokM2nqH3poc',
|
||||
value: '0.00004579644712312366',
|
||||
},
|
||||
Paths: [
|
||||
[{ currency: 'USD', issuer: 'rVnYNK9yuxBz4uP8zC8LEFokM2nqH3poc' }],
|
||||
],
|
||||
LastLedgerSequence: 15696358,
|
||||
Sequence: 1,
|
||||
Fee: '12',
|
||||
}
|
||||
const result = this.client.sign(JSON.stringify(payment), secret)
|
||||
assert.deepEqual(result, {
|
||||
signedTransaction:
|
||||
'12000022800200002400000001201B00EF81E661EC6386F26FC0FFFF0000000000000000000000005553440000000000054F6F784A58F9EFB0A9EB90B83464F9D166461968400000000000000C6940000000000000646AD3504529A0465E2E0000000000000000000000005553440000000000054F6F784A58F9EFB0A9EB90B83464F9D1664619732102F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D87446304402200A693FB5CA6B21250EBDFD8CFF526EE0DF7C9E4E31EB0660692E75E6A93BF5F802203CC39463DDA21386898CA31E18AD1A6828647D65741DD637BAD71BC83E29DB9481145E7B112523F68D2F5E879DB4EAC51C6698A693048314CA6EDC7A28252DAEA6F2045B24F4D7C333E146170112300000000000000000000000005553440000000000054F6F784A58F9EFB0A9EB90B83464F9D166461900',
|
||||
id: '78874FE5F5299FEE3EA85D3CF6C1FB1F1D46BB08F716662A3E3D1F0ADE4EF796',
|
||||
})
|
||||
})
|
||||
|
||||
it('succeeds - prepared payment', async function () {
|
||||
const payment = {
|
||||
TransactionType: 'Payment',
|
||||
Account: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
|
||||
Destination: 'rQ3PTWGLCbPz8ZCicV5tCX3xuymojTng5r',
|
||||
Amount: '1',
|
||||
Flags: 2147483648,
|
||||
Sequence: 23,
|
||||
LastLedgerSequence: 8819954,
|
||||
Fee: '12',
|
||||
}
|
||||
const secret = 'shsWGZcmZz6YsWWmcnpfr6fLTdtFV'
|
||||
const result = this.client.sign(JSON.stringify(payment), secret)
|
||||
const expectedResult = {
|
||||
signedTransaction:
|
||||
'12000022800000002400000017201B008694F261400000000000000168400000000000000C732102F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D874473045022100A9C91D4CFAE45686146EE0B56D4C53A2E7C2D672FB834D43E0BE2D2E9106519A022075DDA2F92DE552B0C45D83D4E6D35889B3FBF51BFBBD9B25EBF70DE3C96D0D6681145E7B112523F68D2F5E879DB4EAC51C6698A693048314FDB08D07AAA0EB711793A3027304D688E10C3648',
|
||||
id: '88D6B913C66279EA31ADC25C5806C48B2D4E5680261666790A736E1961217700',
|
||||
}
|
||||
assert.deepEqual(result, expectedResult)
|
||||
})
|
||||
|
||||
it('throws when encoded tx does not match decoded tx - prepared payment', async function () {
|
||||
const payment = {
|
||||
TransactionType: 'Payment',
|
||||
Account: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
|
||||
Destination: 'rQ3PTWGLCbPz8ZCicV5tCX3xuymojTng5r',
|
||||
Amount: '1.1234567',
|
||||
Flags: 2147483648,
|
||||
Sequence: 23,
|
||||
LastLedgerSequence: 8819954,
|
||||
Fee: '12',
|
||||
}
|
||||
const secret = 'shsWGZcmZz6YsWWmcnpfr6fLTdtFV'
|
||||
assert.throws(() => {
|
||||
this.client.sign(JSON.stringify(payment), secret)
|
||||
}, /^1.1234567 is an illegal amount/)
|
||||
})
|
||||
|
||||
it('throws when encoded tx does not match decoded tx - prepared order', async function () {
|
||||
const offerCreate = {
|
||||
TransactionType: 'OfferCreate',
|
||||
Account: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
|
||||
TakerGets: {
|
||||
currency: 'USD',
|
||||
issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
|
||||
value: '3.140000',
|
||||
},
|
||||
TakerPays: '31415000000',
|
||||
Flags: 2148007936,
|
||||
Sequence: 123,
|
||||
LastLedgerSequence: 8819954,
|
||||
Fee: '12',
|
||||
}
|
||||
const secret = 'shsWGZcmZz6YsWWmcnpfr6fLTdtFV'
|
||||
try {
|
||||
this.client.sign(JSON.stringify(offerCreate), secret)
|
||||
return await Promise.reject(
|
||||
new Error('this.client.sign should have thrown'),
|
||||
)
|
||||
} catch (error) {
|
||||
assert.equal(error.name, 'ValidationError')
|
||||
assert.equal(
|
||||
error.message,
|
||||
'Serialized transaction does not match original txJSON. See `error.data`',
|
||||
)
|
||||
assert.deepEqual(error.data.diff, {
|
||||
TakerGets: {
|
||||
value: '3.14',
|
||||
},
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -4,10 +4,20 @@ import _ from 'lodash'
|
||||
import { isValidXAddress } from 'ripple-address-codec'
|
||||
|
||||
import { Client } from 'xrpl-local'
|
||||
import { isValidSecret } from 'xrpl-local/utils'
|
||||
import {
|
||||
AccountSet,
|
||||
OfferCreate,
|
||||
SignerListSet,
|
||||
TrustSet,
|
||||
} from 'xrpl-local/models/transactions'
|
||||
import {
|
||||
isValidSecret,
|
||||
generateXAddress,
|
||||
xrpToDrops,
|
||||
convertStringToHex,
|
||||
} from 'xrpl-local/utils'
|
||||
|
||||
import { generateXAddress } from '../../src/utils/generateAddress'
|
||||
import requests from '../fixtures/requests'
|
||||
// import requests from '../fixtures/requests'
|
||||
|
||||
import { payTo, ledgerAccept } from './utils'
|
||||
import wallet from './wallet'
|
||||
@@ -116,16 +126,20 @@ const masterSecret = 'snoPBrXtMeMyMHUVTgbuqAfg1SUTb'
|
||||
|
||||
function makeTrustLine(testcase, address, secret) {
|
||||
const client = testcase.client
|
||||
const specification = {
|
||||
currency: 'USD',
|
||||
counterparty: masterAccount,
|
||||
limit: '1341.1',
|
||||
ripplingDisabled: true,
|
||||
const trustSet: TrustSet = {
|
||||
TransactionType: 'TrustSet',
|
||||
Account: address,
|
||||
LimitAmount: {
|
||||
value: '1341.1',
|
||||
issuer: masterAccount,
|
||||
currency: 'USD',
|
||||
},
|
||||
Flags: 0x00020000,
|
||||
}
|
||||
const trust = client
|
||||
.prepareTrustline(address, specification, {})
|
||||
.then((data) => {
|
||||
const signed = client.sign(data.txJSON, secret)
|
||||
.autofill(trustSet)
|
||||
.then(async (tx) => {
|
||||
const signed = client.sign(JSON.stringify(tx), secret)
|
||||
if (address === wallet.getAddress()) {
|
||||
testcase.transactions.push(signed.id)
|
||||
}
|
||||
@@ -134,32 +148,65 @@ function makeTrustLine(testcase, address, secret) {
|
||||
tx_blob: signed.signedTransaction,
|
||||
})
|
||||
})
|
||||
.then(() => ledgerAccept(client))
|
||||
.then((response) => {
|
||||
if (
|
||||
response.result.engine_result !== 'tesSUCCESS' &&
|
||||
response.result.engine_result !== 'tecPATH_PARTIAL'
|
||||
) {
|
||||
console.log(response)
|
||||
assert.fail(`Response not successful, ${response.result.engine_result}`)
|
||||
}
|
||||
ledgerAccept(client)
|
||||
})
|
||||
return trust
|
||||
}
|
||||
|
||||
function makeOrder(client, address, specification, secret) {
|
||||
function makeOrder(client, offerCreate, secret) {
|
||||
return client
|
||||
.prepareOrder(address, specification)
|
||||
.then((data) => client.sign(data.txJSON, secret))
|
||||
.autofill(offerCreate)
|
||||
.then((tx) => client.sign(JSON.stringify(tx), secret))
|
||||
.then((signed) =>
|
||||
client.request({ command: 'submit', tx_blob: signed.signedTransaction }),
|
||||
)
|
||||
.then(() => ledgerAccept(client))
|
||||
.then((response) => {
|
||||
if (
|
||||
response.result.engine_result !== 'tesSUCCESS' &&
|
||||
response.result.engine_result !== 'tecPATH_PARTIAL'
|
||||
) {
|
||||
console.log(response)
|
||||
assert.fail(`Response not successful, ${response.result.engine_result}`)
|
||||
}
|
||||
ledgerAccept(client)
|
||||
})
|
||||
}
|
||||
|
||||
function setupAccounts(testcase) {
|
||||
const client = testcase.client
|
||||
let fundAmount = '20'
|
||||
|
||||
const promise = payTo(client, 'rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM')
|
||||
.then(() => payTo(client, wallet.getAddress()))
|
||||
.then(() => payTo(client, testcase.newWallet.xAddress))
|
||||
.then(() => payTo(client, 'rKmBGxocj9Abgy25J51Mk1iqFzW9aVF9Tc'))
|
||||
.then(() => payTo(client, 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q'))
|
||||
const promise = client
|
||||
.request({ command: 'server_info' })
|
||||
.then(
|
||||
(response) =>
|
||||
(fundAmount = xrpToDrops(
|
||||
Number(response.result.info.validated_ledger.reserve_base_xrp) * 2,
|
||||
)),
|
||||
)
|
||||
.then(() => payTo(client, 'rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM', fundAmount))
|
||||
.then(() => payTo(client, wallet.getAddress(), fundAmount))
|
||||
.then(() => payTo(client, testcase.newWallet.classicAddress, fundAmount))
|
||||
.then(() => payTo(client, 'rKmBGxocj9Abgy25J51Mk1iqFzW9aVF9Tc', fundAmount))
|
||||
.then(() => payTo(client, 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q', fundAmount))
|
||||
.then(() => {
|
||||
const accountSet: AccountSet = {
|
||||
TransactionType: 'AccountSet',
|
||||
Account: masterAccount,
|
||||
// default ripple
|
||||
SetFlag: 8,
|
||||
}
|
||||
return client
|
||||
.prepareSettings(masterAccount, { defaultRipple: true })
|
||||
.then((data) => client.sign(data.txJSON, masterSecret))
|
||||
.autofill(accountSet)
|
||||
.then((tx) => client.sign(JSON.stringify(tx), masterSecret))
|
||||
.then((signed) =>
|
||||
client.request({
|
||||
command: 'submit',
|
||||
@@ -181,44 +228,30 @@ function setupAccounts(testcase) {
|
||||
.then(() => payTo(client, wallet.getAddress(), '123', 'USD', masterAccount))
|
||||
.then(() => payTo(client, 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q'))
|
||||
.then(() => {
|
||||
const orderSpecification = {
|
||||
direction: 'buy',
|
||||
quantity: {
|
||||
const offerCreate: OfferCreate = {
|
||||
TransactionType: 'OfferCreate',
|
||||
Account: testcase.newWallet.xAddress,
|
||||
TakerPays: {
|
||||
currency: 'USD',
|
||||
value: '432',
|
||||
counterparty: masterAccount,
|
||||
},
|
||||
totalPrice: {
|
||||
currency: 'XRP',
|
||||
value: '432',
|
||||
issuer: masterAccount,
|
||||
},
|
||||
TakerGets: xrpToDrops('432'),
|
||||
}
|
||||
return makeOrder(
|
||||
testcase.client,
|
||||
testcase.newWallet.xAddress,
|
||||
orderSpecification,
|
||||
testcase.newWallet.secret,
|
||||
)
|
||||
return makeOrder(testcase.client, offerCreate, testcase.newWallet.secret)
|
||||
})
|
||||
.then(() => {
|
||||
const orderSpecification = {
|
||||
direction: 'buy',
|
||||
quantity: {
|
||||
currency: 'XRP',
|
||||
value: '1741',
|
||||
},
|
||||
totalPrice: {
|
||||
const offerCreate: OfferCreate = {
|
||||
TransactionType: 'OfferCreate',
|
||||
Account: masterAccount,
|
||||
TakerPays: xrpToDrops('1741'),
|
||||
TakerGets: {
|
||||
currency: 'USD',
|
||||
value: '171',
|
||||
counterparty: masterAccount,
|
||||
issuer: masterAccount,
|
||||
},
|
||||
}
|
||||
return makeOrder(
|
||||
testcase.client,
|
||||
masterAccount,
|
||||
orderSpecification,
|
||||
masterSecret,
|
||||
)
|
||||
return makeOrder(testcase.client, offerCreate, masterSecret)
|
||||
})
|
||||
return promise
|
||||
}
|
||||
@@ -234,7 +267,10 @@ function suiteSetup(this: any) {
|
||||
setup
|
||||
.bind(this)(serverUrl)
|
||||
.then(() => ledgerAccept(this.client))
|
||||
.then(() => (this.newWallet = generateXAddress()))
|
||||
.then(
|
||||
() =>
|
||||
(this.newWallet = generateXAddress({ includeClassicAddress: true })),
|
||||
)
|
||||
// two times to give time to server to send `ledgerClosed` event
|
||||
// so getLedgerVersion will return right value
|
||||
.then(() => ledgerAccept(this.client))
|
||||
@@ -256,128 +292,12 @@ function suiteSetup(this: any) {
|
||||
|
||||
describe('integration tests', function () {
|
||||
const address = wallet.getAddress()
|
||||
const instructions = { maxLedgerVersionOffset: 10 }
|
||||
this.timeout(TIMEOUT)
|
||||
|
||||
before(suiteSetup)
|
||||
beforeEach(_.partial(setup, serverUrl))
|
||||
afterEach(teardown)
|
||||
|
||||
it('trustline', function () {
|
||||
return this.client
|
||||
.request({
|
||||
command: 'ledger',
|
||||
ledger_index: 'validated',
|
||||
})
|
||||
.then((response) => response.result.ledger_index)
|
||||
.then((ledgerVersion) => {
|
||||
return this.client
|
||||
.prepareTrustline(
|
||||
address,
|
||||
requests.prepareTrustline.simple,
|
||||
instructions,
|
||||
)
|
||||
.then((prepared) =>
|
||||
testTransaction(this, 'TrustSet', ledgerVersion, prepared),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
it('payment', function () {
|
||||
const amount = { currency: 'XRP', value: '0.000001' }
|
||||
const paymentSpecification = {
|
||||
source: {
|
||||
address,
|
||||
maxAmount: amount,
|
||||
},
|
||||
destination: {
|
||||
address: 'rKmBGxocj9Abgy25J51Mk1iqFzW9aVF9Tc',
|
||||
amount,
|
||||
},
|
||||
}
|
||||
return this.client
|
||||
.request({
|
||||
command: 'ledger',
|
||||
ledger_index: 'validated',
|
||||
})
|
||||
.then((response) => response.result.ledger_index)
|
||||
.then((ledgerVersion) => {
|
||||
return this.client
|
||||
.preparePayment(address, paymentSpecification, instructions)
|
||||
.then((prepared) =>
|
||||
testTransaction(this, 'Payment', ledgerVersion, prepared),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
it('order', function () {
|
||||
const orderSpecification = {
|
||||
direction: 'buy',
|
||||
quantity: {
|
||||
currency: 'USD',
|
||||
value: '237',
|
||||
counterparty: 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
|
||||
},
|
||||
totalPrice: {
|
||||
currency: 'XRP',
|
||||
value: '0.0002',
|
||||
},
|
||||
}
|
||||
const expectedOrder = {
|
||||
flags: 0,
|
||||
quality: '1.185',
|
||||
taker_gets: '200',
|
||||
taker_pays: {
|
||||
currency: 'USD',
|
||||
value: '237',
|
||||
issuer: 'rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q',
|
||||
},
|
||||
}
|
||||
return this.client
|
||||
.request({
|
||||
command: 'ledger',
|
||||
ledger_index: 'validated',
|
||||
})
|
||||
.then((response) => response.result.ledger_index)
|
||||
.then((ledgerVersion) => {
|
||||
return this.client
|
||||
.prepareOrder(address, orderSpecification, instructions)
|
||||
.then((prepared) =>
|
||||
testTransaction(this, 'OfferCreate', ledgerVersion, prepared),
|
||||
)
|
||||
.then((result) => {
|
||||
const txData = JSON.parse(result.txJSON)
|
||||
return this.client
|
||||
.request({
|
||||
command: 'account_offers',
|
||||
account: address,
|
||||
})
|
||||
.then((response) => response.result.offers)
|
||||
.then((orders) => {
|
||||
assert(orders && orders.length > 0)
|
||||
const createdOrder = orders.filter((order) => {
|
||||
return order.seq === txData.Sequence
|
||||
})[0]
|
||||
assert(createdOrder)
|
||||
delete createdOrder.seq
|
||||
assert.deepEqual(createdOrder, expectedOrder)
|
||||
return txData
|
||||
})
|
||||
})
|
||||
.then((txData) =>
|
||||
this.client
|
||||
.prepareOrderCancellation(
|
||||
address,
|
||||
{ orderSequence: txData.Sequence },
|
||||
instructions,
|
||||
)
|
||||
.then((prepared) =>
|
||||
testTransaction(this, 'OfferCancel', ledgerVersion, prepared),
|
||||
),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
it('isConnected', function () {
|
||||
assert(this.client.isConnected())
|
||||
})
|
||||
@@ -390,29 +310,29 @@ describe('integration tests', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('getTrustlines', function () {
|
||||
const fixture = requests.prepareTrustline.simple
|
||||
const { currency, counterparty } = fixture
|
||||
const options = { currency, counterparty }
|
||||
return this.client.getTrustlines(address, options).then((data) => {
|
||||
assert(data && data.length > 0 && data[0] && data[0].specification)
|
||||
const specification = data[0].specification
|
||||
assert.strictEqual(Number(specification.limit), Number(fixture.limit))
|
||||
assert.strictEqual(specification.currency, fixture.currency)
|
||||
assert.strictEqual(specification.counterparty, fixture.counterparty)
|
||||
})
|
||||
})
|
||||
// it('getTrustlines', function () {
|
||||
// const fixture = requests.prepareTrustline.simple
|
||||
// const { currency, counterparty } = fixture
|
||||
// const options = { currency, counterparty }
|
||||
// return this.client.getTrustlines(address, options).then((data) => {
|
||||
// assert(data && data.length > 0 && data[0] && data[0].specification)
|
||||
// const specification = data[0].specification
|
||||
// assert.strictEqual(Number(specification.limit), Number(fixture.limit))
|
||||
// assert.strictEqual(specification.currency, fixture.currency)
|
||||
// assert.strictEqual(specification.counterparty, fixture.counterparty)
|
||||
// })
|
||||
// })
|
||||
|
||||
it('getBalances', function () {
|
||||
const fixture = requests.prepareTrustline.simple
|
||||
const { currency, counterparty } = fixture
|
||||
const options = { currency, counterparty }
|
||||
return this.client.getBalances(address, options).then((data) => {
|
||||
assert(data && data.length > 0 && data[0])
|
||||
assert.strictEqual(data[0].currency, fixture.currency)
|
||||
assert.strictEqual(data[0].counterparty, fixture.counterparty)
|
||||
})
|
||||
})
|
||||
// it('getBalances', function () {
|
||||
// const fixture = requests.prepareTrustline.simple
|
||||
// const { currency, counterparty } = fixture
|
||||
// const options = { currency, counterparty }
|
||||
// return this.client.getBalances(address, options).then((data) => {
|
||||
// assert(data && data.length > 0 && data[0])
|
||||
// assert.strictEqual(data[0].currency, fixture.currency)
|
||||
// assert.strictEqual(data[0].counterparty, fixture.counterparty)
|
||||
// })
|
||||
// })
|
||||
|
||||
it('getOrderbook', function () {
|
||||
const orderbook = {
|
||||
@@ -505,98 +425,122 @@ describe('integration tests', function () {
|
||||
assert(isValidXAddress(newWallet.xAddress))
|
||||
assert(isValidSecret(newWallet.secret))
|
||||
})
|
||||
})
|
||||
|
||||
describe('integration tests - standalone rippled', function () {
|
||||
const instructions = { maxLedgerVersionOffset: 10 }
|
||||
this.timeout(TIMEOUT)
|
||||
|
||||
beforeEach(_.partial(setup, serverUrl))
|
||||
afterEach(teardown)
|
||||
const address = 'r5nx8ZkwEbFztnc8Qyi22DE9JYjRzNmvs'
|
||||
const secret = 'ss6F8381Br6wwpy9p582H8sBt19J3'
|
||||
const multisignAccount = 'r5nx8ZkwEbFztnc8Qyi22DE9JYjRzNmvs'
|
||||
const multisignSecret = 'ss6F8381Br6wwpy9p582H8sBt19J3'
|
||||
const signer1address = 'rQDhz2ZNXmhxzCYwxU6qAbdxsHA4HV45Y2'
|
||||
const signer1secret = 'shK6YXzwYfnFVn3YZSaMh5zuAddKx'
|
||||
const signer2address = 'r3RtUvGw9nMoJ5FuHxuoVJvcENhKtuF9ud'
|
||||
const signer2secret = 'shUHQnL4EH27V4EiBrj6EfhWvZngF'
|
||||
|
||||
it('submit multisigned transaction', function () {
|
||||
const signers = {
|
||||
threshold: 2,
|
||||
weights: [
|
||||
{ address: signer1address, weight: 1 },
|
||||
{ address: signer2address, weight: 1 },
|
||||
const signerListSet: SignerListSet = {
|
||||
TransactionType: 'SignerListSet',
|
||||
Account: multisignAccount,
|
||||
SignerEntries: [
|
||||
{
|
||||
SignerEntry: {
|
||||
Account: signer1address,
|
||||
SignerWeight: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
SignerEntry: {
|
||||
Account: signer2address,
|
||||
SignerWeight: 1,
|
||||
},
|
||||
},
|
||||
],
|
||||
SignerQuorum: 2,
|
||||
}
|
||||
let minLedgerVersion = null
|
||||
return payTo(this.client, address)
|
||||
.then(() => {
|
||||
return this.client
|
||||
.request({
|
||||
command: 'ledger',
|
||||
ledger_index: 'validated',
|
||||
})
|
||||
.then((response) => response.result.ledger_index)
|
||||
.then((ledgerVersion) => {
|
||||
minLedgerVersion = ledgerVersion
|
||||
let fundAmount = '20'
|
||||
return this.client
|
||||
.request({ command: 'server_info' })
|
||||
.then(
|
||||
(response) =>
|
||||
(fundAmount = xrpToDrops(
|
||||
Number(response.result.info.validated_ledger.reserve_base_xrp) * 2,
|
||||
)),
|
||||
)
|
||||
.then(() =>
|
||||
payTo(this.client, multisignAccount, fundAmount)
|
||||
.then(() => {
|
||||
return this.client
|
||||
.prepareSettings(address, { signers }, instructions)
|
||||
.then((prepared) => {
|
||||
.request({
|
||||
command: 'ledger',
|
||||
ledger_index: 'validated',
|
||||
})
|
||||
.then((response) => response.result.ledger_index)
|
||||
.then((ledgerVersion) => {
|
||||
minLedgerVersion = ledgerVersion
|
||||
})
|
||||
.then(() => this.client.autofill(signerListSet, 2))
|
||||
.then((tx) => {
|
||||
return testTransaction(
|
||||
this,
|
||||
'SignerListSet',
|
||||
ledgerVersion,
|
||||
prepared,
|
||||
address,
|
||||
secret,
|
||||
minLedgerVersion,
|
||||
{ txJSON: JSON.stringify(tx) },
|
||||
multisignAccount,
|
||||
multisignSecret,
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
.then(() => {
|
||||
const multisignInstructions = { ...instructions, signersCount: 2 }
|
||||
return this.client
|
||||
.prepareSettings(
|
||||
address,
|
||||
{ domain: 'example.com' },
|
||||
multisignInstructions,
|
||||
)
|
||||
.then((prepared) => {
|
||||
const signed1 = this.client.sign(prepared.txJSON, signer1secret, {
|
||||
signAs: signer1address,
|
||||
})
|
||||
const signed2 = this.client.sign(prepared.txJSON, signer2secret, {
|
||||
signAs: signer2address,
|
||||
})
|
||||
const combined = this.client.combine([
|
||||
signed1.signedTransaction,
|
||||
signed2.signedTransaction,
|
||||
])
|
||||
return this.client
|
||||
.request({
|
||||
command: 'submit',
|
||||
tx_blob: combined.signedTransaction,
|
||||
})
|
||||
.then((response) =>
|
||||
acceptLedger(this.client).then(() => response),
|
||||
.then(() => {
|
||||
const accountSet: AccountSet = {
|
||||
TransactionType: 'AccountSet',
|
||||
Account: multisignAccount,
|
||||
Domain: convertStringToHex('example.com'),
|
||||
}
|
||||
return this.client.autofill(accountSet, 2).then((tx) => {
|
||||
const signed1 = this.client.sign(
|
||||
JSON.stringify(tx),
|
||||
signer1secret,
|
||||
{
|
||||
signAs: signer1address,
|
||||
},
|
||||
)
|
||||
.then((response) => {
|
||||
assert.strictEqual(response.result.engine_result, 'tesSUCCESS')
|
||||
const options = { minLedgerVersion }
|
||||
return verifyTransaction(
|
||||
this,
|
||||
combined.id,
|
||||
'AccountSet',
|
||||
options,
|
||||
{},
|
||||
address,
|
||||
const signed2 = this.client.sign(
|
||||
JSON.stringify(tx),
|
||||
signer2secret,
|
||||
{
|
||||
signAs: signer2address,
|
||||
},
|
||||
)
|
||||
const combined = this.client.combine([
|
||||
signed1.signedTransaction,
|
||||
signed2.signedTransaction,
|
||||
])
|
||||
return this.client
|
||||
.request({
|
||||
command: 'submit',
|
||||
tx_blob: combined.signedTransaction,
|
||||
})
|
||||
.then((response) =>
|
||||
acceptLedger(this.client).then(() => response),
|
||||
)
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error.message)
|
||||
throw error
|
||||
})
|
||||
})
|
||||
})
|
||||
.then((response) => {
|
||||
assert.strictEqual(
|
||||
response.result.engine_result,
|
||||
'tesSUCCESS',
|
||||
)
|
||||
const options = { minLedgerVersion }
|
||||
return verifyTransaction(
|
||||
this,
|
||||
combined.id,
|
||||
'AccountSet',
|
||||
options,
|
||||
{},
|
||||
multisignAccount,
|
||||
)
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error.message)
|
||||
throw error
|
||||
})
|
||||
})
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,57 +1,80 @@
|
||||
'use strict';
|
||||
const assert = require('chai').assert
|
||||
|
||||
const masterAccount = 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh';
|
||||
const masterSecret = 'snoPBrXtMeMyMHUVTgbuqAfg1SUTb';
|
||||
const models = require('xrpl-local/models/transactions')
|
||||
const utils = require('xrpl-local/utils')
|
||||
|
||||
const masterAccount = 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'
|
||||
const masterSecret = 'snoPBrXtMeMyMHUVTgbuqAfg1SUTb'
|
||||
|
||||
function ledgerAccept(client) {
|
||||
const request = {command: 'ledger_accept'};
|
||||
return client.connection.request(request);
|
||||
const request = { command: 'ledger_accept' }
|
||||
return client.connection.request(request)
|
||||
}
|
||||
|
||||
function pay(client, from, to, amount, secret, currency = 'XRP', counterparty) {
|
||||
const paymentSpecification = {
|
||||
source: {
|
||||
address: from,
|
||||
maxAmount: {
|
||||
value: amount,
|
||||
currency: currency
|
||||
}
|
||||
},
|
||||
destination: {
|
||||
address: to,
|
||||
amount: {
|
||||
value: amount,
|
||||
currency: currency
|
||||
}
|
||||
}
|
||||
};
|
||||
function pay(client, from, to, amount, secret, currency = 'XRP', issuer) {
|
||||
const paymentAmount =
|
||||
currency === 'XRP' ? amount : { value: amount, currency, issuer }
|
||||
|
||||
if (counterparty != null) {
|
||||
paymentSpecification.source.maxAmount.counterparty = counterparty;
|
||||
paymentSpecification.destination.amount.counterparty = counterparty;
|
||||
const payment = {
|
||||
TransactionType: 'Payment',
|
||||
Account: from,
|
||||
Destination: to,
|
||||
Amount: paymentAmount,
|
||||
}
|
||||
|
||||
let id = null;
|
||||
return client.preparePayment(from, paymentSpecification, {})
|
||||
.then(data => client.sign(data.txJSON, secret))
|
||||
.then(signed => {
|
||||
id = signed.id;
|
||||
return client.request({command: 'submit', tx_blob: signed.signedTransaction});
|
||||
})
|
||||
// TODO: add better error handling here
|
||||
.then(() => ledgerAccept(client))
|
||||
.then(() => id);
|
||||
let id = null
|
||||
return (
|
||||
client
|
||||
.autofill(payment, 1)
|
||||
.then((tx) => {
|
||||
models.verifyPayment(payment)
|
||||
return client.sign(JSON.stringify(tx), secret)
|
||||
})
|
||||
.then((signed) => {
|
||||
id = signed.id
|
||||
return client.request({
|
||||
command: 'submit',
|
||||
tx_blob: signed.signedTransaction,
|
||||
})
|
||||
})
|
||||
// TODO: add better error handling here
|
||||
// TODO: fix path issues
|
||||
.then((response) => {
|
||||
if (
|
||||
response.result.engine_result !== 'tesSUCCESS' &&
|
||||
response.result.engine_result !== 'tecPATH_PARTIAL'
|
||||
) {
|
||||
console.log(response)
|
||||
assert.fail(
|
||||
`Response not successful, ${response.result.engine_result}`,
|
||||
)
|
||||
}
|
||||
ledgerAccept(client)
|
||||
})
|
||||
.then(() => id)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
function payTo(client, to, amount = '4003218', currency = 'XRP', counterparty) {
|
||||
return pay(client, masterAccount, to, amount, masterSecret, currency,
|
||||
counterparty);
|
||||
function payTo(
|
||||
client,
|
||||
to,
|
||||
amount = '40000000',
|
||||
currency = 'XRP',
|
||||
counterparty,
|
||||
) {
|
||||
return pay(
|
||||
client,
|
||||
masterAccount,
|
||||
to,
|
||||
amount,
|
||||
masterSecret,
|
||||
currency,
|
||||
counterparty,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
pay,
|
||||
payTo,
|
||||
ledgerAccept
|
||||
};
|
||||
ledgerAccept,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user