add BCH createTX tests
This commit is contained in:
parent
d8e6964587
commit
5186392558
|
@ -1929,6 +1929,7 @@ WalletService.prototype._canCreateTx = function(cb) {
|
|||
};
|
||||
|
||||
WalletService.prototype._validateOutputs = function(opts, wallet, cb) {
|
||||
var A = Bitcore_[wallet.coin].Address;
|
||||
var dustThreshold = Math.max(Defaults.MIN_OUTPUT_AMOUNT, Bitcore_[wallet.coin].Transaction.DUST_AMOUNT);
|
||||
|
||||
if (_.isEmpty(opts.outputs)) return new ClientError('No outputs were specified');
|
||||
|
@ -1943,7 +1944,7 @@ WalletService.prototype._validateOutputs = function(opts, wallet, cb) {
|
|||
|
||||
var toAddress = {};
|
||||
try {
|
||||
toAddress = new Bitcore.Address(output.toAddress);
|
||||
toAddress = new A(output.toAddress);
|
||||
} catch (ex) {
|
||||
return Errors.INVALID_ADDRESS;
|
||||
}
|
||||
|
|
|
@ -277,6 +277,8 @@ helpers.stubUtxos = function(server, wallet, amounts, opts, cb) {
|
|||
|
||||
if (!helpers._utxos) helpers._utxos = {};
|
||||
|
||||
var S = Bitcore_[wallet.coin].Script;
|
||||
|
||||
async.waterfall([
|
||||
|
||||
function(next) {
|
||||
|
@ -298,10 +300,10 @@ helpers.stubUtxos = function(server, wallet, amounts, opts, cb) {
|
|||
var scriptPubKey;
|
||||
switch (wallet.addressType) {
|
||||
case Constants.SCRIPT_TYPES.P2SH:
|
||||
scriptPubKey = Bitcore.Script.buildMultisigOut(address.publicKeys, wallet.m).toScriptHashOut();
|
||||
scriptPubKey = S.buildMultisigOut(address.publicKeys, wallet.m).toScriptHashOut();
|
||||
break;
|
||||
case Constants.SCRIPT_TYPES.P2PKH:
|
||||
scriptPubKey = Bitcore.Script.buildPublicKeyHashOut(address.address);
|
||||
scriptPubKey = S.buildPublicKeyHashOut(address.address);
|
||||
break;
|
||||
}
|
||||
should.exist(scriptPubKey);
|
||||
|
|
|
@ -11,6 +11,12 @@ log.debug = log.verbose;
|
|||
log.level = 'info';
|
||||
|
||||
var Bitcore = require('bitcore-lib');
|
||||
var Bitcore_ = {
|
||||
btc: Bitcore,
|
||||
bch: require('bitcore-lib-cash')
|
||||
};
|
||||
|
||||
|
||||
|
||||
var Common = require('../../lib/common');
|
||||
var Utils = Common.Utils;
|
||||
|
@ -2518,22 +2524,39 @@ describe('Wallet service', function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe('#createTx', function() {
|
||||
describe('Tx proposal creation & publishing', function() {
|
||||
var addrMap = {
|
||||
btc: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
bch: 'CPrtPWbp8cCftTQu5fzuLG5zPJNDHMMf8X',
|
||||
}
|
||||
|
||||
_.each(['bch', 'btc'], function(coin) {
|
||||
|
||||
describe('#createTx ' + coin, function() {
|
||||
var addressStr;
|
||||
before(function() {
|
||||
addressStr = addrMap[coin];
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe('Tx proposal creation & publishing ' + coin, function() {
|
||||
var server, wallet;
|
||||
beforeEach(function(done) {
|
||||
helpers.createAndJoinWallet(1, 1, function(s, w) {
|
||||
helpers.createAndJoinWallet(1, 1, {
|
||||
coin: coin,
|
||||
}, function(s, w) {
|
||||
server = s;
|
||||
wallet = w;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should create a tx', function(done) {
|
||||
helpers.stubUtxos(server, wallet, [1, 2], function() {
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: 0.8 * 1e8,
|
||||
}],
|
||||
message: 'some message',
|
||||
|
@ -2616,7 +2639,7 @@ describe('Wallet service', function() {
|
|||
it('should fail to create tx for invalid amount', function(done) {
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: 0,
|
||||
}],
|
||||
feePerKb: 100e2,
|
||||
|
@ -2632,7 +2655,7 @@ describe('Wallet service', function() {
|
|||
helpers.stubUtxos(server, wallet, 2, function() {
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: 1e8,
|
||||
}],
|
||||
feeLevel: 'normal',
|
||||
|
@ -2653,7 +2676,7 @@ describe('Wallet service', function() {
|
|||
var inputs = [utxos[0], utxos[2]];
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: 2.5e8,
|
||||
}],
|
||||
feePerKb: 100e2,
|
||||
|
@ -2675,7 +2698,7 @@ describe('Wallet service', function() {
|
|||
helpers.stubUtxos(server, wallet, [1, 2], function(utxos) {
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: 0.8e8,
|
||||
}],
|
||||
feePerKb: 100e2,
|
||||
|
@ -2694,7 +2717,7 @@ describe('Wallet service', function() {
|
|||
helpers.stubUtxos(server, wallet, [1, 2], function(utxos) {
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: 0.8e8,
|
||||
}],
|
||||
inputs: utxos,
|
||||
|
@ -2721,7 +2744,7 @@ describe('Wallet service', function() {
|
|||
var txOpts = {
|
||||
txProposalId: '123',
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: 1e8,
|
||||
}],
|
||||
feePerKb: 100e2,
|
||||
|
@ -2739,7 +2762,7 @@ describe('Wallet service', function() {
|
|||
var txOpts = {
|
||||
txProposalId: '123',
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: 1e8,
|
||||
}],
|
||||
feePerKb: 100e2,
|
||||
|
@ -2767,7 +2790,7 @@ describe('Wallet service', function() {
|
|||
var txOpts = {
|
||||
txProposalId: '123',
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: 1e8,
|
||||
}],
|
||||
feePerKb: 100e2,
|
||||
|
@ -2802,7 +2825,7 @@ describe('Wallet service', function() {
|
|||
helpers.stubUtxos(server, wallet, [1, 2], function() {
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: 0.8 * 1e8,
|
||||
}],
|
||||
feePerKb: 100e2,
|
||||
|
@ -2829,7 +2852,7 @@ describe('Wallet service', function() {
|
|||
helpers.stubUtxos(server, wallet, [1, 2], function() {
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: 0.8 * 1e8,
|
||||
}],
|
||||
feePerKb: 100e2,
|
||||
|
@ -2855,7 +2878,7 @@ describe('Wallet service', function() {
|
|||
helpers.stubUtxos(server, wallet, [1, 2], function() {
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: 0.8 * 1e8,
|
||||
}],
|
||||
feePerKb: 100e2,
|
||||
|
@ -2905,7 +2928,7 @@ describe('Wallet service', function() {
|
|||
helpers.stubUtxos(server, wallet, [1, 2], function() {
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: 0.8 * 1e8,
|
||||
}],
|
||||
feePerKb: 100e2,
|
||||
|
@ -2929,7 +2952,7 @@ describe('Wallet service', function() {
|
|||
helpers.stubUtxos(server, wallet, [1, 2], function() {
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: 0.8 * 1e8,
|
||||
}],
|
||||
feePerKb: 100e2,
|
||||
|
@ -2956,7 +2979,7 @@ describe('Wallet service', function() {
|
|||
var txp1, txp2;
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: 0.8 * 1e8,
|
||||
}],
|
||||
message: 'some message',
|
||||
|
@ -3024,7 +3047,7 @@ describe('Wallet service', function() {
|
|||
var txp1, txp2;
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: 0.8 * 1e8,
|
||||
}],
|
||||
message: 'some message',
|
||||
|
@ -3098,7 +3121,7 @@ describe('Wallet service', function() {
|
|||
helpers.stubUtxos(server, wallet, 2, function() {
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: 1e8,
|
||||
}],
|
||||
feeLevel: 'economy',
|
||||
|
@ -3116,7 +3139,7 @@ describe('Wallet service', function() {
|
|||
helpers.stubUtxos(server, wallet, 2, function() {
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: 1e8,
|
||||
}],
|
||||
feeLevel: 'madeUpLevel',
|
||||
|
@ -3139,7 +3162,7 @@ describe('Wallet service', function() {
|
|||
helpers.stubUtxos(server, wallet, 2, function() {
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: 1e8,
|
||||
}],
|
||||
};
|
||||
|
@ -3157,7 +3180,7 @@ describe('Wallet service', function() {
|
|||
helpers.stubUtxos(server, wallet, [1, 2], function() {
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: 0.8e8,
|
||||
}],
|
||||
feePerKb: 100e2,
|
||||
|
@ -3179,7 +3202,7 @@ describe('Wallet service', function() {
|
|||
var max = 3e8 - 7000; // Fees for this tx at 100bits/kB = 7000 sat
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: max,
|
||||
}],
|
||||
feePerKb: 100e2,
|
||||
|
@ -3200,7 +3223,7 @@ describe('Wallet service', function() {
|
|||
should.not.exist(err);
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: 1e8
|
||||
}],
|
||||
feePerKb: 100e2,
|
||||
|
@ -3214,14 +3237,14 @@ describe('Wallet service', function() {
|
|||
});
|
||||
it('should fail gracefully when bitcore throws exception on raw tx creation', function(done) {
|
||||
helpers.stubUtxos(server, wallet, 1, function() {
|
||||
var bitcoreStub = sinon.stub(Bitcore, 'Transaction');
|
||||
var bitcoreStub = sinon.stub(Bitcore_[coin], 'Transaction');
|
||||
bitcoreStub.throws({
|
||||
name: 'dummy',
|
||||
message: 'dummy exception'
|
||||
});
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: 0.5e8,
|
||||
}],
|
||||
feePerKb: 100e2,
|
||||
|
@ -3240,7 +3263,7 @@ describe('Wallet service', function() {
|
|||
helpers.stubUtxos(server, wallet, _.range(1, 10, 0), function() {
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: 8e8,
|
||||
}],
|
||||
feePerKb: 100e2,
|
||||
|
@ -3257,7 +3280,7 @@ describe('Wallet service', function() {
|
|||
helpers.stubUtxos(server, wallet, [1, 1], function() {
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: 1.1e8,
|
||||
}],
|
||||
feePerKb: 100e2,
|
||||
|
@ -3282,7 +3305,7 @@ describe('Wallet service', function() {
|
|||
helpers.stubUtxos(server, wallet, 1, function() {
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: 20e2,
|
||||
}],
|
||||
feePerKb: 100e2,
|
||||
|
@ -3302,7 +3325,7 @@ describe('Wallet service', function() {
|
|||
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: amount,
|
||||
}],
|
||||
feePerKb: 100e2,
|
||||
|
@ -3321,7 +3344,7 @@ describe('Wallet service', function() {
|
|||
helpers.stubUtxos(server, wallet, [1.1, 1.2, 1.3], function() {
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: 1.5e8,
|
||||
}],
|
||||
feePerKb: 100e2,
|
||||
|
@ -3349,7 +3372,7 @@ describe('Wallet service', function() {
|
|||
helpers.stubUtxos(server, wallet, [1.1, 1.2, 1.3], function() {
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: 1.5e8,
|
||||
}],
|
||||
feePerKb: 100e2,
|
||||
|
@ -3395,7 +3418,7 @@ describe('Wallet service', function() {
|
|||
helpers.stubUtxos(server, wallet, [1, 2], function() {
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: 0.8 * 1e8,
|
||||
}],
|
||||
message: 'some message',
|
||||
|
@ -3430,7 +3453,7 @@ describe('Wallet service', function() {
|
|||
helpers.stubUtxos(server, wallet, [1, 2], function() {
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: null,
|
||||
}],
|
||||
feePerKb: 10000,
|
||||
|
@ -3456,7 +3479,7 @@ describe('Wallet service', function() {
|
|||
var txOpts = {
|
||||
outputs: _.times(30, function(i) {
|
||||
return {
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
toAddress: addressStr,
|
||||
amount: (i + 1) * 100e2,
|
||||
};
|
||||
}),
|
||||
|
@ -3486,6 +3509,7 @@ describe('Wallet service', function() {
|
|||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Backoff time', function(done) {
|
||||
var server, wallet, txid, clock;
|
||||
|
|
Loading…
Reference in New Issue