Ejemplo n.º 1
0
def test_ethereum_cli_fund(cli_tester):

    fund = cli_tester.invoke(cli_main, [
        "ethereum", "fund", "--secret-hash",
        _["ethereum"]["htlc"]["secret"]["hash"], "--recipient-address",
        _["ethereum"]["wallet"]["recipient"]["address"], "--sender-address",
        _["ethereum"]["wallet"]["sender"]["address"], "--endtime",
        get_current_timestamp(plus=3600), "--amount", _["ethereum"]["amount"],
        "--unit", _["ethereum"]["unit"], "--network", _["ethereum"]["network"]
    ])
    assert fund.exit_code == 0
    assert is_transaction_raw(fund.output)
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)
Ejemplo n.º 3
0
def test_xinfin_cli_xrc20_fund(cli_tester):

    xrc20_fund = cli_tester.invoke(cli_main, [
        "xinfin", "fund", "--secret-hash",
        _["xinfin"]["xrc20_htlc"]["secret"]["hash"], "--recipient-address",
        _["xinfin"]["wallet"]["recipient"]["address"], "--sender-address",
        _["xinfin"]["wallet"]["sender"]["address"], "--endtime",
        get_current_timestamp(plus=3600), "--amount",
        _["xinfin"]["xrc20_amount"], "--network", _["xinfin"]["network"],
        "--token-address",
        _["xinfin"]["xrc20_htlc"]["agreements"]["token_address"], "--xrc20",
        True
    ])
    assert xrc20_fund.exit_code == 0
    assert is_transaction_raw(xrc20_fund.output)
Ejemplo n.º 4
0
def test_xinfin_fund_transaction():

    htlc = HTLC(
        contract_address=_["xinfin"]["htlc"]["contract_address"],
        network=_["xinfin"]["network"]).build_htlc(
            secret_hash=_["xinfin"]["htlc"]["secret"]["hash"],
            recipient_address=_["xinfin"]["wallet"]["recipient"]["address"],
            sender_address=_["xinfin"]["wallet"]["sender"]["address"],
            endtime=get_current_timestamp(plus=3600))

    unsigned_fund_transaction = FundTransaction(network=_["xinfin"]["network"])

    unsigned_fund_transaction.build_transaction(
        address=_["xinfin"]["wallet"]["sender"]["address"],
        htlc=htlc,
        amount=_["xinfin"]["amount"],
        unit=_["xinfin"]["unit"])

    assert unsigned_fund_transaction.type(
    ) == _["xinfin"]["fund"]["unsigned"]["type"]
    assert unsigned_fund_transaction.fee(
    ) == _["xinfin"]["fund"]["unsigned"]["fee"]
    assert unsigned_fund_transaction.hash(
    ) == _["xinfin"]["fund"]["unsigned"]["hash"]
    assert unsigned_fund_transaction.raw(
    ) == _["xinfin"]["fund"]["unsigned"]["raw"]
    assert isinstance(unsigned_fund_transaction.json(), dict)
    assert unsigned_fund_transaction.signature(
    ) == _["xinfin"]["fund"]["unsigned"]["signature"]
    assert isinstance(unsigned_fund_transaction.transaction_raw(), str)

    signed_fund_transaction = unsigned_fund_transaction.sign(solver=FundSolver(
        xprivate_key=_["xinfin"]["wallet"]["sender"]["root_xprivate_key"],
        path=_["xinfin"]["wallet"]["sender"]["derivation"]["path"],
        account=_["xinfin"]["wallet"]["sender"]["derivation"]["account"],
        change=_["xinfin"]["wallet"]["sender"]["derivation"]["change"],
        address=_["xinfin"]["wallet"]["sender"]["derivation"]["address"]))

    assert signed_fund_transaction.type(
    ) == _["xinfin"]["fund"]["signed"]["type"]
    assert signed_fund_transaction.fee(
    ) == _["xinfin"]["fund"]["signed"]["fee"]
    assert isinstance(signed_fund_transaction.hash(), str)
    assert isinstance(signed_fund_transaction.raw(), str)
    assert isinstance(signed_fund_transaction.json(), dict)
    assert isinstance(signed_fund_transaction.signature(), dict)
    assert isinstance(signed_fund_transaction.transaction_raw(), str)
