From db773e13cee51d36584869e4f80ee28a878ac294 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 20 Sep 2024 20:57:39 +0000 Subject: [PATCH] add test and move accountId check location --- api/clients/disperser_client.go | 44 +++++++++++++++--------------- api/clients/eigenda_client_test.go | 12 ++++++++ 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/api/clients/disperser_client.go b/api/clients/disperser_client.go index 0b32ce921e..50fc4500b0 100644 --- a/api/clients/disperser_client.go +++ b/api/clients/disperser_client.go @@ -107,26 +107,11 @@ func (c *disperserClient) DisperseBlob(ctx context.Context, data []byte, quorums } func (c *disperserClient) DisperseBlobAuthenticated(ctx context.Context, data []byte, quorums []uint8) (*disperser.BlobStatus, []byte, error) { - - addr := fmt.Sprintf("%v:%v", c.config.Hostname, c.config.Port) - - dialOptions := c.getDialOptions() - conn, err := grpc.Dial(addr, dialOptions...) - + // first check if signer is valid + accountId, err := c.signer.GetAccountID() if err != nil { return nil, nil, err } - defer func() { _ = conn.Close() }() - - disperserClient := disperser_rpc.NewDisperserClient(conn) - ctxTimeout, cancel := context.WithTimeout(ctx, c.config.Timeout) - - defer cancel() - - stream, err := disperserClient.DisperseBlobAuthenticated(ctxTimeout) - if err != nil { - return nil, nil, fmt.Errorf("error while calling DisperseBlobAuthenticated: %w", err) - } quorumNumbers := make([]uint32, len(quorums)) for i, q := range quorums { @@ -139,17 +124,32 @@ func (c *disperserClient) DisperseBlobAuthenticated(ctx context.Context, data [] return nil, nil, fmt.Errorf("encountered an error to convert a 32-bytes into a valid field element, please use the correct format where every 32bytes(big-endian) is less than 21888242871839275222246405745257275088548364400416034343698204186575808495617, %w", err) } - accountId, err := c.signer.GetAccountID() - if err != nil { - return nil, nil, err - } - request := &disperser_rpc.DisperseBlobRequest{ Data: data, CustomQuorumNumbers: quorumNumbers, AccountId: accountId, } + addr := fmt.Sprintf("%v:%v", c.config.Hostname, c.config.Port) + + dialOptions := c.getDialOptions() + conn, err := grpc.Dial(addr, dialOptions...) + + if err != nil { + return nil, nil, err + } + defer func() { _ = conn.Close() }() + + disperserClient := disperser_rpc.NewDisperserClient(conn) + ctxTimeout, cancel := context.WithTimeout(ctx, c.config.Timeout) + + defer cancel() + + stream, err := disperserClient.DisperseBlobAuthenticated(ctxTimeout) + if err != nil { + return nil, nil, fmt.Errorf("error while calling DisperseBlobAuthenticated: %w", err) + } + // Send the initial request err = stream.Send(&disperser_rpc.AuthenticatedRequest{Payload: &disperser_rpc.AuthenticatedRequest_DisperseRequest{ DisperseRequest: request, diff --git a/api/clients/eigenda_client_test.go b/api/clients/eigenda_client_test.go index 41351158fc..41f8dd2013 100644 --- a/api/clients/eigenda_client_test.go +++ b/api/clients/eigenda_client_test.go @@ -11,6 +11,7 @@ import ( clientsmock "github.com/Layr-Labs/eigenda/api/clients/mock" "github.com/Layr-Labs/eigenda/api/grpc/common" grpcdisperser "github.com/Layr-Labs/eigenda/api/grpc/disperser" + "github.com/Layr-Labs/eigenda/core/auth" "github.com/Layr-Labs/eigenda/disperser" "github.com/ethereum/go-ethereum/log" "github.com/stretchr/testify/assert" @@ -505,3 +506,14 @@ func TestPutBlobTotalTimeout(t *testing.T) { require.Error(t, err) require.Nil(t, blobInfo) } + +func TestPutBlobNoopSigner(t *testing.T) { + config := clients.NewConfig("nohost", "noport", time.Second, false) + disperserClient := clients.NewDisperserClient(config, auth.NewLocalNoopSigner()) + + test := []byte("test") + test[0] = 0x00 // make sure the first byte of the requst is always 0 + quorums := []uint8{0} + _, _, err := disperserClient.DisperseBlobAuthenticated(context.Background(), test, quorums) + assert.EqualError(t, err, "noop signer cannot get accountID") +}