This repository has been archived by the owner on Feb 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LL-6959 Add estimateAccountMaxSpendable (#39)
* add estimateAccountMaxSpendable * add test for estimateMaxSpendable
- Loading branch information
1 parent
dface0a
commit 83bc0b9
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import WalletLedger from '../wallet'; | ||
import * as utils from '../utils'; | ||
import { Account } from '../account'; | ||
import MockBtc from './mocks/Btc'; | ||
|
||
describe('testing estimateMaxSpendable', () => { | ||
const wallet = new WalletLedger(); | ||
let account: Account; | ||
it('should generate an account', async () => { | ||
account = await wallet.generateAccount({ | ||
btc: new MockBtc(), | ||
path: "44'/0'", | ||
index: 0, | ||
network: 'mainnet', | ||
derivationMode: 'Legacy', | ||
explorer: 'ledgerv3', | ||
explorerURI: 'https://explorers.api.vault.ledger.com/blockchain/v3/btc', | ||
storage: 'mock', | ||
storageParams: [], | ||
}); | ||
|
||
expect(account.xpub.xpub).toEqual( | ||
'xpub6CV2NfQJYxHn7MbSQjQip3JMjTZGUbeoKz5xqkBftSZZPc7ssVPdjKrgh6N8U1zoQDxtSo6jLarYAQahpd35SJoUKokfqf1DZgdJWZhSMqP' | ||
); | ||
}); | ||
|
||
it('should estimate max spendable correctly', async () => { | ||
await wallet.syncAccount(account); | ||
let maxSpendable = await wallet.estimateAccountMaxSpendable(account, 0); | ||
const balance = 109088; | ||
expect(maxSpendable.toNumber()).toEqual(balance); | ||
let feesPerByte = 100; | ||
maxSpendable = await wallet.estimateAccountMaxSpendable(account, feesPerByte); | ||
expect(maxSpendable.toNumber()).toEqual( | ||
balance - feesPerByte * utils.estimateTxSize(2, 1, account.xpub.crypto, account.xpub.derivationMode) | ||
); | ||
feesPerByte = 10000; | ||
maxSpendable = await wallet.estimateAccountMaxSpendable(account, feesPerByte); | ||
expect(maxSpendable.toNumber()).toEqual(0); | ||
}, 60000); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters