Skip to content

Commit f76b511

Browse files
committed
Fix ConnectWallet and tests
Fix REST case to use DEVICE_DOMAIN_NAME instead of HIDDEN_SERVICE_URL since this was just REST not REST (Tor). Add new values and renamed values to test-utilities walletConnect Fix unit tests in ConnectWallet.test.tsx
1 parent 4ebb932 commit f76b511

File tree

3 files changed

+46
-37
lines changed

3 files changed

+46
-37
lines changed

apps/frontend/src/components/modals/ConnectWallet/ConnectWallet.test.tsx

+39-32
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ describe('ConnectWallet component ', () => {
1818
expect(screen.getByText('LN Message')).toBeInTheDocument();
1919
expect(screen.getByTestId('port')).toHaveValue('5001');
2020
expect(screen.getByTestId('host')).toHaveValue('user.local');
21-
expect(screen.getByTestId('macaroon')).toHaveValue('mRXhnFyVWrRQChA9eJ01RQT9W502daqrP0JA4BiHHw89MCZGb3IgQXBwbGljYXRpb24j');
22-
expect(screen.getByTestId('connect-url')).toHaveValue('ln-message://user.local:5001?rune=mRXhnFyVWrRQChA9eJ01RQT9W502daqrP0JA4BiHHw89MCZGb3IgQXBwbGljYXRpb24j');
21+
expect(screen.getByTestId('rune')).toHaveValue('mRXhnFyVWrRQChA9eJ01RQT9W502daqrP0JA4BiHHw89MCZGb3IgQXBwbGljYXRpb24j');
22+
expect(screen.getByTestId('connect-url')).toHaveValue(
23+
'ln-message://user.local:5001?rune=mRXhnFyVWrRQChA9eJ01RQT9W502daqrP0JA4BiHHw89MCZGb3IgQXBwbGljYXRpb24j&invoiceRune=aHFhnFyVWrRQChA9eJ01RQT9W502daqrP0JA4BiHHw89MCZGb3IgQXBwbGljYXRpb2==',
24+
);
2325
expect(screen.getByTestId('invoice-rune')).toHaveValue('aHFhnFyVWrRQChA9eJ01RQT9W502daqrP0JA4BiHHw89MCZGb3IgQXBwbGljYXRpb2==');
2426
expect(screen.queryByTestId('invoice-rune-spinner')).not.toBeInTheDocument();
2527
});
@@ -41,10 +43,12 @@ describe('ConnectWallet component ', () => {
4143

4244
expect(screen.getByTestId('port')).toHaveValue('5001');
4345
expect(screen.getByTestId('host')).toHaveValue('user.local');
44-
expect(screen.getByTestId('macaroon')).toHaveValue('mRXhnFyVWrRQChA9eJ01RQT9W502daqrP0JA4BiHHw89MCZGb3IgQXBwbGljYXRpb24j');
46+
expect(screen.getByTestId('rune')).toHaveValue('mRXhnFyVWrRQChA9eJ01RQT9W502daqrP0JA4BiHHw89MCZGb3IgQXBwbGljYXRpb24j');
4547
expect(screen.queryByTestId('client-cert')).not.toBeInTheDocument();
4648
expect(screen.queryByTestId('ca-cert')).not.toBeInTheDocument();
47-
expect(screen.getByTestId('connect-url')).toHaveValue('ln-message://user.local:5001?rune=mRXhnFyVWrRQChA9eJ01RQT9W502daqrP0JA4BiHHw89MCZGb3IgQXBwbGljYXRpb24j');
49+
expect(screen.getByTestId('connect-url')).toHaveValue(
50+
'ln-message://user.local:5001?rune=mRXhnFyVWrRQChA9eJ01RQT9W502daqrP0JA4BiHHw89MCZGb3IgQXBwbGljYXRpb24j&invoiceRune=aHFhnFyVWrRQChA9eJ01RQT9W502daqrP0JA4BiHHw89MCZGb3IgQXBwbGljYXRpb2==',
51+
);
4852
expect(screen.getByTestId('invoice-rune')).toHaveValue('aHFhnFyVWrRQChA9eJ01RQT9W502daqrP0JA4BiHHw89MCZGb3IgQXBwbGljYXRpb2==');
4953
});
5054

