Exemplo n.º 1
0
    def test_staking_balance_issue(self):
        address = "tz1V4qCyvPKZ5UeqdH14HN42rxvNPQfc9UZg"
        cycle = 220  # snapshot index == 15

        rpc_rewards = load_reward_model(address, cycle, "actual")
        if rpc_rewards is None:
            rpc_impl = RpcRewardApiImpl(
                nw=DEFAULT_NETWORK_CONFIG_MAP["MAINNET"],
                baking_address=address,
                node_url=RPC_PUBLIC_API_URL["MAINNET"],
            )
            rpc_rewards = rpc_impl.get_rewards_for_cycle_map(cycle, RewardsType.ACTUAL)
            store_reward_model(address, cycle, "actual", rpc_rewards)

        tzkt_impl = TzKTRewardApiImpl(
            nw=DEFAULT_NETWORK_CONFIG_MAP["MAINNET"], baking_address=address
        )
        tzkt_rewards = tzkt_impl.get_rewards_for_cycle_map(cycle, RewardsType.ACTUAL)

        self.assertAlmostEqual(
            rpc_rewards.delegate_staking_balance, tzkt_rewards.delegate_staking_balance
        )
        self.assertAlmostEqual(
            rpc_rewards.total_reward_amount, tzkt_rewards.total_reward_amount, delta=1
        )
Exemplo n.º 2
0
    def test_expected_rewards(self, address, cycle):
        tzstats_rewards = load_reward_model(address, cycle, "expected")
        if tzstats_rewards is None:
            tzstats_impl = TzStatsRewardApiImpl(
                nw=DEFAULT_NETWORK_CONFIG_MAP["MAINNET"], baking_address=address
            )
            tzstats_rewards = tzstats_impl.get_rewards_for_cycle_map(
                cycle, RewardsType.ESTIMATED
            )
            store_reward_model(address, cycle, "expected", tzstats_rewards)

        tzkt_impl = TzKTRewardApiImpl(
            nw=DEFAULT_NETWORK_CONFIG_MAP["MAINNET"], baking_address=address
        )
        tzkt_rewards = tzkt_impl.get_rewards_for_cycle_map(cycle, RewardsType.ESTIMATED)

        self.assertAlmostEqual(
            tzstats_rewards.delegate_staking_balance,
            tzkt_rewards.delegate_staking_balance,
            delta=1,
        )
        self.assertAlmostEqual(
            tzstats_rewards.total_reward_amount,
            tzkt_rewards.total_reward_amount,
            delta=1,
        )
        self.assertBalancesAlmostEqual(
            tzstats_rewards.delegator_balance_dict,
            tzkt_rewards.delegator_balance_dict,
            delta=1,
        )
Exemplo n.º 3
0
 def test_update_current_balances(self):
     log_items = [RewardLog(address='KT1Np1h72jGkRkfxNHLXNNJLHNbj9doPz4bR',
                            type='D',
                            staking_balance=100500,
                            current_balance=0)]
     tzkt_impl = TzKTRewardApiImpl(nw=default_network_config_map['MAINNET'],
                                   baking_address='tz1gk3TDbU7cJuiBRMhwQXVvgDnjsxuWhcEA')
     tzkt_impl.update_current_balances(log_items)
     self.assertNotEqual(0, log_items[0].current_balance)
Exemplo n.º 4
0
 def test_update_current_balances(self):
     log_items = [
         RewardLog(
             address="KT1Np1h72jGkRkfxNHLXNNJLHNbj9doPz4bR",
             type="D",
             staking_balance=100500,
             current_balance=0,
         )
     ]
     tzkt_impl = TzKTRewardApiImpl(
         nw=DEFAULT_NETWORK_CONFIG_MAP["MAINNET"],
         baking_address="tz1gk3TDbU7cJuiBRMhwQXVvgDnjsxuWhcEA",
     )
     tzkt_impl.update_current_balances(log_items)
     self.assertNotEqual(0, log_items[0].current_balance)
Exemplo n.º 5
0
    def newRewardApi(
        self,
        network_config,
        baking_address,
        node_url,
        node_url_public="",
        api_base_url=None,
    ):
        if self.provider == "rpc":
            if node_url.find("http") == -1:
                node_url = "http://" + node_url
            return RpcRewardApiImpl(network_config, baking_address, node_url)
        elif self.provider == "prpc":
            if node_url_public == "":
                node_url_public = PUBLIC_NODE_URL[network_config["NAME"]]
            return RpcRewardApiImpl(network_config, baking_address,
                                    node_url_public)
        elif self.provider == "tzstats":
            return TzStatsRewardApiImpl(network_config, baking_address)
        elif self.provider == "tzkt":
            return TzKTRewardApiImpl(network_config,
                                     baking_address,
                                     base_url=api_base_url)

        raise Exception("No supported reward data provider : {}".format(
            self.provider))
Exemplo n.º 6
0
    def newRewardApi(self,
                     network_config,
                     baking_address,
                     node_url,
                     node_url_public='',
                     api_base_url=None):
        if self.provider == 'rpc':
            if node_url.find("http") == -1:
                node_url = 'http://' + node_url
            return RpcRewardApiImpl(network_config,
                                    baking_address,
                                    node_url,
                                    verbose=self.verbose)
        elif self.provider == 'prpc':
            if node_url_public == '':
                node_url_public = PUBLIC_NODE_URL[network_config['NAME']][0]
            return RpcRewardApiImpl(network_config,
                                    baking_address,
                                    node_url_public,
                                    verbose=self.verbose)
        elif self.provider == 'tzstats':
            return TzStatsRewardApiImpl(network_config,
                                        baking_address,
                                        verbose=self.verbose)
        elif self.provider == 'tzkt':
            return TzKTRewardApiImpl(network_config,
                                     baking_address,
                                     verbose=self.verbose,
                                     base_url=api_base_url)

        raise Exception("No supported reward data provider : {}".format(
            self.provider))
