1

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.
2

Having number of transactions in a block is possible but doing it manually is not possible, Block is created in 2 situations,

1.Time out period is reached.

There is a time out period to create a block (the exact time out period is unknown to me, may be 1 or 2 seconds), the transaction made in-between this timeout period are kept under a single block.

2.Max Limitation Reached

When we reach the max limitation of transactions to be contained in a single block(max limitation is unknown to me) before the time out reached , a new block is created and the transactions done after that are registered in new block

I think you are doing single transaction at a time and before doing another transaction the time out is getting expired, try doing multiple transactions at a time

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.