MCPcopy Create free account
hub / github.com/ethstorage/es-node / TestFillEmpty

Function TestFillEmpty

ethstorage/p2p/protocol/sync_test.go:1211–1264  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1209}
1210
1211func TestFillEmpty(t *testing.T) {
1212 var (
1213 kvSize = defaultChunkSize
1214 kvEntries = uint64(256)
1215 lastKvIndex = uint64(12)
1216 db = rawdb.NewMemoryDatabase()
1217 mux = new(event.Feed)
1218 shards = []uint64{0}
1219 shardMap = make(map[common.Address][]uint64)
1220 m = metrics.NewMetrics("sync_test")
1221 chainID = new(big.Int).SetUint64(3333)
1222 )
1223
1224 metafile, err := CreateMetaFile(metafileName, int64(kvEntries))
1225 if err != nil {
1226 t.Error("Create metafileName fail", err.Error())
1227 }
1228 defer metafile.Close()
1229
1230 shardMap[contract] = shards
1231 shardManager, files := createEthStorage(contract, shards, defaultChunkSize, kvSize, kvEntries, common.Address{}, defaultEncodeType)
1232 if shardManager == nil {
1233 t.Fatalf("createEthStorage failed")
1234 }
1235 defer func(files []string) {
1236 for _, file := range files {
1237 os.Remove(file)
1238 }
1239 }(files)
1240
1241 makeKVStorage(contract, shards, defaultChunkSize, kvSize, kvEntries, lastKvIndex, common.Address{}, defaultEncodeType, metafile)
1242
1243 l1 := NewMockL1Source(lastKvIndex, metafileName)
1244 sm := ethstorage.NewStorageManager(shardManager, l1, lg)
1245 sm.Reset(0)
1246 _, syncCl := createLocalHostAndSyncClient(t, chainID, db, sm, m, mux)
1247 syncCl.Start()
1248 for i := 0; i < 4; i++ {
1249 time.Sleep(500 * time.Millisecond)
1250 l1.lastBlobIndex = l1.lastBlobIndex + rand.Uint64()%(kvEntries/4)
1251 sm.Reset(1)
1252 }
1253 time.Sleep(8 * time.Second)
1254
1255 if len(syncCl.tasks[0].SubEmptyTasks) > 0 {
1256 t.Fatalf("fill empty should be done")
1257 }
1258 if syncCl.tasks[0].state.EmptyToFill != 0 {
1259 t.Fatalf("emptyBlobsToFill should be 0, value %d", syncCl.tasks[0].state.EmptyToFill)
1260 }
1261 if syncCl.tasks[0].state.EmptyFilled != (kvEntries - lastKvIndex) {
1262 t.Fatalf("emptyBlobsFilled is wrong, expect %d, value %d", kvEntries-lastKvIndex, syncCl.tasks[0].state.EmptyFilled)
1263 }
1264}

Callers

nothing calls this directly

Calls 11

ResetMethod · 0.95
NewMetricsFunction · 0.92
NewStorageManagerFunction · 0.92
CreateMetaFileFunction · 0.85
makeKVStorageFunction · 0.85
NewMockL1SourceFunction · 0.85
createEthStorageFunction · 0.70
CloseMethod · 0.65
ErrorMethod · 0.45
StartMethod · 0.45

Tested by

no test coverage detected