def test_account_zero_withdraw(wallet: Wallet, account, amount): response = wallet.withdraw(account, amount) validate_response(response, wallet.withdraw.__name__) response = wallet.withdraw(account, Amount("0 SP")) validate_response(response, wallet.withdraw.__name__) transfers = wallet.get_account_transfers(account) expect(len(transfers) == 2, "Was created more withdrawals then was expected.") expect(transfers[0][1]["status"] == "interrupted") expect(transfers[1][1]["status"] == "empty") assert_expectations()
def test_account_active_withdraw(wallet: Wallet, account, amount): response = wallet.withdraw(account, amount) validate_response(response, wallet.withdraw.__name__) transfers = wallet.get_account_transfers(account) expect(len(transfers) == 1, "Was created more withdrawals then was expected.") withdraw = transfers[0][1] expect(withdraw["status"] == "active") expect(Amount(withdraw["withdrawn"]) == Amount("0 SP")) # e.g. any payment was not provided yet expect(withdraw["op"][0] == "withdraw_scorumpower") expect(Amount(withdraw["op"][1]["scorumpower"]) == amount) expect(withdraw["op"][1]["account"] == account) assert_expectations()
def test_account_final_withdraw(wallet: Wallet, account, amount): response = wallet.withdraw(account, amount) validate_response(response, wallet.withdraw.__name__) account_before = wallet.get_account(account) constants = wallet.get_config() intervals = constants["SCORUM_VESTING_WITHDRAW_INTERVALS"] single_payment = amount / intervals interval_sec = constants["SCORUM_VESTING_WITHDRAW_INTERVAL_SECONDS"] for i in range(1, intervals + 1): time.sleep(interval_sec + 1) expected_withdraw = single_payment * i transfers = wallet.get_account_transfers(account) expect(len(transfers) == 1, "Was created more withdrawals then was expected.") withdrawn = Amount(transfers[0][1]["withdrawn"]) expect( withdrawn == expected_withdraw, "step: %d, actual '%s', expected '%s'" % (i, withdrawn, expected_withdraw) ) account_after = wallet.get_account(account) sp_change = Amount(account_before["scorumpower"]) - Amount(account_after["scorumpower"]) expect( sp_change == expected_withdraw, "step: %d, actual '%s', expected '%s'" % (i, sp_change, expected_withdraw) ) scr_change = Amount(account_after["balance"]) - Amount(account_before["balance"]) expect( scr_change == expected_withdraw, "step: %d, actual '%s', expected '%s'" % (i, scr_change, expected_withdraw) ) assert_expectations() if i == intervals: assert transfers[0][1]["status"] == "finished"