emit: use io.BinWriter instead of bytes.Buffer

This commit is contained in:
Evgenii Stratonikov 2020-02-03 17:46:51 +03:00
parent 698c647f07
commit 8243a8b3a7
6 changed files with 128 additions and 199 deletions

View file

@ -8,6 +8,8 @@ import (
"math/rand"
"testing"
"github.com/CityOfZion/neo-go/pkg/io"
"github.com/CityOfZion/neo-go/pkg/crypto/hash"
"github.com/CityOfZion/neo-go/pkg/crypto/keys"
"github.com/CityOfZion/neo-go/pkg/util"
@ -31,9 +33,9 @@ func TestInteropHook(t *testing.T) {
v := New()
v.RegisterInteropGetter(fooInteropGetter)
buf := new(bytes.Buffer)
emit.Syscall(buf, "foo")
emit.Opcode(buf, opcode.RET)
buf := io.NewBufBinWriter()
emit.Syscall(buf.BinWriter, "foo")
emit.Opcode(buf.BinWriter, opcode.RET)
v.Load(buf.Bytes())
runVM(t, v)
assert.Equal(t, 1, v.estack.Len())
@ -44,12 +46,12 @@ func TestInteropHookViaID(t *testing.T) {
v := New()
v.RegisterInteropGetter(fooInteropGetter)
buf := new(bytes.Buffer)
buf := io.NewBufBinWriter()
fooid := InteropNameToID([]byte("foo"))
var id = make([]byte, 4)
binary.LittleEndian.PutUint32(id, fooid)
_ = emit.Syscall(buf, string(id))
_ = emit.Opcode(buf, opcode.RET)
emit.Syscall(buf.BinWriter, string(id))
emit.Opcode(buf.BinWriter, opcode.RET)
v.Load(buf.Bytes())
runVM(t, v)
assert.Equal(t, 1, v.estack.Len())
@ -131,10 +133,10 @@ func TestBytesToPublicKey(t *testing.T) {
}
func TestPushBytes1to75(t *testing.T) {
buf := new(bytes.Buffer)
buf := io.NewBufBinWriter()
for i := 1; i <= 75; i++ {
b := randomBytes(i)
emit.Bytes(buf, b)
emit.Bytes(buf.BinWriter, b)
vm := load(buf.Bytes())
err := vm.Step()
require.NoError(t, err)