vm: remove XSWAP/XTUCK opcodes

Regenerate RPC testchain as these were used in compiler.
This commit is contained in:
Evgenii Stratonikov 2020-05-06 12:16:10 +03:00
parent d18199ce42
commit dd20320615
7 changed files with 62 additions and 142 deletions

View file

@ -47,18 +47,18 @@ type rpcTestCase struct {
check func(t *testing.T, e *executor, result interface{}) check func(t *testing.T, e *executor, result interface{})
} }
const testContractHash = "5d49c5a1127c23ad64a2ede6259b8ca61cc9f2fb" const testContractHash = "76751a2fdde4dc6c7489799a28bb539bc09d1f54"
var rpcTestCases = map[string][]rpcTestCase{ var rpcTestCases = map[string][]rpcTestCase{
"getapplicationlog": { "getapplicationlog": {
{ {
name: "positive", name: "positive",
params: `["3f056daab3c7824a6bf2cc863b5d4a0089bb3561316d65bf5e344278c0311901"]`, params: `["113437bd8dfc44e3a6dfe77b750fcff246cbe933ca9667311f45d794cf0410cc"]`,
result: func(e *executor) interface{} { return &result.ApplicationLog{} }, result: func(e *executor) interface{} { return &result.ApplicationLog{} },
check: func(t *testing.T, e *executor, acc interface{}) { check: func(t *testing.T, e *executor, acc interface{}) {
res, ok := acc.(*result.ApplicationLog) res, ok := acc.(*result.ApplicationLog)
require.True(t, ok) require.True(t, ok)
expectedTxHash, err := util.Uint256DecodeStringLE("3f056daab3c7824a6bf2cc863b5d4a0089bb3561316d65bf5e344278c0311901") expectedTxHash, err := util.Uint256DecodeStringLE("113437bd8dfc44e3a6dfe77b750fcff246cbe933ca9667311f45d794cf0410cc")
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, expectedTxHash, res.TxHash) assert.Equal(t, expectedTxHash, res.TxHash)
assert.Equal(t, 1, len(res.Executions)) assert.Equal(t, 1, len(res.Executions))

Binary file not shown.

Binary file not shown.

View file

@ -92,8 +92,6 @@ const (
DUPFROMALTSTACK Opcode = 0x6A DUPFROMALTSTACK Opcode = 0x6A
TOALTSTACK Opcode = 0x6B TOALTSTACK Opcode = 0x6B
FROMALTSTACK Opcode = 0x6C FROMALTSTACK Opcode = 0x6C
XSWAP Opcode = 0x72
XTUCK Opcode = 0x73
// Splice // Splice
CAT Opcode = 0x7E CAT Opcode = 0x7E

View file

@ -82,8 +82,6 @@ func _() {
_ = x[DUPFROMALTSTACK-106] _ = x[DUPFROMALTSTACK-106]
_ = x[TOALTSTACK-107] _ = x[TOALTSTACK-107]
_ = x[FROMALTSTACK-108] _ = x[FROMALTSTACK-108]
_ = x[XSWAP-114]
_ = x[XTUCK-115]
_ = x[CAT-126] _ = x[CAT-126]
_ = x[SUBSTR-127] _ = x[SUBSTR-127]
_ = x[LEFT-128] _ = x[LEFT-128]
@ -144,7 +142,7 @@ func _() {
_ = x[THROWIFNOT-241] _ = x[THROWIFNOT-241]
} }
const _Opcode_name = "PUSHINT8PUSHINT16PUSHINT32PUSHINT64PUSHINT128PUSHINT256PUSHNULLPUSHDATA1PUSHDATA2PUSHDATA4PUSHM1PUSH0PUSH1PUSH2PUSH3PUSH4PUSH5PUSH6PUSH7PUSH8PUSH9PUSH10PUSH11PUSH12PUSH13PUSH14PUSH15PUSH16NOPJMPJMPLJMPIFJMPIFLJMPIFNOTJMPIFNOTLJMPEQJMPEQLJMPNEJMPNELJMPGTJMPGTLJMPGEJMPGELJMPLTJMPLTLJMPLEJMPLELCALLCALLLDEPTHDROPNIPXDROPCLEARDUPOVERPICKTUCKSWAPOLDPUSH1ROLLREVERSE3REVERSE4REVERSENRETAPPCALLSYSCALLTAILCALLDUPFROMALTSTACKTOALTSTACKFROMALTSTACKXSWAPXTUCKCATSUBSTRLEFTRIGHTINVERTANDORXOREQUALNOTEQUALSIGNABSNEGATEINCDECADDSUBMULDIVMODSHLSHRNOTBOOLANDBOOLORNZNUMEQUALNUMNOTEQUALLTLTEGTGTEMINMAXWITHINPACKUNPACKNEWARRAY0NEWARRAYNEWARRAYTNEWSTRUCT0NEWSTRUCTNEWMAPSIZEHASKEYKEYSVALUESPICKITEMAPPENDSETITEMREVERSEITEMSREMOVECLEARITEMSISNULLISTYPECONVERTTHROWTHROWIFNOT" const _Opcode_name = "PUSHINT8PUSHINT16PUSHINT32PUSHINT64PUSHINT128PUSHINT256PUSHNULLPUSHDATA1PUSHDATA2PUSHDATA4PUSHM1PUSH0PUSH1PUSH2PUSH3PUSH4PUSH5PUSH6PUSH7PUSH8PUSH9PUSH10PUSH11PUSH12PUSH13PUSH14PUSH15PUSH16NOPJMPJMPLJMPIFJMPIFLJMPIFNOTJMPIFNOTLJMPEQJMPEQLJMPNEJMPNELJMPGTJMPGTLJMPGEJMPGELJMPLTJMPLTLJMPLEJMPLELCALLCALLLDEPTHDROPNIPXDROPCLEARDUPOVERPICKTUCKSWAPOLDPUSH1ROLLREVERSE3REVERSE4REVERSENRETAPPCALLSYSCALLTAILCALLDUPFROMALTSTACKTOALTSTACKFROMALTSTACKCATSUBSTRLEFTRIGHTINVERTANDORXOREQUALNOTEQUALSIGNABSNEGATEINCDECADDSUBMULDIVMODSHLSHRNOTBOOLANDBOOLORNZNUMEQUALNUMNOTEQUALLTLTEGTGTEMINMAXWITHINPACKUNPACKNEWARRAY0NEWARRAYNEWARRAYTNEWSTRUCT0NEWSTRUCTNEWMAPSIZEHASKEYKEYSVALUESPICKITEMAPPENDSETITEMREVERSEITEMSREMOVECLEARITEMSISNULLISTYPECONVERTTHROWTHROWIFNOT"
var _Opcode_map = map[Opcode]string{ var _Opcode_map = map[Opcode]string{
0: _Opcode_name[0:8], 0: _Opcode_name[0:8],
@ -218,66 +216,64 @@ var _Opcode_map = map[Opcode]string{
106: _Opcode_name[403:418], 106: _Opcode_name[403:418],
107: _Opcode_name[418:428], 107: _Opcode_name[418:428],
108: _Opcode_name[428:440], 108: _Opcode_name[428:440],
114: _Opcode_name[440:445], 126: _Opcode_name[440:443],
115: _Opcode_name[445:450], 127: _Opcode_name[443:449],
126: _Opcode_name[450:453], 128: _Opcode_name[449:453],
127: _Opcode_name[453:459], 129: _Opcode_name[453:458],
128: _Opcode_name[459:463], 144: _Opcode_name[458:464],
129: _Opcode_name[463:468], 145: _Opcode_name[464:467],
144: _Opcode_name[468:474], 146: _Opcode_name[467:469],
145: _Opcode_name[474:477], 147: _Opcode_name[469:472],
146: _Opcode_name[477:479], 151: _Opcode_name[472:477],
147: _Opcode_name[479:482], 152: _Opcode_name[477:485],
151: _Opcode_name[482:487], 153: _Opcode_name[485:489],
152: _Opcode_name[487:495], 154: _Opcode_name[489:492],
153: _Opcode_name[495:499], 155: _Opcode_name[492:498],
154: _Opcode_name[499:502], 156: _Opcode_name[498:501],
155: _Opcode_name[502:508], 157: _Opcode_name[501:504],
156: _Opcode_name[508:511], 158: _Opcode_name[504:507],
157: _Opcode_name[511:514], 159: _Opcode_name[507:510],
158: _Opcode_name[514:517], 160: _Opcode_name[510:513],
159: _Opcode_name[517:520], 161: _Opcode_name[513:516],
160: _Opcode_name[520:523], 162: _Opcode_name[516:519],
161: _Opcode_name[523:526], 168: _Opcode_name[519:522],
162: _Opcode_name[526:529], 169: _Opcode_name[522:525],
168: _Opcode_name[529:532], 170: _Opcode_name[525:528],
169: _Opcode_name[532:535], 171: _Opcode_name[528:535],
170: _Opcode_name[535:538], 172: _Opcode_name[535:541],
171: _Opcode_name[538:545], 177: _Opcode_name[541:543],
172: _Opcode_name[545:551], 179: _Opcode_name[543:551],
177: _Opcode_name[551:553], 180: _Opcode_name[551:562],
179: _Opcode_name[553:561], 181: _Opcode_name[562:564],
180: _Opcode_name[561:572], 182: _Opcode_name[564:567],
181: _Opcode_name[572:574], 183: _Opcode_name[567:569],
182: _Opcode_name[574:577], 184: _Opcode_name[569:572],
183: _Opcode_name[577:579], 185: _Opcode_name[572:575],
184: _Opcode_name[579:582], 186: _Opcode_name[575:578],
185: _Opcode_name[582:585], 187: _Opcode_name[578:584],
186: _Opcode_name[585:588], 192: _Opcode_name[584:588],
187: _Opcode_name[588:594], 193: _Opcode_name[588:594],
192: _Opcode_name[594:598], 194: _Opcode_name[594:603],
193: _Opcode_name[598:604], 195: _Opcode_name[603:611],
194: _Opcode_name[604:613], 196: _Opcode_name[611:620],
195: _Opcode_name[613:621], 197: _Opcode_name[620:630],
196: _Opcode_name[621:630], 198: _Opcode_name[630:639],
197: _Opcode_name[630:640], 200: _Opcode_name[639:645],
198: _Opcode_name[640:649], 202: _Opcode_name[645:649],
200: _Opcode_name[649:655], 203: _Opcode_name[649:655],
202: _Opcode_name[655:659], 204: _Opcode_name[655:659],
203: _Opcode_name[659:665], 205: _Opcode_name[659:665],
204: _Opcode_name[665:669], 206: _Opcode_name[665:673],
205: _Opcode_name[669:675], 207: _Opcode_name[673:679],
206: _Opcode_name[675:683], 208: _Opcode_name[679:686],
207: _Opcode_name[683:689], 209: _Opcode_name[686:698],
208: _Opcode_name[689:696], 210: _Opcode_name[698:704],
209: _Opcode_name[696:708], 211: _Opcode_name[704:714],
210: _Opcode_name[708:714], 216: _Opcode_name[714:720],
211: _Opcode_name[714:724], 217: _Opcode_name[720:726],
216: _Opcode_name[724:730], 219: _Opcode_name[726:733],
217: _Opcode_name[730:736], 240: _Opcode_name[733:738],
219: _Opcode_name[736:743], 241: _Opcode_name[738:748],
240: _Opcode_name[743:748],
241: _Opcode_name[748:758],
} }
func (i Opcode) String() string { func (i Opcode) String() string {

View file

@ -633,27 +633,6 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
s := v.estack.Pop().Bytes() s := v.estack.Pop().Bytes()
v.estack.PushVal(s[len(s)-l:]) 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: case opcode.DEPTH:
v.estack.PushVal(v.estack.Len()) v.estack.PushVal(v.estack.Len())

View file

@ -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)) 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) { func TestTUCKbadNoitems(t *testing.T) {
prog := makeProgram(opcode.TUCK) prog := makeProgram(opcode.TUCK)
t.Run("NoArgument", getTestFuncForVM(prog, nil)) t.Run("NoArgument", getTestFuncForVM(prog, nil))
@ -2095,34 +2070,6 @@ func TestSWAP(t *testing.T) {
t.Run("SmallStack", getTestFuncForVM(prog, nil, 4)) 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) { func TestDupInt(t *testing.T) {
prog := makeProgram(opcode.DUP, opcode.ABS) prog := makeProgram(opcode.DUP, opcode.ABS)
vm := load(prog) vm := load(prog)