Skip to content

Commit

Permalink
Autopay text (#551)
Browse files Browse the repository at this point in the history
* patch paths on github actions

* fix text output of autopay instructions
  • Loading branch information
0o-de-lally authored Jun 7, 2021
1 parent e827fb8 commit c3b7c82
Show file tree
Hide file tree
Showing 13 changed files with 255 additions and 80 deletions.
34 changes: 30 additions & 4 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,34 @@ jobs:
run: sudo apt-get install -y lld
- name: Check branch
run: echo "${{ steps.branch-name.outputs.current_branch }}"
- name: Swarm upgrade test
run: RUSTC_WRAPPER=sccache SOURCE_PATH=./ make -f ol/util/test-mining.mk test
- name: Swarm mining test
run: RUSTC_WRAPPER=sccache SOURCE_PATH=./ make -f ol/integration-tests/test-mining.mk test
autopay:
name: Autopay
runs-on: self-hosted
timeout-minutes: 45
env:
NODE_ENV: test
TEST: y
steps:
- uses: actions/checkout@v2
- name: Get branch names
id: branch-name
uses: tj-actions/branch-names@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.46.0
override: true
components: rustfmt, clippy
- name: Install deps
run: sudo apt-get install -y lld
- name: Check branch
run: echo "${{ steps.branch-name.outputs.current_branch }}"
- name: Swarm autopay percent-change
run: RUSTC_WRAPPER=sccache SOURCE_PATH=./ make -f ol/integration-tests/test-autopay.mk test-percent-change
- name: Swarm autopay fixed-once
run: RUSTC_WRAPPER=sccache SOURCE_PATH=./ make -f ol/integration-tests/test-autopay.mk test-fixed-once
upgrade:
name: Stdlib Upgrade
runs-on: self-hosted
Expand All @@ -53,6 +79,6 @@ jobs:
- name: File permissions
run: sudo chmod -R 777 language/stdlib/
- name: Swarm upgrade test
run: BRANCH_NAME=${{ steps.branch-name.outputs.current_branch }} RUSTC_WRAPPER=sccache SOURCE_PATH=./ make -f ol/util/test-upgrade.mk test
run: BRANCH_NAME=${{ steps.branch-name.outputs.current_branch }} RUSTC_WRAPPER=sccache SOURCE_PATH=./ make -f ol/integration-tests/test-upgrade.mk test



2 changes: 1 addition & 1 deletion ol/cli/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use crate::{
check::items::Items,
mgmt::management::HostProcess,
node::{account::OwnerAccountView, chain_info::ChainView, states::HostState},
node::{account::OwnerAccountView, chain_view::ChainView, states::HostState},
};
use anyhow::Error;
use serde::{Deserialize, Serialize};
Expand Down
6 changes: 3 additions & 3 deletions ol/cli/src/explorer/app.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

#[allow(missing_docs)]
use crate::node::chain_info;
use crate::node::chain_view;
use crate::node::node::Node;
use super::TabsState;
use libra_json_rpc_client::views::TransactionView;
Expand Down Expand Up @@ -60,9 +60,9 @@ pub struct App<'a> {
/// caches for account state
pub account_state: Option<AccountState>,
/// caches for chain state
pub chain_state: Option<chain_info::ChainView>,
pub chain_state: Option<chain_view::ChainView>,
/// caches for validator list
pub validators: Vec<chain_info::ValidatorView>,
pub validators: Vec<chain_view::ValidatorView>,
/// latest fetched tx version
pub last_fetch_tx_version: u64,
/// transaction list
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion ol/cli/src/node/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! `node` state of the host, account, node, and miner
pub mod node;
pub mod account;
pub mod chain_info;
pub mod chain_view;
pub mod query;
pub mod sync;
pub mod client;
Expand Down
14 changes: 9 additions & 5 deletions ol/cli/src/node/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use libra_json_rpc_client::views::{MinerStateResourceView};
use libra_types::waypoint::Waypoint;
use libra_types::{account_address::AccountAddress, account_state::AccountState};
use storage_interface::DbReader;
use super::client;
use super::{account::OwnerAccountView, states::HostState};

/// name of key in kv store for sync
Expand Down Expand Up @@ -72,6 +73,14 @@ impl Node {
};
}