Exemplo n.º 7
0
    def test_get_rewards_for_cycle_map(self, address, cycle):
        rpc_rewards = load_reward_model(address, cycle, 'actual')
        if rpc_rewards is None:
            rpc_impl = RpcRewardApiImpl(
                nw=default_network_config_map['MAINNET'],
                baking_address=address,
                node_url='https://rpc.tzkt.io/mainnet')
            rpc_rewards = rpc_impl.get_rewards_for_cycle_map(cycle)
            store_reward_model(address, cycle, 'actual', rpc_rewards)

        tzkt_impl = TzKTRewardApiImpl(
            nw=default_network_config_map['MAINNET'],
            baking_address=address)
        tzkt_rewards = tzkt_impl.get_rewards_for_cycle_map(cycle)

        self.assertAlmostEqual(rpc_rewards.delegate_staking_balance, tzkt_rewards.delegate_staking_balance, delta=1)
        self.assertAlmostEqual(rpc_rewards.total_reward_amount, tzkt_rewards.total_reward_amount, delta=1)
        self.assertBalancesAlmostEqual(rpc_rewards.delegator_balance_dict, tzkt_rewards.delegator_balance_dict, delta=1)
    def test_get_rewards_for_cycle_map(self, address, cycle):
        """
        This test compares the total rewards and balance according to tzkt,
        to the total rewards according to rpc.

        It also compares the balances per delegator.
        """
        rpc_rewards = load_reward_model(address,
                                        cycle,
                                        RewardsType.ACTUAL,
                                        dir_name="tzkt_data")
        if rpc_rewards is None:
            rpc_impl = RpcRewardApiImpl(
                nw=DEFAULT_NETWORK_CONFIG_MAP["MAINNET"],
                baking_address=address,
                node_url=PUBLIC_NODE_URL["MAINNET"],
            )
            rpc_rewards = rpc_impl.get_rewards_for_cycle_map(
                cycle, RewardsType.ACTUAL)
            store_reward_model(address,
                               cycle,
                               RewardsType.ACTUAL,
                               rpc_rewards,
                               dir_name="tzkt_data")

        tzkt_impl = TzKTRewardApiImpl(nw=DEFAULT_NETWORK_CONFIG_MAP["MAINNET"],
                                      baking_address=address)
        tzkt_rewards = tzkt_impl.get_rewards_for_cycle_map(
            cycle, RewardsType.ACTUAL)

        self.assertAlmostEqual(
            rpc_rewards.delegate_staking_balance,
            tzkt_rewards.delegate_staking_balance,
            delta=1,
        )
        self.assertAlmostEqual(rpc_rewards.total_reward_amount,
                               tzkt_rewards.total_reward_amount,
                               delta=1)
        self.assertBalancesAlmostEqual(
            rpc_rewards.delegator_balance_dict,
            tzkt_rewards.delegator_balance_dict,
            delta=1,
        )
Exemplo n.º 9
0
    def test_staking_balance_issue(self):
        address = 'tz1V4qCyvPKZ5UeqdH14HN42rxvNPQfc9UZg'
        cycle = 220  # snapshot index == 15

        rpc_rewards = load_reward_model(address, cycle, 'actual')
        if rpc_rewards is None:
            rpc_impl = RpcRewardApiImpl(
                nw=default_network_config_map['MAINNET'],
                baking_address=address,
                node_url='https://rpc.tzkt.io/mainnet')
            rpc_rewards = rpc_impl.get_rewards_for_cycle_map(cycle)
            store_reward_model(address, cycle, 'actual', rpc_rewards)

        tzkt_impl = TzKTRewardApiImpl(
            nw=default_network_config_map['MAINNET'],
            baking_address=address)
        tzkt_rewards = tzkt_impl.get_rewards_for_cycle_map(cycle)

        self.assertNotEqual(rpc_rewards.delegate_staking_balance, tzkt_rewards.delegate_staking_balance)
        self.assertAlmostEqual(rpc_rewards.total_reward_amount, tzkt_rewards.total_reward_amount, delta=1)
Exemplo n.º 10
0
    def test_expected_rewards(self, address, cycle):
        tzstats_rewards = load_reward_model(address, cycle, 'expected')
        if tzstats_rewards is None:
            tzstats_impl = TzStatsRewardApiImpl(
                nw=default_network_config_map['MAINNET'],
                baking_address=address)
            tzstats_rewards = tzstats_impl.get_rewards_for_cycle_map(cycle, expected_reward=True)
            store_reward_model(address, cycle, 'expected', tzstats_rewards)

        tzkt_impl = TzKTRewardApiImpl(
            nw=default_network_config_map['MAINNET'],
            baking_address=address)
        tzkt_rewards = tzkt_impl.get_rewards_for_cycle_map(cycle, expected_reward=True)

        self.assertAlmostEqual(
            tzstats_rewards.delegate_staking_balance, tzkt_rewards.delegate_staking_balance, delta=1)
        self.assertAlmostEqual(
            tzstats_rewards.total_reward_amount, tzkt_rewards.total_reward_amount, delta=1)
        self.assertBalancesAlmostEqual(
            tzstats_rewards.delegator_balance_dict, tzkt_rewards.delegator_balance_dict, delta=1)
Exemplo n.º 11
0
def address_api():
    return TzKTRewardApiImpl(
        nw=DEFAULT_NETWORK_CONFIG_MAP["MAINNET"], baking_address=STAKENOW_ADDRESS
    )