diff --git a/package.json b/package.json index 3587cbc5..c0f4c2c1 100644 --- a/package.json +++ b/package.json @@ -25,11 +25,13 @@ "superagent": "^0.18.0" }, "devDependencies": { + "assert-diff": "0.0.4", "coveralls": "~2.10.0", "gulp": "~3.6.2", "gulp-bump": "~0.1.10", "gulp-clean-dest": "^0.1.0", "gulp-concat": "~2.2.0", + "gulp-eslint": "^0.2.0", "gulp-filelog": "^0.4.1", "gulp-flowtype": "^0.4.1", "gulp-plumber": "^0.6.6", @@ -38,7 +40,6 @@ "gulp-uglify": "~0.3.0", "gulp-util": "^3.0.2", "gulp-watch": "^3.0.0", - "gulp-eslint": "^0.2.0", "istanbul": "~0.2.10", "map-stream": "~0.1.0", "mocha": "~1.14.0", diff --git a/src/js/ripple/orderbook.js b/src/js/ripple/orderbook.js index aaa598f1..2c5cb4cf 100644 --- a/src/js/ripple/orderbook.js +++ b/src/js/ripple/orderbook.js @@ -439,7 +439,14 @@ OrderBook.prototype.setFundedAmount = function(offer, fundedAmount) { return offer; } - offer.taker_gets_funded = fundedAmount; + var isOfferGetsExceeded = Amount.from_json(fundedAmount) + .compareTo(offer.TakerGets) > 0; + + if (isOfferGetsExceeded) { + offer.taker_gets_funded = offer.TakerGets; + } else { + offer.taker_gets_funded = fundedAmount; + } var takerPaysValue = (typeof offer.TakerPays === 'object') ? offer.TakerPays.value diff --git a/test/orderbook-test.js b/test/orderbook-test.js index 80a34117..77835344 100644 --- a/test/orderbook-test.js +++ b/test/orderbook-test.js @@ -1,4 +1,4 @@ -var assert = require('assert'); +var assert = require('assert-diff'); var Remote = require('ripple-lib').Remote; var Currency = require('ripple-lib').Currency; var Amount = require('ripple-lib').Amount; @@ -756,75 +756,75 @@ describe('OrderBook', function() { var meta = new Meta({ AffectedNodes: [ { - ModifiedNode: { - FinalFields: { - Balance: { - currency: 'USD', - issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji', - value: '10' + ModifiedNode: { + FinalFields: { + Balance: { + currency: 'USD', + issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji', + value: '10' + }, + Flags: 131072, + HighLimit: { + currency: 'USD', + issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji', + value: '100' + }, + HighNode: '0000000000000000', + LowLimit: { + currency: 'USD', + issuer: 'r3PDtZSa5LiYp1Ysn1vMuMzB59RzV3W9QH', + value: '0' + }, + LowNode: '0000000000000000' }, - Flags: 131072, - HighLimit: { - currency: 'USD', - issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji', - value: '100' + LedgerEntryType: 'RippleState', + LedgerIndex: 'EA4BF03B4700123CDFFB6EB09DC1D6E28D5CEB7F680FB00FC24BC1C3BB2DB959', + PreviousFields: { + Balance: { + currency: 'USD', + issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji', + value: '0' + } }, - HighNode: '0000000000000000', - LowLimit: { - currency: 'USD', - issuer: 'r3PDtZSa5LiYp1Ysn1vMuMzB59RzV3W9QH', - value: '0' - }, - LowNode: '0000000000000000' - }, - LedgerEntryType: 'RippleState', - LedgerIndex: 'EA4BF03B4700123CDFFB6EB09DC1D6E28D5CEB7F680FB00FC24BC1C3BB2DB959', - PreviousFields: { - Balance: { - currency: 'USD', - issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji', - value: '0' - } - }, - PreviousTxnID: '53354D84BAE8FDFC3F4DA879D984D24B929E7FEB9100D2AD9EFCD2E126BCCDC8', - PreviousTxnLgrSeq: 343570 - } - }, + PreviousTxnID: '53354D84BAE8FDFC3F4DA879D984D24B929E7FEB9100D2AD9EFCD2E126BCCDC8', + PreviousTxnLgrSeq: 343570 + } + }, { - ModifiedNode: { - FinalFields: { - Balance: { - currency: 'USD', - issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji', - value: '-10' + ModifiedNode: { + FinalFields: { + Balance: { + currency: 'USD', + issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji', + value: '-10' + }, + Flags: 131072, + HighLimit: { + currency: 'USD', + issuer: 'r3PDtZSa5LiYp1Ysn1vMuMzB59RzV3W9QH', + value: '100' + }, + HighNode: '0000000000000000', + LowLimit: { + currency: 'USD', + issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji', + value: '0' + }, + LowNode: '0000000000000000' }, - Flags: 131072, - HighLimit: { - currency: 'USD', - issuer: 'r3PDtZSa5LiYp1Ysn1vMuMzB59RzV3W9QH', - value: '100' + LedgerEntryType: 'RippleState', + LedgerIndex: 'EA4BF03B4700123CDFFB6EB09DC1D6E28D5CEB7F680FB00FC24BC1C3BB2DB959', + PreviousFields: { + Balance: { + currency: 'USD', + issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji', + value: '0' + } }, - HighNode: '0000000000000000', - LowLimit: { - currency: 'USD', - issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji', - value: '0' - }, - LowNode: '0000000000000000' - }, - LedgerEntryType: 'RippleState', - LedgerIndex: 'EA4BF03B4700123CDFFB6EB09DC1D6E28D5CEB7F680FB00FC24BC1C3BB2DB959', - PreviousFields: { - Balance: { - currency: 'USD', - issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji', - value: '0' - } - }, - PreviousTxnID: '53354D84BAE8FDFC3F4DA879D984D24B929E7FEB9100D2AD9EFCD2E126BCCDC8', - PreviousTxnLgrSeq: 343570 + PreviousTxnID: '53354D84BAE8FDFC3F4DA879D984D24B929E7FEB9100D2AD9EFCD2E126BCCDC8', + PreviousTxnLgrSeq: 343570 + } } - } ] }); @@ -934,103 +934,103 @@ describe('OrderBook', function() { book._offers = [ { - Account: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', - BookDirectory: '4627DFFCFF8B5A265EDBD8AE8C14A52325DBFEDAF4F5C32E5D06F15E821839FB', - BookNode: '0000000000000000', - Flags: 0, - LedgerEntryType: 'Offer', - OwnerNode: '0000000000001897', - PreviousTxnID: '11BA57676711A42C2FC2191EAEE98023B04627DFA84926B0C8E9D61A9CAF13AD', - PreviousTxnLgrSeq: 8265601, - Sequence: 531927, - TakerGets: { - currency: 'USD', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '19.84580331' + Account: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', + BookDirectory: '4627DFFCFF8B5A265EDBD8AE8C14A52325DBFEDAF4F5C32E5D06F15E821839FB', + BookNode: '0000000000000000', + Flags: 0, + LedgerEntryType: 'Offer', + OwnerNode: '0000000000001897', + PreviousTxnID: '11BA57676711A42C2FC2191EAEE98023B04627DFA84926B0C8E9D61A9CAF13AD', + PreviousTxnLgrSeq: 8265601, + Sequence: 531927, + TakerGets: { + currency: 'USD', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '19.84580331' + }, + taker_gets_funded: '100', + is_fully_funded: true, + TakerPays: '3878342440', + index: '06AFB03237286C1566CD649CFD5388C2C1F5BEFC5C3302A1962682803A9946FA', + owner_funds: '318.3643710638508', + quality: '195423807.2109563' }, - taker_gets_funded: '100', - is_fully_funded: true, - TakerPays: '3878342440', - index: '06AFB03237286C1566CD649CFD5388C2C1F5BEFC5C3302A1962682803A9946FA', - owner_funds: '318.3643710638508', - quality: '195423807.2109563' - }, - { - Account: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', - BookDirectory: '4627DFFCFF8B5A265EDBD8AE8C14A52325DBFEDAF4F5C32E5D06F4C3362FE1D0', - BookNode: '0000000000000000', - Flags: 0, - LedgerEntryType: 'Offer', - OwnerNode: '00000000000063CC', - PreviousTxnID: 'CD77500EF28984BFC123E8A257C10E44FF486EA8FC43E1356C42BD6DB853A602', - PreviousTxnLgrSeq: 8265523, - Sequence: 1139002, - TakerGets: { - currency: 'USD', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '4.9656112525' + { + Account: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', + BookDirectory: '4627DFFCFF8B5A265EDBD8AE8C14A52325DBFEDAF4F5C32E5D06F4C3362FE1D0', + BookNode: '0000000000000000', + Flags: 0, + LedgerEntryType: 'Offer', + OwnerNode: '00000000000063CC', + PreviousTxnID: 'CD77500EF28984BFC123E8A257C10E44FF486EA8FC43E1356C42BD6DB853A602', + PreviousTxnLgrSeq: 8265523, + Sequence: 1139002, + TakerGets: { + currency: 'USD', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '4.9656112525' + }, + taker_gets_funded: '100', + is_fully_funded: true, + TakerPays: '972251352', + index: 'D3338DA77BA23122FB5647B74B53636AB54BE246D4B21707C9D6887DEB334252', + owner_funds: '235.0194163432668', + quality: '195796912.5171664' }, - taker_gets_funded: '100', - is_fully_funded: true, - TakerPays: '972251352', - index: 'D3338DA77BA23122FB5647B74B53636AB54BE246D4B21707C9D6887DEB334252', - owner_funds: '235.0194163432668', - quality: '195796912.5171664' - }, - { - Account: 'r8cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', - BookDirectory: '4627DFFCFF8B5A265EDBD8AE8C14A52325DBFEDAF4F5C32E5D06F4C3362FE1D0', - BookNode: '0000000000000000', - Flags: 0, - LedgerEntryType: 'Offer', - OwnerNode: '00000000000063CC', - PreviousTxnID: 'CD77500EF28984BFC123E8A257C10E44FF486EA8FC43E1356C42BD6DB853A602', - PreviousTxnLgrSeq: 8265523, - Sequence: 1139002, - TakerGets: { - currency: 'USD', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '4.9656112525' + { + Account: 'r8cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', + BookDirectory: '4627DFFCFF8B5A265EDBD8AE8C14A52325DBFEDAF4F5C32E5D06F4C3362FE1D0', + BookNode: '0000000000000000', + Flags: 0, + LedgerEntryType: 'Offer', + OwnerNode: '00000000000063CC', + PreviousTxnID: 'CD77500EF28984BFC123E8A257C10E44FF486EA8FC43E1356C42BD6DB853A602', + PreviousTxnLgrSeq: 8265523, + Sequence: 1139002, + TakerGets: { + currency: 'USD', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '4.9656112525' + }, + taker_gets_funded: '100', + is_fully_funded: true, + TakerPays: '972251352', + index: 'D3338DA77BA23122FB5647B74B53636AB54BE246D4B21707C9D6887DEB334252', + owner_funds: '235.0194163432668', + quality: '195796912.5171664' }, - taker_gets_funded: '100', - is_fully_funded: true, - TakerPays: '972251352', - index: 'D3338DA77BA23122FB5647B74B53636AB54BE246D4B21707C9D6887DEB334252', - owner_funds: '235.0194163432668', - quality: '195796912.5171664' - }, ]; - var receivedChangedEvents = 0; - var receivedFundsChangedEvents = 0; + var receivedChangedEvents = 0; + var receivedFundsChangedEvents = 0; - book.on('offer_changed', function(offer) { - receivedChangedEvents += 1; - }); + book.on('offer_changed', function(offer) { + receivedChangedEvents += 1; + }); - book.on('offer_funds_changed', function(offer, previousFunds, newFunds) { - assert.strictEqual(previousFunds, '100'); - assert.strictEqual(newFunds, offer.taker_gets_funded); - assert.notStrictEqual(previousFunds, newFunds); - switch (++receivedFundsChangedEvents) { - case 1: - assert(!offer.is_fully_funded); - break; - case 2: - assert(offer.is_fully_funded); - break; - } - }); + book.on('offer_funds_changed', function(offer, previousFunds, newFunds) { + assert.strictEqual(previousFunds, '100'); + assert.strictEqual(newFunds, offer.taker_gets_funded); + assert.notStrictEqual(previousFunds, newFunds); + switch (++receivedFundsChangedEvents) { + case 1: + assert(!offer.is_fully_funded); + break; + case 2: + assert(offer.is_fully_funded); + break; + } + }); - book.addCachedFunds('r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', '100'); - book.updateFundedAmounts(message); + book.addCachedFunds('r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', '100'); + book.updateFundedAmounts(message); - setImmediate(function() { - book.getCachedFunds('r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', '10'); - assert.strictEqual(receivedChangedEvents, 2); - assert.strictEqual(receivedFundsChangedEvents, 2); - done(); - }); + setImmediate(function() { + book.getCachedFunds('r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', '10'); + assert.strictEqual(receivedChangedEvents, 2); + assert.strictEqual(receivedFundsChangedEvents, 2); + done(); + }); }); it('Update funded amounts - native currency', function(done) { @@ -1071,101 +1071,101 @@ describe('OrderBook', function() { book._offers = [ { - Account: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', - BookDirectory: 'DFA3B6DDAB58C7E8E5D944E736DA4B7046C30E4F460FD9DE4C124AF94ED1781B', - BookNode: '0000000000000000', - Flags: 0, - LedgerEntryType: 'Offer', - OwnerNode: '00000000000063CA', - PreviousTxnID: '51C64E0B300E9C0E877BA3E79B4ED1DBD5FDDCE58FA1A8FDA5F8DDF139787A24', - PreviousTxnLgrSeq: 8265275, - Sequence: 1138918, - TakerGets: '50', - taker_gets_funded: '100', - is_fully_funded: true, - TakerPays: { - currency: 'USD', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '5' + Account: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', + BookDirectory: 'DFA3B6DDAB58C7E8E5D944E736DA4B7046C30E4F460FD9DE4C124AF94ED1781B', + BookNode: '0000000000000000', + Flags: 0, + LedgerEntryType: 'Offer', + OwnerNode: '00000000000063CA', + PreviousTxnID: '51C64E0B300E9C0E877BA3E79B4ED1DBD5FDDCE58FA1A8FDA5F8DDF139787A24', + PreviousTxnLgrSeq: 8265275, + Sequence: 1138918, + TakerGets: '50', + taker_gets_funded: '100', + is_fully_funded: true, + TakerPays: { + currency: 'USD', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '5' + }, + index: 'DC003E09AD1306FBBD1957C955EE668E429CC85B0EC0EC17297F6676E6108DE7', + owner_funds: '162110617177', + quality: '0.000000005148984210454555' }, - index: 'DC003E09AD1306FBBD1957C955EE668E429CC85B0EC0EC17297F6676E6108DE7', - owner_funds: '162110617177', - quality: '0.000000005148984210454555' - }, - { - Account: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', - BookDirectory: 'DFA3B6DDAB58C7E8E5D944E736DA4B7046C30E4F460FD9DE4C124B054BAD1D79', - BookNode: '0000000000000000', - Flags: 0, - LedgerEntryType: 'Offer', - OwnerNode: '0000000000001896', - PreviousTxnID: '9B21C7A4B66DC1CD5FC9D85C821C4CAA8F80E437582BAD11E88A1E9E6C7AA59C', - PreviousTxnLgrSeq: 8265118, - Sequence: 531856, - TakerGets: '10', - taker_gets_funded: '100', - is_fully_funded: true, - TakerPays: { - currency: 'USD', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '20' + { + Account: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', + BookDirectory: 'DFA3B6DDAB58C7E8E5D944E736DA4B7046C30E4F460FD9DE4C124B054BAD1D79', + BookNode: '0000000000000000', + Flags: 0, + LedgerEntryType: 'Offer', + OwnerNode: '0000000000001896', + PreviousTxnID: '9B21C7A4B66DC1CD5FC9D85C821C4CAA8F80E437582BAD11E88A1E9E6C7AA59C', + PreviousTxnLgrSeq: 8265118, + Sequence: 531856, + TakerGets: '10', + taker_gets_funded: '100', + is_fully_funded: true, + TakerPays: { + currency: 'USD', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '20' + }, + index: '7AC0458676A54E99FAA5ED0A56CD0CB814D3DEFE1C7874F0BB39875D60668E41', + owner_funds: '430527438338', + quality: '0.000000005149035697347961' }, - index: '7AC0458676A54E99FAA5ED0A56CD0CB814D3DEFE1C7874F0BB39875D60668E41', - owner_funds: '430527438338', - quality: '0.000000005149035697347961' - }, - { - Account: 'r8cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', - BookDirectory: '4627DFFCFF8B5A265EDBD8AE8C14A52325DBFEDAF4F5C32E5D06F4C3362FE1D0', - BookNode: '0000000000000000', - Flags: 0, - LedgerEntryType: 'Offer', - OwnerNode: '00000000000063CC', - PreviousTxnID: 'CD77500EF28984BFC123E8A257C10E44FF486EA8FC43E1356C42BD6DB853A602', - PreviousTxnLgrSeq: 8265523, - Sequence: 1139002, - TakerGets: { - currency: 'USD', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '4.9656112525' + { + Account: 'r8cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', + BookDirectory: '4627DFFCFF8B5A265EDBD8AE8C14A52325DBFEDAF4F5C32E5D06F4C3362FE1D0', + BookNode: '0000000000000000', + Flags: 0, + LedgerEntryType: 'Offer', + OwnerNode: '00000000000063CC', + PreviousTxnID: 'CD77500EF28984BFC123E8A257C10E44FF486EA8FC43E1356C42BD6DB853A602', + PreviousTxnLgrSeq: 8265523, + Sequence: 1139002, + TakerGets: { + currency: 'USD', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '4.9656112525' + }, + TakerPays: '972251352', + index: 'D3338DA77BA23122FB5647B74B53636AB54BE246D4B21707C9D6887DEB334252', + owner_funds: '235.0194163432668', + quality: '195796912.5171664' }, - TakerPays: '972251352', - index: 'D3338DA77BA23122FB5647B74B53636AB54BE246D4B21707C9D6887DEB334252', - owner_funds: '235.0194163432668', - quality: '195796912.5171664' - }, ]; - var receivedChangedEvents = 0; - var receivedFundsChangedEvents = 0; + var receivedChangedEvents = 0; + var receivedFundsChangedEvents = 0; - book.on('offer_changed', function(offer) { - receivedChangedEvents += 1; - }); + book.on('offer_changed', function(offer) { + receivedChangedEvents += 1; + }); - book.on('offer_funds_changed', function(offer, previousFunds, newFunds) { - assert.strictEqual(previousFunds, '100'); - assert.strictEqual(newFunds, offer.taker_gets_funded); - assert.notStrictEqual(previousFunds, newFunds); - switch (++receivedFundsChangedEvents) { - case 1: - assert(!offer.is_fully_funded); - break; - case 2: - assert(offer.is_fully_funded); - break; - } - }); + book.on('offer_funds_changed', function(offer, previousFunds, newFunds) { + assert.strictEqual(previousFunds, '100'); + assert.strictEqual(newFunds, offer.taker_gets_funded); + assert.notStrictEqual(previousFunds, newFunds); + switch (++receivedFundsChangedEvents) { + case 1: + assert(!offer.is_fully_funded); + break; + case 2: + assert(offer.is_fully_funded); + break; + } + }); - book.addCachedFunds('r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', '100'); - book.updateFundedAmounts(message); + book.addCachedFunds('r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', '100'); + book.updateFundedAmounts(message); - setImmediate(function() { - book.getCachedFunds('r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', '25'); - assert.strictEqual(receivedChangedEvents, 2); - assert.strictEqual(receivedFundsChangedEvents, 2); - done(); - }); + setImmediate(function() { + book.getCachedFunds('r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', '25'); + assert.strictEqual(receivedChangedEvents, 2); + assert.strictEqual(receivedFundsChangedEvents, 2); + done(); + }); }); it('Update funded amounts - no affected account', function(done) { @@ -1206,27 +1206,27 @@ describe('OrderBook', function() { book._offers = [ { - Account: 'rrrrrrrrrrrrrrrrrrrrBZbvji', - BookDirectory: 'DFA3B6DDAB58C7E8E5D944E736DA4B7046C30E4F460FD9DE4C124AF94ED1781B', - BookNode: '0000000000000000', - Flags: 0, - LedgerEntryType: 'Offer', - OwnerNode: '00000000000063CA', - PreviousTxnID: '51C64E0B300E9C0E877BA3E79B4ED1DBD5FDDCE58FA1A8FDA5F8DDF139787A24', - PreviousTxnLgrSeq: 8265275, - Sequence: 1138918, - TakerGets: '50', - taker_gets_funded: '100', - is_fully_funded: true, - TakerPays: { - currency: 'USD', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '5' - }, - index: 'DC003E09AD1306FBBD1957C955EE668E429CC85B0EC0EC17297F6676E6108DE7', - owner_funds: '162110617177', - quality: '0.000000005148984210454555' - } + Account: 'rrrrrrrrrrrrrrrrrrrrBZbvji', + BookDirectory: 'DFA3B6DDAB58C7E8E5D944E736DA4B7046C30E4F460FD9DE4C124AF94ED1781B', + BookNode: '0000000000000000', + Flags: 0, + LedgerEntryType: 'Offer', + OwnerNode: '00000000000063CA', + PreviousTxnID: '51C64E0B300E9C0E877BA3E79B4ED1DBD5FDDCE58FA1A8FDA5F8DDF139787A24', + PreviousTxnLgrSeq: 8265275, + Sequence: 1138918, + TakerGets: '50', + taker_gets_funded: '100', + is_fully_funded: true, + TakerPays: { + currency: 'USD', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '5' + }, + index: 'DC003E09AD1306FBBD1957C955EE668E429CC85B0EC0EC17297F6676E6108DE7', + owner_funds: '162110617177', + quality: '0.000000005148984210454555' + } ]; book._offers.__defineGetter__(0, function() { @@ -1279,27 +1279,27 @@ describe('OrderBook', function() { book._offers = [ { - Account: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', - BookDirectory: 'DFA3B6DDAB58C7E8E5D944E736DA4B7046C30E4F460FD9DE4C124AF94ED1781B', - BookNode: '0000000000000000', - Flags: 0, - LedgerEntryType: 'Offer', - OwnerNode: '00000000000063CA', - PreviousTxnID: '51C64E0B300E9C0E877BA3E79B4ED1DBD5FDDCE58FA1A8FDA5F8DDF139787A24', - PreviousTxnLgrSeq: 8265275, - Sequence: 1138918, - TakerGets: '50', - taker_gets_funded: '100', - is_fully_funded: true, - TakerPays: { - currency: 'USD', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '5' - }, - index: 'DC003E09AD1306FBBD1957C955EE668E429CC85B0EC0EC17297F6676E6108DE7', - owner_funds: '162110617177', - quality: '0.000000005148984210454555' - } + Account: 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59', + BookDirectory: 'DFA3B6DDAB58C7E8E5D944E736DA4B7046C30E4F460FD9DE4C124AF94ED1781B', + BookNode: '0000000000000000', + Flags: 0, + LedgerEntryType: 'Offer', + OwnerNode: '00000000000063CA', + PreviousTxnID: '51C64E0B300E9C0E877BA3E79B4ED1DBD5FDDCE58FA1A8FDA5F8DDF139787A24', + PreviousTxnLgrSeq: 8265275, + Sequence: 1138918, + TakerGets: '50', + taker_gets_funded: '100', + is_fully_funded: true, + TakerPays: { + currency: 'USD', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '5' + }, + index: 'DC003E09AD1306FBBD1957C955EE668E429CC85B0EC0EC17297F6676E6108DE7', + owner_funds: '162110617177', + quality: '0.000000005148984210454555' + } ]; book.on('offer_changed', function() { @@ -1403,226 +1403,99 @@ describe('OrderBook', function() { var offers = { offers: [ { - Account: 'rGCHV41NxoK7wHQJhmao2RqjWZvBrTUhW1', - BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711A3A4254F5000', - BookNode: '0000000000000000', - Flags: 131072, - LedgerEntryType: 'Offer', - OwnerNode: '0000000000000000', - PreviousTxnID: '9BB337CC8B34DC8D1A3FFF468556C8BA70977C37F7436439D8DA19610F214AD1', - PreviousTxnLgrSeq: 8342933, - Sequence: 195, - TakerGets: { - currency: 'BTC', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '0.1129232560043778' - }, - TakerPays: { - currency: 'USD', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '56.06639660617357' - }, - index: 'B6BC3B0F87976370EE11F5575593FE63AA5DC1D602830DC96F04B2D597F044BF', - owner_funds: '0.1129267125000245', - quality: '496.5', - taker_gets_funded: { - currency: 'BTC', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '0.1127013098802639' - }, - taker_pays_funded: { - currency: 'USD', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '55.95620035555103' - } - }, - { - Account: 'raudnGKfTK23YKfnS7ixejHrqGERTYNFXk', - BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414', - BookNode: '0000000000000000', - Expiration: 461498565, - Flags: 131072, - LedgerEntryType: 'Offer', - OwnerNode: '0000000000000144', - PreviousTxnID: 'C8296B9CCA6DC594C7CD271C5D8FD11FEE380021A07768B25935642CDB37048A', - PreviousTxnLgrSeq: 8342469, - Sequence: 29354, - TakerGets: { - currency: 'BTC', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '0.2' - }, - TakerPays: { - currency: 'USD', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '99.72233516476456' - }, - index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86', - owner_funds: '0.950363009783092', - quality: '498.6116758238228' - }, - { - Account: 'rwBG69mujDoD5yQfL3Sf7Yuh7rUNYdxe9Y', - BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414', - BookNode: '0000000000000000', - Expiration: 461498565, - Flags: 131072, - LedgerEntryType: 'Offer', - OwnerNode: '0000000000000144', - PreviousTxnID: 'C8296B9CCA6DC594C7CD271C5D8FD11FEE380021A07768B25935642CDB37048A', - PreviousTxnLgrSeq: 8342469, - Sequence: 29356, - TakerGets: { - currency: 'BTC', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '0.5' - }, - TakerPays: { - currency: 'USD', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '99.72233516476456' - }, - index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86', - owner_funds: '0.950363009783092', - quality: '498.6116758238228' - }, - { - Account: 'rwBG69mujDoD5yQfL3Sf7Yuh7rUNYdxe9Y', - BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414', - BookNode: '0000000000000000', - Expiration: 461498565, - Flags: 131078, - LedgerEntryType: 'Offer', - OwnerNode: '0000000000000144', - PreviousTxnID: 'C8296B9CCA6DC594C7CD271C5D8FD11FEE380021A07768B25935642CDB37048A', - PreviousTxnLgrSeq: 8342469, - Sequence: 29354, - TakerGets: { - currency: 'BTC', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '0.5' - }, - TakerPays: { - currency: 'USD', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '99.72233516476456' - }, - index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86', - owner_funds: '0.950363009783092', - quality: '498.6116758238228' - } - ] - }; - - remote.request = function(request) { - switch (request.message.command) { - case 'book_offers': - assert.deepEqual(request.message, { - command: 'book_offers', - id: void(0), - taker_gets: { - currency: '0000000000000000000000004254430000000000', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B' + Account: 'rGCHV41NxoK7wHQJhmao2RqjWZvBrTUhW1', + BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711A3A4254F5000', + BookNode: '0000000000000000', + Flags: 131072, + LedgerEntryType: 'Offer', + OwnerNode: '0000000000000000', + PreviousTxnID: '9BB337CC8B34DC8D1A3FFF468556C8BA70977C37F7436439D8DA19610F214AD1', + PreviousTxnLgrSeq: 8342933, + Sequence: 195, + TakerGets: { + currency: 'BTC', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '0.1129232560043778' + }, + TakerPays: { + currency: 'USD', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '56.06639660617357' + }, + index: 'B6BC3B0F87976370EE11F5575593FE63AA5DC1D602830DC96F04B2D597F044BF', + owner_funds: '0.1129267125000245', + quality: '496.5', + taker_gets_funded: { + currency: 'BTC', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '0.1127013098802639' + }, + taker_pays_funded: { + currency: 'USD', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '55.95620035555103' + } }, - taker_pays: { - currency: '0000000000000000000000005553440000000000', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B' + { + Account: 'raudnGKfTK23YKfnS7ixejHrqGERTYNFXk', + BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414', + BookNode: '0000000000000000', + Expiration: 461498565, + Flags: 131072, + LedgerEntryType: 'Offer', + OwnerNode: '0000000000000144', + PreviousTxnID: 'C8296B9CCA6DC594C7CD271C5D8FD11FEE380021A07768B25935642CDB37048A', + PreviousTxnLgrSeq: 8342469, + Sequence: 29354, + TakerGets: { + currency: 'BTC', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '0.2' + }, + TakerPays: { + currency: 'USD', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '99.72233516476456' + }, + index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86', + owner_funds: '0.950363009783092', + quality: '498.6116758238228' }, - taker: 'rrrrrrrrrrrrrrrrrrrrBZbvji' - }); - - setImmediate(function() { - request.emit('success', offers); - }); - break; - } - }; - - var book = remote.createOrderBook({ - currency_gets: 'BTC', - issuer_gets: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - currency_pays: 'USD', - issuer_pays: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B' - }); - - book._issuerTransferRate = 1002000000; - - var expected = [ - { Account: 'rGCHV41NxoK7wHQJhmao2RqjWZvBrTUhW1', - BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711A3A4254F5000', - BookNode: '0000000000000000', - Flags: 131072, - LedgerEntryType: 'Offer', - OwnerNode: '0000000000000000', - Sequence: 195, - TakerGets: { currency: 'BTC', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '0.1129232560043778' - }, - TakerPays: { - currency: 'USD', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '56.06639660617357' - }, - index: 'B6BC3B0F87976370EE11F5575593FE63AA5DC1D602830DC96F04B2D597F044BF', - owner_funds: '0.1129267125000245', - taker_gets_funded: '0.112701309880264', - taker_pays_funded: '55.95620035555106', - is_fully_funded: false }, - - { Account: 'raudnGKfTK23YKfnS7ixejHrqGERTYNFXk', - BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414', - BookNode: '0000000000000000', - Expiration: 461498565, - Flags: 131072, - LedgerEntryType: 'Offer', - OwnerNode: '0000000000000144', - Sequence: 29354, - TakerGets: { - currency: 'BTC', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '0.2' + { + Account: 'rwBG69mujDoD5yQfL3Sf7Yuh7rUNYdxe9Y', + BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414', + BookNode: '0000000000000000', + Expiration: 461498565, + Flags: 131072, + LedgerEntryType: 'Offer', + OwnerNode: '0000000000000144', + PreviousTxnID: 'C8296B9CCA6DC594C7CD271C5D8FD11FEE380021A07768B25935642CDB37048A', + PreviousTxnLgrSeq: 8342469, + Sequence: 29356, + TakerGets: { + currency: 'BTC', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '0.5' + }, + TakerPays: { + currency: 'USD', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '99.72233516476456' + }, + index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86', + owner_funds: '0.950363009783092', + quality: '498.6116758238228' }, - TakerPays: { - currency: 'USD', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '99.72233516476456' - }, - index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86', - owner_funds: '0.950363009783092', - is_fully_funded: true, - taker_gets_funded: '0.2', - taker_pays_funded: '99.72233516476456' - }, - { Account: 'rwBG69mujDoD5yQfL3Sf7Yuh7rUNYdxe9Y', - BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414', - BookNode: '0000000000000000', - Expiration: 461498565, - Flags: 131072, - LedgerEntryType: 'Offer', - OwnerNode: '0000000000000144', - Sequence: 29356, - TakerGets: { currency: 'BTC', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '0.5' - }, - TakerPays: { - currency: 'USD', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '99.72233516476456' - }, - index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86', - owner_funds: '0.950363009783092', - is_fully_funded: false, - taker_gets_funded: '0.9484660776278363', - taker_pays_funded: '94.58325208561269' }, - { Account: 'rwBG69mujDoD5yQfL3Sf7Yuh7rUNYdxe9Y', + { + Account: 'rwBG69mujDoD5yQfL3Sf7Yuh7rUNYdxe9Y', BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414', BookNode: '0000000000000000', Expiration: 461498565, Flags: 131078, LedgerEntryType: 'Offer', OwnerNode: '0000000000000144', + PreviousTxnID: 'C8296B9CCA6DC594C7CD271C5D8FD11FEE380021A07768B25935642CDB37048A', + PreviousTxnLgrSeq: 8342469, Sequence: 29354, TakerGets: { currency: 'BTC', @@ -1636,18 +1509,145 @@ describe('OrderBook', function() { }, index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86', owner_funds: '0.950363009783092', + quality: '498.6116758238228' + } + ] + }; + + remote.request = function(request) { + switch (request.message.command) { + case 'book_offers': + assert.deepEqual(request.message, { + command: 'book_offers', + id: void(0), + taker_gets: { + currency: '0000000000000000000000004254430000000000', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B' + }, + taker_pays: { + currency: '0000000000000000000000005553440000000000', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B' + }, + taker: 'rrrrrrrrrrrrrrrrrrrrBZbvji' + }); + + setImmediate(function() { + request.emit('success', offers); + }); + break; + } + }; + + var book = remote.createOrderBook({ + currency_gets: 'BTC', + issuer_gets: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + currency_pays: 'USD', + issuer_pays: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B' + }); + + book._issuerTransferRate = 1002000000; + + var expected = [ + { Account: 'rGCHV41NxoK7wHQJhmao2RqjWZvBrTUhW1', + BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711A3A4254F5000', + BookNode: '0000000000000000', + Flags: 131072, + LedgerEntryType: 'Offer', + OwnerNode: '0000000000000000', + Sequence: 195, + TakerGets: { currency: 'BTC', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '0.1129232560043778' + }, + TakerPays: { + currency: 'USD', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '56.06639660617357' + }, + index: 'B6BC3B0F87976370EE11F5575593FE63AA5DC1D602830DC96F04B2D597F044BF', + owner_funds: '0.1129267125000245', + taker_gets_funded: '0.112701309880264', + taker_pays_funded: '55.95620035555106', + is_fully_funded: false }, + + { Account: 'raudnGKfTK23YKfnS7ixejHrqGERTYNFXk', + BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414', + BookNode: '0000000000000000', + Expiration: 461498565, + Flags: 131072, + LedgerEntryType: 'Offer', + OwnerNode: '0000000000000144', + Sequence: 29354, + TakerGets: { + currency: 'BTC', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '0.2' + }, + TakerPays: { + currency: 'USD', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '99.72233516476456' + }, + index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86', + owner_funds: '0.950363009783092', + is_fully_funded: true, + taker_gets_funded: '0.2', + taker_pays_funded: '99.72233516476456' + }, + { Account: 'rwBG69mujDoD5yQfL3Sf7Yuh7rUNYdxe9Y', + BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414', + BookNode: '0000000000000000', + Expiration: 461498565, + Flags: 131072, + LedgerEntryType: 'Offer', + OwnerNode: '0000000000000144', + Sequence: 29356, + TakerGets: { currency: 'BTC', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '0.5' + }, + TakerPays: { + currency: 'USD', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '99.72233516476456' + }, + index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86', + owner_funds: '0.950363009783092', is_fully_funded: false, taker_gets_funded: '0.9484660776278363', - taker_pays_funded: '94.58325208561269' - } - ] + taker_pays_funded: '94.58325208561269' }, + { Account: 'rwBG69mujDoD5yQfL3Sf7Yuh7rUNYdxe9Y', + BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414', + BookNode: '0000000000000000', + Expiration: 461498565, + Flags: 131078, + LedgerEntryType: 'Offer', + OwnerNode: '0000000000000144', + Sequence: 29354, + TakerGets: { + currency: 'BTC', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '0.5' + }, + TakerPays: { + currency: 'USD', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '99.72233516476456' + }, + index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86', + owner_funds: '0.950363009783092', + is_fully_funded: false, + taker_gets_funded: '0.9484660776278363', + taker_pays_funded: '94.58325208561269' + } + ] - book.on('model', function(model) { - assert.deepEqual(model, expected); - assert.strictEqual(book._synchronized, true); - done(); - }); + book.on('model', function(model) { + assert.deepEqual(model, expected); + assert.strictEqual(book._synchronized, true); + done(); + }); }); it('Request offers -- native currency', function(done) { @@ -1656,199 +1656,199 @@ describe('OrderBook', function() { var offers = { offers: [ { - Account: 'rGCHV41NxoK7wHQJhmao2RqjWZvBrTUhW1', - BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711A3A4254F5000', - BookNode: '0000000000000000', - Flags: 131072, - LedgerEntryType: 'Offer', - OwnerNode: '0000000000000000', - Sequence: 195, - TakerGets: '1000', - TakerPays: { - currency: 'USD', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '56.06639660617357' + Account: 'rGCHV41NxoK7wHQJhmao2RqjWZvBrTUhW1', + BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711A3A4254F5000', + BookNode: '0000000000000000', + Flags: 131072, + LedgerEntryType: 'Offer', + OwnerNode: '0000000000000000', + Sequence: 195, + TakerGets: '1000', + TakerPays: { + currency: 'USD', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '56.06639660617357' + }, + index: 'B6BC3B0F87976370EE11F5575593FE63AA5DC1D602830DC96F04B2D597F044BF', + owner_funds: '600' + }, + { + Account: 'raudnGKfTK23YKfnS7ixejHrqGERTYNFXk', + BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414', + BookNode: '0000000000000000', + Expiration: 461498565, + Flags: 131072, + LedgerEntryType: 'Offer', + OwnerNode: '0000000000000144', + Sequence: 29354, + TakerGets: '2000', + TakerPays: { + currency: 'USD', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '99.72233516476456' + }, + index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86', + owner_funds: '4000', + }, + { + Account: 'rwBG69mujDoD5yQfL3Sf7Yuh7rUNYdxe9Y', + BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414', + BookNode: '0000000000000000', + Expiration: 461498565, + Flags: 131072, + LedgerEntryType: 'Offer', + OwnerNode: '0000000000000144', + Sequence: 29356, + TakerGets: '2000', + TakerPays: { + currency: 'USD', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '99.72233516476456' + }, + index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86', + owner_funds: '3900', + }, + { + Account: 'rwBG69mujDoD5yQfL3Sf7Yuh7rUNYdxe9Y', + BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414', + BookNode: '0000000000000000', + Expiration: 461498565, + Flags: 131078, + LedgerEntryType: 'Offer', + OwnerNode: '0000000000000144', + PreviousTxnID: 'C8296B9CCA6DC594C7CD271C5D8FD11FEE380021A07768B25935642CDB37048A', + PreviousTxnLgrSeq: 8342469, + Sequence: 29354, + TakerGets: '2000', + TakerPays: { + currency: 'USD', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '99.72233516476456' + }, + index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86', + quality: '498.6116758238228' + } + ] + }; + + var expected = [ + { + Account: 'rGCHV41NxoK7wHQJhmao2RqjWZvBrTUhW1', + BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711A3A4254F5000', + BookNode: '0000000000000000', + Flags: 131072, + LedgerEntryType: 'Offer', + OwnerNode: '0000000000000000', + Sequence: 195, + TakerGets: '1000', + TakerPays: { + currency: 'USD', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '56.06639660617357' + }, + index: 'B6BC3B0F87976370EE11F5575593FE63AA5DC1D602830DC96F04B2D597F044BF', + owner_funds: '600', + is_fully_funded: false, + taker_gets_funded: '600', + taker_pays_funded: '33.63983796370414' }, - index: 'B6BC3B0F87976370EE11F5575593FE63AA5DC1D602830DC96F04B2D597F044BF', - owner_funds: '600' - }, - { - Account: 'raudnGKfTK23YKfnS7ixejHrqGERTYNFXk', - BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414', - BookNode: '0000000000000000', - Expiration: 461498565, - Flags: 131072, - LedgerEntryType: 'Offer', - OwnerNode: '0000000000000144', - Sequence: 29354, - TakerGets: '2000', - TakerPays: { - currency: 'USD', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '99.72233516476456' + { + Account: 'raudnGKfTK23YKfnS7ixejHrqGERTYNFXk', + BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414', + BookNode: '0000000000000000', + Expiration: 461498565, + Flags: 131072, + LedgerEntryType: 'Offer', + OwnerNode: '0000000000000144', + Sequence: 29354, + TakerGets: '2000', + TakerPays: { + currency: 'USD', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '99.72233516476456' + }, + index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86', + owner_funds: '4000', + is_fully_funded: true, + taker_gets_funded: '2000', + taker_pays_funded: '99.72233516476456' }, - index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86', - owner_funds: '4000', - }, - { - Account: 'rwBG69mujDoD5yQfL3Sf7Yuh7rUNYdxe9Y', - BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414', - BookNode: '0000000000000000', - Expiration: 461498565, - Flags: 131072, - LedgerEntryType: 'Offer', - OwnerNode: '0000000000000144', - Sequence: 29356, - TakerGets: '2000', - TakerPays: { - currency: 'USD', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '99.72233516476456' + { + Account: 'rwBG69mujDoD5yQfL3Sf7Yuh7rUNYdxe9Y', + BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414', + BookNode: '0000000000000000', + Expiration: 461498565, + Flags: 131072, + LedgerEntryType: 'Offer', + OwnerNode: '0000000000000144', + Sequence: 29356, + TakerGets: '2000', + TakerPays: { + currency: 'USD', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '99.72233516476456' + }, + index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86', + owner_funds: '3900', + is_fully_funded: false, + taker_gets_funded: '2000', + taker_pays_funded: '97.22927678564545' }, - index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86', - owner_funds: '3900', - }, - { - Account: 'rwBG69mujDoD5yQfL3Sf7Yuh7rUNYdxe9Y', - BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414', - BookNode: '0000000000000000', - Expiration: 461498565, - Flags: 131078, - LedgerEntryType: 'Offer', - OwnerNode: '0000000000000144', - PreviousTxnID: 'C8296B9CCA6DC594C7CD271C5D8FD11FEE380021A07768B25935642CDB37048A', - PreviousTxnLgrSeq: 8342469, - Sequence: 29354, - TakerGets: '2000', - TakerPays: { - currency: 'USD', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '99.72233516476456' - }, - index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86', - quality: '498.6116758238228' - } + { + Account: 'rwBG69mujDoD5yQfL3Sf7Yuh7rUNYdxe9Y', + BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414', + BookNode: '0000000000000000', + Expiration: 461498565, + Flags: 131078, + LedgerEntryType: 'Offer', + OwnerNode: '0000000000000144', + Sequence: 29354, + TakerGets: '2000', + TakerPays: { + currency: 'USD', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', + value: '99.72233516476456' + }, + index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86', + is_fully_funded: false, + taker_gets_funded: '2000', + taker_pays_funded: '97.22927678564545' + } ] - }; - var expected = [ - { - Account: 'rGCHV41NxoK7wHQJhmao2RqjWZvBrTUhW1', - BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711A3A4254F5000', - BookNode: '0000000000000000', - Flags: 131072, - LedgerEntryType: 'Offer', - OwnerNode: '0000000000000000', - Sequence: 195, - TakerGets: '1000', - TakerPays: { - currency: 'USD', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '56.06639660617357' - }, - index: 'B6BC3B0F87976370EE11F5575593FE63AA5DC1D602830DC96F04B2D597F044BF', - owner_funds: '600', - is_fully_funded: false, - taker_gets_funded: '600', - taker_pays_funded: '33.63983796370414' - }, - { - Account: 'raudnGKfTK23YKfnS7ixejHrqGERTYNFXk', - BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414', - BookNode: '0000000000000000', - Expiration: 461498565, - Flags: 131072, - LedgerEntryType: 'Offer', - OwnerNode: '0000000000000144', - Sequence: 29354, - TakerGets: '2000', - TakerPays: { - currency: 'USD', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '99.72233516476456' - }, - index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86', - owner_funds: '4000', - is_fully_funded: true, - taker_gets_funded: '2000', - taker_pays_funded: '99.72233516476456' - }, - { - Account: 'rwBG69mujDoD5yQfL3Sf7Yuh7rUNYdxe9Y', - BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414', - BookNode: '0000000000000000', - Expiration: 461498565, - Flags: 131072, - LedgerEntryType: 'Offer', - OwnerNode: '0000000000000144', - Sequence: 29356, - TakerGets: '2000', - TakerPays: { - currency: 'USD', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '99.72233516476456' - }, - index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86', - owner_funds: '3900', - is_fully_funded: false, - taker_gets_funded: '3900', - taker_pays_funded: '97.22927678564545' - }, - { - Account: 'rwBG69mujDoD5yQfL3Sf7Yuh7rUNYdxe9Y', - BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414', - BookNode: '0000000000000000', - Expiration: 461498565, - Flags: 131078, - LedgerEntryType: 'Offer', - OwnerNode: '0000000000000144', - Sequence: 29354, - TakerGets: '2000', - TakerPays: { - currency: 'USD', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B', - value: '99.72233516476456' - }, - index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86', - is_fully_funded: false, - taker_gets_funded: '3900', - taker_pays_funded: '97.22927678564545' - } - ] + remote.request = function(request) { + switch (request.message.command) { + case 'book_offers': + assert.deepEqual(request.message, { + command: 'book_offers', + id: void(0), + taker_gets: { + currency: '0000000000000000000000000000000000000000', + }, + taker_pays: { + currency: '0000000000000000000000005553440000000000', + issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B' + }, + taker: 'rrrrrrrrrrrrrrrrrrrrBZbvji' + }); - remote.request = function(request) { - switch (request.message.command) { - case 'book_offers': - assert.deepEqual(request.message, { - command: 'book_offers', - id: void(0), - taker_gets: { - currency: '0000000000000000000000000000000000000000', - }, - taker_pays: { - currency: '0000000000000000000000005553440000000000', - issuer: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B' - }, - taker: 'rrrrrrrrrrrrrrrrrrrrBZbvji' - }); + setImmediate(function() { + request.emit('success', offers); + }); + break; + } + }; - setImmediate(function() { - request.emit('success', offers); - }); - break; - } - }; + var book = remote.createOrderBook({ + currency_gets: 'XRP', + currency_pays: 'USD', + issuer_pays: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B' + }); - var book = remote.createOrderBook({ - currency_gets: 'XRP', - currency_pays: 'USD', - issuer_pays: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B' - }); - - book.on('model', function(model) { - assert.deepEqual(model, expected); - assert.strictEqual(book._synchronized, true); - done(); - }); + book.on('model', function(model) { + assert.deepEqual(model, expected); + assert.strictEqual(book._synchronized, true); + done(); + }); }); });