Skip to content
Snippets Groups Projects
  • Jonas Theis's avatar
    14948393
    Integration tests (#312) · 14948393
    Jonas Theis authored
    * Add docker compose for running integration tests.
    Runs entry_node and arbitrary number of peers in docker network
    
    * Fix permission denied in container if run without mounting a `rw` volume making it possible to run as throw-away container.
    Remove `VOLUME` from Dockerfile as this only pollutes host system with anonymous volumes.
    
    * Use named network for easier external use
    
    * Add test container that discovers peers and waits for autopeering to happen
    
    * Fix min waitForNeighbors
    
    * Add go.sum
    
    * Run integration tests with Github Actions
    
    * Added framework that abstracts the docker network and provides convenience functionality
    
    * Update directory in Github Actions
    
    * Add bash script for automated local test execution
    
    * Add getMessageByHash endpoint
    
    * Adjust to merge changes
    
    * Add methods to easily do HTTP POST requests
    
    * Added relay message test
    
    * Increase client timeout
    
    * Verbose output for tests makes it easier to follow the execution
    
    * Introduce small API wrapper for GoShimmer HTTP API
    
    * Adjust relay test to use new API wrapper
    
    * WIP: Docker logs
    
    * Fix issue with serving visualizer analysis server of entry node
    
    * Persist logs of containers after CI run
    
    * Fix test file
    
    * Fix uploading of artifacts
    
    * Save all containers' logs as artifacts
    
    * Create logs files also with local run
    
    * Add possibility to retrieve logs from a peer via Docker logs
    
    * Make tester part of the goshimmer module to make code sharing possible
    
    * Use client/lib to make HTTP requests in tester
    
    * Fix unit test directory
    
    * Add comments/doc to the code
    
    * Add readme
    
    * Move tester to own module and don't build container but use existing golang one instead
    
    * Address PR comments
    
    * Adjust to merge
    
    * Only use 1 config file for all containers
    
    * go mod tidy
    
    * Rename client lib base url
    Integration tests (#312)
    Jonas Theis authored
    * Add docker compose for running integration tests.
    Runs entry_node and arbitrary number of peers in docker network
    
    * Fix permission denied in container if run without mounting a `rw` volume making it possible to run as throw-away container.
    Remove `VOLUME` from Dockerfile as this only pollutes host system with anonymous volumes.
    
    * Use named network for easier external use
    
    * Add test container that discovers peers and waits for autopeering to happen
    
    * Fix min waitForNeighbors
    
    * Add go.sum
    
    * Run integration tests with Github Actions
    
    * Added framework that abstracts the docker network and provides convenience functionality
    
    * Update directory in Github Actions
    
    * Add bash script for automated local test execution
    
    * Add getMessageByHash endpoint
    
    * Adjust to merge changes
    
    * Add methods to easily do HTTP POST requests
    
    * Added relay message test
    
    * Increase client timeout
    
    * Verbose output for tests makes it easier to follow the execution
    
    * Introduce small API wrapper for GoShimmer HTTP API
    
    * Adjust relay test to use new API wrapper
    
    * WIP: Docker logs
    
    * Fix issue with serving visualizer analysis server of entry node
    
    * Persist logs of containers after CI run
    
    * Fix test file
    
    * Fix uploading of artifacts
    
    * Save all containers' logs as artifacts
    
    * Create logs files also with local run
    
    * Add possibility to retrieve logs from a peer via Docker logs
    
    * Make tester part of the goshimmer module to make code sharing possible
    
    * Use client/lib to make HTTP requests in tester
    
    * Fix unit test directory
    
    * Add comments/doc to the code
    
    * Add readme
    
    * Move tester to own module and don't build container but use existing golang one instead
    
    * Address PR comments
    
    * Adjust to merge
    
    * Only use 1 config file for all containers
    
    * go mod tidy
    
    * Rename client lib base url
plugin.go 2.53 KiB
package getMessageByHash

import (
	"net/http"

	"github.com/iotaledger/goshimmer/packages/binary/messagelayer/message"
	"github.com/iotaledger/goshimmer/plugins/messagelayer"
	"github.com/labstack/echo"

	"github.com/iotaledger/goshimmer/plugins/webapi"

	"github.com/iotaledger/hive.go/logger"
	"github.com/iotaledger/hive.go/node"
)

var PLUGIN = node.NewPlugin("WebAPI getMessageByHash Endpoint", node.Enabled, configure)
var log *logger.Logger

func configure(plugin *node.Plugin) {
	log = logger.NewLogger("API-getMessageByHash")
	webapi.Server.POST("getMessageByHash", getMessageByHash)
}

// getMessageByHash returns the array of messages for the
// given message hashes (in the same order as the parameters).
// If a node doesn't have the message for a given message hash in its ledger,
// the value at the index of that message hash is empty.
func getMessageByHash(c echo.Context) error {
	var request Request
	if err := c.Bind(&request); err != nil {
		log.Info(err.Error())
		return c.JSON(http.StatusBadRequest, Response{Error: err.Error()})
	}

	var result []Message
	for _, hash := range request.Hashes {
		log.Info("Received:", hash)

		msgId, err := message.NewId(hash)
		if err != nil {
			log.Info(err)
			continue
		}

		msgObject := messagelayer.Tangle.Message(msgId)
		if !msgObject.Exists() {
			continue
		}

		msg := msgObject.Unwrap()
		msgResp := Message{
			MessageId:           msg.Id().String(),
			TrunkTransactionId:  msg.TrunkId().String(),
			BranchTransactionId: msg.BranchId().String(),
			IssuerPublicKey:     msg.IssuerPublicKey().String(),
			IssuingTime:         msg.IssuingTime().String(),
			SequenceNumber:      msg.SequenceNumber(),
			Payload:             msg.Payload().String(),
			Signature:           msg.Signature().String(),
		}
		result = append(result, msgResp)
		msgObject.Release()
	}

	return c.JSON(http.StatusOK, Response{Messages: result})
}

type Response struct {
	Messages []Message `json:"messages,omitempty"`
	Error    string    `json:"error,omitempty"`
}

type Request 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"`
}