def test_change_stamps_works(self): network = mocks.MockNetwork(num_of_masternodes=2, num_of_delegates=3, ctx=self.ctx) async def test(): await network.start() network.refresh() await network.make_and_push_tx( wallet=mocks.TEST_FOUNDATION_WALLET, contract='currency', function='transfer', kwargs={ 'amount': 1_000_000, 'to': network.delegates[0].wallet.verifying_key } )
def test_mock_network_init_creates_correct_bootnodes(self): # 2 mn, 3 delegate expected_ips = [ 'tcp://127.0.0.1:18000', 'tcp://127.0.0.1:18001', 'tcp://127.0.0.1:18002', 'tcp://127.0.0.1:18003', 'tcp://127.0.0.1:18004', ] n = mocks.MockNetwork(num_of_masternodes=2, num_of_delegates=3, ctx=self.ctx) self.assertEqual(n.masternodes[0].ip, expected_ips[0]) self.assertEqual(n.masternodes[1].ip, expected_ips[1]) self.assertEqual(n.delegates[0].ip, expected_ips[2]) self.assertEqual(n.delegates[1].ip, expected_ips[3]) self.assertEqual(n.delegates[2].ip, expected_ips[4])
def test_startup_and_blocks_from_network_object_works_no_wait(self): network = mocks.MockNetwork(ctx=self.ctx, num_of_masternodes=1, num_of_delegates=1) sender = Wallet() async def test(): await network.start() network.refresh() await network.make_and_push_tx( wallet=mocks.TEST_FOUNDATION_WALLET, contract='currency', function='transfer', kwargs={ 'amount': 1_000_000, 'to': sender.verifying_key } )
def test_vote_new_masternode_in_can_join_and_accept_transactions(self): network = mocks.MockNetwork(num_of_masternodes=2, num_of_delegates=3, ctx=self.ctx) stu = Wallet() candidate = Wallet() async def test(): await network.start() network.refresh() await network.make_and_push_tx( wallet=mocks.TEST_FOUNDATION_WALLET, contract='currency', function='transfer', kwargs={ 'amount': 1_000_000, 'to': stu.verifying_key } )
def test_process_two_tx(self): network = mocks.MockNetwork(num_of_masternodes=2, num_of_delegates=2, ctx=self.ctx) stu = Wallet() stu2 = Wallet() candidate = Wallet() candidate2 = Wallet() N_tx = 3 w_stu = [] for k in range(N_tx): w_stu.append(Wallet()) async def test(): await network.start() network.refresh() await network.make_and_push_tx(wallet=mocks.TEST_FOUNDATION_WALLET, contract='currency', function='transfer', kwargs={ 'amount': 1_000_000, 'to': w_stu[0].verifying_key }) # for k in range(1,N_tx): # await network.make_and_push_tx( # wallet=mocks.TEST_FOUNDATION_WALLET, # contract='currency', # function='transfer', # kwargs={ # 'amount': 2, # 'to': w_stu[0].verifying_key # } # ) for k1 in range(N_tx - 1):
def test_mock_network_init_makes_correct_number_of_nodes_many_nodes(self): n = mocks.MockNetwork(num_of_delegates=123, num_of_masternodes=143, ctx=self.ctx) self.assertEqual(len(n.masternodes), 143) self.assertEqual(len(n.delegates), 123)
def test_eat_stamps(self): network = mocks.MockNetwork(num_of_masternodes=2, num_of_delegates=3, ctx=self.ctx) code = '''\ @export def eat_stamps(): while True: pass ''' stu = Wallet() candidate = Wallet() print(candidate.verifying_key) async def test(): await network.start() network.refresh() await network.make_and_push_tx( wallet=mocks.TEST_FOUNDATION_WALLET, contract='submission', function='submit_contract', kwargs={ 'name': 'con_stamp_eater', 'code': code } ) await asyncio.sleep(2) await network.make_and_push_tx( wallet=mocks.TEST_FOUNDATION_WALLET, contract='con_stamp_eater', function='eat_stamps', kwargs={}, stamps=10000 ) await asyncio.sleep(2) await network.make_and_push_tx( wallet=mocks.TEST_FOUNDATION_WALLET, contract='con_stamp_eater', function='eat_stamps', kwargs={}, stamps=10000 ) await network.make_and_push_tx( wallet=mocks.TEST_FOUNDATION_WALLET, contract='currency', function='transfer', kwargs={ 'amount': 1, 'to': 'jeff' } ) await asyncio.sleep(2) await network.make_and_push_tx( wallet=mocks.TEST_FOUNDATION_WALLET, contract='currency', function='transfer', kwargs={ 'amount': 1, 'to': 'jeff' } ) await asyncio.sleep(2) await network.make_and_push_tx( wallet=mocks.TEST_FOUNDATION_WALLET, contract='currency', function='transfer', kwargs={ 'amount': 1, 'to': 'jeff' } ) await asyncio.sleep(2) await network.make_and_push_tx( wallet=mocks.TEST_FOUNDATION_WALLET, contract='currency', function='transfer', kwargs={ 'amount': 1, 'to': 'jeff' } ) await asyncio.sleep(4) self.loop.run_until_complete(test()) network.stop() network.flush()
def test_two_masters_one_offline_can_come_back_without_issue(self): network = mocks.MockNetwork(num_of_masternodes=2, num_of_delegates=2, ctx=self.ctx) async def test(): await network.start() network.refresh() await network.make_and_push_tx( wallet=mocks.TEST_FOUNDATION_WALLET, contract='currency', function='transfer', kwargs={ 'amount': 1, 'to': 'stu' } ) await asyncio.sleep(1) await network.make_and_push_tx( wallet=mocks.TEST_FOUNDATION_WALLET, contract='currency', function='transfer', kwargs={ 'amount': 1, 'to': 'stu2' } ) await asyncio.sleep(1) await network.make_and_push_tx( wallet=mocks.TEST_FOUNDATION_WALLET, contract='currency', function='transfer', kwargs={ 'amount': 1, 'to': 'stu3' } ) await asyncio.sleep(1) m = network.masternodes[0] m.stop() await network.make_and_push_tx( wallet=mocks.TEST_FOUNDATION_WALLET, contract='currency', function='transfer', kwargs={ 'amount': 1, 'to': 'stu3' }, mn_idx=1 ) await asyncio.sleep(1) await m.start() await asyncio.sleep(4) await network.make_and_push_tx( wallet=mocks.TEST_FOUNDATION_WALLET, contract='currency', function='transfer', kwargs={ 'amount': 1, 'to': 'stu3' } ) await asyncio.sleep(1) await network.make_and_push_tx( wallet=mocks.TEST_FOUNDATION_WALLET, contract='currency', function='transfer', kwargs={ 'amount': 1, 'to': 'jeff' } ) await asyncio.sleep(1) stu = m.driver.get_var(contract='currency', variable='balances', arguments=['stu']) stu2 = m.driver.get_var(contract='currency', variable='balances', arguments=['stu2']) stu3 = m.driver.get_var(contract='currency', variable='balances', arguments=['stu3']) jeff = m.driver.get_var(contract='currency', variable='balances', arguments=['jeff']) self.assertEqual(stu, 1) self.assertEqual(stu2, 1) self.assertEqual(stu3, 3) self.assertEqual(jeff, 1) self.loop.run_until_complete(test())
def test_single_masternode_goes_offline_and_back_on_has_no_problem_rejoining(self): network = mocks.MockNetwork(num_of_masternodes=1, num_of_delegates=2, ctx=self.ctx) async def test(): await network.start() network.refresh() await network.make_and_push_tx( wallet=mocks.TEST_FOUNDATION_WALLET, contract='currency', function='transfer', kwargs={ 'amount': 1, 'to': 'stu' } ) await asyncio.sleep(2) await network.make_and_push_tx( wallet=mocks.TEST_FOUNDATION_WALLET, contract='currency', function='transfer', kwargs={ 'amount': 1, 'to': 'stu2' } ) await asyncio.sleep(2) await network.make_and_push_tx( wallet=mocks.TEST_FOUNDATION_WALLET, contract='currency', function='transfer', kwargs={ 'amount': 1, 'to': 'stu3' } ) await asyncio.sleep(2) m = network.masternodes[0] m.stop() await asyncio.sleep(2) await m.start() await asyncio.sleep(4) await network.make_and_push_tx( wallet=mocks.TEST_FOUNDATION_WALLET, contract='currency', function='transfer', kwargs={ 'amount': 1, 'to': 'stu3' } ) await asyncio.sleep(2) await network.make_and_push_tx( wallet=mocks.TEST_FOUNDATION_WALLET, contract='currency', function='transfer', kwargs={ 'amount': 1, 'to': 'jeff' } ) await asyncio.sleep(2) stu = m.driver.get_var(contract='currency', variable='balances', arguments=['stu']) stu2 = m.driver.get_var(contract='currency', variable='balances', arguments=['stu2']) stu3 = m.driver.get_var(contract='currency', variable='balances', arguments=['stu3']) jeff = m.driver.get_var(contract='currency', variable='balances', arguments=['jeff']) self.assertEqual(stu, 1) self.assertEqual(stu2, 1) self.assertEqual(stu3, 2) self.assertEqual(jeff, 1) self.loop.run_until_complete(test())