Exemple #1
0
def test_bitcoin_normal_solver():

    normal_solver = NormalSolver(
        xprivate_key=_["bitcoin"]["wallet"]["sender"]["root_xprivate_key"],
        path=_["bitcoin"]["wallet"]["sender"]["derivation"]["path"],
        account=_["bitcoin"]["wallet"]["sender"]["derivation"]["account"],
        change=_["bitcoin"]["wallet"]["sender"]["derivation"]["change"],
        address=_["bitcoin"]["wallet"]["sender"]["derivation"]["address"])

    assert isinstance(normal_solver.solve(network=_["bitcoin"]["network"]),
                      P2pkhSolver)
Exemple #2
0
def test_bitcoin_normal_transaction():

    unsigned_normal_transaction = NormalTransaction(network=_["bitcoin"]["network"])

    unsigned_normal_transaction.build_transaction(
        address=_["bitcoin"]["wallet"]["sender"]["address"],
        htlc_address=_["bitcoin"]["htlc"]["address"],
        recipients={
            _["bitcoin"]["wallet"]["recipient"]["address"]: (
                _["bitcoin"]["amount"] if _["bitcoin"]["unit"] == "SATOSHI" else amount_unit_converter(
                    _["bitcoin"]["amount"], f"{_['bitcoin']['unit']}2SATOSHI")
            )
        }
    )

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

    signed_normal_transaction = unsigned_normal_transaction.sign(
        solver=NormalSolver(
            root_xprivate_key=_["bitcoin"]["wallet"]["sender"]["root_xprivate_key"],
            path=_["bitcoin"]["wallet"]["sender"]["derivation"]["path"],
            account=_["bitcoin"]["wallet"]["sender"]["derivation"]["account"],
            change=_["bitcoin"]["wallet"]["sender"]["derivation"]["change"],
            address=_["bitcoin"]["wallet"]["sender"]["derivation"]["address"]
        )
    )

    assert signed_normal_transaction.type() == _["bitcoin"]["normal"]["signed"]["type"]
    assert signed_normal_transaction.fee() == _["bitcoin"]["normal"]["signed"]["fee"]
    assert signed_normal_transaction.hash() == _["bitcoin"]["normal"]["signed"]["hash"]
    assert signed_normal_transaction.raw() == _["bitcoin"]["normal"]["signed"]["raw"]
    assert signed_normal_transaction.json() == _["bitcoin"]["normal"]["signed"]["json"]
    assert signed_normal_transaction.transaction_raw() == clean_transaction_raw(
        transaction_raw=_["bitcoin"]["normal"]["signed"]["transaction_raw"]
    )
Exemple #3
0
def test_bitcoin_normal_signature():

    unsigned_normal_transaction_raw = _["bitcoin"]["normal"]["unsigned"]["transaction_raw"]

    normal_solver = NormalSolver(
        root_xprivate_key=_["bitcoin"]["wallet"]["sender"]["root_xprivate_key"],
        path=_["bitcoin"]["wallet"]["sender"]["derivation"]["path"],
        account=_["bitcoin"]["wallet"]["sender"]["derivation"]["account"],
        change=_["bitcoin"]["wallet"]["sender"]["derivation"]["change"],
        address=_["bitcoin"]["wallet"]["sender"]["derivation"]["address"]
    )

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

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

    normal_signature = NormalSignature(network=_["bitcoin"]["network"]).sign(
        transaction_raw=unsigned_normal_transaction_raw,
        solver=normal_solver
    )

    assert normal_signature.type() == _["bitcoin"]["normal"]["signed"]["type"]
    assert normal_signature.fee() == _["bitcoin"]["normal"]["signed"]["fee"]
    assert normal_signature.hash() == _["bitcoin"]["normal"]["signed"]["hash"]
    assert normal_signature.raw() == _["bitcoin"]["normal"]["signed"]["raw"]
    assert normal_signature.json() == _["bitcoin"]["normal"]["signed"]["json"]
    assert normal_signature.transaction_raw() == clean_transaction_raw(
        transaction_raw=_["bitcoin"]["normal"]["signed"]["transaction_raw"]
    )
def test_bitcoin_normal_transaction():

    unsigned_normal_transaction = NormalTransaction(network=_["bitcoin"]["network"])

    unsigned_normal_transaction.build_transaction(
        address=_["bitcoin"]["wallet"]["sender"]["address"],
        recipients={
            _["bitcoin"]["wallet"]["recipient"]["address"]: _["bitcoin"]["amount"]
        },
        unit=_["bitcoin"]["unit"]
    )

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

    signed_normal_transaction = unsigned_normal_transaction.sign(
        solver=NormalSolver(
            xprivate_key=_["bitcoin"]["wallet"]["sender"]["root_xprivate_key"],
            path=_["bitcoin"]["wallet"]["sender"]["derivation"]["path"],
            account=_["bitcoin"]["wallet"]["sender"]["derivation"]["account"],
            change=_["bitcoin"]["wallet"]["sender"]["derivation"]["change"],
            address=_["bitcoin"]["wallet"]["sender"]["derivation"]["address"]
        )
    )

    assert signed_normal_transaction.type() == _["bitcoin"]["normal"]["signed"]["type"]
    assert signed_normal_transaction.fee() == _["bitcoin"]["normal"]["signed"]["fee"]
    assert signed_normal_transaction.hash() == _["bitcoin"]["normal"]["signed"]["hash"]
    assert signed_normal_transaction.raw() == _["bitcoin"]["normal"]["signed"]["raw"]
    assert signed_normal_transaction.json() == _["bitcoin"]["normal"]["signed"]["json"]
    assert signed_normal_transaction.transaction_raw() == clean_transaction_raw(
        transaction_raw=_["bitcoin"]["normal"]["signed"]["transaction_raw"]
    )
Exemple #5
0
print("Unsigned Normal Transaction Fee:",
      unsigned_normal_transaction.fee(unit="Satoshi"), "Satoshi")
print("Unsigned Normal Transaction Hash:", unsigned_normal_transaction.hash())
print("Unsigned Normal Transaction Main Raw:",
      unsigned_normal_transaction.raw())
# print("Unsigned Normal Transaction Json:", json.dumps(unsigned_normal_transaction.json(), indent=4))
print("Unsigned Normal Transaction Type:", unsigned_normal_transaction.type())

unsigned_normal_transaction_raw: str = unsigned_normal_transaction.transaction_raw(
)
print("Unsigned Normal Transaction Raw:", unsigned_normal_transaction_raw)

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

# Initialize normal solver
normal_solver: NormalSolver = NormalSolver(
    xprivate_key=sender_wallet.root_xprivate_key())

# Sing unsigned normal transaction
signed_normal_transaction: NormalTransaction = unsigned_normal_transaction.sign(
    solver=normal_solver)

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

signed_normal_transaction_raw = signed_normal_transaction.transaction_raw()
print("Signed Normal Transaction Raw:", signed_normal_transaction_raw)