def test_blockchain(self): t = tn.CoinbaseTransaction(wt.pubToAddress(wt.privToPub(pk))) t.sign(pk) genesis_block = bk.Block(time.time(), '0' * 64, s.Serializer.serialize(t)) genesis_block.mine(2) bv.validate(genesis_block) '''genesis''' tr = tn.Transaction(wt.pubToAddress(wt.privToPub(pk)), '12pULxeW59imr1mWs8AjQogji8H77KD3KT', 5) tr.sign(pk) sr = s.Serializer.serialize(tr) lst = [] lst.append(s.Serializer.serialize(t)) lst.append(sr) lst.append(sr) lst.append(sr) b1 = bk.Block(time.time(), genesis_block.hash, lst) b1.mine(2) bv.validate(b1) b2 = bk.Block(time.time(), b1.hash, lst) b2.mine(2) bv.validate(b2) chain = [] chain.append(genesis_block) chain.append(b1) chain.append(b2) #b2.timestamp = "1241" self.assertTrue(is_valid_chain(chain)) chain
def premine(): kg = wallet.KeyGenerator() priv_keys = [] addresses = [] f_addr = open('public_address', 'w+') f_privk = open('private_key.wif', "w+") for i in range(3): priv_keys.append(kg.generate_key()) addresses.append(wallet.pubToAddress(wallet.privToPub(priv_keys[i]))) f_privk.write(wallet.privToWif(priv_keys[i]) + '\n') f_addr.write(addresses[i] + '\n') for i in range(10): t = transaction.Transaction(addresses[0], addresses[1], 10 + i) t.sign(priv_keys[0]) tx_validator.validation(t) tx = {'serialized': serializer.Serializer.serialize(t)} requests.post(URL + NODE_PORT + '/transactions/new', json=tx) t = transaction.Transaction(addresses[1], addresses[2], 11 + i) t.sign(priv_keys[1]) tx_validator.validation(t) tx = {'serialized': serializer.Serializer.serialize(t)} requests.post(URL + NODE_PORT + '/transactions/new', json=tx) t = transaction.Transaction(addresses[2], addresses[0], 12 + i) t.sign(priv_keys[2]) tx_validator.validation(t) tx = {'serialized': serializer.Serializer.serialize(t)} requests.post(URL + NODE_PORT + '/transactions/new', json=tx) miner = miner_cli.MinerCli(NODE_PORT) miner.do_mine(None) for i in range(10): miner.do_mine(None)
def do_import(self, arg): try: self.file = open(arg, "r") except: print(arg + ": invalid file or directory") return wif = self.file.read() try: self.private_key = wallet.wifToPriv(wif) except Exception as e: print(str(e)) return addr = wallet.pubToAddress(wallet.privToPub(self.private_key)) self.print_it(self.private_key, addr) self.file.close()
def test_genesis_block(self): t = tn.CoinbaseTransaction(wt.pubToAddress(wt.privToPub(pk))) t.sign(pk) b = bk.Block('123142.124', '0' * 64, s.Serializer.serialize(t)) b.mine(2) bv.validate(b)
def test_address(self): self.assertTrue(tv.check_address(wt.pubToAddress(wt.privToPub(pk))))
def do_new(self, arg): kg = wallet.KeyGenerator() self.private_key = kg.generate_key() addr = wallet.pubToAddress(wallet.privToPub(self.private_key)) self.print_it(self.private_key, addr)