Skip to content

Commit

Permalink
[FIX] Do not allow creation of account if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielbazan7 committed Jun 19, 2024
1 parent 405f8b1 commit 76cf531
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/bitcore-wallet-client/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3095,8 +3095,8 @@ export class API extends EventEmitter {
settings.account++;
const clonedSettings = JSON.parse(JSON.stringify(settings));
let c = key.createCredentials(null, {
coin: clonedSettings.coin,
chain: clonedSettings.coin, // chain === coin for stored clients
coin: clonedSettings.coin, // base currency used for fees. Helpful for UI
chain: clonedSettings.chain || clonedSettings.coin,
network: clonedSettings.network,
account: clonedSettings.account,
n: clonedSettings.n,
Expand Down
56 changes: 56 additions & 0 deletions packages/bitcore-wallet-client/test/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7268,6 +7268,62 @@ describe('client API', function() {
});
});

it('should be able to gain access to three arb accounts from mnemonic and add wallet info correctly to all of them', done => {
let key = new Key({ seedType: 'new' });
helpers.createAndJoinWallet(clients, keys, 1, 1, {key, coin: 'eth', chain: 'arb'}, () => {
helpers.createAndJoinWallet(clients, keys, 1, 1, {key, coin: 'eth', chain: 'arb', account: 1}, () => {
helpers.createAndJoinWallet(clients, keys, 1, 1, {key, coin: 'eth', chain: 'arb', account: 2}, () => {
var words = keys[0].get(null, true).mnemonic;
var walletName = clients[0].credentials.walletName;
var copayerName = clients[0].credentials.copayerName;
clients[0].createAddress((err, addr) => {
should.not.exist(err);
should.exist(addr);
Client.serverAssistedImport(
{ words, includeTestnetWallets: true },
{
clientFactory: () => {
return helpers.newClient(app);
}
},
(err, k, c) => {
should.not.exist(err);
c.length.should.equal(3);
c[0].credentials.coin.should.equal('eth');
c[1].credentials.coin.should.equal('eth');
c[2].credentials.coin.should.equal('eth');
c[0].credentials.chain.should.equal('arb');
c[1].credentials.chain.should.equal('arb');
c[2].credentials.chain.should.equal('arb');
c[0].credentials.account.should.equal(0);
c[1].credentials.account.should.equal(1);
c[2].credentials.account.should.equal(2);
c[0].credentials.copayerId.should.not.equal(c[1].credentials.copayerId);
c[0].credentials.copayerId.should.not.equal(c[2].credentials.copayerId);
c[1].credentials.copayerId.should.not.equal(c[2].credentials.copayerId);
should.exist(c[0].credentials.walletId);
should.exist(c[1].credentials.walletId);
should.exist(c[2].credentials.walletId);
let recoveryClient = c[2];
recoveryClient.openWallet(err => {
should.not.exist(err);
recoveryClient.credentials.walletName.should.equal(walletName);
recoveryClient.credentials.copayerName.should.equal(copayerName);
recoveryClient.getMainAddresses({}, (err, list) => {
should.not.exist(err);
should.exist(list);
list[0].address.should.equal(addr.address);
done();
});
});
}
);
});
});
});
});
});

it('should be able to gain access to a 1-1 wallet from mnemonic with passphrase', done => {
let passphrase = 'xxx';
helpers.createAndJoinWallet(clients, keys, 1, 1, { passphrase }, () => {
Expand Down
26 changes: 26 additions & 0 deletions packages/bitcore-wallet-client/test/bulkclient.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,32 @@ describe('Bulk Client', function () {
});
});

it('returns two arb wallets and token wallets associated with one of them', done => {
let key = new Key({ seedType: 'new' });
helpers.createAndJoinWallet(clients, keys, 1, 1, { coin: 'eth', chain: 'arb', key: key, network: 'livenet' }, () => {
helpers.createAndJoinWallet(clients.slice(1), keys, 1, 1, { coin: 'eth', chain: 'arb', key: key, account: 1, network: 'livenet' }, () => {
let walletOptions = {
[clients[0].credentials.copayerId]: {
tokenAddresses: [
'0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
'0x056fd409e1d7a124bd7017459dfea2f387b6d5cd'
]
}
};

clients[0].bulkClient.getStatusAll([clients[0].credentials, clients[1].credentials], { includeExtendedInfo: true, twoStep: true, wallets: walletOptions }, (err, wallets) => {
should.not.exist(err);
wallets.length.should.equal(4);
wallets.filter(wallet => wallet.tokenAddress === null).length.should.equal(2);
wallets.findIndex(wallet => wallet.tokenAddress === '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48').should.be.above(-1);
wallets.findIndex(wallet => wallet.tokenAddress === '0x056fd409e1d7a124bd7017459dfea2f387b6d5cd').should.be.above(-1);

done();
});
});
});
});

it('fails gracefully when given bad signature', done => {
clients[0].fromString(
k.createCredentials(null, {
Expand Down

0 comments on commit 76cf531

Please sign in to comment.