Skip to content

Commit

Permalink
NOTMP
Browse files Browse the repository at this point in the history
  • Loading branch information
Tibo-lg committed Apr 3, 2024
1 parent bed75be commit 8c1da20
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jobs:
- name: Wait for electrs to be ready
run: ./scripts/wait_for_electrs.sh
- name: Create wallets
run: ./scripts/create_wallets.sh
run: docker exec bitcoin-node /scripts/create_wallets.sh
- name: Run test
run: |
if ! cargo test -- --ignored sample; then
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ services:
volumes:
- bitcoind-data:/home/bitcoin/.bitcoin
- ./testconfig/config:/config
- ./scripts:/scripts
electrs:
image: ghcr.io/cryptogarageinc/electrs:v0.4.12-bitcoin
command: |
Expand Down
34 changes: 20 additions & 14 deletions sample/tests/cli_tests.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::process::Command;
use std::{process::Command, thread::sleep, time::Duration};

use assert_cmd::cargo::cargo_bin;
use dlc_manager::contract::contract_input::ContractInput;
use rexpect::session::spawn_command;
use time::Duration;
use rexpect::session::{spawn_command, PtySession};

#[test]
#[ignore]
Expand All @@ -15,7 +14,7 @@ fn sample_cli_test() {
.duration_since(std::time::SystemTime::UNIX_EPOCH)
.unwrap()
+ Duration::new(300, 0))
.as_seconds_f32() as u32;
.as_secs();
contract.contract_infos[0].oracles.event_id = format!("btcusd{}", unix_time);

let alice_config_str = include_str!("../examples/configurations/alice.yml");
Expand Down Expand Up @@ -54,25 +53,32 @@ fn sample_cli_test() {

std::thread::sleep(std::time::Duration::from_secs(5));

bob_cli.send_line("listoffers").unwrap();
try_send_until(&mut bob_cli, "listoffers", "Offer");

bob_cli.exp_string("Offer").unwrap();
let (_, offer_id) = bob_cli.exp_regex("[a-f0-9]{64}").unwrap();

bob_cli
.send_line(&format!("acceptoffer {}", offer_id))
.unwrap();
bob_cli.exp_char('>').unwrap();

std::thread::sleep(std::time::Duration::from_secs(5));

alice_cli.send_line("listcontracts").unwrap();
alice_cli.exp_string("Signed contract").unwrap();
try_send_until(&mut alice_cli, "listcontracts", "Signed contract");
alice_cli.exp_char('>').unwrap();

std::thread::sleep(std::time::Duration::from_secs(5));

bob_cli.send_line("listcontracts").unwrap();
bob_cli.exp_string("Signed contract").unwrap();
try_send_until(&mut bob_cli, "listcontracts", "Signed contract");
bob_cli.exp_char('>').unwrap();
}

fn try_send_until(session: &mut PtySession, to_send: &str, expected: &str) {
const RETRY: u8 = 5;

for _ in 0..RETRY {
session.send_line(to_send).unwrap();
if let Ok(_) = session.exp_string(expected) {
return;
}
sleep(Duration::from_secs(1));
}

panic!("Did not receive expected output after {} tries", RETRY);
}

0 comments on commit 8c1da20

Please sign in to comment.