Exemplo n.º 1
0
def make_casper_genesis(alloc, epoch_length, withdrawal_delay,
                        base_interest_factor, base_penalty_factor):
    # The Casper-specific config declaration
    casper_config = copy.deepcopy(config.default_config)
    casper_config['HOMESTEAD_FORK_BLKNUM'] = 0
    casper_config['ANTI_DOS_FORK_BLKNUM'] = 0
    casper_config['CLEARING_FORK_BLKNUM'] = 0
    casper_config['CONSENSUS_STRATEGY'] = 'hybrid_casper'
    casper_config['NULL_SENDER'] = utils.sha3('NULL_SENDER')
    casper_config['EPOCH_LENGTH'] = epoch_length
    casper_config['WITHDRAWAL_DELAY'] = withdrawal_delay
    casper_config['OWNER'] = a0
    casper_config['BASE_INTEREST_FACTOR'] = base_interest_factor
    casper_config['BASE_PENALTY_FACTOR'] = base_penalty_factor
    # Get initialization txs
    init_txs, casper_address = mk_initializers(casper_config,
                                               casper_config['NULL_SENDER'])
    casper_config['CASPER_ADDRESS'] = casper_address
    # Create state and apply required state_transitions for initializing Casper
    state = genesis_helpers.mk_basic_state(
        alloc, None, env=config.Env(config=casper_config))
    state.gas_limit = 10**8
    for tx in init_txs:
        state.set_balance(utils.privtoaddr(casper_config['NULL_SENDER']),
                          15**18)
        success, output = apply_transaction(state, tx)
        assert success
        state.gas_used = 0
        state.set_balance(utils.privtoaddr(casper_config['NULL_SENDER']), 0)
    consensus.initialize(state)
    state.commit()
    return state
Exemplo n.º 2
0
    def setUp(self):
        config.config_metropolis['BLOCK_GAS_LIMIT'] = 2**60
        self.chain = t.Chain(env=config.Env(config=config.config_metropolis))
        self.chain.mine()

        contract_dir = os.path.abspath(
            os.path.join(os.path.dirname(__file__), '..'))
        self.verifier_contract = deploy_solidity_contract(
            self.chain,
            {
                'ProvethVerifier.sol': {
                    'urls':
                    [os.path.join(contract_dir, 'ProvethVerifier.sol')]
                },
                'RLP.sol': {
                    'urls': [os.path.join(contract_dir, 'RLP.sol')]
                },
                'ExposedProvethVerifier.sol': {
                    'urls':
                    [os.path.join(contract_dir, 'ExposedProvethVerifier.sol')]
                },
            },
            contract_dir,
            'ExposedProvethVerifier.sol',
            'ExposedProvethVerifier',
            10**7,
        )

        self.rpc_cache = {}
Exemplo n.º 3
0
    def setUp(self):
        config.config_metropolis['BLOCK_GAS_LIMIT'] = 2**60
        self.chain = t.Chain(env=config.Env(config=config.config_metropolis))
        self.chain.mine()

        self.verifier_contract = deploy_solidity_contract_with_args(
            self.chain, {
                'LibSubmarine.sol': {
                    'urls': ['contract/LibSubmarine.sol']
                },
                'SafeMath.sol': {
                    'urls': ['contract/SafeMath.sol']
                },
                'proveth/ProvethVerifier.sol': {
                    'urls': ['contract/proveth/ProvethVerifier.sol']
                },
                'proveth/RLP.sol': {
                    'urls': ['contract/proveth/RLP.sol']
                }
            },
            os.path.abspath(os.getcwd()),
            'LibSubmarine.sol',
            'LibSubmarine',
            10**7,
            args=[REVEAL_DEPOSIT, CHALLENGE_PERIOD_LENGTH])
    def setUp(self):
        config.config_metropolis['BLOCK_GAS_LIMIT'] = 2**60
        self.chain = t.Chain(env=config.Env(config=config.config_metropolis))
        self.chain.mine()
        contract_dir = os.path.abspath(
            os.path.join(root_repo_dir, 'contracts/'))
        os.chdir(root_repo_dir)

        self.verifier_contract = deploy_solidity_contract_with_args(
            chain=self.chain,
            solc_config_sources={
                'LibSubmarineSimpleTestHelper.sol': {
                    'urls': [
                        os.path.join(contract_dir,
                                     'LibSubmarineSimpleTestHelper.sol')
                    ]
                },
                'LibSubmarineSimple.sol': {
                    'urls':
                    [os.path.join(contract_dir, 'LibSubmarineSimple.sol')]
                },
                'openzeppelin-solidity/contracts/math/SafeMath.sol': {
                    'urls': [
                        os.path.join(
                            contract_dir,
                            'openzeppelin-solidity/contracts/math/SafeMath.sol'
                        )
                    ]
                },
                'proveth/ProvethVerifier.sol': {
                    'urls': [
                        os.path.join(contract_dir,
                                     'proveth/ProvethVerifier.sol')
                    ]
                },
                'proveth/RLP.sol': {
                    'urls': [os.path.join(contract_dir, 'proveth/RLP.sol')]
                }
            },
            allow_paths=root_repo_dir,
            contract_file='LibSubmarineSimpleTestHelper.sol',
            contract_name='LibSubmarineSimpleTestHelper',
            startgas=10**7)
Exemplo n.º 5
0
    def setUp(self):
        config.config_metropolis['BLOCK_GAS_LIMIT'] = 2**60
        self.chain = t.Chain(env=config.Env(config=config.config_metropolis))
        self.chain.mine(1)
        contract_dir = os.path.abspath(
            os.path.join(root_repo_dir, 'contracts/'))
        os.chdir(root_repo_dir)

        self.verifier_contract = deploy_solidity_contract_with_args(
            chain=self.chain,
            solc_config_sources={
                'examples/Auction.sol': {
                    'urls':
                    [os.path.join(contract_dir, 'examples/Auction.sol')]
                },
                'LibSubmarineSimple.sol': {
                    'urls':
                    [os.path.join(contract_dir, 'LibSubmarineSimple.sol')]
                },
                'SafeMath.sol': {
                    'urls': [os.path.join(contract_dir, 'SafeMath.sol')]
                },
                'proveth/ProvethVerifier.sol': {
                    'urls': [
                        os.path.join(contract_dir,
                                     'proveth/ProvethVerifier.sol')
                    ]
                },
                'proveth/RLP.sol': {
                    'urls': [os.path.join(contract_dir, 'proveth/RLP.sol')]
                }
            },
            allow_paths=root_repo_dir,
            contract_file='examples/Auction.sol',
            contract_name='Auction',
            startgas=10**7,
            args=[COMMIT_PERIOD_LENGTH, REVEAL_PERIOD_LENGTH],
            contractDeploySender=CONTRACT_OWNER_PRIVATE_KEY)
Exemplo n.º 6
0
 def setUp(self):
     config.config_metropolis['BLOCK_GAS_LIMIT'] = 2**60
     self.chain = t.Chain(env=config.Env(config=config.config_metropolis))
     self.chain.mine(1)
     contract_dir = os.path.abspath(
         os.path.join(root_repo_dir, 'contracts/'))
     os.chdir(root_repo_dir)
     self.token_contract = deploy_solidity_contract_with_args(
         chain=self.chain,
         solc_config_sources={
         'examples/exchange/ERC20Interface.sol': {
             'urls':
             [os.path.join(contract_dir, 'examples/exchange/ERC20Interface.sol')]
         },
         'examples/exchange/TestToken.sol': {
             'urls':
             [os.path.join(contract_dir, 'examples/exchange/TestToken.sol')]
             },
             'openzeppelin-solidity/contracts/math/SafeMath.sol': {
                 'urls': [os.path.join(contract_dir, 'openzeppelin-solidity/contracts/math/SafeMath.sol')]
             },
         },
         allow_paths=root_repo_dir,
         contract_file='examples/exchange/TestToken.sol',
         contract_name='TestToken',
         startgas=10**7,
         args=["TestToken", "TTT", 18],
         contract_creator=CONTRACT_OWNER_PRIVATE_KEY)
     self.token_contract.mint(CONTRACT_OWNER_ADDRESS, TOTAL_TOKEN_SUPPLY, sender=CONTRACT_OWNER_PRIVATE_KEY)
     self.exchange_contract = deploy_solidity_contract_with_args(
         chain=self.chain,
         solc_config_sources={
             'examples/exchange/Exchange.sol': {
                 'urls':
                 [os.path.join(contract_dir, 'examples/exchange/Exchange.sol')]
             },
             'examples/exchange/ERC20Interface.sol': {
                 'urls':
                 [os.path.join(contract_dir, 'examples/exchange/ERC20Interface.sol')]
             },
             'examples/exchange/TestToken.sol': {
                 'urls':
                 [os.path.join(contract_dir, 'examples/exchange/TestToken.sol')]
             },
             'LibSubmarineSimple.sol': {
                 'urls':
                 [os.path.join(contract_dir, 'LibSubmarineSimple.sol')]
             },
             'openzeppelin-solidity/contracts/math/SafeMath.sol': {
                 'urls': [os.path.join(contract_dir, 'openzeppelin-solidity/contracts/math/SafeMath.sol')]
             },
             'proveth/ProvethVerifier.sol': {
                 'urls': [
                     os.path.join(contract_dir,
                                  'proveth/ProvethVerifier.sol')
                 ]
             },
             'proveth/RLP.sol': {
                 'urls': [os.path.join(contract_dir, 'proveth/RLP.sol')]
             }
         },
         allow_paths=root_repo_dir,
         contract_file='examples/exchange/Exchange.sol',
         contract_name='Exchange',
         startgas=10**7,
         args=[self.token_contract.address],
         contract_creator=CONTRACT_OWNER_PRIVATE_KEY)
     self.token_contract.approve(self.exchange_contract.address, TOKEN_AMOUNT_STARTING, sender=CONTRACT_OWNER_PRIVATE_KEY)
     self.exchange_contract.initializeExchange(TOKEN_AMOUNT_STARTING, value=ETH_AMOUNT_STARTING, sender=CONTRACT_OWNER_PRIVATE_KEY)
     self.token_contract.transfer(BOB_ADDRESS, BOB_STARTING_TOKEN_AMOUNT, sender=CONTRACT_OWNER_PRIVATE_KEY)
