2018-11-04 19:23:11 +00:00
|
|
|
"""
|
|
|
|
This file is part of nucypher.
|
|
|
|
|
|
|
|
nucypher is free software: you can redistribute it and/or modify
|
2019-03-05 02:50:11 +00:00
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
2018-11-04 19:23:11 +00:00
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
nucypher is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-03-05 02:50:11 +00:00
|
|
|
GNU Affero General Public License for more details.
|
2018-11-04 19:23:11 +00:00
|
|
|
|
2019-03-05 02:50:11 +00:00
|
|
|
You should have received a copy of the GNU Affero General Public License
|
2018-11-04 19:23:11 +00:00
|
|
|
along with nucypher. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
"""
|
2019-04-09 11:52:14 +00:00
|
|
|
import web3
|
|
|
|
|
|
|
|
from nucypher.blockchain.eth.constants import (NUMBER_OF_ETH_TEST_ACCOUNTS,
|
|
|
|
NUMBER_OF_URSULAS_IN_BLOCKCHAIN_TESTS)
|
|
|
|
from nucypher.utilities.sandbox.constants import TESTING_ETH_AIRDROP_AMOUNT
|
2019-02-14 08:23:48 +00:00
|
|
|
|
|
|
|
|
2018-10-16 19:43:29 +00:00
|
|
|
def test_testerchain_creation(testerchain):
|
2018-03-02 05:16:36 +00:00
|
|
|
# Ensure we are testing on the correct network...
|
2018-10-02 02:45:24 +00:00
|
|
|
assert 'tester' in testerchain.interface.provider_uri
|
2018-03-02 05:16:36 +00:00
|
|
|
|
|
|
|
# ... and that there are already some blocks mined
|
2019-04-09 11:52:14 +00:00
|
|
|
assert testerchain.interface.w3.eth.blockNumber > 0
|
|
|
|
|
|
|
|
# Check that we have enough test accounts
|
|
|
|
assert len(testerchain.interface.w3.eth.accounts) >= NUMBER_OF_ETH_TEST_ACCOUNTS
|
|
|
|
|
|
|
|
# Check that distinguished accounts are assigned
|
|
|
|
etherbase = testerchain.etherbase_account
|
|
|
|
assert etherbase == testerchain.interface.w3.eth.accounts[0]
|
|
|
|
|
|
|
|
alice = testerchain.alice_account
|
|
|
|
assert alice == testerchain.interface.w3.eth.accounts[1]
|
|
|
|
|
|
|
|
bob = testerchain.bob_account
|
|
|
|
assert bob == testerchain.interface.w3.eth.accounts[2]
|
|
|
|
|
|
|
|
ursulas = [testerchain.ursula_account(i) for i in range(NUMBER_OF_URSULAS_IN_BLOCKCHAIN_TESTS)]
|
|
|
|
assert ursulas == testerchain.ursulas_accounts
|
|
|
|
|
2019-04-10 08:27:42 +00:00
|
|
|
# Check that the remaining accounts are different from the previous ones:
|
|
|
|
assert set([etherbase, alice, bob] + ursulas).isdisjoint(set(testerchain.unassigned_accounts))
|
|
|
|
|
2019-04-09 11:52:14 +00:00
|
|
|
# Check that accounts are funded
|
|
|
|
for account in testerchain.interface.w3.eth.accounts:
|
|
|
|
assert testerchain.interface.w3.eth.getBalance(account) >= TESTING_ETH_AIRDROP_AMOUNT
|
|
|
|
|
2019-04-10 08:27:42 +00:00
|
|
|
# Check that accounts can send transactions
|
|
|
|
for account in testerchain.interface.w3.eth.accounts:
|
|
|
|
tx = {'to': etherbase, 'from': account, 'value': 100}
|
|
|
|
txhash = testerchain.interface.w3.eth.sendTransaction(tx)
|
|
|
|
_receipt = testerchain.wait_for_receipt(txhash)
|
|
|
|
|