-
Notifications
You must be signed in to change notification settings - Fork 276
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
[feature] #3094: Generate network with n
peers
#3096
Conversation
Codecov Report
@@ Coverage Diff @@
## iroha2-dev #3096 +/- ##
==============================================
+ Coverage 62.33% 65.13% +2.80%
==============================================
Files 169 171 +2
Lines 31218 33570 +2352
==============================================
+ Hits 19459 21866 +2407
+ Misses 11759 11704 -55
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
e179747
to
d66adab
Compare
@@ -7,62 +7,66 @@ TEST=${TEST:-"./test"} | |||
HOST=${HOST:-"127.0.0.1"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is no longer what I'd call "reasonably small to be best done in bash
".
We should consider looking at other alternatives, e.g. python
:
https://unix.stackexchange.com/questions/24802/on-which-unix-distributions-is-python-installed-as-part-of-the-default-install
@astrokov7 had the idea of rewriting tests using python
's subprocess infrastructure, it might be worth it to do the same here.
mapfile -t -n 3 buffer < <($TEST/kagami crypto -c) | ||
public_keys[$1]="${buffer[0]}" | ||
private_keys[$1]=$(printf '{"digest_function": "%s", "payload": "%s"}' "${buffer[2]}" "${buffer[1]}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we might be doing something wrong in kagami
if we need this. Should we adjust the syntax so we can just pipe the output? kagami crypto -c --json
?
function generate_genesis_key_pair { | ||
mapfile -t -n 3 buffer < <($TEST/kagami crypto -c) | ||
IROHA_GENESIS_ACCOUNT_PUBLIC_KEY="${buffer[0]}" | ||
IROHA_GENESIS_ACCOUNT_PRIVATE_KEY=$(printf '{"digest_function": "%s", "payload": "%s"}' "${buffer[2]}" "${buffer[1]}") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd wager this is not what we want to do. If the genesis key pair is not specified, sure, generate a fresh pair. But it might not work in all contexts. If the environment variable is defined and set properly, we should just leave it alone and use it directly.
That was actually the whole point of using environment variables for this purpose.
scripts/test_env.sh
Outdated
do | ||
trusted_peer_entry "iroha$iter" | ||
trusted_peer_entry "$iter" | ||
echo -n "," | ||
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
printf
? It should make sense stylistically.
scripts/test_env.sh
Outdated
generate_genesis_key_pair | ||
for peer in $(seq 0 $(($1-1))) | ||
do | ||
generate_p2p_port $peer | ||
generate_api_port $peer | ||
generate_telemetry_port $peer | ||
generate_peer_key_pair $peer | ||
hosts[$peer]="$HOST" | ||
done | ||
SUMERAGI_TRUSTED_PEERS="$(generate_trusted_peers $1)" | ||
for peer in $(seq 1 $(($1-1))) | ||
do | ||
run_peer $peer | ||
done | ||
run_peer 0 --submit-genesis |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't quite what I'd like to happen. Overwriting the same environment variable can have unforeseen consequences. Again one more reason to consider writing this logic in Python.
scripts/test_env.sh
Outdated
if [ "$N_PEERS" -le 0 ] | ||
then | ||
echo "Expected number of peers as non-zero positive number (> 0). Recieved: $3" | ||
exit 1 | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, this is not what we do for other variables.
json: bool, | ||
/// Output the key-pair without additional text | ||
#[clap(long, short, group = "format")] | ||
compact: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm all for this format, but IMO the fact that we need to do some bash
scripting to use this information as part of JSON means that the format probably needs adjustment. Most people would assume that you can just assign the output of kagami to an environment variable and be done with it.
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Signed-off-by: Shanin Roman shanin1000@yandex.ru
Description of the Change
Extend
./scripts/test_env.sh
to work with arbitrary number of nodes.Add option to kagami to generate peers in compact format.
Issue
Closes #3094
Benefits
Easier to test iroha with different number of peers.
Possible Drawbacks
None.
Usage Examples or Tests [optional]