UT add testing for ledger_closed and update ledger_current.

This commit is contained in:
Arthur Britto
2012-09-26 14:08:56 -07:00
parent 4cec959e78
commit 8993c8f268
2 changed files with 70 additions and 6 deletions

View File

@@ -82,7 +82,7 @@ Remote.method('connect_helper', function() {
self.done(ws.readyState);
};
// XXX Why doesn't onmessage work?
// Node's ws module doesn't pass arguments to onmessage.
ws.on('message', function(json, flags) {
var message = JSON.parse(json);
// console.log("message: %s", json);
@@ -167,12 +167,16 @@ Remote.method('request', function(command, done) {
ws.send(JSON.stringify(command));
});
// Get the current ledger entry (may be live or not).
Remote.method('ledger_closed', function(done) {
this.request({ 'command' : 'ledger_closed' }, done);
});
// Get the current proposed ledger entry. May be closed (and revised) at any time (even before returning).
// Only for use by unit tests.
Remote.method('ledger_current', function(done) {
this.request({ 'command' : 'ledger_current' }, done);
});
// Submit a json transaction.
// done(value)
// <-> value: { 'status', status, 'result' : result, ... }

View File

@@ -92,15 +92,75 @@ buster.testCase("Websocket commands", {
});
},
"ledger_current" :
'ledger_closed' :
function(done) {
alpha.ledger_closed(function (r) {
console.log(r);
buster.assert(r.ledger === 1);
done();
});
},
'ledger_current' :
function(done) {
alpha.ledger_current(function (r) {
console.log(r);
buster.assert(r.ledger === 2);
buster.assert.equals(r.ledger_index, 2);
done();
});
}
},
'ledger_closed' :
function(done) {
alpha.ledger_closed(function (r) {
console.log("result: %s", JSON.stringify(r));
buster.assert.equals(r.ledger_index, 1);
done();
});
},
});
buster.testCase("// Work in progress", {
'setUp' :
function(done) {
server.start("alpha",
function(e) {
buster.refute(e);
alpha = remote.remoteConfig(config, "alpha");
alpha.connect(function(stat) {
buster.assert(1 == stat); // OPEN
done();
}, serverDelay);
});
},
'tearDown' :
function(done) {
alpha.disconnect(function(stat) {
buster.assert(3 == stat); // CLOSED
server.stop("alpha", function(e) {
buster.refute(e);
done();
});
});
},
'ledger_closed' :
function(done) {
alpha.ledger_closed(function (r) {
console.log("result: %s", JSON.stringify(r));
buster.assert.equals(r.ledger_index, 1);
done();
});
},
});
// vim:ts=4