mirror of
https://github.com/status-im/status-go.git
synced 2025-01-28 07:27:00 +00:00
ebd77aabe2
* static: updates Whisper test (to work with Geth 1.6.1) * jail: VM persistence implemented * jail: sendMessage/showSuggestions minor fixes (to be squashed) * node: CHT and boot nodes auto-load implemented * Replaced CHT data file from farazdagi's to tiabc's * Rewrote config_test.go using testify having reduced it twice in size * Increased SyncTime and panic timeout in tests * Fixed test - remove go default test to testify/suite (#207) * Add flag setup for RPCEnabled and add comment (#225) * jail: register method handlers before running initial js in jail (#226) * Console Jail Mod #179 (#228) * Added ./statusd-data into .gitignore * Increased log level for the test node from INFO to ERROR * Add call to loop.Run to evaluate all setTimeout/setIntervals methods. (#208) * Rebase onto geth1.6.7 (#232) * Got back sync duration from 60s to 30s, updated bindata.go
96 lines
2.2 KiB
Go
96 lines
2.2 KiB
Go
package console_test
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/robertkrimen/otto"
|
|
"github.com/status-im/status-go/geth/jail/console"
|
|
"github.com/status-im/status-go/geth/node"
|
|
"github.com/stretchr/testify/suite"
|
|
)
|
|
|
|
// TestConsole validates the behaviour of giving conole extensions.
|
|
func TestConsole(t *testing.T) {
|
|
suite.Run(t, new(ConsoleTestSuite))
|
|
}
|
|
|
|
type ConsoleTestSuite struct {
|
|
suite.Suite
|
|
vm *otto.Otto
|
|
}
|
|
|
|
func (s *ConsoleTestSuite) SetupTest() {
|
|
require := s.Require()
|
|
|
|
vm := otto.New()
|
|
require.NotNil(vm)
|
|
s.vm = vm
|
|
}
|
|
|
|
// TestConsoleLog will validate the operations of the console.log extension
|
|
// for the otto vm.
|
|
func (s *ConsoleTestSuite) TestConsoleLog() {
|
|
require := s.Require()
|
|
written := "Bob Marley"
|
|
|
|
var customWriter bytes.Buffer
|
|
|
|
err := s.vm.Set("console", map[string]interface{}{
|
|
"log": func(fn otto.FunctionCall) otto.Value {
|
|
return console.Write(fn, &customWriter, "vm.console")
|
|
},
|
|
})
|
|
require.NoError(err)
|
|
|
|
_, err = s.vm.Run(fmt.Sprintf(`console.log(%q);`, written))
|
|
require.NoError(err)
|
|
require.Equal(written, strings.TrimPrefix(customWriter.String(), "vm.console: "))
|
|
}
|
|
|
|
// TestObjectLogging will validate the operations of the console.log extension
|
|
// when capturing objects declared from javascript.
|
|
func (s *ConsoleTestSuite) TestObjectLogging() {
|
|
require := s.Require()
|
|
|
|
var customWriter bytes.Buffer
|
|
|
|
node.SetDefaultNodeNotificationHandler(func(event string) {
|
|
|
|
var eventReceived struct {
|
|
Type string `json:"type"`
|
|
Event []struct {
|
|
Age int `json:"age"`
|
|
Name string `json:"name"`
|
|
} `json:"event"`
|
|
}
|
|
|
|
err := json.Unmarshal([]byte(event), &eventReceived)
|
|
require.NoError(err)
|
|
|
|
require.Equal(eventReceived.Type, "vm.console")
|
|
require.NotEmpty(eventReceived.Event)
|
|
|
|
objectReceived := eventReceived.Event[0]
|
|
require.Equal(objectReceived.Age, 24)
|
|
require.Equal(objectReceived.Name, "bob")
|
|
})
|
|
|
|
err := s.vm.Set("console", map[string]interface{}{
|
|
"log": func(fn otto.FunctionCall) otto.Value {
|
|
return console.Write(fn, &customWriter, "vm.console")
|
|
},
|
|
})
|
|
require.NoError(err)
|
|
|
|
_, err = s.vm.Run(`
|
|
var person = {name:"bob", age:24}
|
|
console.log(person);
|
|
`)
|
|
require.NoError(err)
|
|
require.NotEmpty(&customWriter)
|
|
}
|