mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
feat(p2p): enable pure browser p2p by default
This commit is contained in:
+4
-4
@@ -204,15 +204,15 @@ describe('AdvancedSettings', () => {
|
|||||||
expect(textInputs[2]?.value).toBe('/tmp/connected-node');
|
expect(textInputs[2]?.value).toBe('/tmp/connected-node');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shows pure p2p browser mode unchecked by default', async () => {
|
it('shows pure p2p browser mode checked by default', async () => {
|
||||||
await renderSettings(false);
|
await renderSettings(false);
|
||||||
|
|
||||||
expect(container.textContent).toContain('advanced_ipfs_gateways');
|
expect(container.textContent).not.toContain('advanced_ipfs_gateways');
|
||||||
expect(container.textContent).toContain('advanced_pubsub_providers');
|
expect(container.textContent).not.toContain('advanced_pubsub_providers');
|
||||||
expect(container.textContent).toContain('advanced_http_routers');
|
expect(container.textContent).toContain('advanced_http_routers');
|
||||||
expect(container.textContent).toContain('advanced_full_node_websocket_rpc');
|
expect(container.textContent).toContain('advanced_full_node_websocket_rpc');
|
||||||
const checkbox = container.querySelector<HTMLInputElement>('input[type="checkbox"]');
|
const checkbox = container.querySelector<HTMLInputElement>('input[type="checkbox"]');
|
||||||
expect(checkbox?.checked).toBe(false);
|
expect(checkbox?.checked).toBe(true);
|
||||||
|
|
||||||
const nodeRpcInput = Array.from(container.querySelectorAll<HTMLInputElement>('input[type="text"]')).find(
|
const nodeRpcInput = Array.from(container.querySelectorAll<HTMLInputElement>('input[type="text"]')).find(
|
||||||
(input) => input.placeholder === 'advanced_p2p_rpc_placeholder',
|
(input) => input.placeholder === 'advanced_p2p_rpc_placeholder',
|
||||||
|
|||||||
@@ -86,7 +86,8 @@ describe('useBrowserPureP2PAccountUpgrade', () => {
|
|||||||
window.isElectron = false;
|
window.isElectron = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not upgrade stale gateway browser accounts when pure p2p is disabled by default', async () => {
|
it('does not upgrade stale gateway browser accounts when pure p2p is explicitly disabled', async () => {
|
||||||
|
localStorage.setItem('5chan:pure-p2p-browser-enabled', 'false');
|
||||||
testState.account = {
|
testState.account = {
|
||||||
id: 'account-1',
|
id: 'account-1',
|
||||||
name: 'Account 1',
|
name: 'Account 1',
|
||||||
@@ -104,8 +105,7 @@ describe('useBrowserPureP2PAccountUpgrade', () => {
|
|||||||
expect(reloadMock).not.toHaveBeenCalled();
|
expect(reloadMock).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('upgrades stale gateway browser accounts when pure p2p is enabled and reloads after saving', async () => {
|
it('upgrades stale gateway browser accounts by default and reloads after saving', async () => {
|
||||||
localStorage.setItem('5chan:pure-p2p-browser-enabled', 'true');
|
|
||||||
testState.account = {
|
testState.account = {
|
||||||
id: 'account-1',
|
id: 'account-1',
|
||||||
name: 'Account 1',
|
name: 'Account 1',
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ const createStorage = (values: Record<string, string | undefined> = {}) => ({
|
|||||||
describe('p2p-browser-config', () => {
|
describe('p2p-browser-config', () => {
|
||||||
const defaultHttpRouters = DEFAULT_HTTP_ROUTER_URLS;
|
const defaultHttpRouters = DEFAULT_HTTP_ROUTER_URLS;
|
||||||
|
|
||||||
it('configures browser PKC options for gateway mode by default', () => {
|
it('configures browser PKC options for pure p2p mode by default', () => {
|
||||||
const chainProviders = {
|
const chainProviders = {
|
||||||
eth: { urls: ['https://eth.example'], chainId: 1 },
|
eth: { urls: ['https://eth.example'], chainId: 1 },
|
||||||
};
|
};
|
||||||
@@ -33,12 +33,14 @@ describe('p2p-browser-config', () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(shouldUsePureP2PBrowser(targetWindow)).toBe(false);
|
expect(shouldUsePureP2PBrowser(targetWindow)).toBe(true);
|
||||||
expect(configureP2PBrowserPkcOptions(targetWindow)).toBe(false);
|
expect(configureP2PBrowserPkcOptions(targetWindow)).toBe(true);
|
||||||
expect(targetWindow.defaultPkcOptions).toEqual({
|
expect(targetWindow.defaultPkcOptions).toMatchObject({
|
||||||
chainProviders,
|
chainProviders,
|
||||||
...getBrowserGatewayPkcOptions(),
|
|
||||||
httpRoutersOptions: defaultHttpRouters,
|
httpRoutersOptions: defaultHttpRouters,
|
||||||
|
ipfsGatewayUrls: undefined,
|
||||||
|
libp2pJsClientsOptions: [{ key: 'libp2pjs' }],
|
||||||
|
pubsubKuboRpcClientsOptions: undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -105,7 +107,7 @@ describe('p2p-browser-config', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
expect(getPureP2PBrowserPreference(targetWindow)).toBeUndefined();
|
expect(getPureP2PBrowserPreference(targetWindow)).toBeUndefined();
|
||||||
expect(shouldUsePureP2PBrowser(targetWindow)).toBe(false);
|
expect(shouldUsePureP2PBrowser(targetWindow)).toBe(true);
|
||||||
|
|
||||||
setPureP2PBrowserPreference(false, targetWindow);
|
setPureP2PBrowserPreference(false, targetWindow);
|
||||||
expect(getPureP2PBrowserPreference(targetWindow)).toBe(false);
|
expect(getPureP2PBrowserPreference(targetWindow)).toBe(false);
|
||||||
|
|||||||
@@ -67,10 +67,10 @@ describe('p2p-runtime', () => {
|
|||||||
expect(getP2PRuntimeMode(account, browserWindow)).toBe('full-node-rpc');
|
expect(getP2PRuntimeMode(account, browserWindow)).toBe('full-node-rpc');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('keeps browser pure p2p off by default while honoring explicit preference and active libp2p accounts', () => {
|
it('keeps browser pure p2p on by default while honoring explicit preference and active libp2p accounts', () => {
|
||||||
expect(shouldShowP2PSettingsSection(undefined, browserWindow)).toBe(false);
|
expect(shouldShowP2PSettingsSection(undefined, browserWindow)).toBe(true);
|
||||||
expect(shouldShowP2PSettingsSection({ pkcOptions: { ipfsGatewayUrls: ['https://gateway.example'] } }, browserWindow)).toBe(false);
|
expect(shouldShowP2PSettingsSection({ pkcOptions: { ipfsGatewayUrls: ['https://gateway.example'] } }, browserWindow)).toBe(true);
|
||||||
expect(isBrowserPureP2PEnabled({ pkcOptions: { ipfsGatewayUrls: ['https://gateway.example'] } }, browserWindow)).toBe(false);
|
expect(isBrowserPureP2PEnabled({ pkcOptions: { ipfsGatewayUrls: ['https://gateway.example'] } }, browserWindow)).toBe(true);
|
||||||
expect(shouldShowP2PSettingsSection({ pkcOptions: { libp2pJsClientsOptions: [{ key: 'libp2pjs' }] } }, browserWindow)).toBe(true);
|
expect(shouldShowP2PSettingsSection({ pkcOptions: { libp2pJsClientsOptions: [{ key: 'libp2pjs' }] } }, browserWindow)).toBe(true);
|
||||||
expect(isBrowserPureP2PEnabled({ pkcOptions: { libp2pJsClientsOptions: [{ key: 'libp2pjs' }] } }, browserWindow)).toBe(true);
|
expect(isBrowserPureP2PEnabled({ pkcOptions: { libp2pJsClientsOptions: [{ key: 'libp2pjs' }] } }, browserWindow)).toBe(true);
|
||||||
expect(shouldShowP2PSettingsSection({ pkcOptions: { ipfsGatewayUrls: ['https://gateway.example'] } }, browserWindowWithEnabledPureP2P)).toBe(true);
|
expect(shouldShowP2PSettingsSection({ pkcOptions: { ipfsGatewayUrls: ['https://gateway.example'] } }, browserWindowWithEnabledPureP2P)).toBe(true);
|
||||||
@@ -98,7 +98,7 @@ describe('p2p-runtime', () => {
|
|||||||
const mixedBrowserAccount = { pkcOptions: { libp2pJsClientsOptions: [{ key: 'libp2pjs' }], pubsubKuboRpcClientsOptions: ['https://pubsub.example/api/v0'] } };
|
const mixedBrowserAccount = { pkcOptions: { libp2pJsClientsOptions: [{ key: 'libp2pjs' }], pubsubKuboRpcClientsOptions: ['https://pubsub.example/api/v0'] } };
|
||||||
const fullNodeAccount = { pkcOptions: { pkcRpcClientsOptions: ['ws://node.example'] } };
|
const fullNodeAccount = { pkcOptions: { pkcRpcClientsOptions: ['ws://node.example'] } };
|
||||||
|
|
||||||
expect(shouldUpgradeBrowserPureP2PAccount(gatewayAccount, browserWindow)).toBe(false);
|
expect(shouldUpgradeBrowserPureP2PAccount(gatewayAccount, browserWindow)).toBe(true);
|
||||||
expect(shouldUpgradeBrowserPureP2PAccount(gatewayAccount, browserWindowWithEnabledPureP2P)).toBe(true);
|
expect(shouldUpgradeBrowserPureP2PAccount(gatewayAccount, browserWindowWithEnabledPureP2P)).toBe(true);
|
||||||
expect(shouldUpgradeBrowserPureP2PAccount(browserAccount, browserWindow)).toBe(false);
|
expect(shouldUpgradeBrowserPureP2PAccount(browserAccount, browserWindow)).toBe(false);
|
||||||
expect(shouldUpgradeBrowserPureP2PAccount(mixedBrowserAccount, browserWindow)).toBe(true);
|
expect(shouldUpgradeBrowserPureP2PAccount(mixedBrowserAccount, browserWindow)).toBe(true);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
export const PURE_P2P_BROWSER_SETTING_KEY = '5chan:pure-p2p-browser-enabled';
|
export const PURE_P2P_BROWSER_SETTING_KEY = '5chan:pure-p2p-browser-enabled';
|
||||||
export const BROWSER_PURE_P2P_DEFAULT_ENABLED = false;
|
export const BROWSER_PURE_P2P_DEFAULT_ENABLED = true;
|
||||||
|
|
||||||
const BROWSER_PUBSUB_KUBO_RPC_CLIENTS_OPTIONS = ['https://pubsubprovider.xyz/api/v0', 'https://plebpubsub.xyz/api/v0', 'https://rannithepleb.com/api/v0'];
|
const BROWSER_PUBSUB_KUBO_RPC_CLIENTS_OPTIONS = ['https://pubsubprovider.xyz/api/v0', 'https://plebpubsub.xyz/api/v0', 'https://rannithepleb.com/api/v0'];
|
||||||
// Keep this aligned with bitsocial-react-hooks' DEFAULT_HTTP_ROUTER_URLS without relying on a package-internal runtime import before window.defaultPkcOptions is configured.
|
// Keep this aligned with bitsocial-react-hooks' DEFAULT_HTTP_ROUTER_URLS without relying on a package-internal runtime import before window.defaultPkcOptions is configured.
|
||||||
|
|||||||
@@ -227,7 +227,7 @@ describe('Rules', () => {
|
|||||||
expect(scrollIntoViewMock).toHaveBeenCalled();
|
expect(scrollIntoViewMock).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shows a friendly loading state string while a board is downloading via IPFS', async () => {
|
it('shows a friendly loading state string while a board is downloading from peers', async () => {
|
||||||
testState.communities = {
|
testState.communities = {
|
||||||
'custom-board.eth': {
|
'custom-board.eth': {
|
||||||
state: 'fetching-ipns',
|
state: 'fetching-ipns',
|
||||||
@@ -237,7 +237,7 @@ describe('Rules', () => {
|
|||||||
await renderRules();
|
await renderRules();
|
||||||
await submitBoardAddress('custom-board.eth');
|
await submitBoardAddress('custom-board.eth');
|
||||||
|
|
||||||
expect(container.textContent).toContain('Downloading board via IPFS');
|
expect(container.textContent).toContain('Downloading board from peers');
|
||||||
expect(container.textContent).not.toContain('loading...');
|
expect(container.textContent).not.toContain('loading...');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user