mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 20:25:48 +00:00
add test for getting order and order cancellation transations
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable max-nested-callbacks */
|
||||||
'use strict';
|
'use strict';
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const assert = require('assert-diff');
|
const assert = require('assert-diff');
|
||||||
@@ -34,6 +35,9 @@ const getOrderbookResponse = require('./fixtures/get-orderbook-response');
|
|||||||
const getServerInfoResponse = require('./fixtures/get-server-info-response');
|
const getServerInfoResponse = require('./fixtures/get-server-info-response');
|
||||||
const getPathsResponse = require('./fixtures/get-paths-response');
|
const getPathsResponse = require('./fixtures/get-paths-response');
|
||||||
const settingsTransactionResponse = require('./fixtures/settings-tx-response');
|
const settingsTransactionResponse = require('./fixtures/settings-tx-response');
|
||||||
|
const orderTransactionResponse = require('./fixtures/responses/order');
|
||||||
|
const orderCancellationTransactionResponse =
|
||||||
|
require('./fixtures/responses/order-cancellation');
|
||||||
const address = addresses.ACCOUNT;
|
const address = addresses.ACCOUNT;
|
||||||
|
|
||||||
const orderbook = {
|
const orderbook = {
|
||||||
@@ -130,6 +134,20 @@ describe('RippleAPI', function() {
|
|||||||
_.partial(checkResult, settingsTransactionResponse, done));
|
_.partial(checkResult, settingsTransactionResponse, done));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('getTransaction - order', function(done) {
|
||||||
|
const hash =
|
||||||
|
'10A6FB4A66EE80BED46AAE4815D7DC43B97E944984CCD5B93BCF3F8538CABC51';
|
||||||
|
this.api.getTransaction(hash, {},
|
||||||
|
_.partial(checkResult, orderTransactionResponse, done));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getTransaction - order cancellation', function(done) {
|
||||||
|
const hash =
|
||||||
|
'809335DD3B0B333865096217AA2F55A4DF168E0198080B3A090D12D88880FF0E';
|
||||||
|
this.api.getTransaction(hash, {},
|
||||||
|
_.partial(checkResult, orderCancellationTransactionResponse, done));
|
||||||
|
});
|
||||||
|
|
||||||
it('getTransactions', function(done) {
|
it('getTransactions', function(done) {
|
||||||
const options = {types: ['payment', 'order'], outgoing: true, limit: 2};
|
const options = {types: ['payment', 'order'], outgoing: true, limit: 2};
|
||||||
this.api.getTransactions(address, options,
|
this.api.getTransactions(address, options,
|
||||||
|
|||||||
41
test/fixtures/responses/order-cancellation.json
vendored
Normal file
41
test/fixtures/responses/order-cancellation.json
vendored
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
{
|
||||||
|
"type": "orderCancellation",
|
||||||
|
"address": "r9UHu5CWni1qRY7Q4CfFZLGvXo2pGQy96b",
|
||||||
|
"id": "809335DD3B0B333865096217AA2F55A4DF168E0198080B3A090D12D88880FF0E",
|
||||||
|
"sequence": 466,
|
||||||
|
"specification": {
|
||||||
|
"orderSequence": 465
|
||||||
|
},
|
||||||
|
"outcome": {
|
||||||
|
"result": "tesSUCCESS",
|
||||||
|
"timestamp": "2014-09-24T21:21:50.000Z",
|
||||||
|
"fee": "0.012",
|
||||||
|
"balanceChanges": {
|
||||||
|
"r9UHu5CWni1qRY7Q4CfFZLGvXo2pGQy96b": [
|
||||||
|
{
|
||||||
|
"currency": "XRP",
|
||||||
|
"value": "-0.012"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"orderbookChanges": {
|
||||||
|
"r9UHu5CWni1qRY7Q4CfFZLGvXo2pGQy96b": [
|
||||||
|
{
|
||||||
|
"taker_pays": {
|
||||||
|
"currency": "USD",
|
||||||
|
"counterparty": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q",
|
||||||
|
"value": "0"
|
||||||
|
},
|
||||||
|
"taker_gets": {
|
||||||
|
"currency": "XRP",
|
||||||
|
"value": "0"
|
||||||
|
},
|
||||||
|
"sequence": 465,
|
||||||
|
"status": "canceled"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"ledgerVersion": 14661789,
|
||||||
|
"indexInLedger": 4
|
||||||
|
}
|
||||||
|
}
|
||||||
50
test/fixtures/responses/order.json
vendored
Normal file
50
test/fixtures/responses/order.json
vendored
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
{
|
||||||
|
"type": "order",
|
||||||
|
"address": "r9UHu5CWni1qRY7Q4CfFZLGvXo2pGQy96b",
|
||||||
|
"id": "5D9B0B246255815B63983C188B4C23325B3544F605CDBE3004769EE9E990D2F2",
|
||||||
|
"sequence": 465,
|
||||||
|
"specification": {
|
||||||
|
"direction": "buy",
|
||||||
|
"quantity": {
|
||||||
|
"currency": "USD",
|
||||||
|
"value": "237",
|
||||||
|
"counterparty": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q"
|
||||||
|
},
|
||||||
|
"totalPrice": {
|
||||||
|
"currency": "XRP",
|
||||||
|
"value": "0.0002"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outcome": {
|
||||||
|
"result": "tesSUCCESS",
|
||||||
|
"timestamp": "2014-09-24T21:21:50.000Z",
|
||||||
|
"fee": "0.012",
|
||||||
|
"balanceChanges": {
|
||||||
|
"r9UHu5CWni1qRY7Q4CfFZLGvXo2pGQy96b": [
|
||||||
|
{
|
||||||
|
"currency": "XRP",
|
||||||
|
"value": "-0.012"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"orderbookChanges": {
|
||||||
|
"r9UHu5CWni1qRY7Q4CfFZLGvXo2pGQy96b": [
|
||||||
|
{
|
||||||
|
"taker_pays": {
|
||||||
|
"currency": "USD",
|
||||||
|
"counterparty": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q",
|
||||||
|
"value": "237"
|
||||||
|
},
|
||||||
|
"taker_gets": {
|
||||||
|
"currency": "XRP",
|
||||||
|
"value": "0.0002"
|
||||||
|
},
|
||||||
|
"sequence": 465,
|
||||||
|
"status": "created"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"ledgerVersion": 14661788,
|
||||||
|
"indexInLedger": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
90
test/fixtures/rippled-responses/offer-cancel.json
vendored
Normal file
90
test/fixtures/rippled-responses/offer-cancel.json
vendored
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
{
|
||||||
|
"TransactionType": "OfferCancel",
|
||||||
|
"Flags": 0,
|
||||||
|
"Sequence": 466,
|
||||||
|
"OfferSequence": 465,
|
||||||
|
"LastLedgerSequence": 14661888,
|
||||||
|
"Fee": "12000",
|
||||||
|
"SigningPubKey": "036A749E3B7187E43E8936E3D83A7030989325249E03803F12B7F64BAACABA6025",
|
||||||
|
"TxnSignature": "3045022100E4148E9809C5CE13BC5583E8CA665614D9FF02D6589D13BA7FBB67CF45EAC0BF02201B84DC18A921260BCEE685908260888BC20D4375DB4A8702F25B346CAD7F3387",
|
||||||
|
"Account": "r9UHu5CWni1qRY7Q4CfFZLGvXo2pGQy96b",
|
||||||
|
"hash": "809335DD3B0B333865096217AA2F55A4DF168E0198080B3A090D12D88880FF0E",
|
||||||
|
"ledger_index": 14661789,
|
||||||
|
"inLedger": 14661789,
|
||||||
|
"meta": {
|
||||||
|
"TransactionIndex": 4,
|
||||||
|
"AffectedNodes": [
|
||||||
|
{
|
||||||
|
"ModifiedNode": {
|
||||||
|
"LedgerEntryType": "AccountRoot",
|
||||||
|
"PreviousTxnLgrSeq": 14661788,
|
||||||
|
"PreviousTxnID": "5D9B0B246255815B63983C188B4C23325B3544F605CDBE3004769EE9E990D2F2",
|
||||||
|
"LedgerIndex": "4AD70690C6FF8A069F8AE00B09F70E9B732360026E8085050D314432091A59C9",
|
||||||
|
"PreviousFields": {
|
||||||
|
"Sequence": 466,
|
||||||
|
"OwnerCount": 4,
|
||||||
|
"Balance": "71827095"
|
||||||
|
},
|
||||||
|
"FinalFields": {
|
||||||
|
"Flags": 0,
|
||||||
|
"Sequence": 467,
|
||||||
|
"OwnerCount": 3,
|
||||||
|
"Balance": "71815095",
|
||||||
|
"Domain": "726970706C652E636F6D",
|
||||||
|
"Account": "r9UHu5CWni1qRY7Q4CfFZLGvXo2pGQy96b"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ModifiedNode": {
|
||||||
|
"LedgerEntryType": "DirectoryNode",
|
||||||
|
"LedgerIndex": "6FCB8B0AF9F22ACF762B7712BF44C6CF172FD2BECD849509604EB7DB3AD2C250",
|
||||||
|
"FinalFields": {
|
||||||
|
"Flags": 0,
|
||||||
|
"RootIndex": "6FCB8B0AF9F22ACF762B7712BF44C6CF172FD2BECD849509604EB7DB3AD2C250",
|
||||||
|
"Owner": "r9UHu5CWni1qRY7Q4CfFZLGvXo2pGQy96b"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DeletedNode": {
|
||||||
|
"LedgerEntryType": "DirectoryNode",
|
||||||
|
"LedgerIndex": "CF8D13399C6ED20BA82740CFA78E928DC8D498255249BA63550435C0500F1000",
|
||||||
|
"FinalFields": {
|
||||||
|
"Flags": 0,
|
||||||
|
"ExchangeRate": "550435C0500F1000",
|
||||||
|
"RootIndex": "CF8D13399C6ED20BA82740CFA78E928DC8D498255249BA63550435C0500F1000",
|
||||||
|
"TakerPaysCurrency": "0000000000000000000000005553440000000000",
|
||||||
|
"TakerPaysIssuer": "DD39C650A96EDA48334E70CC4A85B8B2E8502CD3",
|
||||||
|
"TakerGetsCurrency": "0000000000000000000000000000000000000000",
|
||||||
|
"TakerGetsIssuer": "0000000000000000000000000000000000000000"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DeletedNode": {
|
||||||
|
"LedgerEntryType": "Offer",
|
||||||
|
"LedgerIndex": "D0BEA7E310CDCEED282911314B0D6D00BB7E3B985EAA275AE2AC2DE3763AAF0C",
|
||||||
|
"FinalFields": {
|
||||||
|
"Flags": 0,
|
||||||
|
"Sequence": 465,
|
||||||
|
"PreviousTxnLgrSeq": 14661788,
|
||||||
|
"BookNode": "0000000000000000",
|
||||||
|
"OwnerNode": "0000000000000000",
|
||||||
|
"PreviousTxnID": "5D9B0B246255815B63983C188B4C23325B3544F605CDBE3004769EE9E990D2F2",
|
||||||
|
"BookDirectory": "CF8D13399C6ED20BA82740CFA78E928DC8D498255249BA63550435C0500F1000",
|
||||||
|
"TakerPays": {
|
||||||
|
"value": "237",
|
||||||
|
"currency": "USD",
|
||||||
|
"issuer": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q"
|
||||||
|
},
|
||||||
|
"TakerGets": "200",
|
||||||
|
"Account": "r9UHu5CWni1qRY7Q4CfFZLGvXo2pGQy96b"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"TransactionResult": "tesSUCCESS"
|
||||||
|
},
|
||||||
|
"validated": true
|
||||||
|
}
|
||||||
87
test/fixtures/rippled-responses/offer-create.json
vendored
Normal file
87
test/fixtures/rippled-responses/offer-create.json
vendored
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
{
|
||||||
|
"TransactionType": "OfferCreate",
|
||||||
|
"Flags": 0,
|
||||||
|
"Sequence": 465,
|
||||||
|
"LastLedgerSequence": 14661886,
|
||||||
|
"TakerPays": {
|
||||||
|
"value": "237",
|
||||||
|
"currency": "USD",
|
||||||
|
"issuer": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q"
|
||||||
|
},
|
||||||
|
"TakerGets": "200",
|
||||||
|
"Fee": "12000",
|
||||||
|
"SigningPubKey": "036A749E3B7187E43E8936E3D83A7030989325249E03803F12B7F64BAACABA6025",
|
||||||
|
"TxnSignature": "3045022100FA4CBD0A54A38906F8D4C18FBA4DBCE45B98F9C5A33BC9102CB5911E9E20E88F022032C47AC74E60042FF1517C866680A41B396D61146FBA9E60B4CF74E373CA7AD2",
|
||||||
|
"Account": "r9UHu5CWni1qRY7Q4CfFZLGvXo2pGQy96b",
|
||||||
|
"hash": "5D9B0B246255815B63983C188B4C23325B3544F605CDBE3004769EE9E990D2F2",
|
||||||
|
"ledger_index": 14661788,
|
||||||
|
"inLedger": 14661788,
|
||||||
|
"meta": {
|
||||||
|
"TransactionIndex": 2,
|
||||||
|
"AffectedNodes": [
|
||||||
|
{
|
||||||
|
"ModifiedNode": {
|
||||||
|
"LedgerEntryType": "AccountRoot",
|
||||||
|
"PreviousTxnLgrSeq": 14660978,
|
||||||
|
"PreviousTxnID": "566D4DE22972C5BAD2506CFFA928B21D2BD33FA52FE16712D17D727681FAA4B1",
|
||||||
|
"LedgerIndex": "4AD70690C6FF8A069F8AE00B09F70E9B732360026E8085050D314432091A59C9",
|
||||||
|
"PreviousFields": {
|
||||||
|
"Sequence": 465,
|
||||||
|
"OwnerCount": 3,
|
||||||
|
"Balance": "71839095"
|
||||||
|
},
|
||||||
|
"FinalFields": {
|
||||||
|
"Flags": 0,
|
||||||
|
"Sequence": 466,
|
||||||
|
"OwnerCount": 4,
|
||||||
|
"Balance": "71827095",
|
||||||
|
"Domain": "726970706C652E636F6D",
|
||||||
|
"Account": "r9UHu5CWni1qRY7Q4CfFZLGvXo2pGQy96b"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ModifiedNode": {
|
||||||
|
"LedgerEntryType": "DirectoryNode",
|
||||||
|
"LedgerIndex": "6FCB8B0AF9F22ACF762B7712BF44C6CF172FD2BECD849509604EB7DB3AD2C250",
|
||||||
|
"FinalFields": {
|
||||||
|
"Flags": 0,
|
||||||
|
"RootIndex": "6FCB8B0AF9F22ACF762B7712BF44C6CF172FD2BECD849509604EB7DB3AD2C250",
|
||||||
|
"Owner": "r9UHu5CWni1qRY7Q4CfFZLGvXo2pGQy96b"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"CreatedNode": {
|
||||||
|
"LedgerEntryType": "DirectoryNode",
|
||||||
|
"LedgerIndex": "CF8D13399C6ED20BA82740CFA78E928DC8D498255249BA63550435C0500F1000",
|
||||||
|
"NewFields": {
|
||||||
|
"ExchangeRate": "550435C0500F1000",
|
||||||
|
"RootIndex": "CF8D13399C6ED20BA82740CFA78E928DC8D498255249BA63550435C0500F1000",
|
||||||
|
"TakerPaysCurrency": "0000000000000000000000005553440000000000",
|
||||||
|
"TakerPaysIssuer": "DD39C650A96EDA48334E70CC4A85B8B2E8502CD3"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"CreatedNode": {
|
||||||
|
"LedgerEntryType": "Offer",
|
||||||
|
"LedgerIndex": "D0BEA7E310CDCEED282911314B0D6D00BB7E3B985EAA275AE2AC2DE3763AAF0C",
|
||||||
|
"NewFields": {
|
||||||
|
"Sequence": 465,
|
||||||
|
"BookDirectory": "CF8D13399C6ED20BA82740CFA78E928DC8D498255249BA63550435C0500F1000",
|
||||||
|
"TakerPays": {
|
||||||
|
"value": "237",
|
||||||
|
"currency": "USD",
|
||||||
|
"issuer": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q"
|
||||||
|
},
|
||||||
|
"TakerGets": "200",
|
||||||
|
"Account": "r9UHu5CWni1qRY7Q4CfFZLGvXo2pGQy96b"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"TransactionResult": "tesSUCCESS"
|
||||||
|
},
|
||||||
|
"validated": true
|
||||||
|
}
|
||||||
@@ -9,6 +9,10 @@ const hashes = require('./fixtures/hashes');
|
|||||||
const accountOffersResponse = require('./fixtures/acct-offers-response');
|
const accountOffersResponse = require('./fixtures/acct-offers-response');
|
||||||
const bookOffers = require('./fixtures/book-offers-response');
|
const bookOffers = require('./fixtures/book-offers-response');
|
||||||
const accountSetTransactionResponse = require('./fixtures/account-set-tx.json');
|
const accountSetTransactionResponse = require('./fixtures/account-set-tx.json');
|
||||||
|
const offerCreateTransactionResponse =
|
||||||
|
require('./fixtures/rippled-responses/offer-create');
|
||||||
|
const offerCancelTransactionResponse =
|
||||||
|
require('./fixtures/rippled-responses/offer-cancel');
|
||||||
const paths = require('./fixtures/paths');
|
const paths = require('./fixtures/paths');
|
||||||
|
|
||||||
function isUSD(json) {
|
function isUSD(json) {
|
||||||
@@ -106,6 +110,14 @@ module.exports = function(port) {
|
|||||||
'4FB3ADF22F3C605E23FAEFAA185F3BD763C4692CAC490D9819D117CD33BFAA1B') {
|
'4FB3ADF22F3C605E23FAEFAA185F3BD763C4692CAC490D9819D117CD33BFAA1B') {
|
||||||
const transaction = accountSetTransactionResponse;
|
const transaction = accountSetTransactionResponse;
|
||||||
conn.send(fixtures.transactionResponse(request, transaction));
|
conn.send(fixtures.transactionResponse(request, transaction));
|
||||||
|
} else if (request.transaction ===
|
||||||
|
'10A6FB4A66EE80BED46AAE4815D7DC43B97E944984CCD5B93BCF3F8538CABC51') {
|
||||||
|
const transaction = offerCreateTransactionResponse;
|
||||||
|
conn.send(fixtures.transactionResponse(request, transaction));
|
||||||
|
} else if (request.transaction ===
|
||||||
|
'809335DD3B0B333865096217AA2F55A4DF168E0198080B3A090D12D88880FF0E') {
|
||||||
|
const transaction = offerCancelTransactionResponse;
|
||||||
|
conn.send(fixtures.transactionResponse(request, transaction));
|
||||||
} else if (request.transaction === hashes.NOTFOUND_TRANSACTION_HASH) {
|
} else if (request.transaction === hashes.NOTFOUND_TRANSACTION_HASH) {
|
||||||
conn.send(fixtures.transactionNotFoundResponse(request));
|
conn.send(fixtures.transactionNotFoundResponse(request));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user