Skip to content

Commit

Permalink
add better comment to GetFunds
Browse files Browse the repository at this point in the history
improve error handling of GetFunds on devnet env
  • Loading branch information
frrist committed Jun 13, 2019
1 parent f0fd8e4 commit 531dc1d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
3 changes: 2 additions & 1 deletion tools/fast/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type Environment interface {
// to remove a process from the environment in a clean way.
TeardownProcess(context.Context, *fast.Filecoin) error

// GetFunds retrieves a fixed amount of tokens from the environment.
// GetFunds retrieves a fixed amount of tokens from the environment to the
// Filecoin processes default wallet address.
GetFunds(context.Context, *fast.Filecoin) error
}
30 changes: 23 additions & 7 deletions tools/fast/environment/environment_devnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package environment
import (
"context"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -147,7 +148,10 @@ func (e *Devnet) TeardownProcess(ctx context.Context, p *fast.Filecoin) error {
return os.RemoveAll(p.Dir())
}

// GetFunds retrieves a fixed amount of tokens from an environment
// GetFunds retrieves a fixed amount of tokens from the environment to the
// Filecoin processes default wallet address.
// GetFunds will send a request to the Faucet, the amount of tokens returned and
// number of requests permitted is determined by the Faucet configuration.
func (e *Devnet) GetFunds(ctx context.Context, p *fast.Filecoin) error {
e.processesMu.Lock()
defer e.processesMu.Unlock()
Expand All @@ -172,15 +176,27 @@ func (e *Devnet) GetFunds(ctx context.Context, p *fast.Filecoin) error {
return err
}

msgcid := resp.Header.Get("Message-Cid")
mcid, err := cid.Decode(msgcid)
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
switch resp.StatusCode {
case 200:
msgcid := resp.Header.Get("Message-Cid")
mcid, err := cid.Decode(msgcid)
if err != nil {
return err
}

if _, err := p.MessageWait(ctx, mcid); err != nil {
return err
if _, err := p.MessageWait(ctx, mcid); err != nil {
return err
}
return nil
case 400:
return fmt.Errorf("Bad Request: %s", string(b))
case 429:
return fmt.Errorf("Rate Limit: %s", string(b))
default:
return fmt.Errorf("Unhandled Status: %s", resp.Status)
}

return nil
}
4 changes: 3 additions & 1 deletion tools/fast/environment/environment_memory_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ func NewMemoryGenesis(funds *big.Int, location string, proofsMode types.ProofsMo
return env, nil
}

// GetFunds retrieves a fixed amount of tokens from an environment
// GetFunds retrieves a fixed amount of tokens from the environment to the
// Filecoin processes default wallet address.
// GetFunds will cause the genesis node to send 1000 filecoin to process `p`.
func (e *MemoryGenesis) GetFunds(ctx context.Context, p *fast.Filecoin) error {
e.processesMu.Lock()
defer e.processesMu.Unlock()
Expand Down

0 comments on commit 531dc1d

Please sign in to comment.