Skip to content
Snippets Groups Projects
Unverified Commit 7238336f authored by jonastheis's avatar jonastheis
Browse files

Adjust relay test to use new API wrapper

parent a78b8b97
No related branches found
No related tags found
No related merge requests found
...@@ -22,6 +22,7 @@ var ( ...@@ -22,6 +22,7 @@ var (
const ( const (
routeBroadcastData = "broadcastData" routeBroadcastData = "broadcastData"
routeGetNeighbors = "getNeighbors" routeGetNeighbors = "getNeighbors"
routeGetMessageByHash = "getMessageByHash"
contentTypeJSON = "application/json" contentTypeJSON = "application/json"
) )
...@@ -159,3 +160,19 @@ func (api *Api) GetNeighbors(knownPeers bool) (*GetNeighborResponse, error) { ...@@ -159,3 +160,19 @@ func (api *Api) GetNeighbors(knownPeers bool) (*GetNeighborResponse, error) {
return res, nil return res, nil
} }
func (api *Api) GetMessageByHash(hashes []string) (*GetMessageByHashResponse, error) {
res := &GetMessageByHashResponse{}
err := api.do(
http.MethodPost,
routeGetMessageByHash,
&GetMessageByHashRequest{Hashes: hashes},
res,
)
if err != nil {
return nil, err
}
return res, nil
}
...@@ -5,9 +5,10 @@ import ( ...@@ -5,9 +5,10 @@ import (
"testing" "testing"
"time" "time"
"github.com/iotaledger/goshimmer/tools/integration-tests/tester/framework"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/iotaledger/goshimmer/tools/integration-tests/tester/framework"
) )
var f *framework.Framework var f *framework.Framework
...@@ -25,12 +26,10 @@ func TestRelayMessages(t *testing.T) { ...@@ -25,12 +26,10 @@ func TestRelayMessages(t *testing.T) {
// create messages on random peers // create messages on random peers
for i := 0; i < numMessages; i++ { for i := 0; i < numMessages; i++ {
req := BroadcastDataRequest{Data: "Test"} hash, err := f.RandomPeer().BroadcastData("Test")
resp := new(BroadcastDataResponse)
err := f.HttpPost(f.RandomPeer(), "broadcastData", req, resp)
require.NoError(t, err) require.NoError(t, err)
hashes[i] = resp.Hash hashes[i] = hash
} }
// wait for messages to be gossiped // wait for messages to be gossiped
...@@ -38,9 +37,7 @@ func TestRelayMessages(t *testing.T) { ...@@ -38,9 +37,7 @@ func TestRelayMessages(t *testing.T) {
// check for messages on every peer // check for messages on every peer
for _, peer := range f.Peers() { for _, peer := range f.Peers() {
req := GetMessageByHashRequest{Hashes: hashes} resp, err := peer.GetMessageByHash(hashes)
resp := new(GetMessageByHashResponse)
err := f.HttpPost(peer, "getMessageByHash", req, resp)
require.NoError(t, err) require.NoError(t, err)
// check for the count of messages // check for the count of messages
...@@ -60,33 +57,3 @@ func TestRelayMessages(t *testing.T) { ...@@ -60,33 +57,3 @@ func TestRelayMessages(t *testing.T) {
} }
} }
} }
// TODO: there should be a nice way to handle all those API endpoints
type BroadcastDataResponse struct {
Hash string `json:"hash,omitempty"`
Error string `json:"error,omitempty"`
}
type BroadcastDataRequest struct {
Data string `json:"data"`
}
type GetMessageByHashResponse struct {
Messages []Message `json:"messages,omitempty"`
Error string `json:"error,omitempty"`
}
type GetMessageByHashRequest struct {
Hashes []string `json:"hashes"`
}
type Message struct {
MessageId string `json:"messageId,omitempty"`
TrunkTransactionId string `json:"trunkTransactionId,omitempty"`
BranchTransactionId string `json:"branchTransactionId,omitempty"`
IssuerPublicKey string `json:"issuerPublicKey,omitempty"`
IssuingTime string `json:"issuingTime,omitempty"`
SequenceNumber uint64 `json:"sequenceNumber,omitempty"`
Payload string `json:"payload,omitempty"`
Signature string `json:"signature,omitempty"`
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment