Add getPaymentChannel

This commit is contained in:
wilsonianb
2017-04-06 22:27:05 -07:00
parent c8f2967de0
commit 19eb88a00e
21 changed files with 445 additions and 2 deletions

View File

@@ -1113,6 +1113,45 @@ describe('RippleAPI', function() {
});
it('getPaymentChannel', function() {
const channelId =
'E30E709CF009A1F26E0E5C48F7AA1BFB79393764F15FB108BDC6E06D3CBD8415';
return this.api.getPaymentChannel(channelId).then(
_.partial(checkResult, responses.getPaymentChannel.normal,
'getPaymentChannel'));
});
it('getPaymentChannel - full', function() {
const channelId =
'D77CD4713AA08195E6B6D0E5BC023DA11B052EBFF0B5B22EDA8AE85345BCF661';
return this.api.getPaymentChannel(channelId).then(
_.partial(checkResult, responses.getPaymentChannel.full,
'getPaymentChannel'));
});
it('getPaymentChannel - not found', function() {
const channelId =
'DFA557EA3497585BFE83F0F97CC8E4530BBB99967736BB95225C7F0C13ACE708';
return this.api.getPaymentChannel(channelId).then(() => {
assert(false, 'Should throw entryNotFound');
}).catch(error => {
assert(error instanceof this.api.errors.RippledError);
assert(_.includes(error.message, 'entryNotFound'));
});
});
it('getPaymentChannel - wrong type', function() {
const channelId =
'8EF9CCB9D85458C8D020B3452848BBB42EAFDDDB69A93DD9D1223741A4CA562B';
return this.api.getPaymentChannel(channelId).then(() => {
assert(false, 'Should throw NotFoundError');
}).catch(error => {
assert(_.includes(error.message,
'Payment channel ledger entry not found'));
assert(error instanceof this.api.errors.NotFoundError);
});
});
it('getServerInfo', function() {
return this.api.getServerInfo().then(
_.partial(checkResult, responses.getServerInfo, 'getServerInfo'));

View File

@@ -0,0 +1,12 @@
{
"account": "r6ZtfQFWbCkp4XqaUygzHaXsQXBT67xLj",
"amount": "10",
"balance": "3",
"destination": "rQf9vCwQtzQQwtnGvr6zc1fqzqg7QBuj7G",
"publicKey": "02A05282CB6197E34490BACCD9405E81D9DFBE123B0969F9F40EC3F9987AD9A97D",
"settleDelay": 10000,
"cancelAfter": "2017-04-08T00:00:00.000Z",
"expiration": "2017-04-07T06:09:31.000Z",
"previousAffectingTransactionID": "39C47AD0AF1532D6A796EEB90BDA1A61B3EE4FA96C7A08070B78B33CE24F2160",
"previousAffectingTransactionLedgerVersion": 156978
}

View File

@@ -0,0 +1,10 @@
{
"account": "r6ZtfQFWbCkp4XqaUygzHaXsQXBT67xLj",
"amount": "10",
"balance": "0",
"destination": "rQf9vCwQtzQQwtnGvr6zc1fqzqg7QBuj7G",
"publicKey": "02A05282CB6197E34490BACCD9405E81D9DFBE123B0969F9F40EC3F9987AD9A97D",
"settleDelay": 10000,
"previousAffectingTransactionID": "F939A0BEF139465403C56CCDC49F59A77C868C78C5AEC184E29D15E9CD1FF675",
"previousAffectingTransactionLedgerVersion": 151322
}

View File

@@ -16,6 +16,10 @@ module.exports = {
XrpToXrp: require('./get-paths-xrp-to-xrp.json'),
sendAll: require('./get-paths-send-all.json')
},
getPaymentChannel: {
normal: require('./get-payment-channel.json'),
full: require('./get-payment-channel-full.json')
},
getServerInfo: require('./get-server-info.json'),
getSettings: require('./get-settings.json'),
getTransaction: {

24
test/fixtures/rippled/escrow.json vendored Normal file
View File

@@ -0,0 +1,24 @@
{
"id": 0,
"status": "success",
"type": "response",
"result" : {
"node" : {
"index" : "8EF9CCB9D85458C8D020B3452848BBB42EAFDDDB69A93DD9D1223741A4CA562B",
"Destination" : "r6ZtfQFWbCkp4XqaUygzHaXsQXBT67xLj",
"LedgerEntryType" : "Escrow",
"Flags" : 0,
"PreviousTxnID" : "0E85B685CEF53E0364829384C226E5479058FF94AFC27EC4D9A49B3E072708D3",
"PreviousTxnLgrSeq" : 150441,
"OwnerNode" : "0000000000000000",
"CancelAfter" : 544838400,
"Amount" : "1000000",
"Account" : "r6ZtfQFWbCkp4XqaUygzHaXsQXBT67xLj",
"Condition" : "A0258020E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855810100"
},
"index" : "8EF9CCB9D85458C8D020B3452848BBB42EAFDDDB69A93DD9D1223741A4CA562B",
"validated" : true,
"ledger_hash" : "6000B3C351D7DC87A1D1EE30603519E164903B104BD0476A2F908877E121BC88",
"ledger_index" : 174353
}
}

View File

@@ -26,12 +26,16 @@ module.exports = {
normal: require('./account-tx'),
one: require('./get-transactions-one')
},
escrow: require('./escrow'),
gateway_balances: require('./gateway-balances'),
book_offers: {
fabric: require('./book-offers'),
usd_xrp: require('./book-offers-usd-xrp'),
xrp_usd: require('./book-offers-xrp-usd')
},
ledger_entry: {
error: require('./ledger-entry-error')
},
server_info: {
normal: require('./server-info'),
noValidated: require('./server-info-no-validated'),
@@ -46,6 +50,10 @@ module.exports = {
srcActNotFound: require('./path-find-srcActNotFound'),
sourceAmountLow: require('./path-find-srcAmtLow')
},
payment_channel: {
normal: require('./payment-channel'),
full: require('./payment-channel-full')
},
tx: {
Payment: require('./tx/payment.json'),
AccountSet: require('./tx/account-set.json'),

View File

@@ -0,0 +1,14 @@
{
"ledger_index" : 172450,
"validated" : true,
"error" : "entryNotFound",
"ledger_hash" : "9A8B034D72FA6CAE2D69425335FDD59D67DEB18A40DD83DF7331D08B19669A19",
"status" : "error",
"request" : {
"index" : "DFA557EA3497585BFE83F0F97CC8E4530BBB99967736BB95225C7F0C13ACE708",
"binary" : false,
"ledger_index" : "validated",
"command" : "ledger_entry"
},
"type": "response"
}

View File

@@ -0,0 +1,27 @@
{
"id": 0,
"status": "success",
"type": "response",
"result" : {
"node" : {
"Account" : "r6ZtfQFWbCkp4XqaUygzHaXsQXBT67xLj",
"Amount" : "10000000",
"Balance" : "3000000",
"CancelAfter" : 544924800,
"Destination" : "rQf9vCwQtzQQwtnGvr6zc1fqzqg7QBuj7G",
"Expiration" : 544860571,
"Flags" : 0,
"LedgerEntryType" : "PayChannel",
"OwnerNode" : "0000000000000000",
"PreviousTxnID" : "39C47AD0AF1532D6A796EEB90BDA1A61B3EE4FA96C7A08070B78B33CE24F2160",
"PreviousTxnLgrSeq" : 156978,
"PublicKey" : "02A05282CB6197E34490BACCD9405E81D9DFBE123B0969F9F40EC3F9987AD9A97D",
"SettleDelay" : 10000,
"index" : "D77CD4713AA08195E6B6D0E5BC023DA11B052EBFF0B5B22EDA8AE85345BCF661"
},
"index" : "D77CD4713AA08195E6B6D0E5BC023DA11B052EBFF0B5B22EDA8AE85345BCF661",
"validated" : true,
"ledger_hash" : "15CEA3135B7F450C12E4CD0B01140551FA16E5FDA3A7083F9B96BBE24CCBABB9",
"ledger_index" : 157007
}
}

View File

@@ -0,0 +1,25 @@
{
"id": 0,
"status": "success",
"type": "response",
"result" : {
"node" : {
"Balance" : "0",
"SettleDelay" : 10000,
"LedgerEntryType" : "PayChannel",
"Flags" : 0,
"Amount" : "10000000",
"index" : "E30E709CF009A1F26E0E5C48F7AA1BFB79393764F15FB108BDC6E06D3CBD8415",
"Destination" : "rQf9vCwQtzQQwtnGvr6zc1fqzqg7QBuj7G",
"OwnerNode" : "0000000000000000",
"Account" : "r6ZtfQFWbCkp4XqaUygzHaXsQXBT67xLj",
"PublicKey" : "02A05282CB6197E34490BACCD9405E81D9DFBE123B0969F9F40EC3F9987AD9A97D",
"PreviousTxnID" : "F939A0BEF139465403C56CCDC49F59A77C868C78C5AEC184E29D15E9CD1FF675",
"PreviousTxnLgrSeq" : 151322
},
"index" : "E30E709CF009A1F26E0E5C48F7AA1BFB79393764F15FB108BDC6E06D3CBD8415",
"validated" : true,
"ledger_hash" : "5EFF42C5C5DD539D62DC176AF638ED11F2B8B13ACD007D973FF40C44CDC49870",
"ledger_index" : 151336
}
}

View File

@@ -220,6 +220,22 @@ module.exports = function createMockRippled(port) {
}
});
mock.on('request_ledger_entry', function(request, conn) {
assert.strictEqual(request.command, 'ledger_entry');
if (request.index ===
'E30E709CF009A1F26E0E5C48F7AA1BFB79393764F15FB108BDC6E06D3CBD8415') {
conn.send(createResponse(request, fixtures.payment_channel.normal));
} else if (request.index ===
'D77CD4713AA08195E6B6D0E5BC023DA11B052EBFF0B5B22EDA8AE85345BCF661') {
conn.send(createResponse(request, fixtures.payment_channel.full));
} else if (request.index ===
'8EF9CCB9D85458C8D020B3452848BBB42EAFDDDB69A93DD9D1223741A4CA562B') {
conn.send(createResponse(request, fixtures.escrow));
} else {
conn.send(createResponse(request, fixtures.ledger_entry.error));
}
});
mock.on('request_tx', function(request, conn) {
assert.strictEqual(request.command, 'tx');
if (request.transaction === hashes.VALID_TRANSACTION_HASH) {