Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Commit

Permalink
Debug siatest
Browse files Browse the repository at this point in the history
  • Loading branch information
MSevey committed Jul 13, 2018
1 parent cac126e commit bcdbd24
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 34 deletions.
6 changes: 3 additions & 3 deletions modules/renter/contractor/contractor.go
Expand Up @@ -155,11 +155,11 @@ func (c *Contractor) ContractByPublicKey(pk types.SiaPublicKey) (modules.RenterC
// CancelContract cancels the Contractor's contract by marking it !GoodForRenew
// and !GoodForUpload
func (c *Contractor) CancelContract(id types.FileContractID) error {
u := modules.ContractUtility{
return c.managedUpdateContractUtility(id, modules.ContractUtility{
GoodForRenew: false,
GoodForUpload: false,
}
return c.managedUpdateContractUtility(id, u)
Locked: true,
})
}

// Contracts returns the contracts formed by the contractor in the current
Expand Down
5 changes: 5 additions & 0 deletions modules/renter/contractor/contracts.go
Expand Up @@ -96,6 +96,11 @@ func (c *Contractor) managedMarkContractsUtility() error {
// Update utility fields for each contract.
for _, contract := range c.staticContracts.ViewAll() {
utility := func() (u modules.ContractUtility) {
// Record current utility of the contract
u.GoodForRenew = contract.Utility.GoodForRenew
u.GoodForUpload = contract.Utility.GoodForUpload
u.Locked = contract.Utility.Locked

// Start the contract in good standing if the utility wasn't
// locked.
if !u.Locked {
Expand Down
6 changes: 3 additions & 3 deletions node/api/client/renter.go
Expand Up @@ -12,12 +12,12 @@ import (
"github.com/NebulousLabs/Sia/types"
)

// RenterCancelContractPost uses the /renter/cancel/contract endpoint to cancel
// RenterContractCancelPost uses the /renter/contract/cancel endpoint to cancel
// a contract
func (c *Client) RenterCancelContractPost(id types.FileContractID) error {
func (c *Client) RenterContractCancelPost(id types.FileContractID) error {
values := url.Values{}
values.Set("id", id.String())
err := c.post("/renter/cancel/contract", values.Encode(), nil)
err := c.post("/renter/contract/cancel", values.Encode(), nil)
return err
}

Expand Down
6 changes: 3 additions & 3 deletions node/api/renter.go
Expand Up @@ -275,10 +275,10 @@ func (api *API) renterHandlerPOST(w http.ResponseWriter, req *http.Request, _ ht
WriteSuccess(w)
}

// renterContractClearHandler handles the API call to cancel a specific Renter contract.
func (api *API) renterContractClearHandler(w http.ResponseWriter, req *http.Request, _ httprouter.Params) {
// renterContractCancelHandler handles the API call to cancel a specific Renter contract.
func (api *API) renterContractCancelHandler(w http.ResponseWriter, req *http.Request, _ httprouter.Params) {
var fcid types.FileContractID
if err := fcid.LoadString(req.FormValue("ID")); err != nil {
if err := fcid.LoadString(req.FormValue("id")); err != nil {
return
}
err := api.renter.CancelContract(fcid)
Expand Down
2 changes: 1 addition & 1 deletion node/api/routes.go
Expand Up @@ -69,7 +69,7 @@ func (api *API) buildHTTPRoutes(requiredUserAgent string, requiredPassword strin
if api.renter != nil {
router.GET("/renter", api.renterHandlerGET)
router.POST("/renter", RequirePassword(api.renterHandlerPOST, requiredPassword))
router.GET("/renter/contract/cancel", api.renterContractClearHandler)
router.POST("/renter/contract/cancel", RequirePassword(api.renterContractCancelHandler, requiredPassword))
router.GET("/renter/contracts", api.renterContractsHandler)
router.GET("/renter/downloads", api.renterDownloadsHandler)
router.POST("/renter/downloads/clear", RequirePassword(api.renterClearDownloadsHandler, requiredPassword))
Expand Down
47 changes: 23 additions & 24 deletions siatest/renter/renter_test.go
Expand Up @@ -90,36 +90,35 @@ func testCancelContract(t *testing.T, tg *siatest.TestGroup) {
contract := rc.ActiveContracts[0]

// Cancel Contract
if err := r.RenterCancelContractPost(contract.ID); err != nil {
if err := r.RenterContractCancelPost(contract.ID); err != nil {
t.Fatal(err)
}

// Mine block to trigger threadedContractMaintenance
m := tg.Miners()[0]
if err := m.MineBlock(); err != nil {
t.Fatal(err)
}
tg.Sync()

// Check that Contract is now in inactive contracts and no longer in Active contracts
rc, err = r.RenterInactiveContractsGet()
if err != nil {
t.Fatal(err)
}
for _, c := range rc.ActiveContracts {
if c.ID == contract.ID {
t.Fatal("Contract not cancelled, contract found in Active Contracts")
err = build.Retry(200, 100*time.Millisecond, func() error {
// Check that Contract is now in inactive contracts and no longer in Active contracts
rc, err = r.RenterInactiveContractsGet()
if err != nil {
t.Fatal(err)
}
}
i := 1
for _, c := range rc.InactiveContracts {
if c.ID == contract.ID {
break
for _, c := range rc.ActiveContracts {
if c.ID == contract.ID {
return errors.New("Contract not cancelled, contract found in Active Contracts")
}
}
if i == len(rc.InactiveContracts) {
t.Fatal("Contract not found in Inactive Contracts")
i := 1
for _, c := range rc.InactiveContracts {
if c.ID == contract.ID {
break
}
if i == len(rc.InactiveContracts) {
return errors.New("Contract not found in Inactive Contracts")
}
i++
}
i++
return nil
})
if err != nil {
t.Fatal(err)
}
}

Expand Down

0 comments on commit bcdbd24

Please sign in to comment.