-
-
Save 26lumineers/1606f89327ea6c2a8fdab9b31c6bf47c to your computer and use it in GitHub Desktop.
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
func ClaimRewards(c *gin.Context) { | |
var address_id = c.PostForm("address_id") | |
error := model.ClaimRewards(address_id) | |
log.Println("address_id : ",address_id) | |
log.Printf("err : %v",error) | |
if error != nil { | |
c.JSON(http.StatusInternalServerError,gin.H{ | |
"message":"failed", | |
}) | |
c.JSON(http.StatusOK,gin.H{ | |
"message":address_id, | |
}) | |
} |
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
func TestClaim(t *testing.T) { | |
gin.SetMode(gin.TestMode) | |
addr := Address_ID{ | |
Address_id:"0x123DFPER321XCAAZ", | |
} | |
jsonStr ,_:= json.Marshal(addr) | |
res:=httptest.NewRecorder() | |
c,r := gin.CreateTestContext(res) | |
c.Request =httptest.NewRequest(http.MethodPost, "/claim",bytes.NewBuffer(jsonStr)) | |
c.Request.Header.Set("Content-Type", "application/x-www-form-urlencoded") | |
c.Request.ParseForm() | |
r.POST("/claim",ClaimRewards) | |
r.ServeHTTP(res,c.Request) | |
if status := res.Code; status != http.StatusOK { | |
t.Errorf("handler returned wrong status code: got %v want %v", | |
status, http.StatusOK) | |
} | |
} | |
type Address_ID struct { | |
Address_id string `json:"address_id"` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment