Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Test and Coverage

on:
push:
branches: [ main, chore/migrate-go ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23.0'

- name: Install dependencies
run: go mod download

- name: Run tests
run: go test ./...
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool
*.out
coverage.html

# Go workspace file
go.work

# IDE files
.vscode/
.idea/

# OS files
.DS_Store

# Project specific
/ethgen
/example/ethgen
/artifacts/
/bindings/
76 changes: 76 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

synceth (also known as ethgen) is a smart contract development toolchain for Go that provides compilation, binding generation, and testing utilities for Ethereum smart contracts.

## Essential Commands

### Development
```bash
# Run all tests (builds ethgen binary and runs example tests)
task test

# Run tests for a specific package
go test ./example/test/...

# Run all tests
go test ./...

# Format code
go fmt ./...

# Vet code
go vet ./...
```

### Code Generation Workflow
```bash
# 1. Compile Solidity contracts to artifacts (.abi.json, .bin)
go run . compile --outdir ./artifacts ./path/to/contracts

# 2. Generate Go bindings from artifacts
go run . bind --handlers --fakes --outdir ./bindings ./artifacts
```

## Architecture Overview

### Core Components

1. **Parser (parser/)**: ANTLR-based Solidity parser that analyzes contract structure
- Entry: `parser/parse.go` - Parses Solidity files into AST
- Grammar: `parser/Solidity.g4` - Defines Solidity syntax

2. **Compiler Integration (solc/)**: Manages Solidity compiler versions
- `solc/resolver.go` - Resolves and downloads compiler versions
- `solc/compile.go` - Handles compilation process

3. **Code Generation (codegen/)**: Generates Go code from contract artifacts
- `codegen/contract.go` - Main contract binding generation
- `codegen/fake.go` - Test fake generation with setter/emitter methods
- `codegen/processor.go` - Processes artifacts and coordinates generation

4. **CLI (cmd/)**: Command-line interface implementations
- `cmd/compile.go` - Compile command implementation
- `cmd/bind.go` - Bind command with --handlers and --fakes flags
- `cmd/root.go` - CLI configuration and command registration

### Key Design Patterns

1. **Fake Contracts**: For testing, generates contracts with additional methods:
- `fakeSet[MethodName]()` - Set return values for view/pure functions
- `fakeEmit[EventName]()` - Programmatically emit events
- Supports struct types as of recent updates

2. **Event Handlers**: Generated with `--handlers` flag, creates typed event handler interfaces for indexing

3. **Compiler Resolution**: Automatically downloads and manages Solidity compiler versions based on pragma statements

### Testing Approach

Tests use simulated blockchain backend (`test.NewSimulatedBackend`) with deployed contracts. See `example/test/example_test.go` for patterns:
- Deploy contracts using generated bindings
- Use `eth.Commit()` to mine blocks
- Test fakes by setting return values before calling methods
Loading
Loading