debug_traceBlockByNumber pattern test (#8655)

added debug_traceBlockByNumber API pattern test
This commit is contained in:
Sixtysixter 2023-11-07 09:51:25 +01:00 committed by GitHub
parent 509a7af26a
commit d1271268c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 79 additions and 1 deletions

View File

@ -290,6 +290,19 @@ func main() {
}
with(benchTraceFilterCmd, withGethUrl, withErigonUrl, withNeedCompare, withBlockNum, withRecord, withErrorFile)
var benchDebugTraceBlockByNumberCmd = &cobra.Command{
Use: "benchDebugTraceBlockByNumber",
Short: "",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
err := rpctest.BenchDebugTraceBlockByNumber(erigonURL, gethURL, needCompare, blockFrom, blockTo, recordFile, errorFile)
if err != nil {
logger.Error(err.Error())
}
},
}
with(benchDebugTraceBlockByNumberCmd, withErigonUrl, withGethUrl, withNeedCompare, withBlockNum, withRecord, withErrorFile, withLatest)
var benchTxReceiptCmd = &cobra.Command{
Use: "benchTxReceipt",
Short: "",
@ -384,6 +397,7 @@ func main() {
benchTraceCallManyCmd,
benchTraceBlockCmd,
benchTraceFilterCmd,
benchDebugTraceBlockByNumberCmd,
benchTxReceiptCmd,
compareAccountRange,
benchTraceReplayTransactionCmd,

View File

@ -0,0 +1,58 @@
package rpctest
import (
"bufio"
"fmt"
"net/http"
"os"
"time"
)
func BenchDebugTraceBlockByNumber(erigonUrl, gethUrl string, needCompare bool, blockFrom uint64, blockTo uint64, recordFileName string, errorFileName string) error {
setRoutes(erigonUrl, gethUrl)
var client = &http.Client{
Timeout: time.Second * 600,
}
var rec *bufio.Writer
if recordFileName != "" {
f, err := os.Create(recordFileName)
if err != nil {
return fmt.Errorf("Cannot create file %s for recording: %v\n", recordFileName, err)
}
defer f.Close()
rec = bufio.NewWriter(f)
defer rec.Flush()
}
var errs *bufio.Writer
if errorFileName != "" {
ferr, err := os.Create(errorFileName)
if err != nil {
return fmt.Errorf("Cannot create file %s for error output: %v\n", errorFileName, err)
}
defer ferr.Close()
errs = bufio.NewWriter(ferr)
defer errs.Flush()
}
var resultsCh chan CallResult = nil
if !needCompare {
resultsCh = make(chan CallResult, 1000)
defer close(resultsCh)
go vegetaWrite(true, []string{"debug_traceBlockByNumber"}, resultsCh)
}
reqGen := &RequestGenerator{
client: client,
}
for bn := blockFrom; bn < blockTo; bn++ {
reqGen.reqID++
request := reqGen.debugTraceBlockByNumber(bn)
errCtx := fmt.Sprintf("block %d", bn)
if err := requestAndCompare(request, "debug_traceBlockByNumber", errCtx, reqGen, needCompare, rec, errs, resultsCh); err != nil {
return err
}
}
return nil
}

View File

@ -3,11 +3,12 @@ package rpctest
import (
"encoding/base64"
"fmt"
"github.com/ledgerwatch/erigon-lib/common/hexutil"
"net/http"
"strings"
"time"
"github.com/ledgerwatch/erigon-lib/common/hexutil"
"github.com/valyala/fastjson"
libcommon "github.com/ledgerwatch/erigon-lib/common"
@ -58,6 +59,11 @@ func (g *RequestGenerator) traceBlockByHash(hash string) string {
return fmt.Sprintf(template, hash, g.reqID)
}
func (g *RequestGenerator) debugTraceBlockByNumber(blockNum uint64) string {
const template = `{"jsonrpc":"2.0","method":"debug_traceBlockByNumber","params":[%d],"id":%d}`
return fmt.Sprintf(template, blockNum, g.reqID)
}
func (g *RequestGenerator) traceTransaction(hash string) string {
const template = `{"jsonrpc":"2.0","method":"debug_traceTransaction","params":["%s"],"id":%d}`
return fmt.Sprintf(template, hash, g.reqID)