Skip to content
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

Merged
merged 8 commits into from
Jan 14, 2018

Conversation

NIC619
Copy link
Contributor

@NIC619 NIC619 commented Jan 8, 2018

How was it fixed?

Add sharing transaction test.

Steps are:

  1. calculate contract address to be deployed
  2. initiate a shard chain(without block validation) with the address derived above funded
  3. deploy the contract
  4. send transaction to the contract

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 to recipient).

Cute Animal Picture

@hwwhww
Copy link
Contributor

hwwhww commented Jan 8, 2018

As the discussion in #238, if we are going to create a Shard class which mirrors the Chain class and a ShardVM which mirrors the VM class, how about creating a new test_shard_vm.py file for these tests?

# 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)
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

@pipermerriam pipermerriam left a 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.

}
}
chain = klass.from_genesis(shard_chaindb, genesis_params, genesis_state)
chain.funded_address = funded_addr
Copy link
Member

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.

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:
Copy link
Member

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.

Copy link
Contributor Author

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?

@hwwhww hwwhww added the eth2.0 label Jan 9, 2018
@jannikluhn
Copy link
Contributor

The simple_transfer_contract is intended just for testing, correct? If so I'd not put it into evm/auxiliary but move it somewhere to the tests subdirectory.

@NIC619
Copy link
Contributor Author

NIC619 commented Jan 11, 2018

@pipermerriam I made some updates and it is ready for review/merge, please have a look, thank you.

Updates:

  1. Switch to NestedTrieBackend for shard chain testing for now to circumvent account data access restriction. Will update it once access list generating helper function is out.
  2. Update contract code fixture for testing. The contract is a simple contract which takes in destination, value, each padded to 32 bytes, and transfer value amount of ether to destination. Steps are, firstly, fund the contract address in genesis, then deploy the contract and finally execute the transfer transaction.

@NIC619
Copy link
Contributor Author

NIC619 commented Jan 11, 2018

@jannikluhn ahh you are right. I will move them to tests directory.

"""
# 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)
Copy link
Member

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

Copy link
Contributor Author

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.

'extra_data': constants.GENESIS_EXTRA_DATA,
'timestamp': 1501851927,
# 'state_root': decode_hex(
# '0x9d354f9b5ba851a35eced279ef377111387197581429cfcc7f744ef89a30b5d4')
Copy link
Member

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?

Copy link
Contributor Author

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.

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'
Copy link
Member

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.

Copy link
Contributor Author

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.

@NIC619 NIC619 merged commit 2f5c87e into ethereum:sharding Jan 14, 2018
@NIC619 NIC619 deleted the add_sharding_transaction_test branch January 14, 2018 04:53
@NIC619 NIC619 restored the add_sharding_transaction_test branch January 14, 2018 05:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants