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

Setup/complete e2e #958

Merged
merged 27 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
486d942
feat: mock sphinx bridge enable function
tobi-bams Feb 19, 2024
ca2576e
feat: getLsat function for e2e test
tobi-bams Feb 20, 2024
a0c10a0
feat: sign message for test sphinx bridge
tobi-bams Feb 20, 2024
5d7fdcd
fix: added needed changes for test to pass
tobi-bams Feb 20, 2024
3bf873b
fix: added --host to make localhost accessible by cypress
tobi-bams Feb 21, 2024
937cef8
feat: added E2E to github workflow
tobi-bams Feb 21, 2024
384936e
Merge branch 'master' into setup/complete-e2e
tobi-bams Feb 21, 2024
b48620b
fix: give relay permission
tobi-bams Feb 21, 2024
753f090
fix: added logs for github action
tobi-bams Feb 21, 2024
ceac9aa
fix: push nodes file to github
tobi-bams Feb 21, 2024
2317820
fix: try to type relay user
tobi-bams Feb 22, 2024
280d690
fix: resassigned nodes object
tobi-bams Feb 22, 2024
10c4686
fix: added git ts-ignore
tobi-bams Feb 22, 2024
9922bd4
fix: added more sleep time after starting server
tobi-bams Feb 22, 2024
e79fa02
fix: i added a wait time after page launch
tobi-bams Feb 22, 2024
ffa5dc2
fix: used the correct compose file
tobi-bams Feb 22, 2024
8f4536c
fix: trying to know what's copied to relay/nodes
tobi-bams Feb 22, 2024
8062f85
fix: added nodes to node file
tobi-bams Feb 22, 2024
5f9fc57
fix: added nodes to the fixutures folder
tobi-bams Feb 22, 2024
a6c0d9c
fix: added little logs to see
tobi-bams Feb 22, 2024
6bdadf9
fix: added videos to artifact
tobi-bams Feb 22, 2024
355c0b5
fix: setup boltwall local endpoint for E2E test
tobi-bams Feb 22, 2024
4db89d6
chore: added stack to the previous e2e test
tobi-bams Feb 22, 2024
292c819
fix: added video logs to artifact
tobi-bams Feb 22, 2024
fd2f16d
chore: ensured we have only one nodes.json file
tobi-bams Feb 22, 2024
10b0ee5
chore: deleted my test e2e file
tobi-bams Feb 22, 2024
60374c7
Merge branch 'master' into setup/complete-e2e
tobi-bams Feb 22, 2024
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
56 changes: 53 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,53 @@ jobs:
cypress-run:
runs-on: ubuntu-latest
steps:
- name: Enable docker.host.internal for Ubuntu
run: |
pwd && sudo bash -c 'echo "172.17.0.1 host.docker.internal" >> /etc/hosts'

- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'yarn'
node-version-file: ".nvmrc"
cache: "yarn"
- name: Clone Stack
run: |
git clone -b feat/second-brain-compose https://github.com/stakwork/sphinx-stack.git stack

- name: Give Permissions to Sphinx Nav Fiber
run: chmod 777 -R relay

- name: Give Permissions to Stack
working-directory: ./stack
run: |
chmod 777 ./bitcoind;
chmod 777 -R ./relay;
chmod 777 -R ./lnd;
chmod 777 -R ./proxy;
chmod 777 -R ./cln;

- name: Check for NODES
uses: nick-fields/retry@v2
with:
timeout_minutes: 10
max_attempts: 3
command: |
GITACTION_ENV=gitactionenv docker-compose -f ./stack/alts/navfiber.yml --project-dir ./stack up -d;
sleep 240;
docker ps
docker logs meme.sphinx
docker logs dave.sphinx
docker wait stack_relaysetup_1
cat stack/relay/NODES.json;

- name: Copy Node.json
uses: canastro/copy-file-action@master
with:
source: "stack/relay/NODES.json"
target: "relay/nodes.json"

- name: Install
run: yarn --immutable
Expand All @@ -26,7 +65,7 @@ jobs:
install-command: yarn --immutable
browser: chrome
start: yarn run start-e2e
wait-on: 'http://localhost:3000' # Waits for above
wait-on: "http://localhost:3000" # Waits for above
wait-on-timeout: 120 # Waits for 2 minutes
# Records to Cypress Dashboard
record: true
Expand All @@ -38,5 +77,16 @@ jobs:
run: yarn run cy-comp
continue-on-error: false

- name: Upload Cypress logs
if: failure()
uses: actions/upload-artifact@v2
with:
name: cypress-logs
path: cypress/videos

- name: Check the coverage value
run: yarn test-coverage

