Ejemplo n.º 1
0
def test_bitcoin_withdraw_solver():

    withdraw_solver = WithdrawSolver(
        xprivate_key=_["bitcoin"]["wallet"]["recipient"]["root_xprivate_key"],
        secret_key=_["bitcoin"]["htlc"]["secret"]["key"],
        bytecode=_["bitcoin"]["htlc"]["bytecode"],
        path=_["bitcoin"]["wallet"]["recipient"]["derivation"]["path"],
        account=_["bitcoin"]["wallet"]["recipient"]["derivation"]["account"],
        change=_["bitcoin"]["wallet"]["recipient"]["derivation"]["change"],
        address=_["bitcoin"]["wallet"]["recipient"]["derivation"]["address"])

    assert isinstance(withdraw_solver.solve(network=_["bitcoin"]["network"]),
                      IfElseSolver)
Ejemplo n.º 2
0
def test_bitcoin_withdraw_transaction():

    unsigned_withdraw_transaction = WithdrawTransaction(
        network=_["bitcoin"]["network"])

    unsigned_withdraw_transaction.build_transaction(
        address=_["bitcoin"]["wallet"]["recipient"]["address"],
        transaction_hash=_["bitcoin"]["transaction_hash"])

    assert unsigned_withdraw_transaction.type(
    ) == _["bitcoin"]["withdraw"]["unsigned"]["type"]
    assert unsigned_withdraw_transaction.fee(
    ) == _["bitcoin"]["withdraw"]["unsigned"]["fee"]
    assert unsigned_withdraw_transaction.hash(
    ) == _["bitcoin"]["withdraw"]["unsigned"]["hash"]
    assert unsigned_withdraw_transaction.raw(
    ) == _["bitcoin"]["withdraw"]["unsigned"]["raw"]
    assert unsigned_withdraw_transaction.json(
    ) == _["bitcoin"]["withdraw"]["unsigned"]["json"]
    assert unsigned_withdraw_transaction.transaction_raw(
    ) == clean_transaction_raw(transaction_raw=_["bitcoin"]["withdraw"]
                               ["unsigned"]["transaction_raw"])

    signed_withdraw_transaction = unsigned_withdraw_transaction.sign(
        solver=WithdrawSolver(
            xprivate_key=_["bitcoin"]["wallet"]["recipient"]
            ["root_xprivate_key"],
            secret_key=_["bitcoin"]["htlc"]["secret"]["key"],
            bytecode=_["bitcoin"]["htlc"]["bytecode"],
            path=_["bitcoin"]["wallet"]["recipient"]["derivation"]["path"],
            account=_["bitcoin"]["wallet"]["recipient"]["derivation"]
            ["account"],
            change=_["bitcoin"]["wallet"]["recipient"]["derivation"]["change"],
            address=_["bitcoin"]["wallet"]["recipient"]["derivation"]
            ["address"]))

    assert signed_withdraw_transaction.type(
    ) == _["bitcoin"]["withdraw"]["signed"]["type"]
    assert signed_withdraw_transaction.fee(
    ) == _["bitcoin"]["withdraw"]["signed"]["fee"]
    assert signed_withdraw_transaction.hash(
    ) == _["bitcoin"]["withdraw"]["signed"]["hash"]
    assert signed_withdraw_transaction.raw(
    ) == _["bitcoin"]["withdraw"]["signed"]["raw"]
    assert signed_withdraw_transaction.json(
    ) == _["bitcoin"]["withdraw"]["signed"]["json"]
    assert signed_withdraw_transaction.transaction_raw(
    ) == clean_transaction_raw(
        transaction_raw=_["bitcoin"]["withdraw"]["signed"]["transaction_raw"])
