Skip to content

Commit e47afe1

Browse files
authored
Merge pull request #3 from OWK50GA/feat/separate-tests
Feat/separate tests
2 parents a6ddc5f + b03d0c7 commit e47afe1

29 files changed

Lines changed: 3698 additions & 114 deletions

.github/CONTRIBUTING.md

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# Contributing to Programming Bitcoin
2+
3+
Thank you for your interest in contributing to this project! This is an educational implementation of Bitcoin cryptography in Rust.
4+
5+
## Getting Started
6+
7+
1. Fork the repository
8+
2. Clone your fork: `git clone https://github.com/YOUR_USERNAME/programming_bitcoin.git`
9+
3. Create a branch: `git checkout -b feature/your-feature-name`
10+
4. Make your changes
11+
5. Run tests: `cargo test`
12+
6. Format code: `cargo fmt`
13+
7. Run clippy: `cargo clippy`
14+
8. Commit your changes: `git commit -am 'Add some feature'`
15+
9. Push to the branch: `git push origin feature/your-feature-name`
16+
10. Create a Pull Request
17+
18+
## Development Setup
19+
20+
### Prerequisites
21+
- Rust 1.70+ (install via [rustup](https://rustup.rs/))
22+
- Git
23+
24+
### Building
25+
```bash
26+
cargo build
27+
```
28+
29+
### Running Tests
30+
```bash
31+
# Run all tests
32+
cargo test
33+
34+
# Run specific chapter tests
35+
cargo test --test ch01_finite_fields_tests
36+
cargo test --test ch02_elliptic_curves_tests
37+
cargo test --test ch03_bitcoin_crypto_tests
38+
cargo test --test ch04_serialization_tests
39+
40+
# Run a specific test
41+
cargo test test_field_element_creation
42+
43+
# Run with output
44+
cargo test -- --nocapture
45+
```
46+
47+
### Code Quality
48+
49+
Before submitting a PR, ensure:
50+
51+
1. **All tests pass:**
52+
```bash
53+
cargo test
54+
```
55+
56+
2. **Code is formatted:**
57+
```bash
58+
cargo fmt
59+
```
60+
61+
3. **No clippy warnings:**
62+
```bash
63+
cargo clippy -- -D warnings
64+
```
65+
66+
4. **Documentation builds:**
67+
```bash
68+
cargo doc --no-deps
69+
```
70+
71+
## Project Structure
72+
73+
```
74+
src/
75+
├── ch01_finite_fields/ # Finite field arithmetic
76+
├── ch02_elliptic_curves/ # Basic elliptic curve operations
77+
├── ch03_ecc/ # Bitcoin's secp256k1 curve
78+
└── ch04_serialization/ # Bitcoin serialization formats
79+
80+
tests/
81+
├── ch01_finite_fields_tests.rs
82+
├── ch02_elliptic_curves_tests.rs
83+
├── ch03_bitcoin_crypto_tests.rs
84+
└── ch04_serialization_tests.rs
85+
```
86+
87+
## Coding Guidelines
88+
89+
### Style
90+
- Follow Rust standard style (enforced by `rustfmt`)
91+
- Use meaningful variable names
92+
- Add comments for complex algorithms
93+
- Keep functions focused and small
94+
95+
### Testing
96+
- Write tests for new functionality
97+
- Maintain or improve code coverage
98+
- Test edge cases and error conditions
99+
- Use descriptive test names: `test_<what>_<scenario>`
100+
101+
### Documentation
102+
- Add doc comments for public APIs
103+
- Include examples in doc comments when helpful
104+
- Update README.md if adding new features
105+
106+
### Commits
107+
- Write clear, descriptive commit messages
108+
- Use present tense ("Add feature" not "Added feature")
109+
- Reference issues when applicable (#123)
110+
111+
## Types of Contributions
112+
113+
### Bug Reports
114+
- Use GitHub Issues
115+
- Include steps to reproduce
116+
- Provide expected vs actual behavior
117+
- Include Rust version and OS
118+
119+
### Feature Requests
120+
- Use GitHub Issues
121+
- Explain the use case
122+
- Describe the proposed solution
123+
- Consider alternatives
124+
125+
### Code Contributions
126+
- Follow the development setup above
127+
- Ensure all checks pass
128+
- Update tests and documentation
129+
- Keep PRs focused on a single concern
130+
131+
### Documentation
132+
- Fix typos and improve clarity
133+
- Add examples
134+
- Improve README or inline docs
135+
136+
## Pull Request Process
137+
138+
1. **Update tests** - Add or update tests for your changes
139+
2. **Update documentation** - Update README.md, doc comments, etc.
140+
3. **Run checks locally** - Ensure tests, fmt, and clippy pass
141+
4. **Create PR** - Provide a clear description of changes
142+
5. **Address feedback** - Respond to review comments
143+
6. **Wait for CI** - All GitHub Actions must pass
144+
145+
## Code Review
146+
147+
All submissions require review. We use GitHub pull requests for this purpose.
148+
149+
Reviewers will check:
150+
- Code quality and style
151+
- Test coverage
152+
- Documentation
153+
- Performance implications
154+
- Security considerations
155+
156+
## Questions?
157+
158+
Feel free to:
159+
- Open an issue for questions
160+
- Start a discussion
161+
- Reach out to maintainers
162+
163+
## License
164+
165+
By contributing, you agree that your contributions will be licensed under the same license as the project (see LICENSE file).
166+
167+
## Learning Resources
168+
169+
This project follows the book "Programming Bitcoin" by Jimmy Song:
170+
- [Programming Bitcoin](https://programmingbitcoin.com/)
171+
- [Bitcoin Wiki](https://en.bitcoin.it/)
172+
- [secp256k1 specification](https://www.secg.org/sec2-v2.pdf)
173+
174+
## Code of Conduct
175+
176+
Be respectful, inclusive, and constructive. This is a learning project - questions and mistakes are welcome!

.github/workflows/ci.yml

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main, master, develop ]
6+
pull_request:
7+
branches: [ main, master, develop ]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
test:
14+
name: Test
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
matrix:
18+
os: [ubuntu-latest, macos-latest, windows-latest]
19+
rust: [stable, beta]
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Install Rust
24+
uses: dtolnay/rust-toolchain@master
25+
with:
26+
toolchain: ${{ matrix.rust }}
27+
28+
- name: Cache cargo registry
29+
uses: actions/cache@v4
30+
with:
31+
path: ~/.cargo/registry
32+
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
33+
34+
- name: Cache cargo index
35+
uses: actions/cache@v4
36+
with:
37+
path: ~/.cargo/git
38+
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
39+
40+
- name: Cache cargo build
41+
uses: actions/cache@v4
42+
with:
43+
path: target
44+
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
45+
46+
- name: Run tests
47+
run: cargo test --verbose
48+
49+
- name: Run tests (release mode)
50+
run: cargo test --release --verbose
51+
52+
fmt:
53+
name: Rustfmt
54+
runs-on: ubuntu-latest
55+
steps:
56+
- uses: actions/checkout@v4
57+
58+
- name: Install Rust
59+
uses: dtolnay/rust-toolchain@stable
60+
with:
61+
components: rustfmt
62+
63+
- name: Check formatting
64+
run: cargo fmt --all -- --check
65+
66+
clippy:
67+
name: Clippy
68+
runs-on: ubuntu-latest
69+
steps:
70+
- uses: actions/checkout@v4
71+
72+
- name: Install Rust
73+
uses: dtolnay/rust-toolchain@stable
74+
with:
75+
components: clippy
76+
77+
- name: Cache cargo registry
78+
uses: actions/cache@v4
79+
with:
80+
path: ~/.cargo/registry
81+
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
82+
83+
- name: Cache cargo index
84+
uses: actions/cache@v4
85+
with:
86+
path: ~/.cargo/git
87+
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
88+
89+
- name: Cache cargo build
90+
uses: actions/cache@v4
91+
with:
92+
path: target
93+
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
94+
95+
- name: Run clippy
96+
run: cargo clippy --all-targets --all-features -- -D warnings
97+
98+
build:
99+
name: Build
100+
runs-on: ubuntu-latest
101+
steps:
102+
- uses: actions/checkout@v4
103+
104+
- name: Install Rust
105+
uses: dtolnay/rust-toolchain@stable
106+
107+
- name: Cache cargo registry
108+
uses: actions/cache@v4
109+
with:
110+
path: ~/.cargo/registry
111+
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
112+
113+
- name: Cache cargo index
114+
uses: actions/cache@v4
115+
with:
116+
path: ~/.cargo/git
117+
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
118+
119+
- name: Cache cargo build
120+
uses: actions/cache@v4
121+
with:
122+
path: target
123+
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
124+
125+
- name: Build
126+
run: cargo build --verbose
127+
128+
- name: Build (release)
129+
run: cargo build --release --verbose
130+
131+
doc:
132+
name: Documentation
133+
runs-on: ubuntu-latest
134+
steps:
135+
- uses: actions/checkout@v4
136+
137+
- name: Install Rust
138+
uses: dtolnay/rust-toolchain@stable
139+
140+
- name: Cache cargo registry
141+
uses: actions/cache@v4
142+
with:
143+
path: ~/.cargo/registry
144+
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
145+
146+
- name: Cache cargo index
147+
uses: actions/cache@v4
148+
with:
149+
path: ~/.cargo/git
150+
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
151+
152+
- name: Cache cargo build
153+
uses: actions/cache@v4
154+
with:
155+
path: target
156+
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
157+
158+
- name: Check documentation
159+
run: cargo doc --no-deps --document-private-items

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
/target
2+
.github/workflows/coverage.yml
3+
.github/workflows/dependency-review.yml
4+
.github/workflows/release.yml
5+
.github/workflows/security-audit.yml
6+
.github/workflows/README.md

0 commit comments

Comments
 (0)