mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-25 21:17:16 +00:00
Merge branch 'frontier/js' into frontier/nodeadmin.js
This commit is contained in:
commit
ff86d7d52a
@ -2,15 +2,11 @@ package jsre
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/obscuren/otto"
|
"github.com/obscuren/otto"
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
var defaultAssetPath = path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "cmd", "mist", "assets", "ext")
|
|
||||||
|
|
||||||
type testNativeObjectBinding struct {
|
type testNativeObjectBinding struct {
|
||||||
toVal func(interface{}) otto.Value
|
toVal func(interface{}) otto.Value
|
||||||
}
|
}
|
||||||
@ -42,20 +38,15 @@ func TestExec(t *testing.T) {
|
|||||||
if !val.IsString() {
|
if !val.IsString() {
|
||||||
t.Errorf("expected string value, got %v", val)
|
t.Errorf("expected string value, got %v", val)
|
||||||
}
|
}
|
||||||
|
exp := "testMsg"
|
||||||
// this errors
|
got, _ := val.ToString()
|
||||||
err = jsre.Exec(path.Join(defaultAssetPath, "bignumber.min.js"))
|
if exp != got {
|
||||||
if err != nil {
|
t.Errorf("expected '%v', got '%v'", exp, got)
|
||||||
t.Errorf("expected no error, got %v", err)
|
|
||||||
}
|
|
||||||
_, err = jsre.Run("x = new BigNumber(123.4567);")
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("expected no error, got %v", err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBind(t *testing.T) {
|
func TestBind(t *testing.T) {
|
||||||
jsre := New(defaultAssetPath)
|
jsre := New("/tmp")
|
||||||
|
|
||||||
jsre.Bind("no", &testNativeObjectBinding{jsre.ToVal})
|
jsre.Bind("no", &testNativeObjectBinding{jsre.ToVal})
|
||||||
|
|
||||||
@ -70,16 +61,24 @@ func TestBind(t *testing.T) {
|
|||||||
t.Logf("no: %v", pp)
|
t.Logf("no: %v", pp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRequire(t *testing.T) {
|
func TestLoadScript(t *testing.T) {
|
||||||
jsre := New(defaultAssetPath)
|
jsre := New("/tmp")
|
||||||
|
|
||||||
_, err := jsre.Run("x = new BigNumber(123.4567);")
|
ethutil.WriteFile("/tmp/test.js", []byte(`msg = "testMsg"`))
|
||||||
if err == nil {
|
_, err := jsre.Run(`loadScript("test.js")`)
|
||||||
t.Errorf("expected error, got nothing")
|
|
||||||
}
|
|
||||||
_, err = jsre.Run(`loadScript("bignumber.min.js"); x = new BigNumber(123.4567)`)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("expected no error, got %v", err)
|
t.Errorf("expected no error, got %v", err)
|
||||||
}
|
}
|
||||||
|
val, err := jsre.Run("msg")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("expected no error, got %v", err)
|
||||||
|
}
|
||||||
|
if !val.IsString() {
|
||||||
|
t.Errorf("expected string value, got %v", val)
|
||||||
|
}
|
||||||
|
exp := "testMsg"
|
||||||
|
got, _ := val.ToString()
|
||||||
|
if exp != got {
|
||||||
|
t.Errorf("expected '%v', got '%v'", exp, got)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user