Skip to content

Commit

Permalink
Test for delegate vesting shares (#21)
Browse files Browse the repository at this point in the history
* Add workflow conditions

* Temporary change id-token to permissions

* Add test for delegate_vesting_shares

* Bump version to 1.0.2
  • Loading branch information
chiliec authored Jan 10, 2024
1 parent 867c2cd commit d458eea
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

We follow [Semantic Versions](https://semver.org/).

## Version 1.0.2

- Add `delegate_vesting_shares` method

## Version 1.0.1

- Support Python 3.12
Expand All @@ -14,4 +18,4 @@ We follow [Semantic Versions](https://semver.org/).

## Version 0.1.0

- Initial release
- Initial release
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "viz-python-lib"
version = "1.0.1"
version = "1.0.2"
description = "Python library for VIZ blockchain"
authors = ["Vladimir Kamarzin <[email protected]>"]
license = "MIT"
Expand Down
14 changes: 12 additions & 2 deletions tests/test_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def test_proposal_update(viz, default_account):


def test_transfer(viz, default_account):

trx = viz.transfer("null", 1, "VIZ", memo="test_viz", account=default_account)
assert isinstance(trx, dict)
viz.transfer(default_account, 1, "VIZ", memo="#encrypted memo", account=default_account)
Expand All @@ -52,7 +51,14 @@ def test_fixed_award(viz, default_account):
viz.fixed_award(default_account, reward_amount=10, max_energy=50, memo="test_viz", account=default_account)

beneficiaries = [{"account": default_account, "weight": 50}]
viz.fixed_award(default_account, reward_amount=10, max_energy=50, memo="test_viz", beneficiaries=beneficiaries, account=default_account)
viz.fixed_award(
default_account,
reward_amount=10,
max_energy=50,
memo="test_viz",
beneficiaries=beneficiaries,
account=default_account,
)


def test_custom(viz, default_account):
Expand Down Expand Up @@ -132,3 +138,7 @@ def test_create_account(viz):

# referrer
viz.create_account('jimmy8', password='123', creator='alice', referrer='bob')


def test_delegate_vesting_shares(viz):
viz.delegate_vesting_shares(delegator='alice', delegatee='bob', amount=10)
29 changes: 13 additions & 16 deletions viz/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Any, DefaultDict, Dict, List, Optional, Union

from graphenecommon.chain import AbstractGrapheneChain
from graphenecommon.exceptions import KeyAlreadyInStoreException,AccountDoesNotExistsException
from graphenecommon.exceptions import KeyAlreadyInStoreException, AccountDoesNotExistsException

from vizapi.noderpc import NodeRPC
from vizbase import operations
Expand Down Expand Up @@ -265,7 +265,7 @@ def award(
)

return self.finalizeOp(op, account, "regular")

def fixed_award(
self,
receiver: str,
Expand Down Expand Up @@ -669,13 +669,13 @@ def create_account(
op = operations.Account_create(**op)

return self.finalizeOp(op, creator, "active")

def update_account_profile(
self,
account_name: str,
memo_key: str,
json_meta: Optional[Dict[str, Any]] = None,
) -> dict:
) -> dict:
"""
Update account profile.
Expand All @@ -685,7 +685,7 @@ def update_account_profile(
:param str account_name: (**required**) new account name
:param dict json_meta: Optional meta data for the account
:raises AccountDoesNotExistsException: if the account does not exist
"""

Expand All @@ -704,19 +704,16 @@ def update_account_profile(
op = operations.Account_update(**op)

return self.finalizeOp(ops=op, account=account_name, permission="active")

def delegate_vesting_shares(
self,
delegator: str,
delegatee: str,
amount: float
) -> dict:

def delegate_vesting_shares(self, delegator: str, delegatee: str, amount: float) -> dict:
"""
Delegate vesting SHARES to account.
:param str delegator: account that delegates
:param str delegatee: account to which is delegated
:param float amount: number of SHARES to be delegated
:raises AccountDoesNotExistsException: if the account does not exist
"""

# check if the account does not exist
Expand All @@ -729,10 +726,10 @@ def delegate_vesting_shares(
"delegator": delegator,
"delegatee": delegatee,
"vesting_shares": "{:.{prec}f} {asset}".format(
float(amount),
prec=PRECISIONS.get(self.rpc.chain_params["shares_symbol"]),
asset=self.rpc.chain_params["shares_symbol"],
),
float(amount),
prec=PRECISIONS.get(self.rpc.chain_params["shares_symbol"]),
asset=self.rpc.chain_params["shares_symbol"],
),
}

op = operations.Delegate_vesting_shares(**op)
Expand Down

0 comments on commit d458eea

Please sign in to comment.