Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post release fixes #709

Merged
merged 3 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/chain/ElementsWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 8 additions & 1 deletion lib/sidecar/Sidecar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion lib/wallet/providers/CoreWalletProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
48 changes: 33 additions & 15 deletions test/integration/wallet/providers/CoreWalletProvider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down
8 changes: 8 additions & 0 deletions test/unit/sidecar/Sidecar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});