2020-01-15 20:49:11 +00:00
|
|
|
package sealing
|
|
|
|
|
|
|
|
import (
|
2020-01-29 20:01:20 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/sbmock"
|
2020-01-15 20:49:11 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
|
|
|
|
)
|
|
|
|
|
|
|
|
func testFill(t *testing.T, n uint64, exp []uint64) {
|
|
|
|
f, err := fillersFromRem(n)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, exp, f)
|
|
|
|
|
|
|
|
var sum uint64
|
|
|
|
for _, u := range f {
|
|
|
|
sum += u
|
|
|
|
}
|
|
|
|
assert.Equal(t, n, sum)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFillersFromRem(t *testing.T) {
|
|
|
|
for i := 8; i < 32; i++ {
|
|
|
|
// single
|
|
|
|
ub := sectorbuilder.UserBytesForSectorSize(uint64(1) << i)
|
|
|
|
testFill(t, ub, []uint64{ub})
|
|
|
|
|
|
|
|
// 2
|
|
|
|
ub = sectorbuilder.UserBytesForSectorSize(uint64(5) << i)
|
|
|
|
ub1 := sectorbuilder.UserBytesForSectorSize(uint64(1) << i)
|
|
|
|
ub3 := sectorbuilder.UserBytesForSectorSize(uint64(4) << i)
|
|
|
|
testFill(t, ub, []uint64{ub1, ub3})
|
|
|
|
|
|
|
|
// 4
|
|
|
|
ub = sectorbuilder.UserBytesForSectorSize(uint64(15) << i)
|
|
|
|
ub2 := sectorbuilder.UserBytesForSectorSize(uint64(2) << i)
|
|
|
|
ub4 := sectorbuilder.UserBytesForSectorSize(uint64(8) << i)
|
|
|
|
testFill(t, ub, []uint64{ub1, ub2, ub3, ub4})
|
|
|
|
|
|
|
|
// different 2
|
|
|
|
ub = sectorbuilder.UserBytesForSectorSize(uint64(9) << i)
|
|
|
|
testFill(t, ub, []uint64{ub1, ub4})
|
|
|
|
}
|
2020-01-29 20:01:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFastPledge(t *testing.T) {
|
|
|
|
sz := uint64(16 << 20)
|
2020-01-15 20:49:11 +00:00
|
|
|
|
2020-01-29 20:01:20 +00:00
|
|
|
s := Sealing{sb: sbmock.NewMockSectorBuilder(0, sz)}
|
2020-01-30 01:01:10 +00:00
|
|
|
if _, err := s.fastPledgeCommitment(sectorbuilder.UserBytesForSectorSize(sz), 5); err != nil {
|
2020-01-29 20:01:20 +00:00
|
|
|
t.Fatalf("%+v", err)
|
|
|
|
}
|
2020-01-31 01:18:48 +00:00
|
|
|
|
|
|
|
sz = uint64(1024)
|
|
|
|
|
|
|
|
s = Sealing{sb: sbmock.NewMockSectorBuilder(0, sz)}
|
|
|
|
if _, err := s.fastPledgeCommitment(sectorbuilder.UserBytesForSectorSize(sz), 64); err != nil {
|
|
|
|
t.Fatalf("%+v", err)
|
|
|
|
}
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|