Example #1
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))
Example #2
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
        )
    def newRewardApi(self,
                     network_config,
                     baking_address,
                     node_url,
                     node_url_public=''):
        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)

        raise Exception("No supported reward data provider : {}".format(
            self.provider))
Example #4
0
    def newRewardApi(self, network_config, baking_address, wllt_clnt_mngr, node_url):
        if self.provider == 'rpc':
            return RpcRewardApiImpl(network_config, baking_address, wllt_clnt_mngr, node_url)
        elif self.provider == 'tzscan':
            if not self.mirror_selector:
                self.init_mirror_selector(network_config)
            return TzScanRewardApiImpl(network_config, baking_address, self.mirror_selector)

        raise Exception("No supported reward data provider : {}".format(self.provider))
Example #5
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,
        )
Example #7
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)
def address_api():
    return RpcRewardApiImpl(
        nw=DEFAULT_NETWORK_CONFIG_MAP["MAINNET"],
        baking_address=STAKENOW_ADDRESS,
        node_url=PUBLIC_NODE_URL["MAINNET"],
    )