test: use memwallet for mempool test.

This commit is contained in:
Christopher Jeffrey 2017-01-30 18:56:56 -08:00
parent df5228c849
commit bc951e25a9
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 20 additions and 32 deletions

View File

@ -16,30 +16,17 @@ var Outpoint = require('../lib/primitives/outpoint');
var Script = require('../lib/script/script'); var Script = require('../lib/script/script');
var Witness = require('../lib/script/witness'); var Witness = require('../lib/script/witness');
var Block = require('../lib/primitives/block'); var Block = require('../lib/primitives/block');
var MemWallet = require('./util/memwallet');
var opcodes = Script.opcodes; var opcodes = Script.opcodes;
describe('Mempool', function() { describe('Mempool', function() {
var chain, mempool, walletdb, wallet, cached; var chain = new Chain({ db: 'memory' });
var mempool = new Mempool({ chain: chain, db: 'memory' });
var wallet = new MemWallet();
var cached;
this.timeout(5000); this.timeout(5000);
chain = new Chain({
name: 'mp-chain',
db: 'memory'
});
mempool = new Mempool({
chain: chain,
name: 'mempool-test',
db: 'memory'
});
walletdb = new WalletDB({
name: 'mempool-wallet-test',
db: 'memory',
verify: true
});
function dummy(prev, prevHash) { function dummy(prev, prevHash) {
var fund, coin, entry; var fund, coin, entry;
@ -69,14 +56,6 @@ describe('Mempool', function() {
chain.state.flags |= Script.flags.VERIFY_WITNESS; chain.state.flags |= Script.flags.VERIFY_WITNESS;
})); }));
it('should open walletdb', co(function* () {
yield walletdb.open();
}));
it('should open wallet', co(function* () {
wallet = yield walletdb.create();
}));
it('should handle incoming orphans and TXs', co(function* () { it('should handle incoming orphans and TXs', co(function* () {
var kp = KeyRing.generate(); var kp = KeyRing.generate();
var w = wallet; var w = wallet;
@ -92,7 +71,7 @@ describe('Mempool', function() {
t1.inputs[0].script = new Script([sig]); t1.inputs[0].script = new Script([sig]);
// balance: 51000 // balance: 51000
yield w.sign(t1); w.sign(t1);
t1 = t1.toTX(); t1 = t1.toTX();
t2 = new MTX(); t2 = new MTX();
@ -101,7 +80,7 @@ describe('Mempool', function() {
t2.addOutput(w.getAddress(), 20000); t2.addOutput(w.getAddress(), 20000);
// balance: 49000 // balance: 49000
yield w.sign(t2); w.sign(t2);
t2 = t2.toTX(); t2 = t2.toTX();
t3 = new MTX(); t3 = new MTX();
@ -110,7 +89,7 @@ describe('Mempool', function() {
t3.addOutput(w.getAddress(), 23000); t3.addOutput(w.getAddress(), 23000);
// balance: 47000 // balance: 47000
yield w.sign(t3); w.sign(t3);
t3 = t3.toTX(); t3 = t3.toTX();
t4 = new MTX(); t4 = new MTX();
@ -120,7 +99,7 @@ describe('Mempool', function() {
t4.addOutput(w.getAddress(), 11000); t4.addOutput(w.getAddress(), 11000);
// balance: 22000 // balance: 22000
yield w.sign(t4); w.sign(t4);
t4 = t4.toTX(); t4 = t4.toTX();
f1 = new MTX(); f1 = new MTX();
@ -128,7 +107,7 @@ describe('Mempool', function() {
f1.addOutput(new Address(), 9000); f1.addOutput(new Address(), 9000);
// balance: 11000 // balance: 11000
yield w.sign(f1); w.sign(f1);
f1 = f1.toTX(); f1 = f1.toTX();
fake = new MTX(); fake = new MTX();
@ -136,7 +115,7 @@ describe('Mempool', function() {
fake.addOutput(w.getAddress(), 6000); // 6000 instead of 500 fake.addOutput(w.getAddress(), 6000); // 6000 instead of 500
// Script inputs but do not sign // Script inputs but do not sign
yield w.template(fake); w.template(fake);
// Fake signature // Fake signature
fake.inputs[0].script.set(0, encoding.ZERO_SIG); fake.inputs[0].script.set(0, encoding.ZERO_SIG);

View File

@ -177,6 +177,10 @@ MemWallet.prototype.removeCoin = function removeCoin(key) {
delete this.coins[key]; delete this.coins[key];
}; };
MemWallet.prototype.getAddress = function getAddress() {
return this.receive.getAddress();
};
MemWallet.prototype.getReceive = function getReceive() { MemWallet.prototype.getReceive = function getReceive() {
return this.receive.getAddress(); return this.receive.getAddress();
}; };
@ -353,6 +357,11 @@ MemWallet.prototype.fund = function fund(mtx, options) {
}); });
}; };
MemWallet.prototype.template = function template(mtx) {
var keys = this.deriveInputs(mtx);
mtx.template(keys);
};
MemWallet.prototype.sign = function sign(mtx) { MemWallet.prototype.sign = function sign(mtx) {
var keys = this.deriveInputs(mtx); var keys = this.deriveInputs(mtx);
mtx.template(keys); mtx.template(keys);