2017-12-21 10:26:01 +00:00
|
|
|
package whisper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/status-im/status-go/geth/node"
|
|
|
|
"github.com/status-im/status-go/geth/params"
|
2018-04-12 16:17:10 +00:00
|
|
|
"github.com/status-im/status-go/t/e2e"
|
2017-12-21 10:26:01 +00:00
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMailServiceSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(MailServiceSuite))
|
|
|
|
}
|
|
|
|
|
|
|
|
type MailServiceSuite struct {
|
2018-04-05 09:45:26 +00:00
|
|
|
e2e.StatusNodeTestSuite
|
2017-12-21 10:26:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MailServiceSuite) SetupTest() {
|
2018-04-05 09:45:26 +00:00
|
|
|
s.StatusNode = node.New()
|
2017-12-21 10:26:01 +00:00
|
|
|
}
|
|
|
|
|
2018-04-26 05:56:19 +00:00
|
|
|
// TestShhextRequestMessagesRPCMethodAvailability tests if `shhext_requestMessages` is available
|
2017-12-21 10:26:01 +00:00
|
|
|
// through inproc and HTTP interfaces.
|
2018-04-26 05:56:19 +00:00
|
|
|
func (s *MailServiceSuite) TestShhextRequestMessagesRPCMethodAvailability() {
|
2017-12-21 10:26:01 +00:00
|
|
|
r := s.Require()
|
|
|
|
|
|
|
|
s.StartTestNode(func(config *params.NodeConfig) {
|
|
|
|
config.RPCEnabled = true
|
2018-06-04 17:13:02 +00:00
|
|
|
config.APIModules = "shhext"
|
2017-12-21 10:26:01 +00:00
|
|
|
})
|
|
|
|
defer s.StopTestNode()
|
|
|
|
|
2018-04-05 09:45:26 +00:00
|
|
|
client := s.StatusNode.RPCClient()
|
2017-12-21 10:26:01 +00:00
|
|
|
r.NotNil(client)
|
|
|
|
|
|
|
|
// This error means that the method is available through inproc communication
|
|
|
|
// as the validation of params occurred.
|
2018-04-26 05:56:19 +00:00
|
|
|
err := client.Call(nil, "shhext_requestMessages", map[string]interface{}{})
|
2017-12-21 10:26:01 +00:00
|
|
|
r.EqualError(err, `invalid mailServerPeer value: invalid URL scheme, want "enode"`)
|
|
|
|
|
|
|
|
// Do the same but using HTTP interface.
|
|
|
|
req, err := http.NewRequest("POST", "http://localhost:8645", bytes.NewBuffer([]byte(`{
|
|
|
|
"jsonrpc": "2.0",
|
|
|
|
"id": 1,
|
2018-04-26 05:56:19 +00:00
|
|
|
"method": "shhext_requestMessages",
|
2017-12-21 10:26:01 +00:00
|
|
|
"params": [{}]
|
|
|
|
}`)))
|
2018-01-17 16:12:40 +00:00
|
|
|
req.Header.Set("Content-Type", "application/json")
|
2017-12-21 10:26:01 +00:00
|
|
|
r.NoError(err)
|
|
|
|
resp, err := http.DefaultClient.Do(req)
|
|
|
|
r.NoError(err)
|
2018-02-12 11:16:06 +00:00
|
|
|
defer func() {
|
|
|
|
err := resp.Body.Close()
|
|
|
|
r.NoError(err)
|
|
|
|
}()
|
2017-12-21 10:26:01 +00:00
|
|
|
r.Equal(200, resp.StatusCode)
|
|
|
|
data, err := ioutil.ReadAll(resp.Body)
|
|
|
|
r.NoError(err)
|
|
|
|
r.Contains(string(data), `invalid mailServerPeer value`)
|
|
|
|
}
|