Improvements to js tests and increment of the ripple-lib version

This commit is contained in:
wltsmrz
2013-09-04 16:29:32 -07:00
committed by Vinnie Falco
parent 604ca590b6
commit 4109e51e30
9 changed files with 2129 additions and 2234 deletions

View File

@@ -10,10 +10,10 @@
}, },
"dependencies": { "dependencies": {
"ripple-lib": "0.7.18", "ripple-lib": "0.7.21",
"async": "~0.1.22", "async": "~0.2.9",
"extend": "~1.1.1", "extend": "~1.2.0",
"simple-jsonrpc": "~0.0.1" "simple-jsonrpc": "~0.0.2"
}, },
"devDependencies": { "devDependencies": {
"buster": "~0.6.12", "buster": "~0.6.12",
@@ -21,7 +21,7 @@
}, },
"scripts": { "scripts": {
"test": "./node_modules/buster/bin/buster-test" "test": "./node_modules/buster/bin/buster-test --reporter specification"
}, },
"repository": { "repository": {

View File

@@ -19,201 +19,198 @@ buster.testCase("AccountSet", {
// 'setUp' : testutils.build_setup({verbose: true , no_server: false}), // 'setUp' : testutils.build_setup({verbose: true , no_server: false}),
'tearDown' : testutils.build_teardown(), 'tearDown' : testutils.build_teardown(),
"RequireDestTag" : "RequireDestTag" : function (done) {
function (done) { var self = this;
var self = this;
async.waterfall([ async.waterfall([
function (callback) { function (callback) {
self.what = "Set RequireDestTag."; self.what = "Set RequireDestTag.";
self.remote.transaction() self.remote.transaction()
.account_set("root") .account_set("root")
.set_flags('RequireDestTag') .set_flags('RequireDestTag')
.on('proposed', function (m) { .on('submitted', function (m) {
//console.log("proposed: %s", JSON.stringify(m)); //console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
},
function (callback) {
self.what = "Check RequireDestTag";
self.remote.request_account_flags('root', 'CURRENT')
.on('success', function (m) {
var wrong = !(m.node.Flags & Remote.flags.account_root.RequireDestTag);
if (wrong)
console.log("Set RequireDestTag: failed: %s", JSON.stringify(m));
callback(wrong);
})
.request();
},
function (callback) {
self.what = "Clear RequireDestTag.";
self.remote.transaction()
.account_set("root")
.set_flags('OptionalDestTag')
.on('proposed', function (m) {
//console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS');
})
.submit();
},
function (callback) {
self.what = "Check No RequireDestTag";
self.remote.request_account_flags('root', 'CURRENT')
.on('success', function (m) {
var wrong = !!(m.node.Flags & Remote.flags.account_root.RequireDestTag);
if (wrong)
console.log("Clear RequireDestTag: failed: %s", JSON.stringify(m));
callback(wrong);
})
.request();
},
], function (error) {
buster.refute(error, self.what);
done();
});
}, },
function (callback) {
self.what = "Check RequireDestTag";
"RequireAuth" : self.remote.request_account_flags('root', 'CURRENT')
function (done) { .on('success', function (m) {
var self = this; var wrong = !(m.node.Flags & Remote.flags.account_root.RequireDestTag);
async.waterfall([ if (wrong)
function (callback) { console.log("Set RequireDestTag: failed: %s", JSON.stringify(m));
self.what = "Set RequireAuth.";
self.remote.transaction() callback(wrong);
.account_set("root") })
.set_flags('RequireAuth') .request();
.on('proposed', function (m) {
//console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS');
})
.submit();
},
function (callback) {
self.what = "Check RequireAuth";
self.remote.request_account_flags('root', 'CURRENT')
.on('success', function (m) {
var wrong = !(m.node.Flags & Remote.flags.account_root.RequireAuth);
if (wrong)
console.log("Set RequireAuth: failed: %s", JSON.stringify(m));
callback(wrong);
})
.request();
},
function (callback) {
self.what = "Clear RequireAuth.";
self.remote.transaction()
.account_set("root")
.set_flags('OptionalAuth')
.on('proposed', function (m) {
//console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS');
})
.submit();
},
function (callback) {
self.what = "Check No RequireAuth";
self.remote.request_account_flags('root', 'CURRENT')
.on('success', function (m) {
var wrong = !!(m.node.Flags & Remote.flags.account_root.RequireAuth);
if (wrong)
console.log("Clear RequireAuth: failed: %s", JSON.stringify(m));
callback(wrong);
})
.request();
},
// XXX Also check fails if something is owned.
], function (error) {
buster.refute(error, self.what);
done();
});
}, },
function (callback) {
self.what = "Clear RequireDestTag.";
"DisallowXRP" : self.remote.transaction()
function (done) { .account_set("root")
var self = this; .set_flags('OptionalDestTag')
.on('submitted', function (m) {
//console.log("proposed: %s", JSON.stringify(m));
async.waterfall([ callback(m.engine_result !== 'tesSUCCESS');
function (callback) { })
self.what = "Set DisallowXRP."; .submit();
self.remote.transaction()
.account_set("root")
.set_flags('DisallowXRP')
.on('proposed', function (m) {
//console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS');
})
.submit();
},
function (callback) {
self.what = "Check DisallowXRP";
self.remote.request_account_flags('root', 'CURRENT')
.on('success', function (m) {
var wrong = !(m.node.Flags & Remote.flags.account_root.DisallowXRP);
if (wrong)
console.log("Set RequireDestTag: failed: %s", JSON.stringify(m));
callback(wrong);
})
.request();
},
function (callback) {
self.what = "Clear DisallowXRP.";
self.remote.transaction()
.account_set("root")
.set_flags('AllowXRP')
.on('proposed', function (m) {
//console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS');
})
.submit();
},
function (callback) {
self.what = "Check AllowXRP";
self.remote.request_account_flags('root', 'CURRENT')
.on('success', function (m) {
var wrong = !!(m.node.Flags & Remote.flags.account_root.DisallowXRP);
if (wrong)
console.log("Clear DisallowXRP: failed: %s", JSON.stringify(m));
callback(wrong);
})
.request();
},
], function (error) {
buster.refute(error, self.what);
done();
});
}, },
function (callback) {
self.what = "Check No RequireDestTag";
self.remote.request_account_flags('root', 'CURRENT')
.on('success', function (m) {
var wrong = !!(m.node.Flags & Remote.flags.account_root.RequireDestTag);
if (wrong)
console.log("Clear RequireDestTag: failed: %s", JSON.stringify(m));
callback(wrong);
})
.request();
},
], function (error) {
buster.refute(error, self.what);
done();
});
},
"RequireAuth" : function (done) {
var self = this;
async.waterfall([
function (callback) {
self.what = "Set RequireAuth.";
self.remote.transaction()
.account_set("root")
.set_flags('RequireAuth')
.on('submitted', function (m) {
//console.log("proposed: %s", JSON.stringify(m));
callback(m.engine_result !== 'tesSUCCESS');
})
.submit();
},
function (callback) {
self.what = "Check RequireAuth";
self.remote.request_account_flags('root', 'CURRENT')
.on('success', function (m) {
var wrong = !(m.node.Flags & Remote.flags.account_root.RequireAuth);
if (wrong)
console.log("Set RequireAuth: failed: %s", JSON.stringify(m));
callback(wrong);
})
.request();
},
function (callback) {
self.what = "Clear RequireAuth.";
self.remote.transaction()
.account_set("root")
.set_flags('OptionalAuth')
.on('submitted', function (m) {
//console.log("proposed: %s", JSON.stringify(m));
callback(m.engine_result !== 'tesSUCCESS');
})
.submit();
},
function (callback) {
self.what = "Check No RequireAuth";
self.remote.request_account_flags('root', 'CURRENT')
.on('success', function (m) {
var wrong = !!(m.node.Flags & Remote.flags.account_root.RequireAuth);
if (wrong)
console.log("Clear RequireAuth: failed: %s", JSON.stringify(m));
callback(wrong);
})
.request();
},
// XXX Also check fails if something is owned.
], function (error) {
buster.refute(error, self.what);
done();
});
},
"DisallowXRP" : function (done) {
var self = this;
async.waterfall([
function (callback) {
self.what = "Set DisallowXRP.";
self.remote.transaction()
.account_set("root")
.set_flags('DisallowXRP')
.on('submitted', function (m) {
//console.log("proposed: %s", JSON.stringify(m));
callback(m.engine_result !== 'tesSUCCESS');
})
.submit();
},
function (callback) {
self.what = "Check DisallowXRP";
self.remote.request_account_flags('root', 'CURRENT')
.on('success', function (m) {
var wrong = !(m.node.Flags & Remote.flags.account_root.DisallowXRP);
if (wrong)
console.log("Set RequireDestTag: failed: %s", JSON.stringify(m));
callback(wrong);
})
.request();
},
function (callback) {
self.what = "Clear DisallowXRP.";
self.remote.transaction()
.account_set("root")
.set_flags('AllowXRP')
.on('submitted', function (m) {
//console.log("proposed: %s", JSON.stringify(m));
callback(m.engine_result !== 'tesSUCCESS');
})
.submit();
},
function (callback) {
self.what = "Check AllowXRP";
self.remote.request_account_flags('root', 'CURRENT')
.on('success', function (m) {
var wrong = !!(m.node.Flags & Remote.flags.account_root.DisallowXRP);
if (wrong)
console.log("Clear DisallowXRP: failed: %s", JSON.stringify(m));
callback(wrong);
})
.request();
},
], function (error) {
buster.refute(error, self.what);
done();
});
},
}); });

View File

@@ -28,181 +28,180 @@ buster.testCase("//Account_tx tests", {
'setUp' : testutils.build_setup(), 'setUp' : testutils.build_setup(),
'tearDown' : testutils.build_teardown(), 'tearDown' : testutils.build_teardown(),
"make a lot of transactions and query using account_tx" : "make a lot of transactions and query using account_tx" : function (done) {
function (done) { var self = this;
var self = this; var final_create;
var final_create; var transactionCounter = 0;
var transactionCounter = 0; var f = 0;
var f = 0; var functionHolder;
var functionHolder; var createOfferFunction = function (callback) {
var createOfferFunction = function (callback) { self.remote.transaction()
self.remote.transaction() .offer_create("root", "500", "100/USD/root")
.offer_create("root", "500", "100/USD/root") .on('proposed', function (m) {
.on('proposed', function (m) { transactionCounter++;
transactionCounter++; if (VERBOSE) console.log('Submitted transaction', transactionCounter);
if (VERBOSE) console.log('Submitted transaction', transactionCounter);
callback(m.result !== 'tesSUCCESS'); callback(m.result !== 'tesSUCCESS');
}) })
.on('final', function (m) { .on('final', function (m) {
f++; f++;
if (VERBOSE) console.log("Finalized transaction", f); if (VERBOSE) console.log("Finalized transaction", f);
buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult); buster.assert.equals('tesSUCCESS', m.metadata.TransactionResult);
buster.assert(final_create); buster.assert(final_create);
if ( f == transactionCounter ) { if ( f == transactionCounter ) {
if (VERBOSE) console.log("All transactions have been finalized."); if (VERBOSE) console.log("All transactions have been finalized.");
functionHolder(); functionHolder();
} }
}) })
.submit(); .submit();
}; };
function lotsOfTransactions(number, whenDone) { function lotsOfTransactions(number, whenDone) {
var bunchOfOffers = []; var bunchOfOffers = [];
for (var i=0; i<number; i++) { for (var i=0; i<number; i++) {
bunchOfOffers.push(createOfferFunction); bunchOfOffers.push(createOfferFunction);
} }
functionHolder = whenDone; //lolwut functionHolder = whenDone; //lolwut
async.parallel(bunchOfOffers, function (error) { async.parallel(bunchOfOffers, function (error) {
if (VERBOSE) console.log("Accepting ledger."); if (VERBOSE) console.log("Accepting ledger.");
buster.refute(error); buster.refute(error);
self.remote self.remote
.once('ledger_closed', function (message) { .once('ledger_closed', function (message) {
final_create = message; final_create = message;
}) })
.ledger_accept(); .ledger_accept();
}); });
} }
function firstBatch() { function firstBatch() {
lotsOfTransactions(FIRST_BATCH, lotsOfTransactions(FIRST_BATCH,
function(){runTests(self, FIRST_BATCH, 0, undefined, function(){runTests(self, FIRST_BATCH, 0, undefined,
function(){runTests(self, FIRST_BATCH, OFFSET, undefined, function(){runTests(self, FIRST_BATCH, OFFSET, undefined,
function(){runTests(self, FIRST_BATCH, 0, LIMIT, secondBatch)})} function(){runTests(self, FIRST_BATCH, 0, LIMIT, secondBatch)})}
)}); )});
} }
function secondBatch() { function secondBatch() {
lotsOfTransactions(SECOND_BATCH, lotsOfTransactions(SECOND_BATCH,
function(){runTests(self, FIRST_BATCH+SECOND_BATCH, 0, undefined, function(){runTests(self, FIRST_BATCH+SECOND_BATCH, 0, undefined,
function(){runTests(self, FIRST_BATCH+SECOND_BATCH, OFFSET, undefined, thirdBatch)} function(){runTests(self, FIRST_BATCH+SECOND_BATCH, OFFSET, undefined, thirdBatch)}
)}); )});
} }
function thirdBatch() { function thirdBatch() {
lotsOfTransactions(THIRD_BATCH, lotsOfTransactions(THIRD_BATCH,
function(){runTests(self, FIRST_BATCH+SECOND_BATCH+THIRD_BATCH, 0, undefined, function(){runTests(self, FIRST_BATCH+SECOND_BATCH+THIRD_BATCH, 0, undefined,
function(){runTests(self, FIRST_BATCH+SECOND_BATCH+THIRD_BATCH, OFFSET, undefined, done)} function(){runTests(self, FIRST_BATCH+SECOND_BATCH+THIRD_BATCH, OFFSET, undefined, done)}
)}); )});
} }
firstBatch(); firstBatch();
function standardErrorHandler(callback) { function standardErrorHandler(callback) {
return function(r) { return function(r) {
if (VERBOSE) console.log("ERROR!"); if (VERBOSE) console.log("ERROR!");
if (VERBOSE) console.log(r); if (VERBOSE) console.log(r);
callback(r); callback(r);
} }
} }
function runTests(self, actualNumberOfTransactions, offset, limit, finalCallback) { function runTests(self, actualNumberOfTransactions, offset, limit, finalCallback) {
if (VERBOSE) console.log("Testing batch with offset and limit:", offset, limit); if (VERBOSE) console.log("Testing batch with offset and limit:", offset, limit);
async.series([ async.series([
function(callback) { function(callback) {
if (VERBOSE) console.log('nonbinary'); if (VERBOSE) console.log('nonbinary');
self.remote.request_account_tx({ self.remote.request_account_tx({
account:ACCOUNT, account:ACCOUNT,
ledger_index_min:-1, ledger_index_min:-1,
ledger_index_max:-1, ledger_index_max:-1,
offset:offset, offset:offset,
limit:limit limit:limit
}).on('success', function (r) { }).on('success', function (r) {
if (r.transactions) { if (r.transactions) {
var targetLength = Math.min(NONBINARY_LIMIT, limit ? Math.min(limit,actualNumberOfTransactions-offset) : actualNumberOfTransactions-offset); var targetLength = Math.min(NONBINARY_LIMIT, limit ? Math.min(limit,actualNumberOfTransactions-offset) : actualNumberOfTransactions-offset);
buster.assert(r.transactions.length == targetLength, "Got "+r.transactions.length+" transactions; expected "+targetLength ); buster.assert(r.transactions.length == targetLength, "Got "+r.transactions.length+" transactions; expected "+targetLength );
//Check for proper ordering. //Check for proper ordering.
for (var i=0; i<r.transactions.length-1; i++) { for (var i=0; i<r.transactions.length-1; i++) {
var t1 = r.transactions[i].tx; var t1 = r.transactions[i].tx;
var t2 = r.transactions[i+1].tx; var t2 = r.transactions[i+1].tx;
buster.assert(t1.inLedger<=t2.inLedger, buster.assert(t1.inLedger<=t2.inLedger,
"Transactions were not ordered correctly: "+t1.inLedger+"#"+t1.Sequence+" should not have come before "+t2.inLedger+"#"+t2.Sequence); "Transactions were not ordered correctly: "+t1.inLedger+"#"+t1.Sequence+" should not have come before "+t2.inLedger+"#"+t2.Sequence);
} }
} else { } else {
buster.assert(r.transactions, "No transactions returned: "+offset+" "+limit); buster.assert(r.transactions, "No transactions returned: "+offset+" "+limit);
} }
callback(false); callback(false);
}) })
.on('error', standardErrorHandler(callback)) .on('error', standardErrorHandler(callback))
.request(); .request();
}, },
function(callback) { function(callback) {
if (VERBOSE) console.log('binary'); if (VERBOSE) console.log('binary');
self.remote.request_account_tx({ self.remote.request_account_tx({
account:ACCOUNT, account:ACCOUNT,
ledger_index_min:-1, ledger_index_min:-1,
ledger_index_max:-1, ledger_index_max:-1,
binary:true, binary:true,
offset:offset, offset:offset,
limit:limit limit:limit
}).on('success', function (r) { }).on('success', function (r) {
if (r.transactions) { if (r.transactions) {
var targetLength = Math.min(BINARY_LIMIT, limit ? Math.min(limit,actualNumberOfTransactions-offset) : actualNumberOfTransactions-offset); var targetLength = Math.min(BINARY_LIMIT, limit ? Math.min(limit,actualNumberOfTransactions-offset) : actualNumberOfTransactions-offset);
buster.assert(r.transactions.length == targetLength, "Got "+r.transactions.length+" transactions; expected "+targetLength ); buster.assert(r.transactions.length == targetLength, "Got "+r.transactions.length+" transactions; expected "+targetLength );
} else { } else {
buster.assert(r.transactions, "No transactions returned: "+offset+" "+limit); buster.assert(r.transactions, "No transactions returned: "+offset+" "+limit);
} }
callback(false); callback(false);
}) })
.on('error', standardErrorHandler(callback)) .on('error', standardErrorHandler(callback))
.request(); .request();
}, },
function(callback) { function(callback) {
if (VERBOSE) console.log('nonbinary+offset'); if (VERBOSE) console.log('nonbinary+offset');
self.remote.request_account_tx({ self.remote.request_account_tx({
account:ACCOUNT, account:ACCOUNT,
ledger_index_min:-1, ledger_index_min:-1,
ledger_index_max:-1, ledger_index_max:-1,
descending:true, descending:true,
offset:offset, offset:offset,
limit:limit limit:limit
}).on('success', function (r) { }).on('success', function (r) {
if (r.transactions) { if (r.transactions) {
var targetLength = Math.min(NONBINARY_LIMIT, limit ? Math.min(limit,actualNumberOfTransactions-offset) : actualNumberOfTransactions-offset ); var targetLength = Math.min(NONBINARY_LIMIT, limit ? Math.min(limit,actualNumberOfTransactions-offset) : actualNumberOfTransactions-offset );
buster.assert(r.transactions.length == targetLength, "Got "+r.transactions.length+" transactions; expected "+targetLength ); buster.assert(r.transactions.length == targetLength, "Got "+r.transactions.length+" transactions; expected "+targetLength );
//Check for proper ordering. //Check for proper ordering.
for (var i=0; i<r.transactions.length-1; i++) { for (var i=0; i<r.transactions.length-1; i++) {
var t1 = r.transactions[i].tx; var t1 = r.transactions[i].tx;
var t2 = r.transactions[i+1].tx; var t2 = r.transactions[i+1].tx;
//buster.assert(t1.inLedger>t2.inLedger || (t1.inLedger==t2.inLedger && t1.Sequence > t2.Sequence ), //buster.assert(t1.inLedger>t2.inLedger || (t1.inLedger==t2.inLedger && t1.Sequence > t2.Sequence ),
// "Transactions were not ordered correctly: "+t1.inLedger+"#"+t1.Sequence+" should not have come before "+t2.inLedger+"#"+t2.Sequence); // "Transactions were not ordered correctly: "+t1.inLedger+"#"+t1.Sequence+" should not have come before "+t2.inLedger+"#"+t2.Sequence);
buster.assert(t1.inLedger>=t2.inLedger, buster.assert(t1.inLedger>=t2.inLedger,
"Transactions were not ordered correctly: "+t1.inLedger+"#"+t1.Sequence+" should not have come before "+t2.inLedger+"#"+t2.Sequence); "Transactions were not ordered correctly: "+t1.inLedger+"#"+t1.Sequence+" should not have come before "+t2.inLedger+"#"+t2.Sequence);
} }
} else { } else {
buster.assert(r.transactions, "No transactions returned: "+offset+" "+limit); buster.assert(r.transactions, "No transactions returned: "+offset+" "+limit);
} }
callback(false); callback(false);
}) })
.on('error', standardErrorHandler(callback)) .on('error', standardErrorHandler(callback))
.request(); .request();
}, },
], function (error) { ], function (error) {
buster.refute(error); buster.refute(error);
finalCallback(); finalCallback();
} }
); );
} }
} }
}); });

View File

@@ -18,8 +18,7 @@ buster.testCase("Offer tests", {
// 'setUp' : testutils.build_setup({ verbose: true, standalone: true }), // 'setUp' : testutils.build_setup({ verbose: true, standalone: true }),
'tearDown' : testutils.build_teardown(), 'tearDown' : testutils.build_teardown(),
"offer create then cancel in one ledger" : "offer create then cancel in one ledger" : function (done) {
function (done) {
var self = this; var self = this;
var final_create; var final_create;
@@ -27,9 +26,9 @@ buster.testCase("Offer tests", {
function (callback) { function (callback) {
self.remote.transaction() self.remote.transaction()
.offer_create("root", "500", "100/USD/root") .offer_create("root", "500", "100/USD/root")
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); // console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS', m); callback(m.engine_result !== 'tesSUCCESS', m);
}) })
.on('final', function (m) { .on('final', function (m) {
// console.log("FINAL: offer_create: %s", JSON.stringify(m)); // console.log("FINAL: offer_create: %s", JSON.stringify(m));
@@ -43,9 +42,9 @@ buster.testCase("Offer tests", {
function (m, callback) { function (m, callback) {
self.remote.transaction() self.remote.transaction()
.offer_cancel("root", m.tx_json.Sequence) .offer_cancel("root", m.tx_json.Sequence)
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("PROPOSED: offer_cancel: %s", JSON.stringify(m)); // console.log("PROPOSED: offer_cancel: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS', m); callback(m.engine_result !== 'tesSUCCESS', m);
}) })
.on('final', function (m) { .on('final', function (m) {
// console.log("FINAL: offer_cancel: %s", JSON.stringify(m, undefined, 2)); // console.log("FINAL: offer_cancel: %s", JSON.stringify(m, undefined, 2));
@@ -72,8 +71,7 @@ buster.testCase("Offer tests", {
}); });
}, },
"offer create then offer create with cancel in one ledger" : "offer create then offer create with cancel in one ledger" : function (done) {
function (done) {
var self = this; var self = this;
var final_create; var final_create;
var sequence_first; var sequence_first;
@@ -84,9 +82,9 @@ buster.testCase("Offer tests", {
function (callback) { function (callback) {
self.remote.transaction() self.remote.transaction()
.offer_create("root", "500", "100/USD/root") .offer_create("root", "500", "100/USD/root")
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); // console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS', m); callback(m.engine_result !== 'tesSUCCESS', m);
}) })
.on('final', function (m) { .on('final', function (m) {
// console.log("FINAL: offer_create: %s", JSON.stringify(m)); // console.log("FINAL: offer_create: %s", JSON.stringify(m));
@@ -105,9 +103,9 @@ buster.testCase("Offer tests", {
// Test canceling existant offer. // Test canceling existant offer.
self.remote.transaction() self.remote.transaction()
.offer_create("root", "300", "100/USD/root", undefined, sequence_first) .offer_create("root", "300", "100/USD/root", undefined, sequence_first)
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); // console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS', m); callback(m.engine_result !== 'tesSUCCESS', m);
}) })
.on('final', function (m) { .on('final', function (m) {
// console.log("FINAL: offer_create: %s", JSON.stringify(m)); // console.log("FINAL: offer_create: %s", JSON.stringify(m));
@@ -135,9 +133,9 @@ buster.testCase("Offer tests", {
// Test canceling non-existant offer. // Test canceling non-existant offer.
self.remote.transaction() self.remote.transaction()
.offer_create("root", "400", "200/USD/root", undefined, sequence_first) .offer_create("root", "400", "200/USD/root", undefined, sequence_first)
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); // console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS', m); callback(m.engine_result !== 'tesSUCCESS', m);
}) })
.on('final', function (m) { .on('final', function (m) {
// console.log("FINAL: offer_create: %s", JSON.stringify(m)); // console.log("FINAL: offer_create: %s", JSON.stringify(m));
@@ -166,8 +164,7 @@ buster.testCase("Offer tests", {
}); });
}, },
"Offer create then self crossing offer, no trust lines with self" : "Offer create then self crossing offer, no trust lines with self" : function (done) {
function (done) {
var self = this; var self = this;
async.waterfall([ async.waterfall([
@@ -176,10 +173,10 @@ buster.testCase("Offer tests", {
self.remote.transaction() self.remote.transaction()
.offer_create("root", "500/BTC/root", "100/USD/root") .offer_create("root", "500/BTC/root", "100/USD/root")
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); // console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
@@ -188,10 +185,10 @@ buster.testCase("Offer tests", {
self.remote.transaction() self.remote.transaction()
.offer_create("root", "100/USD/root", "500/BTC/root") .offer_create("root", "100/USD/root", "500/BTC/root")
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); // console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
} }
@@ -202,8 +199,7 @@ buster.testCase("Offer tests", {
}); });
}, },
"Offer create then crossing offer with XRP. Negative balance." : "Offer create then crossing offer with XRP. Negative balance." : function (done) {
function (done) {
var self = this; var self = this;
var alices_initial_balance = 499946999680; var alices_initial_balance = 499946999680;
@@ -232,7 +228,7 @@ buster.testCase("Offer tests", {
.transfer_rate(1005000000) .transfer_rate(1005000000)
.once('proposed', function (m) { .once('proposed', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
@@ -261,10 +257,10 @@ buster.testCase("Offer tests", {
self.remote.transaction() self.remote.transaction()
.offer_create("alice", "50/USD/mtgox", "150000.0") // get 50/USD pay 150000/XRP .offer_create("alice", "50/USD/mtgox", "150000.0") // get 50/USD pay 150000/XRP
.on('proposed', function (m) { .once('proposed', function (m) {
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); // console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
@@ -301,10 +297,10 @@ buster.testCase("Offer tests", {
self.remote.transaction() self.remote.transaction()
.offer_create("bob", "2000.0", "1/USD/mtgox") // get 2,000/XRP pay 1/USD (has insufficient USD) .offer_create("bob", "2000.0", "1/USD/mtgox") // get 2,000/XRP pay 1/USD (has insufficient USD)
.on('proposed', function (m) { .once('proposed', function (m) {
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); // console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
@@ -333,7 +329,6 @@ buster.testCase("Offer tests", {
{ {
"alice" : [ "-50/USD/mtgox", alices_final_balance.to_json()], "alice" : [ "-50/USD/mtgox", alices_final_balance.to_json()],
"bob" : [ "2710505431213761e-33/USD/mtgox", "bob" : [ "2710505431213761e-33/USD/mtgox",
bobs_final_balance.to_json() bobs_final_balance.to_json()
// bobs_final_balance.to_json() // bobs_final_balance.to_json()
@@ -360,8 +355,7 @@ buster.testCase("Offer tests", {
}); });
}, },
"Offer create then crossing offer with XRP. Reverse order." : "Offer create then crossing offer with XRP. Reverse order." : function (done) {
function (done) {
var self = this; var self = this;
async.waterfall([ async.waterfall([
@@ -394,10 +388,10 @@ buster.testCase("Offer tests", {
self.remote.transaction() self.remote.transaction()
.offer_create("bob", "1/USD/mtgox", "4000.0") // get 1/USD pay 4000/XRP : offer pays 4000 XRP for 1 USD .offer_create("bob", "1/USD/mtgox", "4000.0") // get 1/USD pay 4000/XRP : offer pays 4000 XRP for 1 USD
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); // console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
@@ -410,10 +404,10 @@ buster.testCase("Offer tests", {
self.remote.transaction() self.remote.transaction()
.offer_create("alice", "150000.0", "50/USD/mtgox") // get 150,000/XRP pay 50/USD : offer pays 1 USD for 3000 XRP .offer_create("alice", "150000.0", "50/USD/mtgox") // get 150,000/XRP pay 50/USD : offer pays 1 USD for 3000 XRP
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); // console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
@@ -446,8 +440,7 @@ buster.testCase("Offer tests", {
}); });
}, },
"Offer create then crossing offer with XRP." : "Offer create then crossing offer with XRP." : function (done) {
function (done) {
var self = this; var self = this;
async.waterfall([ async.waterfall([
@@ -480,10 +473,10 @@ buster.testCase("Offer tests", {
self.remote.transaction() self.remote.transaction()
.offer_create("alice", "150000.0", "50/USD/mtgox") // pays 1 USD for 3000 XRP .offer_create("alice", "150000.0", "50/USD/mtgox") // pays 1 USD for 3000 XRP
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); // console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
@@ -492,10 +485,10 @@ buster.testCase("Offer tests", {
self.remote.transaction() self.remote.transaction()
.offer_create("bob", "1/USD/mtgox", "4000.0") // pays 4000 XRP for 1 USD .offer_create("bob", "1/USD/mtgox", "4000.0") // pays 4000 XRP for 1 USD
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); // console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
@@ -531,8 +524,7 @@ buster.testCase("Offer tests", {
}); });
}, },
"Offer create then crossing offer with XRP with limit override." : "Offer create then crossing offer with XRP with limit override." : function (done) {
function (done) {
var self = this; var self = this;
async.waterfall([ async.waterfall([
@@ -565,10 +557,10 @@ buster.testCase("Offer tests", {
self.remote.transaction() self.remote.transaction()
.offer_create("alice", "150000.0", "50/USD/mtgox") // 300 XRP = 1 USD .offer_create("alice", "150000.0", "50/USD/mtgox") // 300 XRP = 1 USD
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); // console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
@@ -588,10 +580,10 @@ buster.testCase("Offer tests", {
self.remote.transaction() self.remote.transaction()
.offer_create("bob", "1/USD/mtgox", "3000.0") // .offer_create("bob", "1/USD/mtgox", "3000.0") //
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); // console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
@@ -623,8 +615,7 @@ buster.testCase("Offer tests", {
}); });
}, },
"offer_create then ledger_accept then offer_cancel then ledger_accept." : "offer_create then ledger_accept then offer_cancel then ledger_accept." : function (done) {
function (done) {
var self = this; var self = this;
var final_create; var final_create;
var offer_seq; var offer_seq;
@@ -633,12 +624,12 @@ buster.testCase("Offer tests", {
function (callback) { function (callback) {
self.remote.transaction() self.remote.transaction()
.offer_create("root", "500", "100/USD/root") .offer_create("root", "500", "100/USD/root")
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); // console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
offer_seq = m.tx_json.Sequence; offer_seq = m.tx_json.Sequence;
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.on('final', function (m) { .on('final', function (m) {
// console.log("FINAL: offer_create: %s", JSON.stringify(m)); // console.log("FINAL: offer_create: %s", JSON.stringify(m));
@@ -669,9 +660,9 @@ buster.testCase("Offer tests", {
self.remote.transaction() self.remote.transaction()
.offer_cancel("root", offer_seq) .offer_cancel("root", offer_seq)
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("PROPOSED: offer_cancel: %s", JSON.stringify(m)); // console.log("PROPOSED: offer_cancel: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.on('final', function (m) { .on('final', function (m) {
// console.log("FINAL: offer_cancel: %s", JSON.stringify(m)); // console.log("FINAL: offer_cancel: %s", JSON.stringify(m));
@@ -708,8 +699,7 @@ buster.testCase("Offer tests", {
}); });
}, },
"//new user offer_create then ledger_accept then offer_cancel then ledger_accept." : "//new user offer_create then ledger_accept then offer_cancel then ledger_accept." : function (done) {
function (done) {
var self = this; var self = this;
var final_create; var final_create;
var offer_seq; var offer_seq;
@@ -718,9 +708,9 @@ buster.testCase("Offer tests", {
function (callback) { function (callback) {
self.remote.transaction() self.remote.transaction()
.payment('root', 'alice', "1000") .payment('root', 'alice', "1000")
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
buster.assert.equals(m.result, 'tesSUCCESS'); buster.assert.equals(m.engine_result, 'tesSUCCESS');
callback(); callback();
}) })
.submit() .submit()
@@ -728,12 +718,12 @@ buster.testCase("Offer tests", {
function (callback) { function (callback) {
self.remote.transaction() self.remote.transaction()
.offer_create("alice", "500", "100/USD/alice") .offer_create("alice", "500", "100/USD/alice")
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); // console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
offer_seq = m.tx_json.Sequence; offer_seq = m.tx_json.Sequence;
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.on('final', function (m) { .on('final', function (m) {
// console.log("FINAL: offer_create: %s", JSON.stringify(m)); // console.log("FINAL: offer_create: %s", JSON.stringify(m));
@@ -764,9 +754,9 @@ buster.testCase("Offer tests", {
self.remote.transaction() self.remote.transaction()
.offer_cancel("alice", offer_seq) .offer_cancel("alice", offer_seq)
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("PROPOSED: offer_cancel: %s", JSON.stringify(m)); // console.log("PROPOSED: offer_cancel: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.on('final', function (m) { .on('final', function (m) {
// console.log("FINAL: offer_cancel: %s", JSON.stringify(m)); // console.log("FINAL: offer_cancel: %s", JSON.stringify(m));
@@ -802,8 +792,7 @@ buster.testCase("Offer tests", {
}); });
}, },
"offer cancel past and future sequence" : "offer cancel past and future sequence" : function (done) {
function (done) {
var self = this; var self = this;
var final_create; var final_create;
@@ -811,13 +800,12 @@ buster.testCase("Offer tests", {
function (callback) { function (callback) {
self.remote.transaction() self.remote.transaction()
.payment('root', 'alice', Amount.from_json("10000.0")) .payment('root', 'alice', Amount.from_json("10000.0"))
.on('proposed', function (m) { .once('submitted', function (m) {
// console.log("PROPOSED: CreateAccount: %s", JSON.stringify(m)); //console.log("PROPOSED: CreateAccount: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS', m); callback(m.engine_result !== 'tesSUCCESS', m);
}) })
.on('error', function(m) { .once('error', function(m) {
// console.log("error: %s", m); //console.log("error: %s", m);
buster.assert(false); buster.assert(false);
callback(m); callback(m);
}) })
@@ -827,9 +815,9 @@ buster.testCase("Offer tests", {
function (m, callback) { function (m, callback) {
self.remote.transaction() self.remote.transaction()
.offer_cancel("root", m.tx_json.Sequence) .offer_cancel("root", m.tx_json.Sequence)
.on('proposed', function (m) { .once('submitted', function (m) {
// console.log("PROPOSED: offer_cancel past: %s", JSON.stringify(m)); //console.log("PROPOSED: offer_cancel past: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS', m); callback(m.engine_result !== 'tesSUCCESS', m);
}) })
.submit(); .submit();
}, },
@@ -837,9 +825,9 @@ buster.testCase("Offer tests", {
function (m, callback) { function (m, callback) {
self.remote.transaction() self.remote.transaction()
.offer_cancel("root", m.tx_json.Sequence+1) .offer_cancel("root", m.tx_json.Sequence+1)
.on('proposed', function (m) { .once('submitted', function (m) {
// console.log("PROPOSED: offer_cancel same: %s", JSON.stringify(m)); //console.log("PROPOSED: offer_cancel same: %s", JSON.stringify(m));
callback(m.result !== 'temBAD_SEQUENCE', m); callback(m.engine_result !== 'temBAD_SEQUENCE', m);
}) })
.submit(); .submit();
}, },
@@ -847,17 +835,17 @@ buster.testCase("Offer tests", {
function (m, callback) { function (m, callback) {
self.remote.transaction() self.remote.transaction()
.offer_cancel("root", m.tx_json.Sequence+2) .offer_cancel("root", m.tx_json.Sequence+2)
.on('proposed', function (m) { .once('submitted', function (m) {
// console.log("ERROR: offer_cancel future: %s", JSON.stringify(m)); //console.log("ERROR: offer_cancel future: %s", JSON.stringify(m));
callback(m.result !== 'temBAD_SEQUENCE'); callback(m.engine_result !== 'temBAD_SEQUENCE');
}) })
.submit(); .submit();
}, },
// See if ledger_accept will crash. // See if ledger_accept will crash.
function (callback) { function (callback) {
self.remote self.remote
.once('ledger_closed', function (mesage) { .once('ledger_closed', function (message) {
// console.log("LEDGER_CLOSED: A: %d: %s", ledger_index, ledger_hash); //console.log("LEDGER_CLOSED: A: %d: %s", message.ledger_index, message.ledger_hash);
callback(); callback();
}) })
.ledger_accept(); .ledger_accept();
@@ -865,7 +853,7 @@ buster.testCase("Offer tests", {
function (callback) { function (callback) {
self.remote self.remote
.once('ledger_closed', function (mesage) { .once('ledger_closed', function (mesage) {
// console.log("LEDGER_CLOSED: B: %d: %s", ledger_index, ledger_hash); //console.log("LEDGER_CLOSED: B: %d: %s", message.ledger_index, message.ledger_hash);
callback(); callback();
}) })
.ledger_accept(); .ledger_accept();
@@ -874,16 +862,14 @@ buster.testCase("Offer tests", {
callback(); callback();
} }
], function (error) { ], function (error) {
// console.log("result: error=%s", error); //console.log("result: error=%s", error);
buster.refute(error, self.what); buster.refute(error, self.what);
done(); done();
}); });
}, },
"ripple currency conversion : entire offer" : "ripple currency conversion : entire offer" : function (done) {
// mtgox in, XRP out // mtgox in, XRP out
function (done) {
var self = this; var self = this;
var seq; var seq;
@@ -932,9 +918,9 @@ buster.testCase("Offer tests", {
self.remote.transaction() self.remote.transaction()
.offer_create("bob", "100/USD/mtgox", "500") .offer_create("bob", "100/USD/mtgox", "500")
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); // console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
seq = m.tx_json.Sequence; seq = m.tx_json.Sequence;
}) })
@@ -961,10 +947,10 @@ buster.testCase("Offer tests", {
self.remote.transaction() self.remote.transaction()
.payment("alice", "alice", "500") .payment("alice", "alice", "500")
.send_max("100/USD/mtgox") .send_max("100/USD/mtgox")
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
@@ -999,9 +985,8 @@ buster.testCase("Offer tests", {
}); });
}, },
"ripple currency conversion : offerer into debt" : "ripple currency conversion : offerer into debt" : function (done) {
// alice in, carol out // alice in, carol out
function (done) {
var self = this; var self = this;
var seq; var seq;
@@ -1027,9 +1012,9 @@ buster.testCase("Offer tests", {
self.remote.transaction() self.remote.transaction()
.offer_create("bob", "50/USD/alice", "200/EUR/carol") .offer_create("bob", "50/USD/alice", "200/EUR/carol")
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); // console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
callback(m.result !== 'tecUNFUNDED_OFFER'); callback(m.engine_result !== 'tecUNFUNDED_OFFER');
seq = m.tx_json.Sequence; seq = m.tx_json.Sequence;
}) })
@@ -1040,9 +1025,9 @@ buster.testCase("Offer tests", {
// //
// self.remote.transaction() // self.remote.transaction()
// .offer_create("alice", "200/EUR/carol", "50/USD/alice") // .offer_create("alice", "200/EUR/carol", "50/USD/alice")
// .on('proposed', function (m) { // .on('submitted', function (m) {
// // console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); // // console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
// callback(m.result !== 'tesSUCCESS'); // callback(m.engine_result !== 'tesSUCCESS');
// //
// seq = m.tx_json.Sequence; // seq = m.tx_json.Sequence;
// }) // })
@@ -1070,8 +1055,7 @@ buster.testCase("Offer tests", {
}); });
}, },
"ripple currency conversion : in parts" : "ripple currency conversion : in parts" : function (done) {
function (done) {
var self = this; var self = this;
var seq; var seq;
@@ -1105,9 +1089,9 @@ buster.testCase("Offer tests", {
self.remote.transaction() self.remote.transaction()
.offer_create("bob", "100/USD/mtgox", "500") .offer_create("bob", "100/USD/mtgox", "500")
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); // console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
seq = m.tx_json.Sequence; seq = m.tx_json.Sequence;
}) })
@@ -1119,10 +1103,10 @@ buster.testCase("Offer tests", {
self.remote.transaction() self.remote.transaction()
.payment("alice", "alice", "200") .payment("alice", "alice", "200")
.send_max("100/USD/mtgox") .send_max("100/USD/mtgox")
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
@@ -1147,10 +1131,10 @@ buster.testCase("Offer tests", {
self.remote.transaction() self.remote.transaction()
.payment("alice", "alice", "600") .payment("alice", "alice", "600")
.send_max("100/USD/mtgox") .send_max("100/USD/mtgox")
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tecPATH_PARTIAL'); callback(m.engine_result !== 'tecPATH_PARTIAL');
}) })
.submit(); .submit();
}, },
@@ -1161,10 +1145,10 @@ buster.testCase("Offer tests", {
.payment("alice", "alice", "600") .payment("alice", "alice", "600")
.send_max("100/USD/mtgox") .send_max("100/USD/mtgox")
.set_flags('PartialPayment') .set_flags('PartialPayment')
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
@@ -1195,10 +1179,8 @@ buster.testCase("Offer cross currency", {
// 'setUp' : testutils.build_setup({ verbose: true }), // 'setUp' : testutils.build_setup({ verbose: true }),
'tearDown' : testutils.build_teardown(), 'tearDown' : testutils.build_teardown(),
"ripple cross currency payment - start with XRP" : "ripple cross currency payment - start with XRP" : function (done) {
// alice --> [XRP --> carol --> USD/mtgox] --> bob // alice --> [XRP --> carol --> USD/mtgox] --> bob
function (done) {
var self = this; var self = this;
var seq; var seq;
@@ -1234,9 +1216,9 @@ buster.testCase("Offer cross currency", {
self.remote.transaction() self.remote.transaction()
.offer_create("carol", "500.0", "50/USD/mtgox") .offer_create("carol", "500.0", "50/USD/mtgox")
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); // console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
seq = m.tx_json.Sequence; seq = m.tx_json.Sequence;
}) })
@@ -1248,10 +1230,10 @@ buster.testCase("Offer cross currency", {
self.remote.transaction() self.remote.transaction()
.payment("alice", "bob", "25/USD/mtgox") .payment("alice", "bob", "25/USD/mtgox")
.send_max("333.0") .send_max("333.0")
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
@@ -1277,10 +1259,8 @@ buster.testCase("Offer cross currency", {
}); });
}, },
"ripple cross currency payment - end with XRP" : "ripple cross currency payment - end with XRP" : function (done) {
// alice --> [USD/mtgox --> carol --> XRP] --> bob // alice --> [USD/mtgox --> carol --> XRP] --> bob
function (done) {
var self = this; var self = this;
var seq; var seq;
@@ -1316,9 +1296,9 @@ buster.testCase("Offer cross currency", {
self.remote.transaction() self.remote.transaction()
.offer_create("carol", "50/USD/mtgox", "500") .offer_create("carol", "50/USD/mtgox", "500")
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); // console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
seq = m.tx_json.Sequence; seq = m.tx_json.Sequence;
}) })
@@ -1330,10 +1310,10 @@ buster.testCase("Offer cross currency", {
self.remote.transaction() self.remote.transaction()
.payment("alice", "bob", "250") .payment("alice", "bob", "250")
.send_max("333/USD/mtgox") .send_max("333/USD/mtgox")
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
@@ -1359,15 +1339,13 @@ buster.testCase("Offer cross currency", {
}); });
}, },
"ripple cross currency bridged payment" : "ripple cross currency bridged payment" : function (done) {
// alice --> [USD/mtgox --> carol --> XRP] --> [XRP --> dan --> EUR/bitstamp] --> bob // alice --> [USD/mtgox --> carol --> XRP] --> [XRP --> dan --> EUR/bitstamp] --> bob
function (done) {
var self = this; var self = this;
var seq_carol; var seq_carol;
var seq_dan; var seq_dan;
// self.remote.set_trace(); //self.remote.set_trace();
async.waterfall([ async.waterfall([
function (callback) { function (callback) {
@@ -1402,9 +1380,9 @@ buster.testCase("Offer cross currency", {
self.remote.transaction() self.remote.transaction()
.offer_create("carol", "50/USD/mtgox", "500") .offer_create("carol", "50/USD/mtgox", "500")
.on('proposed', function (m) { .once('proposed', function (m) {
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); //console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
seq_carol = m.tx_json.Sequence; seq_carol = m.tx_json.Sequence;
}) })
@@ -1415,9 +1393,9 @@ buster.testCase("Offer cross currency", {
self.remote.transaction() self.remote.transaction()
.offer_create("dan", "500", "50/EUR/bitstamp") .offer_create("dan", "500", "50/EUR/bitstamp")
.on('proposed', function (m) { .once('proposed', function (m) {
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); //console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
seq_dan = m.tx_json.Sequence; seq_dan = m.tx_json.Sequence;
}) })
@@ -1430,10 +1408,10 @@ buster.testCase("Offer cross currency", {
.payment("alice", "bob", "30/EUR/bitstamp") .payment("alice", "bob", "30/EUR/bitstamp")
.send_max("333/USD/mtgox") .send_max("333/USD/mtgox")
.path_add( [ { currency: "XRP" } ]) .path_add( [ { currency: "XRP" } ])
.on('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); //console.log("PROPOSED: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
@@ -1472,8 +1450,7 @@ buster.testCase("Offer tests 3", {
// 'setUp' : testutils.build_setup({ verbose: true, standalone: true }), // 'setUp' : testutils.build_setup({ verbose: true, standalone: true }),
'tearDown' : testutils.build_teardown(), 'tearDown' : testutils.build_teardown(),
"offer fee consumes funds" : "offer fee consumes funds" : function (done) {
function (done) {
var self = this; var self = this;
var final_create; var final_create;
@@ -1536,9 +1513,9 @@ buster.testCase("Offer tests 3", {
self.remote.transaction() self.remote.transaction()
.offer_create("bob", "200.0", "200/USD/mtgox") .offer_create("bob", "200.0", "200/USD/mtgox")
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("proposed: offer_create: %s", json.stringify(m)); // console.log("proposed: offer_create: %s", json.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
seq_carol = m.tx_json.sequence; seq_carol = m.tx_json.sequence;
}) })
.submit(); .submit();
@@ -1550,9 +1527,9 @@ buster.testCase("Offer tests 3", {
self.remote.transaction() self.remote.transaction()
.offer_create("alice", "200/USD/mtgox", "200.0") .offer_create("alice", "200/USD/mtgox", "200.0")
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("proposed: offer_create: %s", json.stringify(m)); // console.log("proposed: offer_create: %s", json.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
seq_carol = m.tx_json.sequence; seq_carol = m.tx_json.sequence;
}) })
@@ -1586,8 +1563,7 @@ buster.testCase("Offer tests 3", {
done(); done();
}); });
}, },
"offer create then cross offer" : "offer create then cross offer" : function (done) {
function (done) {
var self = this; var self = this;
var final_create; var final_create;
@@ -1605,7 +1581,7 @@ buster.testCase("Offer tests 3", {
.transfer_rate(1005000000) .transfer_rate(1005000000)
.once('proposed', function (m) { .once('proposed', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
@@ -1644,9 +1620,9 @@ buster.testCase("Offer tests 3", {
self.remote.transaction() self.remote.transaction()
.offer_create("alice", "50/USD/mtgox", "150000.0") .offer_create("alice", "50/USD/mtgox", "150000.0")
.on('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: offer_create: %s", json.stringify(m)); // console.log("proposed: offer_create: %s", json.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
seq_carol = m.tx_json.sequence; seq_carol = m.tx_json.sequence;
}) })
@@ -1657,9 +1633,9 @@ buster.testCase("Offer tests 3", {
self.remote.transaction() self.remote.transaction()
.offer_create("bob", "100.0", ".1/USD/mtgox") .offer_create("bob", "100.0", ".1/USD/mtgox")
.on('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: offer_create: %s", json.stringify(m)); // console.log("proposed: offer_create: %s", json.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
seq_carol = m.tx_json.sequence; seq_carol = m.tx_json.sequence;
}) })
@@ -1689,7 +1665,6 @@ buster.testCase("Offer tests 3", {
], function (error) { ], function (error) {
// console.log("result: error=%s", error); // console.log("result: error=%s", error);
buster.refute(error, self.what); buster.refute(error, self.what);
done(); done();
}); });
}, },
@@ -1701,8 +1676,7 @@ buster.testCase("Offer tfSell", {
// 'setUp' : testutils.build_setup({ verbose: true, standalone: true }), // 'setUp' : testutils.build_setup({ verbose: true, standalone: true }),
'tearDown' : testutils.build_teardown(), 'tearDown' : testutils.build_teardown(),
"basic sell" : "basic sell" : function (done) {
function (done) {
var self = this; var self = this;
var final_create, seq_carol; var final_create, seq_carol;
@@ -1740,10 +1714,10 @@ buster.testCase("Offer tfSell", {
self.remote.transaction() self.remote.transaction()
.offer_create("bob", "200.0", "200/USD/mtgox") .offer_create("bob", "200.0", "200/USD/mtgox")
.set_flags('Sell') // Should not matter at all. .set_flags('Sell') // Should not matter at all.
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("proposed: offer_create: %s", json.stringify(m)); // console.log("proposed: offer_create: %s", json.stringify(m));
if (m.result !== 'tesSUCCESS') { if (m.engine_result !== 'tesSUCCESS') {
throw new Error("Bob's OfferCreate tx did not succeed: "+m.result); throw new Error("Bob's OfferCreate tx did not succeed: "+m.engine_result);
} else callback(null); } else callback(null);
seq_carol = m.tx_json.sequence; seq_carol = m.tx_json.sequence;
@@ -1758,9 +1732,9 @@ buster.testCase("Offer tfSell", {
self.remote.transaction() self.remote.transaction()
.offer_create("alice", "200/USD/mtgox", "200.0") .offer_create("alice", "200/USD/mtgox", "200.0")
.set_flags('Sell') // Should not matter at all. .set_flags('Sell') // Should not matter at all.
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("proposed: offer_create: %s", json.stringify(m)); // console.log("proposed: offer_create: %s", json.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
seq_carol = m.tx_json.sequence; seq_carol = m.tx_json.sequence;
}) })
@@ -1795,8 +1769,7 @@ buster.testCase("Offer tfSell", {
}); });
}, },
"2x sell exceed limit" : "2x sell exceed limit" : function (done) {
function (done) {
var self = this; var self = this;
var final_create, seq_carol; var final_create, seq_carol;
@@ -1804,7 +1777,6 @@ buster.testCase("Offer tfSell", {
function (callback) { function (callback) {
// Provide micro amounts to compensate for fees to make results round nice. // Provide micro amounts to compensate for fees to make results round nice.
self.what = "Create accounts."; self.what = "Create accounts.";
var starting_xrp = self.amount_for({ var starting_xrp = self.amount_for({
ledger_entries: 1, ledger_entries: 1,
default_transactions: 2, default_transactions: 2,
@@ -1838,9 +1810,9 @@ buster.testCase("Offer tfSell", {
// Selling USD. // Selling USD.
self.remote.transaction() self.remote.transaction()
.offer_create("bob", "100.0", "200/USD/mtgox") .offer_create("bob", "100.0", "200/USD/mtgox")
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("proposed: offer_create: %s", json.stringify(m)); // console.log("proposed: offer_create: %s", json.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
seq_carol = m.tx_json.sequence; seq_carol = m.tx_json.sequence;
}) })
.submit(); .submit();
@@ -1856,10 +1828,10 @@ buster.testCase("Offer tfSell", {
self.remote.transaction() self.remote.transaction()
.offer_create("alice", "100/USD/mtgox", "100.0") .offer_create("alice", "100/USD/mtgox", "100.0")
.set_flags('Sell') .set_flags('Sell')
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("proposed: offer_create: %s", json.stringify(m)); // console.log("proposed: offer_create: %s", json.stringify(m));
if (m.result !== 'tesSUCCESS') { if (m.engine_result !== 'tesSUCCESS') {
callback(new Error("Alice's OfferCreate didn't succeed: "+m.result)); callback(new Error("Alice's OfferCreate didn't succeed: "+m.engine_result));
} else callback(null); } else callback(null);
seq_carol = m.tx_json.sequence; seq_carol = m.tx_json.sequence;
@@ -1902,8 +1874,7 @@ buster.testCase("Client Issue #535", {
// 'setUp' : testutils.build_setup({ verbose: true, standalone: true }), // 'setUp' : testutils.build_setup({ verbose: true, standalone: true }),
'tearDown' : testutils.build_teardown(), 'tearDown' : testutils.build_teardown(),
"gateway cross currency" : "gateway cross currency" : function (done) {
function (done) {
var self = this; var self = this;
var final_create; var final_create;
@@ -1944,9 +1915,9 @@ buster.testCase("Client Issue #535", {
self.remote.transaction() self.remote.transaction()
.offer_create("alice", "100/XTS/mtgox", "100/XXX/mtgox") .offer_create("alice", "100/XTS/mtgox", "100/XXX/mtgox")
.on('proposed', function (m) { .on('submitted', function (m) {
// console.log("proposed: offer_create: %s", json.stringify(m)); // console.log("proposed: offer_create: %s", json.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
seq_carol = m.tx_json.sequence; seq_carol = m.tx_json.sequence;
}) })
@@ -1959,11 +1930,11 @@ buster.testCase("Client Issue #535", {
.payment("bob", "bob", "1/XXX/bob") .payment("bob", "bob", "1/XXX/bob")
.send_max("1.5/XTS/bob") .send_max("1.5/XTS/bob")
.build_path(true) .build_path(true)
.on('proposed', function (m) { .on('submitted', function (m) {
if (m.result !== 'tesSUCCESS') if (m.engine_result !== 'tesSUCCESS')
console.log("proposed: %s", JSON.stringify(m, undefined, 2)); console.log("proposed: %s", JSON.stringify(m, undefined, 2));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
@@ -1990,7 +1961,7 @@ buster.testCase("Client Issue #535", {
}, },
], function (error) { ], function (error) {
if (error) if (error)
console.log("result: %s: error=%s", self.what, error); //console.log("result: %s: error=%s", self.what, error);
buster.refute(error, self.what); buster.refute(error, self.what);
done(); done();

View File

@@ -18,8 +18,7 @@ buster.testCase("Basic Path finding", {
// 'setUp' : testutils.build_setup({ verbose: true, no_server: true }), // 'setUp' : testutils.build_setup({ verbose: true, no_server: true }),
'tearDown' : testutils.build_teardown(), 'tearDown' : testutils.build_teardown(),
"no direct path, no intermediary -> no alternatives" : "no direct path, no intermediary -> no alternatives" : function (done) {
function (done) {
var self = this; var self = this;
async.waterfall([ async.waterfall([
@@ -46,8 +45,7 @@ buster.testCase("Basic Path finding", {
}); });
}, },
"direct path, no intermediary" : "direct path, no intermediary" : function (done) {
function (done) {
var self = this; var self = this;
async.waterfall([ async.waterfall([
@@ -110,8 +108,7 @@ buster.testCase("Basic Path finding", {
}); });
}, },
"payment auto path find (using build_path)" : "payment auto path find (using build_path)" : function (done) {
function (done) {
var self = this; var self = this;
async.waterfall([ async.waterfall([
@@ -145,9 +142,9 @@ buster.testCase("Basic Path finding", {
self.remote.transaction() self.remote.transaction()
.payment('alice', 'bob', "24/USD/bob") .payment('alice', 'bob', "24/USD/bob")
.build_path(true) .build_path(true)
.once('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); //console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
@@ -163,13 +160,13 @@ buster.testCase("Basic Path finding", {
callback); callback);
}, },
], function (error) { ], function (error) {
//console.log(error);
buster.refute(error, self.what); buster.refute(error, self.what);
done(); done();
}); });
}, },
"path find" : "path find" : function (done) {
function (done) {
var self = this; var self = this;
async.waterfall([ async.waterfall([
@@ -221,14 +218,15 @@ buster.testCase("Basic Path finding", {
}, },
}); });
buster.testCase("Extended Path finding", { buster.testCase("Extended Path finding", {
// 'setUp' : testutils.build_setup({ verbose: true, no_server: true }), // 'setUp' : testutils.build_setup({ verbose: true, no_server: true }),
// 'setUp' : testutils.build_setup({ verbose: true }), // 'setUp' : testutils.build_setup({ verbose: true }),
'setUp' : testutils.build_setup(), 'setUp' : testutils.build_setup(),
'tearDown' : testutils.build_teardown(), 'tearDown' : testutils.build_teardown(),
"alternative paths - consume both" : "alternative paths - consume both" : function (done) {
function (done) {
var self = this; var self = this;
async.waterfall([ async.waterfall([
@@ -263,7 +261,7 @@ buster.testCase("Extended Path finding", {
self.remote.transaction() self.remote.transaction()
.payment('alice', 'bob', "140/USD/bob") .payment('alice', 'bob', "140/USD/bob")
.build_path(true) .build_path(true)
.once('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.result !== 'tesSUCCESS');
}) })
@@ -287,8 +285,7 @@ buster.testCase("Extended Path finding", {
}); });
}, },
"alternative paths - consume best transfer" : "alternative paths - consume best transfer" : function (done) {
function (done) {
var self = this; var self = this;
async.waterfall([ async.waterfall([
@@ -303,7 +300,7 @@ buster.testCase("Extended Path finding", {
self.remote.transaction() self.remote.transaction()
.account_set("bitstamp") .account_set("bitstamp")
.transfer_rate(1e9*1.1) .transfer_rate(1e9*1.1)
.once('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.result !== 'tesSUCCESS');
}) })
@@ -335,7 +332,7 @@ buster.testCase("Extended Path finding", {
self.remote.transaction() self.remote.transaction()
.payment('alice', 'bob', "70/USD/bob") .payment('alice', 'bob', "70/USD/bob")
.build_path(true) .build_path(true)
.once('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.result !== 'tesSUCCESS');
}) })
@@ -359,8 +356,7 @@ buster.testCase("Extended Path finding", {
}); });
}, },
"alternative paths - consume best transfer first" : "alternative paths - consume best transfer first" : function (done) {
function (done) {
var self = this; var self = this;
async.waterfall([ async.waterfall([
@@ -375,7 +371,7 @@ buster.testCase("Extended Path finding", {
self.remote.transaction() self.remote.transaction()
.account_set("bitstamp") .account_set("bitstamp")
.transfer_rate(1e9*1.1) .transfer_rate(1e9*1.1)
.once('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.result !== 'tesSUCCESS');
}) })
@@ -408,7 +404,7 @@ buster.testCase("Extended Path finding", {
.payment('alice', 'bob', "77/USD/bob") .payment('alice', 'bob', "77/USD/bob")
.build_path(true) .build_path(true)
.send_max("100/USD/alice") .send_max("100/USD/alice")
.once('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.result !== 'tesSUCCESS');
}) })
@@ -441,12 +437,11 @@ buster.testCase("More Path finding", {
'setUp' : testutils.build_setup(), 'setUp' : testutils.build_setup(),
'tearDown' : testutils.build_teardown(), 'tearDown' : testutils.build_teardown(),
"// alternative paths - limit returned paths to best quality" :
// alice +- bitstamp -+ bob // alice +- bitstamp -+ bob
// |- carol(fee) -| // To be excluded. // |- carol(fee) -| // To be excluded.
// |- dan(issue) -| // |- dan(issue) -|
// |- mtgox -| // |- mtgox -|
function (done) { "// alternative paths - limit returned paths to best quality" : function (done) {
var self = this; var self = this;
async.waterfall([ async.waterfall([
@@ -461,7 +456,7 @@ buster.testCase("More Path finding", {
self.remote.transaction() self.remote.transaction()
.account_set("carol") .account_set("carol")
.transfer_rate(1e9*1.1) .transfer_rate(1e9*1.1)
.once('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.result !== 'tesSUCCESS');
}) })
@@ -513,8 +508,7 @@ buster.testCase("More Path finding", {
}); });
}, },
"alternative paths - consume best transfer" : "alternative paths - consume best transfer" : function (done) {
function (done) {
var self = this; var self = this;
async.waterfall([ async.waterfall([
@@ -529,7 +523,7 @@ buster.testCase("More Path finding", {
self.remote.transaction() self.remote.transaction()
.account_set("bitstamp") .account_set("bitstamp")
.transfer_rate(1e9*1.1) .transfer_rate(1e9*1.1)
.once('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.result !== 'tesSUCCESS');
}) })
@@ -561,7 +555,7 @@ buster.testCase("More Path finding", {
self.remote.transaction() self.remote.transaction()
.payment('alice', 'bob', "70/USD/bob") .payment('alice', 'bob', "70/USD/bob")
.build_path(true) .build_path(true)
.once('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.result !== 'tesSUCCESS');
}) })
@@ -585,8 +579,7 @@ buster.testCase("More Path finding", {
}); });
}, },
"alternative paths - consume best transfer first" : "alternative paths - consume best transfer first" : function (done) {
function (done) {
var self = this; var self = this;
async.waterfall([ async.waterfall([
@@ -601,7 +594,7 @@ buster.testCase("More Path finding", {
self.remote.transaction() self.remote.transaction()
.account_set("bitstamp") .account_set("bitstamp")
.transfer_rate(1e9*1.1) .transfer_rate(1e9*1.1)
.once('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.result !== 'tesSUCCESS');
}) })
@@ -634,7 +627,7 @@ buster.testCase("More Path finding", {
.payment('alice', 'bob', "77/USD/bob") .payment('alice', 'bob', "77/USD/bob")
.build_path(true) .build_path(true)
.send_max("100/USD/alice") .send_max("100/USD/alice")
.once('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.result !== 'tesSUCCESS');
}) })
@@ -667,8 +660,7 @@ buster.testCase("Issues", {
'setUp' : testutils.build_setup(), 'setUp' : testutils.build_setup(),
'tearDown' : testutils.build_teardown(), 'tearDown' : testutils.build_teardown(),
"Path negative: Issue #5" : "Path negative: Issue #5" : function (done) {
function (done) {
var self = this; var self = this;
async.waterfall([ async.waterfall([
@@ -696,7 +688,7 @@ buster.testCase("Issues", {
self.remote.transaction() self.remote.transaction()
.payment("bob", "carol", "75/USD/bob") .payment("bob", "carol", "75/USD/bob")
.on('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.result !== 'tesSUCCESS');
@@ -745,7 +737,7 @@ buster.testCase("Issues", {
self.remote.transaction() self.remote.transaction()
.payment('alice', 'bob', "25/USD/alice") .payment('alice', 'bob', "25/USD/alice")
.once('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tecPATH_DRY'); callback(m.result !== 'tecPATH_DRY');
}) })
@@ -801,7 +793,7 @@ buster.testCase("Issues", {
self.remote.transaction() self.remote.transaction()
.payment('alice', 'bob', "55/USD/bob") .payment('alice', 'bob', "55/USD/bob")
.build_path(true) .build_path(true)
.once('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.result !== 'tesSUCCESS');
}) })
@@ -865,7 +857,7 @@ buster.testCase("Issues", {
self.remote.transaction() self.remote.transaction()
.payment('alice', 'bob', "50/USD/bob") .payment('alice', 'bob', "50/USD/bob")
.build_path(true) .build_path(true)
.once('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.result !== 'tesSUCCESS');
}) })
@@ -926,7 +918,7 @@ buster.testCase("Via offers", {
self.remote.transaction() self.remote.transaction()
.account_set("mtgox") .account_set("mtgox")
.transfer_rate(1005000000) .transfer_rate(1005000000)
.once('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.result !== 'tesSUCCESS');
}) })
@@ -956,7 +948,7 @@ buster.testCase("Via offers", {
self.remote.transaction() self.remote.transaction()
.offer_create("carol", "50.0", "50/AUD/mtgox") .offer_create("carol", "50.0", "50/AUD/mtgox")
.on('proposed', function (m) { .once('submitted', function (m) {
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); // console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.result !== 'tesSUCCESS');
@@ -972,7 +964,7 @@ buster.testCase("Via offers", {
.payment("alice", "bob", "10/AUD/mtgox") .payment("alice", "bob", "10/AUD/mtgox")
.build_path(true) .build_path(true)
.send_max("100.0") .send_max("100.0")
.on('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.result !== 'tesSUCCESS');
@@ -1041,7 +1033,7 @@ buster.testCase("Via offers", {
self.remote.transaction() self.remote.transaction()
.account_set("mtgox") .account_set("mtgox")
.transfer_rate(1005000000) .transfer_rate(1005000000)
.once('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.result !== 'tesSUCCESS');
}) })
@@ -1071,7 +1063,7 @@ buster.testCase("Via offers", {
self.remote.transaction() self.remote.transaction()
.offer_create("carol", "50", "50/AUD/mtgox") .offer_create("carol", "50", "50/AUD/mtgox")
.on('proposed', function (m) { .once('submitted', function (m) {
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m)); // console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.result !== 'tesSUCCESS');
@@ -1087,7 +1079,7 @@ buster.testCase("Via offers", {
.payment("alice", "bob", "10/AUD/mtgox") .payment("alice", "bob", "10/AUD/mtgox")
.build_path(true) .build_path(true)
.send_max("100") .send_max("100")
.on('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.result !== 'tesSUCCESS');
@@ -1246,14 +1238,16 @@ buster.testCase("Quality paths", {
function (callback) { function (callback) {
self.what = "Payment with auto path"; self.what = "Payment with auto path";
self.remote.trace = true;
self.remote.transaction() self.remote.transaction()
.payment('alice', 'bob', "100/USD/bob") .payment('alice', 'bob', "100/USD/bob")
.send_max("120/USD/alice") .send_max("120/USD/alice")
// .set_flags('PartialPayment') // .set_flags('PartialPayment')
// .build_path(true) // .build_path(true)
.once('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); console.log("proposed: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },

View File

@@ -10,31 +10,25 @@ var config = testutils.init_config();
// How long to wait for server to start. // How long to wait for server to start.
var serverDelay = 1500; // XXX Not implemented. var serverDelay = 1500; // XXX Not implemented.
buster.testRunner.timeout = 5000; buster.testRunner.timeout = 5000 * 10;
buster.testCase("Remote functions", { buster.testCase("Remote functions", {
'setUp' : testutils.build_setup(), 'setUp' : testutils.build_setup(),
'tearDown' : testutils.build_teardown(), 'tearDown' : testutils.build_teardown(),
"request_ledger_current" : "request_ledger_current" : function (done) {
function (done) {
this.remote.request_ledger_current().on('success', function (m) { this.remote.request_ledger_current().on('success', function (m) {
// console.log(m);
buster.assert.equals(m.ledger_current_index, 3); buster.assert.equals(m.ledger_current_index, 3);
done(); done();
}) })
.on('error', function(m) { .on('error', function(m) {
// console.log(m);
buster.assert(false); buster.assert(false);
}) })
.request(); .request();
}, },
"request_ledger_hash" : "request_ledger_hash" : function (done) {
function (done) {
this.remote.request_ledger_hash().on('success', function (m) { this.remote.request_ledger_hash().on('success', function (m) {
// console.log("result: %s", JSON.stringify(m)); // console.log("result: %s", JSON.stringify(m));
@@ -49,8 +43,7 @@ buster.testCase("Remote functions", {
.request(); .request();
}, },
"manual account_root success" : "manual account_root success" : function (done) {
function (done) {
var self = this; var self = this;
this.remote.request_ledger_hash().on('success', function (r) { this.remote.request_ledger_hash().on('success', function (r) {
@@ -82,8 +75,7 @@ buster.testCase("Remote functions", {
}, },
// XXX This should be detected locally. // XXX This should be detected locally.
"account_root remote malformedAddress" : "account_root remote malformedAddress" : function (done) {
function (done) {
var self = this; var self = this;
this.remote.request_ledger_hash().on('success', function (r) { this.remote.request_ledger_hash().on('success', function (r) {
@@ -95,12 +87,10 @@ buster.testCase("Remote functions", {
.account_root("zHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh") .account_root("zHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh")
.on('success', function (r) { .on('success', function (r) {
// console.log("account_root: %s", JSON.stringify(r)); // console.log("account_root: %s", JSON.stringify(r));
buster.assert(false); buster.assert(false);
}) })
.on('error', function(m) { .on('error', function(m) {
// console.log("error: %s", m); // console.log("error: %s", m);
buster.assert.equals(m.error, 'remoteError'); buster.assert.equals(m.error, 'remoteError');
buster.assert.equals(m.remote.error, 'malformedAddress'); buster.assert.equals(m.remote.error, 'malformedAddress');
done(); done();
@@ -115,8 +105,7 @@ buster.testCase("Remote functions", {
.request(); .request();
}, },
"account_root entryNotFound" : "account_root entryNotFound" : function (done) {
function (done) {
var self = this; var self = this;
this.remote.request_ledger_hash().on('success', function (r) { this.remote.request_ledger_hash().on('success', function (r) {
@@ -147,8 +136,7 @@ buster.testCase("Remote functions", {
}).request(); }).request();
}, },
"ledger_entry index" : "ledger_entry index" : function (done) {
function (done) {
var self = this; var self = this;
this.remote.request_ledger_hash().on('success', function (r) { this.remote.request_ledger_hash().on('success', function (r) {
@@ -180,63 +168,64 @@ buster.testCase("Remote functions", {
.request(); .request();
}, },
"create account" : "create account" : function (done) {
function (done) { var self = this;
this.remote.transaction()
.payment('root', 'alice', "10000.0")
.on('success', function (r) {
// console.log("account_root: %s", JSON.stringify(r));
// Need to verify account and balance. var root_id = this.remote.account('root')._account_id;
buster.assert(true); this.remote.request_subscribe().accounts(root_id).request();
done();
})
.on('error', function(m) {
// console.log("error: %s", m);
buster.assert(false); this.remote.transaction()
}) .payment('root', 'alice', "10000.0")
.submit(); .on('proposed', function(res) {
//console.log('Submitted', res);
self.remote.ledger_accept();
})
.on('success', function (r) {
//console.log("account_root: %s", JSON.stringify(r));
// Need to verify account and balance.
buster.assert(true);
done();
})
.on('error', function(m) {
console.log('Error');
console.log("error: %s", m);
buster.assert(false);
})
.submit();
}, },
"create account final" : "create account final" : function (done) {
function (done) {
var self = this; var self = this;
var got_proposed;
var got_success;
var got_proposed; var root_id = this.remote.account('root')._account_id;
var got_success; this.remote.request_subscribe().accounts(root_id).request();
this.remote.transaction() this.remote.transaction()
.payment('root', 'alice', "10000.0") .payment('root', 'alice', "10000.0")
.on('success', function (r) { .on('success', function (r) {
// console.log("create_account: %s", JSON.stringify(r)); // console.log("create_account: %s", JSON.stringify(r));
got_success = true;
got_success = true; })
})
.on('error', function (m) { .on('error', function (m) {
// console.log("error: %s", m); // console.log("error: %s", m);
buster.assert(false);
buster.assert(false); })
})
.on('final', function (m) { .on('final', function (m) {
// console.log("final: %s", JSON.stringify(m)); // console.log("final: %s", JSON.stringify(m));
buster.assert(got_success && got_proposed);
buster.assert(got_success && got_proposed); done();
done(); })
}) .on('proposed', function() {
.on('proposed', function (m) { got_proposed = true;
// console.log("proposed: %s", JSON.stringify(m)); self.remote.ledger_accept();
})
// buster.assert.equals(m.result, 'terNO_DST_INSUF_XRP'); .on('submitted', function (m) {
buster.assert.equals(m.result, 'tesSUCCESS'); // console.log("proposed: %s", JSON.stringify(m));
// buster.assert.equals(m.result, 'terNO_DST_INSUF_XRP');
got_proposed = true; buster.assert.equals(m.engine_result, 'tesSUCCESS');
})
self.remote.ledger_accept();
})
.on('status', function (s) {
// console.log("status: %s", JSON.stringify(s));
})
.submit(); .submit();
}, },
}); });

File diff suppressed because it is too large Load Diff

View File

@@ -1,43 +1,58 @@
var async = require("async"); var async = require('async');
var extend = require("extend"); var extend = require('extend');
var Amount = require("ripple-lib").Amount; var Amount = require('ripple-lib').Amount;
var Remote = require("ripple-lib").Remote; var Remote = require('ripple-lib').Remote;
var Server = require("./server").Server; var Server = require('./server').Server;
var Transaction = require("ripple-lib").Transaction; var Transaction = require('ripple-lib').Transaction;
var account_dump = function (remote, account, callback) { function get_config() {
var cfg = require('./config-example');
// See if the person testing wants to override the configuration by creating a
// file called test/config.js.
try {
cfg = extend({}, cfg, require('./config'));
} catch (e) { }
return cfg;
};
function init_config() {
return require('ripple-lib').config.load(get_config());
};
function prepare_tests(tests, fn) {
var tests = typeof tests === 'string' ? [ tests ] : tests;
var result = [ ];
for (var i in tests) {
result.push(fn(tests[i], i));
}
return result;
};
function account_dump(remote, account, callback) {
var self = this; var self = this;
async.waterfall([ this.what = 'Get latest account_root';
function (callback) {
self.what = "Get latest account_root";
remote var request = remote.request_ledger_entry('account_root');
.request_ledger_entry('account_root') request.ledger_hash(remote.ledger_hash());
.ledger_hash(remote.ledger_hash()) request.account_root('root');
.account_root("root") request.callback(function(err, r) {
.on('success', function (r) { buster.isNull(err);
//console.log("account_root: %s", JSON.stringify(r, undefined, 2)); if (err) {
//console.log('error: %s', m);
callback(); callback(err);
}) } else {
.on('error', function(m) { //console.log('account_root: %s', JSON.stringify(r, undefined, 2));
console.log("error: %s", m); callback();
}
buster.assert(false); });
callback();
})
.request();
},
], function (error) {
callback(error);
});
// get closed ledger hash // get closed ledger hash
// get account root // get account root
// construct a json result // construct a json result
//
}; };
/** /**
@@ -48,7 +63,7 @@ var account_dump = function (remote, account, callback) {
* debugging. * debugging.
* *
* @example * @example
* buster.testCase("Foobar", { * buster.testCase('Foobar', {
* setUp: testutils.build_setup({verbose: true}), * setUp: testutils.build_setup({verbose: true}),
* // ... * // ...
* }); * });
@@ -63,67 +78,69 @@ var account_dump = function (remote, account, callback) {
* @param opts.no_server {Bool} Don't auto-run rippled. * @param opts.no_server {Bool} Don't auto-run rippled.
* @param host {String} Identifier for the host configuration to be used. * @param host {String} Identifier for the host configuration to be used.
*/ */
var build_setup = function (opts, host) { function build_setup(opts, host) {
var config = get_config(); var config = get_config();
var host = host || config.server_default;
opts = opts || {}; var opts = opts || {};
// Normalize options // Normalize options
if (opts.verbose) { if (opts.verbose) {
opts.verbose_ws = true; opts.verbose_ws = true;
opts.verbose_server = true; opts.verbose_server = true;
}; };
return function (done) { function setup(done) {
var self = this; var self = this;
self.compute_fees_amount_for_txs = function(txs) { self.compute_fees_amount_for_txs = function(txs) {
var fee_units = Transaction.fee_units["default"] * txs; var fee_units = Transaction.fee_units['default'] * txs;
return self.remote.fee_tx(fee_units); return self.remote.fee_tx(fee_units);
}; };
self.amount_for = function(options) { self.amount_for = function(options) {
var reserve = self.remote.reserve(options.ledger_entries || 0); var reserve = self.remote.reserve(options.ledger_entries || 0);
var fees = self.compute_fees_amount_for_txs(options.default_transactions || 0) var fees = self.compute_fees_amount_for_txs(options.default_transactions || 0)
return reserve.add(fees) return reserve.add(fees).add(options.extra || 0);
.add(options.extra || 0);
}; };
host = host || config.server_default;
this.store = this.store || {}; this.store = this.store || {};
this.store[host] = this.store[host] || { };
var data = this.store[host] = this.store[host] || {}; var data = this.store[host];
data.opts = opts; data.opts = opts;
async.series([ var series = [
function runServerStep(callback) { function run_server(callback) {
if (opts.no_server) return callback(); if (opts.no_server) {
return callback();
}
var server_config = extend({}, config.default_server_config, var server_config = extend({}, config.default_server_config, config.servers[host]);
config.servers[host]);
data.server = Server data.server = Server.from_config(host, server_config, !!opts.verbose_server);
.from_config(host, server_config,
!!opts.verbose_server) data.server.once('started', callback);
.on('started', callback) data.server.once('exited', function () {
.on('exited', function () { // If know the remote, tell it server is gone.
// If know the remote, tell it server is gone. if (self.remote) {
if (self.remote) self.remote.server_fatal();
self.remote.server_fatal(); }
}) });
.start();
data.server.start();
}, },
function connectWebsocketStep(callback) {
self.remote = data.remote = function connect_websocket(callback) {
Remote self.remote = data.remote = Remote.from_config(host, !!opts.verbose_ws);
.from_config(host, !!opts.verbose_ws) self.remote.once('ledger_closed', callback);
.once('ledger_closed', callback) self.remote.connect();
.connect();
} }
], done); ];
async.series(series, done);
}; };
return setup;
}; };
/** /**
@@ -131,41 +148,41 @@ var build_setup = function (opts, host) {
* *
* @param host {String} Identifier for the host configuration to be used. * @param host {String} Identifier for the host configuration to be used.
*/ */
var build_teardown = function (host) { function build_teardown(host) {
var config = get_config(); var config = get_config();
var host = host || config.server_default;
return function (done) { function teardown(done) {
host = host || config.server_default;
var data = this.store[host]; var data = this.store[host];
var opts = data.opts; var opts = data.opts;
async.series([ var series = [
function disconnectWebsocketStep(callback) { function disconnect_websocket(callback) {
data.remote.once('disconnected', callback)
data.remote.once('error', function (m) {
console.log('server error: ', m);
})
data.remote.connect(false);
},
data.remote function stop_server(callback) {
.on('disconnected', callback) if (opts.no_server) {
.on('error', function (m) { callback();
console.log("server error: ", m); } else {
}) data.server.once('stopped', callback)
.connect(false); data.server.stop();
},
function stopServerStep(callback) {
if (opts.no_server)
{
return callback();
}
data.server
.on('stopped', callback)
.stop();
} }
], done); }
];
async.series(series, done);
}; };
return teardown;
}; };
var create_accounts = function (remote, src, amount, accounts, callback) { function create_accounts(remote, src, amount, accounts, callback) {
assert(5 === arguments.length); assert(arguments.length === 5);
remote.set_account_seq(src, 1); remote.set_account_seq(src, 1);
@@ -174,334 +191,311 @@ var create_accounts = function (remote, src, amount, accounts, callback) {
// Otherwise, when other operations attempt to opperate async against the account they may get confused. // Otherwise, when other operations attempt to opperate async against the account they may get confused.
remote.set_account_seq(account, 1); remote.set_account_seq(account, 1);
remote.transaction() var tx = remote.transaction();
.payment(src, account, amount)
.on('proposed', function (m) {
// console.log("proposed: %s", JSON.stringify(m));
if (m.result != 'tesSUCCESS') { tx.payment(src, account, amount);
callback(new Error("Payment to create account did not succeed."));
} else callback(null);
})
.on('error', function (m) {
// console.log("error: %s", JSON.stringify(m));
callback(m); tx.once('proposed', function (m) {
}) // console.log('proposed: %s', JSON.stringify(m));
.submit(); callback(m.engine_result === 'tesSUCCESS' ? null : new Error());
}, callback); });
tx.once('error', function (m) {
// console.log('error: %s', JSON.stringify(m));
callback(m);
});
tx.submit();
}, callback);
}; };
var credit_limit = function (remote, src, amount, callback) { function credit_limit(remote, src, amount, callback) {
assert(4 === arguments.length); assert(arguments.length === 4);
var _m = amount.match(/^(\d+\/...\/[^\:]+)(?::(\d+)(?:,(\d+))?)?$/);
var _m = amount.match(/^(\d+\/...\/[^\:]+)(?::(\d+)(?:,(\d+))?)?$/);
if (!_m) { if (!_m) {
console.log("credit_limit: parse error: %s", amount); //console.log('credit_limit: parse error: %s', amount);
return callback(new Error('parse_error'));
callback('parse_error');
} }
else
{
// console.log("credit_limit: parsed: %s", JSON.stringify(_m, undefined, 2));
var _account_limit = _m[1];
var _quality_in = _m[2];
var _quality_out = _m[3];
remote.transaction() // console.log('credit_limit: parsed: %s', JSON.stringify(_m, undefined, 2));
.ripple_line_set(src, _account_limit, _quality_in, _quality_out) var account_limit = _m[1];
.on('proposed', function (m) { var quality_in = _m[2];
// console.log("proposed: %s", JSON.stringify(m)); var quality_out = _m[3];
callback(m.result != 'tesSUCCESS'); var tx = remote.transaction()
})
.on('error', function (m) {
// console.log("error: %s", JSON.stringify(m));
callback(m); tx.ripple_line_set(src, account_limit, quality_in, quality_out)
})
.submit(); tx.once('proposed', function (m) {
} // console.log('proposed: %s', JSON.stringify(m));
callback(m.engine_result === 'tesSUCCESS' ? null : new Error());
});
tx.once('error', function (m) {
// console.log('error: %s', JSON.stringify(m));
callback(m);
});
tx.submit();
}; };
function get_config() { function verify_limit(remote, src, amount, callback) {
var cfg = require('./config-example'); assert(arguments.length === 4);
// See if the person testing wants to override the configuration by creating a var _m = amount.match(/^(\d+\/...\/[^\:]+)(?::(\d+)(?:,(\d+))?)?$/);
// file called test/config.js.
try {
cfg = extend({}, cfg, require('./config'));
} catch (e) { }
return cfg;
}
function init_config() {
var cfg = get_config();
return require('ripple-lib').config.load(cfg);
}
var verify_limit = function (remote, src, amount, callback) {
assert(4 === arguments.length);
var _m = amount.match(/^(\d+\/...\/[^\:]+)(?::(\d+)(?:,(\d+))?)?$/);
if (!_m) { if (!_m) {
// console.log("credit_limit: parse error: %s", amount); // console.log('credit_limit: parse error: %s', amount);
return callback(new Error('parse_error'));
callback('parse_error');
} }
else
{
// console.log("_m", _m.length, _m);
// console.log("verify_limit: parsed: %s", JSON.stringify(_m, undefined, 2));
var _account_limit = _m[1];
var _quality_in = _m[2];
var _quality_out = _m[3];
var _limit = Amount.from_json(_account_limit); // console.log('_m', _m.length, _m);
// console.log('verify_limit: parsed: %s', JSON.stringify(_m, undefined, 2));
var account_limit = _m[1];
var quality_in = Number(_m[2]);
var quality_out = Number(_m[3]);
var limit = Amount.from_json(account_limit);
remote.request_ripple_balance(src, _limit.issuer().to_json(), _limit.currency().to_json(), 'CURRENT') var options = {
.once('ripple_state', function (m) { account: src,
buster.assert(m.account_limit.equals(_limit)); issuer: limit.issuer().to_json(),
buster.assert('undefined' === _quality_in || m.account_quality_in == _quality_in); currency: limit.currency().to_json(),
buster.assert('undefined' === _quality_out || m.account_quality_out == _quality_out); ledger: 'CURRENT'
};
callback(); remote.request_ripple_balance(options, function(err, m) {
}) if (err) {
.once('error', function (m) { callback(err);
// console.log("error: %s", JSON.stringify(m)); } else {
buster.assert(m.account_limit.equals(limit));
callback(m); buster.assert(isNaN(quality_in) || m.account_quality_in === quality_in);
}) buster.assert(isNaN(quality_out) || m.account_quality_out === quality_out);
.request(); callback(null);
} }
});
}; };
var credit_limits = function (remote, balances, callback) { function credit_limits(remote, balances, callback) {
assert(3 === arguments.length); assert(arguments.length === 3);
var limits = []; var limits = [ ];
for (var src in balances) { for (var src in balances) {
var values_src = balances[src]; prepare_tests(balances[src], function(amount) {
var values = 'string' === typeof values_src ? [ values_src ] : values_src; limits.push({
source: src,
for (var index in values) { amount: amount
limits.push( { "source" : src, "amount" : values[index] } ); });
} });
} }
async.every(limits, function iterator(limit, callback) {
function (limit, callback) { credit_limit(remote, limit.source, limit.amount, callback);
credit_limit(remote, limit.source, limit.amount, }
function (mismatch) { callback(!mismatch); });
}, async.some(limits, iterator, callback);
function (every) {
callback(!every);
});
}; };
var ledger_close = function (remote, callback) { function ledger_close(remote, callback) {
remote.once('ledger_closed', function (m) { callback(); }).ledger_accept(); remote.once('ledger_closed', function (m) {
} callback();
});
var payment = function (remote, src, dst, amount, callback) { remote.ledger_accept();
assert(5 === arguments.length);
remote.transaction()
.payment(src, dst, amount)
.on('proposed', function (m) {
// console.log("proposed: %s", JSON.stringify(m));
callback(m.result != 'tesSUCCESS');
})
.on('error', function (m) {
// console.log("error: %s", JSON.stringify(m));
callback(m);
})
.submit();
}; };
var payments = function (remote, balances, callback) { function payment(remote, src, dst, amount, callback) {
assert(3 === arguments.length); assert(arguments.length === 5);
var sends = []; var tx = remote.transaction();
tx.payment(src, dst, amount);
tx.once('proposed', function (m) {
// console.log('proposed: %s', JSON.stringify(m));
callback(m.engine_result === 'tesSUCCESS' ? null : new Error());
});
tx.once('error', function (m) {
// console.log('error: %s', JSON.stringify(m));
callback(m);
});
tx.submit();
};
function payments(remote, balances, callback) {
assert(arguments.length === 3);
var sends = [ ];
for (var src in balances) { for (var src in balances) {
var values_src = balances[src]; prepare_tests(balances[src], function(amount_json) {
var values = 'string' === typeof values_src ? [ values_src ] : values_src; sends.push({
source: src,
for (var index in values) { destination : Amount.from_json(amount_json).issuer().to_json(),
var amount_json = values[index]; amount : amount_json
var amount = Amount.from_json(amount_json); });
});
sends.push( { "source" : src, "destination" : amount.issuer().to_json(), "amount" : amount_json } );
}
} }
async.every(sends, function iterator(send, callback) {
function (send, callback) { payment(remote, send.source, send.destination, send.amount, callback);
payment(remote, send.source, send.destination, send.amount, }
function (mismatch) { callback(!mismatch); });
}, async.some(sends, iterator, callback);
function (every) {
callback(!every);
});
}; };
var transfer_rate = function (remote, src, billionths, callback) { function transfer_rate(remote, src, billionths, callback) {
assert(4 === arguments.length); assert(arguments.length === 4);
remote.transaction() var tx = remote.transaction();
.account_set(src) tx.account_set(src);
.transfer_rate(billionths) tx.transfer_rate(billionths);
.on('proposed', function (m) {
// console.log("proposed: %s", JSON.stringify(m));
callback(m.result != 'tesSUCCESS'); tx.once('proposed', function (m) {
}) // console.log('proposed: %s', JSON.stringify(m));
.on('error', function (m) { callback(m.engine_result === 'tesSUCCESS' ? null : new Error());
// console.log("error: %s", JSON.stringify(m)); });
callback(m); tx.once('error', function (m) {
}) // console.log('error: %s', JSON.stringify(m));
.submit(); callback(m);
});
tx.submit();
}; };
var verify_balance = function (remote, src, amount_json, callback) { function verify_balance(remote, src, amount_json, callback) {
assert(4 === arguments.length); assert(arguments.length === 4);
var amount_req = Amount.from_json(amount_json); var amount_req = Amount.from_json(amount_json);
if (amount_req.is_native()) { if (amount_req.is_native()) {
remote.request_account_balance(src, 'CURRENT') remote.request_account_balance(src, 'CURRENT', function(err, amount_act) {
.once('account_balance', function (amount_act) { if (err) {
if (!amount_act.equals(amount_req, true)) { return callback(err);
console.log("verify_balance: failed: %s / %s", }
amount_act.to_text_full(), var valid_balance = amount_act.equals(amount_req, true);
amount_req.to_text_full()); if (!valid_balance) {
} //console.log('verify_balance: failed: %s / %s',
//amount_act.to_text_full(),
//amount_req.to_text_full());
}
callback(valid_balance ? null : new Error());
});
} else {
var issuer = amount_req.issuer().to_json();
var currency = amount_req.currency().to_json();
remote.request_ripple_balance(src, issuer, currency, 'CURRENT', function(err, m) {
if (err) {
return callback(err);
}
// console.log('BALANCE: %s', JSON.stringify(m));
// console.log('account_balance: %s', m.account_balance.to_text_full());
// console.log('account_limit: %s', m.account_limit.to_text_full());
// console.log('issuer_balance: %s', m.issuer_balance.to_text_full());
// console.log('issuer_limit: %s', m.issuer_limit.to_text_full());
var account_balance = Amount.from_json(m.account_balance);
callback(!amount_act.equals(amount_req, true)); var valid_balance = account_balance.equals(amount_req, true);
})
.request();
}
else {
remote.request_ripple_balance(src, amount_req.issuer().to_json(), amount_req.currency().to_json(), 'CURRENT')
.once('ripple_state', function (m) {
// console.log("BALANCE: %s", JSON.stringify(m));
// console.log("account_balance: %s", m.account_balance.to_text_full());
// console.log("account_limit: %s", m.account_limit.to_text_full());
// console.log("issuer_balance: %s", m.issuer_balance.to_text_full());
// console.log("issuer_limit: %s", m.issuer_limit.to_text_full());
var account_balance = Amount.from_json(m.account_balance); if (!valid_balance) {
//console.log('verify_balance: failed: %s vs %s / %s: %s',
//src,
//account_balance.to_text_full(),
//amount_req.to_text_full(),
//account_balance.not_equals_why(amount_req, true));
}
if (!account_balance.equals(amount_req, true)) { callback(valid_balance ? null : new Error());
console.log("verify_balance: failed: %s vs %s / %s: %s", })
src,
account_balance.to_text_full(),
amount_req.to_text_full(),
account_balance.not_equals_why(amount_req, true));
}
callback(!account_balance.equals(amount_req, true));
})
.request();
} }
}; };
var verify_balances = function (remote, balances, callback) { function verify_balances(remote, balances, callback) {
var tests = []; var tests = [ ];
for (var src in balances) { for (var src in balances) {
var values_src = balances[src]; prepare_tests(balances[src], function(amount) {
var values = 'string' === typeof values_src ? [ values_src ] : values_src; tests.push({ source: src, amount: amount });
});
for (var index in values) {
tests.push( { "source" : src, "amount" : values[index] } );
}
} }
async.every(tests, function iterator(test, callback) {
function (check, callback) { verify_balance(remote, test.source, test.amount, callback)
verify_balance(remote, check.source, check.amount, }
function (mismatch) { callback(!mismatch); });
}, async.every(tests, iterator, callback);
function (every) {
callback(!every);
});
}; };
// --> owner: account // --> owner: account
// --> seq: sequence number of creating transaction. // --> seq: sequence number of creating transaction.
// --> taker_gets: json amount // --> taker_gets: json amount
// --> taker_pays: json amount // --> taker_pays: json amount
var verify_offer = function (remote, owner, seq, taker_pays, taker_gets, callback) { function verify_offer(remote, owner, seq, taker_pays, taker_gets, callback) {
assert(6 === arguments.length); assert(arguments.length === 6);
remote.request_ledger_entry('offer') var request = remote.request_ledger_entry('offer')
.offer_id(owner, seq) request.offer_id(owner, seq)
.on('success', function (m) { request.callback(function(err, m) {
var wrong = !Amount.from_json(m.node.TakerGets).equals(Amount.from_json(taker_gets), true) var wrong = err
|| !Amount.from_json(m.node.TakerPays).equals(Amount.from_json(taker_pays), true); || !Amount.from_json(m.node.TakerGets).equals(Amount.from_json(taker_gets), true)
|| !Amount.from_json(m.node.TakerPays).equals(Amount.from_json(taker_pays), true);
if (wrong) if (wrong) {
console.log("verify_offer: failed: %s", JSON.stringify(m)); //console.log('verify_offer: failed: %s', JSON.stringify(m));
}
callback(wrong); callback(wrong ? (err || new Error()) : null);
}) });
.request();
}; };
var verify_offer_not_found = function (remote, owner, seq, callback) { function verify_offer_not_found(remote, owner, seq, callback) {
assert(4 === arguments.length); assert(arguments.length === 4);
remote.request_ledger_entry('offer') var request = remote.request_ledger_entry('offer');
.offer_id(owner, seq)
.on('success', function (m) {
console.log("verify_offer_not_found: found offer: %s", JSON.stringify(m));
callback('entryFound'); request.offer_id(owner, seq);
})
.on('error', function (m) {
// console.log("verify_offer_not_found: success: %s", JSON.stringify(m));
callback('remoteError' !== m.error request.once('success', function (m) {
|| 'entryNotFound' !== m.remote.error); //console.log('verify_offer_not_found: found offer: %s', JSON.stringify(m));
}) callback(new Error('entryFound'));
.request(); });
request.once('error', function (m) {
// console.log('verify_offer_not_found: success: %s', JSON.stringify(m));
var is_not_found = m.error === 'remoteError' && m.remote.error === 'entryNotFound';
if (is_not_found) {
callback(null);
} else {
callback(new Error());
}
});
request.request();
}; };
var verify_owner_count = function (remote, account, value, callback) { function verify_owner_count(remote, account, count, callback) {
assert(4 === arguments.length); assert(arguments.length === 4);
var options = { account: account, ledger: 'CURRENT' };
remote.request_owner_count(account, 'CURRENT') remote.request_owner_count(options, function(err, owner_count) {
.once('owner_count', function (owner_count) { //console.log('owner_count: %s/%d', owner_count, value);
if (owner_count !== value) callback(owner_count === count ? null : new Error());
console.log("owner_count: %s/%d", owner_count, value); });
callback(owner_count !== value);
})
.request();
}; };
var verify_owner_counts = function (remote, counts, callback) { function verify_owner_counts(remote, counts, callback) {
var tests = []; var tests = prepare_tests(counts, function(account) {
return { account: account, count: counts[account] };
});
for (var src in counts) { function iterator(test, callback) {
tests.push( { "source" : src, "count" : counts[src] } ); verify_owner_count(remote, test.account, test.count, callback)
} }
async.every(tests, async.every(tests, iterator, callback);
function (check, callback) {
verify_owner_count(remote, check.source, check.count,
function (mismatch) { callback(!mismatch); });
},
function (every) {
callback(!every);
});
}; };
exports.account_dump = account_dump; exports.account_dump = account_dump;