From 3563b81f236f2f7b659b840539bba23c6c1e0ee8 Mon Sep 17 00:00:00 2001 From: Sophie Date: Thu, 21 Mar 2024 14:34:40 -0700 Subject: [PATCH] integ test in ci --- .github/workflows/frontend-build-and-test.yml | 8 +++ app/src/constants.ts | 3 +- .../features/editor/examples/examples.test.ts | 65 +++++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 app/src/features/editor/examples/examples.test.ts diff --git a/.github/workflows/frontend-build-and-test.yml b/.github/workflows/frontend-build-and-test.yml index e8ab410..2eab169 100644 --- a/.github/workflows/frontend-build-and-test.yml +++ b/.github/workflows/frontend-build-and-test.yml @@ -21,3 +21,11 @@ jobs: run: | cd app && npm ci && npm run build cp -r build ../build + + steps: + - uses: actions/checkout@v2 + - name: npm test + run: | + cargo run + cd app && npm run test + diff --git a/app/src/constants.ts b/app/src/constants.ts index 179507d..f4ba3c0 100644 --- a/app/src/constants.ts +++ b/app/src/constants.ts @@ -1,5 +1,6 @@ export const FUEL_GREEN = '#00f58c'; +export const LOCAL_SERVER_URI = 'http://0.0.0.0:8080'; export const SERVER_URI = process.env.REACT_APP_LOCAL_SERVER - ? 'http://0.0.0.0:8080' + ? LOCAL_SERVER_URI : 'https://api.sway-playground.org'; diff --git a/app/src/features/editor/examples/examples.test.ts b/app/src/features/editor/examples/examples.test.ts new file mode 100644 index 0000000..8e03a13 --- /dev/null +++ b/app/src/features/editor/examples/examples.test.ts @@ -0,0 +1,65 @@ +import { EXAMPLE_CONTRACTS } from '.'; +import { LOCAL_SERVER_URI } from '../../../constants'; +import { ExampleMenuItem } from '../components/ExampleDropdown'; + +describe(`test examples`, () => { + beforeAll(() => { + // Start server + // require('../../../server'); + }); + + describe(`transpile solidity examples`, () => { + const uri = `${LOCAL_SERVER_URI}/transpile`; + + it.each( + EXAMPLE_CONTRACTS['solidity'].map(({ label, code }: ExampleMenuItem) => [ + label, + code, + ]) + )('%s', async (_label, code) => { + // Call server + const request = new Request(uri, { + method: 'POST', + body: JSON.stringify({ + contract: code, + lanaguage: 'solidity', + }), + }); + + const response = await fetch(request); + const {error, swayContract} = await response.json(); + + expect(error).toBeUndefined(); + expect(swayContract).toContain('contract;'); + }); + }); + + describe(`compile sway examples`, () => { + const uri = `${LOCAL_SERVER_URI}/compile`; + + it.each( + EXAMPLE_CONTRACTS['sway'].map(({ label, code }: ExampleMenuItem) => [ + label, + code, + ]) + )('%s', async (_label, code) => { + // Call server + const request = new Request(uri, { + method: 'POST', + body: JSON.stringify({ + contract: code, + toolchain: 'latest' + }), + }); + + const response = await fetch(request); + const { error, abi, bytecode, storageSlots, forcVersion } = await response.json(); + + expect(error).toBeUndefined(); + expect(abi).toBeDefined(); + expect(bytecode).toBeDefined(); + expect(storageSlots).toBeDefined(); + expect(forcVersion).toBeDefined(); + }, 10000); + }); +});