-
Notifications
You must be signed in to change notification settings - Fork 924
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
!feat(api/gateway): return txdata from submitPFB if it is present (#2329
) ## Overview Closes #2328
- Loading branch information
Showing
2 changed files
with
59 additions
and
5 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
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,48 @@ | ||
package gateway | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"errors" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
"github.com/stretchr/testify/require" | ||
|
||
stateMock "github.com/celestiaorg/celestia-node/nodebuilder/state/mocks" | ||
"github.com/celestiaorg/celestia-node/state" | ||
) | ||
|
||
func TestHandleSubmitPFB(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
mock := stateMock.NewMockModule(ctrl) | ||
handler := NewHandler(mock, nil, nil, nil) | ||
|
||
t.Run("partial response", func(t *testing.T) { | ||
txResponse := state.TxResponse{ | ||
Height: 1, | ||
TxHash: "hash", | ||
Codespace: "codespace", | ||
Code: 1, | ||
} | ||
// simulate core-app err, since it is not exported | ||
timedErr := errors.New("timed out waiting for tx to be included in a block") | ||
mock.EXPECT().SubmitPayForBlob(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). | ||
Return(&txResponse, timedErr) | ||
|
||
bs, err := json.Marshal(submitPFBRequest{}) | ||
require.NoError(t, err) | ||
httpreq := httptest.NewRequest("GET", "/", bytes.NewReader(bs)) | ||
respRec := httptest.NewRecorder() | ||
handler.handleSubmitPFB(respRec, httpreq) | ||
|
||
var resp state.TxResponse | ||
err = json.NewDecoder(respRec.Body).Decode(&resp) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, http.StatusPartialContent, respRec.Code) | ||
require.Equal(t, resp, txResponse) | ||
}) | ||
} |