Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pythcoiner committed Sep 10, 2023
1 parent d4f0569 commit 5950a4b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ impl DaemonControl {
let index = if count != 0 {
start_index + count - 1
} else {
max_index
max_index - 1
};

let addresses: Vec<AddressInfo> = (start_index..=index)
Expand Down Expand Up @@ -1027,6 +1027,35 @@ mod tests {
ms.shutdown();
}

#[test]
fn listaddresses() {
let ms = DummyLiana::new(DummyBitcoind::new(), DummyDatabase::new());

let control = &ms.handle.control;

let addr0 = control.get_new_address().address;
let addr1 = control.get_new_address().address;
let _addr2 = control.get_new_address().address;
let addr3 = control.get_new_address().address;
let addr4 = control.get_new_address().address;

let list = control.list_addresses(0, 0);

assert_eq!(list.addresses[0].index, 0);
assert_eq!(list.addresses[0].receive, addr0);
assert_eq!(list.addresses.last().unwrap().index, 4);
assert_eq!(list.addresses.last().unwrap().receive, addr4);

let list2 = control.list_addresses(1, 3);

assert_eq!(list2.addresses[0].index, 1);
assert_eq!(list2.addresses[0].receive, addr1);
assert_eq!(list2.addresses.last().unwrap().index, 3);
assert_eq!(list2.addresses.last().unwrap().receive, addr3);

ms.shutdown();
}

#[test]
fn create_spend() {
let dummy_op = bitcoin::OutPoint::from_str(
Expand Down
10 changes: 10 additions & 0 deletions tests/test_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ def test_getaddress(lianad):
assert res["address"] != lianad.rpc.getnewaddress()["address"]


def test_listadresses(lianad):
list = lianad.rpc.listaddresses(2, 5)
assert 'addresses' in list

addr = list['addresses']

assert addr[0]['index'] == 2
assert addr[-1]['index'] == 6


def test_listcoins(lianad, bitcoind):
# Initially empty
res = lianad.rpc.listcoins()
Expand Down

0 comments on commit 5950a4b

Please sign in to comment.