-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
153 lines (130 loc) · 5.22 KB
/
Makefile
File metadata and controls
153 lines (130 loc) · 5.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Loadtest_v2 Makefile
# Generates Go bindings for smart contracts and builds the seiload CLI
# Directories
CONTRACTS_DIR := generator/contracts
SCENARIOS_DIR := generator/scenarios
BINDINGS_DIR := generator/bindings
BUILD_DIR := build
# Binary configuration
BINARY_NAME := seiload
INSTALL_PATH := $(GOPATH)/bin
ifeq ($(GOPATH),)
INSTALL_PATH := $(HOME)/go/bin
endif
# Tools
SOLC := /tmp/solc
ABIGEN := abigen
NVM_DIR := $(HOME)/.nvm
NODE_VERSION := 20
# Find all .sol files in contracts directory
SOL_FILES := $(wildcard $(CONTRACTS_DIR)/*.sol)
CONTRACT_NAMES := $(basename $(notdir $(SOL_FILES)))
# Generated files
ABI_FILES := $(addprefix $(BUILD_DIR)/, $(addsuffix .abi, $(CONTRACT_NAMES)))
BIN_FILES := $(addprefix $(BUILD_DIR)/, $(addsuffix .bin, $(CONTRACT_NAMES)))
BINDING_FILES := $(addprefix $(BINDINGS_DIR)/, $(addsuffix .go, $(CONTRACT_NAMES)))
SCENARIO_TEMPLATE_FILES := $(addprefix $(SCENARIOS_DIR)/, $(addsuffix .go, $(CONTRACT_NAMES)))
.PHONY: generate clean help build-cli install setup-node build test lint
# Default target
help:
@echo "Available targets:"
@echo " build - Build the seiload CLI (alias for build-cli)"
@echo " test - Run tests with coverage"
@echo " lint - Run linting and static analysis"
@echo " setup-node - Install nvm, Node.js 20, and solc"
@echo " generate - Generate Go bindings and scenario templates for all contracts"
@echo " clean - Remove generated files"
@echo " help - Show this help message"
@echo " build-cli - Build the seiload CLI"
@echo " install - Install the seiload CLI"
# Setup Node.js environment with nvm
setup-node:
@echo "🔧 Setting up Node.js environment..."
@if [ ! -d "$(NVM_DIR)" ]; then \
echo "📦 Installing nvm..."; \
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash; \
echo "🔄 Sourcing nvm for current session..."; \
export NVM_DIR="$(HOME)/.nvm"; \
[ -s "$$NVM_DIR/nvm.sh" ] && . "$$NVM_DIR/nvm.sh"; \
else \
echo "✅ nvm already installed"; \
fi
@echo "🔧 Setting up Node.js $(NODE_VERSION)..."
@export NVM_DIR="$(HOME)/.nvm" && \
[ -s "$$NVM_DIR/nvm.sh" ] && . "$$NVM_DIR/nvm.sh" && \
nvm install $(NODE_VERSION) && \
nvm use $(NODE_VERSION)
@echo "📦 Installing native solc binary..."
@curl -L https://github.com/ethereum/solidity/releases/download/v0.8.19/solc-static-linux -o /tmp/solc && \
chmod +x /tmp/solc
@echo "✅ Node.js environment setup complete"
@echo "ℹ️ Note: You may need to restart your shell or run 'source ~/.bashrc' to use nvm in new sessions"
# Main generate target
generate: $(BINDING_FILES) $(SCENARIO_TEMPLATE_FILES)
@echo "🏭 Updating scenario factory..."
@./scripts/update_factory.sh $(CONTRACT_NAMES)
@echo "✅ Generated bindings and scenario templates for contracts: $(CONTRACT_NAMES)"
# Create build directory
$(BUILD_DIR):
@mkdir -p $(BUILD_DIR)
# Create bindings directory
$(BINDINGS_DIR):
@mkdir -p $(BINDINGS_DIR)
# Create scenarios directory
$(SCENARIOS_DIR):
@mkdir -p $(SCENARIOS_DIR)
# Compile a single contract to ABI and bytecode
$(BUILD_DIR)/%.abi $(BUILD_DIR)/%.bin: $(CONTRACTS_DIR)/%.sol | $(BUILD_DIR)
@echo "🔨 Compiling contract: $*"
@$(SOLC) --abi --bin --optimize --overwrite -o $(BUILD_DIR) $<
@echo "✅ Compiled: $*"
# Generate Go binding from ABI and bytecode
$(BINDINGS_DIR)/%.go: $(BUILD_DIR)/%.abi $(BUILD_DIR)/%.bin | $(BINDINGS_DIR)
@echo "🏭 Generating Go binding: $*"
@$(ABIGEN) --abi=$(BUILD_DIR)/$*.abi --bin=$(BUILD_DIR)/$*.bin --pkg=bindings --type=$* --out=$@
@echo "✅ Generated binding: $*"
# Generate scenario template files (only if they don't exist)
$(SCENARIOS_DIR)/%.go: | $(SCENARIOS_DIR)
@./scripts/generate_scenario_template.sh $* $@
# Clean generated files
clean:
@echo "🧹 Cleaning generated files ..."
@rm -rf $(BUILD_DIR) $(BINDINGS_DIR)
@echo "✅ Cleaned up generated files"
# Check if required tools are installed
check-tools:
@echo "🔍 Checking required tools ..."
@which $(SOLC) > /dev/null || (echo "❌ solc not found. Run 'make setup-node' to install" && exit 1)
@which $(ABIGEN) > /dev/null || (echo "❌ abigen not found. Run 'make install-tools' to install" && exit 1)
@echo "✅ All required tools are available"
# Install tools (optional convenience target)
install-tools: setup-node
@echo "📦 Installing required tools ..."
@echo "Installing abigen ..."
@go install github.com/ethereum/go-ethereum/cmd/abigen@latest
@echo "✅ Tools installation complete"
# Build the seiload CLI binary
build-cli: | $(BUILD_DIR)
@echo "🔨 Building CLI"
@go mod tidy
@go mod download
@go build -o $(BUILD_DIR)/$(BINARY_NAME) .
@echo "✅ Built CLI: $(BUILD_DIR)/$(BINARY_NAME)"
# Install the seiload CLI
install: build-cli
@echo "📦 Installing CLI ..."
@cp $(BUILD_DIR)/$(BINARY_NAME) $(INSTALL_PATH)/$(BINARY_NAME)
@echo "✅ Installed CLI: $(BINARY_NAME)"
# Build the seiload CLI binary (alias for build-cli)
build: build-cli
# Run tests with coverage
test:
@echo "🔍 Running tests with coverage..."
@go test -v -race -coverprofile=coverage.out ./...
@go tool cover -func=coverage.out
@echo "✅ Tests passed"
# Run linting and static analysis
lint:
@echo "🔍 Running linting and static analysis..."
@golangci-lint run
@echo "✅ Linting and static analysis passed"