import '../justfiles/go.just'

# Build ldflags string
_VERSION_META_STR := if VERSION_META != "" { "+" + VERSION_META } else { "" }
_LDFLAGSSTRING := "'" + trim(
    "-X main.GitCommit=" + GITCOMMIT + " " + \
    "-X main.GitDate=" + GITDATE + " " + \
    "-X github.com/ethereum-optimism/optimism/op-chain-ops/deployer/version.Version=" + VERSION + " " + \
    "-X github.com/ethereum-optimism/optimism/op-chain-ops/deployer/version.Meta=" + _VERSION_META_STR + " " + \
    "") + "'"

# Build ecotone-scalar binary
ecotone-scalar: (go_build "./bin/ecotone-scalar" "./cmd/ecotone-scalar" "-ldflags" _LDFLAGSSTRING)

# Build receipt-reference-builder binary  
receipt-reference-builder: (go_build "./bin/receipt-reference-builder" "./cmd/receipt-reference-builder" "-ldflags" _LDFLAGSSTRING)

# Run tests
test: (go_test "./...")

# Build op-deployer binary
op-deployer:
    just ../op-deployer/build
    mkdir -p ./bin && ln -f ../op-deployer/bin/op-deployer ./bin/op-deployer

# Run fuzzing tests
[private]
fuzz_task FUZZ TIME='10s': (go_fuzz FUZZ TIME "./crossdomain")

fuzz:
    printf "%s\n" \
        "FuzzEncodeDecodeWithdrawal" \
        "FuzzEncodeDecodeLegacyWithdrawal" \
        "FuzzAliasing" \
        "FuzzVersionedNonce" \
    | parallel -j {{PARALLEL_JOBS}} {{just_executable()}} fuzz_task {}
