Skip to content

Commit ad50637

Browse files
committed
chore: tidy
1 parent edf3b3e commit ad50637

File tree

2 files changed

+53
-33
lines changed

2 files changed

+53
-33
lines changed

tests/integration/token_pause_transaction_e2e_test.py

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_pause_missing_token_id_raises_value_error(env):
4747
tx = TokenPauseTransaction()
4848

4949
with pytest.raises(ValueError, match="token_id must be set"):
50-
tx.freeze_with(env.client)
50+
tx.freeze_with(env.client) # ← builds the body which fails
5151

5252
@mark.integration
5353
def test_pause_nonexistent_token_id_raises_precheck_error(env):
@@ -60,7 +60,7 @@ def test_pause_nonexistent_token_id_raises_precheck_error(env):
6060

6161
with pytest.raises(PrecheckError, match=ResponseCode.get_name(ResponseCode.INVALID_TOKEN_ID)):
6262
# .execute() will auto‐freeze and auto‐sign with the operator key
63-
tx.execute(env.client)
63+
tx.execute(env.client) # ← this is what runs the precheck
6464

6565
@mark.integration
6666
def test_pause_fails_for_unpausable_token(env, unpausable_token):
@@ -72,7 +72,7 @@ def test_pause_fails_for_unpausable_token(env, unpausable_token):
7272

7373
with pytest.raises(PrecheckError, match=ResponseCode.get_name(ResponseCode.TOKEN_HAS_NO_PAUSE_KEY),):
7474
# .execute() will auto‐freeze and auto‐sign with the operator key
75-
tx.execute(env.client)
75+
tx.execute(env.client) # ← this is what runs the precheck
7676

7777
@mark.integration
7878
def test_pause_requires_pause_key_signature(env, pausable_token):
@@ -85,7 +85,7 @@ def test_pause_requires_pause_key_signature(env, pausable_token):
8585
tx = tx.freeze_with(env.client)
8686

8787
with pytest.raises(PrecheckError, match=ResponseCode.get_name(ResponseCode.TOKEN_HAS_NO_PAUSE_KEY),):
88-
tx.execute(env.client)
88+
tx.execute(env.client) # ← this is what runs the precheck
8989

9090
@mark.integration
9191
def test_pause_with_invalid_key_fails_precheck(env, pausable_token):
@@ -98,20 +98,37 @@ def test_pause_with_invalid_key_fails_precheck(env, pausable_token):
9898
# freeze, sign with wrong key, then execute
9999
tx = TokenPauseTransaction().set_token_id(pausable_token)
100100
tx = tx.freeze_with(env.client)
101-
tx = tx.sign(bad_key)
102-
tx.execute(env.client)
101+
tx = tx.sign(bad_key) # ← signed with wrong key
102+
tx.execute(env.client) # ← this is what runs the precheck
103103

104104
@mark.integration
105105
def test_pause_already_paused_token_fails(env, pausable_token):
106106
"""
107-
Attempting to pause a token that is already paused should fail
107+
Attempting to pause a token that is already paused should fail
108108
in the handle phase with TOKEN_IS_PAUSED.
109109
"""
110-
env.pause_token(pausable_token)
111-
112-
# 2) Second pause (signed with the same pause key by default)
113-
with pytest.raises(ReceiptStatusError,match=ResponseCode.get_name(ResponseCode.TOKEN_IS_PAUSED)):
114-
env.pause_token(pausable_token)
110+
# 1) First pause: build, freeze, sign with the real pause key, execute
111+
tx1 = (
112+
TokenPauseTransaction()
113+
.set_token_id(pausable_token)
114+
.freeze_with(env.client)
115+
.sign(env.operator_key)
116+
)
117+
receipt1 = tx1.execute(env.client)
118+
assert receipt1.status == ResponseCode.SUCCESS
119+
120+
# 2) Second pause: do the exact same, but now expect TOKEN_IS_PAUSED
121+
tx2 = (
122+
TokenPauseTransaction()
123+
.set_token_id(pausable_token)
124+
.freeze_with(env.client)
125+
.sign(env.operator_key)
126+
)
127+
with pytest.raises(
128+
ReceiptStatusError,
129+
match=ResponseCode.get_name(ResponseCode.TOKEN_IS_PAUSED)
130+
):
131+
tx2.execute(env.client)
115132

116133
@mark.integration
117134
class TestTokenPause:
@@ -129,18 +146,28 @@ def test_transfer_before_pause(self, env, account: Account, pausable_token):
129146

130147
def test_pause_sets_token_status_to_paused(self, env, pausable_token):
131148
"""
132-
Take a pausable token, that is not paused, it should be UNPAUSED.
133-
A token pause transaction to an unpaused token now makes it PAUSED.
149+
Take a pausable token (UNPAUSED), submit a pause transaction signed
150+
with its pause key, then verify it ends up PAUSED.
134151
"""
135-
# pre-pause sanity check
152+
# 1) pre-pause sanity check
136153
info = TokenInfoQuery().set_token_id(pausable_token).execute(env.client)
154+
137155
assert info.token_status.name == "UNPAUSED"
138156

139-
# pause via fixture
140-
env.pause_token(pausable_token, key=env.operator_key)
157+
# 2) build, freeze, sign & execute the pause tx
158+
pause_key = env.operator_key
159+
tx = (
160+
TokenPauseTransaction()
161+
.set_token_id(pausable_token)
162+
.freeze_with(env.client)
163+
.sign(pause_key)
164+
)
165+
receipt = tx.execute(env.client)
166+
assert receipt.status == ResponseCode.SUCCESS
141167

142-
# verify
168+
# 3) post-pause verify
143169
info2 = TokenInfoQuery().set_token_id(pausable_token).execute(env.client)
170+
144171
assert info2.token_status.name == "PAUSED"
145172

146173
def test_transfers_blocked_when_paused(self, env, account: Account, pausable_token):
@@ -159,7 +186,14 @@ def test_transfers_blocked_when_paused(self, env, account: Account, pausable_tok
159186

160187
# pause the token
161188
pause_key = env.operator_key
162-
env.pause_token(pausable_token, key=pause_key)
189+
tx = (
190+
TokenPauseTransaction()
191+
.set_token_id(pausable_token)
192+
.freeze_with(env.client)
193+
.sign(pause_key)
194+
)
195+
receipt = tx.execute(env.client)
196+
assert receipt.status == ResponseCode.SUCCESS
163197

164198
# attempt to transfer 1 token
165199
tx = (

tests/integration/utils_for_test.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,6 @@ def associate_and_transfer(self, receiver: AccountId, receiver_key: PrivateKey,
9090
f"Transfer failed: {ResponseCode.get_name(transfer_receipt.status)}"
9191
)
9292

93-
def pause_token(self, token_id, key=None):
94-
"""
95-
Pause a token:
96-
• If `key` is None: use the operator’s pause key (the normal happy-path).
97-
• If `key` is provided: sign with *that* key.
98-
"""
99-
tx = TokenPauseTransaction().set_token_id(token_id)
100-
tx = tx.freeze_with(self.client)
101-
102-
signer = self.operator_key if key is None else key
103-
tx = tx.sign(signer)
104-
105-
return tx.execute(self.client)
106-
10793
def create_fungible_token(env, opts=[]):
10894
"""
10995
Create a fungible token with the given options.

0 commit comments

Comments
 (0)