def test_ethereum_fund_solver(): fund_solver = FundSolver( xprivate_key=_["ethereum"]["wallet"]["sender"]["root_xprivate_key"], path=_["ethereum"]["wallet"]["sender"]["derivation"]["path"], account=_["ethereum"]["wallet"]["sender"]["derivation"]["account"], change=_["ethereum"]["wallet"]["sender"]["derivation"]["change"], address=_["ethereum"]["wallet"]["sender"]["derivation"]["address"]) assert isinstance(fund_solver.solve(network=_["ethereum"]["network"]), Wallet)
def test_ethereum_fund_signature(): unsigned_fund_transaction_raw = _["ethereum"]["fund"]["unsigned"][ "transaction_raw"] fund_solver = FundSolver( xprivate_key=_["ethereum"]["wallet"]["sender"]["root_xprivate_key"], path=_["ethereum"]["wallet"]["sender"]["derivation"]["path"], account=_["ethereum"]["wallet"]["sender"]["derivation"]["account"], change=_["ethereum"]["wallet"]["sender"]["derivation"]["change"], address=_["ethereum"]["wallet"]["sender"]["derivation"]["address"]) signature = Signature(network=_["ethereum"]["network"]).sign( transaction_raw=unsigned_fund_transaction_raw, solver=fund_solver) assert signature.type() == _["ethereum"]["fund"]["signed"]["type"] assert signature.fee() == _["ethereum"]["fund"]["signed"]["fee"] assert signature.hash() == _["ethereum"]["fund"]["signed"]["hash"] assert signature.raw() == _["ethereum"]["fund"]["signed"]["raw"] assert signature.json() == _["ethereum"]["fund"]["signed"]["json"] assert signature.transaction_raw() == clean_transaction_raw( transaction_raw=_["ethereum"]["fund"]["signed"]["transaction_raw"]) fund_signature = FundSignature(network=_["ethereum"]["network"]).sign( transaction_raw=unsigned_fund_transaction_raw, solver=fund_solver) assert fund_signature.type() == _["ethereum"]["fund"]["signed"]["type"] assert fund_signature.fee() == _["ethereum"]["fund"]["signed"]["fee"] assert fund_signature.hash() == _["ethereum"]["fund"]["signed"]["hash"] assert fund_signature.raw() == _["ethereum"]["fund"]["signed"]["raw"] assert fund_signature.json() == _["ethereum"]["fund"]["signed"]["json"] assert fund_signature.transaction_raw() == clean_transaction_raw( transaction_raw=_["ethereum"]["fund"]["signed"]["transaction_raw"])
def test_ethereum_erc20_fund_transaction(): erc20_htlc = HTLC( contract_address=_["ethereum"]["erc20_htlc"]["contract_address"], network=_["ethereum"]["network"], erc20=True).build_htlc( secret_hash=_["ethereum"]["erc20_htlc"]["secret"]["hash"], recipient_address=_["ethereum"]["wallet"]["recipient"]["address"], sender_address=_["ethereum"]["wallet"]["sender"]["address"], endtime=get_current_timestamp(plus=3600), token_address=_["ethereum"]["erc20_htlc"]["agreements"] ["token_address"]) unsigned_erc20_fund_transaction = FundTransaction( network=_["ethereum"]["network"], erc20=True) unsigned_erc20_fund_transaction.build_transaction( address=_["ethereum"]["wallet"]["sender"]["address"], htlc=erc20_htlc, amount=_["ethereum"]["erc20_amount"] * (10**_["ethereum"]["decimals"])) assert unsigned_erc20_fund_transaction.type( ) == _["ethereum"]["erc20_fund"]["unsigned"]["type"] assert unsigned_erc20_fund_transaction.fee( ) == _["ethereum"]["erc20_fund"]["unsigned"]["fee"] assert unsigned_erc20_fund_transaction.hash( ) == _["ethereum"]["erc20_fund"]["unsigned"]["hash"] assert unsigned_erc20_fund_transaction.raw( ) == _["ethereum"]["erc20_fund"]["unsigned"]["raw"] assert isinstance(unsigned_erc20_fund_transaction.json(), dict) assert unsigned_erc20_fund_transaction.signature( ) == _["ethereum"]["erc20_fund"]["unsigned"]["signature"] assert isinstance(unsigned_erc20_fund_transaction.transaction_raw(), str) signed_erc20_fund_transaction = unsigned_erc20_fund_transaction.sign( solver=FundSolver( xprivate_key=_["ethereum"]["wallet"]["sender"] ["root_xprivate_key"], path=_["ethereum"]["wallet"]["sender"]["derivation"]["path"], account=_["ethereum"]["wallet"]["sender"]["derivation"]["account"], change=_["ethereum"]["wallet"]["sender"]["derivation"]["change"], address=_["ethereum"]["wallet"]["sender"]["derivation"] ["address"])) assert signed_erc20_fund_transaction.type( ) == _["ethereum"]["erc20_fund"]["signed"]["type"] assert signed_erc20_fund_transaction.fee( ) == _["ethereum"]["erc20_fund"]["signed"]["fee"] assert isinstance(signed_erc20_fund_transaction.hash(), str) assert isinstance(signed_erc20_fund_transaction.raw(), str) assert isinstance(signed_erc20_fund_transaction.json(), dict) assert isinstance(signed_erc20_fund_transaction.signature(), dict) assert isinstance(signed_erc20_fund_transaction.transaction_raw(), str)
print("Unsigned Fund Transaction Fee:", unsigned_fund_transaction.fee()) print("Unsigned Fund Transaction Hash:", unsigned_fund_transaction.hash()) print("Unsigned Fund Transaction Raw:", unsigned_fund_transaction.raw()) # print("Unsigned Fund Transaction Json:", json.dumps(unsigned_fund_transaction.json(), indent=4)) print("Unsigned Fund Transaction Signature:", json.dumps(unsigned_fund_transaction.signature(), indent=4)) print("Unsigned Fund Transaction Type:", unsigned_fund_transaction.type()) unsigned_fund_transaction_raw: str = unsigned_fund_transaction.transaction_raw( ) print("Unsigned Fund Transaction Raw:", unsigned_fund_transaction_raw) print("=" * 10, "Signed Fund Transaction") # Initialize fund solver fund_solver: FundSolver = FundSolver( xprivate_key=sender_wallet.root_xprivate_key(), path=sender_wallet.path()) # Sing unsigned fund transaction signed_fund_transaction: FundTransaction = unsigned_fund_transaction.sign( solver=fund_solver) print("Signed Fund Transaction Fee:", signed_fund_transaction.fee()) print("Signed Fund Transaction Hash:", signed_fund_transaction.hash()) print("Signed Fund Transaction Main Raw:", signed_fund_transaction.raw()) # print("Signed Fund Transaction Json:", json.dumps(signed_fund_transaction.json(), indent=4)) print("Signed Fund Transaction Signature:", json.dumps(signed_fund_transaction.signature(), indent=4)) print("Signed Fund Transaction Type:", signed_fund_transaction.type()) signed_fund_transaction_raw: str = signed_fund_transaction.transaction_raw() print("Signed Fund Transaction Raw:", signed_fund_transaction_raw)