mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
add used gas
This commit is contained in:
parent
74f41ac3e9
commit
46040cc544
2 changed files with 13 additions and 10 deletions
|
|
@ -183,11 +183,14 @@ func runStateTest(ctx *cli.Context, fname string, cfg vm.Config, dump bool, benc
|
|||
|
||||
if !bench {
|
||||
return nil
|
||||
} else if len(matchingTests) != 1 {
|
||||
return fmt.Errorf("can only benchmark single state test case (more than one matching params)")
|
||||
}
|
||||
var gasUsed uint64
|
||||
result := testing.Benchmark(func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
for _, test := range matchingTests {
|
||||
test.test.Run(test.st, cfg, false, rawdb.HashScheme, func(err error, tstate *tests.StateTestState) {})
|
||||
_, _, gasUsed, _ = test.test.RunNoVerify(test.st, cfg, false, rawdb.HashScheme)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
@ -201,6 +204,6 @@ func runStateTest(ctx *cli.Context, fname string, cfg vm.Config, dump bool, benc
|
|||
execution time: %v
|
||||
allocations: %d
|
||||
allocated bytes: %d
|
||||
`, 0, stats.time, stats.allocs, stats.bytesAllocated)
|
||||
`, gasUsed, stats.time, stats.allocs, stats.bytesAllocated)
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ func (t *StateTest) checkError(subtest StateSubtest, err error) error {
|
|||
|
||||
// Run executes a specific subtest and verifies the post-state and logs
|
||||
func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config, snapshotter bool, scheme string, postCheck func(err error, st *StateTestState)) (result error) {
|
||||
st, root, err := t.RunNoVerify(subtest, vmconfig, snapshotter, scheme)
|
||||
st, root, _, err := t.RunNoVerify(subtest, vmconfig, snapshotter, scheme)
|
||||
// Invoke the callback at the end of function for further analysis.
|
||||
defer func() {
|
||||
postCheck(result, &st)
|
||||
|
|
@ -228,10 +228,10 @@ func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config, snapshotter bo
|
|||
|
||||
// RunNoVerify runs a specific subtest and returns the statedb and post-state root.
|
||||
// Remember to call state.Close after verifying the test result!
|
||||
func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapshotter bool, scheme string) (st StateTestState, root common.Hash, err error) {
|
||||
func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapshotter bool, scheme string) (st StateTestState, root common.Hash, gasUsed uint64, err error) {
|
||||
config, eips, err := GetChainConfig(subtest.Fork)
|
||||
if err != nil {
|
||||
return st, common.Hash{}, UnsupportedForkError{subtest.Fork}
|
||||
return st, common.Hash{}, 0, UnsupportedForkError{subtest.Fork}
|
||||
}
|
||||
vmconfig.ExtraEips = eips
|
||||
|
||||
|
|
@ -250,7 +250,7 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapsh
|
|||
post := t.json.Post[subtest.Fork][subtest.Index]
|
||||
msg, err := t.json.Tx.toMessage(post, baseFee)
|
||||
if err != nil {
|
||||
return st, common.Hash{}, err
|
||||
return st, common.Hash{}, 0, err
|
||||
}
|
||||
|
||||
{ // Blob transactions may be present after the Cancun fork.
|
||||
|
|
@ -260,7 +260,7 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapsh
|
|||
// Here, we just do this shortcut smaller fix, since state tests do not
|
||||
// utilize those codepaths
|
||||
if len(msg.BlobHashes)*params.BlobTxBlobGasPerBlob > params.MaxBlobGasPerBlock {
|
||||
return st, common.Hash{}, errors.New("blob gas exceeds maximum")
|
||||
return st, common.Hash{}, 0, errors.New("blob gas exceeds maximum")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -269,10 +269,10 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapsh
|
|||
var ttx types.Transaction
|
||||
err := ttx.UnmarshalBinary(post.TxBytes)
|
||||
if err != nil {
|
||||
return st, common.Hash{}, err
|
||||
return st, common.Hash{}, 0, err
|
||||
}
|
||||
if _, err := types.Sender(types.LatestSigner(config), &ttx); err != nil {
|
||||
return st, common.Hash{}, err
|
||||
return st, common.Hash{}, 0, err
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -322,7 +322,7 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapsh
|
|||
receipt := &types.Receipt{GasUsed: vmRet.UsedGas}
|
||||
tracer.OnTxEnd(receipt, nil)
|
||||
}
|
||||
return st, root, err
|
||||
return st, root, vmRet.UsedGas, err
|
||||
}
|
||||
|
||||
func (t *StateTest) gasLimit(subtest StateSubtest) uint64 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue