Skip to content

Commit

Permalink
Merge pull request #23 from Topl/DAPP-387
Browse files Browse the repository at this point in the history
feat(Select Chain Test): Adds tests for select chain
  • Loading branch information
KalervoHyyppa authored Oct 31, 2023
2 parents 6847dd2 + 79934e2 commit 286d4f9
Show file tree
Hide file tree
Showing 11 changed files with 296 additions and 140 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,4 @@ web_build_and_host:

file_test:
@reset
@flutter test test/search/desktop_search_test.dart
@flutter test test/requests/open_request_menu_test.dart
@flutter test test/chain/tablet_chain_test.dart
31 changes: 16 additions & 15 deletions lib/blocks/providers/block_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -273,21 +273,6 @@ class BlockNotifier extends StateNotifier<AsyncValue<Map<int, Block>>> {
}
}

//TODO: figure out a better way since a ton of empty blocks means this is taking too long
Future<BlockResponse> getFirstPopulatedBlock() async {
int depth = 0;
final genusClient = ref.read(genusProvider(selectedChain));
var nextBlock = await genusClient.getBlockByDepth(depth: depth);

//check that block has transactions
while (!nextBlock.block.fullBody.hasField(1)) {
depth++;
nextBlock = await genusClient.getBlockByDepth(depth: depth);
}

return nextBlock;
}

Future<BlockResponse> getNextPopulatedBlock({required int height}) async {
var blocks = state.asData?.value;
if (blocks == null) {
Expand Down Expand Up @@ -361,3 +346,19 @@ class BlockNotifier extends StateNotifier<AsyncValue<Map<int, Block>>> {
}
}
}

//TODO: figure out a better way since a ton of empty blocks means this is taking too long
final getFirstPopulatedBlockProvider =
FutureProvider.autoDispose.family<BlockResponse, Chains>((ref, selectedChain) async {
int depth = 0;
final genusClient = ref.read(genusProvider(selectedChain));
var nextBlock = await genusClient.getBlockByDepth(depth: depth);

//check that block has transactions
while (!nextBlock.block.fullBody.hasField(1)) {
depth++;
nextBlock = await genusClient.getBlockByDepth(depth: depth);
}

return nextBlock;
});
7 changes: 7 additions & 0 deletions lib/chain/models/chains.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Package imports:
import 'package:faucet/chain/models/currency.dart';
import 'package:flutter/material.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'chains.freezed.dart';
Expand All @@ -12,26 +13,31 @@ sealed class Chains with _$Chains {
@Default('Toplnet') String networkName,
@Default('mainnet.topl.co') String hostUrl,
@Default(443) int port,
@Default('toplnetKey') String key,
}) = ToplMainnet;
const factory Chains.valhalla_testnet({
@Default('Valhalla') String networkName,
@Default('testnet.topl.network') String hostUrl,
@Default(50051) int port,
@Default('valhallaKey') String key,
}) = ValhallaTestNet;
const factory Chains.private_network({
@Default('Private') String networkName,
@Default('localhost') String hostUrl,
@Default(8080) int port,
@Default('privateKey') String key,
}) = PrivateNetwork;
const factory Chains.dev_network({
@Default('Development') String networkName,
@Default('testnet.topl.tech') String hostUrl,
@Default(443) int port,
@Default('devKey') String key,
}) = DevNetwork;
const factory Chains.mock({
@Default('Mock') String networkName,
@Default('mock') String hostUrl,
@Default(0000) int port,
@Default('mockKey') String key,
}) = MockNetwork;
const factory Chains.custom({
required String chainId,
Expand All @@ -40,6 +46,7 @@ sealed class Chains with _$Chains {
required int port,
required Currency currency,
String? blockExplorerUrl,
@Default('customKey') String key,
}) = CustomNetwork;

factory Chains.fromJson(Map<String, dynamic> json) => _$ChainsFromJson(json);
Expand Down
Loading

0 comments on commit 286d4f9

Please sign in to comment.