mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-24 09:25:21 +00:00
vm: remove XSWAP/XTUCK opcodes
Regenerate RPC testchain as these were used in compiler.
This commit is contained in:
parent
d18199ce42
commit
dd20320615
7 changed files with 62 additions and 142 deletions
|
@ -47,18 +47,18 @@ type rpcTestCase struct {
|
|||
check func(t *testing.T, e *executor, result interface{})
|
||||
}
|
||||
|
||||
const testContractHash = "5d49c5a1127c23ad64a2ede6259b8ca61cc9f2fb"
|
||||
const testContractHash = "76751a2fdde4dc6c7489799a28bb539bc09d1f54"
|
||||
|
||||
var rpcTestCases = map[string][]rpcTestCase{
|
||||
"getapplicationlog": {
|
||||
{
|
||||
name: "positive",
|
||||
params: `["3f056daab3c7824a6bf2cc863b5d4a0089bb3561316d65bf5e344278c0311901"]`,
|
||||
params: `["113437bd8dfc44e3a6dfe77b750fcff246cbe933ca9667311f45d794cf0410cc"]`,
|
||||
result: func(e *executor) interface{} { return &result.ApplicationLog{} },
|
||||
check: func(t *testing.T, e *executor, acc interface{}) {
|
||||
res, ok := acc.(*result.ApplicationLog)
|
||||
require.True(t, ok)
|
||||
expectedTxHash, err := util.Uint256DecodeStringLE("3f056daab3c7824a6bf2cc863b5d4a0089bb3561316d65bf5e344278c0311901")
|
||||
expectedTxHash, err := util.Uint256DecodeStringLE("113437bd8dfc44e3a6dfe77b750fcff246cbe933ca9667311f45d794cf0410cc")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, expectedTxHash, res.TxHash)
|
||||
assert.Equal(t, 1, len(res.Executions))
|
||||
|
|
BIN
pkg/rpc/server/testdata/test_contract.avm
vendored
BIN
pkg/rpc/server/testdata/test_contract.avm
vendored
Binary file not shown.
BIN
pkg/rpc/server/testdata/testblocks.acc
vendored
BIN
pkg/rpc/server/testdata/testblocks.acc
vendored
Binary file not shown.
|
@ -92,8 +92,6 @@ const (
|
|||
DUPFROMALTSTACK Opcode = 0x6A
|
||||
TOALTSTACK Opcode = 0x6B
|
||||
FROMALTSTACK Opcode = 0x6C
|
||||
XSWAP Opcode = 0x72
|
||||
XTUCK Opcode = 0x73
|
||||
|
||||
// Splice
|
||||
CAT Opcode = 0x7E
|
||||
|
|
|
@ -82,8 +82,6 @@ func _() {
|
|||
_ = x[DUPFROMALTSTACK-106]
|
||||
_ = x[TOALTSTACK-107]
|
||||
_ = x[FROMALTSTACK-108]
|
||||
_ = x[XSWAP-114]
|
||||
_ = x[XTUCK-115]
|
||||
_ = x[CAT-126]
|
||||
_ = x[SUBSTR-127]
|
||||
_ = x[LEFT-128]
|
||||
|
@ -144,7 +142,7 @@ func _() {
|
|||
_ = x[THROWIFNOT-241]
|
||||
}
|
||||
|
||||
const _Opcode_name = "PUSHINT8PUSHINT16PUSHINT32PUSHINT64PUSHINT128PUSHINT256PUSHNULLPUSHDATA1PUSHDATA2PUSHDATA4PUSHM1PUSH0PUSH1PUSH2PUSH3PUSH4PUSH5PUSH6PUSH7PUSH8PUSH9PUSH10PUSH11PUSH12PUSH13PUSH14PUSH15PUSH16NOPJMPJMPLJMPIFJMPIFLJMPIFNOTJMPIFNOTLJMPEQJMPEQLJMPNEJMPNELJMPGTJMPGTLJMPGEJMPGELJMPLTJMPLTLJMPLEJMPLELCALLCALLLDEPTHDROPNIPXDROPCLEARDUPOVERPICKTUCKSWAPOLDPUSH1ROLLREVERSE3REVERSE4REVERSENRETAPPCALLSYSCALLTAILCALLDUPFROMALTSTACKTOALTSTACKFROMALTSTACKXSWAPXTUCKCATSUBSTRLEFTRIGHTINVERTANDORXOREQUALNOTEQUALSIGNABSNEGATEINCDECADDSUBMULDIVMODSHLSHRNOTBOOLANDBOOLORNZNUMEQUALNUMNOTEQUALLTLTEGTGTEMINMAXWITHINPACKUNPACKNEWARRAY0NEWARRAYNEWARRAYTNEWSTRUCT0NEWSTRUCTNEWMAPSIZEHASKEYKEYSVALUESPICKITEMAPPENDSETITEMREVERSEITEMSREMOVECLEARITEMSISNULLISTYPECONVERTTHROWTHROWIFNOT"
|
||||
const _Opcode_name = "PUSHINT8PUSHINT16PUSHINT32PUSHINT64PUSHINT128PUSHINT256PUSHNULLPUSHDATA1PUSHDATA2PUSHDATA4PUSHM1PUSH0PUSH1PUSH2PUSH3PUSH4PUSH5PUSH6PUSH7PUSH8PUSH9PUSH10PUSH11PUSH12PUSH13PUSH14PUSH15PUSH16NOPJMPJMPLJMPIFJMPIFLJMPIFNOTJMPIFNOTLJMPEQJMPEQLJMPNEJMPNELJMPGTJMPGTLJMPGEJMPGELJMPLTJMPLTLJMPLEJMPLELCALLCALLLDEPTHDROPNIPXDROPCLEARDUPOVERPICKTUCKSWAPOLDPUSH1ROLLREVERSE3REVERSE4REVERSENRETAPPCALLSYSCALLTAILCALLDUPFROMALTSTACKTOALTSTACKFROMALTSTACKCATSUBSTRLEFTRIGHTINVERTANDORXOREQUALNOTEQUALSIGNABSNEGATEINCDECADDSUBMULDIVMODSHLSHRNOTBOOLANDBOOLORNZNUMEQUALNUMNOTEQUALLTLTEGTGTEMINMAXWITHINPACKUNPACKNEWARRAY0NEWARRAYNEWARRAYTNEWSTRUCT0NEWSTRUCTNEWMAPSIZEHASKEYKEYSVALUESPICKITEMAPPENDSETITEMREVERSEITEMSREMOVECLEARITEMSISNULLISTYPECONVERTTHROWTHROWIFNOT"
|
||||
|
||||
var _Opcode_map = map[Opcode]string{
|
||||
0: _Opcode_name[0:8],
|
||||
|
@ -218,66 +216,64 @@ var _Opcode_map = map[Opcode]string{
|
|||
106: _Opcode_name[403:418],
|
||||
107: _Opcode_name[418:428],
|
||||
108: _Opcode_name[428:440],
|
||||
114: _Opcode_name[440:445],
|
||||
115: _Opcode_name[445:450],
|
||||
126: _Opcode_name[450:453],
|
||||
127: _Opcode_name[453:459],
|
||||
128: _Opcode_name[459:463],
|
||||
129: _Opcode_name[463:468],
|
||||
144: _Opcode_name[468:474],
|
||||
145: _Opcode_name[474:477],
|
||||
146: _Opcode_name[477:479],
|
||||
147: _Opcode_name[479:482],
|
||||
151: _Opcode_name[482:487],
|
||||
152: _Opcode_name[487:495],
|
||||
153: _Opcode_name[495:499],
|
||||
154: _Opcode_name[499:502],
|
||||
155: _Opcode_name[502:508],
|
||||
156: _Opcode_name[508:511],
|
||||
157: _Opcode_name[511:514],
|
||||
158: _Opcode_name[514:517],
|
||||
159: _Opcode_name[517:520],
|
||||
160: _Opcode_name[520:523],
|
||||
161: _Opcode_name[523:526],
|
||||
162: _Opcode_name[526:529],
|
||||
168: _Opcode_name[529:532],
|
||||
169: _Opcode_name[532:535],
|
||||
170: _Opcode_name[535:538],
|
||||
171: _Opcode_name[538:545],
|
||||
172: _Opcode_name[545:551],
|
||||
177: _Opcode_name[551:553],
|
||||
179: _Opcode_name[553:561],
|
||||
180: _Opcode_name[561:572],
|
||||
181: _Opcode_name[572:574],
|
||||
182: _Opcode_name[574:577],
|
||||
183: _Opcode_name[577:579],
|
||||
184: _Opcode_name[579:582],
|
||||
185: _Opcode_name[582:585],
|
||||
186: _Opcode_name[585:588],
|
||||
187: _Opcode_name[588:594],
|
||||
192: _Opcode_name[594:598],
|
||||
193: _Opcode_name[598:604],
|
||||
194: _Opcode_name[604:613],
|
||||
195: _Opcode_name[613:621],
|
||||
196: _Opcode_name[621:630],
|
||||
197: _Opcode_name[630:640],
|
||||
198: _Opcode_name[640:649],
|
||||
200: _Opcode_name[649:655],
|
||||
202: _Opcode_name[655:659],
|
||||
203: _Opcode_name[659:665],
|
||||
204: _Opcode_name[665:669],
|
||||
205: _Opcode_name[669:675],
|
||||
206: _Opcode_name[675:683],
|
||||
207: _Opcode_name[683:689],
|
||||
208: _Opcode_name[689:696],
|
||||
209: _Opcode_name[696:708],
|
||||
210: _Opcode_name[708:714],
|
||||
211: _Opcode_name[714:724],
|
||||
216: _Opcode_name[724:730],
|
||||
217: _Opcode_name[730:736],
|
||||
219: _Opcode_name[736:743],
|
||||
240: _Opcode_name[743:748],
|
||||
241: _Opcode_name[748:758],
|
||||
126: _Opcode_name[440:443],
|
||||
127: _Opcode_name[443:449],
|
||||
128: _Opcode_name[449:453],
|
||||
129: _Opcode_name[453:458],
|
||||
144: _Opcode_name[458:464],
|
||||
145: _Opcode_name[464:467],
|
||||
146: _Opcode_name[467:469],
|
||||
147: _Opcode_name[469:472],
|
||||
151: _Opcode_name[472:477],
|
||||
152: _Opcode_name[477:485],
|
||||
153: _Opcode_name[485:489],
|
||||
154: _Opcode_name[489:492],
|
||||
155: _Opcode_name[492:498],
|
||||
156: _Opcode_name[498:501],
|
||||
157: _Opcode_name[501:504],
|
||||
158: _Opcode_name[504:507],
|
||||
159: _Opcode_name[507:510],
|
||||
160: _Opcode_name[510:513],
|
||||
161: _Opcode_name[513:516],
|
||||
162: _Opcode_name[516:519],
|
||||
168: _Opcode_name[519:522],
|
||||
169: _Opcode_name[522:525],
|
||||
170: _Opcode_name[525:528],
|
||||
171: _Opcode_name[528:535],
|
||||
172: _Opcode_name[535:541],
|
||||
177: _Opcode_name[541:543],
|
||||
179: _Opcode_name[543:551],
|
||||
180: _Opcode_name[551:562],
|
||||
181: _Opcode_name[562:564],
|
||||
182: _Opcode_name[564:567],
|
||||
183: _Opcode_name[567:569],
|
||||
184: _Opcode_name[569:572],
|
||||
185: _Opcode_name[572:575],
|
||||
186: _Opcode_name[575:578],
|
||||
187: _Opcode_name[578:584],
|
||||
192: _Opcode_name[584:588],
|
||||
193: _Opcode_name[588:594],
|
||||
194: _Opcode_name[594:603],
|
||||
195: _Opcode_name[603:611],
|
||||
196: _Opcode_name[611:620],
|
||||
197: _Opcode_name[620:630],
|
||||
198: _Opcode_name[630:639],
|
||||
200: _Opcode_name[639:645],
|
||||
202: _Opcode_name[645:649],
|
||||
203: _Opcode_name[649:655],
|
||||
204: _Opcode_name[655:659],
|
||||
205: _Opcode_name[659:665],
|
||||
206: _Opcode_name[665:673],
|
||||
207: _Opcode_name[673:679],
|
||||
208: _Opcode_name[679:686],
|
||||
209: _Opcode_name[686:698],
|
||||
210: _Opcode_name[698:704],
|
||||
211: _Opcode_name[704:714],
|
||||
216: _Opcode_name[714:720],
|
||||
217: _Opcode_name[720:726],
|
||||
219: _Opcode_name[726:733],
|
||||
240: _Opcode_name[733:738],
|
||||
241: _Opcode_name[738:748],
|
||||
}
|
||||
|
||||
func (i Opcode) String() string {
|
||||
|
|
21
pkg/vm/vm.go
21
pkg/vm/vm.go
|
@ -633,27 +633,6 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
|
|||
s := v.estack.Pop().Bytes()
|
||||
v.estack.PushVal(s[len(s)-l:])
|
||||
|
||||
case opcode.XSWAP:
|
||||
n := int(v.estack.Pop().BigInt().Int64())
|
||||
err := v.estack.Swap(n, 0)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
case opcode.XTUCK:
|
||||
n := int(v.estack.Pop().BigInt().Int64())
|
||||
if n <= 0 {
|
||||
panic("XTUCK: invalid length")
|
||||
}
|
||||
a := v.estack.Dup(0)
|
||||
if a == nil {
|
||||
panic("no top-level element found")
|
||||
}
|
||||
if n > v.estack.Len() {
|
||||
panic("can't push to the position specified")
|
||||
}
|
||||
v.estack.InsertAt(a, n)
|
||||
|
||||
case opcode.DEPTH:
|
||||
v.estack.PushVal(v.estack.Len())
|
||||
|
||||
|
|
|
@ -1609,31 +1609,6 @@ func TestREVERSEN(t *testing.T) {
|
|||
t.Run("Good", getCustomTestFuncForVM(prog, getCheckEStackFunc(1, 2, 3, 4, 5), 1, 2, 3, 4, 5, 5))
|
||||
}
|
||||
|
||||
func TestXTUCK(t *testing.T) {
|
||||
prog := makeProgram(opcode.XTUCK)
|
||||
t.Run("NoItem", getTestFuncForVM(prog, nil, 1))
|
||||
t.Run("NoN", getTestFuncForVM(prog, nil, 1, 2))
|
||||
t.Run("Negative", getTestFuncForVM(prog, nil, -1))
|
||||
t.Run("Zero", getTestFuncForVM(prog, nil, 1, 0))
|
||||
}
|
||||
|
||||
func TestXTUCKgood(t *testing.T) {
|
||||
prog := makeProgram(opcode.XTUCK)
|
||||
topelement := 5
|
||||
xtuckdepth := 3
|
||||
vm := load(prog)
|
||||
vm.estack.PushVal(0)
|
||||
vm.estack.PushVal(1)
|
||||
vm.estack.PushVal(2)
|
||||
vm.estack.PushVal(3)
|
||||
vm.estack.PushVal(4)
|
||||
vm.estack.PushVal(topelement)
|
||||
vm.estack.PushVal(xtuckdepth)
|
||||
runVM(t, vm)
|
||||
assert.Equal(t, int64(topelement), vm.estack.Peek(0).BigInt().Int64())
|
||||
assert.Equal(t, int64(topelement), vm.estack.Peek(xtuckdepth).BigInt().Int64())
|
||||
}
|
||||
|
||||
func TestTUCKbadNoitems(t *testing.T) {
|
||||
prog := makeProgram(opcode.TUCK)
|
||||
t.Run("NoArgument", getTestFuncForVM(prog, nil))
|
||||
|
@ -2095,34 +2070,6 @@ func TestSWAP(t *testing.T) {
|
|||
t.Run("SmallStack", getTestFuncForVM(prog, nil, 4))
|
||||
}
|
||||
|
||||
func TestXSWAPGood(t *testing.T) {
|
||||
prog := makeProgram(opcode.XSWAP)
|
||||
vm := load(prog)
|
||||
vm.estack.PushVal(1)
|
||||
vm.estack.PushVal(2)
|
||||
vm.estack.PushVal(3)
|
||||
vm.estack.PushVal(4)
|
||||
vm.estack.PushVal(5)
|
||||
vm.estack.PushVal(3)
|
||||
runVM(t, vm)
|
||||
assert.Equal(t, 5, vm.estack.Len())
|
||||
assert.Equal(t, int64(2), vm.estack.Pop().BigInt().Int64())
|
||||
assert.Equal(t, int64(4), vm.estack.Pop().BigInt().Int64())
|
||||
assert.Equal(t, int64(3), vm.estack.Pop().BigInt().Int64())
|
||||
assert.Equal(t, int64(5), vm.estack.Pop().BigInt().Int64())
|
||||
assert.Equal(t, int64(1), vm.estack.Pop().BigInt().Int64())
|
||||
}
|
||||
|
||||
func TestXSWAPBad1(t *testing.T) {
|
||||
prog := makeProgram(opcode.XSWAP)
|
||||
runWithArgs(t, prog, nil, 1, 2, -1)
|
||||
}
|
||||
|
||||
func TestXSWAPBad2(t *testing.T) {
|
||||
prog := makeProgram(opcode.XSWAP)
|
||||
runWithArgs(t, prog, nil, 1, 2, 3, 4, 4)
|
||||
}
|
||||
|
||||
func TestDupInt(t *testing.T) {
|
||||
prog := makeProgram(opcode.DUP, opcode.ABS)
|
||||
vm := load(prog)
|
||||
|
|
Loading…
Reference in a new issue