vm: add test to check CLI UTF-8 compatibility

This commit is contained in:
AnnaShaleva 2022-02-18 16:27:00 +03:00
parent c182141624
commit c35950206a

View file

@ -206,29 +206,35 @@ func TestLoad(t *testing.T) {
}` }`
tmpDir := t.TempDir() tmpDir := t.TempDir()
t.Run("loadgo", func(t *testing.T) { checkLoadgo := func(t *testing.T, tName, cName, cErrName string) {
filename := filepath.Join(tmpDir, "vmtestcontract.go") t.Run("loadgo "+tName, func(t *testing.T) {
require.NoError(t, ioutil.WriteFile(filename, []byte(src), os.ModePerm)) filename := filepath.Join(tmpDir, cName)
filename = "'" + filename + "'" require.NoError(t, ioutil.WriteFile(filename, []byte(src), os.ModePerm))
filenameErr := filepath.Join(tmpDir, "vmtestcontract_err.go") filename = "'" + filename + "'"
require.NoError(t, ioutil.WriteFile(filenameErr, []byte(src+"invalid_token"), os.ModePerm)) filenameErr := filepath.Join(tmpDir, cErrName)
filenameErr = "'" + filenameErr + "'" require.NoError(t, ioutil.WriteFile(filenameErr, []byte(src+"invalid_token"), os.ModePerm))
goMod := []byte(`module test.example/vmcli filenameErr = "'" + filenameErr + "'"
goMod := []byte(`module test.example/vmcli
go 1.16`) go 1.16`)
require.NoError(t, ioutil.WriteFile(filepath.Join(tmpDir, "go.mod"), goMod, os.ModePerm)) require.NoError(t, ioutil.WriteFile(filepath.Join(tmpDir, "go.mod"), goMod, os.ModePerm))
e := newTestVMCLI(t) e := newTestVMCLI(t)
e.runProgWithTimeout(t, 10*time.Second, e.runProgWithTimeout(t, 10*time.Second,
"loadgo", "loadgo",
"loadgo "+filenameErr, "loadgo "+filenameErr,
"loadgo "+filename, "loadgo "+filename,
"run main add 3 5") "run main add 3 5")
e.checkError(t, ErrMissingParameter)
e.checkNextLine(t, "Error:")
e.checkNextLine(t, "READY: loaded \\d* instructions")
e.checkStack(t, 8)
})
}
checkLoadgo(t, "simple", "vmtestcontract.go", "vmtestcontract_err.go")
checkLoadgo(t, "utf-8 with spaces", "тестовый контракт.go", "тестовый контракт с ошибкой.go")
e.checkError(t, ErrMissingParameter)
e.checkNextLine(t, "Error:")
e.checkNextLine(t, "READY: loaded \\d* instructions")
e.checkStack(t, 8)
})
t.Run("loadgo, check calling flags", func(t *testing.T) { t.Run("loadgo, check calling flags", func(t *testing.T) {
srcAllowNotify := `package kek srcAllowNotify := `package kek
import "github.com/nspcc-dev/neo-go/pkg/interop/runtime" import "github.com/nspcc-dev/neo-go/pkg/interop/runtime"