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"
|
|
|
|
|
2020-03-06 18:59:08 +00:00
|
|
|
"github.com/filecoin-project/go-statemachine"
|
|
|
|
|
2020-01-15 20:04:02 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
|
|
|
)
|
|
|
|
|
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{})
|
2020-04-03 16:54:01 +00:00
|
|
|
require.Equal(m.t, m.state.State, api.PreCommit1)
|
2020-01-15 20:04:02 +00:00
|
|
|
|
2020-04-04 02:55:19 +00:00
|
|
|
m.planSingle(SectorPreCommit1{})
|
|
|
|
require.Equal(m.t, m.state.State, api.PreCommit2)
|
|
|
|
|
2020-04-03 16:54:01 +00:00
|
|
|
m.planSingle(SectorPreCommit2{})
|
2020-01-15 20:04:02 +00:00
|
|
|
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{})
|
2020-01-31 01:27:38 +00:00
|
|
|
require.Equal(m.t, m.state.State, api.FinalizeSector)
|
|
|
|
|
|
|
|
m.planSingle(SectorFinalized{})
|
2020-01-15 20:04:02 +00:00
|
|
|
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{})
|
2020-04-03 16:54:01 +00:00
|
|
|
require.Equal(m.t, m.state.State, api.PreCommit1)
|
2020-01-15 20:04:02 +00:00
|
|
|
|
2020-04-04 02:55:19 +00:00
|
|
|
m.planSingle(SectorPreCommit1{})
|
|
|
|
require.Equal(m.t, m.state.State, api.PreCommit2)
|
|
|
|
|
2020-04-03 16:54:01 +00:00
|
|
|
m.planSingle(SectorPreCommit2{})
|
2020-01-15 20:04:02 +00:00
|
|
|
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-03-22 20:44:27 +00:00
|
|
|
_, err := m.s.plan([]statemachine.Event{{SectorSeedReady{Seed: api.SealSeed{Epoch: 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-03-22 20:44:27 +00:00
|
|
|
_, err = m.s.plan([]statemachine.Event{{SectorSeedReady{Seed: api.SealSeed{Epoch: 5}}}, {SectorCommitted{}}}, m.state)
|
2020-01-15 20:04:02 +00:00
|
|
|
require.Equal(m.t, m.state.State, api.CommitWait)
|
|
|
|
|
|
|
|
m.planSingle(SectorProving{})
|
2020-01-31 01:27:38 +00:00
|
|
|
require.Equal(m.t, m.state.State, api.FinalizeSector)
|
|
|
|
|
|
|
|
m.planSingle(SectorFinalized{})
|
2020-01-15 20:04:02 +00:00
|
|
|
require.Equal(m.t, m.state.State, api.Proving)
|
|
|
|
}
|
2020-01-28 20:39:07 +00:00
|
|
|
|
|
|
|
func TestPlanCommittingHandlesSectorCommitFailed(t *testing.T) {
|
|
|
|
m := test{
|
|
|
|
s: &Sealing{},
|
|
|
|
t: t,
|
|
|
|
state: &SectorInfo{State: api.Committing},
|
|
|
|
}
|
|
|
|
|
|
|
|
events := []statemachine.Event{{SectorCommitFailed{}}}
|
|
|
|
|
|
|
|
require.NoError(t, planCommitting(events, m.state))
|
|
|
|
|
2020-04-03 16:36:48 +00:00
|
|
|
require.Equal(t, api.CommitFailed, m.state.State)
|
2020-01-28 20:39:07 +00:00
|
|
|
}
|