Skip to content

Commit

Permalink
test: add tests for new methods
Browse files Browse the repository at this point in the history
  • Loading branch information
emjshrx committed Feb 10, 2024
1 parent 85b18ef commit ec4445e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
10 changes: 10 additions & 0 deletions test/wallet-db.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ describe('Wallet DB', () => {
expect(await walletDB.getVersion()).toBe(1);
});

it('should set and retrieve encryptedPrivateKey and encryptedChainCode', async () => {
const samplePrivateKey = 'samplePrivateKey';
const sampleChainCode = 'sampleChainCode';
await walletDB.setMasterKey(samplePrivateKey, sampleChainCode);
const { encryptedPrivateKey, encryptedChainCode } =
await walletDB.getMasterKey();
expect(encryptedPrivateKey).toStrictEqual(samplePrivateKey);
expect(encryptedChainCode).toStrictEqual(sampleChainCode);
});

afterAll(async () => {
await walletDB.close();
fs.rmSync('./test/wallet-db', { recursive: true, force: true });
Expand Down
44 changes: 41 additions & 3 deletions test/wallet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ describe('Wallet', () => {
});

it('should initialise the wallet', async () => {
await wallet.init(
'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about',
);
await wallet.init({
mnemonic:
'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about',
});
});

it('should derive first receive address', async () => {
Expand Down Expand Up @@ -132,3 +133,40 @@ describe('Wallet', () => {
fs.rmSync('./test/wallet', { recursive: true, force: true });
});
});

describe('Wallet - DB', () => {
let wallet: Wallet;

beforeAll(async () => {
const walletDB = new WalletDB({
location: './test/wallet',
});

wallet = new Wallet({
db: walletDB,
networkClient: new EsploraClient({
protocol: 'http',
host: '127.0.0.1:8094',
network: 'regtest',
}),
});
await wallet.init({
mnemonic:
'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about',
password: 'samplePassword',
});
});

it('should write masterKey with new password', async () => {
await wallet.setPassword('newPassword');
await wallet.close();
await wallet.init({ password: 'newPassword' });
const address = await wallet.deriveReceiveAddress();
expect(address).toBe('bcrt1qcr8te4kr609gcawutmrza0j4xv80jy8zeqchgx');
});

afterAll(async () => {
await wallet.close();
fs.rmSync('./test/wallet', { recursive: true, force: true });
});
});

0 comments on commit ec4445e

Please sign in to comment.