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

fix: mocha tests #263

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions .github/workflows/e2e-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ jobs:
working-directory: lib
run: yarn build

- name: Remove lib node_modules
working-directory: lib
run: rm -rf node_modules

- name: Use gradle caches
uses: actions/cache@v4
with:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/e2e-ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ jobs:
working-directory: lib
run: yarn build

- name: Remove lib node_modules
working-directory: lib
run: rm -rf node_modules

- name: Install Dependencies
working-directory: example
run: (yarn || yarn) && yarn rn-setup
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/mocha-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ jobs:
working-directory: lib
run: yarn build

- name: Remove lib node_modules
working-directory: lib
run: rm -rf node_modules

- name: Use gradle caches
uses: actions/cache@v4
with:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/mocha-ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ jobs:
working-directory: lib
run: yarn build

- name: Remove lib node_modules
working-directory: lib
run: rm -rf node_modules

- name: Install Dependencies
working-directory: example
run: (yarn || yarn) && yarn rn-setup
Expand Down
19 changes: 11 additions & 8 deletions example/Tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,17 @@ class Tests extends Component {
});
// global.fs = require("react-native-fs");
// global.path = require("path-browserify");
global.environment = {
// Default to the host machine when running on Android
// realmBaseUrl: Platform.OS === "android" ? "http://10.0.2.2:9090" : undefined,
...context,
// reactNative: Platform.OS,
// android: Platform.OS === "android",
// ios: Platform.OS === "ios",
};
// global.environment = {
// Default to the host machine when running on Android
// realmBaseUrl: Platform.OS === "android" ? "http://10.0.2.2:9090" : undefined,
// ...context,
// reactNative: Platform.OS,
// android: Platform.OS === "android",
// ios: Platform.OS === "ios",
// };
global.environment = JSON.parse(
Buffer.from(context.c as string, 'hex').toString('utf-8'),
);
// Make the tests reinitializable, to allow test running on changes to the "realm" package
// Probing the existance of `getModules` as this only exists in debug mode
// if ("getModules" in require) {
Expand Down
14 changes: 6 additions & 8 deletions example/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3'
services:
bitcoind:
container_name: bitcoin
Expand Down Expand Up @@ -112,12 +111,10 @@ services:
depends_on:
- bitcoind
expose:
- '18080' # REST
- '18081' # DOCPORT
- '18081' # REST
- '9736' # P2P
- '11001' # RPC
ports:
- '18080:18080'
- '18081:18081'
- '9736:9736'
- '11001:11001'
Expand All @@ -135,11 +132,12 @@ services:
- '--dev-bitcoind-poll=2'
- '--dev-fast-gossip'
- '--grpc-port=11001'
- '--log-file=-' # log to stdo
- '--bitcoin-rpcport=18443'
- '--plugin=/opt/c-lightning-rest/plugin.js'
- '--rest-port=18080'
- '--rest-protocol=http'
- '--rest-docport=18081'
- '--clnrest-port=18081'
- '--clnrest-protocol=http'
- '--clnrest-host=0.0.0.0'
- '--developer'

