status-go/t/e2e/whisper/mailservice_test.go

71 lines
1.8 KiB
Go
Raw Normal View History

package whisper
import (
"bytes"
"io/ioutil"
"net/http"
"testing"
2020-01-02 09:10:19 +00:00
"github.com/stretchr/testify/suite"
"github.com/status-im/status-go/node"
"github.com/status-im/status-go/params"
"github.com/status-im/status-go/t/e2e"
"github.com/status-im/status-go/t/utils"
)
func TestMailServiceSuite(t *testing.T) {
utils.Init()
suite.Run(t, new(MailServiceSuite))
}
type MailServiceSuite struct {
e2e.StatusNodeTestSuite
}
func (s *MailServiceSuite) SetupTest() {
s.StatusNode = node.New()
}
// TestShhextRequestMessagesRPCMethodAvailability tests if `shhext_requestMessages` is available
// through inproc and HTTP interfaces.
func (s *MailServiceSuite) TestShhextRequestMessagesRPCMethodAvailability() {
r := s.Require()
s.StartTestNode(func(config *params.NodeConfig) {
config.HTTPEnabled = true
config.AddAPIModule("shhext")
})
defer s.StopTestNode()
client := s.StatusNode.RPCPrivateClient()
r.NotNil(client)
// This error means that the method is available through inproc communication
// as the validation of params occurred.
Mail peer store and connection manager (#1295) This change implements connection manager that monitors 3 types of events: 1. update of the selected mail servers 2. disconnect from a mail server 3. errors for requesting mail history When selected mail servers provided we will try to connect with as many as possible, and later disconnect the surplus. For example if we want to connect with one mail server and 3 were selected, we try to connect with all (3), and later disconnect with 2. It will to establish connection with live mail server faster. If mail server disconnects we will choose any other mail server from the list of selected. Unless we have only one mail server. In such case we don't have any other choice and we will leave things as is. If request for history was expired we will disconnect such peer and try to find another one. We will follow same rules as described above. We will have two components that will rely on this logic: 1. requesting history If target peer is provided we will use that peer, otherwise we will request history from any selected mail server that is connected at the time of request. 2. confirmation from selected mail server Confirmation from any selected mail server will bee used to send a feedback that envelope was sent. I will add several extensions, but probably in separate PRs: 1. prioritize connection with mail server that was used before reboot 2. disconnect from mail servers if history request wasn't expired but failed. 3. wait some time in RequestsMessage RPC to establish connection with any mail server Currently this feature is hidden, as certain changes will be necessary in status-react. partially implements: https://github.com/status-im/status-go/issues/1285
2018-12-05 13:57:05 +00:00
err := client.Call(nil, "shhext_requestMessages", map[string]interface{}{
"mailServerPeer": "xxx",
})
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,
"method": "shhext_requestMessages",
"params": [{}]
}`)))
req.Header.Set("Content-Type", "application/json")
r.NoError(err)
resp, err := http.DefaultClient.Do(req)
r.NoError(err)
defer func() {
err := resp.Body.Close()
r.NoError(err)
}()
r.Equal(200, resp.StatusCode)
data, err := ioutil.ReadAll(resp.Body)
r.NoError(err)
r.Contains(string(data), `invalid mailServerPeer value`)
}