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,8 +19,7 @@ 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([
@@ -30,10 +29,10 @@ buster.testCase("AccountSet", {
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();
}, },
@@ -57,10 +56,10 @@ buster.testCase("AccountSet", {
self.remote.transaction() self.remote.transaction()
.account_set("root") .account_set("root")
.set_flags('OptionalDestTag') .set_flags('OptionalDestTag')
.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();
}, },
@@ -84,8 +83,7 @@ buster.testCase("AccountSet", {
}); });
}, },
"RequireAuth" : "RequireAuth" : function (done) {
function (done) {
var self = this; var self = this;
async.waterfall([ async.waterfall([
@@ -95,10 +93,10 @@ buster.testCase("AccountSet", {
self.remote.transaction() self.remote.transaction()
.account_set("root") .account_set("root")
.set_flags('RequireAuth') .set_flags('RequireAuth')
.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();
}, },
@@ -122,10 +120,10 @@ buster.testCase("AccountSet", {
self.remote.transaction() self.remote.transaction()
.account_set("root") .account_set("root")
.set_flags('OptionalAuth') .set_flags('OptionalAuth')
.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();
}, },
@@ -150,8 +148,7 @@ buster.testCase("AccountSet", {
}); });
}, },
"DisallowXRP" : "DisallowXRP" : function (done) {
function (done) {
var self = this; var self = this;
async.waterfall([ async.waterfall([
@@ -161,10 +158,10 @@ buster.testCase("AccountSet", {
self.remote.transaction() self.remote.transaction()
.account_set("root") .account_set("root")
.set_flags('DisallowXRP') .set_flags('DisallowXRP')
.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();
}, },
@@ -188,10 +185,10 @@ buster.testCase("AccountSet", {
self.remote.transaction() self.remote.transaction()
.account_set("root") .account_set("root")
.set_flags('AllowXRP') .set_flags('AllowXRP')
.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();
}, },

View File

@@ -28,8 +28,7 @@ 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;

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();
@@ -876,14 +864,12 @@ buster.testCase("Offer tests", {
], 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,10 +1339,8 @@ 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;
@@ -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,62 +168,63 @@ buster.testCase("Remote functions", {
.request(); .request();
}, },
"create account" : "create account" : function (done) {
function (done) { var self = this;
var root_id = this.remote.account('root')._account_id;
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('proposed', function(res) {
//console.log('Submitted', res);
self.remote.ledger_accept();
})
.on('success', function (r) { .on('success', function (r) {
//console.log("account_root: %s", JSON.stringify(r)); //console.log("account_root: %s", JSON.stringify(r));
// Need to verify account and balance. // Need to verify account and balance.
buster.assert(true); buster.assert(true);
done(); done();
}) })
.on('error', function(m) { .on('error', function(m) {
// console.log("error: %s", m); console.log('Error');
console.log("error: %s", m);
buster.assert(false); buster.assert(false);
}) })
.submit(); .submit();
}, },
"create account final" : "create account final" : function (done) {
function (done) {
var self = this; var self = this;
var got_proposed; var got_proposed;
var got_success; var got_success;
var root_id = this.remote.account('root')._account_id;
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 (m) { .on('proposed', function() {
// console.log("proposed: %s", JSON.stringify(m));
// buster.assert.equals(m.result, 'terNO_DST_INSUF_XRP');
buster.assert.equals(m.result, 'tesSUCCESS');
got_proposed = true; got_proposed = true;
self.remote.ledger_accept(); self.remote.ledger_accept();
}) })
.on('status', function (s) { .on('submitted', function (m) {
// console.log("status: %s", JSON.stringify(s)); // console.log("proposed: %s", JSON.stringify(m));
// buster.assert.equals(m.result, 'terNO_DST_INSUF_XRP');
buster.assert.equals(m.engine_result, 'tesSUCCESS');
}) })
.submit(); .submit();
}, },

View File

@@ -42,80 +42,43 @@ buster.testCase("Sending", {
//'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(),
"send XRP to non-existent account with insufficent fee" : "send XRP to non-existent account with insufficent fee" : function (done) {
function (done) {
var self = this; var self = this;
var ledgers = 20; var ledgers = 20;
var got_proposed; var got_proposed;
this.remote.transaction() this.remote.transaction()
.payment('root', 'alice', "1") .payment('root', 'alice', "1")
.on('success', function (r) { .once('submitted', function (m) {
// Transaction sent.
// console.log("success: %s", JSON.stringify(r));
})
.on('pending', function() {
// Moving ledgers along.
// console.log("missing: %d", ledgers);
ledgers -= 1;
if (ledgers) {
self.remote.ledger_accept();
}
else {
buster.assert(false, "Final never received.");
done();
}
})
.on('lost', function () {
// Transaction did not make it in.
// console.log("lost");
buster.assert(true);
done();
})
.on('proposed', function (m) {
// Transaction got an error. // Transaction got an error.
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
buster.assert.equals(m.engine_result, 'tecNO_DST_INSUF_XRP');
buster.assert.equals(m.result, 'tecNO_DST_INSUF_XRP');
got_proposed = true; got_proposed = true;
self.remote.ledger_accept(); // Move it along. self.remote.ledger_accept(); // Move it along.
}) })
.on('final', function (m) { .once('final', function (m) {
// console.log("final: %s", JSON.stringify(m, undefined, 2)); // console.log("final: %s", JSON.stringify(m, undefined, 2));
buster.assert.equals(m.engine_result, 'tecNO_DST_INSUF_XRP');
buster.assert.equals(m.metadata.TransactionResult, 'tecNO_DST_INSUF_XRP');
done(); done();
}) })
.on('error', function(m) {
// console.log("error: %s", m);
buster.assert(false);
})
.submit(); .submit();
}, },
// Also test transaction becomes lost after tecNO_DST. // Also test transaction becomes lost after tecNO_DST.
"credit_limit to non-existent account = tecNO_DST" : "credit_limit to non-existent account = tecNO_DST" : function (done) {
function (done) {
this.remote.transaction() this.remote.transaction()
.ripple_line_set("root", "100/USD/alice") .ripple_line_set("root", "100/USD/alice")
.on('proposed', function (m) { .once('submitted', function (m) {
//console.log("proposed: %s", JSON.stringify(m)); //console.log("proposed: %s", JSON.stringify(m));
buster.assert.equals(m.result, 'tecNO_DST'); buster.assert.equals(m.engine_result, 'tecNO_DST');
done(); done();
}) })
.submit(); .submit();
}, },
"credit_limit" : "credit_limit" : function (done) {
function (done) {
var self = this; var self = this;
async.waterfall([ async.waterfall([
@@ -183,10 +146,9 @@ buster.testCase("Sending", {
function (callback) { function (callback) {
self.remote.transaction() self.remote.transaction()
.ripple_line_set("alice", "-1/USD/mtgox") .ripple_line_set("alice", "-1/USD/mtgox")
.on('proposed', function (m) { .once('submitted', function (m) {
buster.assert.equals('temBAD_LIMIT', m.result); buster.assert.equals('temBAD_LIMIT', m.engine_result);
callback();
callback('temBAD_LIMIT' !== m.result);
}) })
.submit(); .submit();
}, },
@@ -282,8 +244,7 @@ buster.testCase("Sending future", {
// 'setUp' : testutils.build_setup({ verbose : true }), // 'setUp' : testutils.build_setup({ verbose : true }),
'tearDown' : testutils.build_teardown(), 'tearDown' : testutils.build_teardown(),
"direct ripple" : "direct ripple" : function (done) {
function (done) {
var self = this; var self = this;
// self.remote.set_trace(); // self.remote.set_trace();
@@ -309,12 +270,12 @@ buster.testCase("Sending future", {
self.remote.transaction() self.remote.transaction()
.payment('alice', 'bob', "24/USD/alice") .payment('alice', 'bob', "24/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.engine_result !== 'tesSUCCESS');
}) })
.once('final', function (m) { .once('final', function (m) {
buster.assert(m.result !== 'tesSUCCESS'); buster.assert(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
@@ -335,12 +296,12 @@ buster.testCase("Sending future", {
self.remote.transaction() self.remote.transaction()
.payment('alice', 'bob', "33/USD/bob") .payment('alice', 'bob', "33/USD/bob")
.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');
}) })
.once('final', function (m) { .once('final', function (m) {
buster.assert(m.result !== 'tesSUCCESS'); buster.assert(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
@@ -361,12 +322,12 @@ buster.testCase("Sending future", {
self.remote.transaction() self.remote.transaction()
.payment('bob', 'alice', "90/USD/bob") .payment('bob', 'alice', "90/USD/bob")
.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');
}) })
.once('final', function (m) { .once('final', function (m) {
buster.assert(m.result !== 'tesSUCCESS'); buster.assert(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
@@ -386,12 +347,12 @@ buster.testCase("Sending future", {
self.remote.transaction() self.remote.transaction()
.payment('alice', 'bob', "733/USD/bob") .payment('alice', 'bob', "733/USD/bob")
.once('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("submitted: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.once('final', function (m) { .once('final', function (m) {
buster.assert(m.result !== 'tesSUCCESS'); buster.assert(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
@@ -411,12 +372,12 @@ buster.testCase("Sending future", {
self.remote.transaction() self.remote.transaction()
.payment('bob', 'alice', "1300/USD/bob") .payment('bob', 'alice', "1300/USD/bob")
.once('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("submitted: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.once('final', function (m) { .once('final', function (m) {
buster.assert(m.result !== 'tesSUCCESS'); buster.assert(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
@@ -437,9 +398,9 @@ buster.testCase("Sending future", {
self.remote.transaction() self.remote.transaction()
.payment('bob', 'alice', "1/USD/bob") .payment('bob', 'alice', "1/USD/bob")
.once('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("submitted: %s", JSON.stringify(m));
callback(m.result !== 'tecPATH_DRY'); callback(m.engine_result !== 'tecPATH_DRY');
}) })
.submit(); .submit();
}, },
@@ -496,8 +457,7 @@ buster.testCase("Gateway", {
// 'setUp' : testutils.build_setup({ verbose: true }), // 'setUp' : testutils.build_setup({ verbose: true }),
'tearDown' : testutils.build_teardown(), 'tearDown' : testutils.build_teardown(),
"customer to customer with and without transfer fee" : "customer to customer with and without transfer fee" : function (done) {
function (done) {
var self = this; var self = this;
// self.remote.set_trace(); // self.remote.set_trace();
@@ -545,7 +505,7 @@ buster.testCase("Gateway", {
.on('proposed', function (m) { .on('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();
}, },
@@ -568,7 +528,7 @@ buster.testCase("Gateway", {
.transfer_rate(1e9*1.1) .transfer_rate(1e9*1.1)
.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();
}, },
@@ -581,7 +541,7 @@ buster.testCase("Gateway", {
.on('proposed', function (m) { .on('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();
}, },
@@ -602,8 +562,7 @@ buster.testCase("Gateway", {
}); });
}, },
"customer to customer, transfer fee, default path with and without specific issuer for Amount and SendMax" : "customer to customer, transfer fee, default path with and without specific issuer for Amount and SendMax" : function (done) {
function (done) {
var self = this; var self = this;
// self.remote.set_trace(); // self.remote.set_trace();
@@ -620,9 +579,9 @@ buster.testCase("Gateway", {
self.remote.transaction() self.remote.transaction()
.account_set("mtgox") .account_set("mtgox")
.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("submitted: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
@@ -660,10 +619,10 @@ buster.testCase("Gateway", {
self.remote.transaction() self.remote.transaction()
.payment("alice", "bob", "1/AUD/mtgox") .payment("alice", "bob", "1/AUD/mtgox")
.send_max("1.1/AUD/mtgox") .send_max("1.1/AUD/mtgox")
.on('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("submitted: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
@@ -683,10 +642,10 @@ buster.testCase("Gateway", {
self.remote.transaction() self.remote.transaction()
.payment("alice", "bob", "1/AUD/bob") .payment("alice", "bob", "1/AUD/bob")
.send_max("1.1/AUD/mtgox") .send_max("1.1/AUD/mtgox")
.on('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("submitted: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
@@ -706,10 +665,10 @@ buster.testCase("Gateway", {
self.remote.transaction() self.remote.transaction()
.payment("alice", "bob", "1/AUD/mtgox") .payment("alice", "bob", "1/AUD/mtgox")
.send_max("1.1/AUD/alice") .send_max("1.1/AUD/alice")
.on('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("submitted: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS'); callback(m.engine_result !== 'tesSUCCESS');
}) })
.submit(); .submit();
}, },
@@ -730,10 +689,10 @@ buster.testCase("Gateway", {
self.remote.transaction() self.remote.transaction()
.payment("alice", "bob", "1/AUD/bob") .payment("alice", "bob", "1/AUD/bob")
.send_max("1.1/AUD/alice") .send_max("1.1/AUD/alice")
.on('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("submitted: %s", JSON.stringify(m));
callback(m.result !== 'terNO_LINE'); callback(m.engine_result !== 'terNO_LINE');
}) })
.submit(); .submit();
}, },
@@ -753,8 +712,7 @@ buster.testCase("Gateway", {
}); });
}, },
"subscribe test: customer to customer with and without transfer fee" : "subscribe test: customer to customer with and without transfer fee" : function (done) {
function (done) {
var self = this; var self = this;
// self.remote.set_trace(); // self.remote.set_trace();
@@ -805,7 +763,7 @@ buster.testCase("Gateway", {
.on('proposed', function (m) { .on('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();
}, },
@@ -829,7 +787,7 @@ buster.testCase("Gateway", {
.transfer_rate(1e9*1.1) .transfer_rate(1e9*1.1)
.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();
}, },
@@ -843,7 +801,7 @@ buster.testCase("Gateway", {
.on('proposed', function (m) { .on('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();
}, },
@@ -896,8 +854,7 @@ buster.testCase("Gateway", {
}); });
}, },
"subscribe test: customer to customer with and without transfer fee: transaction retry logic" : "subscribe test: customer to customer with and without transfer fee: transaction retry logic" : function (done) {
function (done) {
var self = this; var self = this;
// self.remote.set_trace(); // self.remote.set_trace();
@@ -945,7 +902,7 @@ buster.testCase("Gateway", {
.on('proposed', function (m) { .on('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();
}, },
@@ -968,7 +925,7 @@ buster.testCase("Gateway", {
// .transfer_rate(1e9*1.1) // .transfer_rate(1e9*1.1)
// .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();
// }, // },
@@ -981,7 +938,7 @@ buster.testCase("Gateway", {
.on('proposed', function (m) { .on('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();
}, },
@@ -1051,8 +1008,7 @@ buster.testCase("Indirect ripple", {
// 'setUp' : testutils.build_setup({ verbose: true }), // 'setUp' : testutils.build_setup({ verbose: true }),
'tearDown' : testutils.build_teardown(), 'tearDown' : testutils.build_teardown(),
"indirect ripple" : "indirect ripple" : function (done) {
function (done) {
var self = this; var self = this;
// self.remote.set_trace(); // self.remote.set_trace();
@@ -1097,10 +1053,9 @@ buster.testCase("Indirect ripple", {
self.remote.transaction() self.remote.transaction()
.payment("alice", "mtgox", "100/USD/mtgox") .payment("alice", "mtgox", "100/USD/mtgox")
.on('proposed', function (m) { .once('submitted', function (m) {
// console.log("proposed: %s", JSON.stringify(m)); // console.log("proposed: %s", JSON.stringify(m));
callback(m.engine_result !== 'tecPATH_PARTIAL');
callback(m.result !== 'tecPATH_PARTIAL');
}) })
.submit(); .submit();
}, },
@@ -1109,10 +1064,9 @@ buster.testCase("Indirect ripple", {
self.remote.transaction() self.remote.transaction()
.payment("alice", "bob", "100/USD/mtgox") .payment("alice", "bob", "100/USD/mtgox")
.on('proposed', function (m) { .once('submitted', function (m) {
//console.log("proposed: %s", JSON.stringify(m)); //console.log("proposed: %s", JSON.stringify(m));
callback(m.engine_result !== 'tecPATH_PARTIAL');
callback(m.result !== 'tecPATH_PARTIAL');
}) })
.submit(); .submit();
}, },
@@ -1122,8 +1076,7 @@ buster.testCase("Indirect ripple", {
}); });
}, },
"indirect ripple with path" : "indirect ripple with path" : function (done) {
function (done) {
var self = this; var self = this;
async.waterfall([ async.waterfall([
@@ -1160,7 +1113,7 @@ buster.testCase("Indirect ripple", {
.on('proposed', function (m) { .on('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();
}, },
@@ -1180,8 +1133,7 @@ buster.testCase("Indirect ripple", {
}); });
}, },
"indirect ripple with multi path" : "indirect ripple with multi path" : function (done) {
function (done) {
var self = this; var self = this;
async.waterfall([ async.waterfall([
@@ -1220,7 +1172,7 @@ buster.testCase("Indirect ripple", {
.on('proposed', function (m) { .on('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();
}, },
@@ -1242,8 +1194,7 @@ buster.testCase("Indirect ripple", {
}); });
}, },
"indirect ripple with path and transfer fee" : "indirect ripple with path and transfer fee" : function (done) {
function (done) {
var self = this; var self = this;
async.waterfall([ async.waterfall([
@@ -1288,7 +1239,7 @@ buster.testCase("Indirect ripple", {
.on('proposed', function (m) { .on('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();
}, },

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
.request_ledger_entry('account_root')
.ledger_hash(remote.ledger_hash())
.account_root("root")
.on('success', function (r) {
//console.log("account_root: %s", JSON.stringify(r, undefined, 2));
var request = remote.request_ledger_entry('account_root');
request.ledger_hash(remote.ledger_hash());
request.account_root('root');
request.callback(function(err, r) {
buster.isNull(err);
if (err) {
//console.log('error: %s', m);
callback(err);
} else {
//console.log('account_root: %s', JSON.stringify(r, undefined, 2));
callback(); callback();
}) }
.on('error', function(m) {
console.log("error: %s", m);
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,10 +78,10 @@ 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) {
@@ -74,56 +89,58 @@ var build_setup = function (opts, host) {
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,
config.servers[host]);
data.server = Server
.from_config(host, server_config,
!!opts.verbose_server)
.on('started', callback)
.on('exited', function () {
// If know the remote, tell it server is gone.
if (self.remote)
self.remote.server_fatal();
})
.start();
},
function connectWebsocketStep(callback) {
self.remote = data.remote =
Remote
.from_config(host, !!opts.verbose_ws)
.once('ledger_closed', callback)
.connect();
} }
], done);
var server_config = extend({}, config.default_server_config, config.servers[host]);
data.server = Server.from_config(host, server_config, !!opts.verbose_server);
data.server.once('started', callback);
data.server.once('exited', function () {
// If know the remote, tell it server is gone.
if (self.remote) {
self.remote.server_fatal();
}
});
data.server.start();
},
function connect_websocket(callback) {
self.remote = data.remote = Remote.from_config(host, !!opts.verbose_ws);
self.remote.once('ledger_closed', callback);
self.remote.connect();
}
];
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 data.remote.once('error', function (m) {
.on('disconnected', callback) console.log('server error: ', m);
.on('error', function (m) {
console.log("server error: ", m);
}) })
.connect(false); data.remote.connect(false);
}, },
function stopServerStep(callback) {
if (opts.no_server)
{
return callback();
}
data.server function stop_server(callback) {
.on('stopped', callback) if (opts.no_server) {
.stop(); callback();
} else {
data.server.once('stopped', callback)
data.server.stop();
} }
], done); }
}; ];
async.series(series, done);
}; };
var create_accounts = function (remote, src, amount, accounts, callback) { return teardown;
assert(5 === arguments.length); };
function create_accounts(remote, src, amount, accounts, callback) {
assert(arguments.length === 5);
remote.set_account_seq(src, 1); remote.set_account_seq(src, 1);
@@ -174,336 +191,313 @@ 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));
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); callback(m);
}) });
.submit();
tx.submit();
}, callback); }, 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));
tx.ripple_line_set(src, account_limit, quality_in, quality_out)
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); callback(m);
}) });
.submit();
} 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
// 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+))?)?$/); 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();
})
.once('error', function (m) {
// console.log("error: %s", JSON.stringify(m));
callback(m);
})
.request();
}
}; };
var credit_limits = function (remote, balances, callback) { remote.request_ripple_balance(options, function(err, m) {
assert(3 === arguments.length); if (err) {
callback(err);
} else {
buster.assert(m.account_limit.equals(limit));
buster.assert(isNaN(quality_in) || m.account_quality_in === quality_in);
buster.assert(isNaN(quality_out) || m.account_quality_out === quality_out);
callback(null);
}
});
};
function credit_limits(remote, balances, callback) {
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 (limit, callback) {
credit_limit(remote, limit.source, limit.amount,
function (mismatch) { callback(!mismatch); });
},
function (every) {
callback(!every);
}); });
};
var ledger_close = function (remote, callback) {
remote.once('ledger_closed', function (m) { callback(); }).ledger_accept();
} }
var payment = function (remote, src, dst, amount, callback) { function iterator(limit, callback) {
assert(5 === arguments.length); credit_limit(remote, limit.source, limit.amount, callback);
}
remote.transaction() async.some(limits, iterator, callback);
.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 ledger_close(remote, callback) {
assert(3 === arguments.length); remote.once('ledger_closed', function (m) {
callback();
});
remote.ledger_accept();
};
function payment(remote, src, dst, amount, callback) {
assert(arguments.length === 5);
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 = [ ]; 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 (send, callback) {
payment(remote, send.source, send.destination, send.amount,
function (mismatch) { callback(!mismatch); });
},
function (every) {
callback(!every);
}); });
});
}
function iterator(send, callback) {
payment(remote, send.source, send.destination, send.amount, callback);
}
async.some(sends, iterator, callback);
}; };
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)); });
tx.once('error', function (m) {
// console.log('error: %s', JSON.stringify(m));
callback(m); callback(m);
}) });
.submit();
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(),
amount_req.to_text_full());
} }
var valid_balance = amount_act.equals(amount_req, true);
callback(!amount_act.equals(amount_req, true)); if (!valid_balance) {
}) //console.log('verify_balance: failed: %s / %s',
.request(); //amount_act.to_text_full(),
//amount_req.to_text_full());
} }
else { callback(valid_balance ? null : new Error());
remote.request_ripple_balance(src, amount_req.issuer().to_json(), amount_req.currency().to_json(), 'CURRENT') });
.once('ripple_state', function (m) { } else {
// console.log("BALANCE: %s", JSON.stringify(m)); var issuer = amount_req.issuer().to_json();
// console.log("account_balance: %s", m.account_balance.to_text_full()); var currency = amount_req.currency().to_json();
// console.log("account_limit: %s", m.account_limit.to_text_full()); remote.request_ripple_balance(src, issuer, currency, 'CURRENT', function(err, m) {
// console.log("issuer_balance: %s", m.issuer_balance.to_text_full()); if (err) {
// console.log("issuer_limit: %s", m.issuer_limit.to_text_full()); 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); var account_balance = Amount.from_json(m.account_balance);
if (!account_balance.equals(amount_req, true)) { var valid_balance = account_balance.equals(amount_req, true);
console.log("verify_balance: failed: %s vs %s / %s: %s",
src, if (!valid_balance) {
account_balance.to_text_full(), //console.log('verify_balance: failed: %s vs %s / %s: %s',
amount_req.to_text_full(), //src,
account_balance.not_equals_why(amount_req, true)); //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)); callback(valid_balance ? null : new Error());
}) })
.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 (check, callback) {
verify_balance(remote, check.source, check.amount,
function (mismatch) { callback(!mismatch); });
},
function (every) {
callback(!every);
}); });
}
function iterator(test, callback) {
verify_balance(remote, test.source, test.amount, callback)
}
async.every(tests, iterator, callback);
}; };
// --> 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.TakerGets).equals(Amount.from_json(taker_gets), true)
|| !Amount.from_json(m.node.TakerPays).equals(Amount.from_json(taker_pays), 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);
})
.request();
};
var verify_offer_not_found = function (remote, owner, seq, callback) {
assert(4 === arguments.length);
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');
})
.on('error', function (m) {
// console.log("verify_offer_not_found: success: %s", JSON.stringify(m));
callback('remoteError' !== m.error
|| 'entryNotFound' !== m.remote.error);
})
.request();
};
var verify_owner_count = function (remote, account, value, callback) {
assert(4 === arguments.length);
remote.request_owner_count(account, 'CURRENT')
.once('owner_count', function (owner_count) {
if (owner_count !== value)
console.log("owner_count: %s/%d", owner_count, value);
callback(owner_count !== value);
})
.request();
};
var verify_owner_counts = function (remote, counts, callback) {
var tests = [];
for (var src in counts) {
tests.push( { "source" : src, "count" : counts[src] } );
} }
async.every(tests, callback(wrong ? (err || new Error()) : null);
function (check, callback) {
verify_owner_count(remote, check.source, check.count,
function (mismatch) { callback(!mismatch); });
},
function (every) {
callback(!every);
}); });
}; };
function verify_offer_not_found(remote, owner, seq, callback) {
assert(arguments.length === 4);
var request = remote.request_ledger_entry('offer');
request.offer_id(owner, seq);
request.once('success', function (m) {
//console.log('verify_offer_not_found: found offer: %s', JSON.stringify(m));
callback(new Error('entryFound'));
});
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();
};
function verify_owner_count(remote, account, count, callback) {
assert(arguments.length === 4);
var options = { account: account, ledger: 'CURRENT' };
remote.request_owner_count(options, function(err, owner_count) {
//console.log('owner_count: %s/%d', owner_count, value);
callback(owner_count === count ? null : new Error());
});
};
function verify_owner_counts(remote, counts, callback) {
var tests = prepare_tests(counts, function(account) {
return { account: account, count: counts[account] };
});
function iterator(test, callback) {
verify_owner_count(remote, test.account, test.count, callback)
}
async.every(tests, iterator, callback);
};
exports.account_dump = account_dump; exports.account_dump = account_dump;
exports.build_setup = build_setup; exports.build_setup = build_setup;
exports.build_teardown = build_teardown; exports.build_teardown = build_teardown;