(t *testing.T)
| 45 | ) |
| 46 | |
| 47 | func TestMining(t *testing.T) { |
| 48 | setup(t) |
| 49 | t.Cleanup(func() { |
| 50 | teardown(t) |
| 51 | }) |
| 52 | |
| 53 | contract := l1Contract |
| 54 | lg.Info("Test mining", "l1Endpoint", l1Endpoint, "contract", contract) |
| 55 | pClient, err := eth.Dial(l1Endpoint, contract, 2, lg) |
| 56 | if err != nil { |
| 57 | t.Fatalf("Failed to connect to the Ethereum client: %v", err) |
| 58 | } |
| 59 | storConfig := initStorageConfig(t, pClient, contract, minerAddr) |
| 60 | lastKv, err := pClient.GetStorageKvEntryCount(rpc.LatestBlockNumber.Int64()) |
| 61 | if err != nil { |
| 62 | t.Fatalf("Failed to get lastKvIdx: %v", err) |
| 63 | } |
| 64 | lg.Info("lastKv", "lastKv", lastKv) |
| 65 | curShard := lastKv / storConfig.KvEntriesPerShard |
| 66 | lg.Info("Current shard", "shardId", curShard) |
| 67 | shardIds := []uint64{curShard + 1, curShard + 2} |
| 68 | lg.Info("Shards to mine", "shardIds", shardIds) |
| 69 | files, err := createDataFiles(storConfig, shardIds) |
| 70 | if err != nil { |
| 71 | t.Fatalf("Create data files error: %v", err) |
| 72 | } |
| 73 | storConfig.Filenames = files |
| 74 | miningConfig := initMiningConfig(t, pClient) |
| 75 | lg.Info("Initialized mining config", "miningConfig", fmt.Sprintf("%+v", miningConfig)) |
| 76 | shardManager, err := initShardManager(*storConfig) |
| 77 | if err != nil { |
| 78 | t.Fatalf("init shard manager error: %v", err) |
| 79 | } |
| 80 | storageManager := ethstorage.NewStorageManager(shardManager, pClient, lg) |
| 81 | |
| 82 | resourcesCtx, close := context.WithCancel(context.Background()) |
| 83 | feed := new(event.Feed) |
| 84 | |
| 85 | rc, err := eth.DialRandaoSource(resourcesCtx, randaoSourceURL, l1Endpoint, 2, lg) |
| 86 | if err != nil { |
| 87 | t.Fatalf("Failed to connect to the randao source: %v", err) |
| 88 | } |
| 89 | |
| 90 | l1api := miner.NewL1MiningAPI(pClient, rc, lg) |
| 91 | pvr := prover.NewKZGPoseidonProver( |
| 92 | miningConfig.ZKWorkingDir, |
| 93 | miningConfig.ZKeyFile, |
| 94 | miningConfig.ZKProverMode, |
| 95 | miningConfig.ZKProverImpl, |
| 96 | lg, |
| 97 | ) |
| 98 | db := rawdb.NewMemoryDatabase() |
| 99 | br := blobs.NewBlobReader(downloader.NewBlobMemCache(), storageManager, lg) |
| 100 | mnr := miner.New(miningConfig, db, storageManager, l1api, br, &pvr, feed, lg) |
| 101 | lg.Info("Initialized miner") |
| 102 | |
| 103 | randaoHeadsSub := event.ResubscribeErr(time.Second*10, func(ctx context.Context, err error) (event.Subscription, error) { |
| 104 | if err != nil { |
nothing calls this directly
no test coverage detected