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

contracts: Basic CI and require message owner #9

Merged
merged 4 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
59 changes: 59 additions & 0 deletions .github/workflows/ci-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: ci-test

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test-backend-frontend:
name: test-backend-frontend
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 18

- uses: pnpm/[email protected]
name: Install pnpm
id: pnpm-install
with:
version: 8
run_install: false

- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT

- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-

- name: Install dependencies
working-directory: backend
run: pnpm install

- name: Build backend
working-directory: backend
run: pnpm build

- name: Test backend
working-directory: backend
run: pnpm test

- name: Build frontend
working-directory: frontend
run: pnpm build
11 changes: 9 additions & 2 deletions backend/contracts/MessageBox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@
pragma solidity ^0.8.0;

contract MessageBox {
string public message;
string private _message;
address public author;

function setMessage(string calldata in_message) external {
message = in_message;
_message = in_message;
author = msg.sender;
}

function message() external view returns (string memory) {
if (msg.sender!=author) {
revert("not allowed");
}
return _message;
}
}
2 changes: 1 addition & 1 deletion backend/test/MessageBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("MessageBox", function () {
return { messageBox };
}

it("Should send message", async function () {
it("Should set message", async function () {
const {messageBox} = await deployMessageBox();

await messageBox.setMessage("hello world");
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { type MessageBox, MessageBox__factory } from '@oasisprotocol/demo-starte
export type { MessageBox } from '@oasisprotocol/demo-starter-backend';

import { useEthereumStore } from './stores/ethereum';
import { VoidSigner } from 'ethers';
import { type ContractRunner, VoidSigner } from 'ethers';

const addr = import.meta.env.VITE_MESSAGE_BOX_ADDR!;

Expand All @@ -23,7 +23,7 @@ export function useMessageBox(): ComputedRef<MessageBox | null> {
return null;
}

return MessageBox__factory.connect(addr, eth.signer);
return MessageBox__factory.connect(addr, eth.signer as ContractRunner);
});
}

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/stores/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function networkName(network?: Network): string {

declare global {
interface Window {
ethereum?: BrowserProvider & Eip1193Provider & sapphire.SapphireAnnex;
ethereum: BrowserProvider & Eip1193Provider & sapphire.SapphireAnnex;
}
}

Expand Down Expand Up @@ -91,7 +91,7 @@ export const useEthereumStore = defineStore('ethereum', () => {
throw new MetaMaskNotInstalledError('MetaMask not installed!');
}

return ethProvider;
return ethProvider as unknown as typeof window.ethereum;
}

async function init(addr: string, eth: Eip1193Provider) {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/views/HomeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ function handleError(error: Error, errorMessage: string) {
}
async function fetchMessage(): Promise<Message> {
const message = await uwMessageBox.value!.message();
const author = await uwMessageBox.value!.author();
const message = await messageBox.value!.message();
const author = await messageBox.value!.author();
return { message, author };
}
Expand Down
Loading