Skip to content

Commit fd403c8

Browse files
committed
bindings: updated python tests to use refactored x-only public key API
1 parent 00610d6 commit fd403c8

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

lwk_bindings/src/types/xonly_public_key.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
use crate::LwkError;
2+
13
use std::{fmt::Display, str::FromStr, sync::Arc};
24

3-
use crate::LwkError;
5+
use elements::hex::ToHex;
46

57
/// An x-only public key, used for verification of Taproot signatures
68
/// and serialized according to BIP-340.
@@ -32,6 +34,11 @@ impl XOnlyPublicKey {
3234
pub fn bytes(&self) -> Vec<u8> {
3335
self.inner.serialize().to_vec()
3436
}
37+
38+
/// Get hex representation of the x-only public key
39+
pub fn to_hex(&self) -> String {
40+
self.inner.to_hex()
41+
}
3542
}
3643

3744
impl XOnlyPublicKey {

lwk_bindings/tests/bindings/simplicity_p2pk.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
assert cmr == TEST_CMR
3333

3434
# Test creating P2TR address for p2pk program
35-
address = simplicity_create_p2tr_address(program, TEST_PUBLIC_KEY, network)
35+
address = simplicity_create_p2tr_address(program, XOnlyPublicKey(TEST_PUBLIC_KEY), network)
3636
assert address is not None
3737
assert str(address) == TEST_ADDRESS
3838

@@ -56,7 +56,7 @@
5656
tx = Transaction(TEST_UNSIGNED_TX)
5757

5858
finalized_tx = simplicity_finalize_transaction(
59-
tx, program, TEST_PUBLIC_KEY, [utxo], 0,
59+
tx, program, XOnlyPublicKey(TEST_PUBLIC_KEY), [utxo], 0,
6060
witness, network, genesis_hash, SimplicityLogLevel.NONE
6161
)
6262

lwk_bindings/tests/bindings/simplicity_p2pk_regtest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222

2323
# 3. Compile P2PK program with the public key
2424
args = SimplicityArguments()
25-
args = args.add_bytes("PUBLIC_KEY", str(xonly_pubkey))
25+
args = args.add_bytes("PUBLIC_KEY", xonly_pubkey.to_hex())
2626
program = simplicity_load_program(P2PK_SOURCE, args)
2727

2828
# 4. Create P2TR address from the program
29-
simplicity_address = simplicity_create_p2tr_address(program, str(xonly_pubkey), network)
29+
simplicity_address = simplicity_create_p2tr_address(program, xonly_pubkey, network)
3030
simplicity_script = simplicity_address.script_pubkey()
3131

3232
# 5. Fund the Simplicity address
@@ -91,7 +91,7 @@
9191
witness = witness.add_bytes("SIGNATURE", str(signature))
9292

9393
finalized_tx = simplicity_finalize_transaction(
94-
unsigned_tx, program, str(xonly_pubkey), all_utxos, 0,
94+
unsigned_tx, program, xonly_pubkey, all_utxos, 0,
9595
witness, network, genesis_hash, SimplicityLogLevel.NONE
9696
)
9797

0 commit comments

Comments
 (0)