예제 #1
0
def test_emergency_unvault_tx(bitcoind):
    """This tests the emergency_unvault_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]
    # The co-signing server, required by the spend tx
    serv_privkey = CKey(os.urandom(32))
    serv_pubkey = serv_privkey.pub
    # Create the vault and unvault transactions
    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
    # Actually vout MUST be 0.
    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
    ]
    CTx = form_emer_unvault_tx(CTx, sigs, stk_pubkeys, serv_pubkey)
    bitcoind.send_tx(b2x(CTx.serialize()))
예제 #2
0
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])