@@ -57,11 +61,13 @@ describe('ConnectWallet component ', () => {
5761
await act(async () => fireEvent.click(restNetworkItem));
5862

5963
expect(screen.getByTestId('port')).toHaveValue('5001');
60-
expect(screen.getByTestId('host')).toHaveValue('oqaer4kd7ufryngx6dsztovs4pnlmaouwmtkofjsd2m7pkq8wd.onion');
61-
expect(screen.getByTestId('macaroon')).toHaveValue('mRXhnFyVWrRQChA9eJ01RQT9W502daqrP0JA4BiHHw89MCZGb3IgQXBwbGljYXRpb24j');
64+
expect(screen.getByTestId('host')).toHaveValue('http://oqaer4kd7ufryngx6dsztovs4pnlmaouwmtkofjsd2m7pkq8wd.onion');
65+
expect(screen.getByTestId('rune')).toHaveValue('mRXhnFyVWrRQChA9eJ01RQT9W502daqrP0JA4BiHHw89MCZGb3IgQXBwbGljYXRpb24j');
6266
expect(screen.queryByTestId('client-cert')).not.toBeInTheDocument();
6367
expect(screen.queryByTestId('ca-cert')).not.toBeInTheDocument();
64-
expect(screen.getByTestId('connect-url')).toHaveValue('ln-message://oqaer4kd7ufryngx6dsztovs4pnlmaouwmtkofjsd2m7pkq8wd.onion:5001?rune=mRXhnFyVWrRQChA9eJ01RQT9W502daqrP0JA4BiHHw89MCZGb3IgQXBwbGljYXRpb24j');
68+
expect(screen.getByTestId('connect-url')).toHaveValue(
69+
'ln-message://http://oqaer4kd7ufryngx6dsztovs4pnlmaouwmtkofjsd2m7pkq8wd.onion:5001?rune=mRXhnFyVWrRQChA9eJ01RQT9W502daqrP0JA4BiHHw89MCZGb3IgQXBwbGljYXRpb24j&invoiceRune=aHFhnFyVWrRQChA9eJ01RQT9W502daqrP0JA4BiHHw89MCZGb3IgQXBwbGljYXRpb2==',
70+
);
6571
expect(screen.getByTestId('invoice-rune')).toHaveValue('aHFhnFyVWrRQChA9eJ01RQT9W502daqrP0JA4BiHHw89MCZGb3IgQXBwbGljYXRpb2==');
6672
});
6773

@@ -73,13 +79,14 @@ describe('ConnectWallet component ', () => {
7379
const restNetworkItem = screen.getAllByTestId('network-item')[2];
7480
await act(async () => fireEvent.click(restNetworkItem));
7581

76-
expect(screen.getByTestId('port')).toHaveValue('3001');
77-
expect(screen.getByTestId('host')).toHaveValue('http://user.local');
78-
expect(screen.getByTestId('macaroon')).toHaveValue('0201036c6e6402e501030a1042beb666ba043f72cb147adf3eaafc9e1201301a160a076164647265737312047265616');
79-
expect(screen.queryByTestId('client-cert')).not.toBeInTheDocument();
80-
expect(screen.queryByTestId('ca-cert')).not.toBeInTheDocument();
81-
expect(screen.getByTestId('connect-url')).toHaveValue('c-lightning-rest://http://user.local:3001?macaroon=0201036c6e6402e501030a1042beb666ba043f72cb147adf3eaafc9e1201301a160a076164647265737312047265616&protocol=http');
82-
expect(screen.queryByTestId('invoice-rune')).not.toBeInTheDocument();
82+
expect(screen.getAllByTestId('port')[1]).toHaveValue('3001');
83+
expect(screen.getByTestId('host')).toHaveValue('user.local');
84+
expect(screen.queryByTestId('client-key')).toBeInTheDocument();
85+
expect(screen.queryByTestId('client-cert')).toBeInTheDocument();
86+
expect(screen.queryByTestId('ca-cert')).toBeInTheDocument();
87+
expect(screen.getByTestId('connect-url')).toHaveValue(
88+
'clnrest://https://user.local:3001?clientKey=ClientKey&clientCert=ClientCert&caCert=CACert',
89+
);
8390
});
8491

