Skip to content

Commit

Permalink
lint and fix fuzz test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
anupsv committed Dec 19, 2024
1 parent 5e72950 commit acf83a4
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 65 deletions.
2 changes: 1 addition & 1 deletion e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
var (
runTestnetIntegrationTests bool // holesky tests
runIntegrationTests bool // memstore tests
runFuzzTests bool
runFuzzTests bool
)

// ParseEnv ... reads testing cfg fields. Go test flags don't work for this library due to the dependency on Optimism's E2E framework
Expand Down
72 changes: 33 additions & 39 deletions e2e/server_fuzz_test.go
Original file line number Diff line number Diff line change
@@ -1,51 +1,45 @@
package e2e_test

import (
"fmt"
"github.com/stretchr/testify/assert"

"github.com/Layr-Labs/eigenda-proxy/client"
"github.com/Layr-Labs/eigenda-proxy/e2e"
"testing"
"unicode"
)

func addAllUnicodeTestCases(f *testing.F) {
// FuzzProxyClientServerIntegrationAndOpClientKeccak256MalformedInputs will fuzz the proxy client server integration
// and op client keccak256 with malformed inputs. This is never meant to be fuzzed with EigenDA.
func FuzzProxyClientServerIntegration(f *testing.F) {
if !runFuzzTests {
f.Skip("Skipping test as FUZZ env var not set")
}

tsConfig := e2e.TestSuiteConfig(e2e.TestConfig(useMemory()))
ts, kill := e2e.CreateTestSuite(tsConfig)

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.Add([]byte(string(r))) // Add each printable Unicode character as a seed
}
}
}

// FuzzProxyClientServerIntegrationAndOpClientKeccak256MalformedInputs will fuzz the proxy client server integration
// and op client keccak256 with malformed inputs. This is never meant to be fuzzed with EigenDA.
//func FuzzProxyClientServerIntegrationAndOpClientKeccak256MalformedInputs(f *testing.F) {
// if !runFuzzTests {
// f.Skip("Skipping test as FUZZ env var not set")
// }
//
// testCfg := e2e.TestConfig(true)
// testCfg.UseKeccak256ModeS3 = true
// tsConfig := e2e.TestSuiteConfig(testCfg)
// ts, kill := e2e.CreateTestSuite(tsConfig)
// defer kill()
//
// // Add each printable Unicode character as a seed
// addAllUnicodeTestCases(f)
//
// cfg := &client.Config{
// URL: ts.Address(),
// }
// daClient := client.New(cfg)
// daClientPcFalse := op_plasma.NewDAClient(ts.Address(), false, false)
//
// // seed and data are expected. `seed` value is seed: {rune} and data is the one with the random byte(s)
// f.Fuzz(func(t *testing.T, _ string, data []byte) {
//
// _, err := daClient.SetData(ts.Ctx, data)
// require.NoError(t, err)
//
// _, 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()))
// }
// })
//}
cfg := &client.Config{
URL: ts.Address(),
}

daClient := client.New(cfg)

// seed and data are expected. `seed` value is seed: {rune} and data is the one with the random byte(s)
f.Fuzz(func(t *testing.T, data []byte) {
_, err := daClient.SetData(ts.Ctx, data)
assert.NoError(t, err)
if err != nil {
t.Errorf("Failed to set data: %v", err)
}
})

f.Cleanup(kill)

}
53 changes: 29 additions & 24 deletions e2e/server_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package e2e_test

import (
"strings"
"testing"
"time"

"github.com/Layr-Labs/eigenda-proxy/client"
"github.com/Layr-Labs/eigenda-proxy/commitments"
"github.com/Layr-Labs/eigenda-proxy/common"
"github.com/Layr-Labs/eigenda-proxy/e2e"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"strings"
"testing"
"time"
)

func useMemory() bool {
Expand Down Expand Up @@ -39,9 +40,9 @@ with a concurrent S3 backend configured
*/
func TestOptimismClientWithGenericCommitment(t *testing.T) {

//if !runIntegrationTests && !runTestnetIntegrationTests {
// t.Skip("Skipping test as INTEGRATION or TESTNET env var not set")
//}
if !runIntegrationTests && !runTestnetIntegrationTests {
t.Skip("Skipping test as INTEGRATION or TESTNET env var not set")
}

t.Parallel()

Expand All @@ -57,29 +58,31 @@ func TestOptimismClientWithGenericCommitment(t *testing.T) {
// many unicode characters, single unicode character and an empty preimage. It then tries to get the data from the
// proxy server with empty byte, single byte and random string.
func TestProxyClientServerIntegration(t *testing.T) {

Check failure on line 60 in e2e/server_test.go

View workflow job for this annotation

GitHub Actions / Linter

TestProxyClientServerIntegration should call t.Parallel on the top level as well as its subtests (tparallel)
//if !runIntegrationTests && !runTestnetIntegrationTests {
// t.Skip("Skipping test as INTEGRATION or TESTNET env var not set")
//}
if !runIntegrationTests && !runTestnetIntegrationTests {
t.Skip("Skipping test as INTEGRATION or TESTNET env var not set")
}

t.Parallel()

tsConfig := e2e.TestSuiteConfig(e2e.TestConfig(useMemory()))
ts, kill := e2e.CreateTestSuite(tsConfig)
defer kill()
t.Cleanup(kill)

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

t.Run("single byte preimage set data case", func(t *testing.T) {
t.Parallel()
testPreimage := []byte{1} // single byte preimage
t.Log("Setting input data on proxy server...")
_, err := daClient.SetData(ts.Ctx, testPreimage)
require.NoError(t, err)
})

t.Run("unicode preimage set data case", func(t *testing.T) {
t.Parallel()
testPreimage := []byte("§§©ˆªªˆ˙√ç®∂§∞¶§ƒ¥√¨¥√¨¥ƒƒ©˙˜ø˜˜˜∫˙∫¥∫√†®®√稈¨˙ï") // many unicode characters
t.Log("Setting input data on proxy server...")
_, err := daClient.SetData(ts.Ctx, testPreimage)
Expand All @@ -93,13 +96,15 @@ func TestProxyClientServerIntegration(t *testing.T) {
})

t.Run("empty preimage set data case", func(t *testing.T) {
t.Parallel()
testPreimage := []byte("") // Empty preimage
t.Log("Setting input data on proxy server...")
_, err := daClient.SetData(ts.Ctx, testPreimage)
require.NoError(t, err)
})

t.Run("get data edge cases", func(t *testing.T) {
t.Parallel()
testCert := []byte("")
_, err := daClient.GetData(ts.Ctx, testCert)
require.Error(t, err)
Expand All @@ -112,7 +117,7 @@ func TestProxyClientServerIntegration(t *testing.T) {
assert.True(t, strings.Contains(err.Error(),
"400") && !isNilPtrDerefPanic(err.Error()))

testCert = []byte(e2e.RandBytes(10000))
testCert = e2e.RandBytes(10000)
_, err = daClient.GetData(ts.Ctx, testCert)
require.Error(t, err)
assert.True(t, strings.Contains(err.Error(), "400") && !isNilPtrDerefPanic(err.Error()))
Expand All @@ -121,9 +126,9 @@ func TestProxyClientServerIntegration(t *testing.T) {
}

func TestProxyClient(t *testing.T) {
//if !runIntegrationTests && !runTestnetIntegrationTests {
// t.Skip("Skipping test as INTEGRATION or TESTNET env var not set")
//}
if !runIntegrationTests && !runTestnetIntegrationTests {
t.Skip("Skipping test as INTEGRATION or TESTNET env var not set")
}

t.Parallel()

Expand All @@ -136,7 +141,7 @@ func TestProxyClient(t *testing.T) {
}
daClient := client.New(cfg)

testPreimage := []byte(e2e.RandBytes(100))
testPreimage := e2e.RandBytes(100)

t.Log("Setting input data on proxy server...")
blobInfo, err := daClient.SetData(ts.Ctx, testPreimage)
Expand All @@ -149,9 +154,9 @@ func TestProxyClient(t *testing.T) {
}

func TestProxyClientWriteRead(t *testing.T) {
//if !runIntegrationTests && !runTestnetIntegrationTests {
// t.Skip("Skipping test as INTEGRATION or TESTNET env var not set")
//}
if !runIntegrationTests && !runTestnetIntegrationTests {
t.Skip("Skipping test as INTEGRATION or TESTNET env var not set")
}

t.Parallel()

Expand All @@ -164,9 +169,9 @@ func TestProxyClientWriteRead(t *testing.T) {
}

func TestProxyWithMaximumSizedBlob(t *testing.T) {
//if !runIntegrationTests && !runTestnetIntegrationTests {
// t.Skip("Skipping test as INTEGRATION or TESTNET env var not set")
//}
if !runIntegrationTests && !runTestnetIntegrationTests {
t.Skip("Skipping test as INTEGRATION or TESTNET env var not set")
}

t.Parallel()

Expand All @@ -182,7 +187,7 @@ func TestProxyWithMaximumSizedBlob(t *testing.T) {
Ensure that proxy is able to write/read from a cache backend when enabled
*/
func TestProxyCaching(t *testing.T) {
//if !runIntegrationTests && !runTestnetIntegrationTests {
// if !runIntegrationTests && !runTestnetIntegrationTests {
// t.Skip("Skipping test as INTEGRATION or TESTNET env var not set")
//}

Expand All @@ -201,7 +206,7 @@ func TestProxyCaching(t *testing.T) {
}

func TestProxyCachingWithRedis(t *testing.T) {
//if !runIntegrationTests && !runTestnetIntegrationTests {
// if !runIntegrationTests && !runTestnetIntegrationTests {
// t.Skip("Skipping test as INTEGRATION or TESTNET env var not set")
//}

Expand All @@ -227,7 +232,7 @@ func TestProxyCachingWithRedis(t *testing.T) {

func TestProxyReadFallback(t *testing.T) {
// test can't be ran against holesky since read failure case can't be manually triggered
//if !runIntegrationTests || runTestnetIntegrationTests {
// if !runIntegrationTests || runTestnetIntegrationTests {
// t.Skip("Skipping test as INTEGRATION env var not set")
//}

Expand Down
1 change: 0 additions & 1 deletion e2e/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ func createS3Config(eigendaCfg server.Config) server.CLIConfig {
}

func TestSuiteConfig(testCfg *Cfg) server.CLIConfig {

// load signer key from environment
pk := os.Getenv(privateKey)
if pk == "" && !testCfg.UseMemory {
Expand Down

0 comments on commit acf83a4

Please sign in to comment.