Skip to content

Commit 90b0ac2

Browse files
author
Jeff Schroeder
committed
Addressing mapping account tests review feedback
thanks @cctdaniel
1 parent 6bcddd4 commit 90b0ac2

File tree

1 file changed

+18
-34
lines changed

1 file changed

+18
-34
lines changed

tests/test_mapping_account.py

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -49,40 +49,29 @@ def entries():
4949

5050

5151
@pytest.fixture
52-
def mapping_key():
53-
return SolanaPublicKey("AHtgzX45WTKfkPG53L6WYhGEXwQkN1BVknET3sVsLL8J")
54-
55-
56-
def test_mapping_account_upate_from(
57-
solana_client, mapping_key, mapping_account_bytes, entries
58-
):
59-
account = PythMappingAccount(
60-
key=mapping_key,
52+
def mapping_account(solana_client):
53+
return PythMappingAccount(
54+
key=SolanaPublicKey("AHtgzX45WTKfkPG53L6WYhGEXwQkN1BVknET3sVsLL8J"),
6155
solana=solana_client,
6256
)
63-
assert account.entries == []
64-
assert account.next_account_key is None
6557

66-
account.update_from(
58+
59+
def test_mapping_account_update_from(
60+
solana_client, mapping_account, mapping_account_bytes, entries
61+
):
62+
mapping_account.update_from(
6763
buffer=mapping_account_bytes,
6864
version=_VERSION_2,
6965
offset=0,
7066
)
7167

72-
assert account.entries == entries
73-
assert account.next_account_key is None
68+
assert mapping_account.entries == entries
69+
assert mapping_account.next_account_key is None
7470

7571

7672
def test_mapping_account_upate_from_null_key(
77-
solana_client, mapping_key, mapping_account_bytes, entries
73+
solana_client, mapping_account, mapping_account_bytes, entries
7874
):
79-
account = PythMappingAccount(
80-
key=mapping_key,
81-
solana=solana_client,
82-
)
83-
assert account.entries == []
84-
assert account.next_account_key is None
85-
8675
# Replace the last key with a null key
8776
null_key_bytes = b"\0" * SolanaPublicKey.LENGTH
8877

@@ -92,25 +81,20 @@ def test_mapping_account_upate_from_null_key(
9281
# Take the original bytes and add a null key to the end
9382
bad_bytes = mapping_account_bytes[:offset] + null_key_bytes
9483

95-
account.update_from(
84+
mapping_account.update_from(
9685
buffer=bad_bytes,
9786
version=_VERSION_2,
9887
offset=0,
9988
)
10089

10190
# The last key in the list is null, so remove it
102-
expected = entries[: len(entries) - 1]
91+
expected = entries[:-1]
10392

104-
assert account.entries == expected
105-
assert account.next_account_key is None
93+
assert mapping_account.entries == expected
94+
assert mapping_account.next_account_key is None
10695

10796

108-
def test_mapping_account_str(mapping_key, solana_client):
109-
actual = str(
110-
PythMappingAccount(
111-
key=mapping_key,
112-
solana=solana_client,
113-
)
114-
)
115-
expected = f"PythMappingAccount ({mapping_key})"
97+
def test_mapping_account_str(mapping_account, solana_client):
98+
actual = str(mapping_account)
99+
expected = f"PythMappingAccount ({mapping_account.key})"
116100
assert actual == expected

0 commit comments

Comments
 (0)