def test_sign_tx_invalid_multisig_already_fully_signed(self): key1 = PrivateKey(WALLET_FORMAT_TEST_1) key2 = PrivateKey(WALLET_FORMAT_TEST_2) multi = MultiSig(key1, [key1.public_key, key2.public_key], 2) txobj = deserialize(FINAL_TX_BATCH) with pytest.raises(ValueError): sign_tx(multi, txobj, unspents=[UNSPENTS_BATCH[0]])
def test_sign_tx_multisig(self): key1 = PrivateKey(WALLET_FORMAT_TEST_1) key2 = PrivateKey(WALLET_FORMAT_TEST_2) multi = MultiSig(key1, [key1.public_key, key2.public_key], 2) txobj = deserialize(UNSIGNED_TX_BATCH) tx = sign_tx(multi, txobj, unspents=[UNSPENTS_BATCH[0]]) assert tx[:238] == FINAL_TX_BATCH[:238]
def test_sign_tx_invalid_segwit_no_amount(self): key = PrivateKey(WALLET_FORMAT_TEST_1) txobj = deserialize(UNSIGNED_TX_SEGWIT) unspents = copy.deepcopy(UNSPENTS_SEGWIT) unspents[1].amount = None with pytest.raises(ValueError): sign_tx(key, txobj, unspents=unspents)
def test_segwit_deserialize(self): txobj = deserialize(SEGWIT_TX_1) assert txobj.version == hex_to_bytes(SEGWIT_TX_1[:8]) assert len(txobj.TxIn) == 2 assert txobj.TxIn[0].txid == hex_to_bytes(SEGWIT_TX_1[14:78]) assert txobj.TxIn[0].txindex == hex_to_bytes(SEGWIT_TX_1[78:86]) assert txobj.TxIn[0].script_sig_len == hex_to_bytes(SEGWIT_TX_1[86:88]) assert txobj.TxIn[0].script_sig == hex_to_bytes(SEGWIT_TX_1[88:300]) assert txobj.TxIn[0].sequence == hex_to_bytes(SEGWIT_TX_1[300:308]) assert txobj.TxIn[0].witness == hex_to_bytes(SEGWIT_TX_1[564:566]) assert txobj.TxIn[1].txid == hex_to_bytes(SEGWIT_TX_1[308:372]) assert txobj.TxIn[1].txindex == hex_to_bytes(SEGWIT_TX_1[372:380]) assert txobj.TxIn[1].script_sig_len == hex_to_bytes( SEGWIT_TX_1[380:382]) assert txobj.TxIn[1].script_sig == hex_to_bytes(SEGWIT_TX_1[382:428]) assert txobj.TxIn[1].sequence == hex_to_bytes(SEGWIT_TX_1[428:436]) assert txobj.TxIn[1].witness == hex_to_bytes(SEGWIT_TX_1[566:780]) assert len(txobj.TxOut) == 2 assert txobj.TxOut[0].amount == hex_to_bytes(SEGWIT_TX_1[438:454]) assert txobj.TxOut[0].script_pubkey_len == hex_to_bytes( SEGWIT_TX_1[454:456]) assert txobj.TxOut[0].script_pubkey == hex_to_bytes( SEGWIT_TX_1[456:500]) assert txobj.TxOut[1].amount == hex_to_bytes(SEGWIT_TX_1[500:516]) assert txobj.TxOut[1].script_pubkey_len == hex_to_bytes( SEGWIT_TX_1[516:518]) assert txobj.TxOut[1].script_pubkey == hex_to_bytes( SEGWIT_TX_1[518:564]) assert txobj.locktime == hex_to_bytes(SEGWIT_TX_1[780:])
def psts_to_inputs(cls, psts): input_sets = [] for pst in psts: tx = deserialize(pst) utxos = [ TxInput(hexlify(input.txid), hexlify(input.txindex)) for input in tx.TxIn ] input_sets.append(set(utxos)) return input_sets
def test_legacy_deserialize(self): txobj = deserialize(FINAL_TX_1) assert txobj.version == hex_to_bytes(FINAL_TX_1[:8]) assert len(txobj.TxIn) == 1 assert txobj.TxIn[0].txid == hex_to_bytes(FINAL_TX_1[10:74]) assert txobj.TxIn[0].txindex == hex_to_bytes(FINAL_TX_1[74:82]) assert txobj.TxIn[0].script_sig_len == hex_to_bytes(FINAL_TX_1[82:84]) assert txobj.TxIn[0].script_sig == hex_to_bytes(FINAL_TX_1[84:360]) assert txobj.TxIn[0].witness == b'' assert txobj.TxIn[0].sequence == hex_to_bytes(FINAL_TX_1[360:368]) assert len(txobj.TxOut) == 2 assert txobj.TxOut[0].amount == hex_to_bytes(FINAL_TX_1[370:386]) assert txobj.TxOut[0].script_pubkey_len == hex_to_bytes(FINAL_TX_1[386:388]) assert txobj.TxOut[0].script_pubkey == hex_to_bytes(FINAL_TX_1[388:438]) assert txobj.TxOut[1].amount == hex_to_bytes(FINAL_TX_1[438:454]) assert txobj.TxOut[1].script_pubkey_len == hex_to_bytes(FINAL_TX_1[454:456]) assert txobj.TxOut[1].script_pubkey == hex_to_bytes(FINAL_TX_1[456:506]) assert txobj.locktime == hex_to_bytes(FINAL_TX_1[506:])
def test_sign_tx_invalid_unspents(self): key = PrivateKey(WALLET_FORMAT_TEST_1) txobj = deserialize(UNSIGNED_TX_SEGWIT) with pytest.raises(TypeError): # Unspents must be presented as list: sign_tx(key, txobj, unspents=UNSPENTS_SEGWIT[0])
def test_sign_tx_segwit(self): key = PrivateKey(WALLET_FORMAT_TEST_1) txobj = deserialize(UNSIGNED_TX_SEGWIT) assert sign_tx(key, txobj, unspents=UNSPENTS_SEGWIT) == FINAL_TX_SEGWIT
def test_sign_tx_legacy_input(self): key = PrivateKey(WALLET_FORMAT_TEST_1) txobj = deserialize(UNSIGNED_TX_SEGWIT) tx = sign_tx(key, txobj, unspents=[UNSPENTS_SEGWIT[0]]) assert tx[:380] == FINAL_TX_SEGWIT[:380]