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

Function prepareData

integration_tests/node_mine_test.go:261–328  ·  view source on GitHub ↗
(t *testing.T, l1Client *eth.PollingClient, storageMgr *ethstorage.StorageManager)

Source from the content-addressed store, hash-verified

259}
260
261func prepareData(t *testing.T, l1Client *eth.PollingClient, storageMgr *ethstorage.StorageManager) {
262 // fill contract with almost 2 shards of blobs
263 data := generateRandomBlobs(int(storageMgr.KvEntries()*2) - 1)
264 blobs := utils.EncodeBlobs(data)
265 t.Logf("Blobs len %d \n", len(blobs))
266 var hashs []common.Hash
267 var ids []uint64
268
269 txs := len(blobs) / maxBlobsPerTx
270 last := len(blobs) % maxBlobsPerTx
271 if last > 0 {
272 txs = txs + 1
273 }
274 t.Logf("tx len %d \n", txs)
275 ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
276 defer cancel()
277 chainID, err := l1Client.ChainID(ctx)
278 if err != nil {
279 t.Fatalf("Get chain id failed %v", err)
280 }
281 for i := 0; i < txs; i++ {
282 blobsPerTx := maxBlobsPerTx
283 if i == txs-1 {
284 blobsPerTx = last
285 }
286 blobGroup := blobs[i*maxBlobsPerTx : i*maxBlobsPerTx+blobsPerTx]
287 var blobData []byte
288 for _, bd := range blobGroup {
289 blobData = append(blobData, bd[:]...)
290 }
291 if len(blobData) == 0 {
292 break
293 }
294 totalValue, err := getPayment(l1Client, l1Contract, uint64(blobsPerTx))
295 if err != nil {
296 t.Fatalf("Get payment failed %v", err)
297 }
298 t.Logf("Get payment totalValue=%v \n", totalValue)
299 kvIdxes, dataHashes, err := utils.UploadBlobs(l1Client, l1Endpoint, privateKey, chainID.String(), storageMgr.ContractAddress(), blobData, false, totalValue.String())
300 if err != nil {
301 t.Fatalf("Upload blobs failed: %v", err)
302 }
303 t.Logf("kvIdxes=%v \n", kvIdxes)
304 t.Logf("dataHashes=%x \n", dataHashes)
305 hashs = append(hashs, dataHashes...)
306 ids = append(ids, kvIdxes...)
307 }
308 block, err := l1Client.BlockNumber(context.Background())
309 if err != nil {
310 t.Fatalf("Failed to get block number %v", err)
311 }
312 storageMgr.Reset(int64(block))
313 err = storageMgr.DownloadAllMetas(context.Background(), 1)
314 if err != nil {
315 t.Fatalf("Download all metas failed %v", err)
316 }
317 startKv := storageMgr.Shards()[0] * storageMgr.KvEntries()
318 for i := 0; i < len(ids); i++ {

Callers 1

TestMiningFunction · 0.85

Calls 12

EncodeBlobsFunction · 0.92
UploadBlobsFunction · 0.92
generateRandomBlobsFunction · 0.85
getPaymentFunction · 0.85
BlockNumberMethod · 0.80
ResetMethod · 0.80
KvEntriesMethod · 0.65
ContractAddressMethod · 0.65
DownloadAllMetasMethod · 0.65
ShardsMethod · 0.65
CommitBlobMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected