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

Web container contract #15

Merged
merged 51 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
2c02cc0
initial
sanity Jan 16, 2025
a90d046
initial
sanity Jan 16, 2025
e5e0f5f
feat: Add web container contract to workspace and build process
sanity Jan 17, 2025
bd84ce8
wip
sanity Jan 17, 2025
99c542a
Merge branch 'main' into web-container-contract
sanity Jan 17, 2025
0abdeee
wip
sanity Jan 18, 2025
d7e4855
wip
sanity Jan 18, 2025
6f31a40
Fix submodule reference for contracts/web-container-contract
sanity Jan 18, 2025
d1cde1f
try to fix submodule
sanity Jan 18, 2025
fbafd1c
do need submodules
sanity Jan 18, 2025
553138d
test: Add comprehensive unit tests for web-container-contract
sanity Jan 18, 2025
6b7a283
feat: Fix web-container-contract compilation errors
sanity Jan 18, 2025
665d242
fix: Resolve parameter naming and unused variable issues in web-conta…
sanity Jan 18, 2025
b9b0ce0
feat: Add test tasks for web-container and room contracts
sanity Jan 19, 2025
59e0ab5
feat: Add test tasks for scaffold and common crates in Makefile.toml
sanity Jan 19, 2025
75ff719
fix: Add crate alias for freenet-scaffold macro resolution
sanity Jan 19, 2025
47e9033
fix: Remove duplicate ComposableState import in scaffold tests
sanity Jan 19, 2025
ab4abd8
fix: Specify native target for scaffold tests in Makefile.toml
sanity Jan 19, 2025
4faac9c
chore: Fix wasm compilation issue in river-common tests
sanity Jan 19, 2025
f3392c3
test: Fix member info delta validation for non-existent members
sanity Jan 19, 2025
7e48352
fix: Resolve Rust borrowing issue in member_info.rs
sanity Jan 19, 2025
8b4d730
wip - cargo make test seems to work
sanity Jan 19, 2025
743d6eb
refactor: Remove explicit Linux target from test tasks in Makefile
sanity Jan 19, 2025
98e7f17
fix: Update test tasks to use native target directory
sanity Jan 19, 2025
9872997
fix: Update Makefile.toml to run tests with native target
sanity Jan 19, 2025
d493ef7
test: Remove explicit Linux target from test tasks
sanity Jan 19, 2025
71e1d75
fix: Exclude WASM targets from contract tests to prevent execution er…
sanity Jan 19, 2025
d45854d
fix: Remove invalid `--exclude-targets` argument from cargo test tasks
sanity Jan 19, 2025
3463291
fix: Specify native target for contract test tasks
sanity Jan 19, 2025
e291e86
fix: Add native target flag to scaffold test task
sanity Jan 19, 2025
04a6b1a
fix: Add native target flag to river-common tests
sanity Jan 19, 2025
4477adb
refactor: Simplify WebContainerMetadata signature handling with Signa…
sanity Jan 19, 2025
710810c
fix: Reject empty states in validate_state function
sanity Jan 19, 2025
9a81c97
refactor: Remove explicit empty state check and update test
sanity Jan 19, 2025
58a105d
fix: Update empty state validation test to match actual error type
sanity Jan 19, 2025
278ac91
refactor: Rename Contract struct to WebContainerContract
sanity Jan 19, 2025
92bc17c
fix: Add wasm-bindgen feature for getrandom to support WebAssembly ta…
sanity Jan 19, 2025
618a2b1
fix: Configure getrandom for WASM compatibility with default-features…
sanity Jan 19, 2025
c73de50
fix: Configure rand and getrandom for WASM compatibility
sanity Jan 19, 2025
bdbf097
fix: Add WASM compatibility features for cryptographic dependencies
sanity Jan 19, 2025
cff7a25
fix: Remove unsupported getrandom features from ed25519-dalek and cur…
sanity Jan 19, 2025
bde1bba
fix: Remove invalid "js" feature from rand crate for WASM compatibility
sanity Jan 19, 2025
8663928
fix: Enable WASM features for getrandom in web-container-contract
sanity Jan 19, 2025
aeda64d
fix: Enable WASM support for getrandom in room-contract
sanity Jan 19, 2025
c945c32
fix: Remove duplicate content in room-contract Cargo.toml
sanity Jan 19, 2025
ccf2251
fix: Add missing common and freenet-scaffold dependencies to room-con…
sanity Jan 19, 2025
dcd21e2
chore: Refactor GitHub workflows to separate build and test processes
sanity Jan 19, 2025
e73dadf
rename workflow
sanity Jan 19, 2025
ac377ff
ci: Optimize GitHub Actions workflow to reduce duplicate CI runs
sanity Jan 19, 2025
248f4ac
fix: Install Dioxus CLI in GitHub Actions workflow
sanity Jan 19, 2025
e9e9bfd
feat: Speed up Dioxus CLI installation using cargo-binstall in workflows
sanity Jan 19, 2025
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
41 changes: 22 additions & 19 deletions .github/workflows/dioxus-build.yml → .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
name: Dioxus Build
name: Build

