1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use crate::jcli::command::rest::v0::BlockCommand;
use assert_cmd::assert::OutputAssertExt;
use jormungandr_lib::crypto::hash::Hash;
use jortestkit::prelude::ProcessOutput;

pub struct Block {
    block_command: BlockCommand,
}

impl Block {
    pub fn new(block_command: BlockCommand) -> Self {
        Self { block_command }
    }

    pub fn get<P: Into<String>, S: Into<String>>(self, block_id: P, host: S) -> String {
        self.block_command
            .get(block_id, host)
            .build()
            .assert()
            .success()
            .get_output()
            .as_lossy_string()
    }

    pub fn get_expect_fail<P: Into<String>, S: Into<String>>(
        self,
        block_id: P,
        host: S,
        expected_msg: &str,
    ) {
        self.block_command
            .get(block_id, host)
            .build()
            .assert()
            .failure()
            .stderr(predicates::str::contains(expected_msg));
    }

    pub fn next<P: Into<String>, S: Into<String>>(
        self,
        block_id: P,
        limit: u32,
        host: S,
    ) -> Vec<Hash> {
        let content = self
            .block_command
            .next(block_id, limit, host)
            .build()
            .assert()
            .success()
            .get_output()
            .as_multi_line();
        content.iter().map(|b| Hash::from_hex(b).unwrap()).collect()
    }

    pub fn next_expect_fail<P: Into<String>, S: Into<String>>(
        self,
        block_id: P,
        limit: u32,
        host: S,
        expected_msg: &str,
    ) {
        self.block_command
            .next(block_id.into(), limit, host.into())
            .build()
            .assert()
            .failure()
            .stderr(predicates::str::contains(expected_msg));
    }
}