@ -159,11 +159,39 @@ func (t *StateTest) Subtests() []StateSubtest {
return sub
}
// checkError checks if the error returned by the state transition matches any expected error.
// A failing expectation returns a wrapped version of the original error, if any,
// or a new error detailing the failing expectation.
// This function does not return or modify the original error, it only evaluates and returns expectations for the error.
func ( t * StateTest ) checkError ( subtest StateSubtest , err error ) error {
expectedError := t . json . Post [ subtest . Fork ] [ subtest . Index ] . ExpectException
if err == nil && expectedError == "" {
return nil
}
if err == nil && expectedError != "" {
return fmt . Errorf ( "expected error %q, got no error" , expectedError )
}
if err != nil && expectedError == "" {
return fmt . Errorf ( "unexpected error: %w" , err )
}
if err != nil && expectedError != "" {
// Ignore expected errors (TODO MariusVanDerWijden check error string)
return nil
}
return nil
}
// Run executes a specific subtest and verifies the post-state and logs
func ( t * StateTest ) Run ( subtest StateSubtest , vmconfig vm . Config , snapshotter bool ) ( * snapshot . Tree , * state . StateDB , error ) {
snaps , statedb , root , err := t . RunNoVerify ( subtest , vmconfig , snapshotter )
if checkedErr := t . checkError ( subtest , err ) ; checkedErr != nil {
return snaps , statedb , checkedErr
}
// The error has been checked; if it was unexpected, it's already returned.
if err != nil {
return snaps , statedb , err
// Here, an error exists but it was expected.
// We do not check the post state or logs.
return snaps , statedb , nil
}
post := t . json . Post [ subtest . Fork ] [ subtest . Index ]
// N.B: We need to do this in a two-step process, because the first Commit takes care
@ -231,7 +259,8 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapsh
snapshot := statedb . Snapshot ( )
gaspool := new ( core . GasPool )
gaspool . AddGas ( block . GasLimit ( ) )
if _ , err := core . ApplyMessage ( evm , msg , gaspool ) ; err != nil {
_ , err = core . ApplyMessage ( evm , msg , gaspool )
if err != nil {
statedb . RevertToSnapshot ( snapshot )
}
// Add 0-value mining reward. This only makes a difference in the cases
@ -244,7 +273,7 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapsh
statedb . Commit ( config . IsEIP158 ( block . Number ( ) ) )
// And _now_ get the state root
root := statedb . IntermediateRoot ( config . IsEIP158 ( block . Number ( ) ) )
return snaps , statedb , root , nil
return snaps , statedb , root , err
}
func ( t * StateTest ) gasLimit ( subtest StateSubtest ) uint64 {