-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dispatcher] Add method to send
AttestBatch
request to nodes (#664)
- Loading branch information
Showing
5 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package mock | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Layr-Labs/eigenda/api/grpc/node" | ||
"github.com/stretchr/testify/mock" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
type MockNodeDispersalClient struct { | ||
mock.Mock | ||
} | ||
|
||
var _ node.DispersalClient = (*MockNodeDispersalClient)(nil) | ||
|
||
func NewMockDispersalClient() *MockNodeDispersalClient { | ||
return &MockNodeDispersalClient{} | ||
} | ||
|
||
func (m *MockNodeDispersalClient) StoreChunks(ctx context.Context, in *node.StoreChunksRequest, opts ...grpc.CallOption) (*node.StoreChunksReply, error) { | ||
args := m.Called() | ||
return args.Get(0).(*node.StoreChunksReply), args.Error(1) | ||
} | ||
|
||
func (m *MockNodeDispersalClient) StoreBlobs(ctx context.Context, in *node.StoreBlobsRequest, opts ...grpc.CallOption) (*node.StoreBlobsReply, error) { | ||
args := m.Called() | ||
return args.Get(0).(*node.StoreBlobsReply), args.Error(1) | ||
} | ||
|
||
func (m *MockNodeDispersalClient) AttestBatch(ctx context.Context, in *node.AttestBatchRequest, opts ...grpc.CallOption) (*node.AttestBatchReply, error) { | ||
args := m.Called() | ||
return args.Get(0).(*node.AttestBatchReply), args.Error(1) | ||
} | ||
|
||
func (m *MockNodeDispersalClient) NodeInfo(ctx context.Context, in *node.NodeInfoRequest, opts ...grpc.CallOption) (*node.NodeInfoReply, error) { | ||
args := m.Called() | ||
return args.Get(0).(*node.NodeInfoReply), args.Error(1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package dispatcher_test | ||
|
||
import ( | ||
"context" | ||
"math/big" | ||
"testing" | ||
"time" | ||
|
||
grpcMock "github.com/Layr-Labs/eigenda/api/grpc/mock" | ||
"github.com/Layr-Labs/eigenda/api/grpc/node" | ||
"github.com/Layr-Labs/eigenda/common" | ||
"github.com/Layr-Labs/eigenda/core" | ||
"github.com/Layr-Labs/eigenda/disperser" | ||
"github.com/Layr-Labs/eigenda/disperser/batcher" | ||
dispatcher "github.com/Layr-Labs/eigenda/disperser/batcher/grpc" | ||
"github.com/consensys/gnark-crypto/ecc/bn254" | ||
"github.com/consensys/gnark-crypto/ecc/bn254/fp" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func newDispatcher(t *testing.T, config *dispatcher.Config) disperser.Dispatcher { | ||
loggerConfig := common.DefaultLoggerConfig() | ||
logger, err := common.NewLogger(loggerConfig) | ||
assert.NoError(t, err) | ||
metrics := batcher.NewMetrics("9091", logger) | ||
return dispatcher.NewDispatcher(config, logger, metrics.DispatcherMetrics) | ||
} | ||
|
||
func TestSendAttestBatchRequest(t *testing.T) { | ||
dispatcher := newDispatcher(t, &dispatcher.Config{ | ||
Timeout: 5 * time.Second, | ||
}) | ||
nodeClient := grpcMock.NewMockDispersalClient() | ||
var X, Y fp.Element | ||
X = *X.SetBigInt(big.NewInt(1)) | ||
Y = *Y.SetBigInt(big.NewInt(2)) | ||
signature := &core.Signature{ | ||
G1Point: &core.G1Point{ | ||
G1Affine: &bn254.G1Affine{ | ||
X: X, | ||
Y: Y, | ||
}, | ||
}, | ||
} | ||
sigBytes := signature.Bytes() | ||
nodeClient.On("AttestBatch").Return(&node.AttestBatchReply{ | ||
Signature: sigBytes[:], | ||
}, nil) | ||
sigReply, err := dispatcher.SendAttestBatchRequest(context.Background(), nodeClient, [][32]byte{{1}}, &core.BatchHeader{ | ||
ReferenceBlockNumber: 10, | ||
BatchRoot: [32]byte{1}, | ||
}, &core.IndexedOperatorInfo{ | ||
PubkeyG1: nil, | ||
PubkeyG2: nil, | ||
Socket: "localhost:8080", | ||
}) | ||
assert.NoError(t, err) | ||
assert.Equal(t, signature, sigReply) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters