Skip to content
This repository was archived by the owner on May 14, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Tue Sep 03 16:14:18 IDT 2019
#Tue Aug 13 08:37:24 IDT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Expand Down
11 changes: 5 additions & 6 deletions kin-sdk/kin-sdk-lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,26 @@ dependencies {
api 'com.github.kinecosystem:kin-utils-android:1.1'

testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.27.0'
testImplementation 'org.mockito:mockito-core:2.25.0'
testImplementation 'org.hamcrest:hamcrest-library:1.3'
testImplementation 'com.squareup.okhttp3:mockwebserver:3.9.1'
testImplementation 'org.robolectric:robolectric:4.3'
testImplementation 'com.google.code.gson:gson:2.8.5'
testImplementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.1.0'
testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0'
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"

androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'org.mockito:mockito-core:2.27.0'
androidTestImplementation 'org.mockito:mockito-core:2.25.0'
androidTestImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0'
androidTestImplementation 'org.hamcrest:hamcrest-library:1.3'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'org.mockito:mockito-android:2.10.0'
androidTestImplementation 'org.mockito:mockito-android:2.10.0'
androidTestImplementation 'org.mockito:mockito-android:2.25.0'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'org.hamcrest:hamcrest-library:1.3'
androidTestImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
androidTestImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.1.0'
}

//bundle javadocs with published aar
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package kin.sdk;


final class IntegConsts {
public final class IntegConsts {

static final String TEST_NETWORK_URL = BuildConfig.INTEG_TESTS_NETWORK_URL.isEmpty() ?
public static final String TEST_NETWORK_URL = BuildConfig.INTEG_TESTS_NETWORK_URL.isEmpty() ?
Environment.TEST.getNetworkUrl() : BuildConfig.INTEG_TESTS_NETWORK_URL;
static final String TEST_NETWORK_ID = BuildConfig.INTEG_TESTS_NETWORK_PASSPHRASE.isEmpty() ?
public static final String TEST_NETWORK_ID =
BuildConfig.INTEG_TESTS_NETWORK_PASSPHRASE.isEmpty() ?
Environment.TEST.getNetworkPassphrase() : BuildConfig.INTEG_TESTS_NETWORK_PASSPHRASE;
static final String FRIENDBOT_URL = BuildConfig.INTEG_TESTS_NETWORK_FRIENDBOT.isEmpty() ?
public static final String FRIENDBOT_URL = BuildConfig.INTEG_TESTS_NETWORK_FRIENDBOT.isEmpty() ?
"https://friendbot-testnet.kininfrastructure.com" : BuildConfig.INTEG_TESTS_NETWORK_FRIENDBOT;
static final String URL_CREATE_ACCOUNT = FRIENDBOT_URL + "?addr=%s&amount=%d";
static final String URL_FUND = FRIENDBOT_URL + "/fund?addr=%s&amount="; // faucet
static final String URL_WHITELISTING_SERVICE = (BuildConfig.INTEG_TESTS_NETWORK_FRIENDBOT.isEmpty() ?
public static final String URL_CREATE_ACCOUNT = FRIENDBOT_URL + "?addr=%s&amount=%d";
public static final String URL_FUND = FRIENDBOT_URL + "/fund?addr=%s&amount="; // faucet
public static final String URL_WHITELISTING_SERVICE = (BuildConfig.INTEG_TESTS_NETWORK_FRIENDBOT.isEmpty() ?
"http://34.239.111.38:3000" : BuildConfig.INTEG_TESTS_NETWORK_FRIENDBOT)
+ "/whitelist";
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import java.util.concurrent.TimeUnit
/**
* Fake on board for integration test, support creating and funding accounts on stellar test net
*/
internal class FakeKinOnBoard @Throws(IOException::class)
class FakeKinOnBoard @Throws(IOException::class)
constructor() {

private val client: OkHttpClient = OkHttpClient.Builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package kin.sdk

import android.content.Context
import kin.sdk.internal.blockchain.TransactionSender
import kin.sdk.internal.queue.PaymentQueueImpl

class IntegrationTestKinClientInjector(context: Context?, environment: Environment?, appId: String?, storeKey: String?,
private val txSender: TransactionSender? = null,
private val configuration: PaymentQueueImpl.PaymentQueueConfiguration?) :
KinClientInjector(context, environment, appId, storeKey) {


override fun getPaymentQueueConfiguration(): PaymentQueueImpl.PaymentQueueConfiguration {
return configuration
?: PaymentQueueImpl.PaymentQueueConfiguration(Constants.delayBetweenPaymentsMillis, Constants.queueTimeoutMillis, Constants.maxNumOfPayments)
}

override fun getTransactionSender(): TransactionSender {
return txSender ?: super.getTransactionSender()
}

object Constants {
const val delayBetweenPaymentsMillis: Long = 250
const val queueTimeoutMillis: Long = 2000
const val maxNumOfPayments: Int = 5
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class KinAccountIntegrationTest {
private val appId = "1a2c"
private val fee: Int = 100
private val feeInKin: BigDecimal = BigDecimal.valueOf(0.001)
private val appIdVersionPrefix = "1"
private val timeoutDurationSeconds: Long = 15
private val timeoutDurationSecondsLong: Long = 20

Expand Down Expand Up @@ -106,10 +105,10 @@ class KinAccountIntegrationTest {
@LargeTest
@Throws(Exception::class)
fun sendTransaction_WithMemo() {
val (kinAccountSender, kinAccountReceiver) = onboardAccounts(senderFundAmount = 100)
val (kinAccountSender, kinAccountReceiver) = onboardAccounts(kinClient, fakeKinOnBoard, senderFundAmount = 100)

val memo = "fake memo"
val expectedMemo = addAppIdToMemo(memo)
val expectedMemo = addAppIdToMemo(memo, appId)

val transactionId = sendTransactionAndAssert(kinAccountSender, kinAccountReceiver, memo)

Expand All @@ -123,8 +122,8 @@ class KinAccountIntegrationTest {
@LargeTest
@Throws(Exception::class)
fun sendTransaction_WithoutMemoJustPrefix() {
val (kinAccountSender, kinAccountReceiver) = onboardAccounts(senderFundAmount = 100)
val expectedMemo = addAppIdToMemo("")
val (kinAccountSender, kinAccountReceiver) = onboardAccounts(kinClient, fakeKinOnBoard, senderFundAmount = 100)
val expectedMemo = addAppIdToMemo("", appId)
val transactionId = sendTransactionAndAssert(kinAccountSender, kinAccountReceiver, null)
val server = Server(TEST_NETWORK_URL)
val transactionResponse = server.transactions().transaction(transactionId.id())
Expand All @@ -136,10 +135,8 @@ class KinAccountIntegrationTest {
@LargeTest
@Throws(Exception::class)
fun sendTransaction_WithoutMemo() {
val (kinAccountSender, kinAccountReceiver) = onboardAccounts(
senderFundAmount = 100,
kinClient = KinClient(InstrumentationRegistry.getTargetContext(), environment, null))

val (kinAccountSender, kinAccountReceiver) = onboardAccounts(KinClient(InstrumentationRegistry.getTargetContext(), environment, null),
fakeKinOnBoard, senderFundAmount = 100)
val transactionId = sendTransactionAndAssert(kinAccountSender, kinAccountReceiver, null)
val server = Server(TEST_NETWORK_URL)
val transactionResponse = server.transactions().transaction(transactionId.id())
Expand All @@ -151,10 +148,8 @@ class KinAccountIntegrationTest {
@LargeTest
@Throws(Exception::class)
fun sendTransaction_WithoutMemoPrefix() {
val (kinAccountSender, kinAccountReceiver) = onboardAccounts(
senderFundAmount = 100,
kinClient = KinClient(InstrumentationRegistry.getTargetContext(), environment, null))

val (kinAccountSender, kinAccountReceiver) = onboardAccounts(KinClient(InstrumentationRegistry.getTargetContext(), environment, null),
fakeKinOnBoard, senderFundAmount = 100)
val memo = "fake memo"
val transactionId = sendTransactionAndAssert(kinAccountSender, kinAccountReceiver, memo)
val server = Server(TEST_NETWORK_URL)
Expand Down Expand Up @@ -234,7 +229,7 @@ class KinAccountIntegrationTest {
@LargeTest
@Throws(Exception::class)
fun sendTransaction_NotEnoughFee_InsufficientFeeException() {
val (kinAccountSender, kinAccountReceiver) = onboardAccounts()
val (kinAccountSender, kinAccountReceiver) = onboardAccounts(kinClient, fakeKinOnBoard)

expectedEx.expect(InsufficientFeeException::class.java)
val minFee: Int = Math.toIntExact(kinClient.minimumFeeSync)
Expand All @@ -246,7 +241,7 @@ class KinAccountIntegrationTest {
@LargeTest
@Throws(Exception::class)
fun sendWhitelistTransaction_FeeNotReduce() {
val (kinAccountSender, kinAccountReceiver) = onboardAccounts(senderFundAmount = 100)
val (kinAccountSender, kinAccountReceiver) = onboardAccounts(kinClient, fakeKinOnBoard, senderFundAmount = 100)

val minFee: Int = Math.toIntExact(kinClient.minimumFeeSync)
val transaction = kinAccountSender.buildTransactionSync(kinAccountReceiver.publicAddress.orEmpty(),
Expand All @@ -260,7 +255,7 @@ class KinAccountIntegrationTest {
@LargeTest
@Throws(Exception::class)
fun sendWhitelistTransaction_Success() {
val (kinAccountSender, kinAccountReceiver) = onboardAccounts(senderFundAmount = 100)
val (kinAccountSender, kinAccountReceiver) = onboardAccounts(kinClient, fakeKinOnBoard, senderFundAmount = 100)

val minFee: Int = Math.toIntExact(kinClient.minimumFeeSync)
val transaction = kinAccountSender.buildTransactionSync(kinAccountReceiver.publicAddress.orEmpty(),
Expand All @@ -275,7 +270,7 @@ class KinAccountIntegrationTest {
@LargeTest
@Throws(Exception::class)
fun sendTransaction_Success() {
val (kinAccountSender, kinAccountReceiver) = onboardAccounts(senderFundAmount = 100)
val (kinAccountSender, kinAccountReceiver) = onboardAccounts(kinClient, fakeKinOnBoard, senderFundAmount = 100)
val transactionId = sendTransactionAndAssert(kinAccountSender, kinAccountReceiver, "fake memo")
assertNotNull(transactionId)
assertThat(transactionId.id(), not(isEmptyString()))
Expand All @@ -302,7 +297,7 @@ class KinAccountIntegrationTest {
val fundingAmount = BigDecimal("100")
val transactionAmount = BigDecimal("21.123")

val (kinAccountSender, kinAccountReceiver) = onboardAccounts(0, 0)
val (kinAccountSender, kinAccountReceiver) = onboardAccounts(kinClient, fakeKinOnBoard, 0, 0)

//register listeners for testing
val actualPaymentsResults = ArrayList<PaymentInfo>()
Expand All @@ -324,7 +319,7 @@ class KinAccountIntegrationTest {
//send the transaction we want to observe
fakeKinOnBoard.fundWithKin(kinAccountSender.publicAddress.orEmpty(), "100")
val memo = "memo"
val expectedMemo = addAppIdToMemo(memo)
val expectedMemo = addAppIdToMemo(memo, appId)
val transaction = kinAccountSender.buildTransactionSync(kinAccountReceiver.publicAddress.orEmpty(), transactionAmount, fee, memo)
val expectedTransactionId = kinAccountSender.sendTransactionSync(transaction)

Expand All @@ -351,7 +346,7 @@ class KinAccountIntegrationTest {
@LargeTest
@Throws(Exception::class)
fun createPaymentListener_RemoveListener_NoEvents() {
val (kinAccountSender, kinAccountReceiver) = onboardAccounts(senderFundAmount = 100)
val (kinAccountSender, kinAccountReceiver) = onboardAccounts(kinClient, fakeKinOnBoard, senderFundAmount = 100)

val latch = CountDownLatch(1)
val listenerRegistration = kinAccountReceiver.addPaymentListener {
Expand All @@ -368,27 +363,13 @@ class KinAccountIntegrationTest {
@LargeTest
@Throws(Exception::class)
fun sendTransaction_NotEnoughKin_InsufficientKinException() {
val (kinAccountSender, kinAccountReceiver) = onboardAccounts()
val (kinAccountSender, kinAccountReceiver) = onboardAccounts(kinClient, fakeKinOnBoard)

expectedEx.expect(InsufficientKinException::class.java)
val transaction = kinAccountSender.buildTransactionSync(kinAccountReceiver.publicAddress.orEmpty(), BigDecimal("21.123"), fee)
kinAccountSender.sendTransactionSync(transaction)
}

private fun onboardAccounts(senderFundAmount: Int = 0,
receiverFundAmount: Int = 0,
kinClient: KinClient = this.kinClient): Pair<KinAccount, KinAccount> {
val kinAccountSender = kinClient.addAccount()
val kinAccountReceiver = kinClient.addAccount()
fakeKinOnBoard.createAccount(kinAccountSender.publicAddress.orEmpty(), senderFundAmount)
fakeKinOnBoard.createAccount(kinAccountReceiver.publicAddress.orEmpty(), receiverFundAmount)
return Pair(kinAccountSender, kinAccountReceiver)
}

private fun addAppIdToMemo(memo: String): String {
return appIdVersionPrefix.plus("-").plus(appId).plus("-").plus(memo)
}

private fun sendTransactionAndAssert(kinAccountSender: KinAccount, kinAccountReceiver: KinAccount, memo: String?): TransactionId {
val transaction = kinAccountSender.buildTransactionSync(kinAccountReceiver.publicAddress.orEmpty(),
BigDecimal("21.123"), fee, memo)
Expand Down
29 changes: 29 additions & 0 deletions kin-sdk/kin-sdk-lib/src/androidTest/kotlin/kin/sdk/Utils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package kin.sdk

import android.support.test.InstrumentationRegistry
import kin.sdk.internal.blockchain.TransactionSender
import kin.sdk.internal.queue.PaymentQueueImpl


private const val appIdVersionPrefix = "1"

fun onboardAccounts(kinClient: KinClient, fakeKinOnBoard: FakeKinOnBoard, senderFundAmount: Int = 0,
receiverFundAmount: Int = 0): Pair<KinAccount, KinAccount> {
val kinAccountSender = kinClient.addAccount()
val kinAccountReceiver = kinClient.addAccount()
fakeKinOnBoard.createAccount(kinAccountSender.publicAddress.orEmpty(), senderFundAmount)
fakeKinOnBoard.createAccount(kinAccountReceiver.publicAddress.orEmpty(), receiverFundAmount)
return Pair(kinAccountSender, kinAccountReceiver)
}

fun addAppIdToMemo(memo: String, appId: String): String {
return appIdVersionPrefix.plus("-").plus(appId).plus("-").plus(memo)
}

fun getPaymentQueueTestKinClient(environment: Environment, appId: String, txSender: TransactionSender? = null,
configuration: PaymentQueueImpl.PaymentQueueConfiguration? = null): KinClient {
val injector = IntegrationTestKinClientInjector(InstrumentationRegistry.getTargetContext(),
environment, appId, "", txSender, configuration)
return KinClient(injector)
}

Loading