test/bench: lint.
This commit is contained in:
parent
d2e61d1fa2
commit
b437b33760
@ -39,5 +39,11 @@
|
||||
"quotmark": "single",
|
||||
|
||||
"laxbreak": true,
|
||||
"laxcomma": true
|
||||
"laxcomma": true,
|
||||
|
||||
"predef": [
|
||||
"it",
|
||||
"describe",
|
||||
"beforeEach"
|
||||
]
|
||||
}
|
||||
|
||||
@ -1,12 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var BN = require('bn.js');
|
||||
var constants = require('../lib/protocol/constants');
|
||||
var util = require('../lib/utils/util');
|
||||
var assert = require('assert');
|
||||
var scriptTypes = constants.scriptTypes;
|
||||
var bench = require('./bench');
|
||||
var fs = require('fs');
|
||||
var bench = require('./bench');
|
||||
var Coins = require('../lib/blockchain/coins-old');
|
||||
var TX = require('../lib/primitives/tx');
|
||||
|
||||
|
||||
@ -1,17 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var assert = require('assert');
|
||||
var util = require('../lib/utils/util');
|
||||
var Coins = require('../lib/blockchain/coins');
|
||||
var TX = require('../lib/primitives/tx');
|
||||
var bench = require('./bench');
|
||||
|
||||
var wtx = fs.readFileSync(__dirname + '/../test/data/wtx.hex', 'utf8');
|
||||
var i, j, coins, raw, end;
|
||||
|
||||
wtx = TX.fromRaw(wtx.trim(), 'hex');
|
||||
coins = Coins.fromTX(wtx);
|
||||
var raw = fs.readFileSync(__dirname + '/../test/data/wtx.hex', 'utf8');
|
||||
var wtx = TX.fromRaw(raw.trim(), 'hex');
|
||||
var coins = Coins.fromTX(wtx);
|
||||
var i, j, end, hash;
|
||||
|
||||
end = bench('serialize');
|
||||
for (i = 0; i < 10000; i++)
|
||||
@ -31,8 +28,8 @@ end(i);
|
||||
|
||||
coins = Coins.fromRaw(raw);
|
||||
end = bench('get');
|
||||
|
||||
for (i = 0; i < 10000; i++)
|
||||
for (i = 0; i < 10000; i++) {
|
||||
for (j = 0; j < coins.outputs.length; j++)
|
||||
coins.get(j);
|
||||
}
|
||||
end(i * coins.outputs.length);
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var assert = require('assert');
|
||||
var constants = require('../lib/protocol/constants');
|
||||
var util = require('../lib/utils/util');
|
||||
var crypto = require('../lib/crypto/crypto');
|
||||
var Script = require('../lib/script/script');
|
||||
var bench = require('./bench');
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var assert = require('assert');
|
||||
var Block = require('../lib/primitives/block');
|
||||
var Address = require('../lib/primitives/address');
|
||||
var TX = require('../lib/primitives/tx');
|
||||
@ -10,7 +9,6 @@ var Coin = require('../lib/primitives/coin');
|
||||
var CoinView = require('../lib/blockchain/coinview');
|
||||
var constants = require('../lib/protocol/constants');
|
||||
var crypto = require('../lib/crypto/crypto');
|
||||
var util = require('../lib/utils/util');
|
||||
var bench = require('./bench');
|
||||
|
||||
var json = require('../test/data/block300025.json');
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
var util = require('../lib/utils/util');
|
||||
var bench = require('./bench');
|
||||
var co = require('../lib/utils/co');
|
||||
var crypto = require('../lib/crypto/crypto');
|
||||
@ -64,7 +62,7 @@ runBench = co(function* runBench() {
|
||||
// TX deposit
|
||||
jobs = [];
|
||||
for (i = 0; i < 10000; i++) {
|
||||
tx = MTX()
|
||||
tx = new MTX()
|
||||
.addInput(dummy())
|
||||
.addOutput(addrs[(i + 0) % addrs.length], 50460)
|
||||
.addOutput(addrs[(i + 1) % addrs.length], 50460)
|
||||
@ -82,7 +80,7 @@ runBench = co(function* runBench() {
|
||||
// TX redemption
|
||||
jobs = [];
|
||||
for (i = 0; i < 10000; i++) {
|
||||
tx = MTX()
|
||||
tx = new MTX()
|
||||
.addInput(tx, 0)
|
||||
.addInput(tx, 1)
|
||||
.addInput(tx, 2)
|
||||
|
||||
@ -816,7 +816,7 @@ Chain.prototype.reorganizeSPV = co(function* reorganizeSPV(competitor, block) {
|
||||
var fork = yield this.findFork(tip, competitor);
|
||||
var disconnect = [];
|
||||
var entry = tip;
|
||||
var i, block, view;
|
||||
var i, headers, view;
|
||||
|
||||
assert(fork, 'No free space or data corruption.');
|
||||
|
||||
@ -837,9 +837,9 @@ Chain.prototype.reorganizeSPV = co(function* reorganizeSPV(competitor, block) {
|
||||
// the chain has successfully reset.
|
||||
for (i = 0; i < disconnect.length; i++) {
|
||||
entry = disconnect[i];
|
||||
block = entry.toHeaders();
|
||||
headers = entry.toHeaders();
|
||||
view = new CoinView();
|
||||
this.emit('disconnect', entry, block, view);
|
||||
this.emit('disconnect', entry, headers, view);
|
||||
}
|
||||
|
||||
this.emit('reorganize', block, tip.height, tip.hash);
|
||||
|
||||
@ -1352,12 +1352,12 @@ ChainDB.prototype._reconnect = co(function* reconnect(entry, block, view) {
|
||||
*/
|
||||
|
||||
ChainDB.prototype.disconnect = co(function* disconnect(entry, block) {
|
||||
var block;
|
||||
var view;
|
||||
|
||||
this.start();
|
||||
|
||||
try {
|
||||
block = yield this._disconnect(entry, block);
|
||||
view = yield this._disconnect(entry, block);
|
||||
} catch (e) {
|
||||
this.drop();
|
||||
throw e;
|
||||
@ -1365,7 +1365,7 @@ ChainDB.prototype.disconnect = co(function* disconnect(entry, block) {
|
||||
|
||||
yield this.commit();
|
||||
|
||||
return block;
|
||||
return view;
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@ -384,22 +384,6 @@ ScriptNum.prototype.toRaw = function toRaw() {
|
||||
return data;
|
||||
};
|
||||
|
||||
/*
|
||||
* Helpers
|
||||
*/
|
||||
|
||||
function isDecimal(obj) {
|
||||
return typeof obj === 'string'
|
||||
&& obj.length > 0
|
||||
&& /^\-?[0-9]+$/i.test(obj);
|
||||
}
|
||||
|
||||
function isHex(obj) {
|
||||
return typeof obj === 'string'
|
||||
&& obj.length > 0
|
||||
&& /^\-?[0-9a-f]+$/i.test(obj);
|
||||
}
|
||||
|
||||
/*
|
||||
* Expose
|
||||
*/
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
var util = require('../lib/utils/util');
|
||||
var crypto = require('../lib/crypto/crypto');
|
||||
var aes = require('../lib/crypto/aes');
|
||||
var nativeCrypto = require('crypto');
|
||||
@ -58,7 +57,7 @@ describe('AES', function() {
|
||||
}
|
||||
|
||||
function bencrypt(data, passphrase) {
|
||||
var key, cipher;
|
||||
var key;
|
||||
|
||||
assert(nativeCrypto, 'No crypto module available.');
|
||||
assert(passphrase, 'No passphrase.');
|
||||
@ -74,7 +73,7 @@ describe('AES', function() {
|
||||
}
|
||||
|
||||
function bdecrypt(data, passphrase) {
|
||||
var key, decipher;
|
||||
var key;
|
||||
|
||||
assert(nativeCrypto, 'No crypto module available.');
|
||||
assert(passphrase, 'No passphrase.');
|
||||
@ -90,7 +89,7 @@ describe('AES', function() {
|
||||
}
|
||||
|
||||
function encrypt(data, passphrase) {
|
||||
var key, cipher;
|
||||
var key;
|
||||
|
||||
assert(nativeCrypto, 'No crypto module available.');
|
||||
assert(passphrase, 'No passphrase.');
|
||||
@ -107,7 +106,7 @@ describe('AES', function() {
|
||||
}
|
||||
|
||||
function decrypt(data, passphrase) {
|
||||
var key, decipher;
|
||||
var key;
|
||||
|
||||
assert(nativeCrypto, 'No crypto module available.');
|
||||
assert(passphrase, 'No passphrase.');
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
var util = require('../lib/utils/util');
|
||||
var crypto = require('../lib/crypto/crypto');
|
||||
var ec = require('../lib/crypto/ec');
|
||||
var BIP150 = require('../lib/net/bip150');
|
||||
var BIP151 = require('../lib/net/bip151');
|
||||
@ -28,8 +26,10 @@ describe('BIP150', function() {
|
||||
it('should do encinit', function() {
|
||||
var init = server.toEncinit();
|
||||
client.encinit(init.publicKey, init.cipher);
|
||||
var init = client.toEncinit();
|
||||
|
||||
init = client.toEncinit();
|
||||
server.encinit(init.publicKey, init.cipher);
|
||||
|
||||
assert(!client.handshake);
|
||||
assert(!server.handshake);
|
||||
});
|
||||
@ -49,12 +49,15 @@ describe('BIP150', function() {
|
||||
});
|
||||
|
||||
it('should do BIP150 handshake', function() {
|
||||
var challenge = client.bip150.toChallenge();
|
||||
var reply = server.bip150.challenge(challenge.hash);
|
||||
var propose = client.bip150.reply(reply);
|
||||
var challenge = server.bip150.propose(propose);
|
||||
var reply = client.bip150.challenge(challenge);
|
||||
var result = server.bip150.reply(reply);
|
||||
var challenge, reply, propose, result;
|
||||
|
||||
challenge = client.bip150.toChallenge();
|
||||
reply = server.bip150.challenge(challenge.hash);
|
||||
propose = client.bip150.reply(reply);
|
||||
challenge = server.bip150.propose(propose);
|
||||
reply = client.bip150.challenge(challenge);
|
||||
result = server.bip150.reply(reply);
|
||||
|
||||
assert(!result);
|
||||
assert(client.bip150.auth);
|
||||
assert(server.bip150.auth);
|
||||
|
||||
@ -14,8 +14,10 @@ describe('BIP151', function() {
|
||||
it('should do encinit', function() {
|
||||
var init = server.toEncinit();
|
||||
client.encinit(init.publicKey, init.cipher);
|
||||
var init = client.toEncinit();
|
||||
|
||||
init = client.toEncinit();
|
||||
server.encinit(init.publicKey, init.cipher);
|
||||
|
||||
assert(!client.handshake);
|
||||
assert(!server.handshake);
|
||||
});
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
|
||||
var assert = require('assert');
|
||||
var util = require('../lib/utils/util');
|
||||
var crypto = require('../lib/crypto/crypto');
|
||||
var bip70 = require('../lib/bip70');
|
||||
var Address = require('../lib/primitives/address');
|
||||
var x509 = bip70.x509;
|
||||
|
||||
@ -2,14 +2,11 @@
|
||||
|
||||
var fs = require('fs');
|
||||
var assert = require('assert');
|
||||
var util = require('../lib/utils/util');
|
||||
var btcutils = require('../lib/btc/utils');
|
||||
var crypto = require('../lib/crypto/crypto');
|
||||
var Bloom = require('../lib/utils/bloom');
|
||||
var Block = require('../lib/primitives/block');
|
||||
var Headers = require('../lib/primitives/headers');
|
||||
var MerkleBlock = require('../lib/primitives/merkleblock');
|
||||
var TX = require('../lib/primitives/tx');
|
||||
var CoinView = require('../lib/blockchain/coinview');
|
||||
var Coin = require('../lib/primitives/coin');
|
||||
var constants = require('../lib/protocol/constants');
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
var util = require('../lib/utils/util');
|
||||
var constants = require('../lib/protocol/constants');
|
||||
var crypto = require('../lib/crypto/crypto');
|
||||
var Bloom = require('../lib/utils/bloom');
|
||||
var murmur3 = require('../lib/utils/murmur3');
|
||||
|
||||
|
||||
@ -3,23 +3,17 @@
|
||||
var assert = require('assert');
|
||||
var BN = require('bn.js');
|
||||
var constants = require('../lib/protocol/constants');
|
||||
var util = require('../lib/utils/util');
|
||||
var co = require('../lib/utils/co');
|
||||
var crypto = require('../lib/crypto/crypto');
|
||||
var CoinView = require('../lib/blockchain/coinview');
|
||||
var Coin = require('../lib/primitives/coin');
|
||||
var Script = require('../lib/script/script');
|
||||
var FullNode = require('../lib/node/fullnode');
|
||||
var TX = require('../lib/primitives/tx');
|
||||
var MTX = require('../lib/primitives/mtx');
|
||||
// var Client = require('../lib/wallet/client');
|
||||
var opcodes = constants.opcodes;
|
||||
var cob = co.cob;
|
||||
|
||||
describe('Chain', function() {
|
||||
var node = new FullNode({ db: 'memory', apiKey: 'foo', network: 'regtest' });
|
||||
var chain = node.chain;
|
||||
var mempool = node.mempool;
|
||||
var walletdb = node.walletdb;
|
||||
var miner = node.miner;
|
||||
var wallet, tip1, tip2, cb1, cb2, mineBlock;
|
||||
@ -105,11 +99,11 @@ describe('Chain', function() {
|
||||
}
|
||||
}));
|
||||
|
||||
it('should have correct chain value', cob(function* () {
|
||||
it('should have correct chain value', function() {
|
||||
assert.equal(chain.db.state.value, 55000000000);
|
||||
assert.equal(chain.db.state.coin, 20);
|
||||
assert.equal(chain.db.state.tx, 21);
|
||||
}));
|
||||
});
|
||||
|
||||
it('should have correct balance', cob(function* () {
|
||||
var balance;
|
||||
@ -146,11 +140,11 @@ describe('Chain', function() {
|
||||
assert(chain.tip.chainwork.cmp(tip1.chainwork) > 0);
|
||||
}));
|
||||
|
||||
it('should have correct chain value', cob(function* () {
|
||||
it('should have correct chain value', function() {
|
||||
assert.equal(chain.db.state.value, 60000000000);
|
||||
assert.equal(chain.db.state.coin, 21);
|
||||
assert.equal(chain.db.state.tx, 22);
|
||||
}));
|
||||
});
|
||||
|
||||
it('should have correct balance', cob(function* () {
|
||||
var balance;
|
||||
@ -213,11 +207,11 @@ describe('Chain', function() {
|
||||
assert(chain.tip === tip);
|
||||
}));
|
||||
|
||||
it('should have correct chain value', cob(function* () {
|
||||
it('should have correct chain value', function() {
|
||||
assert.equal(chain.db.state.value, 65000000000);
|
||||
assert.equal(chain.db.state.coin, 23);
|
||||
assert.equal(chain.db.state.tx, 24);
|
||||
}));
|
||||
});
|
||||
|
||||
it('should get coin', cob(function* () {
|
||||
var block, tx, output, coin;
|
||||
|
||||
72
test/data/hd.json
Normal file
72
test/data/hd.json
Normal file
@ -0,0 +1,72 @@
|
||||
{
|
||||
"vector1": {
|
||||
"seed": "000102030405060708090a0b0c0d0e0f",
|
||||
"m": {
|
||||
"pub": "xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8",
|
||||
"prv": "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi"
|
||||
},
|
||||
"m/0'": {
|
||||
"pub": "xpub68Gmy5EdvgibQVfPdqkBBCHxA5htiqg55crXYuXoQRKfDBFA1WEjWgP6LHhwBZeNK1VTsfTFUHCdrfp1bgwQ9xv5ski8PX9rL2dZXvgGDnw",
|
||||
"prv": "xprv9uHRZZhk6KAJC1avXpDAp4MDc3sQKNxDiPvvkX8Br5ngLNv1TxvUxt4cV1rGL5hj6KCesnDYUhd7oWgT11eZG7XnxHrnYeSvkzY7d2bhkJ7"
|
||||
},
|
||||
"m/0'/1": {
|
||||
"pub": "xpub6ASuArnXKPbfEwhqN6e3mwBcDTgzisQN1wXN9BJcM47sSikHjJf3UFHKkNAWbWMiGj7Wf5uMash7SyYq527Hqck2AxYysAA7xmALppuCkwQ",
|
||||
"prv": "xprv9wTYmMFdV23N2TdNG573QoEsfRrWKQgWeibmLntzniatZvR9BmLnvSxqu53Kw1UmYPxLgboyZQaXwTCg8MSY3H2EU4pWcQDnRnrVA1xe8fs"
|
||||
},
|
||||
"m/0'/1/2'": {
|
||||
"pub": "xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5",
|
||||
"prv": "xprv9z4pot5VBttmtdRTWfWQmoH1taj2axGVzFqSb8C9xaxKymcFzXBDptWmT7FwuEzG3ryjH4ktypQSAewRiNMjANTtpgP4mLTj34bhnZX7UiM"
|
||||
},
|
||||
"m/0'/1/2'/2": {
|
||||
"pub": "xpub6FHa3pjLCk84BayeJxFW2SP4XRrFd1JYnxeLeU8EqN3vDfZmbqBqaGJAyiLjTAwm6ZLRQUMv1ZACTj37sR62cfN7fe5JnJ7dh8zL4fiyLHV",
|
||||
"prv": "xprvA2JDeKCSNNZky6uBCviVfJSKyQ1mDYahRjijr5idH2WwLsEd4Hsb2Tyh8RfQMuPh7f7RtyzTtdrbdqqsunu5Mm3wDvUAKRHSC34sJ7in334"
|
||||
},
|
||||
"m/0'/1/2'/2/1000000000": {
|
||||
"pub": "xpub6H1LXWLaKsWFhvm6RVpEL9P4KfRZSW7abD2ttkWP3SSQvnyA8FSVqNTEcYFgJS2UaFcxupHiYkro49S8yGasTvXEYBVPamhGW6cFJodrTHy",
|
||||
"prv": "xprvA41z7zogVVwxVSgdKUHDy1SKmdb533PjDz7J6N6mV6uS3ze1ai8FHa8kmHScGpWmj4WggLyQjgPie1rFSruoUihUZREPSL39UNdE3BBDu76"
|
||||
}
|
||||
},
|
||||
"vector2": {
|
||||
"seed": "fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542",
|
||||
"m": {
|
||||
"pub": "xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB",
|
||||
"prv": "xprv9s21ZrQH143K31xYSDQpPDxsXRTUcvj2iNHm5NUtrGiGG5e2DtALGdso3pGz6ssrdK4PFmM8NSpSBHNqPqm55Qn3LqFtT2emdEXVYsCzC2U"
|
||||
},
|
||||
"m/0": {
|
||||
"pub": "xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH",
|
||||
"prv": "xprv9vHkqa6EV4sPZHYqZznhT2NPtPCjKuDKGY38FBWLvgaDx45zo9WQRUT3dKYnjwih2yJD9mkrocEZXo1ex8G81dwSM1fwqWpWkeS3v86pgKt"
|
||||
},
|
||||
"m/0/2147483647'": {
|
||||
"pub": "xpub6ASAVgeehLbnwdqV6UKMHVzgqAG8Gr6riv3Fxxpj8ksbH9ebxaEyBLZ85ySDhKiLDBrQSARLq1uNRts8RuJiHjaDMBU4Zn9h8LZNnBC5y4a",
|
||||
"prv": "xprv9wSp6B7kry3Vj9m1zSnLvN3xH8RdsPP1Mh7fAaR7aRLcQMKTR2vidYEeEg2mUCTAwCd6vnxVrcjfy2kRgVsFawNzmjuHc2YmYRmagcEPdU9"
|
||||
},
|
||||
"m/0/2147483647'/1": {
|
||||
"pub": "xpub6DF8uhdarytz3FWdA8TvFSvvAh8dP3283MY7p2V4SeE2wyWmG5mg5EwVvmdMVCQcoNJxGoWaU9DCWh89LojfZ537wTfunKau47EL2dhHKon",
|
||||
"prv": "xprv9zFnWC6h2cLgpmSA46vutJzBcfJ8yaJGg8cX1e5StJh45BBciYTRXSd25UEPVuesF9yog62tGAQtHjXajPPdbRCHuWS6T8XA2ECKADdw4Ef"
|
||||
},
|
||||
"m/0/2147483647'/1/2147483646'": {
|
||||
"pub": "xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL",
|
||||
"prv": "xprvA1RpRA33e1JQ7ifknakTFpgNXPmW2YvmhqLQYMmrj4xJXXWYpDPS3xz7iAxn8L39njGVyuoseXzU6rcxFLJ8HFsTjSyQbLYnMpCqE2VbFWc"
|
||||
},
|
||||
"m/0/2147483647'/1/2147483646'/2": {
|
||||
"pub": "xpub6FnCn6nSzZAw5Tw7cgR9bi15UV96gLZhjDstkXXxvCLsUXBGXPdSnLFbdpq8p9HmGsApME5hQTZ3emM2rnY5agb9rXpVGyy3bdW6EEgAtqt",
|
||||
"prv": "xprvA2nrNbFZABcdryreWet9Ea4LvTJcGsqrMzxHx98MMrotbir7yrKCEXw7nadnHM8Dq38EGfSh6dqA9QWTyefMLEcBYJUuekgW4BYPJcr9E7j"
|
||||
}
|
||||
},
|
||||
"phrase": "volume doll flush federal inflict tomato result property total curtain shield aisle",
|
||||
"seed": "5559092716434b83f158bffb51337a944529ae30d7e62d46d3be0c66fa4b36e8d60ccfd2c976b831885dc9df9ac3716ee4bf90003f25621070a49cbea58f528b",
|
||||
"master_priv": "xprv9s21ZrQH143K35zTejeVRhkXgegDFUVpoh8Mxs2BQmXEB4w9SZ1CuoJPuQ2KGQrS1ZF3Pk7V7KWHn7FqR2JbAE9Bh8PURnrFnrmArj4kxos",
|
||||
"master_pub": "xpub661MyMwAqRbcFa4vkmBVnqhGEgWhewDgAv3xmFRny74D3sGHz6KTTbcskg2vZEMbEwxc4oaR435oczhSu4GdNwhwiVewcewU8A1Rr6HehAU",
|
||||
"child1_priv": "xprv9v414VeuxMoGt3t7jzkPni79suCfkgFwjxG38X2wgfg2mrYtV4Bhj3prhDDCcBiJrz9n4xLYoDtBFRuQmreVLKzmiZAqvbGpx5q4yHfzfah",
|
||||
"child1_pub": "xpub693MU1BonjMa6Xxar2HQ9r3tRw3AA8yo7BBdvuSZF1D1eet32bVxGr9LYViWMtaLfQaa2StXeUmDG5VELFkU9pc3yfTzCk61WQJdR6ezj7a",
|
||||
"child2_pub": "xpub693MU1BonjMa8MMoz9opJhrFejcXcGmhMP9gzySLsip4Dz1UrSLT4i2pAimHDyM2onW2H2L2HkbwrZqoizQLMoErXu8mPYxDf8tJUBAfBuT",
|
||||
"child3_priv": "xprv9v414VeuxMoGusHLt8GowZuX6hn3Cp3qzAE6Cb2jKPH5MBgLJu2CWuiLKTdWV8WoNFYvpCcBfbpWfeyEQ8zytZW5qy39roTcugBGUkeAvCc",
|
||||
"child3_pub": "xpub693MU1BonjMa8MMoz9opJhrFejcXcGmhMP9gzySLsip4Dz1UrSLT4i2pAimHDyM2onW2H2L2HkbwrZqoizQLMoErXu8mPYxDf8tJUBAfBuT",
|
||||
"child4_priv": "xprv9v414VeuxMoGyViVYuzEN5vLDzff3nkrH5Bf4KzD1iTeY855Q4cCc6xPPNoc6MJcsqqRQiGqR977cEEGK2mhVp7ALKHqY1icEw3Q9UmfQ1v",
|
||||
"child4_pub": "xpub693MU1BonjMaBynxewXEjDs4n2W9TFUheJ7FriPpa3zdQvQDwbvT9uGsEebvioAcYbtRUU7ge4yVgj8WDLrwtwuXKTWiieFoYX2B1JYUEfK",
|
||||
"child5_priv": "xprv9xaK29Nm86ytEwsV9YSsL3jWYR6KtZYY3cKdjAbxHrwKyxH9YWoxvqKwtgQmExGpxAEDrwB4WK9YG1iukth3XiSgsxXLK1W3NB31gLee8fi",
|
||||
"child5_pub": "xpub6BZfReuexUYBTRwxFZyshBgF6SvpJ2GPQqFEXZ1ZrCUJrkcJ648DUdeRjx9QiNQxQvPcHYV3rGkvuExFQbVRS4kU5ynx4fAsWWhHgyPh1pP",
|
||||
"child6_priv": "xprv9xaK29Nm86ytGx9uDhNKUBjvbJ1sAEM11aYxGQS66Rmg6oHwy7HbB6kWwMHvukzdbPpGhfNXhZgePWFHm1DCh5PACPFywJJKr1AnUJTLjUc",
|
||||
"child6_pub": "xpub6BZfReuexUYBVSENKiuKqKgf9KrMZh4rNoUZ4nqhemJeybd6Webqiu4zndBwa9UB4Jvr5jB5Bcgng6reXAKCuDiVm7zhzJ13BUDBiM8HidZ",
|
||||
"zero_priv": "xprv9s21ZrQH143K3ckY9DgU79uMTJkQRLdbCCVDh81SnxTgPzLLGax6uHeBULTtaEtcAvKjXfT7ZWtHzKjTpujMkUd9dDb8msDeAfnJxrgAYhr"
|
||||
}
|
||||
170
test/hd-test.js
170
test/hd-test.js
@ -1,148 +1,81 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
var util = require('../lib/utils/util');
|
||||
var HD = require('../lib/hd');
|
||||
var base58 = require('../lib/utils/base58');
|
||||
var crypto = require('../lib/crypto/crypto');
|
||||
var vectors = require('./data/hd.json');
|
||||
var vector1 = vectors.vector1;
|
||||
var vector2 = vectors.vector2;
|
||||
|
||||
// https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
|
||||
var vector1 = {
|
||||
'seed': '000102030405060708090a0b0c0d0e0f',
|
||||
'm': {
|
||||
'pub': 'xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8',
|
||||
'prv': 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi'
|
||||
},
|
||||
'm/0\'': {
|
||||
'pub': 'xpub68Gmy5EdvgibQVfPdqkBBCHxA5htiqg55crXYuXoQRKfDBFA1WEjWgP6LHhwBZeNK1VTsfTFUHCdrfp1bgwQ9xv5ski8PX9rL2dZXvgGDnw',
|
||||
'prv': 'xprv9uHRZZhk6KAJC1avXpDAp4MDc3sQKNxDiPvvkX8Br5ngLNv1TxvUxt4cV1rGL5hj6KCesnDYUhd7oWgT11eZG7XnxHrnYeSvkzY7d2bhkJ7'
|
||||
},
|
||||
'm/0\'/1': {
|
||||
'pub': 'xpub6ASuArnXKPbfEwhqN6e3mwBcDTgzisQN1wXN9BJcM47sSikHjJf3UFHKkNAWbWMiGj7Wf5uMash7SyYq527Hqck2AxYysAA7xmALppuCkwQ',
|
||||
'prv': 'xprv9wTYmMFdV23N2TdNG573QoEsfRrWKQgWeibmLntzniatZvR9BmLnvSxqu53Kw1UmYPxLgboyZQaXwTCg8MSY3H2EU4pWcQDnRnrVA1xe8fs'
|
||||
},
|
||||
'm/0\'/1/2\'': {
|
||||
'pub': 'xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5',
|
||||
'prv': 'xprv9z4pot5VBttmtdRTWfWQmoH1taj2axGVzFqSb8C9xaxKymcFzXBDptWmT7FwuEzG3ryjH4ktypQSAewRiNMjANTtpgP4mLTj34bhnZX7UiM'
|
||||
},
|
||||
'm/0\'/1/2\'/2': {
|
||||
'pub': 'xpub6FHa3pjLCk84BayeJxFW2SP4XRrFd1JYnxeLeU8EqN3vDfZmbqBqaGJAyiLjTAwm6ZLRQUMv1ZACTj37sR62cfN7fe5JnJ7dh8zL4fiyLHV',
|
||||
'prv': 'xprvA2JDeKCSNNZky6uBCviVfJSKyQ1mDYahRjijr5idH2WwLsEd4Hsb2Tyh8RfQMuPh7f7RtyzTtdrbdqqsunu5Mm3wDvUAKRHSC34sJ7in334'
|
||||
},
|
||||
'm/0\'/1/2\'/2/1000000000': {
|
||||
'pub': 'xpub6H1LXWLaKsWFhvm6RVpEL9P4KfRZSW7abD2ttkWP3SSQvnyA8FSVqNTEcYFgJS2UaFcxupHiYkro49S8yGasTvXEYBVPamhGW6cFJodrTHy',
|
||||
'prv': 'xprvA41z7zogVVwxVSgdKUHDy1SKmdb533PjDz7J6N6mV6uS3ze1ai8FHa8kmHScGpWmj4WggLyQjgPie1rFSruoUihUZREPSL39UNdE3BBDu76'
|
||||
}
|
||||
};
|
||||
function ub58(data) {
|
||||
return base58.decode(data).toString('hex');
|
||||
}
|
||||
|
||||
var vector2 = {
|
||||
'seed': 'fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542',
|
||||
'm': {
|
||||
'pub': 'xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB',
|
||||
'prv': 'xprv9s21ZrQH143K31xYSDQpPDxsXRTUcvj2iNHm5NUtrGiGG5e2DtALGdso3pGz6ssrdK4PFmM8NSpSBHNqPqm55Qn3LqFtT2emdEXVYsCzC2U'
|
||||
},
|
||||
'm/0': {
|
||||
'pub': 'xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH',
|
||||
'prv': 'xprv9vHkqa6EV4sPZHYqZznhT2NPtPCjKuDKGY38FBWLvgaDx45zo9WQRUT3dKYnjwih2yJD9mkrocEZXo1ex8G81dwSM1fwqWpWkeS3v86pgKt'
|
||||
},
|
||||
'm/0/2147483647\'': {
|
||||
'pub': 'xpub6ASAVgeehLbnwdqV6UKMHVzgqAG8Gr6riv3Fxxpj8ksbH9ebxaEyBLZ85ySDhKiLDBrQSARLq1uNRts8RuJiHjaDMBU4Zn9h8LZNnBC5y4a',
|
||||
'prv': 'xprv9wSp6B7kry3Vj9m1zSnLvN3xH8RdsPP1Mh7fAaR7aRLcQMKTR2vidYEeEg2mUCTAwCd6vnxVrcjfy2kRgVsFawNzmjuHc2YmYRmagcEPdU9'
|
||||
},
|
||||
'm/0/2147483647\'/1': {
|
||||
'pub': 'xpub6DF8uhdarytz3FWdA8TvFSvvAh8dP3283MY7p2V4SeE2wyWmG5mg5EwVvmdMVCQcoNJxGoWaU9DCWh89LojfZ537wTfunKau47EL2dhHKon',
|
||||
'prv': 'xprv9zFnWC6h2cLgpmSA46vutJzBcfJ8yaJGg8cX1e5StJh45BBciYTRXSd25UEPVuesF9yog62tGAQtHjXajPPdbRCHuWS6T8XA2ECKADdw4Ef'
|
||||
},
|
||||
'm/0/2147483647\'/1/2147483646\'': {
|
||||
'pub': 'xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL',
|
||||
'prv': 'xprvA1RpRA33e1JQ7ifknakTFpgNXPmW2YvmhqLQYMmrj4xJXXWYpDPS3xz7iAxn8L39njGVyuoseXzU6rcxFLJ8HFsTjSyQbLYnMpCqE2VbFWc'
|
||||
},
|
||||
'm/0/2147483647\'/1/2147483646\'/2': {
|
||||
'pub': 'xpub6FnCn6nSzZAw5Tw7cgR9bi15UV96gLZhjDstkXXxvCLsUXBGXPdSnLFbdpq8p9HmGsApME5hQTZ3emM2rnY5agb9rXpVGyy3bdW6EEgAtqt',
|
||||
'prv': 'xprvA2nrNbFZABcdryreWet9Ea4LvTJcGsqrMzxHx98MMrotbir7yrKCEXw7nadnHM8Dq38EGfSh6dqA9QWTyefMLEcBYJUuekgW4BYPJcr9E7j'
|
||||
},
|
||||
};
|
||||
function equal(a, b) {
|
||||
assert.equal(a, b);
|
||||
assert.equal(ub58(a), ub58(b));
|
||||
}
|
||||
|
||||
describe('HD', function() {
|
||||
var phrase = 'volume doll flush federal inflict tomato result property total curtain shield aisle';
|
||||
|
||||
var seed = '5559092716434b83f158bffb51337a944529ae30d7e62d46d3be0c66fa4b36e8d60ccfd2c976b831885dc9df9ac3716ee4bf90003f25621070a49cbea58f528b';
|
||||
|
||||
var master_priv = 'xprv9s21ZrQH143K35zTejeVRhkXgegDFUVpoh8Mxs2BQmXEB4w9SZ1CuoJPuQ2KGQrS1ZF3Pk7V7KWHn7FqR2JbAE9Bh8PURnrFnrmArj4kxos';
|
||||
var master_pub = 'xpub661MyMwAqRbcFa4vkmBVnqhGEgWhewDgAv3xmFRny74D3sGHz6KTTbcskg2vZEMbEwxc4oaR435oczhSu4GdNwhwiVewcewU8A1Rr6HehAU';
|
||||
|
||||
var child1_priv = 'xprv9v414VeuxMoGt3t7jzkPni79suCfkgFwjxG38X2wgfg2mrYtV4Bhj3prhDDCcBiJrz9n4xLYoDtBFRuQmreVLKzmiZAqvbGpx5q4yHfzfah';
|
||||
var child1_pub = 'xpub693MU1BonjMa6Xxar2HQ9r3tRw3AA8yo7BBdvuSZF1D1eet32bVxGr9LYViWMtaLfQaa2StXeUmDG5VELFkU9pc3yfTzCk61WQJdR6ezj7a';
|
||||
|
||||
var child2_pub = 'xpub693MU1BonjMa8MMoz9opJhrFejcXcGmhMP9gzySLsip4Dz1UrSLT4i2pAimHDyM2onW2H2L2HkbwrZqoizQLMoErXu8mPYxDf8tJUBAfBuT';
|
||||
|
||||
var child3_priv = 'xprv9v414VeuxMoGusHLt8GowZuX6hn3Cp3qzAE6Cb2jKPH5MBgLJu2CWuiLKTdWV8WoNFYvpCcBfbpWfeyEQ8zytZW5qy39roTcugBGUkeAvCc';
|
||||
var child3_pub = 'xpub693MU1BonjMa8MMoz9opJhrFejcXcGmhMP9gzySLsip4Dz1UrSLT4i2pAimHDyM2onW2H2L2HkbwrZqoizQLMoErXu8mPYxDf8tJUBAfBuT';
|
||||
|
||||
var child4_priv = 'xprv9v414VeuxMoGyViVYuzEN5vLDzff3nkrH5Bf4KzD1iTeY855Q4cCc6xPPNoc6MJcsqqRQiGqR977cEEGK2mhVp7ALKHqY1icEw3Q9UmfQ1v';
|
||||
var child4_pub = 'xpub693MU1BonjMaBynxewXEjDs4n2W9TFUheJ7FriPpa3zdQvQDwbvT9uGsEebvioAcYbtRUU7ge4yVgj8WDLrwtwuXKTWiieFoYX2B1JYUEfK';
|
||||
|
||||
var child5_priv = 'xprv9xaK29Nm86ytEwsV9YSsL3jWYR6KtZYY3cKdjAbxHrwKyxH9YWoxvqKwtgQmExGpxAEDrwB4WK9YG1iukth3XiSgsxXLK1W3NB31gLee8fi';
|
||||
var child5_pub = 'xpub6BZfReuexUYBTRwxFZyshBgF6SvpJ2GPQqFEXZ1ZrCUJrkcJ648DUdeRjx9QiNQxQvPcHYV3rGkvuExFQbVRS4kU5ynx4fAsWWhHgyPh1pP';
|
||||
|
||||
var child6_priv = 'xprv9xaK29Nm86ytGx9uDhNKUBjvbJ1sAEM11aYxGQS66Rmg6oHwy7HbB6kWwMHvukzdbPpGhfNXhZgePWFHm1DCh5PACPFywJJKr1AnUJTLjUc';
|
||||
var child6_pub = 'xpub6BZfReuexUYBVSENKiuKqKgf9KrMZh4rNoUZ4nqhemJeybd6Webqiu4zndBwa9UB4Jvr5jB5Bcgng6reXAKCuDiVm7zhzJ13BUDBiM8HidZ';
|
||||
|
||||
var master, child1, child2, child3, child4, child5, child6;
|
||||
|
||||
it('should create a pbkdf2 seed', function() {
|
||||
var checkSeed = crypto.pbkdf2(
|
||||
phrase, 'mnemonic' + 'foo', 2048, 64, 'sha512').toString('hex');
|
||||
assert.equal(checkSeed, seed);
|
||||
var seed = crypto.pbkdf2(vectors.phrase, 'mnemonicfoo', 2048, 64, 'sha512');
|
||||
assert.equal(seed.toString('hex'), vectors.seed);
|
||||
});
|
||||
|
||||
it('should create master private key', function() {
|
||||
master = HD.PrivateKey.fromSeed(new Buffer(seed, 'hex'));
|
||||
assert.equal(master.toBase58(), master_priv);
|
||||
assert.equal(master.toPublic().toBase58(), master_pub);
|
||||
master = HD.PrivateKey.fromSeed(new Buffer(vectors.seed, 'hex'));
|
||||
assert.equal(master.toBase58(), vectors.master_priv);
|
||||
assert.equal(master.toPublic().toBase58(), vectors.master_pub);
|
||||
});
|
||||
|
||||
it('should derive(0) child from master', function() {
|
||||
child1 = master.derive(0);
|
||||
assert.equal(child1.toBase58(), child1_priv);
|
||||
assert.equal(child1.toPublic().toBase58(), child1_pub);
|
||||
assert.equal(child1.toBase58(), vectors.child1_priv);
|
||||
assert.equal(child1.toPublic().toBase58(), vectors.child1_pub);
|
||||
});
|
||||
|
||||
it('should derive(1) child from master public key', function() {
|
||||
child2 = master.toPublic().derive(1);
|
||||
assert.equal(child2.toBase58(), child2_pub);
|
||||
assert.equal(child2.toBase58(), vectors.child2_pub);
|
||||
});
|
||||
|
||||
it('should derive(1) child from master', function() {
|
||||
child3 = master.derive(1);
|
||||
assert.equal(child3.toBase58(), child3_priv);
|
||||
assert.equal(child3.toPublic().toBase58(), child3_pub);
|
||||
assert.equal(child3.toBase58(), vectors.child3_priv);
|
||||
assert.equal(child3.toPublic().toBase58(), vectors.child3_pub);
|
||||
});
|
||||
|
||||
it('should derive(2) child from master', function() {
|
||||
child4 = master.derive(2);
|
||||
assert.equal(child4.toBase58(), child4_priv);
|
||||
assert.equal(child4.toPublic().toBase58(), child4_pub);
|
||||
assert.equal(child4.toBase58(), vectors.child4_priv);
|
||||
assert.equal(child4.toPublic().toBase58(), vectors.child4_pub);
|
||||
});
|
||||
|
||||
it('should derive(0) child from child(2)', function() {
|
||||
child5 = child4.derive(0);
|
||||
assert.equal(child5.toBase58(), child5_priv);
|
||||
assert.equal(child5.toPublic().toBase58(), child5_pub);
|
||||
assert.equal(child5.toBase58(), vectors.child5_priv);
|
||||
assert.equal(child5.toPublic().toBase58(), vectors.child5_pub);
|
||||
});
|
||||
|
||||
it('should derive(1) child from child(2)', function() {
|
||||
child6 = child4.derive(1);
|
||||
assert.equal(child6.toBase58(), child6_priv);
|
||||
assert.equal(child6.toPublic().toBase58(), child6_pub);
|
||||
assert.equal(child6.toBase58(), vectors.child6_priv);
|
||||
assert.equal(child6.toPublic().toBase58(), vectors.child6_pub);
|
||||
});
|
||||
|
||||
it('should derive correctly when private key has leading zeros', function() {
|
||||
var key = 'xprv9s21ZrQH143K3ckY9DgU79uMTJkQRLdbCCVDh81SnxTgPzLLGax6uHeBULTtaEtcAvKjXfT7ZWtHzKjTpujMkUd9dDb8msDeAfnJxrgAYhr';
|
||||
var hdkey = HD.PrivateKey.fromBase58(key);
|
||||
assert.equal(hdkey.privateKey.toString('hex'), '00000055378cf5fafb56c711c674143f9b0ee82ab0ba2924f19b64f5ae7cdbfd');
|
||||
var child = hdkey.derivePath('m/44\'/0\'/0\'/0/0\'');
|
||||
assert.equal(child.privateKey.toString('hex'), '3348069561d2a0fb925e74bf198762acc47dce7db27372257d2d959a9e6f8aeb');
|
||||
var key = HD.PrivateKey.fromBase58(vectors.zero_priv);
|
||||
var child;
|
||||
|
||||
assert.equal(key.privateKey.toString('hex'),
|
||||
'00000055378cf5fafb56c711c674143f9b0ee82ab0ba2924f19b64f5ae7cdbfd');
|
||||
|
||||
child = key.derivePath('m/44\'/0\'/0\'/0/0\'');
|
||||
assert.equal(child.privateKey.toString('hex'),
|
||||
'3348069561d2a0fb925e74bf198762acc47dce7db27372257d2d959a9e6f8aeb');
|
||||
});
|
||||
|
||||
it('should deserialize master private key', function() {
|
||||
@ -158,34 +91,25 @@ describe('HD', function() {
|
||||
assert.equal(HD.fromJSON(key.toJSON()).toBase58(), key.toBase58());
|
||||
});
|
||||
|
||||
function ub58(data) {
|
||||
return base58.decode(data).toString('hex');
|
||||
}
|
||||
|
||||
function equal(a, b) {
|
||||
assert.equal(a, b);
|
||||
assert.equal(ub58(a), ub58(b));
|
||||
}
|
||||
|
||||
[vector1, vector2].forEach(function(vector) {
|
||||
var seed = vector.seed;
|
||||
var m = vector.m;
|
||||
var master;
|
||||
delete vector.seed;
|
||||
delete vector.m;
|
||||
|
||||
it('should create from a seed', function() {
|
||||
master = HD.PrivateKey.fromSeed(new Buffer(seed, 'hex'));
|
||||
equal(master.toBase58(), m.prv);
|
||||
equal(master.toPublic().toBase58(), m.pub);
|
||||
master = HD.PrivateKey.fromSeed(new Buffer(vector.seed, 'hex'));
|
||||
equal(master.toBase58(), vector.m.prv);
|
||||
equal(master.toPublic().toBase58(), vector.m.pub);
|
||||
});
|
||||
|
||||
Object.keys(vector).forEach(function(path) {
|
||||
var data = vector[path];
|
||||
var xpriv = data.prv;
|
||||
var xpub = data.pub;
|
||||
var kp = vector[path];
|
||||
|
||||
if (path === 'seed' || path === 'm')
|
||||
return;
|
||||
|
||||
it('should derive ' + path + ' from master', function() {
|
||||
var key = master.derive(path);
|
||||
equal(key.toBase58(), xpriv);
|
||||
equal(key.toPublic().toBase58(), xpub);
|
||||
equal(key.toBase58(), kp.prv);
|
||||
equal(key.toPublic().toBase58(), kp.pub);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -2,15 +2,11 @@
|
||||
|
||||
var assert = require('assert');
|
||||
var constants = require('../lib/protocol/constants');
|
||||
var network = require('../lib/protocol/networks');
|
||||
var util = require('../lib/utils/util');
|
||||
var crypto = require('../lib/crypto/crypto');
|
||||
var co = require('../lib/utils/co');
|
||||
var Amount = require('../lib/btc/amount');
|
||||
var MTX = require('../lib/primitives/mtx');
|
||||
var HTTP = require('../lib/http');
|
||||
var FullNode = require('../lib/node/fullnode');
|
||||
var scriptTypes = constants.scriptTypes;
|
||||
var cob = co.cob;
|
||||
|
||||
var dummyInput = {
|
||||
@ -21,8 +17,7 @@ var dummyInput = {
|
||||
};
|
||||
|
||||
describe('HTTP', function() {
|
||||
var request = HTTP.request;
|
||||
var node, wallet, w, addr, hash;
|
||||
var node, wallet, addr, hash;
|
||||
|
||||
node = new FullNode({
|
||||
network: 'regtest',
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
|
||||
var assert = require('assert');
|
||||
var constants = require('../lib/protocol/constants');
|
||||
var util = require('../lib/utils/util');
|
||||
var crypto = require('../lib/crypto/crypto');
|
||||
var co = require('../lib/utils/co');
|
||||
var MempoolEntry = require('../lib/mempool/mempoolentry');
|
||||
@ -87,7 +86,7 @@ describe('Mempool', function() {
|
||||
var w = wallet;
|
||||
var t1, t2, t3, t4, f1, fake, prev, sig, balance, txs;
|
||||
|
||||
t1 = MTX()
|
||||
t1 = new MTX()
|
||||
.addOutput(w.getAddress(), 50000)
|
||||
.addOutput(w.getAddress(), 10000);
|
||||
|
||||
@ -100,7 +99,7 @@ describe('Mempool', function() {
|
||||
yield w.sign(t1);
|
||||
t1 = t1.toTX();
|
||||
|
||||
t2 = MTX()
|
||||
t2 = new MTX()
|
||||
.addInput(t1, 0) // 50000
|
||||
.addOutput(w.getAddress(), 20000)
|
||||
.addOutput(w.getAddress(), 20000);
|
||||
@ -109,7 +108,7 @@ describe('Mempool', function() {
|
||||
yield w.sign(t2);
|
||||
t2 = t2.toTX();
|
||||
|
||||
t3 = MTX()
|
||||
t3 = new MTX()
|
||||
.addInput(t1, 1) // 10000
|
||||
.addInput(t2, 0) // 20000
|
||||
.addOutput(w.getAddress(), 23000);
|
||||
@ -118,7 +117,7 @@ describe('Mempool', function() {
|
||||
yield w.sign(t3);
|
||||
t3 = t3.toTX();
|
||||
|
||||
t4 = MTX()
|
||||
t4 = new MTX()
|
||||
.addInput(t2, 1) // 24000
|
||||
.addInput(t3, 0) // 23000
|
||||
.addOutput(w.getAddress(), 11000)
|
||||
@ -128,7 +127,7 @@ describe('Mempool', function() {
|
||||
yield w.sign(t4);
|
||||
t4 = t4.toTX();
|
||||
|
||||
f1 = MTX()
|
||||
f1 = new MTX()
|
||||
.addInput(t4, 1) // 11000
|
||||
.addOutput(new Address(), 9000);
|
||||
|
||||
@ -136,7 +135,7 @@ describe('Mempool', function() {
|
||||
yield w.sign(f1);
|
||||
f1 = f1.toTX();
|
||||
|
||||
fake = MTX()
|
||||
fake = new MTX()
|
||||
.addInput(t1, 1) // 1000 (already redeemed)
|
||||
.addOutput(w.getAddress(), 6000); // 6000 instead of 500
|
||||
|
||||
@ -186,7 +185,7 @@ describe('Mempool', function() {
|
||||
var kp = KeyRing.generate();
|
||||
var tx, prev, prevHash, sig;
|
||||
|
||||
tx = MTX()
|
||||
tx = new MTX()
|
||||
.addOutput(w.getAddress(), 50000)
|
||||
.addOutput(w.getAddress(), 10000);
|
||||
|
||||
@ -212,7 +211,7 @@ describe('Mempool', function() {
|
||||
var kp = KeyRing.generate();
|
||||
var tx, prev, prevHash, sig, err;
|
||||
|
||||
tx = MTX()
|
||||
tx = new MTX()
|
||||
.addOutput(w.getAddress(), 50000)
|
||||
.addOutput(w.getAddress(), 10000);
|
||||
|
||||
@ -241,11 +240,11 @@ describe('Mempool', function() {
|
||||
it('should not cache a malleated wtx with mutated sig', cob(function* () {
|
||||
var w = wallet;
|
||||
var kp = KeyRing.generate();
|
||||
var tx, prev, prevHash, prevs, sig, tx, err;
|
||||
var tx, prev, prevHash, prevs, sig, err;
|
||||
|
||||
kp.witness = true;
|
||||
|
||||
tx = MTX()
|
||||
tx = new MTX()
|
||||
.addOutput(w.getAddress(), 50000)
|
||||
.addOutput(w.getAddress(), 10000);
|
||||
|
||||
@ -258,6 +257,7 @@ describe('Mempool', function() {
|
||||
|
||||
sig = tx.signature(0, prevs, 70000, kp.privateKey, 'all', 1);
|
||||
sig[sig.length - 1] = 0;
|
||||
|
||||
tx.inputs[0].witness = new Witness([sig, kp.publicKey]);
|
||||
tx = tx.toTX();
|
||||
|
||||
@ -274,9 +274,9 @@ describe('Mempool', function() {
|
||||
it('should not cache a malleated tx with unnecessary witness', cob(function* () {
|
||||
var w = wallet;
|
||||
var kp = KeyRing.generate();
|
||||
var tx, prev, prevHash, sig, tx, err;
|
||||
var tx, prev, prevHash, sig, err;
|
||||
|
||||
tx = MTX()
|
||||
tx = new MTX()
|
||||
.addOutput(w.getAddress(), 50000)
|
||||
.addOutput(w.getAddress(), 10000);
|
||||
|
||||
@ -303,11 +303,11 @@ describe('Mempool', function() {
|
||||
it('should not cache a malleated wtx with wit removed', cob(function* () {
|
||||
var w = wallet;
|
||||
var kp = KeyRing.generate();
|
||||
var tx, prev, prevHash, tx, err;
|
||||
var tx, prev, prevHash, err;
|
||||
|
||||
kp.witness = true;
|
||||
|
||||
tx = MTX()
|
||||
tx = new MTX()
|
||||
.addOutput(w.getAddress(), 50000)
|
||||
.addOutput(w.getAddress(), 10000);
|
||||
|
||||
@ -332,9 +332,9 @@ describe('Mempool', function() {
|
||||
it('should cache non-malleated tx without sig', cob(function* () {
|
||||
var w = wallet;
|
||||
var kp = KeyRing.generate();
|
||||
var tx, prev, prevHash, tx, err;
|
||||
var tx, prev, prevHash, err;
|
||||
|
||||
tx = MTX()
|
||||
tx = new MTX()
|
||||
.addOutput(w.getAddress(), 50000)
|
||||
.addOutput(w.getAddress(), 10000);
|
||||
|
||||
@ -359,10 +359,9 @@ describe('Mempool', function() {
|
||||
|
||||
it('should clear reject cache', cob(function* () {
|
||||
var w = wallet;
|
||||
var tx, input, tx, block;
|
||||
var tx, input, block;
|
||||
|
||||
tx = MTX()
|
||||
.addOutput(w.getAddress(), 50000);
|
||||
tx = new MTX().addOutput(w.getAddress(), 50000);
|
||||
|
||||
input = {
|
||||
prevout: {
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
var util = require('../lib/utils/util');
|
||||
var crypto = require('../lib/crypto/crypto');
|
||||
var HD = require('../lib/hd');
|
||||
|
||||
var mnemonic1 = require('./data/mnemonic1').english;
|
||||
|
||||
@ -6,7 +6,6 @@ var constants = require('../lib/protocol/constants');
|
||||
var Network = require('../lib/protocol/network');
|
||||
var util = require('../lib/utils/util');
|
||||
var BufferReader = require('../lib/utils/reader');
|
||||
var crypto = require('../lib/crypto/crypto');
|
||||
var NetworkAddress = require('../lib/primitives/netaddress');
|
||||
var TX = require('../lib/primitives/tx');
|
||||
var Framer = require('../lib/net/framer');
|
||||
|
||||
@ -5,8 +5,6 @@ var Script = require('../lib/script/script');
|
||||
var Witness = require('../lib/script/witness');
|
||||
var Stack = require('../lib/script/stack');
|
||||
var TX = require('../lib/primitives/tx');
|
||||
var util = require('../lib/utils/util');
|
||||
var crypto = require('../lib/crypto/crypto');
|
||||
var constants = require('../lib/protocol/constants');
|
||||
var opcodes = constants.opcodes;
|
||||
|
||||
@ -239,7 +237,7 @@ describe('Script', function() {
|
||||
var comments = Array.isArray(data[4]) ? data[4].join('. ') : data[4] || '';
|
||||
var amount = 0;
|
||||
var flag = 0;
|
||||
var i, name, err, res;
|
||||
var i, name;
|
||||
|
||||
if (data.length === 1)
|
||||
return;
|
||||
|
||||
@ -170,7 +170,6 @@ describe('TX', function() {
|
||||
clearCache(p, noCache);
|
||||
|
||||
assert(tx.verify(view));
|
||||
util.log(tx.format(view));
|
||||
});
|
||||
|
||||
it('should verify non-minimal output' + suffix, function() {
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
|
||||
var assert = require('assert');
|
||||
var BN = require('bn.js');
|
||||
var util = require('../lib/utils/util');
|
||||
var ec = require('../lib/crypto/ec');
|
||||
var btcutils = require('../lib/btc/utils');
|
||||
var base58 = require('../lib/utils/base58');
|
||||
@ -30,12 +29,12 @@ describe('Utils', function() {
|
||||
];
|
||||
|
||||
it('should encode/decode base58', function() {
|
||||
var arr = new Buffer([ 0, 0, 0, 0xde, 0xad, 0xbe, 0xef ]);
|
||||
var b = base58.encode(arr);
|
||||
var i, r, b;
|
||||
var buf = new Buffer('000000deadbeef', 'hex');
|
||||
var b = base58.encode(buf);
|
||||
var i, r;
|
||||
|
||||
assert.equal(b, '1116h8cQN');
|
||||
assert.deepEqual(base58.decode(b), arr);
|
||||
assert.deepEqual(base58.decode(b), buf);
|
||||
|
||||
for (i = 0; i < vectors.length; i++) {
|
||||
r = new Buffer(vectors[i][0], 'hex');
|
||||
@ -257,12 +256,12 @@ describe('Utils', function() {
|
||||
|
||||
it('should do proper hkdf', function() {
|
||||
// https://tools.ietf.org/html/rfc5869
|
||||
var hash = 'sha256';
|
||||
var alg = 'sha256';
|
||||
var ikm = '0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b';
|
||||
var salt = '000102030405060708090a0b0c';
|
||||
var info = 'f0f1f2f3f4f5f6f7f8f9';
|
||||
var len = 42;
|
||||
var prkE, okmE, prk, okm, hash;
|
||||
var prkE, okmE, prk, okm;
|
||||
|
||||
prkE = '077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec844ad7c2b3e5';
|
||||
okmE = '3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1'
|
||||
@ -272,13 +271,13 @@ describe('Utils', function() {
|
||||
salt = new Buffer(salt, 'hex');
|
||||
info = new Buffer(info, 'hex');
|
||||
|
||||
prk = crypto.hkdfExtract(ikm, salt, 'sha256');
|
||||
okm = crypto.hkdfExpand(prk, info, len, 'sha256');
|
||||
prk = crypto.hkdfExtract(ikm, salt, alg);
|
||||
okm = crypto.hkdfExpand(prk, info, len, alg);
|
||||
|
||||
assert.equal(prk.toString('hex'), prkE);
|
||||
assert.equal(okm.toString('hex'), okmE);
|
||||
|
||||
hash = 'sha256';
|
||||
alg = 'sha256';
|
||||
|
||||
ikm = '000102030405060708090a0b0c0d0e0f'
|
||||
+ '101112131415161718191a1b1c1d1e1f'
|
||||
@ -314,8 +313,8 @@ describe('Utils', function() {
|
||||
salt = new Buffer(salt, 'hex');
|
||||
info = new Buffer(info, 'hex');
|
||||
|
||||
prk = crypto.hkdfExtract(ikm, salt, 'sha256');
|
||||
okm = crypto.hkdfExpand(prk, info, len, 'sha256');
|
||||
prk = crypto.hkdfExtract(ikm, salt, alg);
|
||||
okm = crypto.hkdfExpand(prk, info, len, alg);
|
||||
|
||||
assert.equal(prk.toString('hex'), prkE);
|
||||
assert.equal(okm.toString('hex'), okmE);
|
||||
|
||||
@ -124,7 +124,7 @@ describe('Wallet', function() {
|
||||
else
|
||||
assert.equal(addr.type, scriptTypes.PUBKEYHASH);
|
||||
|
||||
src = MTX({
|
||||
src = new MTX({
|
||||
outputs: [{
|
||||
value: 5460 * 2,
|
||||
address: bullshitNesting
|
||||
@ -138,7 +138,7 @@ describe('Wallet', function() {
|
||||
|
||||
src.addInput(dummy());
|
||||
|
||||
tx = MTX()
|
||||
tx = new MTX()
|
||||
.addInput(src, 0)
|
||||
.addOutput(w.getAddress(), 5460);
|
||||
|
||||
@ -178,7 +178,7 @@ describe('Wallet', function() {
|
||||
];
|
||||
|
||||
// Input transaction (bare 1-of-2 multisig)
|
||||
src = MTX({
|
||||
src = new MTX({
|
||||
outputs: [{
|
||||
value: 5460 * 2,
|
||||
script: Script.fromMultisig(1, 2, keys)
|
||||
@ -190,7 +190,7 @@ describe('Wallet', function() {
|
||||
|
||||
src.addInput(dummy());
|
||||
|
||||
tx = MTX()
|
||||
tx = new MTX()
|
||||
.addInput(src, 0)
|
||||
.addOutput(w.getAddress(), 5460);
|
||||
|
||||
@ -210,7 +210,7 @@ describe('Wallet', function() {
|
||||
doubleSpendWallet = w;
|
||||
|
||||
// Coinbase
|
||||
t1 = MTX()
|
||||
t1 = new MTX()
|
||||
.addOutput(w.getAddress(), 50000)
|
||||
.addOutput(w.getAddress(), 1000);
|
||||
t1.addInput(dummy());
|
||||
@ -220,7 +220,7 @@ describe('Wallet', function() {
|
||||
// yield w.sign(t1);
|
||||
t1 = t1.toTX();
|
||||
|
||||
t2 = MTX()
|
||||
t2 = new MTX()
|
||||
.addInput(t1, 0) // 50000
|
||||
.addOutput(w.getAddress(), 24000)
|
||||
.addOutput(w.getAddress(), 24000);
|
||||
@ -230,7 +230,7 @@ describe('Wallet', function() {
|
||||
// balance: 49000
|
||||
yield w.sign(t2);
|
||||
t2 = t2.toTX();
|
||||
t3 = MTX()
|
||||
t3 = new MTX()
|
||||
.addInput(t1, 1) // 1000
|
||||
.addInput(t2, 0) // 24000
|
||||
.addOutput(w.getAddress(), 23000);
|
||||
@ -238,7 +238,7 @@ describe('Wallet', function() {
|
||||
// balance: 47000
|
||||
yield w.sign(t3);
|
||||
t3 = t3.toTX();
|
||||
t4 = MTX()
|
||||
t4 = new MTX()
|
||||
.addInput(t2, 1) // 24000
|
||||
.addInput(t3, 0) // 23000
|
||||
.addOutput(w.getAddress(), 11000)
|
||||
@ -247,7 +247,7 @@ describe('Wallet', function() {
|
||||
// balance: 22000
|
||||
yield w.sign(t4);
|
||||
t4 = t4.toTX();
|
||||
f1 = MTX()
|
||||
f1 = new MTX()
|
||||
.addInput(t4, 1) // 11000
|
||||
.addOutput(f.getAddress(), 10000);
|
||||
|
||||
@ -255,7 +255,7 @@ describe('Wallet', function() {
|
||||
yield w.sign(f1);
|
||||
f1 = f1.toTX();
|
||||
|
||||
fake = MTX()
|
||||
fake = new MTX()
|
||||
.addInput(t1, 1) // 1000 (already redeemed)
|
||||
.addOutput(w.getAddress(), 500);
|
||||
|
||||
@ -316,7 +316,7 @@ describe('Wallet', function() {
|
||||
var w = doubleSpendWallet;
|
||||
var tx, txs, total, balance;
|
||||
|
||||
tx = MTX().addOutput(w.getAddress(), 5000);
|
||||
tx = new MTX().addOutput(w.getAddress(), 5000);
|
||||
tx.addInput(doubleSpend);
|
||||
|
||||
txs = yield w.getHistory();
|
||||
@ -348,7 +348,7 @@ describe('Wallet', function() {
|
||||
}));
|
||||
|
||||
it('should handle missed txs without resolution', cob(function* () {
|
||||
var walletdb, w, f, t1, t2, t3, t4, f1, fake, balance, txs;
|
||||
var walletdb, w, f, t1, t2, t3, t4, f1, balance, txs;
|
||||
|
||||
walletdb = new WalletDB({
|
||||
name: 'wallet-test',
|
||||
@ -363,7 +363,7 @@ describe('Wallet', function() {
|
||||
f = yield walletdb.create();
|
||||
|
||||
// Coinbase
|
||||
t1 = MTX()
|
||||
t1 = new MTX()
|
||||
.addOutput(w.getAddress(), 50000)
|
||||
.addOutput(w.getAddress(), 1000);
|
||||
t1.addInput(dummy());
|
||||
@ -372,7 +372,7 @@ describe('Wallet', function() {
|
||||
// yield w.sign(t1);
|
||||
t1 = t1.toTX();
|
||||
|
||||
t2 = MTX()
|
||||
t2 = new MTX()
|
||||
.addInput(t1, 0) // 50000
|
||||
.addOutput(w.getAddress(), 24000)
|
||||
.addOutput(w.getAddress(), 24000);
|
||||
@ -380,7 +380,7 @@ describe('Wallet', function() {
|
||||
// balance: 49000
|
||||
yield w.sign(t2);
|
||||
t2 = t2.toTX();
|
||||
t3 = MTX()
|
||||
t3 = new MTX()
|
||||
.addInput(t1, 1) // 1000
|
||||
.addInput(t2, 0) // 24000
|
||||
.addOutput(w.getAddress(), 23000);
|
||||
@ -388,7 +388,7 @@ describe('Wallet', function() {
|
||||
// balance: 47000
|
||||
yield w.sign(t3);
|
||||
t3 = t3.toTX();
|
||||
t4 = MTX()
|
||||
t4 = new MTX()
|
||||
.addInput(t2, 1) // 24000
|
||||
.addInput(t3, 0) // 23000
|
||||
.addOutput(w.getAddress(), 11000)
|
||||
@ -397,7 +397,7 @@ describe('Wallet', function() {
|
||||
// balance: 22000
|
||||
yield w.sign(t4);
|
||||
t4 = t4.toTX();
|
||||
f1 = MTX()
|
||||
f1 = new MTX()
|
||||
.addInput(t4, 1) // 11000
|
||||
.addOutput(f.getAddress(), 10000);
|
||||
|
||||
@ -405,7 +405,7 @@ describe('Wallet', function() {
|
||||
yield w.sign(f1);
|
||||
f1 = f1.toTX();
|
||||
|
||||
// fake = MTX()
|
||||
// fake = new MTX()
|
||||
// .addInput(t1, 1) // 1000 (already redeemed)
|
||||
// .addOutput(w.getAddress(), 500);
|
||||
|
||||
@ -482,7 +482,7 @@ describe('Wallet', function() {
|
||||
var view, t1, t2, t3, err;
|
||||
|
||||
// Coinbase
|
||||
t1 = MTX()
|
||||
t1 = new MTX()
|
||||
.addOutput(w1.getAddress(), 5460)
|
||||
.addOutput(w1.getAddress(), 5460)
|
||||
.addOutput(w1.getAddress(), 5460)
|
||||
@ -494,7 +494,7 @@ describe('Wallet', function() {
|
||||
yield walletdb.addTX(t1);
|
||||
|
||||
// Create new transaction
|
||||
t2 = MTX().addOutput(w2.getAddress(), 5460);
|
||||
t2 = new MTX().addOutput(w2.getAddress(), 5460);
|
||||
yield w1.fund(t2, { rate: 10000, round: true });
|
||||
yield w1.sign(t2);
|
||||
view = t2.view;
|
||||
@ -511,7 +511,7 @@ describe('Wallet', function() {
|
||||
assert.equal(t2.getFee(view), 10000); // minrelay=1000
|
||||
|
||||
// Create new transaction
|
||||
t3 = MTX().addOutput(w2.getAddress(), 15000);
|
||||
t3 = new MTX().addOutput(w2.getAddress(), 15000);
|
||||
|
||||
try {
|
||||
yield w1.fund(t3, { rate: 10000, round: true });
|
||||
@ -529,7 +529,7 @@ describe('Wallet', function() {
|
||||
var view, t1, t2, t3, balance, err;
|
||||
|
||||
// Coinbase
|
||||
t1 = MTX()
|
||||
t1 = new MTX()
|
||||
.addOutput(w1.getAddress(), 5460)
|
||||
.addOutput(w1.getAddress(), 5460)
|
||||
.addOutput(w1.getAddress(), 5460)
|
||||
@ -541,7 +541,7 @@ describe('Wallet', function() {
|
||||
yield walletdb.addTX(t1);
|
||||
|
||||
// Create new transaction
|
||||
t2 = MTX().addOutput(w2.getAddress(), 5460);
|
||||
t2 = new MTX().addOutput(w2.getAddress(), 5460);
|
||||
yield w1.fund(t2, { rate: 10000 });
|
||||
|
||||
yield w1.sign(t2);
|
||||
@ -568,7 +568,7 @@ describe('Wallet', function() {
|
||||
yield walletdb.addTX(t2);
|
||||
|
||||
// Create new transaction
|
||||
t3 = MTX().addOutput(w2.getAddress(), 15000);
|
||||
t3 = new MTX().addOutput(w2.getAddress(), 15000);
|
||||
|
||||
try {
|
||||
yield w1.fund(t3, { rate: 10000 });
|
||||
@ -588,7 +588,7 @@ describe('Wallet', function() {
|
||||
var t1, t2, tx, cost, total, coins1, coins2, left;
|
||||
|
||||
// Coinbase
|
||||
t1 = MTX()
|
||||
t1 = new MTX()
|
||||
.addOutput(w1.getAddress(), 5460)
|
||||
.addOutput(w1.getAddress(), 5460)
|
||||
.addOutput(w1.getAddress(), 5460)
|
||||
@ -598,7 +598,7 @@ describe('Wallet', function() {
|
||||
t1 = t1.toTX();
|
||||
|
||||
// Coinbase
|
||||
t2 = MTX()
|
||||
t2 = new MTX()
|
||||
.addOutput(w2.getAddress(), 5460)
|
||||
.addOutput(w2.getAddress(), 5460)
|
||||
.addOutput(w2.getAddress(), 5460)
|
||||
@ -611,7 +611,7 @@ describe('Wallet', function() {
|
||||
yield walletdb.addTX(t2);
|
||||
|
||||
// Create our tx with an output
|
||||
tx = MTX();
|
||||
tx = new MTX();
|
||||
tx.addOutput(to.getAddress(), 5460);
|
||||
|
||||
cost = tx.getOutputValue();
|
||||
@ -718,7 +718,7 @@ describe('Wallet', function() {
|
||||
assert.equal(w3.getNested('base58'), paddr);
|
||||
|
||||
// Add a shared unspent transaction to our wallets
|
||||
utx = MTX();
|
||||
utx = new MTX();
|
||||
if (bullshitNesting)
|
||||
utx.addOutput({ address: paddr, value: 5460 * 10 });
|
||||
else
|
||||
@ -749,7 +749,7 @@ describe('Wallet', function() {
|
||||
assert.equal(w3.account[rec].getAddress('base58'), b58);
|
||||
|
||||
// Create a tx requiring 2 signatures
|
||||
send = MTX();
|
||||
send = new MTX();
|
||||
send.addOutput({ address: receive.getAddress(), value: 5460 });
|
||||
assert(!send.verify(flags));
|
||||
yield w1.fund(send, { rate: 10000, round: true });
|
||||
@ -772,7 +772,7 @@ describe('Wallet', function() {
|
||||
assert.equal(w3.account.change.getAddress('base58'), change);
|
||||
|
||||
// Simulate a confirmation
|
||||
var block = nextBlock();
|
||||
block = nextBlock();
|
||||
send.height = block.height;
|
||||
send.block = block.hash;
|
||||
send.ts = block.ts;
|
||||
@ -828,7 +828,7 @@ describe('Wallet', function() {
|
||||
rec = account.receive;
|
||||
|
||||
// Coinbase
|
||||
t1 = MTX()
|
||||
t1 = new MTX()
|
||||
.addOutput(rec.getAddress(), 5460)
|
||||
.addOutput(rec.getAddress(), 5460)
|
||||
.addOutput(rec.getAddress(), 5460)
|
||||
@ -840,7 +840,7 @@ describe('Wallet', function() {
|
||||
yield walletdb.addTX(t1);
|
||||
|
||||
// Create new transaction
|
||||
t2 = MTX().addOutput(w2.getAddress(), 5460);
|
||||
t2 = new MTX().addOutput(w2.getAddress(), 5460);
|
||||
yield w1.fund(t2, { rate: 10000, round: true });
|
||||
yield w1.sign(t2);
|
||||
|
||||
@ -855,7 +855,7 @@ describe('Wallet', function() {
|
||||
assert.equal(t2.getFee(), 10000); // minrelay=1000
|
||||
|
||||
// Create new transaction
|
||||
t3 = MTX().addOutput(w2.getAddress(), 15000);
|
||||
t3 = new MTX().addOutput(w2.getAddress(), 15000);
|
||||
|
||||
try {
|
||||
yield w1.fund(t3, { rate: 10000, round: true });
|
||||
@ -894,7 +894,7 @@ describe('Wallet', function() {
|
||||
w.account.receive.getAddress('base58'));
|
||||
|
||||
// Coinbase
|
||||
t1 = MTX()
|
||||
t1 = new MTX()
|
||||
.addOutput(w.getAddress(), 5460)
|
||||
.addOutput(w.getAddress(), 5460)
|
||||
.addOutput(w.getAddress(), 5460)
|
||||
@ -906,7 +906,7 @@ describe('Wallet', function() {
|
||||
yield walletdb.addTX(t1);
|
||||
|
||||
// Should fill from `foo` and fail
|
||||
t2 = MTX().addOutput(w.getAddress(), 5460);
|
||||
t2 = new MTX().addOutput(w.getAddress(), 5460);
|
||||
try {
|
||||
yield w.fund(t2, { rate: 10000, round: true, account: 'foo' });
|
||||
} catch (e) {
|
||||
@ -915,11 +915,11 @@ describe('Wallet', function() {
|
||||
assert(err);
|
||||
|
||||
// Should fill from whole wallet and succeed
|
||||
t2 = MTX().addOutput(w.getAddress(), 5460);
|
||||
t2 = new MTX().addOutput(w.getAddress(), 5460);
|
||||
yield w.fund(t2, { rate: 10000, round: true });
|
||||
|
||||
// Coinbase
|
||||
t1 = MTX()
|
||||
t1 = new MTX()
|
||||
.addOutput(account.receive.getAddress(), 5460)
|
||||
.addOutput(account.receive.getAddress(), 5460)
|
||||
.addOutput(account.receive.getAddress(), 5460);
|
||||
@ -930,17 +930,22 @@ describe('Wallet', function() {
|
||||
|
||||
yield walletdb.addTX(t1);
|
||||
|
||||
t2 = MTX().addOutput(w.getAddress(), 5460);
|
||||
t2 = new MTX().addOutput(w.getAddress(), 5460);
|
||||
// Should fill from `foo` and succeed
|
||||
yield w.fund(t2, { rate: 10000, round: true, account: 'foo' });
|
||||
}));
|
||||
|
||||
it('should create two accounts multiple encryption', cob(function* () {
|
||||
it('should create two accounts (multiple encryption)', cob(function* () {
|
||||
var w = yield walletdb.create({ id: 'foobar', passphrase: 'foo' });
|
||||
var account;
|
||||
|
||||
yield w.destroy();
|
||||
var w = yield walletdb.get('foobar');
|
||||
var account = yield w.createAccount({ name: 'foo1' }, 'foo');
|
||||
|
||||
w = yield walletdb.get('foobar');
|
||||
|
||||
account = yield w.createAccount({ name: 'foo1' }, 'foo');
|
||||
assert(account);
|
||||
|
||||
yield w.lock();
|
||||
}));
|
||||
|
||||
@ -952,7 +957,7 @@ describe('Wallet', function() {
|
||||
w.master.key = null;
|
||||
|
||||
// Coinbase
|
||||
t1 = MTX()
|
||||
t1 = new MTX()
|
||||
.addOutput(w.getAddress(), 5460)
|
||||
.addOutput(w.getAddress(), 5460)
|
||||
.addOutput(w.getAddress(), 5460)
|
||||
@ -964,7 +969,7 @@ describe('Wallet', function() {
|
||||
yield walletdb.addTX(t1);
|
||||
|
||||
// Create new transaction
|
||||
t2 = MTX().addOutput(w.getAddress(), 5460);
|
||||
t2 = new MTX().addOutput(w.getAddress(), 5460);
|
||||
yield w.fund(t2, { rate: 10000, round: true });
|
||||
|
||||
// Should fail
|
||||
@ -988,7 +993,7 @@ describe('Wallet', function() {
|
||||
var t1, t2;
|
||||
|
||||
// Coinbase
|
||||
t1 = MTX()
|
||||
t1 = new MTX()
|
||||
.addOutput(w1.getAddress(), 5460)
|
||||
.addOutput(w1.getAddress(), 5460)
|
||||
.addOutput(w1.getAddress(), 5460)
|
||||
@ -1000,7 +1005,7 @@ describe('Wallet', function() {
|
||||
yield walletdb.addTX(t1);
|
||||
|
||||
// Create new transaction
|
||||
t2 = MTX().addOutput(w2.getAddress(), 21840);
|
||||
t2 = new MTX().addOutput(w2.getAddress(), 21840);
|
||||
yield w1.fund(t2, { rate: 10000, round: true, subtractFee: true });
|
||||
yield w1.sign(t2);
|
||||
|
||||
@ -1017,7 +1022,7 @@ describe('Wallet', function() {
|
||||
var options, t1, t2;
|
||||
|
||||
// Coinbase
|
||||
t1 = MTX()
|
||||
t1 = new MTX()
|
||||
.addOutput(w1.getAddress(), 5460)
|
||||
.addOutput(w1.getAddress(), 5460)
|
||||
.addOutput(w1.getAddress(), 5460)
|
||||
@ -1090,7 +1095,7 @@ describe('Wallet', function() {
|
||||
assert.equal(k.getHash('hex'), key.getHash('hex'));
|
||||
|
||||
// Coinbase
|
||||
t1 = MTX()
|
||||
t1 = new MTX()
|
||||
.addOutput(key.getAddress(), 5460)
|
||||
.addOutput(key.getAddress(), 5460)
|
||||
.addOutput(key.getAddress(), 5460)
|
||||
@ -1125,7 +1130,7 @@ describe('Wallet', function() {
|
||||
var priv = KeyRing.generate();
|
||||
var key = new KeyRing(priv.publicKey);
|
||||
var w = yield walletdb.create({ watchOnly: true });
|
||||
var options, k, t1, t2, tx;
|
||||
var k;
|
||||
|
||||
yield w.importKey('default', key);
|
||||
|
||||
@ -1140,7 +1145,7 @@ describe('Wallet', function() {
|
||||
it('should import address', cob(function* () {
|
||||
var key = KeyRing.generate();
|
||||
var w = yield walletdb.create({ watchOnly: true });
|
||||
var options, k, t1, t2, tx;
|
||||
var k;
|
||||
|
||||
yield w.importAddress('default', key.getAddress());
|
||||
|
||||
@ -1223,7 +1228,7 @@ describe('Wallet', function() {
|
||||
addr = alice.getAddress();
|
||||
|
||||
// Coinbase
|
||||
t1 = MTX()
|
||||
t1 = new MTX()
|
||||
.addOutput(addr, 50000);
|
||||
t1.addInput(dummy());
|
||||
|
||||
@ -1234,7 +1239,7 @@ describe('Wallet', function() {
|
||||
yield bob.add(t1);
|
||||
|
||||
// Bob misses this tx!
|
||||
t2 = MTX()
|
||||
t2 = new MTX()
|
||||
.addInput(t1, 0)
|
||||
.addOutput(addr, 24000)
|
||||
.addOutput(addr, 24000);
|
||||
@ -1249,7 +1254,7 @@ describe('Wallet', function() {
|
||||
(yield bob.getBalance()).unconfirmed);
|
||||
|
||||
// Bob sees this one.
|
||||
t3 = MTX()
|
||||
t3 = new MTX()
|
||||
.addInput(t2, 0)
|
||||
.addInput(t2, 1)
|
||||
.addOutput(addr, 30000);
|
||||
@ -1290,7 +1295,7 @@ describe('Wallet', function() {
|
||||
addr = alice.getAddress();
|
||||
|
||||
// Coinbase
|
||||
t1 = MTX()
|
||||
t1 = new MTX()
|
||||
.addOutput(addr, 50000);
|
||||
t1.addInput(dummy());
|
||||
|
||||
@ -1301,7 +1306,7 @@ describe('Wallet', function() {
|
||||
yield bob.add(t1);
|
||||
|
||||
// Bob misses this tx!
|
||||
t2 = MTX()
|
||||
t2 = new MTX()
|
||||
.addInput(t1, 0)
|
||||
.addOutput(addr, 24000)
|
||||
.addOutput(addr, 24000);
|
||||
@ -1316,7 +1321,7 @@ describe('Wallet', function() {
|
||||
(yield bob.getBalance()).unconfirmed);
|
||||
|
||||
// Bob doublespends.
|
||||
t2a = MTX()
|
||||
t2a = new MTX()
|
||||
.addInput(t1, 0)
|
||||
.addOutput(addr, 10000)
|
||||
.addOutput(addr, 10000);
|
||||
@ -1327,7 +1332,7 @@ describe('Wallet', function() {
|
||||
yield bob.add(t2a);
|
||||
|
||||
// Bob sees this one.
|
||||
t3 = MTX()
|
||||
t3 = new MTX()
|
||||
.addInput(t2, 0)
|
||||
.addInput(t2, 1)
|
||||
.addOutput(addr, 30000);
|
||||
@ -1351,8 +1356,7 @@ describe('Wallet', function() {
|
||||
assert.equal((yield bob.getBalance()).unconfirmed, 30000);
|
||||
}));
|
||||
|
||||
it('should cleanup', cob(function* () {
|
||||
var records = yield walletdb.dump();
|
||||
it('should cleanup', function() {
|
||||
constants.tx.COINBASE_MATURITY = 100;
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user