Skip to content

Commit

Permalink
8th oct. test_fds_wallet all tests passed
Browse files Browse the repository at this point in the history
  • Loading branch information
Aviksaikat committed Oct 8, 2023
1 parent 4f885e2 commit ee20598
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .build/__local__.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/fds/fds_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ def generate(self, password):

def from_json(self, wallet_json, password):
try:
account = Account.decrypt(wallet_json, password)
private_key = Account.decrypt(wallet_json, password)
account = Account.from_key(private_key)
# print(account)
wallet = WalletClass(
{
"address": account.address.lower(),
Expand Down
3 changes: 3 additions & 0 deletions src/fds/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ def wallet_instance(test_wallet):
return test_wallet


# * Ape fixtures


@pytest.fixture(autouse=True)
def setenviron(monkeypatch):
"""
Expand Down
53 changes: 31 additions & 22 deletions src/fds/tests/unit_tests/test_fds_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def test_generate_wallet(wallet_instance):
# password = "test_password"
# generated_wallet = test_wallet.generate(password)
generated_wallet = wallet_instance
print(generated_wallet)
# print(generated_wallet.wallet_v3)

assert generated_wallet.wallet.address != ""
assert generated_wallet.wallet.publicKey != ""
Expand All @@ -17,34 +17,43 @@ def test_generate_wallet(wallet_instance):
assert generated_wallet.wallet_v3


# def test_from_json_valid(test_wallet):
# password = "test_password"
# generated_wallet = test_wallet.generate(password)
# wallet_json = json.dumps(generated_wallet.wallet_v3)
def test_from_json_valid(test_wallet):
password = "test_password"
generated_wallet = test_wallet.generate(password)
wallet_json = json.dumps(generated_wallet.wallet_v3)

# wallet_from_json = test_wallet.from_json(wallet_json, password)
wallet_from_json = test_wallet.from_json(wallet_json, password)

# assert wallet_from_json.address == generated_wallet.wallet.address
# assert wallet_from_json.publicKey == generated_wallet.wallet.publicKey
# assert wallet_from_json.privateKey == generated_wallet.wallet.privateKey
assert wallet_from_json.address == generated_wallet.wallet.address
assert wallet_from_json.publicKey == generated_wallet.wallet.publicKey
assert wallet_from_json.privateKey == generated_wallet.wallet.privateKey


# def test_from_json_invalid(test_wallet):
# password = "test_password"
# generated_wallet = test_wallet.generate(password)
# wallet_json = json.dumps(generated_wallet.wallet_v3)
def test_fail_from_json_invalid(test_wallet):
password = "test_password"
generated_wallet = test_wallet.generate(password)
wallet_json = json.dumps(generated_wallet.wallet_v3)

# # Provide an incorrect password to test decryption failure
# invalid_password = "wrong_password"
# wallet_from_json = test_wallet.from_json(wallet_json, invalid_password)
# Provide an incorrect password to test decryption failure
invalid_password = "wrong_password"
try:
wallet_from_json = test_wallet.from_json(wallet_json, invalid_password)
except ValueError as e:
assert str(e) == "MAC mismatch", f"Unexpected error message: {e}"
return

# assert wallet_from_json is False
# If no exception was raised, the test fails
assert (
False
), 'Expected a ValueError with message "MAC mismatch", but no exception was raised'


# def test_encrypt(test_wallet):
# private_key = "0x1234567890abcdef" # Replace with a valid private key
# password = "test_password"
def test_encrypt(test_wallet):
private_key = "0x7cbb15a540c3954792bf3729f9b26c0242e745890332bcf2ffeaece345f9d141" # Replace with a valid private key
password = "test_password"

# wallet_json = test_wallet.encrypt(private_key, password)
wallet_json = test_wallet.encrypt(private_key, password)

# assert isinstance(wallet_json, str)
# print(wallet_json)

assert isinstance(wallet_json, str)

0 comments on commit ee20598

Please sign in to comment.