Commit 57c0eb89 authored by Malena López-Batista's avatar Malena López-Batista

Merge branch 'release/1.5.6'

parents e9aa207e 1b0eed7b
Pipeline #157963939 passed with stages
in 8 minutes and 51 seconds
......@@ -11,8 +11,8 @@ android {
defaultConfig {
minSdkVersion 24
targetSdkVersion 29
versionCode 15
versionName "1.5.5"
versionCode 16
versionName "1.5.6"
testApplicationId "io.camlcase.javatezos.test"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
......
......@@ -114,10 +114,9 @@ class DexterTokenClientRealTest {
*/
@Test
fun testRealNode() {
testAddLiquidity()
// Let the connection return something
Thread.sleep(15 * 60 * 1000)
// Thread.sleep(15 * 60 * 1000)
}
companion object {
......
......@@ -102,7 +102,7 @@ class FeeEstimatorRealTest {
fun estimateMultipleOp_SmartContract() {
val wallet: Wallet = bakerWallet1!!
val contract: Address = "KT1F2DowtrTnvLTWFSz7iJwYgqyfJvfLnowg" // baker1
val dexterContractAddress: Address = "KT1Var2egEQtc58fCVDpsNJdyzuWZ8yacvW4" // TZG
val dexterContractAddress: Address = "KT197ExFb97FX3Xw4F8K8CE1PmrBxe6h5noi" // TZG
val tezAmount: Tez = Tez(1.0)
val tokenAmount: BigInteger = BigInteger("40")
......
......@@ -80,7 +80,7 @@ class TokenContractRealTest {
fun testRealNode() {
// Let the connection return something
Thread.sleep(15 * 60 * 1000)
// Thread.sleep(15 * 60 * 1000)
}
companion object {
......
......@@ -7,7 +7,7 @@ package io.camlcase.javatezos.test.crypto
import io.camlcase.javatezos.crypto.PublicKey
import io.camlcase.javatezos.crypto.SecretKey
import io.camlcase.javatezos.test.crypto.mnemonic.MnemonicFacadeTest.Companion.MNEMONIC
import io.camlcase.javatezos.test.util.Params.Companion.MNEMONIC
import org.junit.Assert
import org.junit.Test
......
......@@ -6,7 +6,7 @@
package io.camlcase.javatezos.test.crypto
import io.camlcase.javatezos.crypto.SecretKey
import io.camlcase.javatezos.test.crypto.mnemonic.MnemonicFacadeTest.Companion.MNEMONIC
import io.camlcase.javatezos.test.util.Params.Companion.MNEMONIC
import org.junit.Assert
import org.junit.Test
......
......@@ -5,8 +5,9 @@
*/
package io.camlcase.javatezos.test.model
import io.camlcase.javatezos.model.TezosError
import io.camlcase.javatezos.model.Wallet
import io.camlcase.javatezos.test.crypto.mnemonic.MnemonicFacadeTest.Companion.MNEMONIC
import io.camlcase.javatezos.test.util.Params.Companion.MNEMONIC
import org.junit.Assert
import org.junit.Test
......@@ -48,12 +49,10 @@ class WalletTest {
Assert.assertEquals(SECRET_KEY_PASSPHRASE, wallet!!.secretKey.base58Representation)
}
// Will generate a 128 one
@Test
// Will crash
@Test(expected = TezosError::class)
fun testGenerate_Wallet_Strength_Not_Multiple_Of_4() {
val wallet = Wallet(65)
Assert.assertNotNull(wallet)
Assert.assertEquals(96, wallet!!.mnemonic!!.size)
}
@Test
......
......@@ -59,6 +59,24 @@ internal val fakeSignature = object : SignatureProvider {
internal class Params {
companion object {
val MNEMONIC = listOf(
"soccer",
"click",
"number",
"muscle",
"police",
"corn",
"couch",
"bitter",
"gorilla",
"camp",
"camera",
"shove",
"expire",
"praise",
"pill"
)
const val fakeAddress = "tz1ADDRESS"
val fakeFees = OperationFees(Tez(1.0), 200, 300)
val fakeMetadata =
......
......@@ -619,9 +619,23 @@ class TezosNodeClient(
/**
* Retrieve the delegate of a given [Address]
* @return String with the address of the delegate or null if none has been set.
*/
fun getDelegate(address: Address, callback: TezosCallback<String>) {
networkClient.send(GetDelegateRPC(address), callback)
networkClient.send(GetDelegateRPC(address))
.onComplete(
onFailure = { throwable ->
// RPC returns 404 if delegate has not been set
// TODO Change this when related issue is resolved: https://gitlab.com/tezos/tezos/-/issues/831
if (throwable is TezosError && throwable.code == 404) {
callback.onSuccess(null)
} else {
callback.onFailure(throwable.wrap())
}
},
onSuccess = { result ->
callback.onSuccess(result)
})
}
/**
......
......@@ -36,17 +36,15 @@ object MnemonicFacade {
/**
* Generate a mnemonic of the given strength in english.
* Process is heavyweight, recommended to launch this in a computation thread.
* @param strength This must be a multiple of 4.
* @return list of mnemonics, null if strength is not valid
* @param strength This must be > 0 and multiple of 4.
*
* @return list of mnemonics
* @throws TezosError with internal exception with details if strength is not valid
*/
fun generateMnemonic(strength: Int): List<String>? {
fun generateMnemonic(strength: Int): List<String> {
val array = ByteArray(strength)
Random.Default.nextBytes(array)
return try {
mnemonicCode.toMnemonic(array)
} catch (e: TezosError) {
null
}
return mnemonicCode.toMnemonic(array)
}
/**
......
......@@ -33,13 +33,13 @@ import io.camlcase.javatezos.model.Wallet.Companion.invoke
* @param publicKey [PublicKey] encapsulation for the Wallet
* @param secretKey [SecretKey] encapsulation for the Wallet
* @param address A base58check encoded public key hash for the wallet, prefixed with "tz1" which represents an address in the Tezos ecosystem.
* @param mnemonic If this wallet was generated from a mnemonic, a list of english mnemonic words used to generate the wallet with the BIP39 specification, otherwise nil.
* @param mnemonic A list of english mnemonic words used to generate the wallet with the BIP39 specification
*/
data class Wallet(
override val publicKey: PublicKey,
val secretKey: SecretKey,
val address: Address,
val mnemonic: List<String>? = null
val mnemonic: List<String>
) : SignatureProvider {
/**
......@@ -63,7 +63,7 @@ data class Wallet(
*/
operator fun invoke(mnemonic: List<String>? = null, passphrase: String = "") = run {
val validatedMnemonic = if (mnemonic.isNullOrEmpty()) {
MnemonicFacade.generateMnemonic(DEFAULT_SEED_PHRASE_STRENGTH)
MnemonicFacade.generateMnemonic(DEFAULT_SEED_PHRASE_STRENGTH)
} else {
mnemonic
}
......@@ -84,7 +84,8 @@ data class Wallet(
/**
* Constructor: Create a new wallet with a seed phrase of the given [strength] and an optional passphrase.
*
* @param strength Should be multiple of 4
* @param strength Should be > 0 and multiple of 4
* @throws TezosError with internal exception with details if strength is not valid
*/
operator fun invoke(strength: Int, passphrase: String = "") = run {
val mnemonic = MnemonicFacade.generateMnemonic(strength)
......
/**
* # Released under MIT License
*
* Copyright (c) 2020 camlCase
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.camlcase.javatezos.test.crypto.mnemonic
import io.camlcase.javatezos.crypto.mnemonic.MnemonicCode
import io.camlcase.javatezos.model.TezosError
import org.junit.Test
/**
* @see MnemonicCode
*/
class MnemonicCodeTest {
@Test(expected = TezosError::class)
fun testBadEntropyLength() {
val mnemonic = MnemonicCode()
val entropy = ByteArray(27)
mnemonic.toMnemonic(entropy)
}
@Test(expected = TezosError::class)
fun test_BadLength() {
val input = "risk tiger venture dinner age assume float denial penalty hello".split(" ")
MnemonicCode().check(input)
}
@Test(expected = TezosError::class)
fun test_BadWord() {
val input = "risk tiger venture dinner xyzzy assume float denial penalty hello game wing".split(" ")
MnemonicCode().check(input)
}
@Test(expected = TezosError::class)
fun test_BadChecksum() {
val input = "bless cloud wheel regular tiny venue bird web grief security dignity zoo".split(" ")
MnemonicCode().check(input)
}
@Test(expected = TezosError::class)
fun test_EmptyEntropy() {
val mnemonic = MnemonicCode()
val entropy = ByteArray(0)
mnemonic.toMnemonic(entropy)
}
}
......@@ -6,6 +6,8 @@
package io.camlcase.javatezos.test.crypto.mnemonic
import io.camlcase.javatezos.crypto.mnemonic.MnemonicFacade
import io.camlcase.javatezos.model.TezosError
import io.camlcase.javatezos.test.util.Params.Companion.MNEMONIC
import org.junit.Assert
import org.junit.Test
......@@ -89,13 +91,13 @@ internal class MnemonicFacadeTest {
Assert.assertTrue(mnemonic?.size == 24)
}
@Test
@Test(expected = TezosError::class)
fun testGenerateMnemonicWith0Strenght() {
val mnemonic = MnemonicFacade.generateMnemonic(0)
Assert.assertNull(mnemonic)
}
@Test
@Test(expected = TezosError::class)
fun testGenerateMnemonicWithBadStrength() {
val mnemonic = MnemonicFacade.generateMnemonic(17)
Assert.assertNull(mnemonic)
......@@ -114,23 +116,7 @@ internal class MnemonicFacadeTest {
}
companion object {
val MNEMONIC = listOf(
"soccer",
"click",
"number",
"muscle",
"police",
"corn",
"couch",
"bitter",
"gorilla",
"camp",
"camera",
"shove",
"expire",
"praise",
"pill"
)
private const val PASSPHRASE = "TezosKitTests"
private const val EXPECTED_STRING_NO_PASSPHRASE =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment