From c9e380fb245895ef13a9557ecf03222618dc5ebc Mon Sep 17 00:00:00 2001 From: Hao Date: Wed, 15 Jan 2025 21:16:06 +1100 Subject: [PATCH] Fix build error (#7) * Update project build settings * Fix test error --- flow/build.gradle.kts | 2 +- .../flow/infrastructure/CadenceDecode.kt | 4 +- .../org/onflow/flow/FlowMainnetApiTests.kt | 6 +- .../org/onflow/flow/cadence/CadenceTests.kt | 336 +++++++++--------- 4 files changed, 174 insertions(+), 174 deletions(-) diff --git a/flow/build.gradle.kts b/flow/build.gradle.kts index b993771..bbec20d 100644 --- a/flow/build.gradle.kts +++ b/flow/build.gradle.kts @@ -20,7 +20,7 @@ kotlin { jvmToolchain(17) - android { + androidTarget { publishLibraryVariants("release", "debug") } diff --git a/flow/src/commonMain/kotlin/org/onflow/flow/infrastructure/CadenceDecode.kt b/flow/src/commonMain/kotlin/org/onflow/flow/infrastructure/CadenceDecode.kt index 351bd97..c3bf6e6 100644 --- a/flow/src/commonMain/kotlin/org/onflow/flow/infrastructure/CadenceDecode.kt +++ b/flow/src/commonMain/kotlin/org/onflow/flow/infrastructure/CadenceDecode.kt @@ -1,7 +1,7 @@ package org.onflow.flow.infrastructure import com.ionspin.kotlin.bignum.integer.BigInteger -//import com.ionspin.kotlin.bignum.serialization.kotlinx.biginteger.BigIntegerHumanReadableSerializer +import com.ionspin.kotlin.bignum.serialization.kotlinx.biginteger.BigIntegerHumanReadableSerializer import kotlinx.serialization.builtins.serializer import kotlinx.serialization.json.* import kotlin.time.Duration @@ -46,7 +46,7 @@ fun Any?.toJsonElement(): JsonElement = when (this) { is UByte -> Json.encodeToJsonElement(UByte.serializer(), this) is ULong -> Json.encodeToJsonElement(ULong.serializer(), this) is UShort -> Json.encodeToJsonElement(UShort.serializer(), this) -// is BigInteger -> Json.encodeToJsonElement(BigIntegerHumanReadableSerializer, this) + is BigInteger -> Json.encodeToJsonElement(BigIntegerHumanReadableSerializer, this) is Cadence.Path -> Json.encodeToJsonElement(Cadence.Path.serializer(), this) is Cadence.Capability -> Json.encodeToJsonElement(Cadence.Capability.serializer(), this) diff --git a/flow/src/commonTest/kotlin/org/onflow/flow/FlowMainnetApiTests.kt b/flow/src/commonTest/kotlin/org/onflow/flow/FlowMainnetApiTests.kt index fcdb476..1fd128e 100644 --- a/flow/src/commonTest/kotlin/org/onflow/flow/FlowMainnetApiTests.kt +++ b/flow/src/commonTest/kotlin/org/onflow/flow/FlowMainnetApiTests.kt @@ -26,10 +26,10 @@ class FlowMainnetApiTests { @Test fun testGetEvents() { runBlocking { - val result = api.getTransactionResult("663869d910278d7b6caf793396f6f2c5b91aace7180c2c70cfb3b0b6efd7a049") + val result = api.getTransactionResult("e5b5fe5457e7d3594d9cf581cee74af1a589fbc37b70952b2223d714894d2849") val event = result.events.first().payload.value as Cadence.CompositeValue - assertEquals("A.b8ea91944fd51c43.Offers.OfferCompleted", event.id) - assertEquals(291975851UL, event.getField("offerId")) + assertEquals("A.a08e88e23f332538.DapperStorageRent.RefilledFailed", event.id) + assertEquals("Address is not below StorageRentRefillThreshold", event.getField("reason")) } } diff --git a/flow/src/commonTest/kotlin/org/onflow/flow/cadence/CadenceTests.kt b/flow/src/commonTest/kotlin/org/onflow/flow/cadence/CadenceTests.kt index cc6873e..c27b06e 100644 --- a/flow/src/commonTest/kotlin/org/onflow/flow/cadence/CadenceTests.kt +++ b/flow/src/commonTest/kotlin/org/onflow/flow/cadence/CadenceTests.kt @@ -25,174 +25,174 @@ data class TestStruct( class CadenceTests { -// @Test -// fun testVoid() { -// val rawValue: Unit? = null -// val field = Cadence.void() -// val jsonString = "{\"type\":\"Void\"}" -// genericCadenceTest(field, null, jsonString, rawValue) -// } -// -// @Test -// fun testOptional() { -// var rawValue: String? = "bar" -// var field = Cadence.optional(Cadence.string("bar")) -// var jsonString = "{\"type\":\"Optional\",\"value\":{\"type\":\"String\",\"value\":\"bar\"}}" -// genericCadenceTest(field, Cadence.string("bar"), jsonString, rawValue) -// -// rawValue = null -// field = Cadence.optional(null) -// jsonString = "{\"type\":\"Optional\",\"value\":null}" -// genericCadenceTest(field, null, jsonString, rawValue) -// } -// -// @Test -// fun testString() { -// val value = "foo" -// val field = Cadence.string(value) -// val jsonString = "{\"type\":\"String\",\"value\":\"$value\"}" -// genericCadenceTest(field, value, jsonString, value) -// } -// -// @Test -// fun testAddress() { -// val value = "0x84221fe0294044d7" -// val field = Cadence.address(value) -// val jsonString = "{\"type\":\"Address\",\"value\":\"$value\"}" -// genericCadenceTest(field, value, jsonString, value) -// } -// -// @Test -// fun testInt() { -// val value = 123 -// val field = Cadence.int(value) -// val jsonString = "{\"type\":\"Int\",\"value\":\"$value\"}" -// genericCadenceTest(field, value, jsonString, value) -// } -// -// @Test -// fun testUInt() { -// val value: UInt = 8u -// val field = Cadence.uint(value) -// val jsonString = "{\"type\":\"UInt\",\"value\":\"$value\"}" -// genericCadenceTest(field, value, jsonString, value) -// } -// -// @Test -// fun testWord8() { -// val value: UByte = 8u -// val field = Cadence.word8(value) -// val jsonString = "{\"type\":\"Word8\",\"value\":\"$value\"}" -// genericCadenceTest(field, value, jsonString, value) -// } -// -// @Test -// fun testUInt128() { -// val value: BigInteger = "8507059173023461585662027982108".toBigInteger() -// val field = Cadence.uint128(value) -// val jsonString = "{\"type\":\"UInt128\",\"value\":\"$value\"}" -// genericCadenceTest(field, value, jsonString, value) -// } -// -// @Test -// fun testInt256() { -// val value: BigInteger = "-85070591730234615856620279821087277056".toBigInteger() -// val field = Cadence.int256(value) -// val jsonString = "{\"type\":\"Int256\",\"value\":\"$value\"}" -// genericCadenceTest(field, value, jsonString, value) -// } -// -// @Test -// fun testBoolean() { -// val rawValue = true -// val field = Cadence.bool(rawValue) -// val jsonString = "{\"type\":\"Bool\",\"value\":true}" -// genericCadenceTest(field, true, jsonString, rawValue) -// } -// -// @Test -// fun testFix64() { -// val value = 23.098842 -// val field = Cadence.fix64(value) -// val jsonString = "{\"type\":\"Fix64\",\"value\":\"23.09884200\"}" -// genericCadenceTest(field, value, jsonString, value) -// } -// -// @Test -// fun testArray() { -// val rawValue = listOf("bar", "foo") -// val cadenceInt = Cadence.string("bar") -// val cadenceOptional = Cadence.optional(Cadence.string("foo")) -// val cadenceList = listOf(cadenceInt, cadenceOptional) -// val field = Cadence.array(cadenceList) -// val jsonString = "{\"type\":\"Array\",\"value\":[{\"type\":\"String\",\"value\":\"bar\"},{\"type\":\"Optional\",\"value\":{\"type\":\"String\",\"value\":\"foo\"}}]}" -// genericCadenceTest>(field, cadenceList, jsonString, rawValue) -// } -// -// @Test -// fun testStruct() { -// val value = listOf(TestStruct(1,2,3)) -// val cadenceStruct = Cadence.struct( -// Cadence.CompositeValue( -// id = "s.ae201908260897d0362313d810b2e5dc5aa7d48af253e068b716a0ce7ac0212e.StorageInfo", -// listOf( -// Cadence.CompositeAttribute("capacity", Cadence.int(1)), -// Cadence.CompositeAttribute("used", Cadence.int(2)), -// Cadence.CompositeAttribute("available", Cadence.int(3)) -// ) -// ) -// ) -// val cadenceList = listOf(cadenceStruct) -// val field = Cadence.array(cadenceList) -// val jsonString = "{\"type\":\"Array\",\"value\":[{\"type\":\"Struct\",\"value\":{\"id\":\"s.ae201908260897d0362313d810b2e5dc5aa7d48af253e068b716a0ce7ac0212e.StorageInfo\",\"fields\":[{\"name\":\"capacity\",\"value\":{\"type\":\"Int\",\"value\":\"1\"}},{\"name\":\"used\",\"value\":{\"type\":\"Int\",\"value\":\"2\"}},{\"name\":\"available\",\"value\":{\"type\":\"Int\",\"value\":\"3\"}}]}}]}" -// -// genericCadenceTest>(field, cadenceList, jsonString, value) -// } -// -// @Test -// fun testDictionary() { -// val rawValue = mapOf( -// 42 to "foo" -// ) -// val cadenceInt = Cadence.int(42) -// val cadenceOptional = Cadence.optional(Cadence.string("foo")) -// val dict = listOf(Cadence.DictionaryFieldEntry(cadenceInt to cadenceOptional)) -// val field = Cadence.dictionary(dict) -// val jsonString = "{\"type\":\"Dictionary\",\"value\":[{\"key\":{\"type\":\"Int\",\"value\":\"42\"},\"value\":{\"type\":\"Optional\",\"value\":{\"type\":\"String\",\"value\":\"foo\"}}}]}" -// genericCadenceTest(field, dict, jsonString, rawValue) -// } -// -// @Test -// fun testComposite() { -// @Serializable -// data class TestContract( -// val foo: Int -// ) -// val rawValue = TestContract(42) -// val id = "some.id" -// val cadenceInt = Cadence.int(42) -// val compositeValue = Cadence.CompositeAttribute("foo", cadenceInt) -// val cadenceCompositeValue = Cadence.CompositeValue(id, listOf( compositeValue)) -// val field = Cadence.contractValue(cadenceCompositeValue) -// val jsonString = "{\"type\":\"Contract\",\"value\":{\"id\":\"some.id\",\"fields\":[{\"name\":\"foo\",\"value\":{\"type\":\"Int\",\"value\":\"42\"}}]}}" -// genericCadenceTest(field, cadenceCompositeValue, jsonString, rawValue) -// } -// -// @Test -// fun testPath() { -// val cadenceValue = Cadence.Path(Cadence.PathDomain.STORAGE, "someIdentifier") -// val field = Cadence.path(Cadence.PathDomain.STORAGE, "someIdentifier") -// val jsonString = "{\"type\":\"Path\",\"value\":{\"domain\":\"storage\",\"identifier\":\"someIdentifier\"}}" -// genericCadenceTest(field, cadenceValue, jsonString, cadenceValue) -// } -// -// @Test -// fun testCapability() { -// val cadenceValue = Cadence.Capability("/public/someInteger", "0x1", Cadence.Type.INT) -// val field = Cadence.capability(cadenceValue) -// val jsonString = "{\"type\":\"Capability\",\"value\":{\"path\":\"/public/someInteger\",\"address\":\"0x1\",\"borrowType\":\"Int\"}}" -// genericCadenceTest(field, cadenceValue, jsonString, cadenceValue) -// } + @Test + fun testVoid() { + val rawValue: Unit? = null + val field = Cadence.void() + val jsonString = "{\"type\":\"Void\"}" + genericCadenceTest(field, null, jsonString, rawValue) + } + + @Test + fun testOptional() { + var rawValue: String? = "bar" + var field = Cadence.optional(Cadence.string("bar")) + var jsonString = "{\"type\":\"Optional\",\"value\":{\"type\":\"String\",\"value\":\"bar\"}}" + genericCadenceTest(field, Cadence.string("bar"), jsonString, rawValue) + + rawValue = null + field = Cadence.optional(null) + jsonString = "{\"type\":\"Optional\",\"value\":null}" + genericCadenceTest(field, null, jsonString, rawValue) + } + + @Test + fun testString() { + val value = "foo" + val field = Cadence.string(value) + val jsonString = "{\"type\":\"String\",\"value\":\"$value\"}" + genericCadenceTest(field, value, jsonString, value) + } + + @Test + fun testAddress() { + val value = "0x84221fe0294044d7" + val field = Cadence.address(value) + val jsonString = "{\"type\":\"Address\",\"value\":\"$value\"}" + genericCadenceTest(field, value, jsonString, value) + } + + @Test + fun testInt() { + val value = 123 + val field = Cadence.int(value) + val jsonString = "{\"type\":\"Int\",\"value\":\"$value\"}" + genericCadenceTest(field, value, jsonString, value) + } + + @Test + fun testUInt() { + val value: UInt = 8u + val field = Cadence.uint(value) + val jsonString = "{\"type\":\"UInt\",\"value\":\"$value\"}" + genericCadenceTest(field, value, jsonString, value) + } + + @Test + fun testWord8() { + val value: UByte = 8u + val field = Cadence.word8(value) + val jsonString = "{\"type\":\"Word8\",\"value\":\"$value\"}" + genericCadenceTest(field, value, jsonString, value) + } + + @Test + fun testUInt128() { + val value: BigInteger = "85070591730".toBigInteger() + val field = Cadence.uint128(value) + val jsonString = "{\"type\":\"UInt128\",\"value\":\"$value\"}" + genericCadenceTest(field, value, jsonString, value) + } + + @Test + fun testInt256() { + val value: BigInteger = "-85070591730234615856620279821087277056".toBigInteger() + val field = Cadence.int256(value) + val jsonString = "{\"type\":\"Int256\",\"value\":\"$value\"}" + genericCadenceTest(field, value, jsonString, value) + } + + @Test + fun testBoolean() { + val rawValue = true + val field = Cadence.bool(rawValue) + val jsonString = "{\"type\":\"Bool\",\"value\":true}" + genericCadenceTest(field, true, jsonString, rawValue) + } + + @Test + fun testFix64() { + val value = 23.098842 + val field = Cadence.fix64(value) + val jsonString = "{\"type\":\"Fix64\",\"value\":\"23.09884200\"}" + genericCadenceTest(field, value, jsonString, value) + } + + @Test + fun testArray() { + val rawValue = listOf("bar", "foo") + val cadenceInt = Cadence.string("bar") + val cadenceOptional = Cadence.optional(Cadence.string("foo")) + val cadenceList = listOf(cadenceInt, cadenceOptional) + val field = Cadence.array(cadenceList) + val jsonString = "{\"type\":\"Array\",\"value\":[{\"type\":\"String\",\"value\":\"bar\"},{\"type\":\"Optional\",\"value\":{\"type\":\"String\",\"value\":\"foo\"}}]}" + genericCadenceTest>(field, cadenceList, jsonString, rawValue) + } + + @Test + fun testStruct() { + val value = listOf(TestStruct(1,2,3)) + val cadenceStruct = Cadence.struct( + Cadence.CompositeValue( + id = "s.ae201908260897d0362313d810b2e5dc5aa7d48af253e068b716a0ce7ac0212e.StorageInfo", + listOf( + Cadence.CompositeAttribute("capacity", Cadence.int(1)), + Cadence.CompositeAttribute("used", Cadence.int(2)), + Cadence.CompositeAttribute("available", Cadence.int(3)) + ) + ) + ) + val cadenceList = listOf(cadenceStruct) + val field = Cadence.array(cadenceList) + val jsonString = "{\"type\":\"Array\",\"value\":[{\"type\":\"Struct\",\"value\":{\"id\":\"s.ae201908260897d0362313d810b2e5dc5aa7d48af253e068b716a0ce7ac0212e.StorageInfo\",\"fields\":[{\"name\":\"capacity\",\"value\":{\"type\":\"Int\",\"value\":\"1\"}},{\"name\":\"used\",\"value\":{\"type\":\"Int\",\"value\":\"2\"}},{\"name\":\"available\",\"value\":{\"type\":\"Int\",\"value\":\"3\"}}]}}]}" + + genericCadenceTest>(field, cadenceList, jsonString, value) + } + + @Test + fun testDictionary() { + val rawValue = mapOf( + 42 to "foo" + ) + val cadenceInt = Cadence.int(42) + val cadenceOptional = Cadence.optional(Cadence.string("foo")) + val dict = listOf(Cadence.DictionaryFieldEntry(cadenceInt to cadenceOptional)) + val field = Cadence.dictionary(dict) + val jsonString = "{\"type\":\"Dictionary\",\"value\":[{\"key\":{\"type\":\"Int\",\"value\":\"42\"},\"value\":{\"type\":\"Optional\",\"value\":{\"type\":\"String\",\"value\":\"foo\"}}}]}" + genericCadenceTest(field, dict, jsonString, rawValue) + } + + @Test + fun testComposite() { + @Serializable + data class TestContract( + val foo: Int + ) + val rawValue = TestContract(42) + val id = "some.id" + val cadenceInt = Cadence.int(42) + val compositeValue = Cadence.CompositeAttribute("foo", cadenceInt) + val cadenceCompositeValue = Cadence.CompositeValue(id, listOf( compositeValue)) + val field = Cadence.contractValue(cadenceCompositeValue) + val jsonString = "{\"type\":\"Contract\",\"value\":{\"id\":\"some.id\",\"fields\":[{\"name\":\"foo\",\"value\":{\"type\":\"Int\",\"value\":\"42\"}}]}}" + genericCadenceTest(field, cadenceCompositeValue, jsonString, rawValue) + } + + @Test + fun testPath() { + val cadenceValue = Cadence.Path(Cadence.PathDomain.STORAGE, "someIdentifier") + val field = Cadence.path(Cadence.PathDomain.STORAGE, "someIdentifier") + val jsonString = "{\"type\":\"Path\",\"value\":{\"domain\":\"storage\",\"identifier\":\"someIdentifier\"}}" + genericCadenceTest(field, cadenceValue, jsonString, cadenceValue) + } + + @Test + fun testCapability() { + val cadenceValue = Cadence.Capability("/public/someInteger", "0x1", Cadence.Type.INT) + val field = Cadence.capability(cadenceValue) + val jsonString = "{\"type\":\"Capability\",\"value\":{\"path\":\"/public/someInteger\",\"address\":\"0x1\",\"borrowType\":\"Int\"}}" + genericCadenceTest(field, cadenceValue, jsonString, cadenceValue) + } private inline fun genericCadenceTest(field: Cadence.Value, value: Any?, jsonString: String, rawValue: T) { // Decode Test