Exemplo n.º 7
0
    def setUp(self):
        config.config_metropolis['BLOCK_GAS_LIMIT'] = 2**60
        self.chain = t.Chain(env=config.Env(config=config.config_metropolis))
        self.chain.mine(1)
        contract_dir = os.path.abspath(
            os.path.join(root_repo_dir, 'contracts/'))
        os.chdir(root_repo_dir)

        self.erc721_contract = deploy_solidity_contract_with_args(
            chain=self.chain,
            solc_config_sources={
                'openzeppelin-solidity/contracts/token/ERC721/ERC721Mintable.sol': {
                    'urls':
                    [os.path.join(contract_dir, 'openzeppelin-solidity/contracts/token/ERC721/ERC721Mintable.sol')]
                },
                'openzeppelin-solidity/contracts/access/roles/MinterRole.sol': {
                    'urls':
                    [os.path.join(contract_dir, 'openzeppelin-solidity/contracts/access/roles/MinterRole.sol')]
                },
                'openzeppelin-solidity/contracts/access/Roles.sol': {
                    'urls':
                    [os.path.join(contract_dir, 'openzeppelin-solidity/contracts/access/Roles.sol')]
                },
                'openzeppelin-solidity/contracts/token/ERC721/ERC721.sol': {
                    'urls':
                    [os.path.join(contract_dir, 'openzeppelin-solidity/contracts/token/ERC721/ERC721.sol')]
                },
                'openzeppelin-solidity/contracts/token/ERC721/IERC721.sol': {
                    'urls':
                    [os.path.join(contract_dir, 'openzeppelin-solidity/contracts/token/ERC721/IERC721.sol')]
                },
                'openzeppelin-solidity/contracts/token/ERC721/IERC721Receiver.sol': {
                    'urls':
                    [os.path.join(contract_dir, 'openzeppelin-solidity/contracts/token/ERC721/IERC721Receiver.sol')]
                },
                'openzeppelin-solidity/contracts/math/SafeMath.sol': {
                    'urls':
                    [os.path.join(contract_dir, 'openzeppelin-solidity/contracts/math/SafeMath.sol')]
                },
                'openzeppelin-solidity/contracts/utils/Address.sol': {
                    'urls':
                    [os.path.join(contract_dir, 'openzeppelin-solidity/contracts/utils/Address.sol')]
                },
                'openzeppelin-solidity/contracts/introspection/IERC165.sol': {
                    'urls':
                    [os.path.join(contract_dir, 'openzeppelin-solidity/contracts/introspection/IERC165.sol')]
                },
                'openzeppelin-solidity/contracts/introspection/ERC165.sol': {
                    'urls':
                    [os.path.join(contract_dir, 'openzeppelin-solidity/contracts/introspection/ERC165.sol')]
                }
            },
            allow_paths=root_repo_dir,
            contract_file='openzeppelin-solidity/contracts/token/ERC721/ERC721Mintable.sol',
            contract_name='ERC721Mintable',
            startgas=10**7,
            args=[],
            contract_creator=CONTRACT_OWNER_PRIVATE_KEY)
        self.erc721_contract.mint(CONTRACT_OWNER_ADDRESS, TOKEN_ID, sender=CONTRACT_OWNER_PRIVATE_KEY)

        self.auction_contract = deploy_solidity_contract_with_args(
            chain=self.chain,
            solc_config_sources={
                'examples/erc721_auction/ERC721AuctionSubmarine.sol': {
                    'urls':
                    [os.path.join(contract_dir, 'examples/erc721_auction/ERC721AuctionSubmarine.sol')]
                },
                'LibSubmarineSimple.sol': {
                    'urls':
                    [os.path.join(contract_dir, 'LibSubmarineSimple.sol')]
                },
                'openzeppelin-solidity/contracts/math/SafeMath.sol': {
                    'urls': [os.path.join(contract_dir, 'openzeppelin-solidity/contracts/math/SafeMath.sol')]
                },
                'proveth/ProvethVerifier.sol': {
                    'urls': [
                        os.path.join(contract_dir,
                                     'proveth/ProvethVerifier.sol')
                    ]
                },
                'proveth/RLP.sol': {
                    'urls': [os.path.join(contract_dir, 'proveth/RLP.sol')]
                },
                'openzeppelin-solidity/contracts/token/ERC721/IERC721.sol': {
                    'urls': [os.path.join(contract_dir, 'openzeppelin-solidity/contracts/token/ERC721/IERC721.sol')]
                },
                'openzeppelin-solidity/contracts/token/ERC721/IERC721Receiver.sol': {
                    'urls': [os.path.join(contract_dir, 'openzeppelin-solidity/contracts/token/ERC721/IERC721Receiver.sol')]
                },
                'openzeppelin-solidity/contracts/introspection/IERC165.sol': {
                    'urls': [os.path.join(contract_dir, 'openzeppelin-solidity/contracts/introspection/IERC165.sol')]
                }
            },
            allow_paths=root_repo_dir,
            contract_file='examples/erc721_auction/ERC721AuctionSubmarine.sol',
            contract_name='ERC721Auction',
            startgas=10**7,
            args=[],
            contract_creator=CONTRACT_OWNER_PRIVATE_KEY)
        self.chain.mine(1)
Exemplo n.º 8
0
from ethereum import slogging
#slogging.configure(':INFO,eth.vm:INFO')
slogging.configure(':DEBUG')
#slogging.configure(':DEBUG,eth.vm:TRACE')

##
# Some utilities for pyethereum tester
##
xor = lambda (x, y): chr(ord(x) ^ ord(y))
xors = lambda x, y: ''.join(map(xor, zip(x, y)))
zfill = lambda s: (32 - len(s)) * '\x00' + s
flatten = lambda x: [z for y in x for z in y]

# Create the simulated blockchain

env = config.Env()
env.config['BLOCK_GAS_LIMIT'] = 3141592000
env.config['START_GAS_LIMIT'] = 3141592000
s = tester.Chain(env=env)
# Need to increase the gas limit. These are some large contracts!
s.mine()

contract_path = './contractNipopow.sol'
contract_name = 'Nipopow'
contract_compiled = compile_file(contract_path)

contract_data = solidity_get_contract_data(
    contract_compiled,
    contract_path,
    contract_name,
)