Skip to content

Commit

Permalink
Merge commit '621715941ca8843652dbc7d21aa7b7a32cd20dbe' into deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
iulianpascalau committed Jan 30, 2020
2 parents 331bdeb + 6217159 commit 7d3ccd2
Show file tree
Hide file tree
Showing 676 changed files with 14,283 additions and 24,040 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div style="text-align:center">
<img src="https://github.com/ElrondNetwork/elrond-go/blob/master/elrond_logo_01.svg"></img>
<img src="https://github.com/ElrondNetwork/elrond-go/blob/master/elrond_logo_01.svg" alt="Elrond Network">
</div>

<br>
Expand Down
18 changes: 0 additions & 18 deletions api/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,12 @@ var ErrGetBalance = errors.New("get balance error")
// ErrEmptyAddress signals an empty address was provided
var ErrEmptyAddress = errors.New("address was empty")

// ErrNodeAlreadyRunning signals the node is already running
var ErrNodeAlreadyRunning = errors.New("node already running")

// ErrNodeAlreadyStopped signals the node is already stopped
var ErrNodeAlreadyStopped = errors.New("node already stopped")

// ErrCouldNotStopNode signals the node is already stopped
var ErrCouldNotStopNode = errors.New("could not stop node")

// ErrBadInitOfNode signals the node is could not be started correctly
var ErrBadInitOfNode = errors.New("bad init of node")

// ErrCouldNotParsePubKey signals that a given public key could not be parsed
var ErrCouldNotParsePubKey = errors.New("could not parse node's public key")

// ErrValidation signals an error in validation
var ErrValidation = errors.New("validation error")

// ErrTxGenerationFailed signals an error generating a transaction
var ErrTxGenerationFailed = errors.New("transaction generation failed")

// ErrMultipleTxGenerationFailed signals an error generating multiple transactions
var ErrMultipleTxGenerationFailed = errors.New("multiple transaction generation failed")

// ErrInvalidSignatureHex signals a wrong hex value was provided for the signature
var ErrInvalidSignatureHex = errors.New("invalid signature, could not decode hex value")

Expand Down
2 changes: 1 addition & 1 deletion api/logs/logSender.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (ls *logSender) StartSendingBlocking() {
_ = ls.writer.Close()
_ = logger.RemoveLogObserver(ls.writer)
_ = logger.SetLogLevel(ls.lastLogPattern)
ls.log.Info("reverted log pattern", "pattern", string(ls.lastLogPattern))
ls.log.Info("reverted log pattern", "pattern", ls.lastLogPattern)
}()

