[FEATURE] add offer autobridging

This commit is contained in:
Bo Chen
2015-03-16 15:42:13 -07:00
committed by Geert Weening
parent 5e2c26a4a2
commit c7bbce8371
8 changed files with 2045 additions and 603 deletions

View File

@@ -2119,7 +2119,7 @@ describe('OrderBook', function() {
assert.strictEqual(book._offers[2].taker_pays_funded, '101533965');
});
it('Insert offer - worst quality - insufficient funds for all orders', function () {
it('Insert offer - worst quality - insufficient funds for all orders', function() {
var remote = new Remote();
var book = remote.createOrderBook({
currency_gets: 'USD',
@@ -2193,159 +2193,6 @@ describe('OrderBook', function() {
assert.strictEqual(book._offers[2].taker_pays_funded, '0');
});
it('Request offers', function(done) {
var remote = new Remote();
var offers = {
offers: fixtures.REQUEST_OFFERS
};
remote.request = function(request) {
switch (request.message.command) {
case 'book_offers':
assert.deepEqual(request.message, {
command: 'book_offers',
id: undefined,
taker_gets: {
currency: '0000000000000000000000004254430000000000',
issuer: addresses.ISSUER
},
taker_pays: {
currency: '0000000000000000000000005553440000000000',
issuer: addresses.ISSUER
},
taker: 'rrrrrrrrrrrrrrrrrrrrBZbvji'
});
setImmediate(function() {
request.emit('success', offers);
});
break;
}
};
var book = remote.createOrderBook({
currency_gets: 'BTC',
issuer_gets: addresses.ISSUER,
currency_pays: 'USD',
issuer_pays: addresses.ISSUER
});
book._issuerTransferRate = 1002000000;
var expected = [
{
Account: addresses.ACCOUNT,
BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711A3A4254F5000',
BookNode: '0000000000000000',
Flags: 131072,
LedgerEntryType: 'Offer',
OwnerNode: '0000000000000000',
Sequence: 195,
TakerGets: {
currency: 'BTC',
issuer: addresses.ISSUER,
value: '0.1129232560043778'
},
TakerPays: {
currency: 'USD',
issuer: addresses.ISSUER,
value: '56.06639660617357'
},
index: 'B6BC3B0F87976370EE11F5575593FE63AA5DC1D602830DC96F04B2D597F044BF',
owner_funds: '0.1129267125000245',
taker_gets_funded: '0.112701309880264',
taker_pays_funded: '55.95620035555106',
is_fully_funded: false,
quality: '496.4999999999999'
},
{
Account: addresses.OTHER_ACCOUNT,
BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414',
BookNode: '0000000000000000',
Expiration: 461498565,
Flags: 131072,
LedgerEntryType: 'Offer',
OwnerNode: '0000000000000144',
Sequence: 29354,
TakerGets: {
currency: 'BTC',
issuer: addresses.ISSUER,
value: '0.2'
},
TakerPays: {
currency: 'USD',
issuer: addresses.ISSUER,
value: '99.72233516476456'
},
index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86',
owner_funds: '0.950363009783092',
is_fully_funded: true,
taker_gets_funded: '0.2',
taker_pays_funded: '99.72233516476456',
quality: '498.6116758238228'
},
{
Account: addresses.THIRD_ACCOUNT,
BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414',
BookNode: '0000000000000000',
Expiration: 461498565,
Flags: 131072,
LedgerEntryType: 'Offer',
OwnerNode: '0000000000000144',
Sequence: 29356,
TakerGets: {
currency: 'BTC',
issuer: addresses.ISSUER,
value: '0.5'
},
TakerPays: {
currency: 'USD',
issuer: addresses.ISSUER,
value: '99.72233516476456'
},
index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86',
owner_funds: '0.950363009783092',
is_fully_funded: true,
taker_gets_funded: '0.5',
taker_pays_funded: '99.72233516476456',
quality: '498.6116758238228'
},
{
Account: addresses.THIRD_ACCOUNT,
BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414',
BookNode: '0000000000000000',
Expiration: 461498565,
Flags: 131078,
LedgerEntryType: 'Offer',
OwnerNode: '0000000000000144',
Sequence: 29354,
TakerGets: {
currency: 'BTC',
issuer: addresses.ISSUER,
value: '0.5'
},
TakerPays: {
currency: 'USD',
issuer: addresses.ISSUER,
value: '99.72233516476456'
},
index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86',
owner_funds: '0.950363009783092',
is_fully_funded: false,
taker_gets_funded: '0.4484660776278363',
taker_pays_funded: '89.44416900646082',
quality: '199.4446703295291'
}
];
book.on('model', function(model) {
assert.deepEqual(model, expected);
assert.strictEqual(book._synchronized, true);
done();
});
});
it('Request offers - native currency', function(done) {
var remote = new Remote();