vm: use new big.Int (de-)serialization routines
Also fix a test with CAT.
This commit is contained in:
parent
f26bdae2c5
commit
f0083b94c5
5 changed files with 6 additions and 12 deletions
|
@ -196,7 +196,7 @@ func compareItems(t *testing.T, a, b StackItem) {
|
|||
case *BigIntegerItem:
|
||||
require.Equal(t, val, ac.value.Int64())
|
||||
case *ByteArrayItem:
|
||||
require.Equal(t, val, new(big.Int).SetBytes(util.ArrayReverse(ac.value)).Int64())
|
||||
require.Equal(t, val, bytesToInt(ac.value).Int64())
|
||||
case *BoolItem:
|
||||
if ac.value {
|
||||
require.Equal(t, val, int64(1))
|
||||
|
|
|
@ -2,10 +2,8 @@ package vm
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"math/big"
|
||||
|
||||
"github.com/CityOfZion/neo-go/pkg/io"
|
||||
"github.com/CityOfZion/neo-go/pkg/util"
|
||||
)
|
||||
|
||||
type stackItemType byte
|
||||
|
@ -50,7 +48,7 @@ func serializeItemTo(item StackItem, w *io.BinWriter, seen map[StackItem]bool) {
|
|||
w.WriteBool(t.value)
|
||||
case *BigIntegerItem:
|
||||
w.WriteBytes([]byte{byte(integerT)})
|
||||
w.WriteVarBytes(t.Bytes())
|
||||
w.WriteVarBytes(intToBytes(t.value))
|
||||
case *InteropItem:
|
||||
w.Err = errors.New("not supported")
|
||||
case *ArrayItem, *StructItem:
|
||||
|
@ -108,7 +106,7 @@ func DecodeBinaryStackItem(r *io.BinReader) StackItem {
|
|||
return NewBoolItem(b)
|
||||
case integerT:
|
||||
data := r.ReadVarBytes()
|
||||
num := new(big.Int).SetBytes(util.ArrayReverse(data))
|
||||
num := bytesToInt(data)
|
||||
return &BigIntegerItem{
|
||||
value: num,
|
||||
}
|
||||
|
|
|
@ -5,8 +5,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
"github.com/CityOfZion/neo-go/pkg/util"
|
||||
)
|
||||
|
||||
// Stack implementation for the neo-go virtual machine. The stack implements
|
||||
|
@ -83,7 +81,7 @@ func (e *Element) BigInt() *big.Int {
|
|||
return big.NewInt(0)
|
||||
default:
|
||||
b := t.Value().([]uint8)
|
||||
return new(big.Int).SetBytes(util.ArrayReverse(b))
|
||||
return bytesToInt(b)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,6 @@ import (
|
|||
"fmt"
|
||||
"math/big"
|
||||
"reflect"
|
||||
|
||||
"github.com/CityOfZion/neo-go/pkg/util"
|
||||
)
|
||||
|
||||
// A StackItem represents the "real" value that is pushed on the stack.
|
||||
|
@ -144,7 +142,7 @@ func NewBigIntegerItem(value int) *BigIntegerItem {
|
|||
|
||||
// Bytes converts i to a slice of bytes.
|
||||
func (i *BigIntegerItem) Bytes() []byte {
|
||||
return util.ArrayReverse(i.value.Bytes())
|
||||
return intToBytes(i.value)
|
||||
}
|
||||
|
||||
// Value implements StackItem interface.
|
||||
|
|
|
@ -2042,7 +2042,7 @@ func TestCATInt0ByteArray(t *testing.T) {
|
|||
vm.estack.PushVal([]byte{})
|
||||
runVM(t, vm)
|
||||
assert.Equal(t, 1, vm.estack.Len())
|
||||
assert.Equal(t, &ByteArrayItem{[]byte{}}, vm.estack.Pop().value)
|
||||
assert.Equal(t, &ByteArrayItem{[]byte{0}}, vm.estack.Pop().value)
|
||||
}
|
||||
|
||||
func TestCATByteArrayInt1(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue