Skip to content

feat: add multi wallet support #31

feat: add multi wallet support

feat: add multi wallet support #31

Workflow file for this run

name: Functional Tests
on:
push:
tags: ['v*']
pull_request:
branches: ['main']
workflow_dispatch:
jobs:
functional-tests:
defaults:
run:
working-directory: './.github/examples/'
shell: bash
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: 'Build dkc script'
uses: actions/setup-go@v4
with:
go-version-file: './go.mod'
- run: go build ../../
- name: 'Install ethdo'
run: |
go install "github.com/wealdtech/ethdo@$ethdo_version"
env:
ethdo_version: 'v1.28.5'
- name: 'Get Original Wallets'
run: |
#FIXME set -e is the default bash flag(this is not obvious btw need to fix)
account_pubkey_map='{}'
accounts_list=$(ethdo wallet --base-dir "${input_distributed_wallets_path}/old1" accounts --wallet="$wallet_name" | tr '\n' ' ')
echo -e "# Original Keys"
for i in $(echo $accounts_list); do
original_key=$(ethdo account --base-dir "${input_distributed_wallets_path}/old1/" info --account "$wallet_name/$i" | grep -i "Composite public key:" | awk '{print $NF}')
if [[ -z "$original_key" ]]; then
echo -e "Account [$i]: ${red}Fail${nc} (len($original_key) == 0)"
exit 1
fi
#Tricky way to create hashmap(bash declare is not working here)
account_pubkey_map=$(echo ${account_pubkey_map} | jq -c --arg account $i --arg key $original_key '. + { ($account): $key }')
echo -e "Account [$i]: $original_key"
done;
echo "account_pubkey_map=${account_pubkey_map}" >> $GITHUB_ENV
- name: 'Prepare configs'
run: |
#FIXME set -e is the default bash flag(this is not obvious btw need to fix)
cp config.yaml config-combine.yaml
cp config.yaml config-split.yaml
#Split Config
sed -i "s,DISTRIBUTED_WALLETS,$input_distributed_wallets_path,g" config-combine.yaml
sed -i "s,ND_WALLETS,$output_nd_wallets_path,g" config-combine.yaml
#Combine Config
sed -i "s,DISTRIBUTED_WALLETS,$output_distributed_wallets_path,g" config-split.yaml
sed -i "s,ND_WALLETS,$output_nd_wallets_path,g" config-split.yaml
- name: 'COMBINE Function Test'
run: |
#FIXME set -e is the default bash flag(this is not obvious btw need to fix)
#Combine
./dkc combine --config=config-combine.yaml
#Compare Composite Pubkey from original accounts to newly created accounts
restored_wallet=$(ethdo wallet --base-dir "${output_nd_wallets_path}" list |head -n 1)
echo -e "# Combine Tests"
for account in $(echo "${account_pubkey_map}" | jq -r 'keys []'); do
original_key=$(echo "${account_pubkey_map}" | jq -r --arg account $account '.[$account]')
restored_key=$(ethdo account --base-dir "${output_nd_wallets_path}" info --account "$restored_wallet/$account" | grep -i "Public key:" | awk '{print $NF}')
if [[ "$original_key" != "$restored_key" ]]; then
echo -e "Account [$account]: ${red}Fail${nc} ($original_key != $restored_key)"
exit 1
fi
echo -e "Account [$account]: ${green}OK${nc}"
done;
- name: 'Split Function Test'
run: |
#FIXME set -e is the default bash flag(this is not obvious btw need to fix)
#Split
./dkc split --config=config-split.yaml
#Compare Composite Pubkey from original accounts to newly created accounts
splited_wallet=$(ethdo wallet --base-dir "${output_distributed_wallets_path}/old1/" list |head -n 1)
echo -e "# Split Tests"
for account in $(echo "${account_pubkey_map}" | jq -r 'keys []'); do
original_key=$(echo "${account_pubkey_map}" | jq -r --arg account $account '.[$account]')
splited_key=$(ethdo account --base-dir "${output_distributed_wallets_path}/old1/" info --account "$splited_wallet/$account" | grep -i "Composite public key:" | awk '{print $NF}')
if [[ "$original_key" != "$splited_key" ]]; then
echo -e "Account [$account]: ${red}Fail${nc} ($original_key != $splited_key)"
exit 1
fi
echo -e "Account [$account]: ${green}OK${nc}"
done;
env:
wallet_name: 'DW'
input_distributed_wallets_path: './wallets'
output_nd_wallets_path: './nd_wallets'
output_distributed_wallets_path: './distributed_wallets'
red: '\033[0;31m'
green: '\033[0;32m'
nc: '\033[0m'