mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-23 04:03:49 +00:00
a8ec9eb471
Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro-2.local>
48 lines
1.4 KiB
Go
48 lines
1.4 KiB
Go
package requests
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"github.com/ledgerwatch/erigon/cmd/devnet/devnetutils"
|
|
"github.com/ledgerwatch/erigon/cmd/devnet/models"
|
|
"github.com/ledgerwatch/erigon/cmd/rpctest/rpctest"
|
|
"github.com/ledgerwatch/log/v3"
|
|
)
|
|
|
|
func GetAndCompareLogs(reqId int, fromBlock uint64, toBlock uint64, expected rpctest.Log, logger log.Logger) error {
|
|
logger.Info("GETTING AND COMPARING LOGS")
|
|
reqGen := initialiseRequestGenerator(reqId, logger)
|
|
var b rpctest.EthGetLogs
|
|
|
|
if res := reqGen.Erigon(models.ETHGetLogs, reqGen.GetLogs(fromBlock, toBlock, expected.Address), &b); res.Err != nil {
|
|
return fmt.Errorf("failed to fetch logs: %v", res.Err)
|
|
}
|
|
|
|
if len(b.Result) == 0 {
|
|
return fmt.Errorf("logs result should not be empty")
|
|
}
|
|
|
|
eventLog := b.Result[0]
|
|
|
|
actual := devnetutils.BuildLog(eventLog.TxHash, strconv.FormatUint(uint64(eventLog.BlockNumber), 10),
|
|
eventLog.Address, eventLog.Topics, eventLog.Data, eventLog.TxIndex, eventLog.BlockHash, eventLog.Index,
|
|
eventLog.Removed)
|
|
|
|
// compare the log events
|
|
errs, ok := devnetutils.CompareLogEvents(expected, actual)
|
|
if !ok {
|
|
logger.Error("Log result is incorrect", "errors", errs)
|
|
return fmt.Errorf("incorrect logs: %v", errs)
|
|
}
|
|
|
|
_, err := devnetutils.ParseResponse(b)
|
|
if err != nil {
|
|
return fmt.Errorf("error parsing response: %v", err)
|
|
}
|
|
|
|
log.Info("SUCCESS => Logs compared successfully, no discrepancies")
|
|
|
|
return nil
|
|
}
|