From 1cca2a9ea3d601c236d1866afdb7ff237c14cdc3 Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Wed, 8 Mar 2023 22:58:02 -0500 Subject: [PATCH] Fix metagraph output (#1116) * fix symbol unicode * add alias for --delegate_ss58 * fix patch * add linux bin * . * nominate test works * delegate stake works * delegate unstake works * remove todo * fix mock of get all hotkeys * use finney for network name and _mock for config * fix add arg * add rich text console helpers * overview test for subnets * add case for overview * add overview test for unregistered subnet 1 and 2 * add transfer test * add test for failed transfer * transfer test with check for error output * fix metagraph output and add test --- bittensor/_cli/commands/metagraph.py | 4 ++-- tests/integration_tests/test_cli.py | 36 +++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/bittensor/_cli/commands/metagraph.py b/bittensor/_cli/commands/metagraph.py index a379927eb5..a8fc0167cc 100644 --- a/bittensor/_cli/commands/metagraph.py +++ b/bittensor/_cli/commands/metagraph.py @@ -50,7 +50,7 @@ def run (cli): ep = metagraph.endpoint_objs[uid] row = [ str(ep.uid), - '{:.5f}'.format( metagraph.stake[uid]), + '{:.5f}'.format( metagraph.total_stake[uid]), '{:.5f}'.format( metagraph.ranks[uid]), '{:.5f}'.format( metagraph.trust[uid]), '{:.5f}'.format( metagraph.consensus[uid]), @@ -66,7 +66,7 @@ def run (cli): ep.hotkey[:10], ep.coldkey[:10] ] - total_stake += metagraph.stake[uid] + total_stake += metagraph.total_stake[uid] total_rank += metagraph.ranks[uid] # total_validator_trust += metagraph.validator_trust[uid] total_trust += metagraph.trust[uid] diff --git a/tests/integration_tests/test_cli.py b/tests/integration_tests/test_cli.py index afc48397fd..b176d2fe06 100644 --- a/tests/integration_tests/test_cli.py +++ b/tests/integration_tests/test_cli.py @@ -1897,9 +1897,43 @@ def test_metagraph( self ): config.command = "metagraph" config.no_prompt = True + # Add some neurons to the metagraph + mock_nn = [] + for i in range(10): + mock_nn.append( + SimpleNamespace( + hotkey = get_mock_keypair(i + 100, self.id()).ss58_address, + coldkey = get_mock_keypair(i, self.id()).ss58_address, + balance = Balance.from_rao( random.randint(0, 2**45) ).rao, + stake = Balance.from_rao( random.randint(0, 2**45) ).rao, + ) + ) + success, err = _subtensor_mock.sudo_register( + netuid = config.netuid, + hotkey = mock_nn[i].hotkey, + coldkey = mock_nn[i].coldkey, + balance = mock_nn[i].balance, + stake = mock_nn[i].stake + ) + self.assertTrue(success, err) cli = bittensor.cli(config) - cli.run() + + mock_console = MockConsole() + with patch('bittensor.__console__', mock_console): + cli.run() + + # Check that the overview was printed. + self.assertIsNotNone(mock_console.captured_print) + + output_no_syntax = mock_console.remove_rich_syntax(mock_console.captured_print) + + self.assertIn('Metagraph', output_no_syntax) + nn = _subtensor_mock.neurons( netuid = config.netuid ) + self.assertIn(str(len(nn) - 1), output_no_syntax) # Check that the number of neurons is output + # Check each uid is in the output + for neuron in nn: + self.assertIn(str(neuron.uid), output_no_syntax) def test_set_weights( self ):