2017-12-21 10:26:01 +00:00
|
|
|
package whisper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
2020-01-02 09:10:19 +00:00
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
2018-06-08 11:29:50 +00:00
|
|
|
"github.com/status-im/status-go/node"
|
|
|
|
"github.com/status-im/status-go/params"
|
2018-04-12 16:17:10 +00:00
|
|
|
"github.com/status-im/status-go/t/e2e"
|
2019-10-04 15:21:24 +00:00
|
|
|
"github.com/status-im/status-go/t/utils"
|
2017-12-21 10:26:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMailServiceSuite(t *testing.T) {
|
2019-10-04 15:21:24 +00:00
|
|
|
utils.Init()
|
2017-12-21 10:26:01 +00:00
|
|
|
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) {
|
2018-09-21 14:09:31 +00:00
|
|
|
config.HTTPEnabled = true
|
2018-08-02 06:48:44 +00:00
|
|
|
config.AddAPIModule("shhext")
|
2017-12-21 10:26:01 +00:00
|
|
|
})
|
|
|
|
defer s.StopTestNode()
|
|
|
|
|
2018-08-02 06:48:44 +00:00
|
|
|
client := s.StatusNode.RPCPrivateClient()
|
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-12-05 13:57:05 +00:00
|
|
|
err := client.Call(nil, "shhext_requestMessages", map[string]interface{}{
|
|
|
|
"mailServerPeer": "xxx",
|
|
|
|
})
|
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`)
|
|
|
|
}
|