Skip to content

Instantly share code, notes, and snippets.

@emschwartz
Created May 6, 2014 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emschwartz/daae091982c8d8db06a0 to your computer and use it in GitHub Desktop.
Save emschwartz/daae091982c8d8db06a0 to your computer and use it in GitHub Desktop.
var test_transaction = new ripple.Transaction(),
client_resource_id = 'ebb9d857-fc71-440f-8b0a-f1ea3535986a';
test_transaction.payment({
from: 'rLpq5RcRzA8FU1yUqEPW4xfsdwon7casuM',
to: 'rLpq5RcRzA8FU1yUqEPW4xfsdwon7casuM',
amount: '10XRP'
});
var states = ['submitted', 'pending', 'validated'];
// Mock the submit function with one that goes through the normal states
// a transaction goes through after submission
test_transaction.submit = function(callback) {
var self = this;
// Save is also emitted when the transaction is signed
self.emit('save');
states.forEach(function(state){
self.setState(state);
});
self.remote.account(account).submit(self);
};
test_transaction.on('save', function(){
console.log('save emitted');
});
// Count the number of times saveTransaction is called and
// call done when it has been called once per state change
var times_called = 0;
function saveTransaction(transaction_data, callback) {
console.log(transaction_data.transaction.state);
if (transaction_data.transaction.state === states[times_called]) {
times_called++;
}
if (times_called === states.length + 1) {
done();
}
}
var dbinterface = {
getTransaction: function(params, callback) {
callback();
},
saveTransaction: saveTransaction
};
var remote = new ripple.Remote({
servers: [],
storage: dbinterface
});
remote._getServer = function() {
return {
_lastLedgerClose: Date.now() - 1 // Considered connected
};
};
remote.connect = function(){};
test_transaction.remote = remote;
transactions.submit({
remote: remote,
dbinterface: dbinterface
}, {
account: 'rLpq5RcRzA8FU1yUqEPW4xfsdwon7casuM',
transaction: test_transaction,
client_resource_id: client_resource_id
}, {
json: function() {}
}, function(err, res){
if (err) {
console.log(err, err.stack);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment