Skip to content

Commit

Permalink
Configure polynomial form in tests
Browse files Browse the repository at this point in the history
Signed-off-by: litt3 <102969658+litt3@users.noreply.github.com>
  • Loading branch information
litt3 committed Jan 14, 2025
1 parent d2d7bea commit 416906a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
24 changes: 12 additions & 12 deletions api/clients/eigenda_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type EigenDAClient struct {
Client DisperserClient
ethClient *ethclient.Client
edasmCaller *edasm.ContractEigenDAServiceManagerCaller
polynomialForm codecs.PolynomialForm
PolynomialForm codecs.PolynomialForm
}

var _ IEigenDAClient = &EigenDAClient{}
Expand Down Expand Up @@ -127,7 +127,7 @@ func NewEigenDAClient(log log.Logger, config EigenDAClientConfig) (*EigenDAClien
Client: disperserClient,
ethClient: ethClient,
edasmCaller: edasmCaller,
polynomialForm: polynomialForm,
PolynomialForm: polynomialForm,
}, nil
}

Expand Down Expand Up @@ -365,12 +365,12 @@ func (m *EigenDAClient) putBlob(ctxFinality context.Context, rawData []byte, res

// Close simply calls Close() on the wrapped disperserClient, to close the grpc connection to the disperser server.
// It is thread safe and can be called multiple times.
func (c *EigenDAClient) Close() error {
return c.Client.Close()
func (m *EigenDAClient) Close() error {
return m.Client.Close()
}

// getConfDeepBlockNumber returns the block number that is `depth` blocks behind the current block number.
func (m EigenDAClient) getConfDeepBlockNumber(ctx context.Context, depth uint64) (*big.Int, error) {
func (m *EigenDAClient) getConfDeepBlockNumber(ctx context.Context, depth uint64) (*big.Int, error) {
curBlockNumber, err := m.ethClient.BlockNumber(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get latest block number: %w", err)
Expand All @@ -387,7 +387,7 @@ func (m EigenDAClient) getConfDeepBlockNumber(ctx context.Context, depth uint64)
// batchIdConfirmedAtDepth checks if a batch ID has been confirmed at a certain depth.
// It returns true if the batch ID has been confirmed at the given depth, and false otherwise,
// or returns an error if any of the network calls fail.
func (m EigenDAClient) batchIdConfirmedAtDepth(ctx context.Context, batchId uint32, depth uint64) (bool, error) {
func (m *EigenDAClient) batchIdConfirmedAtDepth(ctx context.Context, batchId uint32, depth uint64) (bool, error) {
confDeepBlockNumber, err := m.getConfDeepBlockNumber(ctx, depth)
if err != nil {
return false, fmt.Errorf("failed to get confirmation deep block number: %w", err)
Expand All @@ -406,8 +406,8 @@ func (m EigenDAClient) batchIdConfirmedAtDepth(ctx context.Context, batchId uint
//
// If the system is configured to distribute blobs in Eval form, the returned bytes exactly match the blob bytes.
// If the system is configured to distribute blobs in Coeff form, the blob is FFTed before being returned
func (m EigenDAClient) blobToEncodedPayload(blob []byte) ([]byte, error) {
switch m.polynomialForm {
func (m *EigenDAClient) blobToEncodedPayload(blob []byte) ([]byte, error) {
switch m.PolynomialForm {
case codecs.Eval:
return blob, nil
case codecs.Coeff:
Expand All @@ -418,16 +418,16 @@ func (m EigenDAClient) blobToEncodedPayload(blob []byte) ([]byte, error) {

return encodedPayload, nil
default:
return nil, fmt.Errorf("unknown polynomial form: %v", m.polynomialForm)
return nil, fmt.Errorf("unknown polynomial form: %v", m.PolynomialForm)
}
}

// encodedPayloadToBlob accepts encoded payload bytes and converts them into a blob
//
// If the system is configured to distribute blobs in Eval form, the returned bytes exactly match the input bytes
// If the system is configured to distribute blobs in Coeff form, the encoded payload is IFFTed before being returned
func (m EigenDAClient) encodedPayloadToBlob(encodedPayload []byte) ([]byte, error) {
switch m.polynomialForm {
func (m *EigenDAClient) encodedPayloadToBlob(encodedPayload []byte) ([]byte, error) {
switch m.PolynomialForm {
case codecs.Eval:
return encodedPayload, nil
case codecs.Coeff:
Expand All @@ -438,6 +438,6 @@ func (m EigenDAClient) encodedPayloadToBlob(encodedPayload []byte) ([]byte, erro

return coeffPolynomial, nil
default:
return nil, fmt.Errorf("unknown polynomial form: %v", m.polynomialForm)
return nil, fmt.Errorf("unknown polynomial form: %v", m.PolynomialForm)
}
}
10 changes: 10 additions & 0 deletions api/clients/eigenda_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func TestPutRetrieveBlobIFFTSuccess(t *testing.T) {
WaitForFinalization: true,
},
Client: disperserClient,
PolynomialForm: codecs.Coeff,
}
expectedBlob := []byte("dc49e7df326cfb2e7da5cf68f263e1898443ec2e862350606e7dfbda55ad10b5d61ed1d54baf6ae7a86279c1b4fa9c49a7de721dacb211264c1f5df31bade51c")
blobInfo, err := eigendaClient.PutBlob(context.Background(), expectedBlob)
Expand Down Expand Up @@ -136,6 +137,7 @@ func TestPutRetrieveBlobIFFTNoDecodeSuccess(t *testing.T) {
WaitForFinalization: true,
},
Client: disperserClient,
PolynomialForm: codecs.Coeff,
}
expectedBlob := []byte("dc49e7df326cfb2e7da5cf68f263e1898443ec2e862350606e7dfbda55ad10b5d61ed1d54baf6ae7a86279c1b4fa9c49a7de721dacb211264c1f5df31bade51c")
blobInfo, err := eigendaClient.PutBlob(context.Background(), expectedBlob)
Expand Down Expand Up @@ -207,6 +209,7 @@ func TestPutRetrieveBlobNoIFFTSuccess(t *testing.T) {
WaitForFinalization: true,
},
Client: disperserClient,
PolynomialForm: codecs.Eval,
}
expectedBlob := []byte("dc49e7df326cfb2e7da5cf68f263e1898443ec2e862350606e7dfbda55ad10b5d61ed1d54baf6ae7a86279c1b4fa9c49a7de721dacb211264c1f5df31bade51c")
blobInfo, err := eigendaClient.PutBlob(context.Background(), expectedBlob)
Expand Down Expand Up @@ -238,6 +241,7 @@ func TestPutBlobFailDispersal(t *testing.T) {
WaitForFinalization: true,
},
Client: disperserClient,
PolynomialForm: codecs.Coeff,
}
blobInfo, err := eigendaClient.PutBlob(context.Background(), []byte("hello"))
require.Error(t, err)
Expand Down Expand Up @@ -270,6 +274,7 @@ func TestPutBlobFailureInsufficentSignatures(t *testing.T) {
WaitForFinalization: true,
},
Client: disperserClient,
PolynomialForm: codecs.Coeff,
}
blobInfo, err := eigendaClient.PutBlob(context.Background(), []byte("hello"))
require.Error(t, err)
Expand Down Expand Up @@ -302,6 +307,7 @@ func TestPutBlobFailureGeneral(t *testing.T) {
WaitForFinalization: true,
},
Client: disperserClient,
PolynomialForm: codecs.Coeff,
}
blobInfo, err := eigendaClient.PutBlob(context.Background(), []byte("hello"))
require.Error(t, err)
Expand Down Expand Up @@ -334,6 +340,7 @@ func TestPutBlobFailureUnknown(t *testing.T) {
WaitForFinalization: true,
},
Client: disperserClient,
PolynomialForm: codecs.Coeff,
}
blobInfo, err := eigendaClient.PutBlob(context.Background(), []byte("hello"))
require.Error(t, err)
Expand Down Expand Up @@ -368,6 +375,7 @@ func TestPutBlobFinalizationTimeout(t *testing.T) {
WaitForFinalization: true,
},
Client: disperserClient,
PolynomialForm: codecs.Coeff,
}
blobInfo, err := eigendaClient.PutBlob(context.Background(), []byte("hello"))
require.Error(t, err)
Expand Down Expand Up @@ -427,6 +435,7 @@ func TestPutBlobIndividualRequestTimeout(t *testing.T) {
WaitForFinalization: true,
},
Client: disperserClient,
PolynomialForm: codecs.Coeff,
}
blobInfo, err := eigendaClient.PutBlob(context.Background(), []byte("hello"))

Expand Down Expand Up @@ -489,6 +498,7 @@ func TestPutBlobTotalTimeout(t *testing.T) {
WaitForFinalization: true,
},
Client: disperserClient,
PolynomialForm: codecs.Coeff,
}
blobInfo, err := eigendaClient.PutBlob(context.Background(), []byte("hello"))

Expand Down

0 comments on commit 416906a

Please sign in to comment.