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

Integration Test Updates, Basic Wallet, Peg-In Riverpod #4

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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
40 changes: 40 additions & 0 deletions integration-test/bridge-consensus/application.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
bridge {
replica {
# the unique number that identifies this replica
replicaId = 0
requests {
# the host where we are listening for requests
host = "[::]"
# the port where we are listening for requests
port = 4000
}
# security configuration
security {
# path to the public key file
publicKeyFile = "/app/wallet/consensusPublicKey.pem"
# path to the private key file
privateKeyFile = "/app/wallet/consensusPrivateKey.pem"
}
consensus {
replicaCount = 1
# map mapping each replica to its corresponding backend
replicas = {
0 = {
publicKeyFile = "/app/wallet/publicKey.pem"
}
}
}
clients {
clientCount = 1
# map mapping each client to its corresponding client
clients = {
0 = {
publicKeyFile = "/app/wallet/clientPublicKey.pem"
host = "bridgepublicapi"
port = 6000
secure = "false"
}
}
}
}
}
4 changes: 4 additions & 0 deletions integration-test/bridge-consensus/bridge-consensus.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM ghcr.io/topl/topl-btc-bridge-consensus:latest

ENTRYPOINT ["sh", "/bridge_custom_launch.sh"]
CMD []
5 changes: 5 additions & 0 deletions integration-test/bridge-consensus/bridge_custom_launch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

export SERIES_ID=$(cat /app/wallet/seriesId.txt)
export GROUP_ID=$(cat /app/wallet/groupId.txt)
/opt/docker/bin/topl-btc-bridge-consensus --topl-host bifrost --btc-url http://bitcoin --zmq-host bitcoin --topl-wallet-seed-file /app/wallet/topl-wallet.json --topl-wallet-db /app/wallet/topl-wallet.db --btc-peg-in-seed-file /app/btc-wallet/peg-in-wallet.json --btc-wallet-seed-file /app/btc-wallet/btc-wallet.json --abtc-group-id $GROUP_ID --abtc-series-id $SERIES_ID --config-file /application.conf
31 changes: 31 additions & 0 deletions integration-test/bridge-public-api/application.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
bridge {
client {
# the unique number that identifies this client
clientId = 0
responses {
# the host where we are listening for responses
host = "[::]"
# the port where we are listening for responses
port = 6000
}
# security configuration
security {
# path to the public key file
publicKeyFile = "/app/wallet/clientPublicKey.pem"
# path to the private key file
privateKeyFile = "/app/wallet/clientPrivateKey.pem"
}
consensus {
replicaCount = 1
# map mapping each replica to its corresponding backend
replicas = {
0 = {
publicKeyFile = "/app/wallet/consensusPublicKey.pem"
host = "bridgeconsensus"
port = 4000
secure = "false"
}
}
}
}
}
55 changes: 35 additions & 20 deletions integration-test/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,10 @@ services:
- "18444:18444"
- "18443:18443"
- "28332:28332"
bridge:
image: toplprotocol/topl-btc-bridge:latest
command:
- "--topl-host"
- "bifrost"
- "--btc-url"
- "http://bitcoin"
- "--zmq-host"
- "bitcoin"
- "--topl-wallet-seed-file"
- "/app/wallet/topl-wallet.json"
- "--topl-wallet-db"
- "/app/wallet/topl-wallet.db"
- "--btc-peg-in-seed-file"
- "/app/btc-wallet/peg-in-wallet.json"
- "--btc-wallet-seed-file"
- "/app/btc-wallet/btc-wallet.json"
ports:
- "4000:4000"
bridgeconsensus:
build:
context: bridge-consensus
dockerfile: bridge-consensus.Dockerfile
depends_on:
bifrost:
condition: service_started
Expand All @@ -39,12 +24,42 @@ services:
- wallet:/app/wallet
- ./peg-in-wallet.json:/app/btc-wallet/peg-in-wallet.json
- ./btc-wallet.json:/app/btc-wallet/btc-wallet.json
- ./bridge-consensus/bridge_custom_launch.sh:/bridge_custom_launch.sh
- ./bridge-consensus/application.conf:/application.conf
bridgepublicapi:
image: ghcr.io/topl/topl-btc-bridge-public-api:latest
command:
- "--config-file"
- "/application.conf"
ports:
- "5000:5000"
depends_on:
bifrost:
condition: service_started
bitcoin:
condition: service_started
bridge_init:
condition: service_completed_successfully
volumes:
- wallet:/app/wallet
- ./bridge-public-api/application.conf:/application.conf
envoy:
build:
context: envoy
dockerfile: envoy.Dockerfile
ports:
- "9094:9094"
links:
- bifrost
volumes:
- ./envoy/config.yaml:/etc/envoy/config.yaml
bridge_init:
build:
context: .
context: init
dockerfile: bridge-init.Dockerfile
volumes:
- wallet:/app/wallet
- ./init/bridge_init.sh:/bridge_init.sh
depends_on:
- bifrost

Expand Down
55 changes: 55 additions & 0 deletions integration-test/envoy/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
static_resources:
listeners:
- name: listener_0
address:
socket_address: { address: 0.0.0.0, port_value: 9094 }
filter_chains:
- filters:
- name: envoy.filters.network.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
codec_type: auto
stat_prefix: ingress_http
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- match: { prefix: "/" }
route:
cluster: greeter_service
max_stream_duration:
grpc_timeout_header_max: 0s
cors:
allow_origin_string_match:
- prefix: "*"
allow_methods: GET, PUT, DELETE, POST, OPTIONS
allow_headers: keep-alive,user-agent,cache-control,content-type,content-transfer-encoding,custom-header-1,x-accept-content-transfer-encoding,x-accept-response-streaming,x-user-agent,x-grpc-web,grpc-timeout
max_age: "1728000"
expose_headers: custom-header-1,grpc-status,grpc-message
http_filters:
- name: envoy.filters.http.grpc_web
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.grpc_web.v3.GrpcWeb
- name: envoy.filters.http.cors
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.cors.v3.Cors
- name: envoy.filters.http.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
clusters:
- name: greeter_service
connect_timeout: 0.25s
type: logical_dns
http2_protocol_options: {}
lb_policy: round_robin
load_assignment:
cluster_name: cluster_0
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: bifrost
port_value: 9084
6 changes: 6 additions & 0 deletions integration-test/envoy/envoy.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM envoyproxy/envoy-alpine:v1.21-latest

RUN apk update
RUN apk add ngrep

CMD ["envoy", "-l","trace", "-c","/etc/envoy/config.yaml"]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM eclipse-temurin:11-jdk

RUN apt update \
&& apt install --no-install-recommends -y curl gzip wget \
&& apt install --no-install-recommends -y curl gzip wget openssl \
&& apt-get clean

RUN mkdir /bitcoin && wget -qO- https://bitcoin.org/bin/bitcoin-core-27.0/bitcoin-27.0-x86_64-linux-gnu.tar.gz | tar xvz -C /bitcoin && install -m 0755 -o root -g root -t /usr/local/bin /bitcoin/bitcoin-27.0/bin/*
Expand All @@ -21,7 +21,7 @@ USER 1001:0
RUN cs setup --yes
RUN cs fetch -r https://s01.oss.sonatype.org/content/repositories/releases co.topl:brambl-cli_2.13:2.0.0-beta5

COPY bridge_init.sh /bridge_init.sh
COPY extract_group_series_id.sh /extract_group_series_id.sh

ENTRYPOINT ["sh", "/bridge_init.sh"]
CMD []
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export TOPL_WALLET_MNEMONIC=/app/wallet/topl-mnemonic.txt

rm -f $TOPL_WALLET_DB $TOPL_WALLET_JSON $TOPL_WALLET_MNEMONIC

openssl ecparam -name secp256k1 -genkey -noout -out /app/wallet/consensusPrivateKey.pem
openssl ec -in /app/wallet/consensusPrivateKey.pem -pubout -out /app/wallet/consensusPublicKey.pem
openssl ecparam -name secp256k1 -genkey -noout -out /app/wallet/clientPrivateKey.pem
openssl ec -in /app/wallet/clientPrivateKey.pem -pubout -out /app/wallet/clientPublicKey.pem

bitcoin-cli -regtest -named -rpcconnect=bitcoin -rpcuser=bitcoin -rpcpassword=password createwallet wallet_name=testwallet
export BTC_ADDRESS=`bitcoin-cli -rpcconnect=bitcoin -rpcuser=$BTC_USER -rpcpassword=$BTC_PASSWORD -rpcwallet=testwallet -regtest getnewaddress`
echo BTC Address: $BTC_ADDRESS
Expand All @@ -23,7 +28,9 @@ export ADDRESS=$(brambl-cli wallet current-address --walletdb $TOPL_WALLET_DB)

cd /app

