Skip to content
Snippets Groups Projects
Select Git revision
  • 490f10e3e0a55f1e7d8f503e681d052c525545b7
  • without_tipselection default
  • develop protected
  • fix/grafana-local-dashboard
  • wasp
  • fix/dashboard-explorer-freeze
  • master
  • feat/timerqueue
  • test/sync_debug_and_650
  • feat/sync_revamp_inv
  • wip/sync
  • tool/db-recovery
  • portcheck/fix
  • fix/synchronization
  • feat/new-dashboard-analysis
  • feat/refactored-analysis-dashboard
  • feat/new-analysis-dashboard
  • test/demo-prometheus-fpc
  • prometheus_metrics
  • wip/analysis-server
  • merge/fpc-test-value-transfer
  • v0.2.2
  • v0.2.1
  • v0.2.0
  • v0.1.3
  • v0.1.2
  • v0.1.1
  • v0.1.0
28 results

plugin.go

Blame
  • relaymessage_test.go 2.32 KiB
    package tests
    
    import (
    	"os"
    	"testing"
    	"time"
    
    	"github.com/iotaledger/goshimmer/tools/integration-tests/tester/framework"
    	"github.com/stretchr/testify/assert"
    	"github.com/stretchr/testify/require"
    )
    
    var f *framework.Framework
    
    func TestMain(m *testing.M) {
    	f = framework.New()
    
    	// call the tests
    	os.Exit(m.Run())
    }
    
    func TestRelayMessages(t *testing.T) {
    	numMessages := 100
    	hashes := make([]string, numMessages)
    
    	// create messages on random peers
    	for i := 0; i < numMessages; i++ {
    		req := BroadcastDataRequest{Data: "Test"}
    		resp := new(BroadcastDataResponse)
    		err := f.HttpPost(f.RandomPeer(), "broadcastData", req, resp)
    		require.NoError(t, err)
    
    		hashes[i] = resp.Hash
    	}
    
    	// wait for messages to be gossiped
    	time.Sleep(5 * time.Second)
    
    	// check for messages on every peer
    	for _, peer := range f.Peers() {
    		req := GetMessageByHashRequest{Hashes: hashes}
    		resp := new(GetMessageByHashResponse)
    		err := f.HttpPost(peer, "getMessageByHash", req, resp)
    		require.NoError(t, err)
    
    		// check for the count of messages
    		assert.Equal(t, numMessages, len(resp.Messages))
    
    		// check that all messages are present in response
    	outer:
    		for _, hash := range hashes {
    			for _, msg := range resp.Messages {
    				// if message found skip to next
    				if msg.MessageId == hash {
    					continue outer
    				}
    			}
    
    			t.Errorf("MessageId=%s not found in peer %s.", hash, peer.String())
    		}
    	}
    }
    
    // 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"`
    }