forked from vechain-labs/vvet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
260 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
# Compile Contracts | ||
compile: | ||
. .env/bin/activate && cd vvet && brownie compile | ||
. .env/bin/activate && cd vvet && brownie compile | ||
|
||
test: | ||
. .env/bin/activate && cd vvet && python3 -m pytest -vv -s | ||
# Install compiler tools | ||
install: | ||
npm install -g ganache-cli | ||
python3 -m venv .env | ||
. .env/bin/activate && pip3 install wheel | ||
. .env/bin/activate && pip3 install -r requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
eth-brownie | ||
pytest | ||
thor-requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[pytest] | ||
testpaths = | ||
tests |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import pytest | ||
from thor_requests.connect import Connect | ||
from thor_requests.contract import Contract | ||
from thor_requests.wallet import Wallet | ||
|
||
|
||
@pytest.fixture | ||
def vtho_contract_address(): | ||
return "0x0000000000000000000000000000456e65726779" | ||
|
||
|
||
@pytest.fixture | ||
def solo_connector(): | ||
endpoints = ["http://localhost:8669", "http://solo.veblocks.net"] | ||
for x in endpoints: | ||
c = Connect(x) | ||
try: | ||
c.get_chainTag() | ||
return c | ||
except: | ||
continue | ||
|
||
raise Exception("Cannot connect to a reliable solo node to run tests") | ||
|
||
|
||
@pytest.fixture | ||
def solo_wallet(): | ||
return Wallet.fromMnemonic( | ||
[ | ||
"denial", | ||
"kitchen", | ||
"pet", | ||
"squirrel", | ||
"other", | ||
"broom", | ||
"bar", | ||
"gas", | ||
"better", | ||
"priority", | ||
"spoil", | ||
"cross", | ||
] | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def testnet_connector(): | ||
return Connect("http://testnet.veblocks.net") | ||
|
||
|
||
@pytest.fixture | ||
def mainnet_connector(): | ||
return Connect("http://mainnet.veblocks.net") | ||
|
||
|
||
@pytest.fixture | ||
def testnet_wallet(): | ||
return Wallet.fromPrivateKey( | ||
bytes.fromhex( | ||
"dce1443bd2ef0c2631adc1c67e5c93f13dc23a41c18b536effbbdcbcdb96fb65" | ||
) | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def mainnet_wallet(): | ||
return Wallet.fromPrivateKey( | ||
bytes.fromhex( | ||
"dce1443bd2ef0c2631adc1c67e5c93f13dc23a41c18b536effbbdcbcdb96fb65" | ||
) | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def clean_wallet(): | ||
return Wallet.newWallet() | ||
|
||
|
||
@pytest.fixture | ||
def vthobox_contract(): | ||
return Contract.fromFile("build/contracts/VTHOBox.json") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import time | ||
import pytest | ||
from thor_requests import utils | ||
from .fixtures import ( | ||
testnet_connector, | ||
testnet_wallet, | ||
vthobox_contract | ||
) | ||
|
||
@pytest.fixture(autouse=True) | ||
def deploy_contract(testnet_connector, testnet_wallet, vthobox_contract): | ||
''' test the storage gas ''' | ||
res = testnet_connector.deploy(testnet_wallet, vthobox_contract, None, None, 0) | ||
assert "id" in res # Should contain a {'id': '0x...' } | ||
# print(f"deploy_vvet_tx_id: {res['id']}") | ||
tx_id = res["id"] | ||
# Should have the deployed contract address now | ||
receipt = testnet_connector.wait_for_tx_receipt(tx_id) | ||
created_contracts = utils.read_created_contracts(receipt) | ||
assert len(created_contracts) == 1 | ||
# print(f"created_vvet_address: {created_contracts[0]}") | ||
return created_contracts[0] | ||
|
||
def test_store(deploy_contract, testnet_connector, testnet_wallet, vthobox_contract): | ||
''' Transaction of add some VET ''' | ||
print("wallet:addr:", testnet_wallet.getAddress()) | ||
contract_addr = deploy_contract | ||
print("contract:addr:", contract_addr) | ||
|
||
# Call to get the balance of user's vet | ||
res = testnet_connector.call( | ||
testnet_wallet.getAddress(), | ||
vthobox_contract, | ||
"vetBalance", | ||
[testnet_wallet.getAddress()], | ||
contract_addr | ||
) | ||
assert res["reverted"] == False | ||
assert res["decoded"]["0"] == 0 # nothing added, so no vet is there | ||
print('call:vetBalance:gas:', res["gasUsed"]) | ||
|
||
# Call to get the balance of user's vtho | ||
res = testnet_connector.call( | ||
testnet_wallet.getAddress(), | ||
vthobox_contract, | ||
"vthoBalance", | ||
[testnet_wallet.getAddress()], | ||
contract_addr | ||
) | ||
assert res["reverted"] == False | ||
assert res["decoded"]["0"] == 0 # nothing added, so no vtho is there | ||
print('call:vthoBalance:gas:', res["gasUsed"]) | ||
|
||
# Add 3 vet for the first time | ||
res = testnet_connector.transact( | ||
testnet_wallet, | ||
vthobox_contract, | ||
"addVET", | ||
[testnet_wallet.getAddress(), 3 * (10 ** 18)], | ||
contract_addr | ||
) | ||
assert res["id"] | ||
|
||
tx_id = res["id"] | ||
receipt = testnet_connector.wait_for_tx_receipt(tx_id) | ||
print('transact:addVET:gas:', receipt["gasUsed"]) | ||
|
||
time.sleep(12) | ||
|
||
# Call to get the balance of user's vet | ||
res = testnet_connector.call( | ||
testnet_wallet.getAddress(), | ||
vthobox_contract, | ||
"vetBalance", | ||
[testnet_wallet.getAddress()], | ||
contract_addr | ||
) | ||
assert res["reverted"] == False | ||
assert res["decoded"]["0"] == 3 * (10 ** 18) # 3 vet should be there | ||
print('call:vetBalance:gas:', res["gasUsed"]) | ||
|
||
# Call to get the balance of user's vtho | ||
res = testnet_connector.call( | ||
testnet_wallet.getAddress(), | ||
vthobox_contract, | ||
"vthoBalance", | ||
[testnet_wallet.getAddress()], | ||
contract_addr | ||
) | ||
assert res["reverted"] == False | ||
assert res["decoded"]["0"] > 0 # Some vtho should be there | ||
print('call:vthoBalance:gas:', res["gasUsed"]) | ||
|
||
# Add more VET (3) to the user | ||
res = testnet_connector.transact( | ||
testnet_wallet, | ||
vthobox_contract, | ||
"addVET", | ||
[testnet_wallet.getAddress(), 3 * (10 ** 18)], | ||
contract_addr | ||
) | ||
assert res["id"] | ||
|
||
tx_id = res["id"] | ||
receipt = testnet_connector.wait_for_tx_receipt(tx_id) | ||
print('transact:addVET:gas:', receipt["gasUsed"]) | ||
|
||
time.sleep(12) | ||
|
||
# Call to get the balance of user's vet | ||
res = testnet_connector.call( | ||
testnet_wallet.getAddress(), | ||
vthobox_contract, | ||
"vetBalance", | ||
[testnet_wallet.getAddress()], | ||
contract_addr | ||
) | ||
assert res["reverted"] == False | ||
assert res["decoded"]["0"] == 6 * (10 ** 18) # 6 vet should be there | ||
print('call:vetBalance:gas:', res["gasUsed"]) | ||
|
||
# Call to get the balance of user's vtho | ||
res = testnet_connector.call( | ||
testnet_wallet.getAddress(), | ||
vthobox_contract, | ||
"vthoBalance", | ||
[testnet_wallet.getAddress()], | ||
contract_addr | ||
) | ||
assert res["reverted"] == False | ||
assert res["decoded"]["0"] > 0 # Some vtho should be there | ||
print('call:vthoBalance:gas:', res["gasUsed"]) |