コード例 #1
0
def test_simulate_single_operation():
    default_fee = TZTX_FEE
    network_config = {"BLOCK_TIME_IN_SEC": 60, "MINIMAL_BLOCK_DELAY": 30}
    batch_payer = BatchPayer(
        node_url="node_addr",
        pymnt_addr="tz1234567890123456789012345678901234",
        clnt_mngr=ClientManager(
            node_endpoint=PUBLIC_NODE_URL[CURRENT_TESTNET],
            signer_endpoint=PRIVATE_SIGNER_URL,
        ),
        delegator_pays_ra_fee=True,
        delegator_pays_xfer_fee=True,
        network_config=network_config,
        plugins_manager=MagicMock(),
        dry_run=False,
    )
    batch_payer.base_counter = 0
    reward_log = RewardLog(
        address="KT1P3Y1mkGASzuJqLh7uGuQEvHatztGuQRgC",
        type="D",
        staking_balance=0,
        current_balance=0,
    )
    reward_log.amount = 15577803
    reward_log.skipped = False
    simulation_status, simulation_results = batch_payer.simulate_single_operation(
        reward_log, reward_log.amount, "hash", "unittest")
    assert PaymentStatus.DONE == simulation_status
    consumed_gas, tx_fee, storage = simulation_results
    assert 150 == consumed_gas
    assert 410 == default_fee + consumed_gas * MUTEZ_PER_GAS_UNIT
    assert int == type(storage)  # type of storage should be int
    assert 24 == storage
コード例 #2
0
    def FromPaymentCSVDictRow(self, row, cycle):
        rl = RewardLog(row["address"], row["type"], 0, 0)
        rl.cycle = cycle
        rl.amount = int(row["amount"])
        rl.hash = None if row["hash"] == 'None' else row["hash"]
        rl.paid = PaymentStatus(int(row["paid"]))

        return rl
コード例 #3
0
    def from_payment_csv_dict_row(row, cycle):
        rl = RewardLog(row["address"], row["type"], 0, 0)
        rl.cycle = cycle
        rl.amount = int(row["amount"])
        rl.hash = None if row["hash"] == "None" else row["hash"]
        rl.paid = PaymentStatus(int(row["paid"]))

        return rl
コード例 #4
0
    def FromPaymentCSVDictRow(self, row, cyle):
        rl = RewardLog(row["address"], row["type"], None)
        rl.cycle = cyle
        rl.amount = int(row["amount"])
        rl.hash = None if row["hash"] == 'None' else row["hash"]
        rl.balance = 0 if rl.balance == None else rl.balance
        rl.paid = PaymentStatus(int(row["paid"]))
        # rl.child = None if row["child"] == 'None' else row["child"]

        return rl
コード例 #5
0
    def calculate(self, reward_logs):
        # if address is in address destination dictionary;
        # then set payment address to mapped address value
        for rl in self.filterskipped(reward_logs):
            rl.ratio6 = rl.ratio

        address_set = set(rl.paymentaddress
                          for rl in self.filterskipped(reward_logs))
        payment_address_list_dict = {addr: [] for addr in address_set}

        # group payments by paymentaddress
        for rl in self.filterskipped(reward_logs):
            payment_address_list_dict[rl.paymentaddress].append(rl)

        reward_data6 = []
        for rl in self.iterateskipped(reward_logs):
            reward_data6.append(rl)

        for addr, rl_list in payment_address_list_dict.items():
            if len(rl_list) > 1:
                total_staking_balance = sum(
                    [rl.staking_balance for rl in rl_list])
                total_current_balance = sum(
                    [rl.current_balance for rl in rl_list])
                total_ratio = sum([rl.ratio for rl in rl_list])
                total_payment_amount = sum([rl.amount for rl in rl_list])
                total_adjusted_payment_amount = sum(
                    [rl.adjusted_amount for rl in rl_list])
                total_adjustment = sum([rl.adjustment for rl in rl_list])
                total_service_fee_amount = sum(
                    [rl.service_fee_amount for rl in rl_list])
                total_service_fee_ratio = sum(
                    [rl.service_fee_ratio for rl in rl_list])

                merged = RewardLog(addr, TYPE_MERGED, total_staking_balance,
                                   total_current_balance)
                merged.ratio = total_ratio
                merged.amount = total_payment_amount
                merged.adjusted_amount = total_adjusted_payment_amount
                merged.adjustment = total_adjustment
                merged.service_fee_amount = total_service_fee_amount
                merged.service_fee_ratio = total_service_fee_ratio
                merged.service_fee_rate = 0
                merged.parents = rl_list

                reward_data6.append(merged)
            else:
                reward_data6.append(rl_list[0])

        return reward_data6
