mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-19 19:30:44 +00:00
core/vm: specify the opcode that should throw error
This commit is contained in:
parent
40ab2dd1e2
commit
903bc0c933
1 changed files with 55 additions and 34 deletions
|
|
@ -1014,10 +1014,11 @@ func TestEIP8024_Execution(t *testing.T) {
|
||||||
evm := NewEVM(BlockContext{}, nil, params.TestChainConfig, Config{})
|
evm := NewEVM(BlockContext{}, nil, params.TestChainConfig, Config{})
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
codeHex string
|
codeHex string
|
||||||
wantErr error
|
wantErr error
|
||||||
wantVals []uint64
|
wantOpcode OpCode
|
||||||
|
wantVals []uint64
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "DUPN",
|
name: "DUPN",
|
||||||
|
|
@ -1070,9 +1071,10 @@ func TestEIP8024_Execution(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "INVALID_SWAPN_LOW",
|
name: "INVALID_SWAPN_LOW",
|
||||||
codeHex: "e75b",
|
codeHex: "e75b",
|
||||||
wantErr: &ErrInvalidOpCode{},
|
wantErr: &ErrInvalidOpCode{},
|
||||||
|
wantOpcode: SWAPN,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "JUMP over INVALID_DUPN",
|
name: "JUMP over INVALID_DUPN",
|
||||||
|
|
@ -1080,50 +1082,59 @@ func TestEIP8024_Execution(t *testing.T) {
|
||||||
wantErr: nil,
|
wantErr: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "UNDERFLOW_DUPN",
|
name: "UNDERFLOW_DUPN_1",
|
||||||
codeHex: "6000808080808080808080808080808080e600",
|
codeHex: "6000808080808080808080808080808080e600",
|
||||||
wantErr: &ErrStackUnderflow{},
|
wantErr: &ErrStackUnderflow{},
|
||||||
|
wantOpcode: DUPN,
|
||||||
},
|
},
|
||||||
// Additional test cases
|
// Additional test cases
|
||||||
{
|
{
|
||||||
name: "INVALID_DUPN_LOW",
|
name: "INVALID_DUPN_LOW",
|
||||||
codeHex: "e65b",
|
codeHex: "e65b",
|
||||||
wantErr: &ErrInvalidOpCode{},
|
wantErr: &ErrInvalidOpCode{},
|
||||||
|
wantOpcode: DUPN,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "INVALID_EXCHANGE_LOW",
|
name: "INVALID_EXCHANGE_LOW",
|
||||||
codeHex: "e850",
|
codeHex: "e850",
|
||||||
wantErr: &ErrInvalidOpCode{},
|
wantErr: &ErrInvalidOpCode{},
|
||||||
|
wantOpcode: EXCHANGE,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "INVALID_DUPN_HIGH",
|
name: "INVALID_DUPN_HIGH",
|
||||||
codeHex: "e67f",
|
codeHex: "e67f",
|
||||||
wantErr: &ErrInvalidOpCode{},
|
wantErr: &ErrInvalidOpCode{},
|
||||||
|
wantOpcode: DUPN,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "INVALID_SWAPN_HIGH",
|
name: "INVALID_SWAPN_HIGH",
|
||||||
codeHex: "e77f",
|
codeHex: "e77f",
|
||||||
wantErr: &ErrInvalidOpCode{},
|
wantErr: &ErrInvalidOpCode{},
|
||||||
|
wantOpcode: SWAPN,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "INVALID_EXCHANGE_HIGH",
|
name: "INVALID_EXCHANGE_HIGH",
|
||||||
codeHex: "e87f",
|
codeHex: "e87f",
|
||||||
wantErr: &ErrInvalidOpCode{},
|
wantErr: &ErrInvalidOpCode{},
|
||||||
|
wantOpcode: EXCHANGE,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "UNDERFLOW_DUPN",
|
name: "UNDERFLOW_DUPN_2",
|
||||||
codeHex: "5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5fe600", // (n=17, need 17 items, have 16)
|
codeHex: "5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5fe600", // (n=17, need 17 items, have 16)
|
||||||
wantErr: &ErrStackUnderflow{},
|
wantErr: &ErrStackUnderflow{},
|
||||||
|
wantOpcode: DUPN,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "UNDERFLOW_SWAPN",
|
name: "UNDERFLOW_SWAPN",
|
||||||
codeHex: "5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5fe700", // (n=17, need 18 items, have 17)
|
codeHex: "5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5fe700", // (n=17, need 18 items, have 17)
|
||||||
wantErr: &ErrStackUnderflow{},
|
wantErr: &ErrStackUnderflow{},
|
||||||
|
wantOpcode: SWAPN,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "UNDERFLOW_EXCHANGE",
|
name: "UNDERFLOW_EXCHANGE",
|
||||||
codeHex: "60016002e801", // (n,m)=(1,2), need 3 items, have 2
|
codeHex: "60016002e801", // (n,m)=(1,2), need 3 items, have 2
|
||||||
wantErr: &ErrStackUnderflow{},
|
wantErr: &ErrStackUnderflow{},
|
||||||
|
wantOpcode: EXCHANGE,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "PC_INCREMENT",
|
name: "PC_INCREMENT",
|
||||||
|
|
@ -1139,6 +1150,7 @@ func TestEIP8024_Execution(t *testing.T) {
|
||||||
pc := uint64(0)
|
pc := uint64(0)
|
||||||
scope := &ScopeContext{Stack: stack, Contract: &Contract{Code: code}}
|
scope := &ScopeContext{Stack: stack, Contract: &Contract{Code: code}}
|
||||||
var err error
|
var err error
|
||||||
|
var errOp OpCode
|
||||||
for pc < uint64(len(code)) && err == nil {
|
for pc < uint64(len(code)) && err == nil {
|
||||||
op := code[pc]
|
op := code[pc]
|
||||||
switch OpCode(op) {
|
switch OpCode(op) {
|
||||||
|
|
@ -1166,12 +1178,21 @@ func TestEIP8024_Execution(t *testing.T) {
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unexpected opcode %s at pc=%d", OpCode(op), pc)
|
t.Fatalf("unexpected opcode %s at pc=%d", OpCode(op), pc)
|
||||||
}
|
}
|
||||||
|
if err != nil {
|
||||||
|
errOp = OpCode(op)
|
||||||
|
}
|
||||||
pc++
|
pc++
|
||||||
}
|
}
|
||||||
if tc.wantErr != nil {
|
if tc.wantErr != nil {
|
||||||
|
// Fail because we wanted an error, but didn't get one.
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("expected error, got nil")
|
t.Fatalf("expected error, got nil")
|
||||||
}
|
}
|
||||||
|
// Fail if the wrong opcode threw an error.
|
||||||
|
if errOp != tc.wantOpcode {
|
||||||
|
t.Fatalf("expected error from opcode %s, got %s", tc.wantOpcode, errOp)
|
||||||
|
}
|
||||||
|
// Fail if we don't get the error we expect.
|
||||||
switch tc.wantErr.(type) {
|
switch tc.wantErr.(type) {
|
||||||
case *ErrInvalidOpCode:
|
case *ErrInvalidOpCode:
|
||||||
var want *ErrInvalidOpCode
|
var want *ErrInvalidOpCode
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue