From b3820e3d750beefa571812355766cd4a762c59b1 Mon Sep 17 00:00:00 2001 From: Lea Lobanov Date: Tue, 20 Aug 2024 01:52:45 +0700 Subject: [PATCH 1/6] Get network parameters - Kotlin example --- .../GetNetworkParametersAccessAPIConnector.kt | 16 ++++++++++ ...NetworkParametersAccessAPIConnectorTest.kt | 32 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnector.kt create mode 100644 kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.kt diff --git a/kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnector.kt b/kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnector.kt new file mode 100644 index 0000000..2c19c6c --- /dev/null +++ b/kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnector.kt @@ -0,0 +1,16 @@ +package org.onflow.examples.kotlin.getNetworkParams + +import org.onflow.flow.sdk.FlowAccessApi +import org.onflow.flow.sdk.FlowChainId + +internal class GetNetworkParametersAPIConnector( + private val accessAPI: FlowAccessApi +) { + fun getNetworkParameters(): FlowChainId { + return when (val response = accessAPI.getNetworkParameters()) { + is FlowAccessApi.AccessApiCallResponse.Success -> response.data + is FlowAccessApi.AccessApiCallResponse.Error -> throw Exception(response.message, response.throwable) + } + } +} + diff --git a/kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.kt b/kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.kt new file mode 100644 index 0000000..2542b67 --- /dev/null +++ b/kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.kt @@ -0,0 +1,32 @@ +package org.onflow.examples.kotlin.getNetworkParams + +import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import org.onflow.flow.common.test.FlowEmulatorProjectTest +import org.onflow.flow.common.test.FlowTestClient +import org.onflow.flow.sdk.FlowAccessApi +import org.onflow.flow.sdk.FlowChainId + +@FlowEmulatorProjectTest(flowJsonLocation = "../flow/flow.json") +internal class GetNetworkParametersAPIConnectorTest { + + @FlowTestClient + lateinit var accessAPI: FlowAccessApi + + private lateinit var networkParametersConnector: GetNetworkParametersAPIConnector + + @BeforeEach + fun setup() { + networkParametersConnector = GetNetworkParametersAPIConnector(accessAPI) + } + + @Test + fun `Can fetch network parameters`() { + val networkParams: FlowChainId = networkParametersConnector.getNetworkParameters() + assertNotNull(networkParams, "Network parameters should not be null") + assertTrue(networkParams.id.isNotEmpty(), "Network parameters should have a valid ID") + assertEquals(networkParams, FlowChainId.EMULATOR) + assertEquals(networkParams.id, "EMULATOR") + } +} From d108a41e2dcdee1075b2e467d0143275ac012369 Mon Sep 17 00:00:00 2001 From: Lea Lobanov Date: Tue, 20 Aug 2024 01:53:44 +0700 Subject: [PATCH 2/6] Get network parameters - Kotlin example --- .../GetNetworkParametersAccessAPIConnectorTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.kt b/kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.kt index 2542b67..14c7264 100644 --- a/kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.kt +++ b/kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.kt @@ -27,6 +27,6 @@ internal class GetNetworkParametersAPIConnectorTest { assertNotNull(networkParams, "Network parameters should not be null") assertTrue(networkParams.id.isNotEmpty(), "Network parameters should have a valid ID") assertEquals(networkParams, FlowChainId.EMULATOR) - assertEquals(networkParams.id, "EMULATOR") + assertEquals(networkParams.id, "flow-emulator") } } From fffcf984e1a7131332e2a14680397b06bd7c5fb9 Mon Sep 17 00:00:00 2001 From: Lea Lobanov Date: Tue, 20 Aug 2024 02:10:21 +0700 Subject: [PATCH 3/6] Get network parameters - Java example --- ...etNetworkParametersAccessAPIConnector.java | 24 ++++++++++++++ ...tworkParametersAccessAPIConnectorTest.java | 33 +++++++++++++++++++ .../GetNetworkParametersAccessAPIConnector.kt | 2 +- ...NetworkParametersAccessAPIConnectorTest.kt | 6 ++-- 4 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 java-example/src/main/java/org/onflow/examples/java/getNetworkParams/GetNetworkParametersAccessAPIConnector.java create mode 100644 java-example/src/test/java/org/onflow/examples/java/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.java diff --git a/java-example/src/main/java/org/onflow/examples/java/getNetworkParams/GetNetworkParametersAccessAPIConnector.java b/java-example/src/main/java/org/onflow/examples/java/getNetworkParams/GetNetworkParametersAccessAPIConnector.java new file mode 100644 index 0000000..9611ac2 --- /dev/null +++ b/java-example/src/main/java/org/onflow/examples/java/getNetworkParams/GetNetworkParametersAccessAPIConnector.java @@ -0,0 +1,24 @@ +package org.onflow.examples.java.getNetworkParams; + +import org.onflow.flow.sdk.FlowAccessApi; +import org.onflow.flow.sdk.FlowChainId; + +public class GetNetworkParametersAccessAPIConnector { + + private final FlowAccessApi accessAPI; + + public GetNetworkParametersAccessAPIConnector(FlowAccessApi accessAPI) { + this.accessAPI = accessAPI; + } + + public FlowChainId getNetworkParameters() { + FlowAccessApi.AccessApiCallResponse response = accessAPI.getNetworkParameters(); + if (response instanceof FlowAccessApi.AccessApiCallResponse.Success) { + return ((FlowAccessApi.AccessApiCallResponse.Success) response).getData(); + } else { + FlowAccessApi.AccessApiCallResponse.Error errorResponse = (FlowAccessApi.AccessApiCallResponse.Error) response; + throw new RuntimeException(errorResponse.getMessage(), errorResponse.getThrowable()); + } + } +} + diff --git a/java-example/src/test/java/org/onflow/examples/java/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.java b/java-example/src/test/java/org/onflow/examples/java/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.java new file mode 100644 index 0000000..d54223d --- /dev/null +++ b/java-example/src/test/java/org/onflow/examples/java/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.java @@ -0,0 +1,33 @@ +package org.onflow.examples.java.getNetworkParams; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.onflow.flow.common.test.FlowEmulatorProjectTest; +import org.onflow.flow.common.test.FlowTestClient; +import org.onflow.flow.sdk.FlowAccessApi; +import org.onflow.flow.sdk.FlowChainId; + +import static org.junit.jupiter.api.Assertions.*; + +@FlowEmulatorProjectTest(flowJsonLocation = "../flow/flow.json") +public class GetNetworkParametersAPIConnectorTest { + + @FlowTestClient + private FlowAccessApi accessAPI; + + private GetNetworkParametersAccessAPIConnector networkParametersConnector; + + @BeforeEach + public void setup() { + networkParametersConnector = new GetNetworkParametersAccessAPIConnector(accessAPI); + } + + @Test + public void canFetchNetworkParameters() { + FlowChainId networkParams = networkParametersConnector.getNetworkParameters(); + assertNotNull(networkParams, "Network parameters should not be null"); + assertFalse(networkParams.getId().isEmpty(), "Network parameters should have a valid ID"); + assertEquals(FlowChainId.EMULATOR, networkParams, "Network parameters should match EMULATOR"); + assertEquals("flow-emulator", networkParams.getId(), "Network ID should be 'flow-emulator'"); + } +} diff --git a/kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnector.kt b/kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnector.kt index 2c19c6c..4afe92c 100644 --- a/kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnector.kt +++ b/kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnector.kt @@ -3,7 +3,7 @@ package org.onflow.examples.kotlin.getNetworkParams import org.onflow.flow.sdk.FlowAccessApi import org.onflow.flow.sdk.FlowChainId -internal class GetNetworkParametersAPIConnector( +internal class GetNetworkParametersAccessAPIConnector( private val accessAPI: FlowAccessApi ) { fun getNetworkParameters(): FlowChainId { diff --git a/kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.kt b/kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.kt index 14c7264..059e95e 100644 --- a/kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.kt +++ b/kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.kt @@ -9,16 +9,16 @@ import org.onflow.flow.sdk.FlowAccessApi import org.onflow.flow.sdk.FlowChainId @FlowEmulatorProjectTest(flowJsonLocation = "../flow/flow.json") -internal class GetNetworkParametersAPIConnectorTest { +internal class GetNetworkParametersAccessAPIConnectorTest { @FlowTestClient lateinit var accessAPI: FlowAccessApi - private lateinit var networkParametersConnector: GetNetworkParametersAPIConnector + private lateinit var networkParametersConnector: GetNetworkParametersAccessAPIConnector @BeforeEach fun setup() { - networkParametersConnector = GetNetworkParametersAPIConnector(accessAPI) + networkParametersConnector = GetNetworkParametersAccessAPIConnector(accessAPI) } @Test From 71b47fbc43b53ce98059c0e92a1659adfdcc4919 Mon Sep 17 00:00:00 2001 From: Lea Lobanov Date: Tue, 20 Aug 2024 02:10:36 +0700 Subject: [PATCH 4/6] Get network parameters - Java example --- .../GetNetworkParametersAccessAPIConnectorTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java-example/src/test/java/org/onflow/examples/java/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.java b/java-example/src/test/java/org/onflow/examples/java/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.java index d54223d..0478b8d 100644 --- a/java-example/src/test/java/org/onflow/examples/java/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.java +++ b/java-example/src/test/java/org/onflow/examples/java/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.java @@ -10,7 +10,7 @@ import static org.junit.jupiter.api.Assertions.*; @FlowEmulatorProjectTest(flowJsonLocation = "../flow/flow.json") -public class GetNetworkParametersAPIConnectorTest { +public class GetNetworkParametersAccessAPIConnectorTest { @FlowTestClient private FlowAccessApi accessAPI; From 4c670feb0ce8e9f96a32ff5cffcce7746f6293b0 Mon Sep 17 00:00:00 2001 From: Lea Lobanov Date: Tue, 20 Aug 2024 02:14:50 +0700 Subject: [PATCH 5/6] Get network parameters - Java example --- .../getNetworkParams/GetNetworkParametersAccessAPIConnector.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnector.kt b/kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnector.kt index 4afe92c..8f7f169 100644 --- a/kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnector.kt +++ b/kotlin-example/src/main/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnector.kt @@ -13,4 +13,3 @@ internal class GetNetworkParametersAccessAPIConnector( } } } - From 4fff2c56bd0418981abf8abf5043d9d196690aec Mon Sep 17 00:00:00 2001 From: Lea Lobanov Date: Tue, 20 Aug 2024 02:17:00 +0700 Subject: [PATCH 6/6] Linting --- .../GetNetworkParametersAccessAPIConnectorTest.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.kt b/kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.kt index 059e95e..c89ff30 100644 --- a/kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.kt +++ b/kotlin-example/src/test/kotlin/org/onflow/examples/kotlin/getNetworkParams/GetNetworkParametersAccessAPIConnectorTest.kt @@ -10,7 +10,6 @@ import org.onflow.flow.sdk.FlowChainId @FlowEmulatorProjectTest(flowJsonLocation = "../flow/flow.json") internal class GetNetworkParametersAccessAPIConnectorTest { - @FlowTestClient lateinit var accessAPI: FlowAccessApi