forked from TrueCloudLab/neoneo-go
Merge pull request #780 from nspcc-dev/fix/776
vm: allow to push integer-like items to stack
This commit is contained in:
commit
b37c5939f8
2 changed files with 21 additions and 0 deletions
|
@ -87,6 +87,11 @@ func makeStackItem(v interface{}) StackItem {
|
||||||
}
|
}
|
||||||
return makeStackItem(a)
|
return makeStackItem(a)
|
||||||
default:
|
default:
|
||||||
|
i64T := reflect.TypeOf(int64(0))
|
||||||
|
if reflect.TypeOf(val).ConvertibleTo(i64T) {
|
||||||
|
i64Val := reflect.ValueOf(val).Convert(i64T).Interface()
|
||||||
|
return makeStackItem(i64Val)
|
||||||
|
}
|
||||||
panic(
|
panic(
|
||||||
fmt.Sprintf(
|
fmt.Sprintf(
|
||||||
"invalid stack item type: %v (%v)",
|
"invalid stack item type: %v (%v)",
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package vm
|
package vm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPushElement(t *testing.T) {
|
func TestPushElement(t *testing.T) {
|
||||||
|
@ -20,6 +22,20 @@ func TestPushElement(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStack_PushVal(t *testing.T) {
|
||||||
|
type (
|
||||||
|
i32 int32
|
||||||
|
testByte uint8
|
||||||
|
)
|
||||||
|
|
||||||
|
s := NewStack("test")
|
||||||
|
require.NotPanics(t, func() { s.PushVal(i32(123)) })
|
||||||
|
require.NotPanics(t, func() { s.PushVal(testByte(42)) })
|
||||||
|
require.Equal(t, 2, s.Len())
|
||||||
|
require.Equal(t, big.NewInt(42), s.Pop().Value())
|
||||||
|
require.Equal(t, big.NewInt(123), s.Pop().Value())
|
||||||
|
}
|
||||||
|
|
||||||
func TestPopElement(t *testing.T) {
|
func TestPopElement(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
s = NewStack("test")
|
s = NewStack("test")
|
||||||
|
|
Loading…
Reference in a new issue