Example #1
0
def test_ethereum_erc20_htlc():

    erc20_htlc = HTLC(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=_["ethereum"]["erc20_htlc"]["endtime"],
        token_address=_["ethereum"]["erc20_htlc"]["agreements"]
        ["token_address"])

    assert erc20_htlc.abi() == _["ethereum"]["erc20_htlc"]["abi"]
    assert erc20_htlc.bytecode() == _["ethereum"]["erc20_htlc"]["bytecode"]
    assert erc20_htlc.bytecode_runtime(
    ) == _["ethereum"]["erc20_htlc"]["bytecode_runtime"]
    assert erc20_htlc.opcode() == _["ethereum"]["erc20_htlc"]["opcode"]
    assert erc20_htlc.contract_address(
    ) == _["ethereum"]["erc20_htlc"]["contract_address"]
    assert erc20_htlc.agreements["secret_hash"] == _["ethereum"]["erc20_htlc"][
        "agreements"]["secret_hash"]
    assert erc20_htlc.agreements["recipient_address"] == _["ethereum"][
        "erc20_htlc"]["agreements"]["recipient_address"]
    assert erc20_htlc.agreements["sender_address"] == _["ethereum"][
        "erc20_htlc"]["agreements"]["sender_address"]
    # assert erc20_htlc.agreements["endtime"]["datetime"] == _["ethereum"]["erc20_htlc"]["agreements"]["endtime"]["datetime"]
    assert erc20_htlc.agreements["endtime"]["timestamp"] == _["ethereum"][
        "erc20_htlc"]["agreements"]["endtime"]["timestamp"]
    assert erc20_htlc.agreements["token_address"] == _["ethereum"][
        "erc20_htlc"]["agreements"]["token_address"]
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)
Example #3
0
# Ethereum HTLC contract address
CONTRACT_ADDRESS: str = "0xE5cb615899436A490dBde26d7880A0C2502Fc676"
# Secret key hash
SECRET_HASH: str = sha256("Hello Meheret!")
# Ethereum recipient address
RECIPIENT_ADDRESS: str = "0x1954C47a5D75bdDA53578CEe5D549bf84b8c6B94"
# Ethereum sender address
SENDER_ADDRESS: str = "0x69e04fe16c9A6A83076B3c2dc4b4Bc21b5d9A20C"
# Expiration block timestamp
ENDTIME: int = get_current_timestamp(plus=3600)  # 1 hour

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

# Initialize Ethereum HTLC
htlc: HTLC = HTLC(
    contract_address=CONTRACT_ADDRESS, network=NETWORK
)
# Build HTLC contract
htlc.build_htlc(
    secret_hash=SECRET_HASH,
    recipient_address=RECIPIENT_ADDRESS,
    sender_address=SENDER_ADDRESS,
    endtime=ENDTIME
)

# Print all Ethereum HTLC info's
print("HTLC Agreements:", json.dumps(htlc.agreements, indent=4))
print("HTLC ABI:", htlc.abi())
print("HTLC Bytecode:", htlc.bytecode())
print("HTLC Bytecode Runtime:", htlc.bytecode_runtime())
print("HTLC OP_Code:", htlc.opcode())
Example #4
0
SECRET_HASH: str = sha256("Hello Meheret!")
# Ethereum recipient address
RECIPIENT_ADDRESS: str = "0x1954C47a5D75bdDA53578CEe5D549bf84b8c6B94"
# Ethereum sender address
SENDER_ADDRESS: str = "0x69e04fe16c9A6A83076B3c2dc4b4Bc21b5d9A20C"
# Expiration block timestamp
ENDTIME: int = get_current_timestamp(plus=3600)  # 1 hour
# Ethereum ERC20 token address
TOKEN_ADDRESS: str = "0xa6f89f08cC9d112870E2561F1A8D750681DB59f1"

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

# Initialize Ethereum HTLC ERC20
htlc_erc20: HTLC = HTLC(contract_address=CONTRACT_ADDRESS,
                        network=NETWORK,
                        erc20=ERC20)
# Build HTLC ERC20 contract
htlc_erc20.build_htlc(secret_hash=SECRET_HASH,
                      recipient_address=RECIPIENT_ADDRESS,
                      sender_address=SENDER_ADDRESS,
                      endtime=ENDTIME,
                      token_address=TOKEN_ADDRESS)

# Print all Ethereum HTLC ERC20 info's
print("HTLC ERC20 Agreements:", json.dumps(htlc_erc20.agreements, indent=4))
print("HTLC ERC20 ABI:", htlc_erc20.abi())
print("HTLC ERC20 Bytecode:", htlc_erc20.bytecode())
print("HTLC ERC20 Bytecode Runtime:", htlc_erc20.bytecode_runtime())
print("HTLC ERC20 OP_Code:", htlc_erc20.opcode())
print("HTLC ERC20 Contract Address:", htlc_erc20.contract_address())
Example #5
0
print("=" * 10, "Deploy HTLC from Ethereum Account")

# Initialize Ethereum wallet
wallet: Wallet = Wallet(network=NETWORK)
# Get Ethereum wallet from private key
wallet.from_private_key(private_key=PRIVATE_KEY)

print("Private Key:", wallet.private_key())
print("Public Key:", wallet.public_key())
print("Address:", wallet.address())
print("Balance:", wallet.balance(unit="Ether"), "Ether")

print("=" * 10, "Compile Hash Time Lock Contract (HTLC) Smart contract")

# Initialize Ethereum HTLC
htlc: HTLC = HTLC(network=NETWORK)

print("HTLC ABI:", htlc.abi())
print("HTLC Bytecode:", htlc.bytecode())
print("HTLC Bytecode Runtime:", htlc.bytecode_runtime())
print("HTLC OP_Code:", htlc.opcode())

print("=" * 10, "Build, Sign and Submit HTLC Transaction")

# Build HTLC transaction
htlc.build_transaction(address=wallet.address())

# Sign HTLC transaction
htlc.sign_transaction(private_key=wallet.private_key())

# Submit HTLC transaction raw
Example #6
0
print("=" * 10, "Deploy HTLC ERC20 from Ethereum Account")

# Initialize Ethereum wallet
wallet: Wallet = Wallet(network=NETWORK)
# Get Ethereum wallet from private key
wallet.from_private_key(private_key=PRIVATE_KEY)

print("Private Key:", wallet.private_key())
print("Public Key:", wallet.public_key())
print("Address:", wallet.address())
print("Balance:", wallet.balance(unit="Ether"), "Ether")

print("=" * 10, "Compile Hash Time Lock Contract (HTLC) ERC20 Smart contract")

# Initialize Ethereum HTLC ERC20
htlc_erc20: HTLC = HTLC(network=NETWORK, erc20=ERC20)

print("HTLC ERC20 ABI:", htlc_erc20.abi())
print("HTLC ERC20 Bytecode:", htlc_erc20.bytecode())
print("HTLC ERC20 Bytecode Runtime:", htlc_erc20.bytecode_runtime())
print("HTLC ERC20 OP_Code:", htlc_erc20.opcode())

print("=" * 10, "Build, Sign and Submit HTLC ERC20 Transaction")

# Build HTLC ERC20 transaction
htlc_erc20.build_transaction(address=wallet.address())

# Sign HTLC ERC20 transaction
htlc_erc20.sign_transaction(private_key=wallet.private_key())

# Submit HTLC ERC20 transaction raw