Exemple #1
0
 def _initialize_blockchain(self, genesis=None):
     log.info('Initializing new chain')
     if not genesis:
         genesis = blocks.genesis(self.env)
         log.info('new genesis', genesis_hash=genesis, difficulty=genesis.difficulty)
         self.index.add_block(genesis)
     self._store_block(genesis)
     assert genesis == blocks.get_block(self.env, genesis.hash)
     self._update_head(genesis)
     assert genesis.hash in self
     self.commit()
Exemple #2
0
 def _initialize_blockchain(self, genesis=None):
     log.info('Initializing new chain')
     if not genesis:
         genesis = blocks.genesis(self.blockchain, difficulty=blocks.GENESIS_DIFFICULTY)
         log.info('new genesis', genesis_hash=genesis, difficulty=genesis.difficulty)
         self.index.add_block(genesis)
     self._store_block(genesis)
     assert genesis == blocks.get_block(self.blockchain, genesis.hash)
     self._update_head(genesis)
     assert genesis.hash in self
     self.commit()
Exemple #3
0
def test_mine_block_with_transaction2(db):
    k, v, k2, v2 = accounts()
    blk = mkquickgenesis({v: {"balance": utils.denoms.ether * 1}}, db)
    store_block(blk)
    tx = get_transaction()
    blk2 = mine_next_block(blk, coinbase=v, transactions=[tx])
    assert tx in blk2.get_transactions()
    store_block(blk2)
    assert tx in blk2.get_transactions()
    assert blocks.get_block(env(blk2.db), blk2.hash) == blk2
    assert tx.gasprice == 0
    assert blk2.get_balance(
        v) == env(db).config['BLOCK_REWARD'] + blk.get_balance(v) - tx.value
    assert blk.state.db.db == blk2.state.db.db.db
    assert blk2.get_parent() == blk
    assert tx in blk2.get_transactions()
    assert tx not in blk.get_transactions()
Exemple #4
0
def test_mine_block_with_transaction2(db):
    k, v, k2, v2 = accounts()
    blk = mkquickgenesis({v: {"balance": utils.denoms.ether * 1}}, db)
    store_block(blk)
    tx = get_transaction()
    blk2 = mine_next_block(blk, coinbase=v, transactions=[tx])
    assert tx in blk2.get_transactions()
    store_block(blk2)
    assert tx in blk2.get_transactions()
    assert blocks.get_block(env(blk2.db), blk2.hash) == blk2
    assert tx.gasprice == 0
    assert blk2.get_balance(
        v) == env(db).config['BLOCK_REWARD'] + blk.get_balance(v) - tx.value
    assert blk.state.db.db == blk2.state.db.db.db
    assert blk2.get_parent() == blk
    assert tx in blk2.get_transactions()
    assert tx not in blk.get_transactions()
Exemple #5
0
 def get(self, blockhash):
     assert is_string(blockhash)
     assert len(blockhash) == 32
     return blocks.get_block(self.env, blockhash)
Exemple #6
0
 def head(self):
     if self.blockchain is None or 'HEAD' not in self.blockchain:
         self._initialize_blockchain()
     ptr = self.blockchain.get('HEAD')
     return blocks.get_block(self.env, ptr)
Exemple #7
0
 def get(self, blockhash):
     assert is_string(blockhash)
     assert len(blockhash) == 32
     return blocks.get_block(self.blockchain, blockhash)
Exemple #8
0
 def head(self):
     if self.blockchain is None or 'HEAD' not in self.blockchain:
         self._initialize_blockchain()
     ptr = self.blockchain.get('HEAD')
     return blocks.get_block(self.blockchain, ptr)
Exemple #9
0
def test_deserialize_commit(db):
    k, v, k2, v2 = accounts()
    blk = blocks.genesis(env(db))
    db.put(blk.hash, rlp.encode(blk))
    db.commit()
    assert blk == blocks.get_block(env(db), blk.hash)
Exemple #10
0
def store_block(blk):
    blk.db.put(blk.hash, rlp.encode(blk))
    assert blocks.get_block(env(blk.db), blk.hash) == blk
Exemple #11
0
def test_deserialize_commit(db):
    k, v, k2, v2 = accounts()
    blk = blocks.genesis(env(db))
    db.put(blk.hash, rlp.encode(blk))
    db.commit()
    assert blk == blocks.get_block(env(db), blk.hash)
Exemple #12
0
def store_block(blk):
    blk.db.put(blk.hash, rlp.encode(blk))
    assert blocks.get_block(env(blk.db), blk.hash) == blk
Exemple #13
0
def test_deserialize(db):
    k, v, k2, v2 = accounts()
    blk = blocks.genesis(db)
    db.put(blk.hash, rlp.encode(blk))
    assert blk == blocks.get_block(db, blk.hash)
Exemple #14
0
def test_deserialize(db):
    k, v, k2, v2 = accounts()
    blk = blocks.genesis(db)
    db.put(blk.hash, rlp.encode(blk))
    assert blk == blocks.get_block(db, blk.hash)