parent
f31ce9289d
commit
74d2f437f4
5 changed files with 72 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
|
@ -214,6 +215,39 @@ func TestECDSAVerify(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestRuntimeEncode(t *testing.T) {
|
||||
str := []byte("my pretty string")
|
||||
v, ic, bc := createVM(t)
|
||||
defer bc.Close()
|
||||
|
||||
v.Estack().PushVal(str)
|
||||
require.NoError(t, runtimeEncode(ic, v))
|
||||
|
||||
expected := []byte(base64.StdEncoding.EncodeToString(str))
|
||||
actual := v.Estack().Pop().Bytes()
|
||||
require.Equal(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestRuntimeDecode(t *testing.T) {
|
||||
expected := []byte("my pretty string")
|
||||
str := base64.StdEncoding.EncodeToString(expected)
|
||||
v, ic, bc := createVM(t)
|
||||
defer bc.Close()
|
||||
|
||||
t.Run("positive", func(t *testing.T) {
|
||||
v.Estack().PushVal(str)
|
||||
require.NoError(t, runtimeDecode(ic, v))
|
||||
|
||||
actual := v.Estack().Pop().Bytes()
|
||||
require.Equal(t, expected, actual)
|
||||
})
|
||||
|
||||
t.Run("error", func(t *testing.T) {
|
||||
v.Estack().PushVal(str + "%")
|
||||
require.Error(t, runtimeDecode(ic, v))
|
||||
})
|
||||
}
|
||||
|
||||
// Helper functions to create VM, InteropContext, TX, Account, Contract.
|
||||
|
||||
func createVM(t *testing.T) (*vm.VM, *interop.Context, *Blockchain) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue