def test_emergency_vault_tx(bitcoind): """This tests the emergency_vault_tx() function.""" # The stakeholders, the first two are the traders. stk_privkeys = [os.urandom(32) for i in range(4)] stk_pubkeys = [CKey(k).pub for k in stk_privkeys] # The stakeholders emergency keys emer_privkeys = [os.urandom(32) for i in range(4)] emer_pubkeys = [CKey(k).pub for k in emer_privkeys] # Create the transaction funding the vault amount = 50 * COIN - 500 vault_txid = lx(send_vault_tx(bitcoind, stk_pubkeys, amount)) # Create the emergency transaction spending from the vault amount_min_fees = amount - 500 emer_tx = create_emergency_vault_tx(vault_txid, 0, amount_min_fees, emer_pubkeys) # Simulate that each stakeholder sign the transaction separately sigs = [sign_emergency_vault_tx(emer_tx, stk_pubkeys, amount, [k])[0] for k in stk_privkeys] emer_tx = form_emergency_vault_tx(emer_tx, stk_pubkeys, sigs) bitcoind.send_tx(b2x(emer_tx.serialize()))
def test_increase_revault_tx_feerate(bitcoind): """This tests that any of the stakeholders can increase the feerate of any of the revaulting transactions in a timely manner. Will justice rule?""" # The stakeholders, the first two are the traders. stk_privkeys = [os.urandom(32) for i in range(4)] stk_pubkeys = [CKey(k).pub for k in stk_privkeys] # Same, but for the EDV emer_privkeys = [os.urandom(32) for i in range(4)] emer_pubkeys = [CKey(k).pub for k in emer_privkeys] # The co-signing server, required by the spend tx serv_privkey = os.urandom(32) serv_pubkey = CKey(serv_privkey).pub # Test the vault emergency amount_vault = 50 * COIN - 500 txid = send_vault_tx(bitcoind, stk_pubkeys, amount_vault) amount_emer = amount_vault - 500 CTx = create_emergency_vault_tx(lx(txid), 0, amount_emer, emer_pubkeys) sigs = [ sign_emergency_vault_tx(CTx, p, stk_pubkeys, amount_vault) for p in stk_privkeys ] # Sanity checks don't hurt assert all(sig[-1] == SIGHASH_ALL | SIGHASH_ANYONECANPAY for sig in sigs) CMTx = CMutableTransaction.from_tx( form_emergency_vault_tx(CTx, stk_pubkeys, sigs)) fees_before = tx_fees(bitcoind, CMTx) first_txid = creates_add_input(bitcoind, CMTx) fees_after = tx_fees(bitcoind, CMTx) assert fees_after > fees_before bitcoind.send_tx(CMTx.serialize().hex(), wait_for_mempool=[first_txid]) # Test the emer unvault amount_vault = 50 * COIN - 500 amount_unvault = amount_vault - 500 txid = send_unvault_tx(bitcoind, stk_privkeys, stk_pubkeys, serv_pubkey, amount_vault, amount_unvault) amount_emer = amount_unvault - 500 CTx = create_emer_unvault_tx(txid, 0, emer_pubkeys, amount_emer) sigs = [ sign_emer_unvault_tx(CTx, p, stk_pubkeys, serv_pubkey, amount_unvault) for p in stk_privkeys ] # Sanity checks don't hurt assert all(sig[-1] == SIGHASH_ALL | SIGHASH_ANYONECANPAY for sig in sigs) CMTx = CMutableTransaction.from_tx( form_emer_unvault_tx(CTx, sigs, stk_pubkeys, serv_pubkey)) fees_before = tx_fees(bitcoind, CMTx) first_txid = creates_add_input(bitcoind, CMTx) fees_after = tx_fees(bitcoind, CMTx) assert fees_after > fees_before bitcoind.send_tx(CMTx.serialize().hex(), wait_for_mempool=[first_txid]) # Test the cancel unvault amount_vault = 50 * COIN - 500 amount_unvault = amount_vault - 500 txid = send_unvault_tx(bitcoind, stk_privkeys, stk_pubkeys, serv_pubkey, amount_vault, amount_unvault) amount_cancel = amount_unvault - 500 CTx = create_cancel_tx(txid, 0, emer_pubkeys, amount_cancel) sigs = [ sign_cancel_tx(CTx, p, stk_pubkeys, serv_pubkey, amount_unvault) for p in stk_privkeys ] # Sanity checks don't hurt assert all(sig[-1] == SIGHASH_ALL | SIGHASH_ANYONECANPAY for sig in sigs) CMTx = CMutableTransaction.from_tx( form_cancel_tx(CTx, sigs, stk_pubkeys, serv_pubkey)) fees_before = tx_fees(bitcoind, CMTx) first_txid = creates_add_input(bitcoind, CMTx) fees_after = tx_fees(bitcoind, CMTx) assert fees_after > fees_before bitcoind.send_tx(CMTx.serialize().hex(), wait_for_mempool=[first_txid])