Skip to content

Commit

Permalink
adding fuzzer cases
Browse files Browse the repository at this point in the history
  • Loading branch information
anupsv committed Sep 20, 2024
1 parent 3e25323 commit e331cbd
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/fuzz-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: unit-tests

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
go-test:
outputs:
COVERAGE: ${{ steps.unit.outputs.coverage }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.21

- name: Install project dependencies
run: |
go mod download
- name: Run E2E Fuzz Tests
run: |
make e2e-fuzz-test
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ LDFLAGSSTRING +=-X main.Version=$(GIT_TAG)
LDFLAGS := -ldflags "$(LDFLAGSSTRING)"

E2ETEST = INTEGRATION=true go test -timeout 1m -v ./e2e -parallel 4 -deploy-config ../.devnet/devnetL1.json
E2EFUZZTEST = INTEGRATION=true go test -fuzz ./e2e -deploy-config ../.devnet/devnetL1.json -v -fuzztime=30m
HOLESKYTEST = TESTNET=true go test -timeout 50m -v ./e2e -parallel 4 -deploy-config ../.devnet/devnetL1.json

.PHONY: eigenda-proxy
Expand Down Expand Up @@ -56,6 +57,11 @@ e2e-test: stop-minio stop-redis run-minio run-redis
make stop-minio && \
make stop-redis

e2e-fuzz-test: stop-minio stop-redis run-minio run-redis
$(E2ETEST) && \
make stop-minio && \
make stop-redis

holesky-test: stop-minio stop-redis run-minio run-redis
$(HOLESKYTEST) && \
make stop-minio && \
Expand Down
66 changes: 66 additions & 0 deletions e2e/server_fuzz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package e2e_test

import (
"github.com/Layr-Labs/eigenda-proxy/client"
"github.com/Layr-Labs/eigenda-proxy/e2e"
op_plasma "github.com/ethereum-optimism/optimism/op-plasma"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
)

func FuzzProxyClientServerIntegration(f *testing.F) {
//if !runIntegrationTests && !runTestnetIntegrationTests {

Check failure on line 13 in e2e/server_fuzz_test.go

View workflow job for this annotation

GitHub Actions / Linter

commentFormatting: put a space between `//` and comment text (gocritic)
// f.Skip("Skipping test as INTEGRATION or TESTNET env var not set")
//}

testCfg := e2e.TestConfig(useMemory())
testCfg.UseKeccak256ModeS3 = true
tsConfig := e2e.TestSuiteConfigF(f, testCfg)
ts, kill := e2e.CreateTestSuiteF(f, tsConfig)
defer kill()

cfg := &client.Config{
URL: ts.Address(),
}
daClient := client.New(cfg)

// Add each printable Unicode character as a seed including ascii
//for r := rune(0); r <= unicode.MaxRune; r++ {

Check failure on line 29 in e2e/server_fuzz_test.go

View workflow job for this annotation

GitHub Actions / Linter

commentFormatting: put a space between `//` and comment text (gocritic)
// if unicode.IsPrint(r) {
// f.Add(fmt.Sprintf("seed: %s", string(r)), []byte(string(r))) // Add each printable Unicode character as a seed
// }
//}

f.Fuzz(func(t *testing.T, seed string, data []byte) {

Check failure on line 35 in e2e/server_fuzz_test.go

View workflow job for this annotation

GitHub Actions / Linter

unused-parameter: parameter 'seed' seems to be unused, consider removing or renaming it as _ (revive)
_, err := daClient.SetData(ts.Ctx, data)
require.NoError(t, err)
})
}

func FuzzOpClientKeccak256MalformedInputs(f *testing.F) {
if !runIntegrationTests || runTestnetIntegrationTests {
f.Skip("Skipping test as INTEGRATION var not set")
}

testCfg := e2e.TestConfig(useMemory())
testCfg.UseKeccak256ModeS3 = true
tsConfig := e2e.TestSuiteConfigF(f, testCfg)
ts, kill := e2e.CreateTestSuiteF(f, tsConfig)
defer kill()

daClientPcFalse := op_plasma.NewDAClient(ts.Address(), false, false)

// Fuzz the SetInput function with random data
// seed and data are expected. `seed` value is seed: {i} and data is the one with the random string
f.Fuzz(func(t *testing.T, seed string, data []byte) {

Check failure on line 56 in e2e/server_fuzz_test.go

View workflow job for this annotation

GitHub Actions / Linter

unused-parameter: parameter 'seed' seems to be unused, consider removing or renaming it as _ (revive)

_, err := daClientPcFalse.SetInput(ts.Ctx, data)
// should fail with proper error message as is now, and cannot contain panics or nils
if err != nil {
assert.True(t, !isNilPtrDerefPanic(err.Error()))
}

})

}
112 changes: 112 additions & 0 deletions e2e/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"testing"
"time"
"unicode"

"github.com/Layr-Labs/eigenda-proxy/metrics"
"github.com/Layr-Labs/eigenda-proxy/server"
Expand Down Expand Up @@ -156,6 +157,77 @@ func TestSuiteConfig(t *testing.T, testCfg *Cfg) server.CLIConfig {
return cfg
}

func TestSuiteConfigF(t *testing.F, testCfg *Cfg) server.CLIConfig {
// load signer key from environment
pk := os.Getenv(privateKey)
if pk == "" && !testCfg.UseMemory {
t.Fatal("SIGNER_PRIVATE_KEY environment variable not set")
}

// load node url from environment
ethRPC := os.Getenv(ethRPC)
if ethRPC == "" && !testCfg.UseMemory {
t.Fatal("ETHEREUM_RPC environment variable is not set")
}

var pollInterval time.Duration
if testCfg.UseMemory {
pollInterval = time.Second * 1
} else {
pollInterval = time.Minute * 1
}

eigendaCfg := server.Config{
ClientConfig: clients.EigenDAClientConfig{
RPC: holeskyDA,
StatusQueryTimeout: time.Minute * 45,
StatusQueryRetryInterval: pollInterval,
DisableTLS: false,
SignerPrivateKeyHex: pk,
},
EthRPC: ethRPC,
SvcManagerAddr: "0xD4A7E1Bd8015057293f0D0A557088c286942e84b", // incompatible with non holeskly networks
CacheDir: "../resources/SRSTables",
G1Path: "../resources/g1.point",
MaxBlobLength: "16mib",
G2PowerOfTauPath: "../resources/g2.point.powerOf2",
PutBlobEncodingVersion: 0x00,
MemstoreEnabled: testCfg.UseMemory,
MemstoreBlobExpiration: testCfg.Expiration,
EthConfirmationDepth: 0,
}

if testCfg.UseMemory {
eigendaCfg.ClientConfig.SignerPrivateKeyHex = "0000000000000000000100000000000000000000000000000000000000000000"
}

var cfg server.CLIConfig
switch {
case testCfg.UseKeccak256ModeS3:
cfg = createS3Config(eigendaCfg)

case testCfg.UseS3Caching:
eigendaCfg.CacheTargets = []string{"S3"}
cfg = createS3Config(eigendaCfg)

case testCfg.UseS3Fallback:
eigendaCfg.FallbackTargets = []string{"S3"}
cfg = createS3Config(eigendaCfg)

case testCfg.UseRedisCaching:
eigendaCfg.CacheTargets = []string{"redis"}
cfg = createRedisConfig(eigendaCfg)

default:
cfg = server.CLIConfig{
EigenDAConfig: eigendaCfg,
MetricsCfg: opmetrics.CLIConfig{},
}
}

return cfg
}

type TestSuite struct {
Ctx context.Context
Log log.Logger
Expand Down Expand Up @@ -195,6 +267,46 @@ func CreateTestSuite(t *testing.T, testSuiteCfg server.CLIConfig) (TestSuite, fu
}, kill
}

func CreateTestSuiteF(t *testing.F, testSuiteCfg server.CLIConfig) (TestSuite, func()) {

Check failure on line 270 in e2e/setup.go

View workflow job for this annotation

GitHub Actions / Linter

unnecessary leading newline (whitespace)

for r := rune(0); r <= unicode.MaxRune; r++ {
if unicode.IsPrint(r) {
t.Add(fmt.Sprintf("seed: %s", string(r)), []byte(string(r))) // Add each printable Unicode character as a seed
}
}

log := oplog.NewLogger(os.Stdout, oplog.CLIConfig{
Level: log.LevelDebug,
Format: oplog.FormatLogFmt,
Color: true,
}).New("role", svcName)

ctx := context.Background()
store, err := server.LoadStoreRouter(
ctx,
testSuiteCfg,
log,
)
require.NoError(t, err)
server := server.NewServer(host, 0, store, log, metrics.NoopMetrics)

t.Log("Starting proxy server...")
err = server.Start()
require.NoError(t, err)

kill := func() {
if err := server.Stop(); err != nil {
panic(err)
}
}

return TestSuite{
Ctx: ctx,
Log: log,
Server: server,
}, kill
}

func (ts *TestSuite) Address() string {
// read port from listener
port := ts.Server.Port()
Expand Down

0 comments on commit e331cbd

Please sign in to comment.