From 0a50b05767bd73158880339daa3f01e7d87bb5ad Mon Sep 17 00:00:00 2001 From: j4qfrost Date: Sun, 15 Sep 2024 08:30:23 -0700 Subject: [PATCH] GitHub actions backend tests (#304) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add test for HandleHTTPError undelete * more verbose http codes * Update Dockerfile Now using go 1.23! Tested this on dev, it works * Update compose_dev.sh Prints initial settings as defined in setup.yaml. Added for usability reasons - users keep getting confused about account balance and maximum allowable debt * add failure condition test * formatting and test standards * add frontend file polling for wsl2 * add workflow files * dependencies need backend working directory * add macos testing * macos * backend test workflow * change name * Add test for HandleHTTPError (#278) * add test for HandleHTTPError undelete * more verbose http codes * Update Dockerfile Now using go 1.23! Tested this on dev, it works * Update compose_dev.sh Prints initial settings as defined in setup.yaml. Added for usability reasons - users keep getting confused about account balance and maximum allowable debt * add failure condition test * formatting and test standards --------- Co-authored-by: Osnat Katz Moon <137817983+astrosnat@users.noreply.github.com> * add failure condition test (#282) * Creation of Market Price Projection API (#277) * Moving test to appropriate location. * Updating, including moving test location. Test not passing due to precision error but generally passing on the terminal up to 6 dits. * market projection handler, not working. * Update market projected probability. * Safe uint conversion. * Updating, adding noop change to push into pipeline. * Update, test passing. * Update, attempting to solve type converstion uint problem. * Adding projected market layout. * Update, still have react JSON parse error but layout added to buyshares. * Market projection updates on buy shares side, upon button press. * Update, change printf to print. * Create SECURITY.md * Adding Fees to Buying and Selling Bets (#287) * Drafting out fees deduction functions and capability. * Attempting working version of initialBetFee function. * Draft adding fees. * Update, adding tests. * Adding working test for GetBetsForMarket * Successful fee util test. * Fees added on backend, tests passing. * Updating such that user record submitted. However fee summing not working yet evidently. * Working fees, at least initial fees. * Updating test scenario passing, made more clear. * Update Dockerfile We need to switch to 3.0.14-1~deb12u2 * Removing logging. * Adding fees, including communicating fees on front end. * totalBetCount to userBetCount so as not to misconstrue meaning. * Simplifying function, test passed. * Simplifying naming. * Updating new function name in test * Changing test to got before want convention. * Update marketid variable * Add combined fee structure for more througough test. * Reverting sale amount to 1 share. * Reversing got want --------- Co-authored-by: Osnat Katz Moon <137817983+astrosnat@users.noreply.github.com> * Frontend fixes (#286) * fix: fixed the market buttons not showing on mobile * fix: removed trade button on closed market --------- Co-authored-by: Patrick Delaney * Attempting toa ddress cors related security concern. (#298) * Drafting out reporting stats. * Add support for dependency injection to setup (#301) * Make EconomicsConfig from component structs Auto initialize config Add support to inject config Add support for testing the setup through test doubles Use new fee for placing bets (EachBetFee) --------- Co-authored-by: Osnat Katz Moon <137817983+astrosnat@users.noreply.github.com> Co-authored-by: Patrick Delaney Co-authored-by: Marko Kovač <124689071+markokovac16@users.noreply.github.com> Co-authored-by: Arthur <25300182+ajlacey@users.noreply.github.com> --- .github/workflows/backend.yml | 59 ++++++++++++++++++++ frontend/package-lock.json | 97 +++++++++++++++++++++++++++++++++ frontend/package.json | 3 +- frontend/vite.config.mjs | 10 ++++ scripts/docker-compose-dev.yaml | 1 - 5 files changed, 168 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/backend.yml diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml new file mode 100644 index 00000000..65df80ab --- /dev/null +++ b/.github/workflows/backend.yml @@ -0,0 +1,59 @@ +name: Backend + +on: + pull_request: + branches: [main] + workflow_dispatch: + +concurrency: + group: "linux-test" + cancel-in-progress: true + +jobs: + smoke: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + go-version: [ '1.23.x' ] + steps: + - uses: actions/checkout@v4 + - name: Setup Go ${{ matrix.go-version }} + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go-version }} + - name: Get Dependencies + working-directory: ./backend + run: | + go mod download + - name: Run tests + working-directory: ./backend + run: | + go build -o ./main && ./main & + SERVER_PID=$! + sleep 10 + kill $SERVER_PID + unit: + needs: smoke + if: | + startsWith(github.head_ref, 'feature/') + || startsWith(github.head_ref, 'fix/') + || startsWith(github.head_ref, 'refactor/') + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + go-version: [ '1.23.x' ] + steps: + - uses: actions/checkout@v4 + - name: Setup Go ${{ matrix.go-version }} + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go-version }} + - name: Get Dependencies + working-directory: ./backend + run: | + go get . + - name: Run tests + working-directory: ./backend + run: go test ./... diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 39dd06ee..e7e6c5b4 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -19,6 +19,7 @@ "react": "^18.2.0", "react-chartjs-2": "^5.2.0", "react-dom": "^18.2.0", + "react-error-boundary": "^4.0.13", "react-router-dom": "^5.3.0", "recharts": "^2.10.3", "web-vitals": "^2.1.4" @@ -26,6 +27,7 @@ "devDependencies": { "@vitejs/plugin-react": "^4.2.1", "autoprefixer": "^10.4.17", + "is-wsl": "^3.1.0", "postcss": "^8.4.35", "tailwindcss": "^3.4.1", "vite": "^5.1.7" @@ -3005,6 +3007,22 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-docker": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-3.0.0.tgz", + "integrity": "sha512-eljcgEDlEns/7AXFosB5K/2nCM4P7FQPkGc/DWLy5rmFEWvZayGrik1d9/QIY5nJ4f9YsVvBkA6kJpHn9rISdQ==", + "dev": true, + "license": "MIT", + "bin": { + "is-docker": "cli.js" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", @@ -3035,6 +3053,25 @@ "node": ">=0.10.0" } }, + "node_modules/is-inside-container": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-inside-container/-/is-inside-container-1.0.0.tgz", + "integrity": "sha512-KIYLCCJghfHZxqjYBE7rEy0OBuTd5xCHS7tHVgvCLkx7StIoaxwNW3hCALgEUjFfeRk+MG/Qxmp/vtETEF3tRA==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-docker": "^3.0.0" + }, + "bin": { + "is-inside-container": "cli.js" + }, + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/is-map": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/is-map/-/is-map-2.0.2.tgz", @@ -3161,6 +3198,22 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-wsl": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-3.1.0.tgz", + "integrity": "sha512-UcVfVfaK4Sc4m7X3dUSoHoozQGBEFeDC+zVo06t98xe8CzHSZZBekNXH+tu0NalHolcJ/QAGqS46Hef7QXBIMw==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-inside-container": "^1.0.0" + }, + "engines": { + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/isarray": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz", @@ -3947,6 +4000,18 @@ "react": "^18.2.0" } }, + "node_modules/react-error-boundary": { + "version": "4.0.13", + "resolved": "https://registry.npmjs.org/react-error-boundary/-/react-error-boundary-4.0.13.tgz", + "integrity": "sha512-b6PwbdSv8XeOSYvjt8LpgpKrZ0yGdtZokYwkwV2wlcZbxgopHX/hgPl5VgpnoVOWd868n1hktM8Qm4b+02MiLQ==", + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.12.5" + }, + "peerDependencies": { + "react": ">=16.13.1" + } + }, "node_modules/react-is": { "version": "17.0.2", "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", @@ -6959,6 +7024,12 @@ "has-tostringtag": "^1.0.0" } }, + "is-docker": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-3.0.0.tgz", + "integrity": "sha512-eljcgEDlEns/7AXFosB5K/2nCM4P7FQPkGc/DWLy5rmFEWvZayGrik1d9/QIY5nJ4f9YsVvBkA6kJpHn9rISdQ==", + "dev": true + }, "is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", @@ -6980,6 +7051,15 @@ "is-extglob": "^2.1.1" } }, + "is-inside-container": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-inside-container/-/is-inside-container-1.0.0.tgz", + "integrity": "sha512-KIYLCCJghfHZxqjYBE7rEy0OBuTd5xCHS7tHVgvCLkx7StIoaxwNW3hCALgEUjFfeRk+MG/Qxmp/vtETEF3tRA==", + "dev": true, + "requires": { + "is-docker": "^3.0.0" + } + }, "is-map": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/is-map/-/is-map-2.0.2.tgz", @@ -7058,6 +7138,15 @@ "get-intrinsic": "^1.1.1" } }, + "is-wsl": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-3.1.0.tgz", + "integrity": "sha512-UcVfVfaK4Sc4m7X3dUSoHoozQGBEFeDC+zVo06t98xe8CzHSZZBekNXH+tu0NalHolcJ/QAGqS46Hef7QXBIMw==", + "dev": true, + "requires": { + "is-inside-container": "^1.0.0" + } + }, "isarray": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz", @@ -7590,6 +7679,14 @@ "scheduler": "^0.23.0" } }, + "react-error-boundary": { + "version": "4.0.13", + "resolved": "https://registry.npmjs.org/react-error-boundary/-/react-error-boundary-4.0.13.tgz", + "integrity": "sha512-b6PwbdSv8XeOSYvjt8LpgpKrZ0yGdtZokYwkwV2wlcZbxgopHX/hgPl5VgpnoVOWd868n1hktM8Qm4b+02MiLQ==", + "requires": { + "@babel/runtime": "^7.12.5" + } + }, "react-is": { "version": "17.0.2", "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", diff --git a/frontend/package.json b/frontend/package.json index 938d263c..627514dc 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -52,8 +52,9 @@ "devDependencies": { "@vitejs/plugin-react": "^4.2.1", "autoprefixer": "^10.4.17", + "is-wsl": "^3.1.0", "postcss": "^8.4.35", "tailwindcss": "^3.4.1", "vite": "^5.1.7" } -} +} \ No newline at end of file diff --git a/frontend/vite.config.mjs b/frontend/vite.config.mjs index 99215350..aaea5cf5 100644 --- a/frontend/vite.config.mjs +++ b/frontend/vite.config.mjs @@ -1,11 +1,21 @@ import { defineConfig } from 'vite'; +import isWsl from 'is-wsl'; import react from '@vitejs/plugin-react'; export default defineConfig(() => { + let watchWSL = isWsl ? { + watch: { + usePolling: true, + interval: 500, + binaryInterval: 1000, + } + } : null; + return { build: { outDir: 'build', }, plugins: [react()], + server: watchWSL, }; }); diff --git a/scripts/docker-compose-dev.yaml b/scripts/docker-compose-dev.yaml index b8c80719..429d8870 100644 --- a/scripts/docker-compose-dev.yaml +++ b/scripts/docker-compose-dev.yaml @@ -82,4 +82,3 @@ networks: driver: bridge frontend_network: driver: bridge -