|
8 | 8 | "time" |
9 | 9 |
|
10 | 10 | "github.com/filecoin-project/go-f3/certchain" |
| 11 | + "github.com/filecoin-project/go-f3/certs" |
11 | 12 | "github.com/filecoin-project/go-f3/gpbft" |
12 | 13 | "github.com/filecoin-project/go-f3/internal/clock" |
13 | 14 | "github.com/filecoin-project/go-f3/internal/consensus" |
@@ -41,6 +42,9 @@ func Test_SnapshotExportImportRoundTrip(t *testing.T) { |
41 | 42 | return signVerifier.Allow(int(id)) |
42 | 43 | } |
43 | 44 | initialPowerTable := generatePowerTable(t, rng, generatePublicKey, nil) |
| 45 | + ptCid, err := certs.MakePowerTableCID(initialPowerTable) |
| 46 | + require.NoError(t, err) |
| 47 | + m.InitialPowerTable = ptCid |
44 | 48 |
|
45 | 49 | ec := consensus.NewFakeEC( |
46 | 50 | consensus.WithClock(clk), |
@@ -103,16 +107,31 @@ func Test_SnapshotExportImportRoundTrip(t *testing.T) { |
103 | 107 | require.Equal(t, c.Hash(), multihash.Multihash(mh)) |
104 | 108 |
|
105 | 109 | ds2 := datastore.NewMapDatastore() |
106 | | - err = importSnapshotToDatastoreWithTestingPowerTableFrequency(ctx, bytes.NewReader(snapshot.Bytes()), ds2, testingPowerTableFreqency) |
| 110 | + err = importSnapshotToDatastoreWithTestingPowerTableFrequency(ctx, bytes.NewReader(snapshot.Bytes()), ds2, &m, testingPowerTableFreqency) |
107 | 111 | require.NoError(t, err) |
108 | 112 |
|
109 | 113 | require.Equal(t, ds1, ds2) |
110 | 114 |
|
111 | 115 | ds3 := datastore.NewMapDatastore() |
112 | | - err = ImportSnapshotToDatastore(ctx, bytes.NewReader(snapshot.Bytes()), ds3) |
| 116 | + err = ImportSnapshotToDatastore(ctx, bytes.NewReader(snapshot.Bytes()), ds3, &m) |
113 | 117 | require.NoError(t, err) |
114 | 118 |
|
115 | 119 | require.NotEqual(t, ds1, ds3) |
| 120 | + |
| 121 | + // Test manifest validation logic |
| 122 | + ds4 := datastore.NewMapDatastore() |
| 123 | + m2 := manifest.LocalDevnetManifest() |
| 124 | + |
| 125 | + // bad initial instance |
| 126 | + m2.InitialInstance = m.InitialInstance + 1 |
| 127 | + err = ImportSnapshotToDatastore(ctx, bytes.NewReader(snapshot.Bytes()), ds4, &m2) |
| 128 | + require.ErrorContains(t, err, "initial instance") |
| 129 | + |
| 130 | + // bad InitialPowerTable |
| 131 | + m2.InitialInstance = m.InitialInstance |
| 132 | + m2.InitialPowerTable = generatedChain[1].ECChain.Head().PowerTable |
| 133 | + err = ImportSnapshotToDatastore(ctx, bytes.NewReader(snapshot.Bytes()), ds4, &m2) |
| 134 | + require.ErrorContains(t, err, "initial power table CID") |
116 | 135 | } |
117 | 136 |
|
118 | 137 | func generatePowerTable(t *testing.T, rng *rand.Rand, generatePublicKey func(id gpbft.ActorID) gpbft.PubKey, previousEntries gpbft.PowerEntries) gpbft.PowerEntries { |
|
0 commit comments