on:
push:
branches: [ "**" ] # Run on all branches
pull_request:
push:
branches:
- main
- master
- develop
- 'releases/**'

env:
CARGO_TERM_COLOR: always
Expand All @@ -17,23 +21,12 @@ jobs:
with:
submodules: recursive

- name: Verify submodule
run: |
ls -la stdlib/
ls -la stdlib/rust/

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown

- name: Install cargo-make
uses: actions-rs/cargo@v1
with:
command: install
args: --force cargo-make

- name: Cache cargo registry
- name: Cache cargo
uses: actions/cache@v3
with:
path: |
Expand All @@ -43,14 +36,24 @@ jobs:
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Cache Dioxus CLI

- name: Cache cargo-make
uses: actions/cache@v3
with:
path: ~/.cargo/bin/dx
key: ${{ runner.os }}-dioxus-cli
path: ~/.cargo/bin/cargo-make
key: ${{ runner.os }}-cargo-make

- name: Install cargo-make
uses: actions-rs/cargo@v1
with:
command: install
args: --force cargo-make

- name: Install cargo-binstall
uses: taiki-e/install-action@cargo-binstall

- name: Install Dioxus CLI
run: cargo install dioxus-cli --force
run: cargo binstall -y dioxus-cli

- name: Build Project
run: cargo make build
54 changes: 54 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Test

on:
pull_request:
push:
branches:
- main
- master
- develop
- 'releases/**'

env:
CARGO_TERM_COLOR: always

jobs:
test:
runs-on: freenet-default-runner

steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Install Rust
uses: dtolnay/rust-toolchain@stable

- name: Cache cargo
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target/
key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-test-

- name: Cache cargo-make
uses: actions/cache@v3
with:
path: ~/.cargo/bin/cargo-make
key: ${{ runner.os }}-cargo-make

- name: Install cargo-make
uses: actions-rs/cargo@v1
with:
command: install
args: --force cargo-make

- name: Install cargo-binstall
uses: taiki-e/install-action@cargo-binstall

- name: Run Tests
run: cargo make test
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
contracts/

# Generated by Cargo
# will have compiled files and executables
debug/
Expand Down
2 changes: 2 additions & 0 deletions .idea/river.iml

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

57 changes: 26 additions & 31 deletions .idea/workspace.xml

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

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = [
"common",
"ui",
"contracts/room-contract",
"contracts/web-container-contract",
"scaffold",
"scaffold-macro",
]
Expand All @@ -17,14 +18,14 @@ serde = { version = "1.0.130", features = ["derive"] }
ed25519-dalek = { version = "2.1.1", features = ["serde", "rand_core"] }
blake3 = { version = "1.5.3", features = ["serde"] }
x25519-dalek = { version = "2.0.0", features = ["static_secrets"] }
curve25519-dalek = "4.1.3"
curve25519-dalek = { version = "4.1.3" }
sha2 = "0.10.8"
aes-gcm = "0.11.0-pre.2"

# Utilities
itertools = "0.13.0"
rand = "0.8.5"
getrandom = { version = "0.2.15", features = ["js"] }
rand = { version = "0.8.5", features = ["getrandom"] }
getrandom = { version = "0.2.15", features = ["js", "wasm-bindgen"], default-features = false }
base64 = "0.22.1"
once_cell = "1.18.0"
data-encoding = "2.3.3"
Expand All @@ -40,6 +41,7 @@ wasm-bindgen-futures = "0.4.43"
common = { path = "common", package = "river-common" }
freenet-scaffold = { path = "scaffold" }
freenet-scaffold-macro = { path = "scaffold-macro" }
freenet-stdlib = { path = "stdlib/rust", features = ["contract"] }

[workspace.package]
version = "0.1.0"
Expand Down
39 changes: 36 additions & 3 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ default_to_workspace = false

