|
1 | | -package blob |
| 1 | +package blob_test |
2 | 2 |
|
3 | 3 | import ( |
4 | 4 | "context" |
5 | 5 | "net/http/httptest" |
6 | 6 | "testing" |
7 | 7 |
|
8 | | - "github.com/filecoin-project/go-jsonrpc" |
| 8 | + fcjsonrpc "github.com/filecoin-project/go-jsonrpc" |
| 9 | + "github.com/stretchr/testify/mock" |
9 | 10 | "github.com/stretchr/testify/require" |
10 | 11 |
|
11 | 12 | libshare "github.com/celestiaorg/go-square/v3/share" |
12 | | -) |
13 | | - |
14 | | -type mockBlobModule struct { |
15 | | - submitHeight uint64 |
16 | | - submitErr error |
17 | | - |
18 | | - blob *Blob |
19 | | - proof *Proof |
20 | | - included bool |
21 | | - commitProof *CommitmentProof |
22 | | -} |
23 | | - |
24 | | -func (m *mockBlobModule) Submit(_ context.Context, _ []*Blob, _ *SubmitOptions) (uint64, error) { |
25 | | - return m.submitHeight, m.submitErr |
26 | | -} |
27 | | - |
28 | | -func (m *mockBlobModule) Get(_ context.Context, _ uint64, _ libshare.Namespace, _ Commitment) (*Blob, error) { |
29 | | - return m.blob, nil |
30 | | -} |
31 | | - |
32 | | -func (m *mockBlobModule) GetAll(_ context.Context, _ uint64, _ []libshare.Namespace) ([]*Blob, error) { |
33 | | - return []*Blob{m.blob}, nil |
34 | | -} |
35 | 13 |
|
36 | | -func (m *mockBlobModule) GetProof(_ context.Context, _ uint64, _ libshare.Namespace, _ Commitment) (*Proof, error) { |
37 | | - return m.proof, nil |
38 | | -} |
39 | | - |
40 | | -func (m *mockBlobModule) Included(_ context.Context, _ uint64, _ libshare.Namespace, _ *Proof, _ Commitment) (bool, error) { |
41 | | - return m.included, nil |
42 | | -} |
43 | | - |
44 | | -func (m *mockBlobModule) GetCommitmentProof(_ context.Context, _ uint64, _ libshare.Namespace, _ []byte) (*CommitmentProof, error) { |
45 | | - return m.commitProof, nil |
46 | | -} |
47 | | - |
48 | | -func (m *mockBlobModule) Subscribe(_ context.Context, _ libshare.Namespace) (<-chan *SubscriptionResponse, error) { |
49 | | - ch := make(chan *SubscriptionResponse, 1) |
50 | | - ch <- &SubscriptionResponse{Height: 11} |
51 | | - close(ch) |
52 | | - return ch, nil |
53 | | -} |
| 14 | + blob "github.com/evstack/ev-node/pkg/da/jsonrpc" |
| 15 | + "github.com/evstack/ev-node/pkg/da/jsonrpc/mocks" |
| 16 | +) |
54 | 17 |
|
55 | 18 | func newTestServer(t *testing.T, module any) *httptest.Server { |
56 | 19 | t.Helper() |
57 | | - rpc := jsonrpc.NewServer() |
| 20 | + rpc := fcjsonrpc.NewServer() |
58 | 21 | rpc.Register("blob", module) |
59 | 22 | return httptest.NewServer(rpc) |
60 | 23 | } |
61 | 24 |
|
62 | 25 | func TestClient_CallsAreForwarded(t *testing.T) { |
63 | 26 | ns := libshare.MustNewV0Namespace([]byte("namespace")) |
64 | | - blb, err := NewBlobV0(ns, []byte("data")) |
| 27 | + blb, err := blob.NewBlobV0(ns, []byte("data")) |
65 | 28 | require.NoError(t, err) |
66 | 29 |
|
67 | | - module := &mockBlobModule{ |
68 | | - submitHeight: 7, |
69 | | - blob: blb, |
70 | | - proof: &Proof{}, |
71 | | - included: true, |
72 | | - commitProof: &CommitmentProof{}, |
73 | | - } |
| 30 | + module := mocks.NewMockBlobModule(t) |
| 31 | + module.On("Submit", mock.Anything, mock.Anything, mock.Anything).Return(uint64(7), nil) |
| 32 | + module.On("Get", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(blb, nil) |
| 33 | + module.On("GetAll", mock.Anything, mock.Anything, mock.Anything).Return([]*blob.Blob{blb}, nil) |
| 34 | + module.On("GetProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&blob.Proof{}, nil) |
| 35 | + module.On("Included", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(true, nil) |
| 36 | + module.On("GetCommitmentProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&blob.CommitmentProof{}, nil) |
| 37 | + |
74 | 38 | srv := newTestServer(t, module) |
75 | 39 | t.Cleanup(srv.Close) |
76 | 40 |
|
77 | | - client, err := NewClient(context.Background(), srv.URL, "", "") |
| 41 | + client, err := blob.NewClient(context.Background(), srv.URL, "", "") |
78 | 42 | require.NoError(t, err) |
79 | 43 | t.Cleanup(client.Close) |
80 | 44 |
|
81 | | - height, err := client.Blob.Submit(context.Background(), []*Blob{blb}, nil) |
| 45 | + height, err := client.Blob.Submit(context.Background(), []*blob.Blob{blb}, nil) |
82 | 46 | require.NoError(t, err) |
83 | 47 | require.Equal(t, uint64(7), height) |
84 | 48 |
|
|
0 commit comments