2020-01-15 20:49:11 +00:00
|
|
|
package sealing
|
2020-01-15 20:04:02 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-01-16 01:25:49 +00:00
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2020-01-16 01:25:49 +00:00
|
|
|
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)
|
|
|
|
|
2020-01-16 01:25:49 +00:00
|
|
|
// 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)
|
|
|
|
}
|