err := ls.waitForPatternMessage()
Expand Down
24 changes: 14 additions & 10 deletions api/mock/facade.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ type Facade struct {
Running bool
ShouldErrorStart bool
ShouldErrorStop bool
GetCurrentPublicKeyHandler func() string
TpsBenchmarkHandler func() *statistics.TpsBenchmark
GetHeartbeatsHandler func() ([]heartbeat.PubKeyHeartbeat, error)
BalanceHandler func(string) (*big.Int, error)
Expand All @@ -33,6 +32,18 @@ type Facade struct {
ValidatorStatisticsHandler func() (map[string]*state.ValidatorApiResponse, error)
}

func (f *Facade) RestApiInterface() string {
return "localhost:8080"
}

func (f *Facade) RestAPIServerDebugMode() bool {
return false
}

func (f *Facade) PprofEnabled() bool {
return false
}

// IsNodeRunning is the mock implementation of a handler's IsNodeRunning method
func (f *Facade) IsNodeRunning() bool {
return f.Running
Expand Down Expand Up @@ -63,11 +74,7 @@ func (f *Facade) StopNode() error {
return nil
}

// GetCurrentPublicKey is the mock implementation of a handler's StopNode method
func (f *Facade) GetCurrentPublicKey() string {
return f.GetCurrentPublicKeyHandler()
}

// GetHeartbeats returns the slice of heartbeat info
func (f *Facade) GetHeartbeats() ([]heartbeat.PubKeyHeartbeat, error) {
return f.GetHeartbeatsHandler()
}
Expand Down Expand Up @@ -135,10 +142,7 @@ func (f *Facade) StatusMetrics() external.StatusMetricsHandler {

// IsInterfaceNil returns true if there is no value under the interface
func (f *Facade) IsInterfaceNil() bool {
if f == nil {
return true
}
return false
return f == nil
}

// WrongFacade is a struct that can be used as a wrong implementation of the node router handler
Expand Down
6 changes: 3 additions & 3 deletions api/node/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ type statisticsResponse struct {
}

type shardStatisticsResponse struct {
ShardID uint32 `json:"shardID"`
LiveTPS float64 `json:"liveTPS"`
AverageTPS *big.Int `json:"averageTPS"`
PeakTPS float64 `json:"peakTPS"`
AverageBlockTxCount uint32 `json:"averageBlockTxCount"`
CurrentBlockNonce uint64 `json:"currentBlockNonce"`
LastBlockTxCount uint32 `json:"lastBlockTxCount"`
TotalProcessedTxCount *big.Int `json:"totalProcessedTxCount"`
ShardID uint32 `json:"shardID"`
AverageBlockTxCount uint32 `json:"averageBlockTxCount"`
LastBlockTxCount uint32 `json:"lastBlockTxCount"`
}

// Routes defines node related routes
Expand Down
3 changes: 2 additions & 1 deletion api/transaction/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ func SendMultipleTransactions(c *gin.Context) {
}

var txs []*transaction.Transaction
var tx *transaction.Transaction
for _, receivedTx := range gtx {
tx, err := ef.CreateTransaction(
tx, err = ef.CreateTransaction(
receivedTx.Nonce,
receivedTx.Value,
receivedTx.Receiver,
Expand Down
82 changes: 82 additions & 0 deletions api/transaction/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,88 @@ func TestSendTransaction_ReturnsSuccessfully(t *testing.T) {
assert.Equal(t, txHashResponse.TxHash, txHash)
}

func TestSendMultipleTransactions_ErrorWithWrongFacade(t *testing.T) {
t.Parallel()

ws := startNodeServerWrongFacade()
req, _ := http.NewRequest("POST", "/transaction/send-multiple", nil)
resp := httptest.NewRecorder()
ws.ServeHTTP(resp, req)

transactionResponse := TransactionResponse{}
loadResponse(resp.Body, &transactionResponse)
assert.Equal(t, http.StatusInternalServerError, resp.Code)
assert.Equal(t, transactionResponse.Error, errors2.ErrInvalidAppContext.Error())
}

func TestSendMultipleTransactions_WrongPayloadShouldErrorOnValidation(t *testing.T) {
t.Parallel()

facade := mock.Facade{}
ws := startNodeServer(&facade)

jsonStr := `{"wrong": json}`

req, _ := http.NewRequest("POST", "/transaction/send-multiple", bytes.NewBuffer([]byte(jsonStr)))

resp := httptest.NewRecorder()
ws.ServeHTTP(resp, req)

transactionResponse := TransactionResponse{}
loadResponse(resp.Body, &transactionResponse)

assert.Equal(t, http.StatusBadRequest, resp.Code)
assert.Contains(t, transactionResponse.Error, errors2.ErrValidation.Error())
assert.Empty(t, transactionResponse.TxResp)
}

func TestSendMultipleTransactions_OkPayloadShouldWork(t *testing.T) {
t.Parallel()

createTxWasCalled := false
sendBulkTxsWasCalled := false

facade := mock.Facade{
CreateTransactionHandler: func(nonce uint64, value string, receiverHex string, senderHex string, gasPrice uint64, gasLimit uint64, data []byte, signatureHex string) (i *tr.Transaction, e error) {
createTxWasCalled = true
return &tr.Transaction{}, nil
},
SendBulkTransactionsHandler: func(txs []*tr.Transaction) (u uint64, e error) {
sendBulkTxsWasCalled = true
return 0, nil
},
}
ws := startNodeServer(&facade)

tx0 := transaction.SendTxRequest{
Sender: "sender1",
Receiver: "receiver1",
Value: "100",
Data: []byte{},
Nonce: 0,
GasPrice: 0,
GasLimit: 0,
Signature: "",
}
tx1 := tx0
tx1.Sender = "sender2"
txs := []*transaction.SendTxRequest{&tx0, &tx1}

jsonBytes, _ := json.Marshal(txs)

req, _ := http.NewRequest("POST", "/transaction/send-multiple", bytes.NewBuffer(jsonBytes))

resp := httptest.NewRecorder()
ws.ServeHTTP(resp, req)

transactionResponse := TransactionResponse{}
loadResponse(resp.Body, &transactionResponse)

assert.Equal(t, http.StatusOK, resp.Code)
assert.True(t, createTxWasCalled)
assert.True(t, sendBulkTxsWasCalled)
}

func loadResponse(rsp io.Reader, destination interface{}) {
jsonParser := json.NewDecoder(rsp)
err := jsonParser.Decode(destination)
Expand Down
3 changes: 2 additions & 1 deletion api/vmValues/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ func createSCQuery(request *VMValueRequest) (*process.SCQuery, error) {
}

arguments := make([][]byte, len(request.Args))
var argBytes []byte
for i, arg := range request.Args {
argBytes, err := hex.DecodeString(arg)
argBytes, err = hex.DecodeString(arg)
if err != nil {
return nil, fmt.Errorf("'%s' is not a valid hex string: %s", arg, err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion api/vmValues/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func doPost(facadeMock interface{}, url string, request VMValueRequest, response
jsonBody, _ := json.Marshal(request)

server := startNodeServer(facadeMock)
httpRequest, _ := http.NewRequest("POST", url, bytes.NewBuffer([]byte(jsonBody)))
httpRequest, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonBody))

responseRecorder := httptest.NewRecorder()
server.ServeHTTP(responseRecorder, httpRequest)
Expand Down
1 change: 0 additions & 1 deletion benchmark-broadcast/.idea/.name

This file was deleted.

8 changes: 0 additions & 8 deletions benchmark-broadcast/.idea/benchmark-broadcast.iml

This file was deleted.

6 changes: 0 additions & 6 deletions benchmark-broadcast/.idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions benchmark-broadcast/.idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions benchmark-broadcast/.idea/vcs.xml

This file was deleted.

0 comments on commit 7d3ccd2

Please sign in to comment.