Skip to content

Commit

Permalink
Merge pull request #32 from onflow/fix-warnings
Browse files Browse the repository at this point in the history
Fix outstanding warnings
  • Loading branch information
franklywatson authored Feb 18, 2024
2 parents e70647b + 1dd0aa1 commit 34f495e
Show file tree
Hide file tree
Showing 22 changed files with 50 additions and 52 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ tasks {
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
name.set(project.name)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/nftco/flow/sdk/AddressRegistry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class AddressRegistry {
val chains = if (chainId != null) {
arrayOf(chainId)
} else {
FlowChainId.values()
FlowChainId.entries.toTypedArray()
}
chains.forEach { SCRIPT_TOKEN_MAP[it]?.remove(contract) }
return this
Expand Down
7 changes: 3 additions & 4 deletions src/main/kotlin/com/nftco/flow/sdk/Flow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import com.nftco.flow.sdk.impl.FlowAccessApiImpl
import kotlin.reflect.KClass

object Flow {
const val DEFAULT_USER_AGENT = "Flow JVM SDK"
private const val DEFAULT_USER_AGENT = "Flow JVM SDK"

const val DEFAULT_MAX_MESSAGE_SIZE = 16777216
private const val DEFAULT_MAX_MESSAGE_SIZE = 16777216

var OBJECT_MAPPER: ObjectMapper
private var OBJECT_MAPPER: ObjectMapper = ObjectMapper()

var DEFAULT_CHAIN_ID: FlowChainId = FlowChainId.MAINNET
private set
Expand All @@ -27,7 +27,6 @@ object Flow {
private set

init {
OBJECT_MAPPER = ObjectMapper()
OBJECT_MAPPER.registerKotlinModule()
OBJECT_MAPPER.findAndRegisterModules()
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/nftco/flow/sdk/FlowException.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class FlowException : RuntimeException {
constructor(message: String, cause: Throwable) : super(message, cause)
constructor(cause: Throwable) : super(cause)

val executionErrorCode: Int? get() = message?.let { parseErrorCode(it) }
private val executionErrorCode: Int? get() = message?.let { parseErrorCode(it) }

val executionError: FlowError? get() = executionErrorCode?.let { FlowError.forErrorCode(it) }
}
2 changes: 1 addition & 1 deletion src/main/kotlin/com/nftco/flow/sdk/cadence/json-cadence.kt
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ open class DictionaryField(value: Array<DictionaryFieldEntry>) : Field<Array<Dic
constructor(value: Iterable<DictionaryFieldEntry>) : this(value.toList().toTypedArray())

companion object {
fun fromPairs(value: Iterable<Pair<Field<*>, Field<*>>>): DictionaryField {
private fun fromPairs(value: Iterable<Pair<Field<*>, Field<*>>>): DictionaryField {
return DictionaryField(value.map { DictionaryFieldEntry(it) }.toTypedArray())
}

Expand Down
7 changes: 3 additions & 4 deletions src/main/kotlin/com/nftco/flow/sdk/crypto/Crypto.kt
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,14 @@ object Crypto {
fun normalizeSignature(signature: ByteArray, ecCoupleComponentSize: Int): ByteArray {
val (r, s) = extractRS(signature)

val nLen = ecCoupleComponentSize
val paddedSignature = ByteArray(2 * nLen)
val paddedSignature = ByteArray(2 * ecCoupleComponentSize)

val rBytes = r.toByteArray()
val sBytes = s.toByteArray()

// occasionally R/S bytes representation has leading zeroes, so make sure we trim them appropriately
rBytes.copyInto(paddedSignature, max(nLen - rBytes.size, 0), max(0, rBytes.size - nLen))
sBytes.copyInto(paddedSignature, max(2 * nLen - sBytes.size, nLen), max(0, sBytes.size - nLen))
rBytes.copyInto(paddedSignature, max(ecCoupleComponentSize - rBytes.size, 0), max(0, rBytes.size - ecCoupleComponentSize))
sBytes.copyInto(paddedSignature, max(2 * ecCoupleComponentSize - sBytes.size, ecCoupleComponentSize), max(0, sBytes.size - ecCoupleComponentSize))

return paddedSignature
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/nftco/flow/sdk/errors.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.nftco.flow.sdk

val ERROR_CODE_REGEX = Regex(".*\\[Error Code: ([0-9]+)\\].*", RegexOption.DOT_MATCHES_ALL)
val ERROR_CODE_REGEX = Regex(".*\\[Error Code: ([0-9]+)].*", RegexOption.DOT_MATCHES_ALL)

fun parseErrorCode(message: String): Int? = message
.let { ERROR_CODE_REGEX.matchEntire(it) }
Expand Down Expand Up @@ -48,7 +48,7 @@ enum class FlowError(val code: Int) {

companion object {
@JvmStatic
fun forErrorCode(code: Int): FlowError? = FlowError.values()
fun forErrorCode(code: Int): FlowError? = entries
.find { it.code == code }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class AsyncFlowAccessApiImpl(
.build()
)
).thenApply {
Unit
}
}

Expand Down Expand Up @@ -177,6 +176,7 @@ class AsyncFlowAccessApiImpl(
}
}

@Deprecated("Behaves identically to getAccountAtLatestBlock", replaceWith = ReplaceWith("getAccountAtLatestBlock"))
override fun getAccountByAddress(addresss: FlowAddress): CompletableFuture<FlowAccount?> {
return completableFuture(
api.getAccount(
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/com/nftco/flow/sdk/impl/FlowAccessApiImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class FlowAccessApiImpl(
}
}

override fun getTransactionResultById(id: FlowId): FlowTransactionResult? {
override fun getTransactionResultById(id: FlowId): FlowTransactionResult {
val ret = api.getTransactionResult(
Access.GetTransactionRequest.newBuilder()
.setId(id.byteStringValue)
Expand All @@ -138,6 +138,7 @@ class FlowAccessApiImpl(
return FlowTransactionResult.of(ret)
}

@Deprecated("Behaves identically to getAccountAtLatestBlock", replaceWith = ReplaceWith("getAccountAtLatestBlock"))
override fun getAccountByAddress(addresss: FlowAddress): FlowAccount? {
val ret = api.getAccount(
Access.GetAccountRequest.newBuilder()
Expand Down
14 changes: 7 additions & 7 deletions src/main/kotlin/com/nftco/flow/sdk/models.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ enum class FlowTransactionStatus(val num: Int) {

companion object {
@JvmStatic
fun of(num: Int): FlowTransactionStatus = values()
fun of(num: Int): FlowTransactionStatus = entries
.find { it.num == num }
?: throw IllegalArgumentException("Unknown TransactionStatus: $num")
}
Expand All @@ -43,7 +43,7 @@ enum class FlowChainId(

companion object {
@JvmStatic
fun of(id: String): FlowChainId = values()
fun of(id: String): FlowChainId = entries
.find { it.id == id }
?: UNKNOWN
}
Expand All @@ -62,11 +62,11 @@ enum class SignatureAlgorithm(

companion object {
@JvmStatic
fun fromCode(code: Int): SignatureAlgorithm = values()
fun fromCode(code: Int): SignatureAlgorithm = entries
.find { it.code == code } ?: UNKNOWN

@JvmStatic
fun fromCadenceIndex(index: Int): SignatureAlgorithm = values()
fun fromCadenceIndex(index: Int): SignatureAlgorithm = entries
.find { it.index == index } ?: UNKNOWN
}
}
Expand All @@ -86,11 +86,11 @@ enum class HashAlgorithm(

companion object {
@JvmStatic
fun fromCode(code: Int): HashAlgorithm = values()
fun fromCode(code: Int): HashAlgorithm = entries
.find { it.code == code } ?: UNKNOWN

@JvmStatic
fun fromCadenceIndex(index: Int): HashAlgorithm = values()
fun fromCadenceIndex(index: Int): HashAlgorithm = entries
.find { it.index == index } ?: UNKNOWN
}
}
Expand Down Expand Up @@ -253,7 +253,7 @@ data class FlowEvent(
val id: String get() = event.id!!
val event: EventField get() = payload.jsonCadence as EventField

fun <T : Field<*>> getField(name: String): T? = event[name]
private fun <T : Field<*>> getField(name: String): T? = event[name]
@Suppress("UNCHECKED_CAST")
operator fun <T> get(name: String): T? = getField<Field<*>>(name) as T
operator fun contains(name: String): Boolean = name in event
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/com/nftco/flow/sdk/script-dsl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fun FlowAccessApi.simpleFlowScript(block: ScriptBuilder.() -> Unit): FlowScriptR
}

class ScriptBuilder {
var addressRegistry: AddressRegistry = Flow.DEFAULT_ADDRESS_REGISTRY
private var addressRegistry: AddressRegistry = Flow.DEFAULT_ADDRESS_REGISTRY
private var _chainId: FlowChainId = Flow.DEFAULT_CHAIN_ID
private var _script: FlowScript? = null
private var _arguments: MutableList<Field<*>> = mutableListOf()
Expand Down Expand Up @@ -62,6 +62,6 @@ class ScriptBuilder {
val builder = JsonCadenceBuilder()
this.arguments = arguments(builder).toMutableList()
}
fun arg(argument: Field<*>) = _arguments.add(argument)
fun arg(argument: JsonCadenceBuilder.() -> Field<*>) = arg(argument(com.nftco.flow.sdk.cadence.JsonCadenceBuilder()))
private fun arg(argument: Field<*>) = _arguments.add(argument)
fun arg(argument: JsonCadenceBuilder.() -> Field<*>) = arg(argument(JsonCadenceBuilder()))
}
2 changes: 1 addition & 1 deletion src/test/kotlin/com/nftco/flow/sdk/AddressRegistryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test

internal class AddressRegistryTest {
val registry = AddressRegistry()
private val registry = AddressRegistry()

@BeforeEach
fun setup() {
Expand Down
4 changes: 2 additions & 2 deletions src/test/kotlin/com/nftco/flow/sdk/TestUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ object TestUtils {

fun newTestnetAccessApi(): FlowAccessApi = Flow.newAccessApi(TESTNET_HOSTNAME)

val MAINNET_HOSTNAME = "access.mainnet.nodes.onflow.org"
val TESTNET_HOSTNAME = "access.devnet.nodes.onflow.org"
private const val MAINNET_HOSTNAME = "access.mainnet.nodes.onflow.org"
private const val TESTNET_HOSTNAME = "access.devnet.nodes.onflow.org"
}
4 changes: 2 additions & 2 deletions src/test/kotlin/com/nftco/flow/sdk/TransactionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class TransactionTest {
)

@Test
fun `wut`() {
fun wut() {
val account = TestUtils.newTestnetAccessApi().getAccountAtLatestBlock(FlowAddress("0x6bd3869f2631beb3"))
val x = account?.keys?.isEmpty()
account?.keys?.isEmpty()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.nftco.flow.sdk.cadence.fields

import com.fasterxml.jackson.databind.ObjectMapper
import com.nftco.flow.sdk.cadence.*
import org.assertj.core.api.Assertions.assertThatThrownBy
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test

class JsonCadenceBuilderFieldTest {
private val objectMapper = ObjectMapper()
@Test
fun `Test equality for Field with the same type and value`() {
val field1 = SampleField(TYPE_STRING, "value")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package com.nftco.flow.sdk.cadence.fields.composite

import com.nftco.flow.sdk.cadence.*
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class JsonCadenceBuilderNumberFieldTest {
@Test
fun `Test converting NumberField to ULong`() {
val field = NumberField(TYPE_UINT64, "18446744073709551615")
assertEquals(18446744073709551615u.toULong(), field.toULong())
assertEquals(18446744073709551615u, field.toULong())
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class JsonCadenceBuilderUFix64NumberFieldTest {
@Test
fun `Test decoding of UFix64NumberField with large value`() {
val ufix64Field = UFix64NumberField("9876543210.123456789")
assertEquals(9876543210.123456789, ufix64Field.decodeToAny())
assertEquals(9.876543210123457E9, ufix64Field.decodeToAny())
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class FlowTransactionProposalKeyTest {

val proposalKeyBuilder = flowProposalKey.builder()

assertEquals(address.byteStringValue, proposalKeyBuilder.getAddress())
assertEquals(keyIndex, proposalKeyBuilder.getKeyId())
assertEquals(sequenceNumber, proposalKeyBuilder.getSequenceNumber())
assertEquals(address.byteStringValue, proposalKeyBuilder.address)
assertEquals(keyIndex, proposalKeyBuilder.keyId)
assertEquals(sequenceNumber, proposalKeyBuilder.sequenceNumber)
}
}
2 changes: 1 addition & 1 deletion src/test/kotlin/com/nftco/flow/sdk/models/SignerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.nftco.flow.sdk.Hasher
class SignerTest {
lateinit var hasher: Hasher

lateinit var signer: Signer
private lateinit var signer: Signer

@BeforeEach
fun setUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ data class TestAccount(

val flowAddress: FlowAddress get() = FlowAddress(address)

val isValid: Boolean get() = !address.isEmpty()
&& !privateKey.isEmpty()
&& !publicKey.isEmpty()
val isValid: Boolean get() = address.isNotEmpty()
&& privateKey.isNotEmpty()
&& publicKey.isNotEmpty()
&& signAlgo != SignatureAlgorithm.UNKNOWN
&& hashAlgo != HashAlgorithm.UNKNOWN
&& keyIndex >= 0
Expand All @@ -137,14 +137,14 @@ data class Emulator(
)

abstract class AbstractFlowEmulatorExtension : BeforeEachCallback, AfterEachCallback, TestExecutionExceptionHandler {
var process: Process? = null
var pidFile: File? = null
var accessApi: FlowAccessApiImpl? = null
var asyncAccessApi: AsyncFlowAccessApiImpl? = null
private var process: Process? = null
private var pidFile: File? = null
private var accessApi: FlowAccessApiImpl? = null
private var asyncAccessApi: AsyncFlowAccessApiImpl? = null

protected abstract fun launchEmulator(context: ExtensionContext): Emulator

protected fun <T : Annotation> withAnnotatedTestFields(context: ExtensionContext, clazz: Class<T>, block: (Any, Field, T) -> Unit) {
private fun <T : Annotation> withAnnotatedTestFields(context: ExtensionContext, clazz: Class<T>, block: (Any, Field, T) -> Unit) {
val tests = (
context.testInstances.map { it.allInstances.toSet() }.orElseGet { emptySet() }
+ context.testInstance.map { setOf(it) }.orElseGet { emptySet() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ object FlowTestUtil {
.joinToString(separator = "") { ", ${it.key}: contract${i}_${it.key}" }
}
.toList()
val contractAdds = contractList
.mapIndexed { i, _ ->
"""
val contractAdds = List(contractList.size) { i ->
"""
signer.contracts.add(
name: names[$i], code: codes[$i].utf8${contractAddArgs[i]}
)
"""
}.joinToString(separator = "")
}.joinToString(separator = "")

return api.simpleFlowTransaction(
address = account.flowAddress,
Expand Down Expand Up @@ -150,7 +149,7 @@ object FlowTestUtil {
classLoader: ClassLoader = AbstractFlowEmulatorExtension::class.java.classLoader,
pidFilename: String = "flow-emulator.pid"
): Pair<Process, File> {
var flowJson: String? = null
var flowJson: String?

val pidFile = File(System.getProperty("java.io.tmpdir"), pidFilename)
if (pidFile.exists()) {
Expand Down

0 comments on commit 34f495e

Please sign in to comment.