diff --git a/tools/fast/environment/environment.go b/tools/fast/environment/environment.go index 4f12fbf7a8..c6cfd9408e 100644 --- a/tools/fast/environment/environment.go +++ b/tools/fast/environment/environment.go @@ -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 } diff --git a/tools/fast/environment/environment_devnet.go b/tools/fast/environment/environment_devnet.go index f53b26802f..3cafeb5d3c 100644 --- a/tools/fast/environment/environment_devnet.go +++ b/tools/fast/environment/environment_devnet.go @@ -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 } diff --git a/tools/fast/environment/environment_memory_genesis.go b/tools/fast/environment/environment_memory_genesis.go index e4b38cd898..508270bcc6 100644 --- a/tools/fast/environment/environment_memory_genesis.go +++ b/tools/fast/environment/environment_memory_genesis.go @@ -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" @@ -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{ diff --git a/tools/fast/tests/retrieval_test.go b/tools/fast/tests/retrieval_test.go index f83c99998b..ca3a51fa27 100644 --- a/tools/fast/tests/retrieval_test.go +++ b/tools/fast/tests/retrieval_test.go @@ -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)