Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples use-cases - get network parameters #86

Merged
merged 6 commits into from
Aug 20, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -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<FlowChainId> response = accessAPI.getNetworkParameters();
if (response instanceof FlowAccessApi.AccessApiCallResponse.Success) {
return ((FlowAccessApi.AccessApiCallResponse.Success<FlowChainId>) response).getData();
} else {
FlowAccessApi.AccessApiCallResponse.Error errorResponse = (FlowAccessApi.AccessApiCallResponse.Error) response;
throw new RuntimeException(errorResponse.getMessage(), errorResponse.getThrowable());
}
}
}

Original file line number Diff line number Diff line change
@@ -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 GetNetworkParametersAccessAPIConnectorTest {

@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'");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.onflow.examples.kotlin.getNetworkParams

import org.onflow.flow.sdk.FlowAccessApi
import org.onflow.flow.sdk.FlowChainId

internal class GetNetworkParametersAccessAPIConnector(
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)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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 GetNetworkParametersAccessAPIConnectorTest {
@FlowTestClient
lateinit var accessAPI: FlowAccessApi

private lateinit var networkParametersConnector: GetNetworkParametersAccessAPIConnector

@BeforeEach
fun setup() {
networkParametersConnector = GetNetworkParametersAccessAPIConnector(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, "flow-emulator")
}
}
Loading