def test_normal_transaction(): wallet: Wallet = Wallet(provider=HTTP_PROVIDER).from_entropy( entropy=_["wallet"]["entropy"], passphrase=_["wallet"]["passphrase"], language=_["wallet"]["language"]).from_path(path=_["wallet"]["path"]) normal_transaction: NormalTransaction = NormalTransaction( provider=HTTP_PROVIDER) normal_transaction.build_transaction( address=wallet.address(prefix="xdc"), recipient="xdc9Cd6fD3519b259B251d881361CAae6BABdC5910b", value=amount_unit_converter(amount=0.1, unit="XDC2Wei")) normal_transaction.sign_transaction( root_xprivate_key=_["wallet"]["root_xprivate_key"], path=_["wallet"]["path"]) assert normal_transaction.fee( ) == _["transaction"]["normal_transaction"]["fee"] assert normal_transaction.hash( ) == _["transaction"]["normal_transaction"]["hash"] assert normal_transaction.raw( ) == _["transaction"]["normal_transaction"]["raw"] assert normal_transaction.json( ) == _["transaction"]["normal_transaction"]["json"]
def test_contract_transaction(): wallet: Wallet = Wallet(provider=HTTP_PROVIDER).from_entropy( entropy=_["wallet"]["entropy"], passphrase=_["wallet"]["passphrase"], language=_["wallet"]["language"]).from_path(path=_["wallet"]["path"]) contract_transaction: ContractTransaction = ContractTransaction( provider=HTTP_PROVIDER) contract_transaction.build_transaction( address=wallet.address(prefix="xdc"), abi=ABI, bytecode=BYTECODE, value=amount_unit_converter(amount=0, unit="XDC2Wei"), estimate_gas=True) contract_transaction.sign_transaction( private_key=_["wallet"]["private_key"]) assert contract_transaction.fee( ) == _["transaction"]["contract_transaction"]["fee"] assert contract_transaction.hash( ) == _["transaction"]["contract_transaction"]["hash"] assert contract_transaction.raw( ) == _["transaction"]["contract_transaction"]["raw"] assert contract_transaction.json( ) == _["transaction"]["contract_transaction"]["json"]
def test_from_mnemonic(): wallet: Wallet = Wallet(provider=HTTP_PROVIDER).from_mnemonic( mnemonic=_["wallet"]["mnemonic"], passphrase=_["wallet"]["passphrase"], language=_["wallet"]["language"]).from_path(path=_["wallet"]["path"]) assert wallet.strength() == _["wallet"]["strength"] assert wallet.entropy() == _["wallet"]["entropy"] assert wallet.mnemonic() == _["wallet"]["mnemonic"] assert wallet.language() == _["wallet"]["language"] assert wallet.passphrase() is None assert wallet.seed() == _["wallet"]["seed"] assert wallet.root_xprivate_key( encoded=True) == _["wallet"]["root_xprivate_key"] assert wallet.root_xprivate_key( encoded=False) == _["wallet"]["root_xprivate_key_hex"] assert wallet.root_xpublic_key( encoded=True) == _["wallet"]["root_xpublic_key"] assert wallet.root_xpublic_key( encoded=False) == _["wallet"]["root_xpublic_key_hex"] assert wallet.xprivate_key(encoded=True) == _["wallet"]["xprivate_key"] assert wallet.xprivate_key( encoded=False) == _["wallet"]["xprivate_key_hex"] assert wallet.xpublic_key(encoded=True) == _["wallet"]["xpublic_key"] assert wallet.xpublic_key(encoded=False) == _["wallet"]["xpublic_key_hex"] assert wallet.uncompressed() == _["wallet"]["uncompressed"] assert wallet.compressed() == _["wallet"]["compressed"] assert wallet.private_key() == _["wallet"]["private_key"] assert wallet.public_key() == _["wallet"]["public_key"] assert wallet.wif() == _["wallet"]["wif"] assert wallet.finger_print() == _["wallet"]["finger_print"] assert wallet.semantic() == _["wallet"]["semantic"] assert wallet.path() == _["wallet"]["path"] assert wallet.hash() == _["wallet"]["hash"] assert wallet.address(prefix="xdc") == _["wallet"]["address_xdc"] assert wallet.address(prefix="0x") == _["wallet"]["address_0x"] assert isinstance(wallet.dumps(), dict) # assert isinstance(wallet.balance(unit="XDC"), float) signature: str = wallet.sign(message=MESSAGE) assert isinstance(signature, str) assert wallet.verify(signature=signature, message=MESSAGE)
#!/usr/bin/env python3 from pyxdc import HTTP_PROVIDER from pyxdc.wallet import Wallet from pyxdc.utils import amount_unit_converter import json # Wallet seed SEED: str = "b3337a2fe409afbb257b504e4c09d36b57c32c452b71a0ed413298a5172f727a06bf6605488" \ "723bc545a4bd51f5cd29a3e8bd1433bd1d26e6bf866ff53d1493f" # Initialize XinFin mainnet Wallet wallet: Wallet = Wallet(provider=HTTP_PROVIDER) # Get XinFin Wallet from seed wallet.from_seed(seed=SEED) # Derivation from path wallet.from_path("m/44'/550'/0'/0/0") # Or derivation from index # wallet.from_index(44, hardened=True) # wallet.from_index(550, hardened=True) # wallet.from_index(0, hardened=True) # wallet.from_index(0) # wallet.from_index(0) # Print all XinFin Wallet information's # print(json.dumps(wallet.dumps(), indent=4, ensure_ascii=False)) print("Seed:", wallet.seed()) print("Root XPrivate Key:", wallet.root_xprivate_key())