[env]
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
CARGO_MAKE_WORKSPACE_INCLUDE_MEMBERS = ["contracts/room-contract", "ui"]
CARGO_MAKE_WORKSPACE_INCLUDE_MEMBERS = ["contracts/room-contract", "contracts/web-container-contract", "ui"]
CONTRACT_TARGET = "wasm32-unknown-unknown"
CONTRACT_NAME = "room_contract"
BUILD_PROFILE = "release"
Expand All @@ -16,15 +16,24 @@ description = "Clean build artifacts"
command = "cargo"
args = ["clean"]

[tasks.build-contract]
[tasks.build-room-contract]
description = "Build the room contract WASM"
command = "cargo"
args = ["build", "--profile", "${BUILD_PROFILE}", "--target", "${CONTRACT_TARGET}", "-p", "room-contract", "--target-dir", "target"]

[tasks.build-web-container]
description = "Build the web container contract WASM"
command = "cargo"
args = ["build", "--profile", "${BUILD_PROFILE}", "--target", "${CONTRACT_TARGET}", "-p", "web-container-contract", "--target-dir", "target"]

[tasks.build-contracts]
description = "Build all contracts"
dependencies = ["build-room-contract", "build-web-container"]


[tasks.build-ui]
description = "Build the Dioxus UI"
dependencies = ["build-contract"]
dependencies = ["build-contracts"]
command = "dx"
args = ["build", "--${BUILD_PROFILE}", "--features", "${UI_FEATURES}"]
cwd = "./ui"
Expand Down Expand Up @@ -53,6 +62,30 @@ command = "dx"
args = ["build", "--${BUILD_PROFILE}", "--features", "${UI_FEATURES}"]
cwd = "./ui"

[tasks.test-web-container]
description = "Run tests for web-container-contract"
command = "cargo"
args = ["test", "--package", "web-container-contract", "--target-dir", "target/native", "--target", "x86_64-unknown-linux-gnu"]

[tasks.test-room-contract]
description = "Run tests for room-contract"
command = "cargo"
args = ["test", "--package", "room-contract", "--target-dir", "target/native", "--target", "x86_64-unknown-linux-gnu"]

[tasks.test-scaffold]
description = "Run tests for scaffold crate"
command = "cargo"
args = ["test", "--package", "freenet-scaffold", "--target-dir", "target/native", "--target", "x86_64-unknown-linux-gnu"]

[tasks.test-common]
description = "Run tests for common crate"
command = "cargo"
args = ["test", "--package", "river-common", "--target-dir", "target/native", "--target", "x86_64-unknown-linux-gnu"]

[tasks.test]
description = "Run all tests"
dependencies = ["test-web-container", "test-room-contract", "test-scaffold", "test-common"]

[tasks.build]
description = "Build everything in release mode (optimized)"
dependencies = ["build-ui"]
Expand Down
7 changes: 5 additions & 2 deletions common/src/room_state/member_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@ impl ComposableState for MemberInfoV1 {
if *member_id == parameters.owner_id() {
// If it's the owner, verify against the room owner's key
member_info.verify_signature(parameters)?;
} else if let Some(member) = parent_state.members.members_by_member_id().get(member_id) {
// For non-owners, verify against their member key
} else {
// For non-owners, verify they exist and check their signature
let members = parent_state.members.members_by_member_id();
let member = members.get(member_id)
.ok_or_else(|| format!("MemberInfo exists for non-existent member: {:?}", member_id))?;
member_info.verify_signature_with_key(&member.member.member_vk)?;
}

Expand Down
24 changes: 13 additions & 11 deletions contracts/room-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ version = "0.1.0"
edition = "2021"

[dependencies]
common.workspace = true
ciborium.workspace = true
getrandom.workspace = true
freenet-scaffold = { path = "../../scaffold" }
freenet-stdlib = { path = "../../stdlib/rust", features = ["contract"] }
serde.workspace = true
ed25519-dalek.workspace = true
rand.workspace = true
freenet-stdlib.workspace = true
freenet-scaffold.workspace = true
common.workspace = true
getrandom = { workspace = true, features = ["js", "wasm-bindgen"], default-features = false }

[lib]
crate-type = ["cdylib"]

[profile.release]
lto = true
opt-level = 'z'
panic = 'abort'
strip = true
crate-type = ["cdylib", "rlib"]

[features]
default = ["freenet-main-contract"]
contract = ["freenet-stdlib/contract"]
freenet-main-contract = []
trace = ["freenet-stdlib/trace"]
3 changes: 3 additions & 0 deletions contracts/room-contract/wasm32-unknown-unknown/CACHEDIR.TAG
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Signature: 8a477f597d28d172789f06886806bc55
# This file is a cache directory tag created by cargo.
# For information about cache directory tags see https://bford.info/cachedir/
Loading