Skip to content

Commit

Permalink
Merge pull request #709 from BoltzExchange/post-release-fixes
Browse files Browse the repository at this point in the history
Post release fixes
michael1011 authored Nov 5, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 183160c + 26262e4 commit fb94ef9
Showing 5 changed files with 57 additions and 18 deletions.
7 changes: 6 additions & 1 deletion lib/chain/ElementsWrapper.ts
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import Logger from '../Logger';
import { allSettledFirst, sleep } from '../PromiseUtils';
import { formatError } from '../Utils';
import { CurrencyType } from '../consts/Enums';
import { liquidSymbol } from '../consts/LiquidTypes';
import { MempoolAcceptResult, UnspentUtxo } from '../consts/Types';
import { AddressType, ChainClientEvents } from './ChainClient';
import ElementsClient, {
@@ -32,6 +33,10 @@ class ElementsWrapper

this.zeroConfCheckTime =
config.zeroConfWaitTime || ElementsWrapper.zeroConfCheckTimeDefault;
this.logger.info(
`Waiting ${this.zeroConfCheckTime}ms before accepting ${liquidSymbol} transactions`,
);

this.clients.push(new ElementsClient(this.logger, config, false));

if (config.lowball !== undefined) {
@@ -70,7 +75,7 @@ class ElementsWrapper
return;
}

this.logger.silly(
this.logger.debug(
`Waiting before accepting 0-conf transaction of ${this.symbol}: ${transaction.getId()}`,
);
await sleep(this.zeroConfCheckTime);
9 changes: 8 additions & 1 deletion lib/sidecar/Sidecar.ts
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@ class Sidecar extends BaseClient<
public static readonly symbol = 'Boltz';
public static readonly serviceName = 'sidecar';

private static readonly dirtySuffix = '-dirty';
private static readonly isProduction = process.env.NODE_ENV === 'production';

private static childProcess?: child_process.ChildProcessWithoutNullStreams;
@@ -168,7 +169,8 @@ class Sidecar extends BaseClient<
const ourVersion = getVersion();

const versionCompatible = Sidecar.isProduction
? info.version === ourVersion
? Sidecar.trimDirtySuffix(info.version) ===
Sidecar.trimDirtySuffix(ourVersion)
: info.version.split('-')[0] === ourVersion.split('-')[0];

if (!versionCompatible) {
@@ -504,6 +506,11 @@ class Sidecar extends BaseClient<
toObject,
);
};

private static trimDirtySuffix = (version: string): string =>
version.endsWith(Sidecar.dirtySuffix)
? version.slice(0, -Sidecar.dirtySuffix.length)
: version;
}

export default Sidecar;
3 changes: 2 additions & 1 deletion lib/wallet/providers/CoreWalletProvider.ts
Original file line number Diff line number Diff line change
@@ -40,7 +40,8 @@ class CoreWalletProvider implements WalletProviderInterface {
utxos.forEach((utxo) => {
const amount = BigInt(Math.round(utxo.amount * ChainClient.decimals));

if (isTxConfirmed(utxo)) {
// Core considers its change as safe to spend, so should we
if (isTxConfirmed(utxo) || utxo.safe) {
confirmed += amount;
} else {
unconfirmed += amount;
48 changes: 33 additions & 15 deletions test/integration/wallet/providers/CoreWalletProvider.spec.ts
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import Logger from '../../../../lib/Logger';
import { AddressType } from '../../../../lib/chain/ChainClient';
import CoreWalletProvider from '../../../../lib/wallet/providers/CoreWalletProvider';
import { SentTransaction } from '../../../../lib/wallet/providers/WalletProviderInterface';
import { bitcoinClient } from '../../Nodes';
import { bitcoinClient, bitcoinLndClient } from '../../Nodes';

jest.mock('../../../../lib/db/repositories/ChainTipRepository');

@@ -74,11 +74,15 @@ describe('CoreWalletProvider', () => {

beforeAll(async () => {
initEccLib(ecc);
await bitcoinClient.connect();
await Promise.all([
bitcoinClient.connect(),
bitcoinLndClient.connect(false),
]);
});

afterAll(() => {
bitcoinClient.disconnect();
bitcoinLndClient.disconnect();
});

beforeEach(async () => {
@@ -122,22 +126,36 @@ describe('CoreWalletProvider', () => {
});
});

it('should get balance', async () => {
const balance = await provider.getBalance();
describe('getBalance', () => {
it('should get confirmed balance', async () => {
const balance = await provider.getBalance();

expect(balance.confirmedBalance).toBeGreaterThan(0);
});
expect(balance.confirmedBalance).toBeGreaterThan(0);
});

it('should get unconfirmed balance correctly', async () => {
await provider.sendToAddress(
await provider.getAddress(''),
10000,
undefined,
'',
);
it('should get safe unconfirmed balance correctly', async () => {
await provider.sendToAddress(
await provider.getAddress(''),
10000,
undefined,
'',
);

const balance = await provider.getBalance();
expect(balance.unconfirmedBalance).toBeGreaterThan(0);
const balance = await provider.getBalance();
expect(balance.unconfirmedBalance).toEqual(0);
});

it('should get unsafe unconfirmed balance correctly', async () => {
await bitcoinLndClient.sendCoins(
await provider.getAddress(''),
10_000,
undefined,
'',
);

const balance = await provider.getBalance();
expect(balance.unconfirmedBalance).toBeGreaterThan(0);
});
});

it('should send transactions', async () => {
8 changes: 8 additions & 0 deletions test/unit/sidecar/Sidecar.spec.ts
Original file line number Diff line number Diff line change
@@ -57,4 +57,12 @@ describe('Sidecar', () => {
);
});
});

describe('trimDirtySuffix', () => {
test('should trim dirty suffix', () => {
const version = '3.8.0-1ec2944b';

expect(Sidecar['trimDirtySuffix'](`${version}-dirty`)).toEqual(version);
});
});
});

0 comments on commit fb94ef9

Please sign in to comment.