/// default node connection from configs
pub fn default_from_cfg(mut cfg: AppCfg) -> Node {
// NOTE: not intended for swarm.
let client = client::pick_client(None, &mut cfg).unwrap();
Node::new(client, cfg, false)
}


/// refresh all checks
pub fn refresh_checks(&mut self) -> &mut Self {
self.vitals.items.configs_exist = self.configs_exist();
Expand Down Expand Up @@ -146,11 +155,6 @@ impl Node {
}
}

/// is validator jailed
pub fn is_jailed() -> bool {
unimplemented!("Don't know how to implement")
}

/// Is current account in validator set
pub fn is_in_validator_set(&self) -> bool {
match &self.chain_state {
Expand Down
12 changes: 12 additions & 0 deletions ol/fixtures/autopay/alice.fixed_once.autopay_batch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"autopay_instructions": [
{
"note": "test balance",
"uid": 0,
"destination": "88E74DFED34420F2AD8032148280A84B",
"type_of": "FixedOnce",
"value": 1,
"duration_epochs": 1
}
]
}
112 changes: 112 additions & 0 deletions ol/integration-tests/test-autopay.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
SHELL=/usr/bin/env bash
DATA_PATH = ${HOME}/.0L
SWARM_TEMP = ${DATA_PATH}/swarm_temp
LOG=${DATA_PATH}/test-mining.log
UNAME := $(shell uname)

NODE_ENV=test
TEST=y

ifndef SOURCE_PATH
SOURCE_PATH = ${HOME}/libra
endif
MAKE_FILE = ${SOURCE_PATH}/ol/integration-tests/test-autopay.mk

# alice
ifndef PERSONA
PERSONA=alice
endif

MNEM="talent sunset lizard pill fame nuclear spy noodle basket okay critic grow sleep legend hurry pitch blanket clerk impose rough degree sock insane purse"

NUM_NODES = 2

START_TEXT = "To run the Libra CLI client"
SUCCESS_TEXT = "transaction executed"

ifndef AUTOPAY_FILE
AUTOPAY_FILE = alice.autopay_batch.json
endif

test: swarm check-swarm send-tx check-tx check-autopay check-transfer stop

test-percent-change:
AUTOPAY_FILE=alice.autopay_batch.json make -f ${MAKE_FILE} test

test-fixed-once:
AUTOPAY_FILE=alice.fixed_once.autopay_batch.json make -f ${MAKE_FILE} test

swarm:
@echo Building Swarm
rm -rf ${SWARM_TEMP}
mkdir ${SWARM_TEMP}
cd ${SOURCE_PATH} && cargo build -p libra-node -p cli
cd ${SOURCE_PATH} && cargo run -p libra-swarm -- --libra-node ${SOURCE_PATH}/target/debug/libra-node -c ${SWARM_TEMP} -n ${NUM_NODES} &> ${LOG} &

stop:
killall libra-swarm libra-node miner ol | true

echo:
@echo hi &> ${LOG} &

init:
cd ${SOURCE_PATH} && cargo r -p ol -- --swarm-path ${SWARM_TEMP} --swarm-persona ${PERSONA} init --source-path ${SOURCE_PATH}

tx:
cd ${SOURCE_PATH} && NODE_ENV=test TEST=y cargo r -p txs -- --swarm-path ${SWARM_TEMP} --swarm-persona ${PERSONA} autopay-batch -f ${SOURCE_PATH}/ol/fixtures/autopay/${AUTOPAY_FILE}

resources:
cd ${SOURCE_PATH} && cargo run -p ol -- --swarm-path ${SWARM_TEMP} --swarm-persona ${PERSONA} query --resources

balance:
cd ${SOURCE_PATH} && cargo run -p ol -- --swarm-path ${SWARM_TEMP} --swarm-persona ${PERSONA} query --balance

balance-bob:
cd ${SOURCE_PATH} && cargo run -p ol -- --account 88E74DFED34420F2AD8032148280A84B --swarm-path ${SWARM_TEMP} --swarm-persona ${PERSONA} query --balance


check-swarm:
@while [[ ${NOW} -le ${END} ]] ; do \
if grep -q ${START_TEXT} ${LOG} ; then \
break; \
else \
echo . ; \
fi ; \
echo "Sleeping for 5 secs" ; \
sleep 5 ; \
done

send-tx:
PERSONA=alice make -f ${MAKE_FILE} init
PERSONA=alice make -f ${MAKE_FILE} tx &>> ${LOG} &

check-tx:
@while [[ ${NOW} -le ${END} ]] ; do \
if grep -q ${SUCCESS_TEXT} ${LOG} ; then \
echo TX SUCCESS ; \
break ; \
else \
echo . ; \
fi ; \
echo "Sleeping for 5 secs" ; \
sleep 5 ; \
done

check-autopay:
# checks if there is any mention of BOB's account as a payee
PERSONA=alice make -f ${MAKE_FILE} resources | grep -e '88E74DFED34420F2AD8032148280A84B' -e 'payee'


check-transfer:
# swarm accounts start with a balance of 4
@while [[ ${NOW} -le ${END} ]] ; do \
if PERSONA=alice make -f ${MAKE_FILE} balance-bob | grep -e '5'; then \
echo TX SUCCESS ; \
break ; \
else \
echo . ; \
fi ; \
echo "Sleeping for 5 secs" ; \
sleep 5 ; \
done

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ TEST=y
ifndef SOURCE_PATH
SOURCE_PATH = ${HOME}/libra
endif
MAKE_FILE = ${SOURCE_PATH}/ol/util/test-mining.mk
MAKE_FILE = ${SOURCE_PATH}/ol/integration-tests/test-mining.mk

# alice
ifndef PERSONA
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ prep:
# save makefile outside of repo, since we'll need it across branches
# mkdir ${HOME}/.0L/ | true
mkdir -p ${UPGRADE_TEMP} | true
cp ${SOURCE_PATH}/ol/util/test-upgrade.mk ${SAFE_MAKE_FILE}
cp ${SOURCE_PATH}/ol/integration-tests/test-upgrade.mk ${SAFE_MAKE_FILE}

get-prev:
cd ${SOURCE_PATH} && git reset --hard && git fetch
Expand Down
47 changes: 1 addition & 46 deletions ol/txs/src/commands/autopay_batch_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,52 +39,7 @@ pub fn process_instructions(instructions: Vec<PayInstruction>, starting_epoch: &
instructions.into_iter().filter_map(|i| {
assert!(i.type_move.unwrap() <= 3);

let warning = if i.type_move.unwrap() == 0 {
format!(
"Instruction {uid}: {note}\nSend {percent_balance:.2?}% of your total balance every day {count_epochs} times (until epoch {epoch_ending}) to address: {destination}?",
uid = &i.uid,
percent_balance = *&i.value_move.unwrap() as f64 /100f64,
count_epochs = &i.duration_epochs.unwrap_or_else(|| {
&i.end_epoch.unwrap() - starting_epoch
}),
note = &i.note.clone().unwrap(),
epoch_ending = &i.end_epoch.unwrap(),
destination = &i.destination,
)
} else if i.type_move.unwrap() == 1 {
format!(
"Instruction {uid}: {note}\nSend {percent_balance:.2?}% new incoming funds every day {count_epochs} times (until epoch {epoch_ending}) to address: {destination}?",
uid = &i.uid,
percent_balance = *&i.value_move.unwrap() as f64 /100f64,
count_epochs = &i.duration_epochs.unwrap_or_else(|| {
&i.end_epoch.unwrap() - starting_epoch
}),
note = &i.note.clone().unwrap(),
epoch_ending = &i.end_epoch.unwrap(),
destination = &i.destination,
)
} else if i.type_move.unwrap() == 2 {
format!(
"Instruction {uid}: {note}\nSend {total_val} every day {count_epochs} times (until epoch {epoch_ending}) to address: {destination}?",
uid = &i.uid,
total_val = *&i.value_move.unwrap() / 1_000_000, // scaling factor
count_epochs = &i.duration_epochs.unwrap_or_else(|| {
&i.end_epoch.unwrap() - starting_epoch
}),
note = &i.note.clone().unwrap(),
epoch_ending = &i.end_epoch.unwrap(),
destination = &i.destination,
)
} else {
format!(
"Instruction {uid}: {note}\nSend {total_val} once to address: {destination}?",
uid = &i.uid,
note = &i.note.clone().unwrap(),
total_val = *&i.value_move.unwrap() / 1_000_000, // scaling factor
destination = &i.destination,
)
};
println!("{}", &warning);
println!("{}", i.text_instructions(starting_epoch));
// accept if CI mode.
if *IS_CI { return Some(i) }

Expand Down
Loading

0 comments on commit c3b7c82

Please sign in to comment.