add timeouts to all tests (#5875)

This commit is contained in:
Stefano Franz
2020-02-11 10:14:05 +00:00
committed by GitHub
parent 1d0918cdde
commit b23af5f0d2
485 changed files with 5655 additions and 5625 deletions

View File

@ -35,33 +35,33 @@ class CordaExceptionTest {
val BOB = Party(BOB_NAME, BOB_KEY)
}
@Test
fun testCordaException() {
@Test(timeout=300_000)
fun testCordaException() {
val ex = assertFailsWith<CordaException> { throw CordaException("BAD THING") }
assertEquals("BAD THING", ex.message)
}
@Test
fun testAttachmentResolutionException() {
@Test(timeout=300_000)
fun testAttachmentResolutionException() {
val ex = assertFailsWith<AttachmentResolutionException> { throw AttachmentResolutionException(TEST_HASH) }
assertEquals(TEST_HASH, ex.hash)
}
@Test
fun testTransactionResolutionException() {
@Test(timeout=300_000)
fun testTransactionResolutionException() {
val ex = assertFailsWith<TransactionResolutionException> { throw TransactionResolutionException(TEST_HASH) }
assertEquals(TEST_HASH, ex.hash)
}
@Test
fun testConflictingAttachmentsRejection() {
@Test(timeout=300_000)
fun testConflictingAttachmentsRejection() {
val ex = assertFailsWith<ConflictingAttachmentsRejection> { throw ConflictingAttachmentsRejection(TX_ID, CONTRACT_CLASS) }
assertEquals(TX_ID, ex.txId)
assertEquals(CONTRACT_CLASS, ex.contractClass)
}
@Test
fun testNotaryChangeInWrongTransactionType() {
@Test(timeout=300_000)
fun testNotaryChangeInWrongTransactionType() {
val ex = assertFailsWith<NotaryChangeInWrongTransactionType> { throw NotaryChangeInWrongTransactionType(TX_ID, ALICE, BOB) }
assertEquals(TX_ID, ex.txId)
assertEquals(ALICE, ex.txNotary)

View File

@ -55,8 +55,8 @@ class AttachmentTest {
}
}
@Test
fun testAttachmentJar() {
@Test(timeout=300_000)
fun testAttachmentJar() {
attachment.openAsJAR().use { jar ->
val entry = jar.nextJarEntry ?: return@use
assertEquals("data.bin", entry.name)
@ -68,8 +68,8 @@ class AttachmentTest {
}
}
@Test
fun testExtractFromAttachment() {
@Test(timeout=300_000)
fun testExtractFromAttachment() {
val resultData = ByteArrayOutputStream().use {
attachment.extractFile("data.bin", it)
it.toByteArray()

View File

@ -9,25 +9,25 @@ class PrivacySaltTest {
private const val SALT_SIZE = 32
}
@Test
fun testValidSalt() {
@Test(timeout=300_000)
fun testValidSalt() {
PrivacySalt(ByteArray(SALT_SIZE) { 0x14 })
}
@Test
fun testInvalidSaltWithAllZeros() {
@Test(timeout=300_000)
fun testInvalidSaltWithAllZeros() {
val ex = assertFailsWith<IllegalArgumentException> { PrivacySalt(ByteArray(SALT_SIZE)) }
assertEquals("Privacy salt should not be all zeros.", ex.message)
}
@Test
fun testTooShortPrivacySalt() {
@Test(timeout=300_000)
fun testTooShortPrivacySalt() {
val ex = assertFailsWith<IllegalArgumentException> { PrivacySalt(ByteArray(SALT_SIZE - 1) { 0x7f }) }
assertEquals("Privacy salt should be 32 bytes.", ex.message)
}
@Test
fun testTooLongPrivacySalt() {
@Test(timeout=300_000)
fun testTooLongPrivacySalt() {
val ex = assertFailsWith<IllegalArgumentException> { PrivacySalt(ByteArray(SALT_SIZE + 1) { 0x7f }) }
assertEquals("Privacy salt should be 32 bytes.", ex.message)
}

View File

@ -14,22 +14,22 @@ class UniqueIdentifierTest {
private val TEST_UUID: UUID = UUID.fromString("00000000-1111-2222-3333-444444444444")
}
@Test
fun testNewInstance() {
@Test(timeout=300_000)
fun testNewInstance() {
val id = UniqueIdentifier(NAME, TEST_UUID)
assertEquals("${NAME}_$TEST_UUID", id.toString())
assertEquals(NAME, id.externalId)
assertEquals(TEST_UUID, id.id)
}
@Test
fun testPrimaryConstructor() {
@Test(timeout=300_000)
fun testPrimaryConstructor() {
val primary = UniqueIdentifier::class.primaryConstructor ?: throw AssertionError("primary constructor missing")
assertThat(primary.call(NAME, TEST_UUID)).isEqualTo(UniqueIdentifier(NAME, TEST_UUID))
}
@Test
fun testConstructors() {
@Test(timeout=300_000)
fun testConstructors() {
assertEquals(1, UniqueIdentifier::class.constructors.size)
val ex = assertFailsWith<IllegalArgumentException> { UniqueIdentifier::class.constructors.first().call() }
assertThat(ex).hasMessage("Callable expects 2 arguments, but 0 were provided.")

View File

@ -6,8 +6,8 @@ import org.junit.Assert.assertEquals
import org.junit.Test
class MerkleTreeTest {
@Test
fun testCreate() {
@Test(timeout=300_000)
fun testCreate() {
val merkle = MerkleTree.getMerkleTree(listOf(SecureHash.allOnesHash, SecureHash.zeroHash))
assertEquals(SecureHash.parse("A5DE9B714ACCD8AFAAABF1CBD6E1014C9D07FF95C2AE154D91EC68485B31E7B5"), merkle.hash)
}

View File

@ -7,31 +7,31 @@ import org.junit.Test
import java.security.MessageDigest
class SecureHashTest {
@Test
fun testSHA256() {
@Test(timeout=300_000)
fun testSHA256() {
val hash = SecureHash.sha256(byteArrayOf(0x64, -0x13, 0x42, 0x3a))
assertEquals(SecureHash.parse("6D1687C143DF792A011A1E80670A4E4E0C25D0D87A39514409B1ABFC2043581F"), hash)
assertEquals("6D1687C143DF792A011A1E80670A4E4E0C25D0D87A39514409B1ABFC2043581F", hash.toString())
}
@Test
fun testPrefix() {
@Test(timeout=300_000)
fun testPrefix() {
val data = byteArrayOf(0x7d, 0x03, -0x21, 0x32, 0x56, 0x47)
val digest = data.digestFor("SHA-256")
val prefix = SecureHash.sha256(data).prefixChars(8)
assertEquals(Hex.toHexString(digest).substring(0, 8).toUpperCase(), prefix)
}
@Test
fun testConcat() {
@Test(timeout=300_000)
fun testConcat() {
val hash1 = SecureHash.sha256(byteArrayOf(0x7d, 0x03, -0x21, 0x32, 0x56, 0x47))
val hash2 = SecureHash.sha256(byteArrayOf(0x63, 0x01, 0x7f, -0x29, 0x1e, 0x3c))
val combined = hash1.hashConcat(hash2)
assertArrayEquals((hash1.bytes + hash2.bytes).digestFor("SHA-256"), combined.bytes)
}
@Test
fun testConstants() {
@Test(timeout=300_000)
fun testConstants() {
assertArrayEquals(SecureHash.zeroHash.bytes, ByteArray(32))
assertArrayEquals(SecureHash.allOnesHash.bytes, ByteArray(32) { 0xFF.toByte() })
}

View File

@ -14,8 +14,8 @@ class SecureRandomTest {
}
}
@Test
fun testNoCordaPRNG() {
@Test(timeout=300_000)
fun testNoCordaPRNG() {
val error = assertFailsWith<NoSuchAlgorithmException> { SecureRandom.getInstance("CordaPRNG") }
assertThat(error).hasMessage("CordaPRNG SecureRandom not available")
}

View File

@ -30,8 +30,8 @@ class TransactionSignatureTest {
}
/** Valid sign and verify. */
@Test
fun `Signature metadata full sign and verify`() {
@Test(timeout=300_000)
fun `Signature metadata full sign and verify`() {
// Create a SignableData object.
val signableData = SignableData(testBytes.sha256(), SignatureMetadata(1, Crypto.findSignatureScheme(keyPair.public).schemeNumberID))
@ -57,8 +57,8 @@ class TransactionSignatureTest {
Crypto.doVerify((testBytes + testBytes).sha256(), transactionSignature)
}
@Test
fun `Verify multi-tx signature`() {
@Test(timeout=300_000)
fun `Verify multi-tx signature`() {
// Deterministically create 5 txIds.
val txIds: List<SecureHash> = IntRange(0, 4).map { byteArrayOf(it.toByte()).sha256() }
// Multi-tx signature.
@ -103,8 +103,8 @@ class TransactionSignatureTest {
}
}
@Test
fun `Verify one-tx signature`() {
@Test(timeout=300_000)
fun `Verify one-tx signature`() {
val txId = "aTransaction".toByteArray().sha256()
// One-tx signature.
val txSignature = try {

View File

@ -7,8 +7,8 @@ import org.junit.Test
import java.security.PublicKey
class TransactionWithSignaturesTest {
@Test
fun txWithSigs() {
@Test(timeout=300_000)
fun txWithSigs() {
val tx = object : TransactionWithSignatures {
override val id: SecureHash
get() = SecureHash.zeroHash

View File

@ -16,13 +16,13 @@ class VerifyTransactionTest {
val serialization = LocalSerializationRule(VerifyTransactionTest::class)
}
@Test
fun success() {
@Test(timeout=300_000)
fun success() {
verifyTransaction(bytesOfResource("txverify/tx-success.bin"))
}
@Test
fun failure() {
@Test(timeout=300_000)
fun failure() {
val e = assertFailsWith<Exception> { verifyTransaction(bytesOfResource("txverify/tx-failure.bin")) }
assertThat(e).hasMessageContaining("Required ${Move::class.java.canonicalName} command")
}