Exemplo n.º 1
0
def test_add_stake_success(setup_chain):
    coldkey = Keypair.create_from_uri("//Alice")
    hotkey = Keypair.create_from_uri('//Alice')

    wallet = generate_wallet(coldkey=coldkey, hotkey=hotkey)
    subtensor = setup_subtensor(setup_chain)

    # Register the hotkey using Alice's cold key
    subtensor.register(wallet=wallet)
    uid = subtensor.get_uid_for_hotkey(hotkey.ss58_address)
    assert uid is not None

    # Verify the node has 0 stake
    result = wallet.get_stake(subtensor=subtensor)
    assert result == Balance(0)

    # Get balance. This should be default account balance value of Alice (1152921504606846976)
    balance_pre = subtensor.get_balance(coldkey.ss58_address)
    add_stake(subtensor, wallet, 100)

    # # Check if the amount of stake ends up in the hotkey account
    result = wallet.get_stake(subtensor=subtensor)
    assert result == Balance.from_tao(100)

    # Check if the balances had reduced by the amount of stake
    balance_post = subtensor.get_balance(coldkey.ss58_address)

    assert balance_post == Balance(
        int(balance_pre) - PARTIAL_FEE - int(Balance.from_tao(100)))
Exemplo n.º 2
0
 def setUp(self):
     self.subtensor = bittensor.subtensor( network = 'nobunaga' )
     self.wallet = bittensor.wallet()
     coldkey = Keypair.create_from_mnemonic(Keypair.generate_mnemonic())
     self.wallet.set_coldkey(coldkey, encrypt=False, overwrite=True)
     self.wallet.set_coldkeypub(coldkey, encrypt=False, overwrite=True)
     self.wallet.set_hotkey(Keypair.create_from_mnemonic(Keypair.generate_mnemonic()), encrypt=False, overwrite=True)
     self.mock_neuron = self.subtensor._neuron_dict_to_namespace(
         dict({
             "version":1,
             "ip":0,
             "port":0,
             "ip_type":0,
             "uid":1,
             "modality":0,
             "hotkey":'some_hotkey',
             "coldkey":'some_coldkey',
             "active":0,
             "last_update":0,
             "priority":0,
             "stake":1000000000000.0,
             "rank":0.0,
             "trust":0.0,
             "consensus":0.0,
             "incentive":0.0,
             "dividends":0.0,
             "emission":0.0,
             "bonds":[],
             "weights":[],
             "is_null":False
         })
     )
     self.neurons = self.subtensor.neurons()
     self.balance = Balance.from_tao(1000)
     assert True
Exemplo n.º 3
0
    def test_stake_failed( self ):
        class failed():
            def __init__(self):
                self.is_success = False
                self.error_message = 'Mock'
            def process_events(self):
                return True

        self.subtensor.substrate.submit_extrinsic = MagicMock(return_value = failed()) 
        self.subtensor.register = MagicMock(return_value = True) 
        self.subtensor.neuron_for_pubkey = MagicMock(return_value = self.mock_neuron) 
        self.subtensor.get_balance = MagicMock(return_value = Balance.from_tao(0))

        fail= self.subtensor.add_stake(self.wallet,
                            amount = 200,
                            wait_for_inclusion = True
                            )
        assert fail == False
Exemplo n.º 4
0
def test_transfer_success(setup_chain):
    coldkey_alice = Keypair.create_from_uri("//Alice")
    coldkey_bob = Keypair.create_from_uri("//Bob")

    subtensor = setup_subtensor(setup_chain)

    balance_alice_pre = subtensor.get_balance(coldkey_alice.ss58_address)
    balance_bob_pre = subtensor.get_balance(coldkey_bob.ss58_address)

    wallet_alice = generate_wallet(coldkey=coldkey_alice)
    result = subtensor.transfer(wallet=wallet_alice,
                                dest=coldkey_bob.ss58_address,
                                amount=100,
                                wait_for_finalization=True)
    assert result == True

    balance_alice_post = subtensor.get_balance(coldkey_alice.ss58_address)
    balance_bob_post = subtensor.get_balance(coldkey_bob.ss58_address)

    # Bob should have its original balance + 100 that we transferred
    assert int(balance_bob_post) == int(balance_bob_pre) + int(
        Balance.from_tao(100))