-
Notifications
You must be signed in to change notification settings - Fork 645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add sharding transaction test #252
Add sharding transaction test #252
Conversation
As the discussion in #238, if we are going to create a |
tests/core/vm/test_vm.py
Outdated
# specified amount of ether to recipient. | ||
# TODO: update contract_deployment_code | ||
contract_deployment_code = b'' | ||
contract_addr = generate_create2_contract_address(b'', contract_deployment_code) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about changing the name to generate_CREATE2_contract_address
to make it a bit clearer that we're referring to the CREATE2
opcode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will update it in CREATE2 PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks well formed. A few minor cleanup suggestions.
tests/core/fixtures.py
Outdated
} | ||
} | ||
chain = klass.from_genesis(shard_chaindb, genesis_params, genesis_state) | ||
chain.funded_address = funded_addr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of storing this on the chain
object, can we just use the funded_address
fixture in any place where we need access to this address. I'm worried that setting a precedent for tacking values onto objects will lead to confusing tests down the road when it's hard for someone to differentiate what is a formal Chain
API and what is just part of the test setup.
tests/core/vm/test_vm.py
Outdated
transfer_tx = new_sharding_transaction(tx_initiator, recipient, amount, b'', b'', b'') | ||
computation = vm.execute_transaction(transfer_tx) | ||
assert not computation.is_error | ||
with vm.state.state_db(read_only=True) as state_db: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just had the thought that we could provide access to a read-only statedb without the context manager as part of the state
object, and have the context manager API be only necessary for when write operations are necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. Just to make sure, context manager's job here is to (1) double check no state were written in read_only mode and (2) decommission the state to prevent further modification to db, correct?
Does it involve managing(opening/closing/cleaning) the actual data base file?
…d make shard chain contract fixture
…ion data in ShardingTransaction
The |
@pipermerriam I made some updates and it is ready for review/merge, please have a look, thank you. Updates:
|
@jannikluhn ahh you are right. I will move them to |
tests/core/fixtures.py
Outdated
""" | ||
# TODO: Comment this out to use NestedTrieBackend to prevent access list validation. | ||
# Uncomment this to use FlatTrieBackend once access list generation is implemented. | ||
# shard_chaindb = BaseChainDB(get_db_backend(), state_backend_class=FlatTrieBackend) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this is what you want, but assuming you want to run this using both state backends you can do that in a very clean way as follows.
@pytest.fixture(params=(FlatTrieBackend, NestedTrieBackend))
def shard_chain_without_block_validation(request):
shard_chaindb = BaseChainDB(get_db_backend(), state_backend_class=request.param)
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry my comment was misleading. What I mean is to comment out FlatTrieBackend and use NestedTrieBackend instead for now. After the helper function which generates access list for a transaction is implemented, we can uncomment it and use FlatTrieBackend. I will update this part.
tests/core/fixtures.py
Outdated
'extra_data': constants.GENESIS_EXTRA_DATA, | ||
'timestamp': 1501851927, | ||
# 'state_root': decode_hex( | ||
# '0x9d354f9b5ba851a35eced279ef377111387197581429cfcc7f744ef89a30b5d4') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reason for this being commented out? Can it be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. This can be removed.
tests/core/vm/contract_fixture.py
Outdated
contract_bytecode = b'0x61003e567401000000000000000000000000000000000000000060205260003560205181101558575060006000600060006020356000356000f1155857005b61000461003e0361000460003961000461003e036000f3' # noqa: E501 | ||
|
||
# address where this contract will be deployed | ||
contract_address = b'\xdb\xcd\xfc\xf2\xea!\xcd\x0c\xa5d\xaay\x8b;\xf0\xe4\xe2\x98S\xca' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this value is based on the contract bytecode? If so, it seems like this value is likely to end up out-of-sync if the bytecode changes. I'd suggest one of:
- make this a computed value.
- put a big loud comment here indicating how to compute this value and at the bytecode above indicating that if the bytecode is changed, then this value needs to be changed also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will update it to a computed value.
…ontract_address computed value
How was it fixed?
Add sharing transaction test.
Steps are:
I'm working on the contract code right now which is similar to the user account contract but simpler(parse the transaction data and transfer
amount
of ether torecipient
).Cute Animal Picture