github.com/cryptotooltop/go-ethereum@v0.0.0-20231103184714-151d1922f3e5/rollup/circuitcapacitychecker/mock.go (about) 1 //go:build !circuit_capacity_checker 2 3 package circuitcapacitychecker 4 5 import ( 6 "math/rand" 7 8 "github.com/scroll-tech/go-ethereum/core/types" 9 ) 10 11 type CircuitCapacityChecker struct { 12 ID uint64 13 countdown int 14 nextError *error 15 } 16 17 // NewCircuitCapacityChecker creates a new CircuitCapacityChecker 18 func NewCircuitCapacityChecker(lightMode bool) *CircuitCapacityChecker { 19 ccc := &CircuitCapacityChecker{ID: rand.Uint64()} 20 ccc.SetLightMode(lightMode) 21 return ccc 22 } 23 24 // Reset resets a ccc, but need to do nothing in mock_ccc. 25 func (ccc *CircuitCapacityChecker) Reset() { 26 } 27 28 // ApplyTransaction appends a tx's wrapped BlockTrace into the ccc, and return the accumulated RowConsumption. 29 // Will only return a dummy value in mock_ccc. 30 func (ccc *CircuitCapacityChecker) ApplyTransaction(traces *types.BlockTrace) (*types.RowConsumption, error) { 31 if ccc.nextError != nil { 32 ccc.countdown-- 33 if ccc.countdown == 0 { 34 err := *ccc.nextError 35 ccc.nextError = nil 36 return nil, err 37 } 38 } 39 return &types.RowConsumption{types.SubCircuitRowUsage{ 40 Name: "mock", 41 RowNumber: 1, 42 }}, nil 43 } 44 45 // ApplyBlock gets a block's RowConsumption. 46 // Will only return a dummy value in mock_ccc. 47 func (ccc *CircuitCapacityChecker) ApplyBlock(traces *types.BlockTrace) (*types.RowConsumption, error) { 48 return &types.RowConsumption{types.SubCircuitRowUsage{ 49 Name: "mock", 50 RowNumber: 2, 51 }}, nil 52 } 53 54 // CheckTxNum compares whether the tx_count in ccc match the expected. 55 // Will alway return true in mock_ccc. 56 func (ccc *CircuitCapacityChecker) CheckTxNum(expected int) (bool, uint64, error) { 57 return true, uint64(expected), nil 58 } 59 60 // SetLightMode sets to ccc light mode 61 func (ccc *CircuitCapacityChecker) SetLightMode(lightMode bool) error { 62 return nil 63 } 64 65 // ScheduleError schedules an error for a tx (see `ApplyTransaction`), only used in tests. 66 func (ccc *CircuitCapacityChecker) ScheduleError(cnt int, err error) { 67 ccc.countdown = cnt 68 ccc.nextError = &err 69 }