2020-07-24 13:54:03 +00:00
|
|
|
package client
|
2020-07-10 14:17:51 +00:00
|
|
|
|
|
|
|
import (
|
2022-06-04 12:03:30 +00:00
|
|
|
"math/big"
|
2020-07-10 14:17:51 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
sc "github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestToStackParameter(t *testing.T) {
|
|
|
|
items := []struct {
|
2023-02-21 11:42:45 +00:00
|
|
|
value any
|
2020-07-10 14:17:51 +00:00
|
|
|
expType sc.ParamType
|
2023-02-21 11:42:45 +00:00
|
|
|
expVal any
|
2020-07-10 14:17:51 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
value: []byte{1, 2, 3},
|
|
|
|
expType: sc.ByteArrayType,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: int64(100),
|
|
|
|
expType: sc.IntegerType,
|
2022-06-04 12:03:30 +00:00
|
|
|
expVal: big.NewInt(100),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: uint64(100),
|
|
|
|
expType: sc.IntegerType,
|
|
|
|
expVal: big.NewInt(100),
|
2020-07-10 14:17:51 +00:00
|
|
|
},
|
2020-10-19 09:22:46 +00:00
|
|
|
{
|
|
|
|
value: "hello world",
|
|
|
|
expType: sc.StringType,
|
|
|
|
},
|
2021-05-25 09:24:03 +00:00
|
|
|
{
|
|
|
|
value: false,
|
2022-03-31 08:27:10 +00:00
|
|
|
expType: sc.BoolType,
|
2021-05-25 09:24:03 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
value: true,
|
2022-03-31 08:27:10 +00:00
|
|
|
expType: sc.BoolType,
|
2021-05-25 09:24:03 +00:00
|
|
|
},
|
2020-07-10 14:17:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, item := range items {
|
|
|
|
t.Run(item.expType.String()+" to stack parameter", func(t *testing.T) {
|
|
|
|
res, err := toStackParameter(item.value)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, item.expType, res.Type)
|
2021-05-25 09:24:03 +00:00
|
|
|
if item.expVal != nil {
|
|
|
|
require.Equal(t, item.expVal, res.Value)
|
|
|
|
} else {
|
|
|
|
require.Equal(t, item.value, res.Value)
|
|
|
|
}
|
2020-07-10 14:17:51 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|