Skip to content

Commit 9a69fcf

Browse files
Update integration tests for Dragonchain 4.2.0 (#13)
* integration test fixes * tune values for less failures * tweak test timings
1 parent cb7c562 commit 9a69fcf

File tree

4 files changed

+27
-25
lines changed

4 files changed

+27
-25
lines changed

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Features:
88
* Add Binance interchain support
99
Development:
1010
* Add integration tests for Binance feature
11+
* Add/Update integration tests for Dragonchain 4.2.0
1112

1213
4.0.1
1314
-----

tests/integration/test_blocks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def test_query_blocks_by_timestamp(self):
7070
)
7171

7272
def test_query_blocks_by_id(self):
73-
current_block = int((time.time() - 1432238220) / 5)
73+
current_block = int((time.time() - 1432238220) / 5) + 1
7474
response1 = self.client.query_blocks("@block_id:[-inf {}]".format(current_block), sort_by="block_id", sort_ascending=True)
7575
response2 = self.client.query_blocks("@block_id:[-inf {}]".format(current_block), sort_by="block_id", sort_ascending=False)
7676
response3 = self.client.query_blocks("@block_id:[{} +inf]".format(current_block)) # Should not return any results

tests/integration/test_smart_contracts.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,15 @@ def test_update_contract_execution_order(self):
205205
# INVOCATION #
206206

207207
def wait_for_scheduler_invocation_1(self):
208-
time.sleep(60)
208+
time.sleep(55)
209209

210210
def disable_schedule(self):
211211
self.assertTrue(self.client.update_smart_contract(SMART_CONTRACT_SCHEDULER_ID, disable_schedule=True).get("ok"))
212212
self.assertTrue(self.client.update_smart_contract(SMART_CONTRACT_CRON_ID, disable_schedule=True).get("ok"))
213213

214+
def wait_for_scheduler_invocation_2(self):
215+
time.sleep(20)
216+
214217
def test_successful_invocation_of_scheduler(self):
215218
transaction_invocation = self.client.query_transactions(SMART_CONTRACT_SCHEDULER_NAME, "*")
216219
global SCHEDULER_INVOCATION_COUNT
@@ -225,7 +228,7 @@ def test_successful_invocation_of_cron(self):
225228
self.assertGreater(CRON_INVOCATION_COUNT, 0)
226229
self.assertGreater(transaction_invocation["response"]["results"][0]["header"]["timestamp"], CREATION_TIMESTAMP)
227230

228-
def wait_for_scheduler_invocation_2(self):
231+
def wait_for_scheduler_invocation_3(self):
229232
time.sleep(65)
230233

231234
def test_disable_schedule_works_on_scheduler(self):
@@ -239,17 +242,24 @@ def test_disable_schedule_works_on_cron(self):
239242
self.assertEqual(CRON_INVOCATION_COUNT, transaction_invocation["response"]["total"])
240243

241244
def test_successful_invocation_with_transactions(self):
242-
args_transaction = self.client.create_transaction(SMART_CONTRACT_ARGS_NAME, "banana", tag="banana")
243-
env_transaction = self.client.create_transaction(SMART_CONTRACT_ENV_NAME, "banana", tag="banana")
244-
secrets_transaction = self.client.create_transaction(SMART_CONTRACT_SECRETS_NAME, "banana", tag="banana")
245-
time.sleep(15)
246-
args_query = self.client.query_transactions(SMART_CONTRACT_ARGS_NAME, "banana")
247-
env_query = self.client.query_transactions(SMART_CONTRACT_ENV_NAME, "banana")
248-
secrets_query = self.client.query_transactions(SMART_CONTRACT_SECRETS_NAME, "banana")
245+
args_transaction = self.client.create_transaction(SMART_CONTRACT_ARGS_NAME, "banana")
246+
env_transaction = self.client.create_transaction(SMART_CONTRACT_ENV_NAME, "banana")
247+
secrets_transaction = self.client.create_transaction(SMART_CONTRACT_SECRETS_NAME, "banana")
248+
time.sleep(30)
249+
# Query for created transactions by invoker tag
250+
args_query = self.client.query_transactions(
251+
SMART_CONTRACT_ARGS_NAME, "@invoker:{{{}}}".format(args_transaction.get("response").get("transaction_id").replace("-", "\\-"))
252+
)
253+
env_query = self.client.query_transactions(
254+
SMART_CONTRACT_ENV_NAME, "@invoker:{{{}}}".format(env_transaction.get("response").get("transaction_id").replace("-", "\\-"))
255+
)
256+
secrets_query = self.client.query_transactions(
257+
SMART_CONTRACT_SECRETS_NAME, "@invoker:{{{}}}".format(secrets_transaction.get("response").get("transaction_id").replace("-", "\\-"))
258+
)
259+
# Check that the queries were successful and had a result with the invoker
249260
self.assertEqual(args_query["response"]["results"][0]["header"]["invoker"], args_transaction["response"]["transaction_id"])
250261
self.assertEqual(env_query["response"]["results"][0]["header"]["invoker"], env_transaction["response"]["transaction_id"])
251262
self.assertEqual(secrets_query["response"]["results"][0]["header"]["invoker"], secrets_transaction["response"]["transaction_id"])
252-
time.sleep(10)
253263

254264
# SMART CONTRACT LOGS #
255265

@@ -381,9 +391,10 @@ def suite():
381391
suite.addTest(TestSmartContracts("test_update_contract_execution_order"))
382392
suite.addTest(TestSmartContracts("wait_for_scheduler_invocation_1"))
383393
suite.addTest(TestSmartContracts("disable_schedule"))
394+
suite.addTest(TestSmartContracts("wait_for_scheduler_invocation_2"))
384395
suite.addTest(TestSmartContracts("test_successful_invocation_of_scheduler"))
385396
suite.addTest(TestSmartContracts("test_successful_invocation_of_cron"))
386-
suite.addTest(TestSmartContracts("wait_for_scheduler_invocation_2"))
397+
suite.addTest(TestSmartContracts("wait_for_scheduler_invocation_3"))
387398
suite.addTest(TestSmartContracts("test_disable_schedule_works_on_scheduler"))
388399
suite.addTest(TestSmartContracts("test_disable_schedule_works_on_cron"))
389400
suite.addTest(TestSmartContracts("test_successful_invocation_with_transactions"))

tests/integration/test_transactions.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def set_up_transaction_types(self):
5454
{"path": "test.num", "field_name": "query_num", "type": "number", "options": {"sortable": True}},
5555
],
5656
)
57-
time.sleep(20)
57+
time.sleep(25)
5858
except Exception:
5959
pass
6060

@@ -201,7 +201,7 @@ def test_create_bulk_transactions_with_all_invalid_transactions(self):
201201
self.assertEqual(response["response"]["error"]["type"], "VALIDATION_ERROR", response)
202202

203203
def wait_for_blocks(self):
204-
time.sleep(8)
204+
time.sleep(15)
205205

206206
# GET #
207207

@@ -288,16 +288,6 @@ def test_get_transaction_fails_with_bad_id(self):
288288

289289
# QUERY #
290290

291-
def test_query_transaction_returns_stub_if_not_in_block(self):
292-
txn_id = self.client.create_transaction(TEST_TXN_TYPE, "", tag="somethingUnique")["response"]["transaction_id"]
293-
response = self.client.query_transactions(TEST_TXN_TYPE, "somethingUnique")
294-
self.assertEqual(response.get("status"), 200)
295-
self.assertTrue(response.get("ok"))
296-
self.assertEqual(
297-
response["response"]["results"][0],
298-
{"header": {"txn_id": txn_id}, "message": "This transaction is waiting to be included in a block", "status": "pending"},
299-
)
300-
301291
def set_up_queryable_transactions(self):
302292
global LOW_TXN_ID
303293
global HIGH_TXN_ID
@@ -308,6 +298,7 @@ def set_up_queryable_transactions(self):
308298
HIGH_TXN_ID = self.client.create_transaction(
309299
QUERY_TXN_TYPE, tag="unique2 content", payload={"test": {"text": "a sortable text2 field", "tag": "someTag2", "num": 4321}}
310300
)["response"]["transaction_id"]
301+
time.sleep(8)
311302

312303
def test_query_transactions_generic(self):
313304
response = self.client.query_transactions(QUERY_TXN_TYPE, "*")
@@ -554,7 +545,6 @@ def suite():
554545
suite.addTest(TestTransactions("test_get_transaction_with_tag"))
555546
suite.addTest(TestTransactions("test_get_transaction_from_bulk_submission"))
556547
suite.addTest(TestTransactions("test_get_transaction_fails_with_bad_id"))
557-
suite.addTest(TestTransactions("test_query_transaction_returns_stub_if_not_in_block"))
558548
suite.addTest(TestTransactions("test_query_transactions_generic"))
559549
suite.addTest(TestTransactions("test_query_transactions_by_timestamp"))
560550
suite.addTest(TestTransactions("test_query_transactions_by_block_id"))

0 commit comments

Comments
 (0)