8592
it('updates selected network and input fields on network change to REST (Tor)', async () => {
@@ -90,13 +97,13 @@ describe('ConnectWallet component ', () => {
9097
const restNetworkItem = screen.getAllByTestId('network-item')[3];
9198
await act(async () => fireEvent.click(restNetworkItem));
9299

93-
expect(screen.getByTestId('port')).toHaveValue('3001');
100+
expect(screen.getAllByTestId('port')[1]).toHaveValue('3001');
94101
expect(screen.getByTestId('host')).toHaveValue('http://oqaer4kd7ufryngx6dsztovs4pnlmaouwmtkofjsd2m7pkq8wd.onion');
95-
expect(screen.getByTestId('macaroon')).toHaveValue('0201036c6e6402e501030a1042beb666ba043f72cb147adf3eaafc9e1201301a160a076164647265737312047265616');
96-
expect(screen.queryByTestId('client-cert')).not.toBeInTheDocument();
97-
expect(screen.queryByTestId('ca-cert')).not.toBeInTheDocument();
98-
expect(screen.getByTestId('connect-url')).toHaveValue('c-lightning-rest://http://oqaer4kd7ufryngx6dsztovs4pnlmaouwmtkofjsd2m7pkq8wd.onion:3001?macaroon=0201036c6e6402e501030a1042beb666ba043f72cb147adf3eaafc9e1201301a160a076164647265737312047265616&protocol=http');
99-
expect(screen.queryByTestId('invoice-rune')).not.toBeInTheDocument();
102+
expect(screen.queryByTestId('client-key')).toBeInTheDocument();
103+
expect(screen.queryByTestId('client-cert')).toBeInTheDocument();
104+
expect(screen.getByTestId('connect-url')).toHaveValue(
105+
'clnrest://https://http://oqaer4kd7ufryngx6dsztovs4pnlmaouwmtkofjsd2m7pkq8wd.onion:3001?clientKey=ClientKey&clientCert=ClientCert&caCert=CACert',
106+
);
100107
});
101108

102109
it('updates selected network and input fields on network change to gRPC', async () => {
@@ -107,13 +114,12 @@ describe('ConnectWallet component ', () => {
107114
const restNetworkItem = screen.getAllByTestId('network-item')[4];
108115
await act(async () => fireEvent.click(restNetworkItem));
109116

110-
expect(screen.getByTestId('port')).toHaveValue('2106');
117+
expect(screen.getAllByTestId('port')[1]).toHaveValue('2106');
111118
expect(screen.getByTestId('host')).toHaveValue('user.local');
112-
expect(screen.getByTestId('macaroon')).toHaveValue('ClientKey');
113-
expect(screen.getByTestId('client-cert')).toHaveValue('ClientCert');
114-
expect(screen.getByTestId('ca-cert')).toHaveValue('CACert');
115-
expect(screen.getByTestId('connect-url')).toHaveValue('cln-grpc://user.local:2106?clientkey=ClientKey&clientCert=ClientCert&caCert=CACert');
116-
expect(screen.queryByTestId('invoice-rune')).not.toBeInTheDocument();
119+
expect(screen.queryByTestId('client-key')).not.toBeInTheDocument();
120+
expect(screen.queryByTestId('client-cert')).not.toBeInTheDocument();
121+
expect(screen.queryByTestId('ca-cert')).not.toBeInTheDocument();
122+
expect(screen.getByTestId('connect-url')).toHaveValue('cln-grpc://http://user.local:2106');
117123
});
118124

119125
it('updates selected network and input fields on network change to gRPC (Tor)', async () => {
@@ -123,13 +129,14 @@ describe('ConnectWallet component ', () => {
123129
await act(async () => fireEvent.click(screen.getByTestId('network-toggle')));
124130
const restNetworkItem = screen.getAllByTestId('network-item')[5];
125131
await act(async () => fireEvent.click(restNetworkItem));
126-
expect(screen.getByTestId('port')).toHaveValue('2106');
127-
expect(screen.getByTestId('host')).toHaveValue('oqaer4kd7ufryngx6dsztovs4pnlmaouwmtkofjsd2m7pkq8wd.onion');
128-
expect(screen.getByTestId('macaroon')).toHaveValue('ClientKey');
129-
expect(screen.getByTestId('client-cert')).toHaveValue('ClientCert');
132+
expect(screen.getAllByTestId('port')[1]).toHaveValue('2106');
133+
expect(screen.getByTestId('host')).toHaveValue('http://oqaer4kd7ufryngx6dsztovs4pnlmaouwmtkofjsd2m7pkq8wd.onion');
134+
expect(screen.queryByTestId('client-key')).not.toBeInTheDocument();
135+
expect(screen.queryByTestId('client-cert')).not.toBeInTheDocument();
130136
expect(screen.queryByTestId('ca-cert')).not.toBeInTheDocument();
131-
expect(screen.getByTestId('connect-url')).toHaveValue('cln-grpc://oqaer4kd7ufryngx6dsztovs4pnlmaouwmtkofjsd2m7pkq8wd.onion:2106?clientkey=ClientKey&clientCert=ClientCert');
132-
expect(screen.queryByTestId('invoice-rune')).not.toBeInTheDocument();
137+
expect(screen.getByTestId('connect-url')).toHaveValue(
138+
'cln-grpc://http://http://oqaer4kd7ufryngx6dsztovs4pnlmaouwmtkofjsd2m7pkq8wd.onion:2106',
139+
);
133140
});
134141

135142
it('when creating an invoice rune, display loading spinner', async () => {

apps/frontend/src/components/modals/ConnectWallet/ConnectWallet.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ const ConnectWallet = () => {
124124
break;
125125

126126
case 'REST':
127-
setConnectValues({ protocol: { title: 'REST Protocol', field: 'LIGHTNING_REST_PROTOCOL' }, host: { title: 'CLN Host', field: 'HIDDEN_SERVICE_URL' }, port: { title: 'REST Port', field: 'LIGHTNING_REST_PORT' }, clientKey: { title: 'Client Key', field: 'CLIENT_KEY' }, clientCert: { title: 'Client Cert', field: 'CLIENT_CERT' }, caCert: { title: 'CA Cert', field: 'CA_CERT' }, connectUrl: { title: 'REST URL', field: '' } });
127+
setConnectValues({ protocol: { title: 'REST Protocol', field: 'LIGHTNING_REST_PROTOCOL' }, host: { title: 'CLN Host', field: 'DEVICE_DOMAIN_NAME' }, port: { title: 'REST Port', field: 'LIGHTNING_REST_PORT' }, clientKey: { title: 'Client Key', field: 'CLIENT_KEY' }, clientCert: { title: 'Client Cert', field: 'CLIENT_CERT' }, caCert: { title: 'CA Cert', field: 'CA_CERT' }, connectUrl: { title: 'REST URL', field: '' } });
128128
setConnectUrl('clnrest://' + appCtx.walletConnect.LIGHTNING_REST_PROTOCOL + '://' + appCtx.walletConnect.DEVICE_DOMAIN_NAME + ':' + appCtx.walletConnect.LIGHTNING_REST_PORT + (appCtx.walletConnect.LIGHTNING_REST_PROTOCOL?.toLowerCase() === 'https' ? '?clientKey=' + appCtx.walletConnect.CLIENT_KEY + '&clientCert=' + appCtx.walletConnect.CLIENT_CERT + '&caCert=' + appCtx.walletConnect.CA_CERT : ''));
129129
break;
130130

apps/frontend/src/utilities/test-utilities.tsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,16 @@ export const mockStoreData = {
189189
},
190190
walletConnect: {
191191
LOCAL_HOST: "http://user.local",
192+
LIGHTNING_REST_PROTOCOL: "https",
193+
LIGHTNING_GRPC_PROTOCOL: "http",
192194
DEVICE_DOMAIN_NAME: "user.local",
193-
HIDDEN_SERVICE_URL: "oqaer4kd7ufryngx6dsztovs4pnlmaouwmtkofjsd2m7pkq8wd.onion",
194-
WS_PORT: "5001",
195-
GRPC_PORT: "2106",
195+
HIDDEN_SERVICE_URL: "http://oqaer4kd7ufryngx6dsztovs4pnlmaouwmtkofjsd2m7pkq8wd.onion",
196+
LIGHTNING_WS_PORT: "5001",
197+
LIGHTNING_GRPC_PORT: "2106",
196198
CLIENT_KEY: "ClientKey",
197199
CLIENT_CERT: "ClientCert",
198200
CA_CERT: "CACert",
199-
REST_PORT: "3001",
201+
LIGHTNING_REST_PORT: "3001",
200202
REST_MACAROON: "0201036c6e6402e501030a1042beb666ba043f72cb147adf3eaafc9e1201301a160a076164647265737312047265616",
201203
CLN_NODE_IP: "127.0.0.1",
202204
NODE_PUBKEY: "03a389b3a2f7aa6f9f4ccc19f2bd7a2eba83596699e86b715caaaa147fc37f3144",

0 commit comments

Comments
 (0)