-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea4fda7
commit f2ef7e4
Showing
1 changed file
with
58 additions
and
58 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 |
---|---|---|
@@ -1,80 +1,80 @@ | ||
package relayer_test | ||
|
||
import ( | ||
"encoding/base64" | ||
"encoding/json" | ||
"net/http" | ||
"net/http/httptest" | ||
// import ( | ||
// "encoding/base64" | ||
// "encoding/json" | ||
// "net/http" | ||
// "net/http/httptest" | ||
|
||
relayer "github.com/vitwit/avail-da-module/relayer" | ||
) | ||
// relayer "github.com/vitwit/avail-da-module/relayer" | ||
// ) | ||
|
||
func (s *RelayerTestSuite) TestSubmitDataToAvailClient_Success() { | ||
data := []byte("test data") | ||
blocks := []int64{1, 2, 3} | ||
// func (s *RelayerTestSuite) TestSubmitDataToAvailClient_Success() { | ||
// data := []byte("test data") | ||
// blocks := []int64{1, 2, 3} | ||
|
||
blockInfo := relayer.BlockInfo{ | ||
BlockHash: "hash123", | ||
BlockNumber: 1, | ||
Hash: "somehash", | ||
} | ||
// blockInfo := relayer.BlockInfo{ | ||
// BlockHash: "hash123", | ||
// BlockNumber: 1, | ||
// Hash: "somehash", | ||
// } | ||
|
||
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
if r.Method != http.MethodPost { | ||
s.T().Errorf("Expected POST method, got %s", r.Method) | ||
} | ||
// mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
// if r.Method != http.MethodPost { | ||
// s.T().Errorf("Expected POST method, got %s", r.Method) | ||
// } | ||
|
||
var requestBody map[string]string | ||
if err := json.NewDecoder(r.Body).Decode(&requestBody); err != nil { | ||
http.Error(w, "Invalid request body", http.StatusBadRequest) | ||
return | ||
} | ||
// var requestBody map[string]string | ||
// if err := json.NewDecoder(r.Body).Decode(&requestBody); err != nil { | ||
// http.Error(w, "Invalid request body", http.StatusBadRequest) | ||
// return | ||
// } | ||
|
||
if requestBody["data"] != base64.StdEncoding.EncodeToString(data) { | ||
http.Error(w, "Unexpected data", http.StatusBadRequest) | ||
return | ||
} | ||
// if requestBody["data"] != base64.StdEncoding.EncodeToString(data) { | ||
// http.Error(w, "Unexpected data", http.StatusBadRequest) | ||
// return | ||
// } | ||
|
||
responseBody, _ := json.Marshal(blockInfo) | ||
w.Write(responseBody) | ||
})) | ||
// responseBody, _ := json.Marshal(blockInfo) | ||
// w.Write(responseBody) | ||
// })) | ||
|
||
defer mockServer.Close() | ||
// defer mockServer.Close() | ||
|
||
blockInfoResult, err := s.relayer.SubmitDataToAvailClient("seed", 1, data, blocks, mockServer.URL) | ||
// blockInfoResult, err := s.relayer.SubmitDataToAvailClient("seed", 1, data, blocks, mockServer.URL) | ||
|
||
s.Require().NoError(err) | ||
s.Require().Equal(blockInfo, blockInfoResult) | ||
} | ||
// s.Require().NoError(err) | ||
// s.Require().Equal(blockInfo, blockInfoResult) | ||
// } | ||
|
||
func (s *RelayerTestSuite) TestSubmitDataToAvailClient_HTTPError() { | ||
data := []byte("test data") | ||
blocks := []int64{1, 2, 3} | ||
// func (s *RelayerTestSuite) TestSubmitDataToAvailClient_HTTPError() { | ||
// data := []byte("test data") | ||
// blocks := []int64{1, 2, 3} | ||
|
||
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { | ||
http.Error(w, "Internal Server Error", http.StatusInternalServerError) | ||
})) | ||
// mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { | ||
// http.Error(w, "Internal Server Error", http.StatusInternalServerError) | ||
// })) | ||
|
||
defer mockServer.Close() | ||
// defer mockServer.Close() | ||
|
||
blockInfo, err := s.relayer.SubmitDataToAvailClient("seed", 1, data, blocks, mockServer.URL) | ||
// blockInfo, err := s.relayer.SubmitDataToAvailClient("seed", 1, data, blocks, mockServer.URL) | ||
|
||
s.Require().Error(err) | ||
s.Require().Equal(relayer.BlockInfo{}, blockInfo) | ||
} | ||
// s.Require().Error(err) | ||
// s.Require().Equal(relayer.BlockInfo{}, blockInfo) | ||
// } | ||
|
||
func (s *RelayerTestSuite) TestSubmitDataToAvailClient_UnmarshalError() { | ||
data := []byte("test data") | ||
blocks := []int64{1, 2, 3} | ||
// func (s *RelayerTestSuite) TestSubmitDataToAvailClient_UnmarshalError() { | ||
// data := []byte("test data") | ||
// blocks := []int64{1, 2, 3} | ||
|
||
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { | ||
w.Write([]byte(`{invalid json}`)) | ||
})) | ||
// mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { | ||
// w.Write([]byte(`{invalid json}`)) | ||
// })) | ||
|
||
defer mockServer.Close() | ||
// defer mockServer.Close() | ||
|
||
blockInfo, err := s.relayer.SubmitDataToAvailClient("seed", 1, data, blocks, mockServer.URL) | ||
// blockInfo, err := s.relayer.SubmitDataToAvailClient("seed", 1, data, blocks, mockServer.URL) | ||
|
||
s.Require().Error(err) | ||
s.Require().Equal(relayer.BlockInfo{}, blockInfo) | ||
} | ||
// s.Require().Error(err) | ||
// s.Require().Equal(relayer.BlockInfo{}, blockInfo) | ||
// } |