Skip to content

Commit

Permalink
GetFunds defined on environment interface
Browse files Browse the repository at this point in the history
  • Loading branch information
frrist committed Jun 12, 2019
1 parent 2351c39 commit 153760f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 30 deletions.
3 changes: 3 additions & 0 deletions tools/fast/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,7 @@ type Environment interface {
// TeardownProcess runs anything that the environment may need to do
// 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(context.Context, *fast.Filecoin) error
}
55 changes: 27 additions & 28 deletions tools/fast/environment/environment_devnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,40 +148,39 @@ func (e *Devnet) TeardownProcess(ctx context.Context, p *fast.Filecoin) error {
}

// GetFunds retrieves a fixed amount of tokens from an environment
func GetFunds(ctx context.Context, env Environment, p *fast.Filecoin) error {
switch devenv := env.(type) {
case *Devnet:
var toAddr address.Address
if err := p.ConfigGet(ctx, "wallet.defaultAddress", &toAddr); err != nil {
return err
}
func (e *Devnet) GetFunds(ctx context.Context, p *fast.Filecoin) error {
e.processesMu.Lock()
defer e.processesMu.Unlock()

data := url.Values{}
data.Set("target", toAddr.String())
e.log.Infof("GetFunds for process: %s", p.String())
var toAddr address.Address
if err := p.ConfigGet(ctx, "wallet.defaultAddress", &toAddr); err != nil {
return err
}

uri := url.URL{
Host: fmt.Sprintf("faucet.%s.kittyhawk.wtf", devenv.network),
Path: "tap",
Scheme: "https",
}
data := url.Values{}
data.Set("target", toAddr.String())

resp, err := http.PostForm(uri.String(), data)
if err != nil {
return err
}
uri := url.URL{
Host: fmt.Sprintf("faucet.%s.kittyhawk.wtf", e.network),
Path: "tap",
Scheme: "https",
}

msgcid := resp.Header.Get("Message-Cid")
mcid, err := cid.Decode(msgcid)
if err != nil {
return err
}
resp, err := http.PostForm(uri.String(), data)
if err != nil {
return err
}

if _, err := p.MessageWait(ctx, mcid); err != nil {
return err
}
msgcid := resp.Header.Get("Message-Cid")
mcid, err := cid.Decode(msgcid)
if err != nil {
return err
}

return nil
if _, err := p.MessageWait(ctx, mcid); err != nil {
return err
}

return fmt.Errorf("environment [%T] does not support GetFunds", env)
return nil
}
9 changes: 9 additions & 0 deletions tools/fast/environment/environment_memory_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/filecoin-project/go-filecoin/commands"
"github.com/filecoin-project/go-filecoin/gengen/util"
"github.com/filecoin-project/go-filecoin/tools/fast"
"github.com/filecoin-project/go-filecoin/tools/fast/series"
"github.com/filecoin-project/go-filecoin/types"

iptb "github.com/ipfs/iptb/testbed"
Expand Down Expand Up @@ -70,6 +71,14 @@ func NewMemoryGenesis(funds *big.Int, location string, proofsMode types.ProofsMo
return env, nil
}

func (e *MemoryGenesis) GetFunds(ctx context.Context, p *fast.Filecoin) error {
e.processesMu.Lock()
defer e.processesMu.Unlock()

e.log.Infof("GetFunds for process: %s", p.String())
return series.SendFilecoinDefaults(ctx, e.Processes()[0], p, 1000)
}

// GenesisCar provides a url where the genesis file can be fetched from
func (e *MemoryGenesis) GenesisCar() string {
uri := url.URL{
Expand Down
4 changes: 2 additions & 2 deletions tools/fast/tests/retrieval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ func TestRetrievalDevnet(t *testing.T) {

// Everyone needs FIL to deal with gas costs and make sure their wallets
// exists (sending FIL to a wallet addr creates it)
err = environment.GetFunds(ctx, env, miner)
err = env.GetFunds(ctx, miner)
require.NoError(t, err)

err = environment.GetFunds(ctx, env, client)
err = env.GetFunds(ctx, client)
require.NoError(t, err)

RunRetrievalTest(ctx, t, miner, client, sectorSize)
Expand Down

0 comments on commit 153760f

Please sign in to comment.