Restore tests to compiling

This commit is contained in:
Kevin Gorham 2019-03-29 02:05:45 -04:00 committed by Kevin Gorham
parent 72283cee81
commit 7265a793c4
10 changed files with 7 additions and 142 deletions

View File

@ -23,13 +23,6 @@ class CacheDbIntegrationTest {
assertNotNull(dao)
}
@Test
fun testDaoPrepopulated() {
dao.findById(343900).apply {
assertEquals(343900, this?.height)
}
}
companion object {
private lateinit var dao: CompactBlockDao
private lateinit var db: CompactBlockDb

View File

@ -7,7 +7,6 @@ import androidx.room.RoomDatabase
import androidx.test.core.app.ApplicationProvider
import cash.z.wallet.sdk.dao.BlockDao
import cash.z.wallet.sdk.dao.CompactBlockDao
import cash.z.wallet.sdk.dao.NoteDao
import cash.z.wallet.sdk.dao.TransactionDao
import cash.z.wallet.sdk.data.SampleSeedProvider
import cash.z.wallet.sdk.ext.toBlockHeight

View File

@ -7,7 +7,6 @@ import androidx.room.RoomDatabase
import androidx.test.core.app.ApplicationProvider
import cash.z.wallet.sdk.dao.BlockDao
import cash.z.wallet.sdk.dao.CompactBlockDao
import cash.z.wallet.sdk.dao.NoteDao
import cash.z.wallet.sdk.dao.TransactionDao
import cash.z.wallet.sdk.ext.toBlockHeight
import cash.z.wallet.sdk.jni.JniConverter

View File

@ -46,7 +46,7 @@ class IntegrationTest {
downloader = CompactBlockStream("10.0.2.2", 9067, logger)
processor = CompactBlockProcessor(context, converter, cacheDdName, dataDbName, logger = logger)
repository = PollingTransactionRepository(context, dataDbName, 10_000L, converter, logger)
repository = PollingTransactionRepository(context, dataDbName, 10_000L)
wallet = Wallet(
context,
converter,

View File

@ -192,10 +192,10 @@ class ActiveTransactionManager(
// Active Transaction Management
//
suspend fun sendToAddress(zatoshi: Long, toAddress: String) = withContext(Dispatchers.IO) {
suspend fun sendToAddress(zatoshi: Long, toAddress: String, memo: String = "", fromAccountId: Int = 0) = withContext(Dispatchers.IO) {
twig("creating send transaction for zatoshi value $zatoshi")
val activeSendTransaction = create(zatoshi, toAddress.masked())
val transactionId: Long = wallet.createRawSendTransaction(zatoshi, toAddress) // this call takes up to 20 seconds
val transactionId: Long = wallet.createRawSendTransaction(zatoshi, toAddress, memo, fromAccountId) // this call takes up to 20 seconds
// cancellation basically just prevents sending to the network but we cannot cancel after this moment
// well, technically we could still allow cancellation in the split second between this line of code and the upload request but lets not complicate things

View File

@ -1,50 +0,0 @@
package cash.z.wallet.sdk
import io.grpc.ManagedChannel
import io.grpc.ManagedChannelBuilder
import org.junit.jupiter.api.*
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotNull
import cash.z.wallet.sdk.rpc.CompactTxStreamerGrpc
import cash.z.wallet.sdk.rpc.Service
import cash.z.wallet.sdk.rpc.Service.BlockID
import cash.z.wallet.sdk.rpc.Service.BlockRange
import java.util.concurrent.TimeUnit
class GlueTest {
@Test
fun testSanity_transactionParsing() {
val result =
blockingStub.getBlockRange(
BlockRange.newBuilder()
.setStart(heightOf(373070))
.setEnd(heightOf(373085))
.build()
)
assertNotNull(result)
assertEquals(372950, result.next().height)
}
fun heightOf(height: Long): Service.BlockID {
return BlockID.newBuilder().setHeight(height).build()
}
companion object {
lateinit var blockingStub: CompactTxStreamerGrpc.CompactTxStreamerBlockingStub
@BeforeAll
@JvmStatic
fun setup() {
val channel = ManagedChannelBuilder.forAddress("localhost", 9067).usePlaintext().build()
blockingStub = CompactTxStreamerGrpc.newBlockingStub(channel)
}
@AfterAll
@JvmStatic
fun tearDown() {
(blockingStub.channel as ManagedChannel).shutdown().awaitTermination(2000L, TimeUnit.MILLISECONDS)
}
}
}

View File

@ -1,67 +0,0 @@
package cash.z.wallet.sdk
import io.grpc.ManagedChannel
import io.grpc.ManagedChannelBuilder
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import cash.z.wallet.sdk.rpc.CompactTxStreamerGrpc
import cash.z.wallet.sdk.rpc.Service
import cash.z.wallet.sdk.rpc.Service.*
import rpc.WalletDataOuterClass
import java.util.concurrent.TimeUnit
class GrpcTest {
@Test
fun testSanity_protoFilesCreated() {
val name = "Zooko"
val data = WalletDataOuterClass.WalletData.newBuilder()
.setName(name)
.setId(1)
.build()
assertEquals(name, data.name)
}
@Test
fun testSanity_serviceCreated() {
val result = blockingStub.getLatestBlock(ChainSpec.newBuilder().build())
assertNotNull(result)
}
@Test
fun testSanity_transactionParsing() {
val result =
blockingStub.getBlockRange(
BlockRange.newBuilder()
.setStart(heightOf(372950))
.setEnd(heightOf(372954))
.build()
)
assertNotNull(result)
assertEquals(372950, result.next().height)
}
fun heightOf(height: Long): Service.BlockID {
return BlockID.newBuilder().setHeight(height).build()
}
companion object {
lateinit var blockingStub: CompactTxStreamerGrpc.CompactTxStreamerBlockingStub
@BeforeAll
@JvmStatic
fun setup() {
val channel = ManagedChannelBuilder.forAddress("localhost", 9067).usePlaintext().build()
blockingStub = CompactTxStreamerGrpc.newBlockingStub(channel)
}
@AfterAll
@JvmStatic
fun tearDown() {
(blockingStub.channel as ManagedChannel).shutdown().awaitTermination(2000L, TimeUnit.MILLISECONDS)
}
}
}

View File

@ -65,7 +65,7 @@ class CompactBlockDownloaderTest {
}
downloader = CompactBlockStream(grpcServerRule.channel, TroubleshootingTwig())
connection = spy(downloader.connection)
whenever(connection.createStub(any())).thenReturn(blockingStub)
whenever(connection.createStub(anyNotNull())).thenReturn(blockingStub)
}
@AfterEach

View File

@ -1,10 +1,7 @@
package cash.z.wallet.sdk.data
import cash.z.wallet.sdk.dao.WalletTransaction
import com.nhaarman.mockitokotlin2.timeout
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.distinctBy
import kotlinx.coroutines.channels.filter
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
@ -188,7 +185,7 @@ internal class MockSynchronizerTest {
fun `is out of sync about 10% of the time`() = runBlocking {
var count = 0
repeat(100_000) {
if (synchronizer.isOutOfSync()) count++
if (synchronizer.isStale()) count++
}
assertTrue(count < 11_000, "a count of $count is too frequent")
assertTrue(count > 9_000, "a count of $count is too infrequent")

View File

@ -27,12 +27,6 @@ internal class ConversionsTest {
fun `toZecString uses banker's rounding`() {
assertEquals("1.123456", 112345650L.convertZatoshiToZecString())
}
// @Test
// fun `toZec preserves precision when scale is changed`() {
// val desiredFunds = 1.1234567890123456789.toZec(3)
// assertEquals(1.123, desiredFunds.toDouble())
// assertEquals("1.1234567", desiredFunds.setScale(7))
// }
@Test
fun `toZecString honors minimum digits`() {
assertEquals("1.1000", 1.1.toZecString(6, 4))
@ -50,7 +44,7 @@ internal class ConversionsTest {
assertEquals("1", 1.0.toZecString(6, 0))
}
@Test
fun `toZecString defaults are resonable`() {
fun `toZecString defaults are reasonable`() {
// basically check for no extra zeros and banker's rounding
assertEquals("1", 1.0000000.toZecString())
assertEquals("0", 0.0000000.toZecString())
@ -60,7 +54,7 @@ internal class ConversionsTest {
assertEquals("1.000006", 1.0000055.toZecString())
}
@Test
fun `toUsdString defaults are resonable`() {
fun `toUsdString defaults are reasonable`() {
// basically check for no extra zeros and banker's rounding
assertEquals("1.00", 1.0000000.toUsdString())
assertEquals("0", 0.0000000.toUsdString())