Ejemplo n.º 3
0
def test_bitcoin_withdraw_signature():

    unsigned_withdraw_transaction_raw = _["bitcoin"]["withdraw"]["unsigned"][
        "transaction_raw"]

    withdraw_solver = WithdrawSolver(
        xprivate_key=_["bitcoin"]["wallet"]["recipient"]["root_xprivate_key"],
        secret_key=_["bitcoin"]["htlc"]["secret"]["key"],
        bytecode=_["bitcoin"]["htlc"]["bytecode"],
        path=_["bitcoin"]["wallet"]["recipient"]["derivation"]["path"],
        account=_["bitcoin"]["wallet"]["recipient"]["derivation"]["account"],
        change=_["bitcoin"]["wallet"]["recipient"]["derivation"]["change"],
        address=_["bitcoin"]["wallet"]["recipient"]["derivation"]["address"])

    signature = Signature(network=_["bitcoin"]["network"]).sign(
        transaction_raw=unsigned_withdraw_transaction_raw,
        solver=withdraw_solver)

    assert signature.type() == _["bitcoin"]["withdraw"]["signed"]["type"]
    assert signature.fee() == _["bitcoin"]["withdraw"]["signed"]["fee"]
    assert signature.hash() == _["bitcoin"]["withdraw"]["signed"]["hash"]
    assert signature.raw() == _["bitcoin"]["withdraw"]["signed"]["raw"]
    assert signature.json() == _["bitcoin"]["withdraw"]["signed"]["json"]
    assert signature.transaction_raw() == clean_transaction_raw(
        transaction_raw=_["bitcoin"]["withdraw"]["signed"]["transaction_raw"])

    withdraw_signature = WithdrawSignature(
        network=_["bitcoin"]["network"]).sign(
            transaction_raw=unsigned_withdraw_transaction_raw,
            solver=withdraw_solver)

    assert withdraw_signature.type(
    ) == _["bitcoin"]["withdraw"]["signed"]["type"]
    assert withdraw_signature.fee(
    ) == _["bitcoin"]["withdraw"]["signed"]["fee"]
    assert withdraw_signature.hash(
    ) == _["bitcoin"]["withdraw"]["signed"]["hash"]
    assert withdraw_signature.raw(
    ) == _["bitcoin"]["withdraw"]["signed"]["raw"]
    assert withdraw_signature.json(
    ) == _["bitcoin"]["withdraw"]["signed"]["json"]
    assert withdraw_signature.transaction_raw() == clean_transaction_raw(
        transaction_raw=_["bitcoin"]["withdraw"]["signed"]["transaction_raw"])
Ejemplo n.º 4
0
print("Unsigned Withdraw Transaction Main Raw:",
      unsigned_withdraw_transaction.raw())
# print("Unsigned Withdraw Transaction Json:", json.dumps(unsigned_withdraw_transaction.json(), indent=4))
print("Unsigned Withdraw Transaction Type:",
      unsigned_withdraw_transaction.type())

unsigned_withdraw_transaction_raw: str = unsigned_withdraw_transaction.transaction_raw(
)
print("Unsigned Withdraw Transaction Raw:", unsigned_withdraw_transaction_raw)

print("=" * 10, "Signed Withdraw Transaction")

# Initialize withdraw solver
withdraw_solver: WithdrawSolver = WithdrawSolver(
    xprivate_key=recipient_wallet.root_xprivate_key(),
    path=recipient_wallet.path(),
    secret_key=SECRET_KEY,
    bytecode=BYTECODE)

# Sing unsigned withdraw transaction
signed_withdraw_transaction: WithdrawTransaction = unsigned_withdraw_transaction.sign(
    solver=withdraw_solver)

print("Signed Withdraw Transaction Fee:",
      signed_withdraw_transaction.fee(unit="Satoshi"), "Satoshi")
print("Signed Withdraw Transaction Hash:", signed_withdraw_transaction.hash())
print("Signed Withdraw Transaction Main Raw:",
      signed_withdraw_transaction.raw())
# print("Signed Withdraw Transaction Json:", json.dumps(signed_withdraw_transaction.json(), indent=4))
print("Signed Withdraw Transaction Type:", signed_withdraw_transaction.type())