Esempio n. 1
0
    def test_hdkd_hard_path(self):
        mnemonic = 'old leopard transfer rib spatial phone calm indicate online fire caution review'
        derivation_address = '5FEiH8iuDUw271xbqWTWuB6WrDjv5dnCeDX1CyHubAniXDNN'
        derivation_path = '//Alice'

        derived_keypair = Keypair.create_from_uri(mnemonic + derivation_path)

        self.assertEqual(derivation_address, derived_keypair.ss58_address)
Esempio n. 2
0
def test_get_stake_for_uid___has_no_stake(setup_chain):
    hotkeypair = Keypair.create_from_mnemonic(Keypair.generate_mnemonic())
    coldkeypair = Keypair.create_from_uri('//Alice')

    wallet = generate_wallet(coldkey_pair=coldkeypair, hotkey_pair=hotkeypair)
    subtensor = connect(setup_chain)

    subscribe(subtensor, wallet)
    uid = subtensor.get_uid_for_pubkey(hotkeypair.public_key)

    result = subtensor.get_stake_for_uid(uid)
    assert int(result) == 0
Esempio n. 3
0
def test_transfer_success(setup_chain):
    coldkey_alice = Keypair.create_from_uri("//Alice")
    coldkey_bob = Keypair.create_from_uri("//Bob")

    subtensor = connect(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_pair=coldkey_alice)

    result = subtensor.transfer(wallet=wallet_alice,
                                dest=coldkey_bob.ss58_address,
                                amount=Balance(10_000),
                                wait_for_finalization=True,
                                timeout=30)
    assert result is True

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

    assert int(balance_alice_post) < int(
        balance_alice_pre) - 10000  # Because of variable transaction fees
    assert int(balance_bob_post) == int(balance_bob_pre) + 10000
Esempio n. 4
0
def test_unstake_success(setup_chain):
    coldkeypair = Keypair.create_from_uri('//Alice')
    hotkey_pair = Keypair.create_from_mnemonic(Keypair.generate_mnemonic())
    wallet = generate_wallet(coldkey_pair=coldkeypair, hotkey_pair=hotkey_pair)

    subtensor = connect(setup_chain)
    subtensor.is_connected()

    subscribe(subtensor, wallet)

    # Get the balance for the cold key, we use this for later comparison
    balance_pre = int(subtensor.get_balance(coldkeypair.public_key))

    add_stake(subtensor, wallet, Balance(4000))

    # Determine the cost of the add_stake transaction
    balance_post = int(subtensor.get_balance(coldkeypair.public_key))
    transaction_fee_add_stake = balance_pre - balance_post - 4000

    logger.error("Trans_fee add_stake: {}", transaction_fee_add_stake)

    # unstake incurs a transaction fee that is added to the block reward
    result = subtensor.unstake(amount=Balance(3000),
                               wallet=wallet,
                               hotkey_id=hotkey_pair.public_key,
                               wait_for_finalization=True,
                               timeout=30)
    assert result is True

    transaction_fee_unstake = balance_post - int(
        subtensor.get_balance(coldkeypair.public_key)) + 3000
    logger.error("Trans_fee add_stake: {}", transaction_fee_unstake)

    assert int(transaction_fee_unstake) == TRANSACTION_FEE_UNSTAKE

    # At this point, the unstake transaction fee is in the transaction_fee_pool, and will make it into the block
    # reward the next block. However, in order to get this reward into the hotkey account of the neuron,
    # and emit needs to take place. This is why the expectation does not include the unstake transaction fee

    uid = subtensor.get_uid_for_pubkey(hotkey_pair.public_key)
    stake = subtensor.get_stake_for_uid(uid)
    expectation = 1000 + (3 * BLOCK_REWARD) + TRANSACTION_FEE_ADD_STAKE

    assert int(stake) == expectation
Esempio n. 5
0
def test_add_stake_success(setup_chain):
    coldkeypair = Keypair.create_from_uri("//Alice")
    hotkeypair = Keypair.create_from_mnemonic(Keypair.generate_mnemonic())

    wallet = generate_wallet(coldkey_pair=coldkeypair, hotkey_pair=hotkeypair)
    subtensor = connect(setup_chain)
    subtensor.is_connected()

    # Subscibe the hotkey using Alice's cold key, which has TAO
    subscribe(subtensor, wallet)

    uid = subtensor.get_uid_for_pubkey(hotkeypair.public_key)
    assert uid is not None

    #Verify the node has 0 stake
    result = subtensor.get_stake_for_uid(uid)
    assert int(result) == int(Balance(0))

    # Get balance
    balance_pre = subtensor.get_balance(coldkeypair.ss58_address)

    # Timeout is 30, because 3 * blocktime does not work.
    result = subtensor.add_stake(wallet,
                                 Balance(4000),
                                 hotkeypair.public_key,
                                 wait_for_finalization=True,
                                 timeout=30)
    assert result == True

    # Check if the amount of stake ends up in the hotkey account
    result = subtensor.get_stake_for_uid(uid)
    assert int(result) == int(Balance(4000))

    # Check if the balances had reduced by the amount of stake + the transaction fee for the staking operation
    balance_post = subtensor.get_balance(coldkeypair.ss58_address)
    assert int(balance_post) == int(balance_pre) - (4000 +
                                                    TRANSACTION_FEE_ADD_STAKE)
Esempio n. 6
0
def test_get_balance_success(setup_chain):
    hotkey_pair = Keypair.create_from_uri('//Alice')
    subtensor = connect(setup_chain)
    subtensor.is_connected()
    result = subtensor.get_balance(hotkey_pair.ss58_address)
    assert int(result) == pow(10, 9)