由于测试失败(CryptoUtilsTest 和 NodeH2SecurityTests),无法在 Ubuntu 20.04 上构建 Corda (release/os/4.6)

Cannot build Corda (release/os/4.6) on Ubuntu 20.04 due to failing tests (CryptoUtilsTest & NodeH2SecurityTests)

我正在尝试在 Ubuntu 20.04 上构建 Corda。我有来自 git 存储库 (release/os/4.6) 的最新资源,并且我在主文件夹中 运行 ./gradlew build。但是,构建在两次测试期间失败(请参阅下面的详细说明)。有什么我想念的吗?我应该使用一些特殊的标志来构建 Corda 吗?


首先,测试 test default SecureRandom uses platformSecureRandom 在最后一个断言处失败,即

// in file net/corda/core/crypto/CryptoUtilsTest.kt
fun `test default SecureRandom uses platformSecureRandom`() {
  // [...]
  // Remove Corda Provider again and add it as the first Provider entry.
  Security.removeProvider(CordaSecurityProvider.PROVIDER_NAME)
  Security.insertProviderAt(CordaSecurityProvider(), 1) // This is base-1.
  val secureRandomRegisteredFirstCordaProvider = SecureRandom()
  assertEquals(PlatformSecureRandomService.algorithm, secureRandomRegisteredFirstCordaProvider.algorithm)
}

测试失败的原因是Expected <CordaPRNG>, actual <SHA1PRNG>.。 出于某种原因,如果在插入提供程序之前,我调用了 getServices() 方法,即

,则测试成功
val provider = CordaSecurityProvider()
provider.getServices()
Security.insertProviderAt(provider, 1) // This is base-1.

我还尝试直接从供应商处获取服务 SecureRandom.CordaPRNG,并且它有效,即

println(provider.getService("SecureRandom", "CordaPRNG"))

打印出Corda: SecureRandom.CordaPRNG -> javaClass


其次,测试 h2 server on the host IP requires non-default database password 失败,因为它期望 CouldNotCreateDataSourceException,但它得到 NullPointerException,即

// in file net/corda/node/internal/NodeH2SecurityTests.kt
fun `h2 server on the host IP requires non-default database password`() {
  // [...]
  address = NetworkHostAndPort(InetAddress.getLocalHost().hostAddress, 1080)
  val node = MockNode()

  val exception = assertFailsWith(CouldNotCreateDataSourceException::class) {
    node.startDb()
  }
  // [...]
}

问题是address127.0.1.1:1080,也就是说net/corda/node/internal/Node.kt::startDatabase()没有抛出CouldNotCreateDataSourceException因为条件进入分支

if (!InetAddress.getByName(effectiveH2Settings.address.host).isLoopbackAddress
    && configuration.dataSourceProperties.getProperty("dataSource.password").isBlank()) {
  throw CouldNotCreateDataSourceException()
}

不满意。相反,它在数据库名称给定的路径的父级上调用 toString();父级为空,因此它抛出 NullPointerException,即

val databaseName = databaseUrl.removePrefix(h2Prefix).substringBefore(';')
// databaseName=my_file
val baseDir = Paths.get(databaseName).parent.toString()

不幸的是,从源代码构建 Corda 可能无法工作的原因有很多。

以下是我的建议:

祝你好运。