Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
colinlyguo committed Apr 16, 2024
1 parent d32c1ef commit 175d544
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
31 changes: 31 additions & 0 deletions Dockerfile.localtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Build libzkp dependency
FROM --platform=linux/arm64 scrolltech/go-rust-builder:go-1.20-rust-nightly-2022-12-10 as chef
WORKDIR app

FROM chef as planner
COPY ./rollup/circuitcapacitychecker/libzkp/ .
RUN cargo chef prepare --recipe-path recipe.json

FROM chef as zkp-builder
COPY ./rollup/circuitcapacitychecker/libzkp/rust-toolchain ./
COPY --from=planner /app/recipe.json recipe.json
RUN mkdir -p .cargo && \
echo '[source.crates-io]' > .cargo/config.toml && \
echo 'registry = "https://github.com/rust-lang/crates.io-index"' >> .cargo/config.toml && \
echo 'replace-with = "ustc"' >> .cargo/config.toml && \
echo '[source.ustc]' >> .cargo/config.toml && \
echo 'registry = "git://mirrors.ustc.edu.cn/crates.io-index"' >> .cargo/config.toml
RUN cargo chef cook --release --recipe-path recipe.json

COPY ./rollup/circuitcapacitychecker/libzkp .
RUN cargo clean
RUN cargo build --release
RUN find ./ | grep libzktrie.so | xargs -I{} cp {} /app/target/release/

# Build Geth in a stock Go builder container
FROM scrolltech/go-rust-builder:go-1.20-rust-nightly-2022-12-10 as builder

ADD . /go-ethereum
COPY --from=zkp-builder /app/target/release/libzkp.so /usr/local/lib/
COPY --from=zkp-builder /app/target/release/libzktrie.so /usr/local/lib/
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/
4 changes: 2 additions & 2 deletions rollup/circuitcapacitychecker/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (ccc *CircuitCapacityChecker) CheckTxNum(expected int) (bool, uint64, error
return false, 0, fmt.Errorf("fail to json unmarshal get_tx_num result, id: %d, err: %w", ccc.ID, err)
}
if result.Error != "" {
return false, 0, fmt.Errorf("fail to get_tx_num in CircuitCapacityChecker, id: %d, err: %w", ccc.ID, result.Error)
return false, 0, fmt.Errorf("fail to get_tx_num in CircuitCapacityChecker, id: %d, err: %s", ccc.ID, result.Error)
}

return result.TxNum == uint64(expected), result.TxNum, nil
Expand All @@ -189,7 +189,7 @@ func (ccc *CircuitCapacityChecker) SetLightMode(lightMode bool) error {
return fmt.Errorf("fail to json unmarshal set_light_mode result, id: %d, err: %w", ccc.ID, err)
}
if result.Error != "" {
return fmt.Errorf("fail to set_light_mode in CircuitCapacityChecker, id: %d, err: %w", ccc.ID, result.Error)
return fmt.Errorf("fail to set_light_mode in CircuitCapacityChecker, id: %d, err: %s", ccc.ID, result.Error)
}

return nil
Expand Down
32 changes: 32 additions & 0 deletions rollup/circuitcapacitychecker/impl_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package circuitcapacitychecker

import (
"encoding/json"
"os"
"testing"

"github.com/scroll-tech/go-ethereum/core/types"
)

func BenchmarkApplyTransaction(b *testing.B) {
data, err := os.ReadFile("block_trace_0xac92e50305b280808a06573888c89cde3556b79d72556c8cdfa97dc6b5695e44.json")
if err != nil {
b.Fatalf("Error reading block trace file: %v", err)
}

var blockTrace types.BlockTrace
err = json.Unmarshal(data, &blockTrace)
if err != nil {
b.Fatalf("Error unmarshaling block trace JSON: %v", err)
}

ccc := NewCircuitCapacityChecker(true)

b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := ccc.ApplyTransaction(&blockTrace)
if err != nil {
b.Fatalf("Error applying transaction: %v", err)
}
}
}

0 comments on commit 175d544

Please sign in to comment.