コード例 #6
0
    def test_merge(self):

        rewards = []

        #
        # Alice is a delegate, owner and founder
        rlAD = RewardLog(address="tz1Alice01", type="D", staking_balance=10000, current_balance=20000)
        rlAD.amount = 1234
        rewards.append(rlAD)

        rlAO = RewardLog(address="tz1Alice01", type="O", staking_balance=10000, current_balance=0)
        rlAO.amount = 2345
        rewards.append(rlAO)

        rlAF = RewardLog(address="tz1Alice01", type="F", staking_balance=10000, current_balance=0)
        rlAF.amount = 3456
        rewards.append(rlAF)

        #
        # Bob is only a delegate
        rlBD = RewardLog(address="tz1Bob01", type="D", staking_balance=10000, current_balance=0)
        rlBD.amount = 5000
        rewards.append(rlBD)

        #
        # Charlie is an Owner and Founder, not a delegate
        rlCO = RewardLog(address="tz1Charlie01", type="O", staking_balance=10000, current_balance=0)
        rlCO.amount = 1122
        rewards.append(rlCO)

        rlCF = RewardLog(address="tz1Charlie01", type="F", staking_balance=10000, current_balance=0)
        rlCF.amount = 2233
        rewards.append(rlCF)

        #
        # Merge Alice and Charlie's payouts
        mergedRewards = CalculatePhaseMerge().calculate(rewards)

        # Check that there now exists only 3 records. Alice's 3 should be merged to 1,
        # and Charlie's 2 merged to 1, Bob only had 1 to begin with
        self.assertEqual(3, len(mergedRewards))

        # Check that Alice's merged record equals the original 3
        aliceSum = 7035
        bobSum = 5000
        charlieSum = 3355

        for r in mergedRewards:
            if r.address == "tz1Alice01":
                self.assertEqual(r.amount, aliceSum)
                self.assertEqual(r.type, TYPE_MERGED)
            elif r.address == "tz1Bob01":
                self.assertEqual(r.amount, bobSum)
                self.assertEqual(r.type, TYPE_DELEGATOR)
            elif r.address == "tz1Charlie01":
                self.assertEqual(r.amount, charlieSum)
                self.assertEqual(r.type, TYPE_MERGED)
コード例 #7
0
def test_simulate_single_operation():
    config = configparser.ConfigParser()
    assert os.path.isfile(FEE_INI) is True
    config.read(FEE_INI)
    default_fee = int(config["KTTX"]["fee"])
    network_config = {"BLOCK_TIME_IN_SEC": 64}
    batch_payer = BatchPayer(
        node_url="node_addr",
        pymnt_addr="tz1234567890123456789012345678901234",
        clnt_mngr=ClientManager(
            node_endpoint="https://testnet-tezos.giganode.io:443",
            signer_endpoint="http://127.0.0.1:6732",
        ),
        delegator_pays_ra_fee=True,
        delegator_pays_xfer_fee=True,
        network_config=network_config,
        plugins_manager=MagicMock(),
        dry_run=False,
    )
    batch_payer.base_counter = 0
    reward_log = RewardLog(
        address="KT1P3Y1mkGASzuJqLh7uGuQEvHatztGuQRgC",
        type="D",
        staking_balance=0,
        current_balance=0,
    )
    reward_log.amount = 15577803
    reward_log.skipped = False
    simulation_status, simulation_results = batch_payer.simulate_single_operation(
        reward_log, reward_log.amount, "hash", "unittest")
    assert PaymentStatus.DONE == simulation_status
    consumed_gas, tx_fee, storage = simulation_results
    assert 150 == consumed_gas
    assert 589 == default_fee + consumed_gas * MUTEZ_PER_GAS_UNIT
    assert int == type(storage)  # type of storage should be int
    assert 24 == storage