brambl-cli simple-transaction create --from-fellowship nofellowship --from-template genesis --from-interaction 1 --change-fellowship nofellowship --change-template genesis --change-interaction 1 -t $ADDRESS -w $TOPL_WALLET_PASSWORD -o genesisTx.pbuf -n private -a 100000 -h bifrost --port 9084 --keyfile $TOPL_WALLET_JSON --walletdb $TOPL_WALLET_DB --fee 10 --transfer-token lvl
echo "Genesis UTxOs"
brambl-cli genus-query utxo-by-address --from-fellowship nofellowship --from-template genesis --host bifrost --port 9084 --secure false --walletdb $TOPL_WALLET_DB
brambl-cli simple-transaction create --from-fellowship nofellowship --from-template genesis --from-interaction 1 --change-fellowship nofellowship --change-template genesis --change-interaction 1 -t $ADDRESS -w $TOPL_WALLET_PASSWORD -o genesisTx.pbuf -n private -a 10000 -h bifrost --port 9084 --keyfile $TOPL_WALLET_JSON --walletdb $TOPL_WALLET_DB --fee 10 --transfer-token lvl
brambl-cli tx prove -i genesisTx.pbuf --walletdb $TOPL_WALLET_DB --keyfile $TOPL_WALLET_JSON -w $TOPL_WALLET_PASSWORD -o genesisTxProved.pbuf
export GROUP_UTXO=$(brambl-cli tx broadcast -i genesisTxProved.pbuf -h bifrost --port 9084 --secure false)
echo "GROUP_UTXO: $GROUP_UTXO"
Expand All @@ -45,3 +52,5 @@ export ASSET_UTXO=$(brambl-cli tx broadcast -i seriesMintingTxProved.pbuf -h bif
echo "ASSET_UTXO: $ASSET_UTXO"
until brambl-cli genus-query utxo-by-address --host bifrost --port 9084 --secure false --walletdb $TOPL_WALLET_DB; do sleep 5; done
brambl-cli wallet balance --from-fellowship self --from-template default --walletdb $TOPL_WALLET_DB --host bifrost --port 9084 --secure false
echo $(brambl-cli genus-query utxo-by-address -h bifrost --port 9084 --secure false --walletdb $TOPL_WALLET_DB | /bin/bash /extract_group_series_id.sh "Group Constructor") > /app/wallet/groupId.txt
echo $(brambl-cli genus-query utxo-by-address -h bifrost --port 9084 --secure false --walletdb $TOPL_WALLET_DB | /bin/bash /extract_group_series_id.sh "Series Constructor") > /app/wallet/seriesId.txt
18 changes: 18 additions & 0 deletions integration-test/init/extract_group_series_id.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

#!/bin/bash

TOKEN_TYPE=$1
# Extract the Id of series or group tokens from the input

while IFS= read -r line; do
# Check if the line contains "Type" and if the next line should be read
if [[ $line == *"Type"* && $line == *$TOKEN_TYPE* ]]; then
read_next_line=true
elif [ "$read_next_line" = true ]; then
# If the next line should be read and contains "Id", extract and print the Id
if [[ $line == "Id"* ]]; then
echo "$line" | awk '{print $NF}'
fi
read_next_line=false
fi
done < /dev/stdin # Read from stdin
23 changes: 23 additions & 0 deletions lib/features/bridge/providers/rpc_channel.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:apparatus_wallet/utils/rpc/channel_factory_web.dart';
import 'package:grpc/grpc_connection_interface.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'rpc_channel.g.dart';

@riverpod
class RpcChannel extends _$RpcChannel {
@override
RpcChannelState build() {
// TODO: User Provided
final channel = makeChannel("localhost", 9094, false);
return RpcChannelState(nodeRpcChannel: channel, genusRpcChannel: channel);
}
}

class RpcChannelState {
final ClientChannelBase nodeRpcChannel;
final ClientChannelBase genusRpcChannel;

RpcChannelState(
{required this.nodeRpcChannel, required this.genusRpcChannel});
}
40 changes: 40 additions & 0 deletions lib/features/bridge/providers/service_kit.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'package:brambldart/brambldart.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:servicekit/servicekit.dart';

part 'service_kit.freezed.dart';

part 'service_kit.g.dart';

@riverpod
class ServiceKit extends _$ServiceKit {
@override
Future<ServiceKitState> build() async {
final storage = await StorageApi.init();
return ServiceKitState.base(storage);
}
}

@freezed
class ServiceKitState with _$ServiceKitState {
factory ServiceKitState(
{required StorageApi storageApi,
required ContractStorageApi contractStorageApi,
required FellowshipStorageApi fellowshipStorageApi,
required WalletApi walletApi,
required WalletStateApi walletStateApi}) = _ServiceKitState;

factory ServiceKitState.base(StorageApi storage) {
final contractStorage = ContractStorageApi(storage.sembast);
final fellowshipStorage = FellowshipStorageApi(storage.sembast);
final walletState = WalletStateApi(storage.sembast, storage.secureStorage);
final wallet = walletState.api;
return ServiceKitState(
storageApi: storage,
contractStorageApi: contractStorage,
fellowshipStorageApi: fellowshipStorage,
walletStateApi: walletState,
walletApi: wallet);
}
}
Loading