def test_get_token_metadata(self): token_txhash = bytes(sha2_256(b'alpha')) token_metadata = TokenMetadata.create( token_txhash, [bytes(sha2_256(b'delta')), bytes(sha2_256(b'gamma'))]) self.state._db.get_raw = MagicMock( return_value=token_metadata.serialize()) self.assertEqual( TokenMetadata.get_token_metadata(self.state, token_txhash).to_json(), token_metadata.to_json())
def setUp(self): self.blockheader = Mock(name='mock BlockHeader', autospec=BlockHeader, block_number=5, headerhash=bytes(sha2_256(b'mock headerhash')), prev_headerhash=bytes(sha2_256(b'test'))) self.block = Block.create(dev_config=config.dev, block_number=5, prev_headerhash=bytes(sha2_256(b'test')), prev_timestamp=10, transactions=[], miner_address=alice.address, seed_height=0, seed_hash=None) self.block.blockheader = self.blockheader
def setUp(self): self.block = Block.create(dev_config=config.dev, block_number=5, prev_headerhash=bytes(sha2_256(b'test')), prev_timestamp=10, transactions=[], miner_address=alice.address, seed_height=0, seed_hash=None)
def sha256(message: bytes) -> bytes: """ :param message: :type message: Union[str, unicode] :return: :rtype: str >>> bin2hstr(sha256(b"test")) '9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08' >>> bin2hstr(sha256(b"another string")) '81e7826a5821395470e5a2fed0277b6a40c26257512319875e1d70106dcb1ca0' """ return bytes(sha2_256(message))
def setUp(self): with set_xrd_dir('no_data'): self.state = State() self.chain_manager = ChainManager(self.state) self.alice = get_alice_xmss() self.bob = get_bob_xmss() self.slave = get_slave_xmss() self.tx1 = TransferTransaction.create(addrs_to=[self.bob.address], amounts=[10], message_data=None, fee=1, xmss_pk=self.alice.pk) self.tx2 = TransferTransaction.create(addrs_to=[self.bob.address], amounts=[10], message_data=None, fee=1, xmss_pk=self.slave.pk, master_addr=self.alice.address) self.tx1._data.nonce = 3 self.tx2._data.nonce = 6 self.tx1.sign(self.alice) self.tx2.sign(self.slave) self.block_attrs = { "dev_config": config.dev, "block_number": 5, "prev_headerhash": bytes(sha2_256(b'test')), "prev_timestamp": 10, "transactions": [self.tx1, self.tx2], "miner_address": self.alice.address, "seed_height": 0, "seed_hash": None, } self.coinbase_addrstate_attrs = OptimizedAddressState.get_default( config.dev.coinbase_address) self.coinbase_addrstate_attrs.update_balance( None, int(config.dev.coin_remaining_at_genesis * config.dev.shor_per_quanta)) self.bob_addrstate_attrs = OptimizedAddressState.get_default( self.bob.address) self.bob_addrstate_attrs.update_balance(None, 20) self.alice_addrstate_attrs = OptimizedAddressState.get_default( self.alice.address) self.alice_addrstate_attrs.update_balance(None, 100) self.alice_addrstate_attrs.pbdata.nonce = 2 self.slave_addrstate_attrs = OptimizedAddressState.get_default( self.slave.address) self.slave_addrstate_attrs.pbdata.nonce = 5
def generate_multi_sig_address(creation_tx_hash: bytes) -> bytes: desc = bytes(hstr2bin('110000')) prev_hash = bytes(sha2_256(desc + creation_tx_hash)) new_hash = bytes(sha2_256(desc + prev_hash))[-4:] return desc + prev_hash + new_hash