Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
wojciechos committed Sep 3, 2024
1 parent 9eebf4c commit ec2f145
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 173 deletions.
43 changes: 0 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

This project contains peer-to-peer (P2P) tests for the Starknet network. It is inspired by Ziggurat (https://github.com/runziggurat) but written in Go.

## Overview

Starknet is a permissionless decentralized Validity-Rollup (often referred to as ZK-Rollup). It operates as a Layer 2 network over Ethereum, enabling any dApp to achieve unlimited scale for its computation without compromising Ethereum's composability and security.

This project focuses on testing the peer-to-peer communication aspects of the Starknet network, with a particular emphasis on conformance, performance, and resilience tests.

## Purpose

The main purposes of these tests are:
Expand Down Expand Up @@ -59,25 +53,6 @@ The project uses environment variables for configuration, which are defined in t

[More info](#environment-variables)

## Environment Variables

- `TARGET_PEER_ADDRESS`: The address of the target Starknet node to connect to for testing.
- `DEFAULT_TEST_TIMEOUT`: The default timeout for tests.
- `SYNTHETIC_LISTEN_ADDRS`: The listen addresses for the synthetic node.
- `NETWORK_NAME`: The name of the Starknet network being tested.

## Synthetic Node

The project implements a synthetic node in `tools/synthetic_node.go`. This synthetic node is used to simulate a Starknet node for testing purposes. It provides capabilities such as:

- Connecting to a target Starknet node
- Requesting block headers
- ...
- ...
- ...

The synthetic node is a key component in our testing infrastructure, allowing us to interact with the Starknet network in a controlled manner.

## Running Tests

Before running the tests, ensure that your environment is properly configured:
Expand Down Expand Up @@ -113,24 +88,6 @@ The following environment variables are available for configuration:
- `SYNTHETIC_LISTEN_ADDRS`: The listen addresses for the synthetic node (default: "/ip4/0.0.0.0/tcp/0")
- `NETWORK_NAME`: The name of the Starknet network being tested (default: "sepolia")

You can set these variables in your shell before running the tests to override the default values.

- To run all tests:
```
go test ./tests/...
```
For verbose output:
```
go test -v ./tests/...
```

- To run specific test categories:
```
go test ./tests/conformance
go test ./tests/performance
```

Note: Some tests may require additional setup or configuration. Please check the output and individual test files for any specific requirements.

Note: For performance tests, you may need to increase the default timeout. Use the -timeout flag, e.g., `go test -timeout 5m ./tests/performance`

Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"fmt"
"os"
"strings"
"time"
Expand All @@ -20,6 +21,7 @@ func init() {
var err error
DefaultTestTimeout, err = time.ParseDuration(timeoutStr)
if err != nil {
fmt.Printf("Error parsing DEFAULT_TEST_TIMEOUT: %v. Defaulting to 30 seconds.\n", err)
DefaultTestTimeout = 30 * time.Second
}

Expand Down
3 changes: 0 additions & 3 deletions src/lib.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/protocol/mod.rs

This file was deleted.

73 changes: 0 additions & 73 deletions src/protocol/starknet.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/tests/mod.rs

This file was deleted.

10 changes: 0 additions & 10 deletions src/tests/tests_p2p.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/tools/mod.rs

This file was deleted.

18 changes: 0 additions & 18 deletions src/tools/synthetic_node.rs

This file was deleted.

4 changes: 1 addition & 3 deletions tests/conformance/getBlock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"starknet-p2p-tests/config"
"starknet-p2p-tests/protocol/p2p/starknet/spec"
"starknet-p2p-tests/protocol/p2p/utils"
synthetic_node "starknet-p2p-tests/tools"
"testing"
"time"
Expand Down Expand Up @@ -53,8 +52,7 @@ func runBlockHeaderTest(t *testing.T, tc blockHeaderTestCase) {
}

func setupSyntheticNode(t *testing.T) (*synthetic_node.SyntheticNode, error) {
logger := &utils.TestSimpleLogger{Logger: t.Logf}
syntheticNode, err := synthetic_node.New(context.Background(), logger)
syntheticNode, err := synthetic_node.New(context.Background())
if err != nil {
return nil, fmt.Errorf("failed to create synthetic node: %w", err)
}
Expand Down
4 changes: 1 addition & 3 deletions tests/performance/getBlocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"starknet-p2p-tests/config"
"starknet-p2p-tests/protocol/p2p/utils"
synthetic_node "starknet-p2p-tests/tools"
"strings"
"sync"
Expand Down Expand Up @@ -119,8 +118,7 @@ func runPerformanceTest(t *testing.T, peerCount int) LatencyStats {
}

func simulatePeer(t *testing.T, ctx context.Context, peerIndex, totalPeers int) ([]float64, int, float64, map[string]int) {
logger := &utils.TestSimpleLogger{Logger: t.Logf}
syntheticNode, err := synthetic_node.New(ctx, logger)
syntheticNode, err := synthetic_node.New(ctx)
require.NoError(t, err, "Failed to create synthetic node")
defer syntheticNode.Close()

Expand Down
42 changes: 25 additions & 17 deletions tools/synthetic_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package synthetic_node
import (
"context"
"crypto/rand"
"fmt"
"errors"
"iter"
"log"
"os"
"starknet-p2p-tests/config"
"starknet-p2p-tests/protocol/p2p/starknet"
"starknet-p2p-tests/protocol/p2p/starknet/spec"
Expand All @@ -22,14 +24,18 @@ import (
type SyntheticNode struct {
Host host.Host
StarknetClient *starknet.Client
logger *utils.TestSimpleLogger
logger utils.SimpleLogger
targetPeer peer.ID
}

func New(ctx context.Context, logger *utils.TestSimpleLogger) (*SyntheticNode, error) {
func New(ctx context.Context) (*SyntheticNode, error) {
stdLogger := log.New(os.Stdout, "[SYNTHETIC-NODE] ", log.Ldate|log.Ltime|log.Lshortfile)
logger := &utils.TestSimpleLogger{Logger: stdLogger.Printf}

priv, _, err := crypto.GenerateEd25519Key(rand.Reader)
if err != nil {
return nil, fmt.Errorf("failed to generate key: %w", err)
logger.Errorw("Failed to generate key", "error", err)
return nil, errors.New("failed to generate key")
}

opts := []libp2p.Option{
Expand All @@ -39,7 +45,8 @@ func New(ctx context.Context, logger *utils.TestSimpleLogger) (*SyntheticNode, e

h, err := libp2p.New(opts...)
if err != nil {
return nil, fmt.Errorf("failed to create libp2p node: %w", err)
logger.Errorw("Failed to create libp2p node", "error", err)
return nil, errors.New("failed to create libp2p node")
}

logger.Infow("Created new synthetic node", "address", h.Addrs(), "id", h.ID())
Expand All @@ -53,12 +60,14 @@ func New(ctx context.Context, logger *utils.TestSimpleLogger) (*SyntheticNode, e
func (sn *SyntheticNode) Connect(ctx context.Context, targetAddress string) error {
targetPeerInfo, err := ParsePeerAddress(targetAddress)
if err != nil {
return fmt.Errorf("failed to parse peer address: %w", err)
sn.logger.Errorw("Failed to parse peer address", "error", err, "address", targetAddress)
return errors.New("failed to parse peer address")
}

sn.logger.Infow("Connecting to peer: ", "address", targetAddress)
sn.logger.Infow("Connecting to peer", "address", targetAddress)
if err := sn.Host.Connect(ctx, targetPeerInfo); err != nil {
return fmt.Errorf("failed to connect to target peer: %w", err)
sn.logger.Errorw("Failed to connect to target peer", "error", err, "address", targetAddress)
return errors.New("failed to connect to target peer")
}

sn.targetPeer = targetPeerInfo.ID
Expand All @@ -84,14 +93,12 @@ func (sn *SyntheticNode) RequestBlockHeaders(ctx context.Context, startBlock uin
Step: stepValue,
}

sn.logger.Infow("Requesting block headers",
"start", startBlock,
"limit", limit,
"step", stepValue)
sn.logger.Infow("Requesting block headers", "start", startBlock, "limit", limit, "step", stepValue)

headersIt, err := sn.StarknetClient.RequestBlockHeaders(ctx, &spec.BlockHeadersRequest{Iteration: iteration})
if err != nil {
return nil, fmt.Errorf("failed to request block headers:", err)
sn.logger.Errorw("Failed to request block headers", "error", err)
return nil, errors.New("failed to request block headers")
}

var headers []*spec.BlockHeadersResponse
Expand All @@ -103,10 +110,11 @@ func (sn *SyntheticNode) RequestBlockHeaders(ctx context.Context, startBlock uin
}

func (sn *SyntheticNode) RequestEvents(ctx context.Context, req *spec.EventsRequest) (iter.Seq[*spec.EventsResponse], error) {
sn.logger.Infow("Requesting events: %+v", req)
sn.logger.Infow("Requesting events", "request", req)
events, err := sn.StarknetClient.RequestEvents(ctx, req)
if err != nil {
return nil, fmt.Errorf("failed to request events: %w", err)
sn.logger.Errorw("Failed to request events", "error", err)
return nil, errors.New("failed to request events")
}
return events, nil
}
Expand All @@ -122,12 +130,12 @@ func (sn *SyntheticNode) Close() error {
func ParsePeerAddress(address string) (peer.AddrInfo, error) {
maddr, err := multiaddr.NewMultiaddr(address)
if err != nil {
return peer.AddrInfo{}, fmt.Errorf("invalid multiaddr: %w", err)
return peer.AddrInfo{}, errors.New("invalid multiaddr")
}

addrInfo, err := peer.AddrInfoFromP2pAddr(maddr)
if err != nil {
return peer.AddrInfo{}, fmt.Errorf("invalid peer address: %w", err)
return peer.AddrInfo{}, errors.New("invalid peer address")
}

return *addrInfo, nil
Expand Down

0 comments on commit ec2f145

Please sign in to comment.