Skip to content

Commit

Permalink
Merge #534: tests: Test psbt signed status
Browse files Browse the repository at this point in the history
60ac9b4 Add bool to signtx return type (Andrew Chow)
4f2beea tests: Test psbt signed status (Andrew Chow)

Pull request description:

  Test for #516

Top commit has no ACKs.

Tree-SHA512: 97465157c1dd7536f6e9abe357ef823d7eb68943ed9531f25322b501edb2379371f05ced042b33059892f106409a48ff8e57ba518bbda53d3f6423f3d4702c13
  • Loading branch information
achow101 committed Oct 23, 2021
2 parents 4d13ef4 + 60ac9b4 commit cc5012a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion hwilib/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
List,
NoReturn,
Optional,
Union,
)


Expand Down Expand Up @@ -86,7 +87,7 @@ def setup_device_handler(args: argparse.Namespace, client: HardwareWalletClient)
def signmessage_handler(args: argparse.Namespace, client: HardwareWalletClient) -> Dict[str, str]:
return signmessage(client, message=args.message, path=args.path)

def signtx_handler(args: argparse.Namespace, client: HardwareWalletClient) -> Dict[str, str]:
def signtx_handler(args: argparse.Namespace, client: HardwareWalletClient) -> Dict[str, Union[bool, str]]:
return signtx(client, psbt=args.psbt)

def wipe_device_handler(args: argparse.Namespace, client: HardwareWalletClient) -> Dict[str, bool]:
Expand Down
3 changes: 2 additions & 1 deletion hwilib/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
Dict,
List,
Optional,
Union,
)


Expand Down Expand Up @@ -176,7 +177,7 @@ def getmasterxpub(client: HardwareWalletClient, addrtype: AddressType = AddressT
"""
return {"xpub": client.get_master_xpub(addrtype, account).to_string()}

def signtx(client: HardwareWalletClient, psbt: str) -> Dict[str, str]:
def signtx(client: HardwareWalletClient, psbt: str) -> Dict[str, Union[bool, str]]:
"""
Sign a Partially Signed Bitcoin Transaction (PSBT) with the client.
Expand Down
7 changes: 7 additions & 0 deletions test/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ def _generate_and_finalize(self, unknown_inputs, psbt):
# Just do the normal signing process to test "all inputs" case
sign_res = self.do_command(self.dev_args + ['signtx', psbt['psbt']])
finalize_res = self.wrpc.finalizepsbt(sign_res['psbt'])
self.assertTrue(sign_res["signed"])
self.assertTrue(finalize_res["complete"])
else:
# Sign only input one on first pass
# then rest on second pass to test ability to successfully
Expand Down Expand Up @@ -312,11 +314,16 @@ def _generate_and_finalize(self, unknown_inputs, psbt):

# First will always have something to sign
first_sign_res = self.do_command(self.dev_args + ['signtx', first_psbt])
self.assertTrue(first_sign_res["signed"])
self.assertTrue(single_input == self.wrpc.finalizepsbt(first_sign_res['psbt'])['complete'])
# Second may have nothing to sign (1 input case)
# and also may throw an error(e.g., ColdCard)
second_sign_res = self.do_command(self.dev_args + ['signtx', second_psbt])
if 'psbt' in second_sign_res:
if single_input:
self.assertFalse(second_sign_res["signed"])
else:
self.assertTrue(second_sign_res["signed"])
self.assertTrue(not self.wrpc.finalizepsbt(second_sign_res['psbt'])['complete'])
combined_psbt = self.wrpc.combinepsbt([first_sign_res['psbt'], second_sign_res['psbt']])

Expand Down

0 comments on commit cc5012a

Please sign in to comment.