diff --git a/core/vm/instructions_test.go b/core/vm/instructions_test.go index 56cb2686a6..7154983f4a 100644 --- a/core/vm/instructions_test.go +++ b/core/vm/instructions_test.go @@ -19,6 +19,7 @@ package vm import ( "bytes" "encoding/json" + "errors" "fmt" "math/big" "os" @@ -1015,7 +1016,7 @@ func TestEIP8024_Execution(t *testing.T) { tests := []struct { name string codeHex string - wantErr bool + wantErr error wantVals []uint64 }{ { @@ -1071,53 +1072,53 @@ func TestEIP8024_Execution(t *testing.T) { { name: "INVALID_SWAPN_LOW", codeHex: "e75b", - wantErr: true, + wantErr: &ErrInvalidOpCode{}, }, { name: "JUMP over INVALID_DUPN", codeHex: "600456e65b", - wantErr: false, + wantErr: nil, }, // Additional test cases { name: "INVALID_DUPN_LOW", codeHex: "e65b", - wantErr: true, + wantErr: &ErrInvalidOpCode{}, }, { name: "INVALID_EXCHANGE_LOW", codeHex: "e850", - wantErr: true, + wantErr: &ErrInvalidOpCode{}, }, { name: "INVALID_DUPN_HIGH", codeHex: "e67f", - wantErr: true, + wantErr: &ErrInvalidOpCode{}, }, { name: "INVALID_SWAPN_HIGH", codeHex: "e77f", - wantErr: true, + wantErr: &ErrInvalidOpCode{}, }, { name: "INVALID_EXCHANGE_HIGH", codeHex: "e87f", - wantErr: true, + wantErr: &ErrInvalidOpCode{}, }, { name: "UNDERFLOW_DUPN", codeHex: "5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5fe600", // (n=17, need 17 items, have 16) - wantErr: true, + wantErr: &ErrStackUnderflow{}, }, { name: "UNDERFLOW_SWAPN", codeHex: "5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5fe700", // (n=17, need 18 items, have 17) - wantErr: true, + wantErr: &ErrStackUnderflow{}, }, { name: "UNDERFLOW_EXCHANGE", codeHex: "60016002e801", // (n,m)=(1,2), need 3 items, have 2 - wantErr: true, + wantErr: &ErrStackUnderflow{}, }, { name: "PC_INCREMENT", @@ -1149,6 +1150,8 @@ func TestEIP8024_Execution(t *testing.T) { _, err = opJumpdest(&pc, evm, scope) case ISZERO: _, err = opIszero(&pc, evm, scope) + case PUSH0: + _, err = opPush0(&pc, evm, scope) case DUPN: _, err = opDupN(&pc, evm, scope) case SWAPN: @@ -1156,14 +1159,28 @@ func TestEIP8024_Execution(t *testing.T) { case EXCHANGE: _, err = opExchange(&pc, evm, scope) default: - err = &ErrInvalidOpCode{opcode: OpCode(op)} + t.Fatalf("unexpected opcode %s at pc=%d", OpCode(op), pc) } pc++ } - if tc.wantErr { + if tc.wantErr != nil { if err == nil { t.Fatalf("expected error, got nil") } + switch tc.wantErr.(type) { + case *ErrInvalidOpCode: + var want *ErrInvalidOpCode + if !errors.As(err, &want) { + t.Fatalf("expected ErrInvalidOpCode, got %v", err) + } + case *ErrStackUnderflow: + var want *ErrStackUnderflow + if !errors.As(err, &want) { + t.Fatalf("expected ErrStackUnderflow, got %v", err) + } + default: + t.Fatalf("unsupported wantErr type %T", tc.wantErr) + } return } if err != nil {