Skip to content

Commit

Permalink
add test and move accountId check location
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Sep 20, 2024
1 parent 61ccc51 commit db773e1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
44 changes: 22 additions & 22 deletions api/clients/disperser_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions api/clients/eigenda_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}

0 comments on commit db773e1

Please sign in to comment.