Skip to content

Commit

Permalink
reregisted addresses if wallet is deregister
Browse files Browse the repository at this point in the history
  • Loading branch information
matiu committed Oct 16, 2019
1 parent aef3b89 commit 1de7bb1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
8 changes: 4 additions & 4 deletions packages/bitcore-wallet-service/src/lib/server.ts
Expand Up @@ -3896,7 +3896,7 @@ export class WalletService {
return cb(err);
}
wallet.beRegistered = true;
return this.storage.storeWallet(wallet, cb);
return this.storage.storeWallet(wallet, (err) => { return cb(err, true); });
});
}

Expand Down Expand Up @@ -3959,16 +3959,15 @@ export class WalletService {
}

this.updateWalletV8Keys(wallet);

this.registerWalletV8(wallet, err => {
this.registerWalletV8(wallet, (err, justRegistered) => {
if (err) {
return cb(err);
}

// First
this.checkWalletSync(bc, wallet, true, (err, isOK) => {
// ignore err
if (isOK) return cb();
if (isOK && !justRegistered) return cb();

this.storage.fetchUnsyncAddresses(this.walletId, (err, addresses) => {
if (err) {
Expand Down Expand Up @@ -4225,6 +4224,7 @@ export class WalletService {
async.series(
[
next => {

// be sure the wallet is onsync
this.syncWallet(wallet, next, true);
},
Expand Down
Expand Up @@ -463,7 +463,7 @@ helpers.createTxsV8 = function(nr, bcHeight, txs) {
};


helpers.stubHistoryV8 = function(nr, bcHeight, txs) {
helpers.stubHistory = function(nr, bcHeight, txs) {
txs= helpers.createTxsV8(nr,bcHeight, txs);
blockchainExplorer.getTransactions = function(walletId, startBlock, cb) {
startBlock = startBlock || 0;
Expand Down
34 changes: 32 additions & 2 deletions packages/bitcore-wallet-service/test/integration/server.js
Expand Up @@ -5365,7 +5365,7 @@ describe('#createTX ETH Only tests', () => {
amount: 200,
}],
}];
helpers.stubHistoryV8(null, null, txs);
helpers.stubHistory(null, null, txs);
helpers.stubFeeLevels({
24: 10000,
});
Expand Down Expand Up @@ -8215,7 +8215,7 @@ describe('#createTX ETH Only tests', () => {
});
});

describe('Sync wallet with grouping block explorer', function() {
describe('Sync wallet', function() {
var server, wallet;
beforeEach(function(done) {

Expand Down Expand Up @@ -8253,6 +8253,36 @@ describe('#createTX ETH Only tests', () => {
});
});

it('should reregisted address is wallet is deregistered', function(done) {
helpers.stubFeeLevels({
1: 40002,
2: 20000,
6: 18000,
24: 9001,
}, true);


server.createAddress({}, function(err, address1) {
helpers.stubHistory(2, 1000);

// deregisted the wallet
server.storage.deregisterWallet(wallet.id, () => {
wallet.beRegistered = false;
server.getTxHistory({}, function(err) {
should.not.exist(err);
blockchainExplorer.register.calledTwice.should.equal(true);
blockchainExplorer.addAddresses.calledTwice.should.equal(true);
var calls = blockchainExplorer.addAddresses.getCalls();

// both calls should registed the same addr
calls[0].args[1].should.deep.equal([address1.address]);
calls[1].args[1].should.deep.equal([address1.address]);
done();
});
});
});
});

it('should sync all wallet address if a first sync failed', function(done) {
blockchainExplorer.addAddresses = sinon.stub().callsArgWith(2, 'error');
server.createAddress({}, function(err, address1) {
Expand Down

0 comments on commit 1de7bb1

Please sign in to comment.