My goal is to write a test case to simulate my contract inside populus
. I observe that each transaction()
(even it is a empty function call) will increment block number as one no matter what.
[Q] As we know in a single block there could be multiple transactions. Is it possible to have multiple transactions in a single block, inside the test case of populus?
test.py:
blkArrayIndex = 0;
gasUsed = [];
blockNumber = [];
set_txn_hash = my_contract.transact().dummy(); #this is a dummy transaction.
contract_address = unmigrated_chain.wait.for_receipt(set_txn_hash)
gasUsed.append( contract_address["gasUsed"] );
blockNumber.append( contract_address["blockNumber"] );
blkArrayIndex = blkArrayIndex + 1;
set_txn_hash = my_contract.transact().dummy(); #added line.#
set_txn_hash = my_contract.transact().dummy(); #added line.#
set_txn_hash = my_contract.transact().dummy(); #added line.#
set_txn_hash = my_contract.transact().dummy(); #this is a dummy transaction.
contract_address = unmigrated_chain.wait.for_receipt(set_txn_hash);
gasUsed.append( contract_address["gasUsed"] );
blockNumber.append( contract_address["blockNumber"] );
blkArrayIndex = blkArrayIndex + 1;
for j in range(0, blkArrayIndex):
print '%s:%d |%s: %d' % ("gasUsed", gasUsed[j], "blockNumber", blockNumber[j])
Output (without added lines):
gasUsed:222648 |blockNumber: 4
gasUsed:290051 |blockNumber: 5
Output (when new lines are added): block number changed from 5 to 8.
gasUsed:222648|blockNumber: 4
gasUsed:350051|blockNumber: 8 <= after the added lines I want block number as 5 instead of 8.