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

View File

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

View File

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

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

@@ -31,4 +31,4 @@ buster.testCase("Standalone server startup", {
}
});
// vim:sw=2:sts=2:ts=8:et
// vim:sw=2:sts=2:ts=8:et

View File

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