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

Integration test for examples #55

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a3660bd
Add selectable example contracts
sdankel Mar 18, 2024
adf6da5
Merge branch 'master' into sophie/examples
sdankel Mar 18, 2024
cc171da
Update solidity examples
sdankel Mar 18, 2024
fe1a445
src20 example
sdankel Mar 19, 2024
2a6fc64
update src20 example
sdankel Mar 19, 2024
35702ec
update examples
sdankel Mar 21, 2024
7277325
Merge branch 'master' into sophie/examples
sdankel Mar 21, 2024
fdd5491
unused deps
sdankel Mar 21, 2024
3563b81
integ test in ci
sdankel Mar 21, 2024
e93d93e
cargo gh action
sdankel Mar 21, 2024
0163f6c
fix typo
sdankel Mar 21, 2024
a0ace05
split up steps
sdankel Mar 21, 2024
277e229
run in background
sdankel Mar 21, 2024
0216017
cargo install
sdankel Mar 21, 2024
e37ff64
remove broken test
sdankel Mar 21, 2024
ce7fbbc
run with docker
sdankel Mar 21, 2024
ad6a774
metadata
sdankel Mar 21, 2024
8856a4b
meta output
sdankel Mar 21, 2024
d29e7b4
toJson
sdankel Mar 21, 2024
8d7f1b7
service
sdankel Mar 22, 2024
407bca9
service name
sdankel Mar 22, 2024
19befc6
combine workflows
sdankel Mar 22, 2024
69487cb
with docker-run-action
sdankel Mar 22, 2024
d1da8da
docker run
sdankel Mar 22, 2024
cfe64ea
tags output
sdankel Mar 22, 2024
180d151
Merge branch 'master' into sophie/examples-test
sdankel Mar 22, 2024
8633c51
rename ci workflow
sdankel Mar 22, 2024
503a3ca
run in detached mode
sdankel Mar 22, 2024
a44a591
debug response
sdankel Mar 22, 2024
bd183ac
increase test timeout
sdankel Mar 22, 2024
5358cb7
Fix error for src20 example
sdankel Mar 23, 2024
5ec6af3
update example
sdankel Mar 23, 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
24 changes: 23 additions & 1 deletion .github/workflows/backend-ci.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Backend CI
name: CI
on:
push:
branches:
Expand All @@ -10,6 +10,7 @@ env:
RUSTFLAGS: -D warnings
REGISTRY: ghcr.io
RUST_VERSION: 1.70.0
NODE_VERSION: '16'

