|
34 | 34 | SMART_CONTRACT_CRON_ID = None |
35 | 35 | ARGS_CONTRACT_BODY = None |
36 | 36 | CREATION_TIMESTAMP = None |
| 37 | +CRON_INVOCATION_COUNT = None |
| 38 | +SCHEDULER_INVOCATION_COUNT = None |
37 | 39 |
|
38 | 40 | SCHEDULER = 60 |
39 | 41 | CRON = "* * * * *" |
@@ -202,19 +204,40 @@ def test_update_contract_execution_order(self): |
202 | 204 |
|
203 | 205 | # INVOCATION # |
204 | 206 |
|
205 | | - def wait_for_scheduler_invocation(self): |
| 207 | + def wait_for_scheduler_invocation_1(self): |
206 | 208 | time.sleep(60) |
207 | 209 |
|
| 210 | + def disable_schedule(self): |
| 211 | + self.assertTrue(self.client.update_smart_contract(SMART_CONTRACT_SCHEDULER_ID, disable_schedule=True).get("ok")) |
| 212 | + self.assertTrue(self.client.update_smart_contract(SMART_CONTRACT_CRON_ID, disable_schedule=True).get("ok")) |
| 213 | + |
208 | 214 | def test_successful_invocation_of_scheduler(self): |
209 | 215 | transaction_invocation = self.client.query_transactions(SMART_CONTRACT_SCHEDULER_NAME, "*") |
210 | | - self.assertGreater(transaction_invocation["response"]["total"], 0) |
| 216 | + global SCHEDULER_INVOCATION_COUNT |
| 217 | + SCHEDULER_INVOCATION_COUNT = transaction_invocation["response"]["total"] |
| 218 | + self.assertGreater(SCHEDULER_INVOCATION_COUNT, 0) |
211 | 219 | self.assertGreater(transaction_invocation["response"]["results"][0]["header"]["timestamp"], CREATION_TIMESTAMP) |
212 | 220 |
|
213 | 221 | def test_successful_invocation_of_cron(self): |
214 | 222 | transaction_invocation = self.client.query_transactions(SMART_CONTRACT_CRON_NAME, "*") |
215 | | - self.assertGreater(transaction_invocation["response"]["total"], 0) |
| 223 | + global CRON_INVOCATION_COUNT |
| 224 | + CRON_INVOCATION_COUNT = transaction_invocation["response"]["total"] |
| 225 | + self.assertGreater(CRON_INVOCATION_COUNT, 0) |
216 | 226 | self.assertGreater(transaction_invocation["response"]["results"][0]["header"]["timestamp"], CREATION_TIMESTAMP) |
217 | 227 |
|
| 228 | + def wait_for_scheduler_invocation_2(self): |
| 229 | + time.sleep(65) |
| 230 | + |
| 231 | + def test_disable_schedule_works_on_scheduler(self): |
| 232 | + transaction_invocation = self.client.query_transactions(SMART_CONTRACT_SCHEDULER_NAME, "*") |
| 233 | + # Assert that the transaction count after waiting 60 seconds is the same as after we immediately disabled the schedule |
| 234 | + self.assertEqual(SCHEDULER_INVOCATION_COUNT, transaction_invocation["response"]["total"]) |
| 235 | + |
| 236 | + def test_disable_schedule_works_on_cron(self): |
| 237 | + transaction_invocation = self.client.query_transactions(SMART_CONTRACT_CRON_NAME, "*") |
| 238 | + # Assert that the transaction count after waiting 60 seconds is the same as after we immediately disabled the schedule |
| 239 | + self.assertEqual(CRON_INVOCATION_COUNT, transaction_invocation["response"]["total"]) |
| 240 | + |
218 | 241 | def test_successful_invocation_with_transactions(self): |
219 | 242 | args_transaction = self.client.create_transaction(SMART_CONTRACT_ARGS_NAME, "banana", tag="banana") |
220 | 243 | env_transaction = self.client.create_transaction(SMART_CONTRACT_ENV_NAME, "banana", tag="banana") |
@@ -356,9 +379,13 @@ def suite(): |
356 | 379 | suite.addTest(TestSmartContracts("test_update_contract_with_env")) |
357 | 380 | suite.addTest(TestSmartContracts("test_update_contract_with_secrets")) |
358 | 381 | suite.addTest(TestSmartContracts("test_update_contract_execution_order")) |
359 | | - suite.addTest(TestSmartContracts("wait_for_scheduler_invocation")) |
| 382 | + suite.addTest(TestSmartContracts("wait_for_scheduler_invocation_1")) |
| 383 | + suite.addTest(TestSmartContracts("disable_schedule")) |
360 | 384 | suite.addTest(TestSmartContracts("test_successful_invocation_of_scheduler")) |
361 | 385 | suite.addTest(TestSmartContracts("test_successful_invocation_of_cron")) |
| 386 | + suite.addTest(TestSmartContracts("wait_for_scheduler_invocation_2")) |
| 387 | + suite.addTest(TestSmartContracts("test_disable_schedule_works_on_scheduler")) |
| 388 | + suite.addTest(TestSmartContracts("test_disable_schedule_works_on_cron")) |
362 | 389 | suite.addTest(TestSmartContracts("test_successful_invocation_with_transactions")) |
363 | 390 | suite.addTest(TestSmartContracts("test_get_contract_logs_with_contract_id")) |
364 | 391 | suite.addTest(TestSmartContracts("test_get_contract_logs_with_contract_id_tail_and_since")) |
|
0 commit comments