diff --git a/README.md b/README.md index c07757a..4283917 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ +# thor-request.py VeChain for humans. This library enables you to talk to VeChain blockchain without hassle. -Covers most topic on contract interaction, vet transfer and transaction debug. +- Covers most topic on contract interaction, vet transfer, vtho transfer and transaction debug. -It automatically estimate gas and decode events/revert reasons for you. +- Automatically estimate gas and decode events/revert reasons for you. ## Installation @@ -241,10 +242,31 @@ print(res) # >>> {'id': '0x51222328b7395860cb9cc6d69d822cf31056851b5694eeccc9f243021eecd547'} ``` -## Local Development -``` -... run a local thor node at 127.0.0.1:8669 -... then test the whole suite: +# Examples (VET and VTHO) +```python +from thor_requests.connect import Connect +from thor_requests.wallet import Wallet + +connector = Connect("http://testnet.veblocks.net") + +# wallet address: 0x7567d83b7b8d80addcb281a71d54fc7b3364ffed +_wallet = Wallet.fromPrivateKey(bytes.fromhex("dce1443bd2ef0c2631adc1c67e5c93f13dc23a41c18b536effbbdcbcdb96fb65")) + +# Transfer 3 VET to 0x0000000000000000000000000000000000000000 +connector.transfer_vet( + _wallet, + to='0x0000000000000000000000000000000000000000', + value=3 * (10 ** 18) +) + +# Transfer 3 VTHO to 0x0000000000000000000000000000000000000000 +connector.transfer_vtho( + _wallet, + to='0x0000000000000000000000000000000000000000', + vtho_in_wei=3 * (10 ** 18) +) -$ make test +# Check VET or VTHO balance of an address: 0x0000000000000000000000000000000000000000 +amount_vet = connector.get_vet_balance('0x0000000000000000000000000000000000000000') +amount_vtho = connector.get_vtho_balance('0x0000000000000000000000000000000000000000') ``` \ No newline at end of file diff --git a/tests/test_transfer.py b/tests/test_vet.py similarity index 100% rename from tests/test_transfer.py rename to tests/test_vet.py diff --git a/tests/test_vtho.py b/tests/test_vtho.py index 8a00d3f..a471ae8 100644 --- a/tests/test_vtho.py +++ b/tests/test_vtho.py @@ -19,28 +19,12 @@ def test_transfer_vtho_easy( vtho_contract ): # Check the sender's vtho balance - res = solo_connector.call( - solo_wallet.getAddress(), - vtho_contract, - "balanceOf", - [solo_wallet.getAddress()], - vtho_contract_address, - value=0, - ) - assert res["reverted"] == False - assert res["decoded"]["balance"] > 0 + sender_balance = solo_connector.get_vtho_balance(solo_wallet.getAddress()) + assert sender_balance > 0 # Check the receiver's vtho balance - res = solo_connector.call( - clean_wallet.getAddress(), - vtho_contract, - "balanceOf", - [clean_wallet.getAddress()], - vtho_contract_address, - value=0, - ) - assert res["reverted"] == False - assert res["decoded"]["balance"] == 0 + receiver_balance = solo_connector.get_vtho_balance(clean_wallet.getAddress()) + assert receiver_balance == 0 # Do the vtho transfer! res = solo_connector.transfer_vtho(solo_wallet, clean_wallet.getAddress(), 3 * (10 ** 18)) @@ -48,16 +32,7 @@ def test_transfer_vtho_easy( receipt = solo_connector.wait_for_tx_receipt(tx_id) # Check the receiver's vtho balance - res = solo_connector.call( - clean_wallet.getAddress(), - vtho_contract, - "balanceOf", - [clean_wallet.getAddress()], - vtho_contract_address, - value=0, - ) - assert res["reverted"] == False - updated_balance = res["decoded"]["balance"] + updated_balance = solo_connector.get_vtho_balance(clean_wallet.getAddress()) assert updated_balance == 3 * (10 ** 18) diff --git a/thor_requests/connect.py b/thor_requests/connect.py index 4686fc0..dd27a75 100644 --- a/thor_requests/connect.py +++ b/thor_requests/connect.py @@ -68,7 +68,7 @@ def get_vet_balance(self, address: str, block: str = "best") -> int: address : str The address of the account block : str, optional - The block ID or number, by default "best" + Query against which block, the block ID or number, by default "best" Returns ------- @@ -87,7 +87,7 @@ def get_vtho_balance(self, address: str, block: str = "best") -> int: address : str The address of the account block : str, optional - The block ID or number, by default "best" + Query against which block, the block ID or number, by default "best" Returns -------