jobs:
cancel-previous-runs:
Expand Down Expand Up @@ -88,6 +89,8 @@ jobs:
- cargo-check
- cargo-test
runs-on: ubuntu-latest
outputs:
tags: ${{ steps.meta.outputs.tags }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand Down Expand Up @@ -124,6 +127,25 @@ jobs:
cache-from: type=gha
cache-to: type=gha,mode=max

frontend-build-and-test:
if: github.ref != 'refs/heads/master'
needs:
- build-and-publish-image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: NPM build
env:
CI: true
run: |
cd app && npm ci && npm run build
- name: Run the service in docker
run: |
docker run -d -p 8080:8080 ${{ needs.build-and-publish-image.outputs.tags }}
- name: NPM test
run: |
cd app && npm run test

deploy:
if: github.ref == 'refs/heads/master'
needs:
Expand Down
23 changes: 0 additions & 23 deletions .github/workflows/frontend-build-and-test.yml

This file was deleted.

26 changes: 23 additions & 3 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"web-vitals": "^2.1.4"
},
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
Expand Down
11 changes: 0 additions & 11 deletions app/src/App.test.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function App() {
style={{
marginRight: drawerOpen ? DRAWER_WIDTH : 0,
transition: 'margin 195ms cubic-bezier(0.4, 0, 0.6, 1) 0ms',
height: 'calc(100vh - 90px)',
height: 'calc(100vh - 95px)',
display: 'flex',
flexDirection: 'column',
}}>
Expand Down
45 changes: 2 additions & 43 deletions app/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,47 +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';

export const DEFAULT_SWAY_CONTRACT = `contract;

abi Counter {
#[storage(read, write)]
fn increment(amount: u64) -> u64;

#[storage(read)]
fn get() -> u64;
}

storage {
counter: u64 = 0,
}

impl Counter for Contract {
#[storage(read, write)]
fn increment(amount: u64) -> u64 {
let incremented = storage.counter.read() + amount;
storage.counter.write(incremented);
incremented
}

#[storage(read)]
fn get() -> u64 {
storage.counter.read()
}
}`;

export const DEFAULT_SOLIDITY_CONTRACT = `pragma solidity ^0.8.24;

contract Counter {
uint64 count;

function get() public view returns (uint64) {
return count;
}

function increment() public {
count += 1;
}
}`;
29 changes: 9 additions & 20 deletions app/src/features/editor/components/ActionOverlay.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import React from 'react';
import IconButton from '@mui/material/IconButton';
import Delete from '@mui/icons-material/Delete';
import ToolchainDropdown, { Toolchain } from './ToolchainDropdown';
import Tooltip from '@mui/material/Tooltip';
import ExampleDropdown from './ExampleDropdown';
import { EXAMPLE_CONTRACTS } from '../examples';

export type EditorLanguage = 'sway' | 'solidity';

export interface ActionOverlayProps {
handleReset: () => void;
handleSelectExample: (example: string) => void;
toolchain?: Toolchain;
setToolchain?: (toolchain: Toolchain) => void;
editorLanguage: EditorLanguage;
}

function ActionOverlay({
handleReset,
handleSelectExample,
toolchain,
setToolchain,
editorLanguage
}: ActionOverlayProps) {
return (
<div style={{ position: 'relative' }}>
Expand All @@ -35,21 +38,7 @@ function ActionOverlay({
toolchain={toolchain}
setToolchain={setToolchain}
/>}
<div>
<Tooltip placement='top' title={'Reset the editor'}>
<IconButton
style={{
position: 'absolute',
right: '18px',
top: '18px',
pointerEvents: 'all',
}}
onClick={handleReset}
aria-label='reset the editor'>
<Delete />
</IconButton>
</Tooltip>
</div>
<ExampleDropdown handleSelect={handleSelectExample} examples={EXAMPLE_CONTRACTS[editorLanguage]} />
</div>
</div>
);
Expand Down
74 changes: 74 additions & 0 deletions app/src/features/editor/components/ExampleDropdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React, { useCallback } from 'react';
import Tooltip from '@mui/material/Tooltip';
import MenuItem from '@mui/material/MenuItem';
import IconButton from '@mui/material/IconButton';
import FileOpen from '@mui/icons-material/FileOpen';
import { Dropdown } from '@mui/base/Dropdown/Dropdown';
import Menu from '@mui/material/Menu/Menu';

export interface ExampleMenuItem {
label: string;
code: string;
}

export interface ExampleDropdownProps {
handleSelect: (example: string) => void;
examples: ExampleMenuItem[];
style?: React.CSSProperties;
}

function ExampleDropdown({
handleSelect,
examples,
style,
}: ExampleDropdownProps) {
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);

const onButtonClick = useCallback((event: any) => {
setAnchorEl(event.target);
}, [setAnchorEl]);

const handleClose = useCallback(() => {
setAnchorEl(null);
}, [setAnchorEl]);

const onItemClick = useCallback((code: string) => {
handleClose();
handleSelect(code);
}, [handleSelect, handleClose]);

return (
<div style={{ ...style }}>
<Dropdown>
<Tooltip placement='top' title={'Select an example'}>
<IconButton
style={{
position: 'absolute',
right: '18px',
top: '18px',
pointerEvents: 'all',
}}
onClick={onButtonClick}
aria-label='select an example'>
<FileOpen />
</IconButton>
</Tooltip>

<Menu
anchorEl={anchorEl}
open={Boolean(anchorEl)}
onClose={handleClose}>
{examples.map(({ label, code }: ExampleMenuItem, index) => (
<MenuItem
key={`${label}-${index}`}
onClick={() => onItemClick(code)}>
{label}
</MenuItem>
))}
</Menu>
</Dropdown>
</div>
);
}

export default ExampleDropdown;
3 changes: 1 addition & 2 deletions app/src/features/editor/components/SolidityEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'ace-builds/src-noconflict/theme-chrome';
import { StyledBorder } from '../../../components/shared';
import 'ace-mode-solidity/build/remix-ide/mode-solidity';
import ActionOverlay from './ActionOverlay';
import { DEFAULT_SOLIDITY_CONTRACT } from '../../../constants';
import { useIsMobile } from '../../../hooks/useIsMobile';

export interface SolidityEditorProps {
Expand All @@ -24,7 +23,7 @@ function SolidityEditor({ code, onChange }: SolidityEditorProps) {
marginRight: isMobile ? 0 : '1rem',
marginBottom: isMobile ? '1rem' : 0,
}}>
<ActionOverlay handleReset={() => onChange(DEFAULT_SOLIDITY_CONTRACT)} />
<ActionOverlay handleSelectExample={onChange} editorLanguage='solidity'/>
<AceEditor
style={{
width: '100%',
Expand Down
4 changes: 2 additions & 2 deletions app/src/features/editor/components/SwayEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'ace-builds/src-noconflict/mode-rust';
import 'ace-builds/src-noconflict/theme-chrome';
import { StyledBorder } from '../../../components/shared';
import ActionOverlay from './ActionOverlay';
import { DEFAULT_SWAY_CONTRACT } from '../../../constants';
import { Toolchain } from './ToolchainDropdown';

export interface SwayEditorProps {
Expand All @@ -24,9 +23,10 @@ function SwayEditor({
return (
<StyledBorder style={{ flex: 1 }}>
<ActionOverlay
handleReset={() => onChange(DEFAULT_SWAY_CONTRACT)}
handleSelectExample={onChange}
toolchain={toolchain}
setToolchain={setToolchain}
editorLanguage='sway'
/>
<AceEditor
style={{
Expand Down
Loading
Loading