Skip to content

Commit

Permalink
fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anupsv committed Sep 20, 2024
1 parent 9975ee9 commit 7dec6cb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 129 deletions.
28 changes: 18 additions & 10 deletions e2e/server_fuzz_test.go
Original file line number Diff line number Diff line change
@@ -1,53 +1,61 @@
package e2e_test

import (
"fmt"
"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"
"unicode"
)

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

func FuzzProxyClientServerIntegration(f *testing.F) {
if !runFuzzTests {
f.Skip("Skipping test as FUZZ env var not set")
}

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

addUnicodeTestCases(f)

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++ {
// 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 41 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 !runFuzzTests {
f.Skip("Skipping test as FUZZ env var not set")
}

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

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

Expand Down
132 changes: 13 additions & 119 deletions e2e/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@ package e2e
import (
"context"
"fmt"
"os"
"testing"
"time"
"unicode"

"github.com/Layr-Labs/eigenda-proxy/metrics"
"github.com/Layr-Labs/eigenda-proxy/server"
"github.com/Layr-Labs/eigenda-proxy/store"
"github.com/Layr-Labs/eigenda/api/clients"
oplog "github.com/ethereum-optimism/optimism/op-service/log"
opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics"
"github.com/ethereum/go-ethereum/log"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
"golang.org/x/exp/rand"

oplog "github.com/ethereum-optimism/optimism/op-service/log"
opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics"
"os"
"time"

"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -86,78 +82,16 @@ func createS3Config(eigendaCfg server.Config) server.CLIConfig {
}
}

func TestSuiteConfig(t *testing.T, 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 TB interface {
Helper()
Log(args ...interface{})
Error(args ...interface{})
Fatal(args ...interface{})
Errorf(format string, args ...interface{})
FailNow()
}

func TestSuiteConfigF(t *testing.F, testCfg *Cfg) server.CLIConfig {
func TestSuiteConfig(t TB, testCfg *Cfg) server.CLIConfig {
// load signer key from environment
pk := os.Getenv(privateKey)
if pk == "" && !testCfg.UseMemory {
Expand Down Expand Up @@ -234,47 +168,7 @@ type TestSuite struct {
Server *server.Server
}

func CreateTestSuite(t *testing.T, testSuiteCfg server.CLIConfig) (TestSuite, func()) {
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 CreateTestSuiteF(t *testing.F, testSuiteCfg server.CLIConfig) (TestSuite, func()) {

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
}
}

func CreateTestSuite(t TB, testSuiteCfg server.CLIConfig) (TestSuite, func()) {
log := oplog.NewLogger(os.Stdout, oplog.CLIConfig{
Level: log.LevelDebug,
Format: oplog.FormatLogFmt,
Expand Down

0 comments on commit 7dec6cb

Please sign in to comment.