2020-06-03 16:18:57 -07:00
|
|
|
//
|
|
|
|
// DarksideSanityCheckTests.swift
|
|
|
|
// ZcashLightClientKit-Unit-Tests
|
|
|
|
//
|
|
|
|
// Created by Francisco Gindre on 5/21/20.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
2022-02-28 09:03:20 -08:00
|
|
|
@testable import TestUtils
|
2020-06-03 16:18:57 -07:00
|
|
|
import XCTest
|
|
|
|
@testable import ZcashLightClientKit
|
2021-09-23 06:26:41 -07:00
|
|
|
|
2020-06-03 16:18:57 -07:00
|
|
|
class DarksideSanityCheckTests: XCTestCase {
|
|
|
|
let sendAmount: Int64 = 1000
|
|
|
|
var birthday: BlockHeight = 663150
|
|
|
|
let defaultLatestHeight: BlockHeight = 663175
|
|
|
|
var coordinator: TestCoordinator!
|
|
|
|
var syncedExpectation = XCTestExpectation(description: "synced")
|
|
|
|
var sentTransactionExpectation = XCTestExpectation(description: "sent")
|
|
|
|
var expectedReorgHeight: BlockHeight = 665188
|
|
|
|
var expectedRewindHeight: BlockHeight = 665188
|
2021-07-28 09:59:10 -07:00
|
|
|
var network = DarksideWalletDNetwork()
|
2021-09-23 06:26:41 -07:00
|
|
|
var reorgExpectation = XCTestExpectation(description: "reorg")
|
2021-07-28 15:25:47 -07:00
|
|
|
let branchID = "2bb40e60"
|
|
|
|
let chainName = "main"
|
|
|
|
|
2020-06-03 16:18:57 -07:00
|
|
|
override func setUpWithError() throws {
|
2021-09-23 06:26:41 -07:00
|
|
|
try super.setUpWithError()
|
2022-11-28 22:40:45 -08:00
|
|
|
self.coordinator = try TestCoordinator(
|
2023-02-13 01:34:41 -08:00
|
|
|
seed: Environment.seedPhrase,
|
2022-11-28 22:40:45 -08:00
|
|
|
walletBirthday: self.birthday,
|
|
|
|
network: self.network
|
|
|
|
)
|
2022-10-31 16:17:05 -07:00
|
|
|
|
2022-11-28 22:40:45 -08:00
|
|
|
try self.coordinator.reset(saplingActivation: self.birthday, branchID: self.branchID, chainName: self.chainName)
|
|
|
|
try self.coordinator.resetBlocks(dataset: .default)
|
2020-06-03 16:18:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
override func tearDownWithError() throws {
|
2021-09-23 06:26:41 -07:00
|
|
|
try super.tearDownWithError()
|
2023-02-16 08:14:31 -08:00
|
|
|
try coordinator.stop()
|
2023-02-02 08:58:12 -08:00
|
|
|
try? FileManager.default.removeItem(at: coordinator.databases.fsCacheDbRoot)
|
2020-06-03 16:18:57 -07:00
|
|
|
try? FileManager.default.removeItem(at: coordinator.databases.dataDB)
|
|
|
|
try? FileManager.default.removeItem(at: coordinator.databases.pendingDB)
|
2023-02-16 08:14:31 -08:00
|
|
|
coordinator = nil
|
2020-06-03 16:18:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func testDarkside() throws {
|
|
|
|
let expectedFirstBlock = (height: BlockHeight(663150), hash: "0000000002fd3be4c24c437bd22620901617125ec2a3a6c902ec9a6c06f734fc")
|
|
|
|
let expectedLastBlock = (height: BlockHeight(663200), hash: "2fc7b4682f5ba6ba6f86e170b40f0aa9302e1d3becb2a6ee0db611ff87835e4a")
|
|
|
|
|
|
|
|
try coordinator.applyStaged(blockheight: expectedLastBlock.height)
|
2022-11-23 10:05:49 -08:00
|
|
|
|
|
|
|
sleep(1)
|
2020-06-03 16:18:57 -07:00
|
|
|
|
|
|
|
let syncExpectation = XCTestExpectation(description: "sync to \(expectedLastBlock.height)")
|
|
|
|
|
2021-09-23 06:26:41 -07:00
|
|
|
try coordinator.sync(
|
|
|
|
completion: { _ in
|
|
|
|
syncExpectation.fulfill()
|
|
|
|
},
|
|
|
|
error: { error in
|
2023-01-18 08:09:04 -08:00
|
|
|
guard let error else {
|
2021-09-23 06:26:41 -07:00
|
|
|
XCTFail("failed with unknown error")
|
|
|
|
return
|
|
|
|
}
|
2023-01-18 08:09:04 -08:00
|
|
|
XCTFail("failed with error: \(error)")
|
2020-06-03 16:18:57 -07:00
|
|
|
return
|
|
|
|
}
|
2021-09-23 06:26:41 -07:00
|
|
|
)
|
2020-06-03 16:18:57 -07:00
|
|
|
|
|
|
|
wait(for: [syncExpectation], timeout: 5)
|
|
|
|
|
2022-10-31 16:17:05 -07:00
|
|
|
let blocksDao = BlockSQLDAO(dbProvider: SimpleConnectionProvider(path: coordinator.databases.dataDB.absoluteString, readonly: false))
|
2020-06-03 16:18:57 -07:00
|
|
|
|
|
|
|
let firstBlock = try blocksDao.block(at: expectedFirstBlock.height)
|
|
|
|
let lastBlock = try blocksDao.block(at: expectedLastBlock.height)
|
|
|
|
|
|
|
|
XCTAssertEqual(firstBlock?.hash.toHexStringTxId(), expectedFirstBlock.hash)
|
|
|
|
XCTAssertEqual(lastBlock?.hash.toHexStringTxId(), expectedLastBlock.hash)
|
|
|
|
}
|
|
|
|
}
|