Skip to content

Commit

Permalink
add test, add vet vtho transfer api, improve readme
Browse files Browse the repository at this point in the history
  • Loading branch information
laalaguer committed Jun 22, 2021
1 parent f928f09 commit 02a0201
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 39 deletions.
36 changes: 29 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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')
```
File renamed without changes.
35 changes: 5 additions & 30 deletions tests/test_vtho.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,45 +19,20 @@ 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))
tx_id = res["id"]
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)


Expand Down
4 changes: 2 additions & 2 deletions thor_requests/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand All @@ -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
-------
Expand Down

0 comments on commit 02a0201

Please sign in to comment.