Skip to content

Instantly share code, notes, and snippets.

@26lumineers
Last active July 4, 2022 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 26lumineers/1606f89327ea6c2a8fdab9b31c6bf47c to your computer and use it in GitHub Desktop.
Save 26lumineers/1606f89327ea6c2a8fdab9b31c6bf47c to your computer and use it in GitHub Desktop.
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,
})
}
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