eclair:
container_name: eclair
Expand Down
6 changes: 3 additions & 3 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
"reinstall": "cd ../lib/ && yarn install && yarn build && cd ../example/ && yarn add ../lib && yarn rn-setup",
"clean": "rm -rf node_modules ios/Pods ios/Podfile.lock ios/build && yarn install && cd ios && pod deintegrate && pod install && cd ../",
"rn-setup": "node rn-setup.js",
"test:mocha": "mocha-remote --context lndmacaroon=$(xxd -ps -u -c 1000 docker/lnd/admin.macaroon) clmacaroon=$(xxd -ps -u -c 1000 docker/clightning/access.macaroon)",
"test:mocha:ios": "mocha-remote --context lndmacaroon=$(xxd -ps -u -c 1000 docker/lnd/admin.macaroon) clmacaroon=$(xxd -ps -u -c 1000 docker/clightning/access.macaroon) -- concurrently --kill-others-on-fail npm:m npm:runner-ios",
"test:mocha:android": "mocha-remote --context lndmacaroon=$(xxd -ps -u -c 1000 docker/lnd/admin.macaroon) clmacaroon=$(xxd -ps -u -c 1000 docker/clightning/access.macaroon) -- concurrently --kill-others-on-fail npm:m npm:runner-android",
"test:mocha": "mocha-remote --context --context c=$(node ./tests/context.js)",
"test:mocha:ios": "mocha-remote --context --context c=$(node ./tests/context.js) -- concurrently --kill-others-on-fail npm:m npm:runner-ios",
"test:mocha:android": "mocha-remote --context --context c=$(node ./tests/context.js) -- concurrently --kill-others-on-fail npm:m npm:runner-android",
"m": "react-native start --reset-cache",
"runner-ios": "react-native run-ios --simulator='iPhone 14' --no-packager",
"runner-android": "react-native run-android --no-packager"
Expand Down
40 changes: 21 additions & 19 deletions example/tests/clightning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import {
const bitcoinURL = 'http://polaruser:polarpass@localhost:9091';
const clConfig = {
host: 'localhost',
port: 18080,
macaroon: global.environment.clmacaroon,
port: 18081,
rune: global.environment.lcrune,
};

describe.skip('Clightning', function () {
Expand All @@ -51,7 +51,7 @@ describe.skip('Clightning', function () {
balance = await rpc.getBalance();
}

const { address: lndAddress } = await cl.newAddr();
const { bech32: lndAddress } = await cl.newAddr();
await rpc.sendToAddress(lndAddress, '1');
await rpc.generateToAddress(1, await rpc.getNewAddress());

Expand Down Expand Up @@ -107,6 +107,18 @@ describe.skip('Clightning', function () {
// - make a few payments

await ldk.stop();

if (!skipRemoteBackups) {
const backupRes = await ldk.backupSetup({
network: ENetworks.regtest,
seed: profile.getAccount().seed,
details: backupServerDetails,
});
if (backupRes.isErr()) {
throw backupRes.error;
}
}

const lmStart = await lm.start({
...profile.getStartParams(),
// getBestBlock: getBestBlock,
Expand All @@ -124,17 +136,6 @@ describe.skip('Clightning', function () {
throw lmStart.error;
}

if (!skipRemoteBackups) {
const backupRes = await ldk.backupSetup({
network: ENetworks.regtest,
seed: profile.getAccount().seed,
details: backupServerDetails,
});
if (backupRes.isErr()) {
throw backupRes.error;
}
}

const nodeId = await ldk.nodeId();
if (nodeId.isErr()) {
throw nodeId.error;
Expand All @@ -155,8 +156,9 @@ describe.skip('Clightning', function () {
// wait for peer to be connected
let n = 0;
while (true) {
const peers = await cl.listPeers();
if (peers.some((p) => p.id === nodeId.value)) {
const { peers } = await cl.listPeers();
const peer = peers.find((p) => p.id === nodeId.value);
if (peer && peer.connected) {
break;
}
await sleep(1000);
Expand All @@ -166,10 +168,10 @@ describe.skip('Clightning', function () {
}

// open a channel
await cl.openChannel({
await cl.fundchannel({
id: nodeId.value,
satoshis: '100000',
// private: true,
amount: '100000',
announce: false,
});
await rpc.generateToAddress(10, await rpc.getNewAddress());
await waitForElectrum({ cl: true });
Expand Down
18 changes: 18 additions & 0 deletions example/tests/context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const fs = require('fs');
const run = require('child_process').execSync;

// read lnd macaroon
const lndmacaroon = fs
.readFileSync('docker/lnd/admin.macaroon')
.toString('hex')
.toUpperCase();

// run command to read clightnng rune
const clightning = run(
'cd docker; docker compose exec --user clightning clightning lightning-cli createrune --regtest',
);
const lcrune = JSON.parse(clightning).rune;

const context = { lndmacaroon, lcrune };
const encoded = Buffer.from(JSON.stringify(context)).toString('hex');
console.log(encoded);
49 changes: 23 additions & 26 deletions example/tests/eclair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ describe('Eclair', function () {
balance = await rpc.getBalance();
}

// const ecAddress = await ec.getnewaddress();
// await rpc.sendToAddress(ecAddress, '1');
await rpc.generateToAddress(1, await rpc.getNewAddress());
const ecAddress = await ec.getnewaddress();
await rpc.sendToAddress(ecAddress, '1');
await rpc.generateToAddress(6, await rpc.getNewAddress());

const storageRes = await lm.setBaseStoragePath(
`${RNFS.DocumentDirectoryPath}/ldk/`,
Expand Down Expand Up @@ -101,23 +101,6 @@ describe('Eclair', function () {
// - make a few payments

await ldk.stop();
const lmStart = await lm.start({
...profile.getStartParams(),
getFees: () => {
return Promise.resolve({
onChainSweep: 30,
maxAllowedNonAnchorChannelRemoteFee: Math.max(25, 30 * 10),
minAllowedAnchorChannelRemoteFee: 5,
minAllowedNonAnchorChannelRemoteFee: Math.max(5 - 1, 0),
anchorChannelFee: 10,
nonAnchorChannelFee: 20,
channelCloseMinimum: 5,
});
},
});
if (lmStart.isErr()) {
throw lmStart.error;
}

if (!skipRemoteBackups) {
const backupRes = await ldk.backupSetup({
Expand All @@ -130,6 +113,13 @@ describe('Eclair', function () {
}
}

const lmStart = await lm.start({
...profile.getStartParams(),
});
if (lmStart.isErr()) {
throw lmStart.error;
}

const nodeId = await ldk.nodeId();
if (nodeId.isErr()) {
throw nodeId.error;
Expand Down Expand Up @@ -160,12 +150,19 @@ describe('Eclair', function () {
}

// open a channel
await ec.open({
const open = await ec.open({
nodeId: nodeId.value,
fundingSatoshis: 100000,
fundingSatoshis: 10000000,
fundingFeeBudgetSatoshis: 2000,
fundingFeerateSatByte: 1,
announceChannel: false,
// channelType: 'anchor_outputs_zero_fee_htlc_tx',
});

if (open.includes('error')) {
throw open;
}

await rpc.generateToAddress(10, await rpc.getNewAddress());
await waitForElectrum({ ec: true });

Expand All @@ -191,7 +188,7 @@ describe('Eclair', function () {
}
}

// CL -> LDK, 0 sats
// Eclair -> LDK, 0 sats
const inv1 = await lm.createAndStorePaymentRequest({
amountSats: 0,
description: 'trololo',
Expand All @@ -205,7 +202,7 @@ describe('Eclair', function () {
amountMsat: 10000 * 1000, // milli-sats
});

// CL -> LDK, 1000 sats
// Eclair -> LDK, 1000 sats
const inv2 = await lm.createAndStorePaymentRequest({
amountSats: 1000,
description: 'ololo',
Expand All @@ -218,7 +215,7 @@ describe('Eclair', function () {

// FIXME LDK -> ECLAIR doesn't work

// // LDK -> CL, 0 sats
// LDK -> Eclair, 0 sats
// const { serialized: invoice3 } = await ec.createinvoice({
// // amount: 0,
// // label: 'payment3' + new Date(),
Expand All @@ -233,7 +230,7 @@ describe('Eclair', function () {
// throw pay3.error;
// }

// LDK -> CL, 444 sats
// // LDK -> Eclair, 444 sats
// const { serialized: invoice4 } = await ec.createinvoice({
// amountMsat: 444000, // milisats
// // label: 'payment4' + new Date(),
Expand Down
Loading
Loading