lotus/storage/sealing/fsm_test.go

86 lines
2.1 KiB
Go
Raw Normal View History

package sealing
2020-01-15 20:04:02 +00:00
import (
"testing"
logging "github.com/ipfs/go-log/v2"
2020-01-15 20:04:02 +00:00
"github.com/stretchr/testify/require"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/lib/statemachine"
)
func init() {
_ = logging.SetLogLevel("*", "INFO")
}
2020-01-15 20:04:02 +00:00
func (t *test) planSingle(evt interface{}) {
2020-01-15 20:53:14 +00:00
_, err := t.s.plan([]statemachine.Event{{evt}}, t.state)
2020-01-15 20:04:02 +00:00
require.NoError(t.t, err)
}
type test struct {
2020-01-15 20:53:14 +00:00
s *Sealing
2020-01-15 20:04:02 +00:00
t *testing.T
state *SectorInfo
next func(statemachine.Context, SectorInfo) error
}
func TestHappyPath(t *testing.T) {
m := test{
2020-01-15 20:53:14 +00:00
s: &Sealing{},
2020-01-15 20:04:02 +00:00
t: t,
state: &SectorInfo{State: api.Packing},
}
m.planSingle(SectorPacked{})
require.Equal(m.t, m.state.State, api.Unsealed)
m.planSingle(SectorSealed{})
require.Equal(m.t, m.state.State, api.PreCommitting)
m.planSingle(SectorPreCommitted{})
2020-01-20 22:04:46 +00:00
require.Equal(m.t, m.state.State, api.WaitSeed)
2020-01-15 20:04:02 +00:00
m.planSingle(SectorSeedReady{})
require.Equal(m.t, m.state.State, api.Committing)
m.planSingle(SectorCommitted{})
require.Equal(m.t, m.state.State, api.CommitWait)
m.planSingle(SectorProving{})
require.Equal(m.t, m.state.State, api.Proving)
}
func TestSeedRevert(t *testing.T) {
m := test{
2020-01-15 20:53:14 +00:00
s: &Sealing{},
2020-01-15 20:04:02 +00:00
t: t,
state: &SectorInfo{State: api.Packing},
}
m.planSingle(SectorPacked{})
require.Equal(m.t, m.state.State, api.Unsealed)
m.planSingle(SectorSealed{})
require.Equal(m.t, m.state.State, api.PreCommitting)
m.planSingle(SectorPreCommitted{})
2020-01-20 22:04:46 +00:00
require.Equal(m.t, m.state.State, api.WaitSeed)
2020-01-15 20:04:02 +00:00
m.planSingle(SectorSeedReady{})
require.Equal(m.t, m.state.State, api.Committing)
2020-01-16 02:54:57 +00:00
_, err := m.s.plan([]statemachine.Event{{SectorSeedReady{seed: SealSeed{BlockHeight: 5}}}, {SectorCommitted{}}}, m.state)
2020-01-15 20:04:02 +00:00
require.NoError(t, err)
require.Equal(m.t, m.state.State, api.Committing)
// not changing the seed this time
2020-01-16 02:54:57 +00:00
_, err = m.s.plan([]statemachine.Event{{SectorSeedReady{seed: SealSeed{BlockHeight: 5}}}, {SectorCommitted{}}}, m.state)
2020-01-15 20:04:02 +00:00
require.Equal(m.t, m.state.State, api.CommitWait)
m.planSingle(SectorProving{})
require.Equal(m.t, m.state.State, api.Proving)
}