testSync sync test with a general process: 1. create a storage manager and a local node, then start the sync client; 2. prepare test data which need to sync to the local node; 3. copy data for remote peers (only copy the data for shard remote peer supported, exclude data whose blob index in the excl
(t *testing.T, chunkSize, kvSize, kvEntries uint64, localShards []uint64, lastKvIndex uint64, encodeType uint64, waitTime time.Duration, remotePeers []*remotePeer, expectedState bool)
| 775 | // 5. wait for sync client syncDone or time out |
| 776 | // 6. verify blobs synced to local node with test data |
| 777 | func testSync(t *testing.T, chunkSize, kvSize, kvEntries uint64, localShards []uint64, lastKvIndex uint64, |
| 778 | encodeType uint64, waitTime time.Duration, remotePeers []*remotePeer, expectedState bool) { |
| 779 | var ( |
| 780 | db = rawdb.NewMemoryDatabase() |
| 781 | ctx, cancel = context.WithCancel(context.Background()) |
| 782 | mux = new(event.Feed) |
| 783 | localShardMap = make(map[common.Address][]uint64) |
| 784 | m = metrics.NewMetrics("sync_test") |
| 785 | chainID = new(big.Int).SetUint64(3333) |
| 786 | ) |
| 787 | |
| 788 | metafile, err := CreateMetaFile(metafileName, int64(kvEntries)*int64(len(localShards))) |
| 789 | if err != nil { |
| 790 | t.Error("Create metafileName fail", err.Error()) |
| 791 | } |
| 792 | defer func() { |
| 793 | metafile.Close() |
| 794 | os.Remove(metafileName) |
| 795 | }() |
| 796 | |
| 797 | localShardMap[contract] = localShards |
| 798 | shardManager, files := createEthStorage(contract, localShards, chunkSize, kvSize, kvEntries, common.Address{}, encodeType) |
| 799 | if shardManager == nil { |
| 800 | t.Fatalf("createEthStorage failed") |
| 801 | } |
| 802 | |
| 803 | defer func(files []string) { |
| 804 | for _, file := range files { |
| 805 | os.Remove(file) |
| 806 | } |
| 807 | }(files) |
| 808 | |
| 809 | l1 := NewMockL1Source(lastKvIndex, metafileName) |
| 810 | sm := ethstorage.NewStorageManager(shardManager, l1, lg) |
| 811 | sm.Reset(0) |
| 812 | data := makeKVStorage(contract, localShards, chunkSize, kvSize, kvEntries, lastKvIndex, common.Address{}, encodeType, metafile) |
| 813 | localHost, syncCl := createLocalHostAndSyncClient(t, chainID, db, sm, m, mux) |
| 814 | syncCl.Start() |
| 815 | |
| 816 | finalExcludedList := remotePeers[0].excludedList |
| 817 | for _, rPeer := range remotePeers { |
| 818 | // fill empty to excludedList for verify KVs |
| 819 | fillEmpty(shardManager, rPeer.excludedList) |
| 820 | finalExcludedList = mergeExcludedList(finalExcludedList, rPeer.excludedList) |
| 821 | pData := copyShardData(data[contract], rPeer.shards, kvEntries, rPeer.excludedList) |
| 822 | smr := &mockStorageManagerReader{ |
| 823 | kvEntries: kvEntries, |
| 824 | maxKvSize: kvSize, |
| 825 | encodeType: encodeType, |
| 826 | shards: rPeer.shards, |
| 827 | contractAddress: contract, |
| 828 | shardMiner: common.Address{}, |
| 829 | blobPayloads: pData, |
| 830 | } |
| 831 | rShardMap := make(map[common.Address][]uint64) |
| 832 | rShardMap[contract] = rPeer.shards |
| 833 | remoteHost := createRemoteHost(t, ctx, chainID, smr, db, m) |
| 834 | connect(t, localHost, remoteHost, localShardMap, rShardMap) |
no test coverage detected