- name: Stop Stack
working-directory: ./stack
run: docker-compose down
27 changes: 27 additions & 0 deletions cypress/e2e/admin/signin.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
describe('Admin Login', () => {
it('Admin uses the enable function', () => {
cy.visit('http://localhost:3000', {
onBeforeLoad(win) {
win['CYPRESS_USER'] = 'alice'
},
})
let title = `Testing NavFiber`
cy.wait(30000)
cy.get('div[data-testid="settings-modal"]').click()
// cy.get('[data-testid="setting-label"]').should('have.text', 'Settings')
cy.get('[data-testid="setting-label"]').should('have.text', 'Admin Settings')
// .invoke('text')
// .then((value) => {
// console.log(value)
// })
cy.get('#cy-about-title-id').click()
cy.get('#cy-about-title-id').type('{selectAll}')
cy.get('#cy-about-title-id').type(title)

cy.get('#add-node-submit-cta').click()
cy.wait(200)
cy.get('div[data-testid="close-modal"]').click()

cy.get('.title').should('have.text', title)
})
})
26 changes: 26 additions & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,36 @@
// ***********************************************************

// Import commands.js using ES2015 syntax:
import nodes from '../../relay/nodes.json'
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')

// coverage
import '@cypress/code-coverage/support'

// Add alice as the Second Brain tribe admin
async function setAdmin() {
let user
for (let i = 0; i < nodes.length; i++) {
if (nodes[i].alias === 'alice') {
user = nodes[i]
break
}
}
try {
await fetch('http://localhost:8444/api/set_admin_pubkey', {
method: 'POST',
headers: { 'x-admin-token': 'navfiber_e2e_testing', 'Content-Type': 'application/json' },
body: JSON.stringify({
pubkey: user.pubkey,
name: user.alias,
}),
})
} catch (error) {
console.error(JSON.stringify(error))
}
}

setAdmin()
4 changes: 3 additions & 1 deletion cypress/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"compilerOptions": {
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress", "node"]
"types": ["cypress", "node"],
"resolveJsonModule": true,
"esModuleInterop": true
},
"include": ["**/*.ts"]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
},
"scripts": {
"start": "vite --port 3000",
"start-e2e": "VITE_APP_IS_E2E=true vite --port 3000",
"start-e2e": "VITE_APP_IS_E2E=true VITE_APP_API_URL=http://localhost:8444/api vite --host --port 3000",
"dev-tribe": "vite --port 3004",
"build": "tsc && vite build",
"build-docker": "tsc && vite build",
Expand Down
1 change: 1 addition & 0 deletions relay/nodes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
2 changes: 1 addition & 1 deletion src/components/App/SideBar/Show/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useMemo, useState } from 'react'
import styled from 'styled-components'
import { useGraphData } from '~/components/DataRetriever'
import { Avatar } from '~/components/common/Avatar'
import { Flex } from '~/components/common/Flex'
import { Text } from '~/components/common/Text'
import { TypeBadge } from '~/components/common/TypeBadge'
import { useGraphData } from '~/components/DataRetriever'
import { useDataStore } from '~/stores/useDataStore'
import { NodeExtended } from '~/types'
import { getSelectedNodeTimestamps } from '~/utils'
Expand Down
69 changes: 38 additions & 31 deletions src/components/Auth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { Text } from '~/components/common/Text'
import { isDevelopment, isE2E } from '~/constants'
import { getIsAdmin } from '~/network/auth'
import { useUserStore } from '~/stores/useUserStore'
import { executeIfProd, getSignedMessageFromRelay, updateBudget } from '~/utils'
import { sphinxBridge } from '~/testSphinxBridge'
import { getSignedMessageFromRelay, updateBudget } from '~/utils'

interface setAuthenticated {
setAuthenticated: (state: boolean) => void
Expand All @@ -18,49 +19,55 @@ export const Auth = ({ setAuthenticated }: setAuthenticated) => {
const [setBudget, setIsAdmin, setPubKey] = useUserStore((s) => [s.setBudget, s.setIsAdmin, s.setPubKey])

const handleAuth = useCallback(async () => {
await executeIfProd(async () => {
localStorage.removeItem('admin')
// await executeIfProd(async () => {
localStorage.removeItem('admin')

try {
let sphinxEnable

try {
if (!isE2E) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const sphinxEnable = await sphinx.enable()

sessionStorage.setItem('isSphinx', sphinxEnable ? 'true' : 'false')

setPubKey(sphinxEnable?.pubkey)
} catch (error) {
setPubKey('')
sphinxEnable = await sphinx.enable()
} else {
sphinxEnable = await sphinxBridge.enable()
}

await updateBudget(setBudget)
sessionStorage.setItem('isSphinx', sphinxEnable ? 'true' : 'false')

try {
const sigAndMessage = await getSignedMessageFromRelay()
setPubKey(sphinxEnable?.pubkey)
} catch (error) {
setPubKey('')
}

const res = await getIsAdmin({
message: sigAndMessage.message,
signature: sigAndMessage.signature,
})
await updateBudget(setBudget)

if (!res.data.isPublic && !res.data.isAdmin && !res.data.isMember) {
setUnauthorized(true)
try {
const sigAndMessage = await getSignedMessageFromRelay()

return
}
const res = await getIsAdmin({
message: sigAndMessage.message,
signature: sigAndMessage.signature,
})

if (res.data.isAdmin) {
localStorage.setItem('admin', JSON.stringify({ isAdmin: true }))
setIsAdmin(true)
}
if (!res.data.isPublic && !res.data.isAdmin && !res.data.isMember) {
setUnauthorized(true)

setAuthenticated(true)
return
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
/* not an admin */
if (res.data.isAdmin) {
localStorage.setItem('admin', JSON.stringify({ isAdmin: true }))
setIsAdmin(true)
}
})

setAuthenticated(true)

// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
/* not an admin */
}
// })

if (isE2E || isDevelopment) {
setAuthenticated(true)
Expand Down
2 changes: 1 addition & 1 deletion src/components/Modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export const BaseModal = ({
py={noWrap ? 0 : 20}
>
{onClose && (
<CloseButton onClick={onClose}>
<CloseButton data-testid="close-modal" onClick={onClose}>
<ClearIcon />
</CloseButton>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/components/SettingsModal/SettingsView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const SettingsView: React.FC<Props> = ({ onClose }) => {
const SettingsHeader = ({ children }: { children: React.ReactNode }) => (
<StyledHeader>
<Flex direction="row" pt={3}>
<StyledText>{getSettingsLabel()}</StyledText>
<StyledText data-testid="setting-label">{getSettingsLabel()}</StyledText>
{resolveAdminActions()}
</Flex>
{children}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Universe/Graph/Particles/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export const Particles: React.FC = () => {
const ref = useRef<THREE.Points>(null)

useFrame(() => {
const positions = (ref.current?.geometry.getAttribute('position') as THREE.BufferAttribute).array as Float32Array
const velocities = (ref.current?.geometry.getAttribute('velocity') as THREE.BufferAttribute).array as Float32Array
const positions = (ref.current?.geometry.getAttribute('position') as THREE.BufferAttribute)?.array as Float32Array
const velocities = (ref.current?.geometry.getAttribute('velocity') as THREE.BufferAttribute)?.array as Float32Array

if (positions && velocities) {
for (let i = 0; i < positions.length; i += 3) {
Expand Down
11 changes: 11 additions & 0 deletions src/testSphinxBridge/enable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { getCurrentUser } from './helper'

export function enableSphinx() {
const user = getCurrentUser()

if (!user) {
return null
}

return { budget: 0, pubkey: user.pubkey }
}
47 changes: 47 additions & 0 deletions src/testSphinxBridge/getLsat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { getCurrentUser } from './helper'

export async function getLsatSphinx(host: string) {
try {
const user = getCurrentUser()

if (user) {
const result = await fetch(`${user.external_ip}/active_lsat?issuer=${host}`, {
headers: { 'x-user-token': user.authToken },
})

const res = await result.json()

if (res.success) {
const { lsat } = res.response

return {
paymentRequest: lsat.paymentRequest,
macaroon: lsat.macaroon,
issuer: lsat.issuer,
identifier: lsat.identifier,
preimage: lsat.preimage,
paths: lsat.paths,
status: lsat.status,
success: false,
}
}

return {
paymentRequest: '',
macaroon: '',
issuer: '',
identifier: '',
preimage: '',
paths: '',
status: '',
success: false,
}
}

return null
} catch (error) {
console.log(JSON.stringify(error))

Check warning on line 43 in src/testSphinxBridge/getLsat.ts

View workflow job for this annotation

GitHub Actions / cypress-run

Unexpected console statement

Check warning on line 43 in src/testSphinxBridge/getLsat.ts

View workflow job for this annotation

GitHub Actions / eslint-run

Unexpected console statement

Check warning on line 43 in src/testSphinxBridge/getLsat.ts

View workflow job for this annotation

GitHub Actions / craco-build-run

Unexpected console statement

return null
}
}
29 changes: 29 additions & 0 deletions src/testSphinxBridge/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { RelayUser } from '~/types'
import nodes from '../../relay/nodes.json'

export function getCurrentUser(): RelayUser | null {
/* eslint-disable @typescript-eslint/no-explicit-any */
if ((window as any).CYPRESS_USER) {
const user = (window as any).CYPRESS_USER

let userNode

for (let i = 0; i < nodes.length; i += 1) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (nodes[i].alias === user) {
userNode = nodes[i]

break
}
}

if (!userNode) {
return null
}

return userNode
}

return null
}
Loading
Loading