def test_validate_not_sane_zeroes(self): db = self.MockDatabase() block1 = MultiChainBlock() # Act block1.up = 0 block1.down = 0 result = block1.validate(db) self.assertEqual(result[0], ValidationResult.invalid) self.assertIn("Up and down are zero", result[1])
def test_validate_not_sane_negatives(self): db = self.MockDatabase() block1 = MultiChainBlock() # Act block1.up = -10 block1.down = -20 block1.total_down = -10 block1.total_up = -20 result = block1.validate(db) self.assertEqual(result[0], ValidationResult.invalid) self.assertIn("Up field is negative", result[1]) self.assertIn("Down field is negative", result[1]) self.assertIn("Total up field is negative", result[1]) self.assertIn("Total down field is negative", result[1])
def test_pack(self): block = MultiChainBlock() block.up = 3251690667711950702 block.down = 7431046511915463784 block.total_up = 7020667011326177138 block.total_down = 2333265293611395173 block.public_key = ' fish, so sad that it should come to this. - We tried to warn you all but ' block.sequence_number = 1869095012 block.link_public_key = 'ear! - You may not share our intellect, which might explain your disrespec' block.link_sequence_number = 1949048934 block.previous_hash = 'or all the natural wonders that ' block.signature = 'grow around you. - So long, so long, and thanks for all the fish' self.assertEqual(block.pack(), '- So long and thanks for all the fish, so sad that it should come to this. - We' ' tried to warn you all but oh dear! - You may not share our intellect, which ' 'might explain your disrespect, for all the natural wonders that grow around you' '. - So long, so long, and thanks for all the fish')
def test_get_statistics(self): """ Testing whether the API returns the correct statistics """ block = MultiChainBlock() block.public_key = self.member.public_key block.link_public_key = "deadbeef".decode("HEX") block.link_sequence_number = 21 block.up = 42 block.down = 8 block.total_up = 1024 block.total_down = 2048 block.sequence_number = 3 block.previous_hash = "babecafe".decode("HEX") block.signature = "babebeef".decode("HEX") self.mc_community.persistence.add_block(block) def verify_response(response): response_json = json.loads(response) self.assertTrue("statistics" in response_json) stats = response_json["statistics"] self.assertEqual(stats["id"], self.member.public_key.encode("HEX")) self.assertEqual(stats["total_blocks"], 3) self.assertEqual(stats["total_up"], 1024) self.assertEqual(stats["total_down"], 2048) self.assertEqual(stats["peers_that_pk_helped"], 1) self.assertEqual(stats["peers_that_helped_pk"], 1) self.assertIn("latest_block", stats) self.assertNotEqual(stats["latest_block"]["insert_time"], "") self.assertEqual(stats["latest_block"]["hash"], block.hash.encode("HEX")) self.assertEqual(stats["latest_block"]["link_public_key"], "deadbeef") self.assertEqual(stats["latest_block"]["link_sequence_number"], 21) self.assertEqual(stats["latest_block"]["up"], 42) self.assertEqual(stats["latest_block"]["down"], 8) self.should_check_equality = False return self.do_request('multichain/statistics', expected_code=200).addCallback(verify_response)