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

Add private community test for CI #60

Merged
merged 4 commits into from
May 1, 2023
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
53 changes: 45 additions & 8 deletions cli/demo_private_community.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ trap "echo The demo is terminated (SIGTERM); exit 1" SIGTERM
# usage:
# demo_private_community.sh -p <NODEPORT> -P <WORKERPORT> -u <NODE_URL> -V <WORKER_URL> -C <CLIENT_BINARY_PATH>

while getopts ":m:p:A:B:t:u:W:V:C:" opt; do
while getopts ":m:p:A:B:u:W:V:C:" opt; do
case $opt in
t)
TEST=$OPTARG
;;
m)
READMRENCLAVE=$OPTARG
;;
Expand Down Expand Up @@ -90,6 +87,9 @@ echo "* Migrating public community ${COMMUNITY_IDENTIFIER} to private"
$CLIENTWORKER1 trusted --mrenclave ${MRENCLAVE} make-community-private //Alice ${COMMUNITY_IDENTIFIER}
echo ""

echo "* Waiting 10 seconds"
sleep 10

echo "* Registering participants : "
echo "- Registering 3 bootstrappers : "
echo " //Alice,"
Expand Down Expand Up @@ -167,14 +167,13 @@ echo "* Waiting enough time, such that xt's are processed... 30 seconds"
sleep 30
echo ""

echo "* Check : "
echo "* Info : "
echo ""
echo "Community infos :"
$CLIENTWORKER1 trusted --mrenclave ${MRENCLAVE} community-infos //Alice ${COMMUNITY_IDENTIFIER}
echo ""

echo "Check Bob balances"

echo "Bob's balances:"
echo "Initial balances"
echo " in native currency: $INIT_BOB_NATIVE"
echo " in community currency: $INIT_BOB_COMMUNITY_CURRENCY"
Expand All @@ -193,5 +192,43 @@ DEMURRAGE_BOB_COMMUNITY_CURRENCY=$(${CLIENTWORKER1} trusted --mrenclave ${MRENCL
echo " in community currency: $DEMURRAGE_BOB_COMMUNITY_CURRENCY"
echo ""

#Todo test
# The following tests are for automated CI.
echo "* Verifying Bob's balance in community currency"
echo ""
echo "1) Reward: "
if [ bc <<< "$REWARDED_BOB_COMMUNITY_CURRENCY > $INIT_BOB_COMMUNITY_CURRENCY" ]; then
echo "Bob's balance in community community has increased ($REWARDED_BOB_COMMUNITY_CURRENCY)."
else
echo "test failed: Bob has not received the rewards. His balance in community currency should be greater than $INIT_BOB_COMMUNITY_CURRENCY"
exit 1
fi

echo "2) Demurrage:"
if [ bc <<< "$REWARDED_BOB_COMMUNITY_CURRENCY > $DEMURRAGE_BOB_COMMUNITY_CURRENCY" ]; then
echo "Bob's balance in community currency got devalued ($DEMURRAGE_BOB_COMMUNITY_CURRENCY)"
else
echo "test failed: It seems that no demurrage was applied on Bob's balances in community currency: $REWARDED_BOB_COMMUNITY_CURRENCY should be greater than $DEMURRAGE_BOB_COMMUNITY_CURRENCY"
exit 1
fi
echo ""

echo "* Verifying Bob's balance in native currency :"
echo "1) No reward:"
if [ bc <<< "$REWARDED_BOB_NATIVE = $INIT_BOB_NATIVE" ]; then
echo "Bob's balance in native currency has not changed ($REWARDED_BOB_NATIVE)"
else
echo "test failed: Bob's balance in native currency has changed: $REWARDED_BOB_NATIVE should be $INIT_BOB_NATIVE"
exit 1
fi

echo "2) No demurrage:"
if [ bc <<< "$DEMURRAGE_BOB_NATIVE = $INIT_BOB_NATIVE" ]; then
echo "Bob's balance in native currency has not changed ($DEMURRAGE_BOB_NATIVE)"
else
echo "test failed: Bob's balance in native currency has changed: $REWARDED_BOB_NATIVE should be $INIT_BOB_NATIVE"
exit 1
fi
echo "Test passed"
echo ""

exit 0
19 changes: 8 additions & 11 deletions cli/src/ceremonies/commands/community_infos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ use crate::{
trusted_commands::TrustedArgs, trusted_operation::perform_trusted_operation, Cli,
};
use codec::Decode;
use encointer_primitives::{
balances::EncointerBalanceConverter,
communities::{CommunityIdentifier, NominalIncome},
};
use encointer_primitives::communities::{CommunityIdentifier, LossyInto, NominalIncome};
use ita_stf::{PublicGetter, TrustedOperation};
use sp_runtime::traits::Convert;
use std::str::FromStr;

/// List various public information for an encointer community.
Expand All @@ -46,15 +42,16 @@ impl CommunityInfosCommand {
let top: TrustedOperation =
PublicGetter::encointer_total_issuance(community_identifier).into();
let encoded_total_issuance = perform_trusted_operation(cli, trusted_args, &top);
let total_issuance = decode_encointer_balance(encoded_total_issuance);
println!(
"Total inssuance {}",
EncointerBalanceConverter::convert(total_issuance.unwrap_or_default()),
);
let total_issuance_fixed =
decode_encointer_balance(encoded_total_issuance).unwrap_or_default();
let total_issuance: f64 = total_issuance_fixed.lossy_into();
println!("Total inssuance {}", total_issuance,);

let top: TrustedOperation = PublicGetter::ceremonies_reward(community_identifier).into();
let encoded_reward = perform_trusted_operation(cli, trusted_args, &top).unwrap();
let reward = NominalIncome::decode(&mut encoded_reward.as_slice()).unwrap_or_default();
let reward_fixed =
NominalIncome::decode(&mut encoded_reward.as_slice()).unwrap_or_default();
let reward: f64 = reward_fixed.lossy_into();
println!("Reward {} ", reward);

//Todo:
Expand Down
8 changes: 4 additions & 4 deletions cli/src/trusted_base_cli/commands/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ use crate::{
trusted_operation::perform_trusted_operation,
Cli,
};
use encointer_primitives::{balances::EncointerBalanceConverter, communities::CommunityIdentifier};
use encointer_primitives::communities::{CommunityIdentifier, LossyInto};
use ita_stf::{KeyPair, TrustedGetter, TrustedOperation};
use sp_core::Pair;
use sp_runtime::traits::Convert;
use std::str::FromStr;

#[derive(Parser)]
Expand All @@ -48,8 +47,9 @@ impl BalanceCommand {
.sign(&KeyPair::Sr25519(who))
.into();
let res = perform_trusted_operation(cli, trusted_args, &top);
let amount = decode_encointer_balance(res);
println!("{}", EncointerBalanceConverter::convert(amount.unwrap_or_default()),);
let balance_type = decode_encointer_balance(res).unwrap_or_default();
let amount: f64 = balance_type.lossy_into();
println!("{}", amount);
},
None => {
println!("{}", get_balance(cli, trusted_args, &self.account).unwrap_or_default());
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
interval: 10s
timeout: 10s
retries: 6
command: --dev --enable-offchain-indexing true --rpc-methods unsafe --ws-external --rpc-external --ws-port 9912
command: --tmp --dev --enable-offchain-indexing true --rpc-methods unsafe --ws-external --rpc-external --ws-port 9912
#logging:
#driver: local
encointer-worker-1:
Expand Down