Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change all tests to use pytest #290

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 0 additions & 46 deletions multiversx_sdk_cli/tests/test_accounts.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,10 @@
from pathlib import Path

import pytest

Check failure on line 3 in multiversx_sdk_cli/tests/test_accounts.py

View workflow job for this annotation

GitHub Actions / runner / mypy

[mypy] reported by reviewdog 🐶 Cannot find implementation or library stub for module named "pytest" [import] Raw Output: /home/runner/work/mx-sdk-py-cli/mx-sdk-py-cli/multiversx_sdk_cli/tests/test_accounts.py:3:1: error: Cannot find implementation or library stub for module named "pytest" [import]
from multiversx_sdk_core import Address, Transaction, TransactionPayload

from multiversx_sdk_cli.accounts import Account


def test_sign_transaction():
alice_pem = Path(__file__).parent / "testdata" / "alice.pem"
alice = Account(pem_file=str(alice_pem))

# With data
transaction = Transaction(
chain_id="chainID",
sender=Address.from_bech32("erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz"),
receiver=Address.from_bech32("erd188nydpkagtpwvfklkl2tn0w6g40zdxkwfgwpjqc2a2m2n7ne9g8q2t22sr"),
gas_limit=500000000,
gas_price=200000000000000,
nonce=0,
value=0,
data=TransactionPayload.from_str("foo"),
version=1
)
transaction.signature = bytes.fromhex(alice.sign_transaction(transaction))

assert "0e69f27e24aba2f3b7a8842dc7e7c085a0bfb5b29112b258318eed73de9c8809889756f8afaa74c7b3c7ce20a028b68ba90466a249aaf999a1a78dcf7f4eb40c" == transaction.signature.hex()

# Without data
transaction = Transaction(
chain_id="chainID",
sender=Address.from_bech32("erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz"),
receiver=Address.from_bech32("erd188nydpkagtpwvfklkl2tn0w6g40zdxkwfgwpjqc2a2m2n7ne9g8q2t22sr"),
gas_limit=500000000,
gas_price=200000000000000,
nonce=0,
value=0,
version=1
)
transaction.signature = bytes.fromhex(alice.sign_transaction(transaction))

assert "83efd1bc35790ecc220b0ed6ddd1fcb44af6653dd74e37b3a49dcc1f002a1b98b6f79779192cca68bdfefd037bc81f4fa606628b751023122191f8c062362805" == transaction.signature.hex()


def test_sign_message():
alice_pem = Path(__file__).parent / "testdata" / "alice.pem"
alice = Account(pem_file=str(alice_pem))

message = b"hello"
signature = alice.sign_message(message)
assert signature == "561bc58f1dc6b10de208b2d2c22c9a474ea5e8cabb59c3d3ce06bbda21cc46454aa71a85d5a60442bd7784effa2e062fcb8fb421c521f898abf7f5ec165e5d0f"


def test_load_account_from_keystore_without_kind():
alice_json = Path(__file__).parent / "testdata" / "alice.json"
account = Account(key_file=str(alice_json), password="password")
Expand Down
1 change: 1 addition & 0 deletions multiversx_sdk_cli/tests/test_cli_contracts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path

from multiversx_sdk_cli.cli import main


Expand Down
3 changes: 3 additions & 0 deletions multiversx_sdk_cli/tests/test_code_metadata.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
from multiversx_sdk_cli.contracts import CodeMetadata


def test_code_metadata_defaults():
assert CodeMetadata().to_hex() == "0500"
assert CodeMetadata().to_hex() == CodeMetadata(upgradeable=True, readable=True, payable=False, payable_by_sc=False).to_hex()


def test_code_metadata_single_flag():
assert CodeMetadata(upgradeable=False, readable=False, payable=False, payable_by_sc=False).to_hex() == "0000"
assert CodeMetadata(upgradeable=True, readable=False, payable=False, payable_by_sc=False).to_hex() == "0100"
assert CodeMetadata(upgradeable=False, readable=True, payable=False, payable_by_sc=False).to_hex() == "0400"
assert CodeMetadata(upgradeable=False, readable=False, payable=True, payable_by_sc=False).to_hex() == "0002"
assert CodeMetadata(upgradeable=False, readable=False, payable=False, payable_by_sc=True).to_hex() == "0004"


def test_code_metadata_multiple_flags():
assert CodeMetadata(upgradeable=False, readable=True, payable=False, payable_by_sc=True).to_hex() == "0404"
assert CodeMetadata(upgradeable=True, readable=True, payable=False, payable_by_sc=False).to_hex() == "0500"
Expand Down
22 changes: 10 additions & 12 deletions multiversx_sdk_cli/tests/test_ledger.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import unittest

from multiversx_sdk_cli.ledger.config import compare_versions
from multiversx_sdk_cli.ledger.ledger_app_handler import get_error


