test sending message without subscription

This commit is contained in:
Evgeny Danienko 2018-03-26 19:01:26 +03:00
parent aed16a9071
commit aaf2b41e2e
No known key found for this signature in database
GPG Key ID: BC8C34D8B45BECBF
1 changed files with 38 additions and 11 deletions

View File

@ -110,7 +110,7 @@ func (s *WhisperMailboxSuite) TestRequestMessageFromMailboxAsync() {
reqMessagesResp := baseRPCResponse{} reqMessagesResp := baseRPCResponse{}
err = json.Unmarshal([]byte(resp), &reqMessagesResp) err = json.Unmarshal([]byte(resp), &reqMessagesResp)
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Nil(reqMessagesResp.Err) s.Require().Nil(reqMessagesResp.Error)
//wait to receive message //wait to receive message
time.Sleep(time.Second) time.Sleep(time.Second)
@ -276,6 +276,31 @@ func (s *WhisperMailboxSuite) TestRequestMessagesInGroupChat() {
s.Require().Equal(helloWorldMessage, messages[0]["payload"].(string)) s.Require().Equal(helloWorldMessage, messages[0]["payload"].(string))
} }
func (s *WhisperMailboxSuite) TestSendMessageWithoutSubscription() {
aliceBackend, stop := s.startBackend("alice")
defer stop()
// we need to wain >= whisper.DefaultSyncAllowance seconds to update
time.Sleep(12 * time.Second)
//get whisper service
aliceWhisperService, err := aliceBackend.NodeManager().WhisperService()
s.Require().NoError(err)
//get rpc client
aliceRPCClient := aliceBackend.NodeManager().RPCClient()
//generate group chat symkey and topic
groupChatKeyID, err := aliceWhisperService.GenerateSymKey()
s.Require().NoError(err)
//generate group chat topic
groupChatTopic := whisper.BytesToTopic([]byte("groupChatTopic"))
//alice send message to group chat
helloWorldMessage := hexutil.Encode([]byte("Hello world!"))
s.postMessageToGroup(aliceRPCClient, groupChatKeyID, groupChatTopic.String(), helloWorldMessage)
time.Sleep(5 * time.Second) //it need to receive envelopes by bob and charlie nodes
}
func newGroupChatParams(symkey []byte, topic whisper.TopicType) groupChatParams { func newGroupChatParams(symkey []byte, topic whisper.TopicType) groupChatParams {
groupChatKeyStr := hexutil.Bytes(symkey).String() groupChatKeyStr := hexutil.Bytes(symkey).String()
return groupChatParams{ return groupChatParams{
@ -314,6 +339,8 @@ func (s *WhisperMailboxSuite) startBackend(name string) (*api.StatusBackend, fun
s.Require().NoError(err) s.Require().NoError(err)
s.Require().False(backend.IsNodeRunning()) s.Require().False(backend.IsNodeRunning())
nodeConfig.WhisperConfig.LightClient = true
if addr, err := GetRemoteURL(); err == nil { if addr, err := GetRemoteURL(); err == nil {
nodeConfig.UpstreamConfig.Enabled = true nodeConfig.UpstreamConfig.Enabled = true
nodeConfig.UpstreamConfig.URL = addr nodeConfig.UpstreamConfig.URL = addr
@ -373,7 +400,7 @@ func (s *WhisperMailboxSuite) createPrivateChatMessageFilter(rpcCli *rpc.Client,
err := json.Unmarshal([]byte(resp), &msgFilterResp) err := json.Unmarshal([]byte(resp), &msgFilterResp)
messageFilterID := msgFilterResp.Result messageFilterID := msgFilterResp.Result
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Nil(msgFilterResp.Err) s.Require().Nil(msgFilterResp.Error)
s.Require().NotEqual("", messageFilterID, resp) s.Require().NotEqual("", messageFilterID, resp)
return messageFilterID return messageFilterID
} }
@ -392,7 +419,7 @@ func (s *WhisperMailboxSuite) createGroupChatMessageFilter(rpcCli *rpc.Client, s
err := json.Unmarshal([]byte(resp), &msgFilterResp) err := json.Unmarshal([]byte(resp), &msgFilterResp)
messageFilterID := msgFilterResp.Result messageFilterID := msgFilterResp.Result
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Nil(msgFilterResp.Err) s.Require().Nil(msgFilterResp.Error)
s.Require().NotEqual("", messageFilterID, resp) s.Require().NotEqual("", messageFilterID, resp)
return messageFilterID return messageFilterID
} }
@ -414,7 +441,7 @@ func (s *WhisperMailboxSuite) postMessageToPrivate(rpcCli *rpc.Client, bobPubkey
postResp := baseRPCResponse{} postResp := baseRPCResponse{}
err := json.Unmarshal([]byte(resp), &postResp) err := json.Unmarshal([]byte(resp), &postResp)
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Nil(postResp.Err) s.Require().Nil(postResp.Error)
} }
func (s *WhisperMailboxSuite) postMessageToGroup(rpcCli *rpc.Client, groupChatKeyID string, topic string, payload string) { func (s *WhisperMailboxSuite) postMessageToGroup(rpcCli *rpc.Client, groupChatKeyID string, topic string, payload string) {
@ -434,7 +461,7 @@ func (s *WhisperMailboxSuite) postMessageToGroup(rpcCli *rpc.Client, groupChatKe
postResp := baseRPCResponse{} postResp := baseRPCResponse{}
err := json.Unmarshal([]byte(resp), &postResp) err := json.Unmarshal([]byte(resp), &postResp)
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Nil(postResp.Err) s.Require().Nil(postResp.Error)
} }
//getMessagesByMessageFilterID get received messages by messageFilterID //getMessagesByMessageFilterID get received messages by messageFilterID
@ -447,7 +474,7 @@ func (s *WhisperMailboxSuite) getMessagesByMessageFilterID(rpcCli *rpc.Client, m
messages := getFilterMessagesResponse{} messages := getFilterMessagesResponse{}
err := json.Unmarshal([]byte(resp), &messages) err := json.Unmarshal([]byte(resp), &messages)
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Nil(messages.Err) s.Require().Nil(messages.Error)
return messages.Result return messages.Result
} }
@ -459,7 +486,7 @@ func (s *WhisperMailboxSuite) addSymKey(rpcCli *rpc.Client, symkey string) strin
symkeyAddResp := returnedIDResponse{} symkeyAddResp := returnedIDResponse{}
err := json.Unmarshal([]byte(resp), &symkeyAddResp) err := json.Unmarshal([]byte(resp), &symkeyAddResp)
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Nil(symkeyAddResp.Err) s.Require().Nil(symkeyAddResp.Error)
symkeyID := symkeyAddResp.Result symkeyID := symkeyAddResp.Result
s.Require().NotEmpty(symkeyID) s.Require().NotEmpty(symkeyID)
return symkeyID return symkeyID
@ -482,19 +509,19 @@ func (s *WhisperMailboxSuite) requestHistoricMessages(rpcCli *rpc.Client, mailbo
reqMessagesResp := baseRPCResponse{} reqMessagesResp := baseRPCResponse{}
err := json.Unmarshal([]byte(resp), &reqMessagesResp) err := json.Unmarshal([]byte(resp), &reqMessagesResp)
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Nil(reqMessagesResp.Err) s.Require().Nil(reqMessagesResp.Error)
} }
type getFilterMessagesResponse struct { type getFilterMessagesResponse struct {
Result []map[string]interface{} Result []map[string]interface{}
Err interface{} Error interface{}
} }
type returnedIDResponse struct { type returnedIDResponse struct {
Result string Result string
Err interface{} Error interface{}
} }
type baseRPCResponse struct { type baseRPCResponse struct {
Result interface{} Result interface{}
Err interface{} Error interface{}
} }