mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-21 04:35:49 +00:00
cover api/ledger/transaction.js with unit tests
This commit is contained in:
@@ -13,6 +13,7 @@ const sjcl = require('../src').sjcl;
|
|||||||
const address = addresses.ACCOUNT;
|
const address = addresses.ACCOUNT;
|
||||||
const RippleError = require('../src/core/rippleerror').RippleError;
|
const RippleError = require('../src/core/rippleerror').RippleError;
|
||||||
const utils = require('../src/api/ledger/utils');
|
const utils = require('../src/api/ledger/utils');
|
||||||
|
const ledgerClosed = require('./fixtures/api/rippled/ledger-close-newer');
|
||||||
const schemaValidate = require('../src/api/common/schema-validator');
|
const schemaValidate = require('../src/api/common/schema-validator');
|
||||||
|
|
||||||
const orderbook = {
|
const orderbook = {
|
||||||
@@ -204,6 +205,64 @@ describe('RippleAPI', function() {
|
|||||||
'getTransaction', done));
|
'getTransaction', done));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('getTransaction - not found in range', function(done) {
|
||||||
|
const hash =
|
||||||
|
'809335DD3B0B333865096217AA2F55A4DF168E0198080B3A090D12D88880FF0E';
|
||||||
|
const options = {
|
||||||
|
minLedgerVersion: 32570,
|
||||||
|
maxLedgerVersion: 32571
|
||||||
|
};
|
||||||
|
this.api.getTransaction(hash, options, (error) => {
|
||||||
|
assert.ok(error instanceof errors.NotFoundError);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getTransaction - not found by hash', function(done) {
|
||||||
|
this.api.getTransaction(hashes.NOTFOUND_TRANSACTION_HASH, {}, (error) => {
|
||||||
|
assert.ok(error instanceof errors.NotFoundError);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getTransaction - missing ledger history', function(done) {
|
||||||
|
// make gaps in history
|
||||||
|
this.api.remote.getServer().emit('message', ledgerClosed);
|
||||||
|
this.api.getTransaction(hashes.NOTFOUND_TRANSACTION_HASH, {}, (error) => {
|
||||||
|
assert.ok(error instanceof errors.MissingLedgerHistoryError);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getTransaction - ledger_index not found', function(done) {
|
||||||
|
const hash =
|
||||||
|
'4FB3ADF22F3C605E23FAEFAA185F3BD763C4692CAC490D9819D117CD33BFAA11';
|
||||||
|
this.api.getTransaction(hash, {}, (error) => {
|
||||||
|
assert.ok(error instanceof errors.NotFoundError);
|
||||||
|
assert.ok(error.message.indexOf('ledger_index') !== -1);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getTransaction - transaction ledger not found', function(done) {
|
||||||
|
const hash =
|
||||||
|
'4FB3ADF22F3C605E23FAEFAA185F3BD763C4692CAC490D9819D117CD33BFAA12';
|
||||||
|
this.api.getTransaction(hash, {}, (error) => {
|
||||||
|
assert.ok(error instanceof errors.NotFoundError);
|
||||||
|
assert.ok(error.message.indexOf('ledger not found') !== -1);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getTransaction - ledger missing close time', function(done) {
|
||||||
|
const hash =
|
||||||
|
'0F7ED9F40742D8A513AE86029462B7A6768325583DF8EE21B7EC663019DD6A04';
|
||||||
|
this.api.getTransaction(hash, {}, (error) => {
|
||||||
|
assert.ok(error instanceof errors.ApiError);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('getTransactions', function(done) {
|
it('getTransactions', function(done) {
|
||||||
const options = {types: ['payment', 'order'], initiated: true, limit: 2};
|
const options = {types: ['payment', 'order'], initiated: true, limit: 2};
|
||||||
this.api.getTransactions(address, options,
|
this.api.getTransactions(address, options,
|
||||||
@@ -248,8 +307,7 @@ describe('RippleAPI', function() {
|
|||||||
counterparty: address
|
counterparty: address
|
||||||
};
|
};
|
||||||
this.api.getTransactions(address, options, (error) => {
|
this.api.getTransactions(address, options, (error) => {
|
||||||
assert.ok(error instanceof RippleError);
|
assert.ok(error instanceof errors.NotFoundError);
|
||||||
assert.strictEqual(error.remote.error, 'txnNotFound');
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
7
test/fixtures/api/rippled/index.js
vendored
7
test/fixtures/api/rippled/index.js
vendored
@@ -3,6 +3,8 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
submit: require('./submit'),
|
submit: require('./submit'),
|
||||||
ledger: require('./ledger'),
|
ledger: require('./ledger'),
|
||||||
|
ledgerNotFound: require('./ledger-not-found'),
|
||||||
|
ledgerWithoutCloseTime: require('./ledger-without-close-time'),
|
||||||
subscribe: require('./subscribe'),
|
subscribe: require('./subscribe'),
|
||||||
unsubscribe: require('./unsubscribe'),
|
unsubscribe: require('./unsubscribe'),
|
||||||
account_info: {
|
account_info: {
|
||||||
@@ -24,6 +26,9 @@ module.exports = {
|
|||||||
OfferCreate: require('./tx/offer-create.json'),
|
OfferCreate: require('./tx/offer-create.json'),
|
||||||
OfferCancel: require('./tx/offer-cancel.json'),
|
OfferCancel: require('./tx/offer-cancel.json'),
|
||||||
TrustSet: require('./tx/trust-set.json'),
|
TrustSet: require('./tx/trust-set.json'),
|
||||||
NotFound: require('./tx/not-found.json')
|
NotFound: require('./tx/not-found.json'),
|
||||||
|
NoLedgerIndex: require('./tx/no-ledger-index.json'),
|
||||||
|
NoLedgerFound: require('./tx/no-ledger-found.json'),
|
||||||
|
LedgerWithoutTime: require('./tx/ledger-without-time.json')
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
12
test/fixtures/api/rippled/ledger-close-newer.json
vendored
Normal file
12
test/fixtures/api/rippled/ledger-close-newer.json
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"fee_base": 10,
|
||||||
|
"fee_ref": 10,
|
||||||
|
"ledger_hash": "9141FA171F2C0CE63E609466AF728FF66C12F7ACD4B4B50B0947A7F3409D593A",
|
||||||
|
"ledger_index": 14804627,
|
||||||
|
"ledger_time": 490945840,
|
||||||
|
"reserve_base": 20000000,
|
||||||
|
"reserve_inc": 5000000,
|
||||||
|
"txn_count": 19,
|
||||||
|
"type": "ledgerClosed",
|
||||||
|
"validated_ledgers": "13983423-14804627"
|
||||||
|
}
|
||||||
13
test/fixtures/api/rippled/ledger-not-found.json
vendored
Normal file
13
test/fixtures/api/rippled/ledger-not-found.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"id": 0,
|
||||||
|
"status": "error",
|
||||||
|
"type": "response",
|
||||||
|
"error": "lgrNotFound",
|
||||||
|
"error_code": 20,
|
||||||
|
"error_message": "ledgerNotFound",
|
||||||
|
"request": {
|
||||||
|
"command": "ledger",
|
||||||
|
"id": 3,
|
||||||
|
"ledger_index": 34
|
||||||
|
}
|
||||||
|
}
|
||||||
26
test/fixtures/api/rippled/ledger-without-close-time.json
vendored
Normal file
26
test/fixtures/api/rippled/ledger-without-close-time.json
vendored
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"id": 0,
|
||||||
|
"status": "success",
|
||||||
|
"type": "response",
|
||||||
|
"result": {
|
||||||
|
"ledger": {
|
||||||
|
"accepted": true,
|
||||||
|
"account_hash": "EC028EC32896D537ECCA18D18BEBE6AE99709FEFF9EF72DBD3A7819E918D8B96",
|
||||||
|
"close_time_human": "2014-Sep-24 21:21:50",
|
||||||
|
"close_time_resolution": 10,
|
||||||
|
"closed": true,
|
||||||
|
"hash": "0F7ED9F40742D8A513AE86029462B7A6768325583DF8EE21B7EC663019DD6A04",
|
||||||
|
"ledger_hash": "0F7ED9F40742D8A513AE86029462B7A6768325583DF8EE21B7EC663019DD6A01",
|
||||||
|
"ledger_index": "9038215",
|
||||||
|
"parent_hash": "4BB9CBE44C39DC67A1BE849C7467FE1A6D1F73949EA163C38A0121A15E04FFDE",
|
||||||
|
"seqNum": "9038214",
|
||||||
|
"totalCoins": "99999973964317514",
|
||||||
|
"total_coins": "99999973964317514",
|
||||||
|
"transaction_hash": "ECB730839EB55B1B114D5D1AD2CD9A932C35BA9AB6D3A8C2F08935EAC2BAC239",
|
||||||
|
"transactions": [
|
||||||
|
"1FC4D12C30CE206A6E23F46FAC62BD393BE9A79A1C452C6F3A04A13BC7A5E5A3",
|
||||||
|
"E25C38FDB8DD4A2429649588638EE05D055EE6D839CABAF8ABFB4BD17CFE1F3E"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
45
test/fixtures/api/rippled/tx/ledger-without-time.json
vendored
Normal file
45
test/fixtures/api/rippled/tx/ledger-without-time.json
vendored
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
{
|
||||||
|
"id": 0,
|
||||||
|
"status": "success",
|
||||||
|
"type": "response",
|
||||||
|
"result": {
|
||||||
|
"Account": "rLVKsA4F9iJBbA6rX2x4wCmkj6drgtqpQe",
|
||||||
|
"Fee": "10",
|
||||||
|
"Flags": 2147483648,
|
||||||
|
"Sequence": 1,
|
||||||
|
"SetFlag": 2,
|
||||||
|
"SigningPubKey": "03EA3ADCA632F125EC2CC4F7F6A82DE0DCE2B65290CAC1F22242C5163F0DA9652D",
|
||||||
|
"TransactionType": "AccountSet",
|
||||||
|
"TxnSignature": "3045022100DE8B666B1A31EA65011B0F32130AB91A5747E32FA49B3054CEE8E8362DBAB98A022040CF0CF254677A8E5CD04C59CA2ED7F6F15F7E184641BAE169C561650967B226",
|
||||||
|
"hash": "4FB3ADF22F3C605E23FAEFAA185F3BD763C4692CAC490D9819D117CD33BFAA12",
|
||||||
|
"inLedger": 8206418,
|
||||||
|
"ledger_index": 9038215,
|
||||||
|
"meta": {
|
||||||
|
"AffectedNodes": [
|
||||||
|
{
|
||||||
|
"ModifiedNode": {
|
||||||
|
"FinalFields": {
|
||||||
|
"Account": "rLVKsA4F9iJBbA6rX2x4wCmkj6drgtqpQe",
|
||||||
|
"Balance": "29999990",
|
||||||
|
"Flags": 786432,
|
||||||
|
"OwnerCount": 0,
|
||||||
|
"Sequence": 2
|
||||||
|
},
|
||||||
|
"LedgerEntryType": "AccountRoot",
|
||||||
|
"LedgerIndex": "3F5072C4875F32ED770DAF3610A716600ED7C7BB0348FADC7A98E011BB2CD36F",
|
||||||
|
"PreviousFields": {
|
||||||
|
"Balance": "30000000",
|
||||||
|
"Flags": 4194304,
|
||||||
|
"Sequence": 1
|
||||||
|
},
|
||||||
|
"PreviousTxnID": "3FB0350A3742BBCC0D8AA3C5247D1AEC01177D0A24D9C34762BAA2FEA8AD88B3",
|
||||||
|
"PreviousTxnLgrSeq": 8206397
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"TransactionIndex": 5,
|
||||||
|
"TransactionResult": "tesSUCCESS"
|
||||||
|
},
|
||||||
|
"validated": true
|
||||||
|
}
|
||||||
|
}
|
||||||
45
test/fixtures/api/rippled/tx/no-ledger-found.json
vendored
Normal file
45
test/fixtures/api/rippled/tx/no-ledger-found.json
vendored
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
{
|
||||||
|
"id": 0,
|
||||||
|
"status": "success",
|
||||||
|
"type": "response",
|
||||||
|
"result": {
|
||||||
|
"Account": "rLVKsA4F9iJBbA6rX2x4wCmkj6drgtqpQe",
|
||||||
|
"Fee": "10",
|
||||||
|
"Flags": 2147483648,
|
||||||
|
"Sequence": 1,
|
||||||
|
"SetFlag": 2,
|
||||||
|
"SigningPubKey": "03EA3ADCA632F125EC2CC4F7F6A82DE0DCE2B65290CAC1F22242C5163F0DA9652D",
|
||||||
|
"TransactionType": "AccountSet",
|
||||||
|
"TxnSignature": "3045022100DE8B666B1A31EA65011B0F32130AB91A5747E32FA49B3054CEE8E8362DBAB98A022040CF0CF254677A8E5CD04C59CA2ED7F6F15F7E184641BAE169C561650967B226",
|
||||||
|
"hash": "4FB3ADF22F3C605E23FAEFAA185F3BD763C4692CAC490D9819D117CD33BFAA12",
|
||||||
|
"inLedger": 8206418,
|
||||||
|
"ledger_index": 34,
|
||||||
|
"meta": {
|
||||||
|
"AffectedNodes": [
|
||||||
|
{
|
||||||
|
"ModifiedNode": {
|
||||||
|
"FinalFields": {
|
||||||
|
"Account": "rLVKsA4F9iJBbA6rX2x4wCmkj6drgtqpQe",
|
||||||
|
"Balance": "29999990",
|
||||||
|
"Flags": 786432,
|
||||||
|
"OwnerCount": 0,
|
||||||
|
"Sequence": 2
|
||||||
|
},
|
||||||
|
"LedgerEntryType": "AccountRoot",
|
||||||
|
"LedgerIndex": "3F5072C4875F32ED770DAF3610A716600ED7C7BB0348FADC7A98E011BB2CD36F",
|
||||||
|
"PreviousFields": {
|
||||||
|
"Balance": "30000000",
|
||||||
|
"Flags": 4194304,
|
||||||
|
"Sequence": 1
|
||||||
|
},
|
||||||
|
"PreviousTxnID": "3FB0350A3742BBCC0D8AA3C5247D1AEC01177D0A24D9C34762BAA2FEA8AD88B3",
|
||||||
|
"PreviousTxnLgrSeq": 8206397
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"TransactionIndex": 5,
|
||||||
|
"TransactionResult": "tesSUCCESS"
|
||||||
|
},
|
||||||
|
"validated": true
|
||||||
|
}
|
||||||
|
}
|
||||||
44
test/fixtures/api/rippled/tx/no-ledger-index.json
vendored
Normal file
44
test/fixtures/api/rippled/tx/no-ledger-index.json
vendored
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
{
|
||||||
|
"id": 0,
|
||||||
|
"status": "success",
|
||||||
|
"type": "response",
|
||||||
|
"result": {
|
||||||
|
"Account": "rLVKsA4F9iJBbA6rX2x4wCmkj6drgtqpQe",
|
||||||
|
"Fee": "10",
|
||||||
|
"Flags": 2147483648,
|
||||||
|
"Sequence": 1,
|
||||||
|
"SetFlag": 2,
|
||||||
|
"SigningPubKey": "03EA3ADCA632F125EC2CC4F7F6A82DE0DCE2B65290CAC1F22242C5163F0DA9652D",
|
||||||
|
"TransactionType": "AccountSet",
|
||||||
|
"TxnSignature": "3045022100DE8B666B1A31EA65011B0F32130AB91A5747E32FA49B3054CEE8E8362DBAB98A022040CF0CF254677A8E5CD04C59CA2ED7F6F15F7E184641BAE169C561650967B226",
|
||||||
|
"hash": "4FB3ADF22F3C605E23FAEFAA185F3BD763C4692CAC490D9819D117CD33BFAA11",
|
||||||
|
"inLedger": 8206418,
|
||||||
|
"meta": {
|
||||||
|
"AffectedNodes": [
|
||||||
|
{
|
||||||
|
"ModifiedNode": {
|
||||||
|
"FinalFields": {
|
||||||
|
"Account": "rLVKsA4F9iJBbA6rX2x4wCmkj6drgtqpQe",
|
||||||
|
"Balance": "29999990",
|
||||||
|
"Flags": 786432,
|
||||||
|
"OwnerCount": 0,
|
||||||
|
"Sequence": 2
|
||||||
|
},
|
||||||
|
"LedgerEntryType": "AccountRoot",
|
||||||
|
"LedgerIndex": "3F5072C4875F32ED770DAF3610A716600ED7C7BB0348FADC7A98E011BB2CD36F",
|
||||||
|
"PreviousFields": {
|
||||||
|
"Balance": "30000000",
|
||||||
|
"Flags": 4194304,
|
||||||
|
"Sequence": 1
|
||||||
|
},
|
||||||
|
"PreviousTxnID": "3FB0350A3742BBCC0D8AA3C5247D1AEC01177D0A24D9C34762BAA2FEA8AD88B3",
|
||||||
|
"PreviousTxnLgrSeq": 8206397
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"TransactionIndex": 5,
|
||||||
|
"TransactionResult": "tesSUCCESS"
|
||||||
|
},
|
||||||
|
"validated": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -111,7 +111,13 @@ module.exports = function(port) {
|
|||||||
|
|
||||||
mock.on('request_ledger', function(request, conn) {
|
mock.on('request_ledger', function(request, conn) {
|
||||||
assert.strictEqual(request.command, 'ledger');
|
assert.strictEqual(request.command, 'ledger');
|
||||||
|
if (request.ledger_index === 34) {
|
||||||
|
conn.send(createResponse(request, fixtures.ledgerNotFound));
|
||||||
|
} else if (request.ledger_index === 9038215) {
|
||||||
|
conn.send(createResponse(request, fixtures.ledgerWithoutCloseTime));
|
||||||
|
} else {
|
||||||
conn.send(createResponse(request, fixtures.ledger));
|
conn.send(createResponse(request, fixtures.ledger));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mock.on('request_tx', function(request, conn) {
|
mock.on('request_tx', function(request, conn) {
|
||||||
@@ -130,6 +136,15 @@ module.exports = function(port) {
|
|||||||
} else if (request.transaction ===
|
} else if (request.transaction ===
|
||||||
'635A0769BD94710A1F6A76CDE65A3BC661B20B798807D1BBBDADCEA26420538D') {
|
'635A0769BD94710A1F6A76CDE65A3BC661B20B798807D1BBBDADCEA26420538D') {
|
||||||
conn.send(createResponse(request, fixtures.tx.TrustSet));
|
conn.send(createResponse(request, fixtures.tx.TrustSet));
|
||||||
|
} else if (request.transaction ===
|
||||||
|
'4FB3ADF22F3C605E23FAEFAA185F3BD763C4692CAC490D9819D117CD33BFAA11') {
|
||||||
|
conn.send(createResponse(request, fixtures.tx.NoLedgerIndex));
|
||||||
|
} else if (request.transaction ===
|
||||||
|
'4FB3ADF22F3C605E23FAEFAA185F3BD763C4692CAC490D9819D117CD33BFAA12') {
|
||||||
|
conn.send(createResponse(request, fixtures.tx.NoLedgerFound));
|
||||||
|
} else if (request.transaction ===
|
||||||
|
'0F7ED9F40742D8A513AE86029462B7A6768325583DF8EE21B7EC663019DD6A04') {
|
||||||
|
conn.send(createResponse(request, fixtures.tx.LedgerWithoutTime));
|
||||||
} else if (request.transaction === hashes.NOTFOUND_TRANSACTION_HASH) {
|
} else if (request.transaction === hashes.NOTFOUND_TRANSACTION_HASH) {
|
||||||
conn.send(createResponse(request, fixtures.tx.NotFound));
|
conn.send(createResponse(request, fixtures.tx.NotFound));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user