class LedgerTestCase(unittest.TestCase):
class TestLedger:
def test_compare_versions(self):
self.assertEqual(compare_versions("v1.0.0", "v1.0.1"), -1)
self.assertEqual(compare_versions("v1.0.1", "v1.0.1"), 0)
self.assertEqual(compare_versions("v1.0.1", "v1.0.0"), 1)
self.assertEqual(compare_versions("v1.0.0.1", "v1.0.0"), 1)
self.assertEqual(compare_versions("v1.0.1", "v1.0.1.0.0.4"), -1)
assert compare_versions("v1.0.0", "v1.0.1") == -1
assert compare_versions("v1.0.1", "v1.0.1") == 0
assert compare_versions("v1.0.1", "v1.0.0") == 1
assert compare_versions("v1.0.0.1", "v1.0.0") == 1
assert compare_versions("v1.0.1", "v1.0.1.0.0.4") == -1

def test_get_error(self):
self.assertEqual(get_error(0x6E0C), "invalid fee")
self.assertEqual(get_error(0x6E11), "regular signing is deprecated")
self.assertEqual(get_error(0x9000), "")
self.assertEqual(get_error(0x9999999999), "unknown error code: 0x9999999999")
assert get_error(0x6E0C) == "invalid fee"
assert get_error(0x6E11) == "regular signing is deprecated"
assert get_error(0x9000) == ""
assert get_error(0x9999999999) == "unknown error code: 0x9999999999"
3 changes: 2 additions & 1 deletion multiversx_sdk_cli/tests/test_modules.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import semver
import pytest
import semver

from multiversx_sdk_cli.config import get_latest_semver


Expand Down
13 changes: 6 additions & 7 deletions multiversx_sdk_cli/tests/test_playground_proxy.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import unittest

import pytest

Check failure on line 1 in multiversx_sdk_cli/tests/test_playground_proxy.py

View workflow job for this annotation

GitHub Actions / runner / mypy

[mypy] reported by reviewdog 🐶 Cannot find implementation or library stub for module named "pytest" [import] Raw Output: /home/runner/work/mx-sdk-py-cli/mx-sdk-py-cli/multiversx_sdk_cli/tests/test_playground_proxy.py:1:1: error: Cannot find implementation or library stub for module named "pytest" [import]
import requests


class TestPlaygroundProxy(unittest.TestCase):
@unittest.skip('manual run only')
class TestPlaygroundProxy:
@pytest.mark.skip('manual run only')
def test_do_request(self):
# use a valid proxy address
url = "http://localhost:8001"
Expand All @@ -13,9 +12,9 @@
response = requests.get(url + "/address/" + address + "/nonce")
print("response status code " + str(response.status_code))
print(response.json())
self.assertTrue(self, response is not None)
assert response is not None

@unittest.skip('manual run only')
@pytest.mark.skip('manual run only')
def test_do_request_node_status(self):
# use a valid proxy address
url = "http://localhost:8001"
Expand All @@ -25,4 +24,4 @@
response = requests.get(f"{url}/network/status/{shard_id}")
print("response status code " + str(response.status_code))
print(response.json())
self.assertTrue(self, response is not None)
assert response is not None
5 changes: 2 additions & 3 deletions multiversx_sdk_cli/tests/test_rust.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import logging
import unittest
from pathlib import Path

from multiversx_sdk_cli import utils

logging.basicConfig(level=logging.INFO)


class ProjectRustTestCase(unittest.TestCase):
def setUp(self):
class TestProjectRust:
def test_set_up(self):
self.testdata = Path(__file__).parent.joinpath("testdata")
self.testdata_out = Path(__file__).parent.joinpath("testdata-out")
utils.ensure_folder(self.testdata_out)
12 changes: 5 additions & 7 deletions multiversx_sdk_cli/tests/test_validators_file.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import unittest
from pathlib import Path

from multiversx_sdk_cli.validators.validators_file import ValidatorsFile


class ValidatorsFileTestCase(unittest.TestCase):
def setUp(self) -> None:
self.testdata = Path(__file__).parent.joinpath("testdata")
self.validators_file_path = self.testdata / "validators.json"
class ValidatorsFileTestCase:
testdata = Path(__file__).parent.joinpath("testdata")
validators_file_path = testdata / "validators.json"

def test_read_validators_files_num_of_nodes(self):
validators_file = ValidatorsFile(self.validators_file_path)

num_of_nodes = validators_file.get_num_of_nodes()
self.assertEqual(3, num_of_nodes)
assert num_of_nodes == 3

def test_read_validators_files_get_validators_list(self):
validators_file = ValidatorsFile(self.validators_file_path)

validators_list = validators_file.get_validators_list()
self.assertEqual(3, len(validators_list))
assert len(validators_list) == 3
Loading