Ejemplo n.º 5
0
)

import json

# Choose network mainnet or testnet
NETWORK: str = "mainnet"
# XinFin HTLC contract address
CONTRACT_ADDRESS: str = "xdc656869af3Ec1E8b2982Fc370A0526541C0Ceb90B"
# Secret key hash
SECRET_HASH: str = sha256("Hello Meheret!")
# XinFin sender wallet mnemonic
SENDER_MNEMONIC: str = "unfair divorce remind addict add roof park clown build renew illness fault"
# XinFin recipient address
RECIPIENT_ADDRESS: str = "xdcf8D43806260CFc6cC79fB408BA1897054667F81C"
# Expiration block timestamp
ENDTIME: int = get_current_timestamp(plus=3600)  # 1 hour
# XinFin fund amount
AMOUNT: int = amount_unit_converter(1, "XDC2Wei")

print("=" * 10, "Sender XinFin Account")

# Initialize XinFin sender wallet
sender_wallet: Wallet = Wallet(network=NETWORK)
# Get XinFin sender wallet from mnemonic
sender_wallet.from_mnemonic(mnemonic=SENDER_MNEMONIC)
# Drive XinFin sender wallet from path
sender_wallet.from_path(path=DEFAULT_PATH)

# Print some XinFin sender wallet info's
print("Root XPrivate Key:", sender_wallet.root_xprivate_key())
print("Root XPublic Key:", sender_wallet.root_xpublic_key())
Ejemplo n.º 6
0
from swap.utils import (
    sha256, get_current_timestamp
)

import json

# Choose network mainnet, solonet or testnet
NETWORK: str = "mainnet"
# Secret key hash
SECRET_HASH: str = sha256("Hello Meheret!")
# Bytom recipient public key
RECIPIENT_PUBLIC_KEY: str = "3e0a377ae4afa031d4551599d9bb7d5b27f4736d77f78cac4d476f0ffba5ae3e"
# Bytom sender public key
SENDER_PUBLIC_KEY: str = "fe6b3fd4458291b19605d92837ae1060cc0237e68022b2eb9faf01a118226212"
# Expiration block height
ENDBLOCK: int = estimate_endblock(endtime=get_current_timestamp(plus=3600))  # 1 hour

print("=" * 10, "Hash Time Lock Contract (HTLC) between Sender and Recipient")

# Initialize Bytom HTLC
htlc: HTLC = HTLC(network=NETWORK)
# Build HTLC contract
htlc.build_htlc(
    secret_hash=SECRET_HASH,
    recipient_public_key=RECIPIENT_PUBLIC_KEY,
    sender_public_key=SENDER_PUBLIC_KEY,
    endblock=ENDBLOCK
)

# Print all Bytom HTLC info's
print("HTLC Agreements:", json.dumps(htlc.agreements, indent=4))
Ejemplo n.º 7
0
                                        estimate_endblock)
from swap.utils import (sha256, get_current_timestamp)

import json

# Choose network mainnet, solonet or testnet
NETWORK: str = "mainnet"
# Secret key hash
SECRET_HASH: str = sha256("Hello Meheret!")
# Vapor sender wallet mnemonic
SENDER_MNEMONIC: str = "unfair divorce remind addict add roof park clown build renew illness fault"
# Vapor recipient public key
RECIPIENT_PUBLIC_KEY: str = "3e0a377ae4afa031d4551599d9bb7d5b27f4736d77f78cac4d476f0ffba5ae3e"
# Expiration block height
ENDBLOCK: int = estimate_endblock(
    endtime=get_current_timestamp(plus=3600))  # 1 hour
# Vapor fund amount
AMOUNT: int = amount_unit_converter(0.1, unit_from="BTM2NEU")

print("=" * 10, "Sender Vapor Account")

# Initialize Vapor sender wallet
sender_wallet: Wallet = Wallet(network=NETWORK)
# Get Vapor sender wallet from mnemonic
sender_wallet.from_mnemonic(mnemonic=SENDER_MNEMONIC)
# Drive Vapor sender wallet from path
sender_wallet.from_path(path=DEFAULT_PATH)

# Print some Vapor sender wallet info's
print("XPrivate Key:", sender_wallet.xprivate_key())
print("XPublic Key:", sender_wallet.xpublic_key())