Skip to content

Commit

Permalink
create fast environment package
Browse files Browse the repository at this point in the history
  • Loading branch information
frrist committed Jun 12, 2019
1 parent 3a320be commit c8d373f
Show file tree
Hide file tree
Showing 16 changed files with 117 additions and 100 deletions.
2 changes: 1 addition & 1 deletion commands/client_daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func TestPieceRejectionInProposeStorageDeal(t *testing.T) {
func TestSelfDialStorageGoodError(t *testing.T) {
tf.IntegrationTest(t)

ctx, env := fastesting.NewTestEnvironment(context.Background(), t, fast.EnvironmentOpts{})
ctx, env := fastesting.NewTestEnvironment(context.Background(), t, fast.FilecoinOpts{})
// Teardown after test ends.
defer func() {
err := env.Teardown(ctx)
Expand Down
2 changes: 1 addition & 1 deletion commands/inspector_daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func TestInspectConfig(t *testing.T) {
tf.IntegrationTest(t)

ctx, env := fastesting.NewTestEnvironment(context.Background(), t, fast.EnvironmentOpts{})
ctx, env := fastesting.NewTestEnvironment(context.Background(), t, fast.FilecoinOpts{})

// Teardown after test ends
defer func() {
Expand Down
22 changes: 11 additions & 11 deletions commands/payment_channel_daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
func TestPaymentChannelCreateSuccess(t *testing.T) {
tf.IntegrationTest(t)

ctx, env := fastesting.NewTestEnvironment(context.Background(), t, fast.EnvironmentOpts{})
ctx, env := fastesting.NewTestEnvironment(context.Background(), t, fast.FilecoinOpts{})

// Teardown after test ends
defer func() {
Expand All @@ -42,7 +42,7 @@ func TestPaymentChannelLs(t *testing.T) {
tf.IntegrationTest(t)

t.Run("Works with default payer", func(t *testing.T) {
ctx, env := fastesting.NewTestEnvironment(context.Background(), t, fast.EnvironmentOpts{})
ctx, env := fastesting.NewTestEnvironment(context.Background(), t, fast.FilecoinOpts{})

// Teardown after test ends
defer func() {
Expand Down Expand Up @@ -72,7 +72,7 @@ func TestPaymentChannelLs(t *testing.T) {
})

t.Run("Works with specified payer", func(t *testing.T) {
ctx, env := fastesting.NewTestEnvironment(context.Background(), t, fast.EnvironmentOpts{})
ctx, env := fastesting.NewTestEnvironment(context.Background(), t, fast.FilecoinOpts{})

// Teardown after test ends
defer func() {
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestPaymentChannelLs(t *testing.T) {
defer cancel()

// Get basic testing environment
ctx, env := fastesting.NewTestEnvironment(ctx, t, fast.EnvironmentOpts{})
ctx, env := fastesting.NewTestEnvironment(ctx, t, fast.FilecoinOpts{})

// Teardown after test ends
defer func() {
Expand All @@ -133,7 +133,7 @@ func TestPaymentChannelLs(t *testing.T) {
func TestPaymentChannelVoucherSuccess(t *testing.T) {
tf.IntegrationTest(t)

ctx, env := fastesting.NewTestEnvironment(context.Background(), t, fast.EnvironmentOpts{})
ctx, env := fastesting.NewTestEnvironment(context.Background(), t, fast.FilecoinOpts{})

// Teardown after test ends
defer func() {
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestPaymentChannelVoucherSuccess(t *testing.T) {
func TestPaymentChannelRedeemSuccess(t *testing.T) {
tf.IntegrationTest(t)

ctx, env := fastesting.NewTestEnvironment(context.Background(), t, fast.EnvironmentOpts{})
ctx, env := fastesting.NewTestEnvironment(context.Background(), t, fast.FilecoinOpts{})

// Teardown after test ends
defer func() {
Expand Down Expand Up @@ -204,7 +204,7 @@ func TestPaymentChannelRedeemSuccess(t *testing.T) {
func TestPaymentChannelRedeemTooEarlyFails(t *testing.T) {
tf.IntegrationTest(t)

ctx, env := fastesting.NewTestEnvironment(context.Background(), t, fast.EnvironmentOpts{})
ctx, env := fastesting.NewTestEnvironment(context.Background(), t, fast.FilecoinOpts{})

// Teardown after test ends
defer func() {
Expand Down Expand Up @@ -245,7 +245,7 @@ func TestPaymentChannelRedeemTooEarlyFails(t *testing.T) {
func TestPaymentChannelReclaimSuccess(t *testing.T) {
tf.IntegrationTest(t)

ctx, env := fastesting.NewTestEnvironment(context.Background(), t, fast.EnvironmentOpts{})
ctx, env := fastesting.NewTestEnvironment(context.Background(), t, fast.FilecoinOpts{})

// Teardown after test ends
defer func() {
Expand Down Expand Up @@ -317,7 +317,7 @@ func TestPaymentChannelReclaimSuccess(t *testing.T) {
func TestPaymentChannelCloseSuccess(t *testing.T) {
tf.IntegrationTest(t)

ctx, env := fastesting.NewTestEnvironment(context.Background(), t, fast.EnvironmentOpts{})
ctx, env := fastesting.NewTestEnvironment(context.Background(), t, fast.FilecoinOpts{})

// Teardown after test ends
defer func() {
Expand Down Expand Up @@ -369,7 +369,7 @@ func TestPaymentChannelCloseSuccess(t *testing.T) {
func TestPaymentChannelExtendSuccess(t *testing.T) {
tf.IntegrationTest(t)

ctx, env := fastesting.NewTestEnvironment(context.Background(), t, fast.EnvironmentOpts{})
ctx, env := fastesting.NewTestEnvironment(context.Background(), t, fast.FilecoinOpts{})

// Teardown after test ends
defer func() {
Expand Down Expand Up @@ -425,7 +425,7 @@ func TestPaymentChannelExtendSuccess(t *testing.T) {
func TestPaymentChannelCancelSuccess(t *testing.T) {
tf.IntegrationTest(t)

ctx, env := fastesting.NewTestEnvironment(context.Background(), t, fast.EnvironmentOpts{})
ctx, env := fastesting.NewTestEnvironment(context.Background(), t, fast.FilecoinOpts{})

// Teardown after test ends
defer func() {
Expand Down
2 changes: 1 addition & 1 deletion commands/retrieval_client_daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
func TestSelfDialRetrievalGoodError(t *testing.T) {
tf.IntegrationTest(t)

ctx, env := fastesting.NewTestEnvironment(context.Background(), t, fast.EnvironmentOpts{})
ctx, env := fastesting.NewTestEnvironment(context.Background(), t, fast.FilecoinOpts{})
// Teardown after test ends.
defer func() {
err := env.Teardown(ctx)
Expand Down
2 changes: 1 addition & 1 deletion commands/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestBlockDaemon(t *testing.T) {
func TestShowDeal(t *testing.T) {
tf.IntegrationTest(t)

fastenvOpts := fast.EnvironmentOpts{}
fastenvOpts := fast.FilecoinOpts{}

ctx, env := fastesting.NewTestEnvironment(context.Background(), t, fastenvOpts)
defer func() {
Expand Down
5 changes: 3 additions & 2 deletions tools/fast/bin/localnet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/filecoin-project/go-filecoin/proofs"
"github.com/filecoin-project/go-filecoin/protocol/storage/storagedeal"
"github.com/filecoin-project/go-filecoin/tools/fast"
"github.com/filecoin-project/go-filecoin/tools/fast/environment"
"github.com/filecoin-project/go-filecoin/tools/fast/series"
lpfc "github.com/filecoin-project/go-filecoin/tools/iptb-plugins/filecoin/local"
)
Expand Down Expand Up @@ -169,7 +170,7 @@ func main() {
return
}

env, err := fast.NewEnvironmentMemoryGenesis(&balance, workdir, getProofsMode(smallSectors))
env, err := environment.NewMemoryGenesis(&balance, workdir, getProofsMode(smallSectors))
if err != nil {
exitcode = handleError(err)
return
Expand All @@ -191,7 +192,7 @@ func main() {
return
}

fastenvOpts := fast.EnvironmentOpts{
fastenvOpts := fast.FilecoinOpts{
InitOpts: []fast.ProcessInitOption{fast.POGenesisFile(genesisURI)},
DaemonOpts: []fast.ProcessDaemonOption{fast.POBlockTime(blocktime)},
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fast
package environment

import (
"context"
Expand All @@ -8,6 +8,7 @@ import (
logging "github.com/ipfs/go-log"

"github.com/filecoin-project/go-filecoin/address"
"github.com/filecoin-project/go-filecoin/tools/fast"
)

// ErrNoGenesisMiner is returned by GenesisMiner if the environment does not
Expand All @@ -24,12 +25,6 @@ type GenesisMiner struct {
Owner io.Reader
}

// EnvironmentOpts are used define process init and daemon options for the environment.
type EnvironmentOpts struct {
InitOpts []ProcessInitOption
DaemonOpts []ProcessDaemonOption
}

// Environment defines the interface common among all environments that the
// FAST lib can work across. It helps smooth out the differences by providing
// a common ground to work from
Expand All @@ -53,17 +48,17 @@ type Environment interface {
// environments may create a Filecoin process that interacts with
// an already running filecoin node, and supplied the API multiaddr
// as options.
NewProcess(ctx context.Context, processType string, options map[string]string, eo EnvironmentOpts) (*Filecoin, error)
NewProcess(ctx context.Context, processType string, options map[string]string, eo fast.FilecoinOpts) (*fast.Filecoin, error)

// Processes returns a slice of all processes the environment knows
// about.
Processes() []*Filecoin
Processes() []*fast.Filecoin

// Teardown runs anything that the environment may need to do to
// be nice to the the execution area of this code.
Teardown(context.Context) error

// TeardownProcess runs anything that the environment may need to do
// to remove a process from the environment in a clean way.
TeardownProcess(context.Context, *Filecoin) error
TeardownProcess(context.Context, *fast.Filecoin) error
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fast
package environment

// The devnet FAST environment provides an environment for using FAST with the deployed kittyhawk
// devnet infrasturture run by the Filecoin development team. It can be used to setup and manage nodes
Expand All @@ -17,24 +17,25 @@ import (
iptb "github.com/ipfs/iptb/testbed"

"github.com/filecoin-project/go-filecoin/address"
"github.com/filecoin-project/go-filecoin/tools/fast"
)

// EnvironmentDevnet is a FAST lib environment that is meant to be used
// Devnet is a FAST lib environment that is meant to be used
// when working with kittyhawk devnets run by the Filecoin development team.
type EnvironmentDevnet struct {
type Devnet struct {
network string
location string

log logging.EventLogger

processesMu sync.Mutex
processes []*Filecoin
processes []*fast.Filecoin
}

// NewEnvironmentDevnet builds an environment that uses deployed infrastructure to
// NewDevnet builds an environment that uses deployed infrastructure to
// the kittyhawk devnets.
func NewEnvironmentDevnet(network, location string) (Environment, error) {
env := &EnvironmentDevnet{
func NewDevnet(network, location string) (Environment, error) {
env := &Devnet{
network: network,
location: location,
log: logging.Logger("environment"),
Expand All @@ -48,7 +49,7 @@ func NewEnvironmentDevnet(network, location string) (Environment, error) {
}

// GenesisCar provides a url where the genesis file can be fetched from
func (e *EnvironmentDevnet) GenesisCar() string {
func (e *Devnet) GenesisCar() string {
uri := url.URL{
Host: fmt.Sprintf("genesis.%s.kittyhawk.wtf", e.network),
Path: "genesis.car",
Expand All @@ -59,18 +60,18 @@ func (e *EnvironmentDevnet) GenesisCar() string {
}

// GenesisMiner returns a ErrNoGenesisMiner for this environment
func (e *EnvironmentDevnet) GenesisMiner() (*GenesisMiner, error) {
func (e *Devnet) GenesisMiner() (*GenesisMiner, error) {
return nil, ErrNoGenesisMiner
}

// Log returns the logger for the environment.
func (e *EnvironmentDevnet) Log() logging.EventLogger {
func (e *Devnet) Log() logging.EventLogger {
return e.log
}

// NewProcess builds a iptb process of the given type and options passed. The
// process is tracked by the environment and returned.
func (e *EnvironmentDevnet) NewProcess(ctx context.Context, processType string, options map[string]string, eo EnvironmentOpts) (*Filecoin, error) {
func (e *Devnet) NewProcess(ctx context.Context, processType string, options map[string]string, eo fast.FilecoinOpts) (*fast.Filecoin, error) {
e.processesMu.Lock()
defer e.processesMu.Unlock()

Expand All @@ -92,31 +93,31 @@ func (e *EnvironmentDevnet) NewProcess(ctx context.Context, processType string,
}

// We require a slightly more extended core interface
fc, ok := c.(IPTBCoreExt)
fc, ok := c.(fast.IPTBCoreExt)
if !ok {
return nil, fmt.Errorf("%s does not implement the extended IPTB.Core interface IPTBCoreExt", processType)
}

p := NewFilecoinProcess(ctx, fc, eo)
p := fast.NewFilecoinProcess(ctx, fc, eo)
e.processes = append(e.processes, p)
return p, nil
}

// Processes returns all processes the environment knows about.
func (e *EnvironmentDevnet) Processes() []*Filecoin {
func (e *Devnet) Processes() []*fast.Filecoin {
e.processesMu.Lock()
defer e.processesMu.Unlock()
return e.processes[:]
}

// Teardown stops all of the nodes and cleans up the environment.
func (e *EnvironmentDevnet) Teardown(ctx context.Context) error {
func (e *Devnet) Teardown(ctx context.Context) error {
e.processesMu.Lock()
defer e.processesMu.Unlock()

e.log.Info("Teardown environment")
for _, p := range e.processes {
if err := p.core.Stop(ctx); err != nil {
if err := p.StopDaemon(ctx); err != nil {
return err
}
}
Expand All @@ -126,12 +127,12 @@ func (e *EnvironmentDevnet) Teardown(ctx context.Context) error {

// TeardownProcess stops the running process and removes it from the
// environment.
func (e *EnvironmentDevnet) TeardownProcess(ctx context.Context, p *Filecoin) error {
func (e *Devnet) TeardownProcess(ctx context.Context, p *fast.Filecoin) error {
e.processesMu.Lock()
defer e.processesMu.Unlock()

e.log.Infof("Teardown process: %s", p.core.String())
if err := p.core.Stop(ctx); err != nil {
e.log.Infof("Teardown process: %s", p.String())
if err := p.StopDaemon(ctx); err != nil {
return err
}

Expand All @@ -143,13 +144,13 @@ func (e *EnvironmentDevnet) TeardownProcess(ctx context.Context, p *Filecoin) er
}

// remove the provess from the process list
return os.RemoveAll(p.core.Dir())
return os.RemoveAll(p.Dir())
}

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

0 comments on commit c8d373f

Please sign in to comment.