Skip to content

Commit 896e74c

Browse files
committed
feat: add e2e workflow tests and CONTRIBUTING.md
1 parent a034fde commit 896e74c

2 files changed

Lines changed: 721 additions & 0 deletions

File tree

CONTRIBUTING.md

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# Contributing to NiffyInsure
2+
3+
## Development Environment
4+
5+
### Required Tools
6+
7+
- **Rust** (1.81+) - Install via [rustup](https://rustup.rs/)
8+
- **wasm32-unknown-unknown target** - `rustup target add wasm32-unknown-unknown`
9+
- **Soroban CLI** - `cargo install stellar-cli`
10+
- **Node.js** (22+) - For backend/frontend
11+
- **Docker** - For running local Stellar quickstart (optional)
12+
13+
### Quick Start
14+
15+
```bash
16+
# Install Rust and wasm target
17+
rustup target add wasm32-unknown-unknown
18+
19+
# Run contract tests
20+
cd contracts/niffyinsure
21+
cargo test
22+
23+
# Build WASM
24+
cargo build --target wasm32-unknown-unknown --release
25+
26+
# Run backend tests
27+
cd ../backend
28+
npm install
29+
npm test
30+
```
31+
32+
### Dockerized Stellar (Optional)
33+
34+
For integration testing with a local Stellar network:
35+
36+
```bash
37+
# Start Stellar quickstart
38+
docker run --rm -it \
39+
--name stellar \
40+
-p 8000:8000 \
41+
stellar/quickstart:latest \
42+
--standalone
43+
44+
# Then use stellar CLI to interact
45+
stellar contract deploy ...
46+
```
47+
48+
## Testing
49+
50+
### Contract Tests
51+
52+
Run all contract tests:
53+
54+
```bash
55+
cd contracts/niffyinsure
56+
cargo test
57+
```
58+
59+
Run specific test:
60+
61+
```bash
62+
cargo test --test voting
63+
```
64+
65+
### Test Structure
66+
67+
- `tests/integration.rs` - Basic initialization and auth tests
68+
- `tests/admin.rs` - Admin privilege matrix tests
69+
- `tests/voting.rs` - DAO voting tests
70+
- `tests/termination.rs` - Policy termination tests
71+
- `tests/security.rs` - Security-focused tests
72+
- `tests/premium.rs` - Premium calculation tests
73+
74+
### Writing Tests
75+
76+
All tests use the Soroban test harness with deterministic `Env` setups:
77+
78+
```rust
79+
#[test]
80+
fn my_test() {
81+
let env = Env::default();
82+
env.mock_all_auths();
83+
let contract_id = env.register(niffyinsure::NiffyInsure, ());
84+
let client = NiffyInsureClient::new(&env, &contract_id);
85+
86+
// Test code here
87+
}
88+
```
89+
90+
## Entrypoint Coverage Checklist
91+
92+
| Entrypoint | Happy Path | Negative Tests | Status |
93+
|------------|------------|----------------|--------|
94+
| `initialize` || ✅ (double init, wrong admin) | Complete |
95+
| `generate_premium` || ✅ (invalid inputs) | Complete |
96+
| `get_multiplier_table` || - | Complete |
97+
| `set_allowed_asset` || ✅ (non-admin) | Complete |
98+
| `is_allowed_asset` || - | Complete |
99+
| `process_claim` || ✅ (not approved, already paid) | Complete |
100+
| `get_claim` || ✅ (not found) | Complete |
101+
| `get_claim_counter` || - | Complete |
102+
| `get_policy_counter` || - | Complete |
103+
| `has_policy` || - | Complete |
104+
| `get_voters` || - | Complete |
105+
| `initiate_policy` || ✅ (paused, duplicate, invalid) | Complete |
106+
| `get_policy` || ✅ (not found) | Complete |
107+
| `get_active_policy_count` || - | Complete |
108+
| `pause` || ✅ (non-admin) | Complete |
109+
| `unpause` || ✅ (non-admin) | Complete |
110+
| `is_paused` || - | Complete |
111+
| `propose_admin` || ✅ (non-admin) | Complete |
112+
| `accept_admin` || ✅ (no proposal) | Complete |
113+
| `cancel_admin` || ✅ (no proposal) | Complete |
114+
| `set_token` || ✅ (non-admin) | Complete |
115+
| `set_treasury` || ✅ (non-admin) | Complete |
116+
| `drain` || ✅ (non-admin, zero amount) | Complete |
117+
| `file_claim` || ✅ (not found, expired, paused) | Complete |
118+
| `vote_on_claim` || ✅ (not eligible, duplicate, paused) | Complete |
119+
| `finalize_claim` || ✅ (window still open) | Complete |
120+
| `renew_policy` || ✅ (not found, paused) | - |
121+
| `terminate_policy` || ✅ (not found, unauthorized) | Complete |
122+
123+
### Coverage Requirements
124+
125+
- **Each public entrypoint must have at least one positive test**
126+
- **Each entrypoint that can fail must have at least one negative test**
127+
- **New features require test updates** (enforced in PR review)
128+
129+
## CI/CD
130+
131+
### GitHub Actions
132+
133+
The CI runs on every pull request:
134+
135+
1. **Contract tests** - `cargo test`
136+
2. **Linting** - `cargo fmt --check`, `cargo clippy`
137+
3. **Build** - `cargo build --target wasm32-unknown-unknown --release`
138+
4. **Backend tests** - `npm test`
139+
5. **Frontend tests** - `npm test`
140+
141+
### Caching
142+
143+
Dependencies are cached using GitHub Actions cache to speed up CI runs.
144+
145+
## Code Style
146+
147+
- Run `cargo fmt` before committing
148+
- Run `cargo clippy` to catch common mistakes
149+
- Use meaningful test names: `fn test_name_describes_scenario()`
150+
151+
## Issue Lifecycle
152+
153+
1. Create issue with clear description
154+
2. Create feature branch: `feat/description` or `fix/description`
155+
3. Add tests for new functionality
156+
4. Update coverage checklist in this file
157+
5. Open PR for review
158+
6. CI must pass before merge

0 commit comments

Comments
 (0)