mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-30 09:33:36 +00:00
core: use opcodes instead of raw bytes in tests
It will be helpful during future opcode reordering in NEO3.
This commit is contained in:
parent
f50eaba202
commit
cc20ba651d
1 changed files with 17 additions and 9 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -24,13 +25,13 @@ func TestGetPrice(t *testing.T) {
|
|||
|
||||
t.Run("Neo.Asset.Create", func(t *testing.T) {
|
||||
// Neo.Asset.Create: 83c5c61f
|
||||
v.Load([]byte{0x68, 0x83, 0xc5, 0xc6, 0x1f})
|
||||
v.Load([]byte{byte(opcode.SYSCALL), 0x83, 0xc5, 0xc6, 0x1f})
|
||||
checkGas(t, util.Fixed8FromInt64(5000), v)
|
||||
})
|
||||
|
||||
t.Run("Neo.Asset.Renew", func(t *testing.T) {
|
||||
// Neo.Asset.Renew: 78849071 (requires push 09 push 09 before)
|
||||
v.Load([]byte{0x59, 0x59, 0x68, 0x78, 0x84, 0x90, 0x71})
|
||||
v.Load([]byte{byte(opcode.PUSH9), byte(opcode.PUSH9), byte(opcode.SYSCALL), 0x78, 0x84, 0x90, 0x71})
|
||||
require.NoError(t, v.StepInto()) // push 9
|
||||
require.NoError(t, v.StepInto()) // push 9
|
||||
|
||||
|
@ -39,7 +40,8 @@ func TestGetPrice(t *testing.T) {
|
|||
|
||||
t.Run("Neo.Contract.Create (no props)", func(t *testing.T) {
|
||||
// Neo.Contract.Create: f66ca56e (requires push properties on fourth position)
|
||||
v.Load([]byte{0x00, 0x00, 0x00, 0x00, 0x68, 0xf6, 0x6c, 0xa5, 0x6e})
|
||||
v.Load([]byte{byte(opcode.PUSH0), byte(opcode.PUSH0), byte(opcode.PUSH0), byte(opcode.PUSH0),
|
||||
byte(opcode.SYSCALL), 0xf6, 0x6c, 0xa5, 0x6e})
|
||||
require.NoError(t, v.StepInto()) // push 0 - ContractPropertyState.NoProperty
|
||||
require.NoError(t, v.StepInto()) // push 0
|
||||
require.NoError(t, v.StepInto()) // push 0
|
||||
|
@ -50,7 +52,8 @@ func TestGetPrice(t *testing.T) {
|
|||
|
||||
t.Run("Neo.Contract.Create (has storage)", func(t *testing.T) {
|
||||
// Neo.Contract.Create: f66ca56e (requires push properties on fourth position)
|
||||
v.Load([]byte{0x51, 0x00, 0x00, 0x00, 0x68, 0xf6, 0x6c, 0xa5, 0x6e})
|
||||
v.Load([]byte{byte(opcode.PUSH1), byte(opcode.PUSH0), byte(opcode.PUSH0), byte(opcode.PUSH0),
|
||||
byte(opcode.SYSCALL), 0xf6, 0x6c, 0xa5, 0x6e})
|
||||
require.NoError(t, v.StepInto()) // push 01 - ContractPropertyState.HasStorage
|
||||
require.NoError(t, v.StepInto()) // push 0
|
||||
require.NoError(t, v.StepInto()) // push 0
|
||||
|
@ -61,7 +64,8 @@ func TestGetPrice(t *testing.T) {
|
|||
|
||||
t.Run("Neo.Contract.Create (has dynamic invoke)", func(t *testing.T) {
|
||||
// Neo.Contract.Create: f66ca56e (requires push properties on fourth position)
|
||||
v.Load([]byte{0x52, 0x00, 0x00, 0x00, 0x68, 0xf6, 0x6c, 0xa5, 0x6e})
|
||||
v.Load([]byte{byte(opcode.PUSH2), byte(opcode.PUSH0), byte(opcode.PUSH0), byte(opcode.PUSH0),
|
||||
byte(opcode.SYSCALL), 0xf6, 0x6c, 0xa5, 0x6e})
|
||||
require.NoError(t, v.StepInto()) // push 02 - ContractPropertyState.HasDynamicInvoke
|
||||
require.NoError(t, v.StepInto()) // push 0
|
||||
require.NoError(t, v.StepInto()) // push 0
|
||||
|
@ -72,7 +76,8 @@ func TestGetPrice(t *testing.T) {
|
|||
|
||||
t.Run("Neo.Contract.Create (has both storage and dynamic invoke)", func(t *testing.T) {
|
||||
// Neo.Contract.Create: f66ca56e (requires push properties on fourth position)
|
||||
v.Load([]byte{0x53, 0x00, 0x00, 0x00, 0x68, 0xf6, 0x6c, 0xa5, 0x6e})
|
||||
v.Load([]byte{byte(opcode.PUSH3), byte(opcode.PUSH0), byte(opcode.PUSH0), byte(opcode.PUSH0),
|
||||
byte(opcode.SYSCALL), 0xf6, 0x6c, 0xa5, 0x6e})
|
||||
require.NoError(t, v.StepInto()) // push 03 - HasStorage and HasDynamicInvoke
|
||||
require.NoError(t, v.StepInto()) // push 0
|
||||
require.NoError(t, v.StepInto()) // push 0
|
||||
|
@ -83,7 +88,8 @@ func TestGetPrice(t *testing.T) {
|
|||
|
||||
t.Run("Neo.Contract.Migrate", func(t *testing.T) {
|
||||
// Neo.Contract.Migrate: 471b6290 (requires push properties on fourth position)
|
||||
v.Load([]byte{0x00, 0x00, 0x00, 0x00, 0x68, 0x47, 0x1b, 0x62, 0x90})
|
||||
v.Load([]byte{byte(opcode.PUSH0), byte(opcode.PUSH0), byte(opcode.PUSH0), byte(opcode.PUSH0),
|
||||
byte(opcode.SYSCALL), 0x47, 0x1b, 0x62, 0x90})
|
||||
require.NoError(t, v.StepInto()) // push 0 - ContractPropertyState.NoProperty
|
||||
require.NoError(t, v.StepInto()) // push 0
|
||||
require.NoError(t, v.StepInto()) // push 0
|
||||
|
@ -94,7 +100,8 @@ func TestGetPrice(t *testing.T) {
|
|||
|
||||
t.Run("System.Storage.Put", func(t *testing.T) {
|
||||
// System.Storage.Put: e63f1884 (requires push key and value)
|
||||
v.Load([]byte{0x53, 0x53, 0x00, 0x68, 0xe6, 0x3f, 0x18, 0x84})
|
||||
v.Load([]byte{byte(opcode.PUSH3), byte(opcode.PUSH3), byte(opcode.PUSH0),
|
||||
byte(opcode.SYSCALL), 0xe6, 0x3f, 0x18, 0x84})
|
||||
require.NoError(t, v.StepInto()) // push 03 (length 1)
|
||||
require.NoError(t, v.StepInto()) // push 03 (length 1)
|
||||
require.NoError(t, v.StepInto()) // push 00
|
||||
|
@ -104,7 +111,8 @@ func TestGetPrice(t *testing.T) {
|
|||
|
||||
t.Run("System.Storage.PutEx", func(t *testing.T) {
|
||||
// System.Storage.PutEx: 73e19b3a (requires push key and value)
|
||||
v.Load([]byte{0x53, 0x53, 0x00, 0x68, 0x73, 0xe1, 0x9b, 0x3a})
|
||||
v.Load([]byte{byte(opcode.PUSH3), byte(opcode.PUSH3), byte(opcode.PUSH0),
|
||||
byte(opcode.SYSCALL), 0x73, 0xe1, 0x9b, 0x3a})
|
||||
require.NoError(t, v.StepInto()) // push 03 (length 1)
|
||||
require.NoError(t, v.StepInto()) // push 03 (length 1)
|
||||
require.NoError(t, v.StepInto()) // push 00
|
||||
|
|
Loading…
Reference in a new issue