예제 #1
0
 def from_data(cls, data: Dict[str, str]) -> Delegation:
     return cls(
         delegator_address=data["delegator_address"],
         validator_address=data["validator_address"],
         shares=Coin(uLuna, data["shares"]),
         balance=Coin(uLuna, data["balance"]),
     )
예제 #2
0
 def from_data(cls, data: Dict[str, str]) -> UnbondingEntry:
     return cls(
         initial_balance=Coin(uLuna, data["initial_balance"]),
         balance=Coin(uLuna, data["balance"]),
         creation_height=int(data["creation_height"]),
         completion_time=Timestamp.from_data(data["completion_time"]),
     )
예제 #3
0
    def test_make_coin(self, d1):
        coin = Coin(d1, "13929")
        assert coin.denom == d1
        assert coin.amount == 13929

        coin = Coin(d1, "0.006250000000000000")
        assert coin.denom == d1
        assert coin.amount == Dec("0.00625")
예제 #4
0
 def from_data(cls, data: dict) -> RedelegationEntry:
     return cls(
         initial_balance=Coin(uLuna, data["initial_balance"]),
         balance=Coin(uLuna, data["balance"]),
         shares_dst=Coin(uLuna, data["shares_dst"]),
         creation_height=int(data["creation_height"]),
         completion_time=Timestamp.from_data(data["completion_time"]),
     )
예제 #5
0
 def test_add_coins(self, t):
     """Coins can be added, which merges the collections of Coins and groups together
     the sum amount for Coins of a similar denom."""
     A = t([Coin("uluna", 2000)])
     B = t([Coin("ukrw", 1000)])
     C = t([Coin("uluna", 1000), Coin("ukrw", 250), Coin("uusd", 2000)])
     assert A + B == Coins([Coin("uluna", 2000), Coin("ukrw", 1000)])
     assert A + B + C == Coins(
         [Coin("uluna", 3000), Coin("ukrw", 1250), Coin("uusd", 2000)]
     )
예제 #6
0
    def test_contains_denom(self):
        """The `in` operator in Python should allow a user to query whether a Coin of a specified denom
        exists in the sdk.Coins object."""

        haystack = Coins(
            [Coin("A", 1000), Coin("B", 500), Coin("needle", 250), Coin("C", 125)]
        )
        assert "needle" in haystack
        assert "B" in haystack
        assert "D" not in haystack
예제 #7
0
    def test_coin_sub(self, d1, d2, x, y):
        coin = Coin(d1, x)
        coin2 = Coin(d1, y)
        coin3 = Coin(d1, x - y)
        coindiff = coin - coin2

        assert isinstance(coindiff.amount, int) or isinstance(
            coindiff.amount, Dec)
        assert coin3 == coindiff
        with pytest.raises(DenomIncompatibleError):
            Coin(d1, x) - Coin(d2, x)
예제 #8
0
    def test_coin_add(self, d1, d2, x, y):
        coin = Coin(d1, x)
        coin2 = Coin(d1, y)
        coin3 = Coin(d1, x + y)
        coinsum = coin + coin2

        assert isinstance(coinsum.amount, int) or isinstance(
            coinsum.amount, Dec)
        assert coin3 == coinsum
        with pytest.raises(DenomIncompatibleError):
            Coin(d1, x) + Coin(d2, x)
예제 #9
0
파일: staking.py 프로젝트: terra-money/jigu
 def pool(
     self, key: Optional[str] = None
 ) -> Union[ApiResponse, Coin, JiguBox[str, Coin]]:
     res = self._api_get("/staking/pool")
     pool = JiguBox(
         {
             "bonded": Coin(uLuna, res["bonded_tokens"]),
             "not_bonded": Coin(uLuna, res["not_bonded_tokens"]),
         }
     )
     return project(res, pool[key] if key else pool)
예제 #10
0
 def from_data(cls, data: dict) -> Validator:
     return cls(
         operator_address=data["operator_address"],
         consensus_pubkey=data["consensus_pubkey"],
         jailed=data["jailed"],
         status_code=data["status"],
         tokens=Coin(uLuna, data["tokens"]),
         delegator_shares=Coin(uLuna, data["delegator_shares"]),
         description=Description.from_data(data["description"]),
         unbonding_height=int(data["unbonding_height"]),
         unbonding_time=Timestamp.from_data(data["unbonding_time"]),
         commission=Commission.from_data(data["commission"]),
         min_self_delegation=int(data["min_self_delegation"]),
     )
예제 #11
0
    def test_coin_compare(self, d1, d2, x, y):
        assume(x < y)
        coin = Coin(d1, x)
        coin2 = Coin(d1, y)
        coin3 = Coin(d2, x)

        coin_dup = Coin(d1, x)
        assert coin < coin2
        assert coin2 > coin

        assert coin >= coin_dup
        assert coin <= coin_dup

        with pytest.raises(DenomIncompatibleError):
            coin < coin3
예제 #12
0
def default_tax_policy():
    return PolicyConstraints(
        rate_min=Dec.with_prec(5, 4),
        rate_max=Dec.with_prec(1, 2),
        cap=Coin("usdr", 1),
        change_max=Dec.with_prec(25, 5),
    )
예제 #13
0
파일: staking.py 프로젝트: terra-money/jigu
 def from_data(cls, data: dict) -> MsgDelegate:
     data = data["value"]
     return cls(
         delegator_address=data["delegator_address"],
         validator_address=data["validator_address"],
         amount=Coin.from_data(data["amount"]),
     )
예제 #14
0
 def from_data(cls, data: dict) -> MsgSwap:
     data = data["value"]
     return cls(
         trader=data["trader"],
         offer_coin=Coin.from_data(data["offer_coin"]),
         ask_denom=data["ask_denom"],
     )
예제 #15
0
    def test_broadcast_txcodespacerror(self, wallet, fee, mnemonics):
        """Tests that a that it captures the correct txcodespace error."""
        fail_swap = MsgSwap(
            trader=wallet.address, offer_coin=Coin("uluna", 1), ask_denom="bebo"
        )
        fail_vote = MsgExchangeRateVote(
            exchange_rate="603.899000000000000000",
            salt="0dff",
            denom="umnt",
            feeder=wallet.address,
            validator="terravaloper1vqnhgc6d0jyggtytzqrnsc40r4zez6tx99382w",
        )
        send = MsgSend(
            from_address=wallet.address,
            to_address=mnemonics[1]["address"],
            amount=Coins(uluna=1),
        )

        tx1 = wallet.create_and_sign_tx(send, send, fail_swap, send, fail_vote, fee=fee)
        with pytest.raises(TxCodespaceError) as excinfo:
            wallet.broadcast(tx1)
        err = excinfo.value
        assert err.codespace == "market"

        tx2 = wallet.create_and_sign_tx(
            send, fail_vote, send, send, fail_swap, fail_swap, fee=fee
        )
        with pytest.raises(TxCodespaceError) as excinfo:
            wallet.broadcast(tx2)
        err = excinfo.value
        assert err.codespace == "oracle"
예제 #16
0
 def test_broadcast(self, wallet, fee):
     swap = MsgSwap(
         trader=wallet.address, offer_coin=Coin("uluna", 1), ask_denom="umnt"
     )
     tx = wallet.create_and_sign_tx(swap, fee=fee)
     res = wallet.broadcast(tx)
     assert res.msgs is not None
예제 #17
0
 def __post_init__(self):
     self.feeder = validate_acc_address(self.feeder)
     self.validator = validate_val_address(self.validator)
     if not isinstance(self.exchange_rate, Coin):
         self.exchange_rate = Coin(self.denom, self.exchange_rate)
     else:
         validate_same_denom(self.exchange_rate.denom, self.denom)
예제 #18
0
 def from_data(cls, data: dict) -> PolicyConstraints:
     return cls(
         rate_min=Dec(data["rate_min"]),
         rate_max=Dec(data["rate_max"]),
         cap=Coin.from_data(data["cap"]),
         change_max=Dec(data["change_max"]),
     )
예제 #19
0
 def tally_for(self,
               proposal_id: str) -> Union[ApiResponse, Dict[str, Coin]]:
     res = self._api_get(f"/gov/proposals/{proposal_id}/tally")
     denoms = res or []
     tally = JiguBox({})
     for denom in denoms:
         tally[denom] = Coin(uLuna, int(res[denom]))
     return project(res, JiguBox(tally))
예제 #20
0
 def from_data(cls, data: dict) -> MsgExchangeRateVote:
     data = data["value"]
     xr = Coin(data["denom"], data["exchange_rate"])
     return cls(
         exchange_rate=xr,
         salt=data["salt"],
         denom=xr.denom,
         feeder=data["feeder"],
         validator=data["validator"],
     )
예제 #21
0
파일: staking.py 프로젝트: terra-money/jigu
 def from_data(cls, data: dict) -> MsgCreateValidator:
     data = data["value"]
     return cls(
         description=Description.from_data(data["description"]),
         commission=CommissionRates.from_data(data["commission"]),
         min_self_delegation=int(data["min_self_delegation"]),
         delegator_address=data["delegator_address"],
         validator_address=data["validator_address"],
         pubkey=data["pubkey"],
         value=Coin.from_data(data["value"]),
     )
예제 #22
0
 def test_uses_correct_internal_amount(self, d1):
     examples = [
         (500, int),
         ("4.2", Dec),
         ("0", int),
         ("0.0", Dec),
         (-100000000000, int),
         ("-0.00000000000001", Dec),
     ]
     for x in examples:
         coin = Coin(d1, x[0])
         assert isinstance(coin.amount, x[1])
예제 #23
0
    def test_constructor_copy(self):
        """sdk.Coins object should copy another sdk.Coins object when passed into constructor,
        rather than maintaining original references."""
        A = Coin("A", 1000)
        C1 = Coins([A])
        C2 = Coins(C1)

        assert C1 == C2
        assert list(C1) == list(C2)
        assert C1 is not C2
        assert C1.coins[0] is not A  # should be a new coin
        assert C2.coins[0] is not C1.coins[0]  # should be a new coin
예제 #24
0
 def swap_rate(self, offer_coin: Coin, ask_denom: str) -> Union[ApiResponse, Coin]:
     if type(offer_coin.amount) != int:
         warnings.warn(
             f"Coin's amount will be converted to integer: {int(offer_coin.amount)} {offer_coin.denom}",
             SyntaxWarning,
         )
     params = {
         "offer_coin": f"{int(offer_coin.amount)}{offer_coin.denom}",
         "ask_denom": ask_denom,
     }
     res = self._api_get(f"/market/swap", params=params)
     return project(res, Coin.deserialize(res))
예제 #25
0
def test_multisend(master_key2):
    """This test highlights how Jigu is flexible to accomodate many input styles."""

    multisend = MsgMultiSend(
        inputs=[
            Input(
                address=master_key2.acc_address,
                coins=[
                    Coin("uluna", 1_000_000),
                    Coin(denom="usdr", amount="1000000")
                ],
            )
        ],
        outputs=[
            Output("terra12dazwl3yq6nwrce052ah3fudkarglsgvacyvl9",
                   [Coin("uluna", 500000)]),
            {
                "address": "terra1ptdx6akgk7wwemlk5j73artt5t6j8am08ql3qv",
                "coins":
                Coins() + Coin("uluna", 500000) + Coin("usdr", 1000000),
            },
        ],
    )

    unsigned = StdSignMsg(
        account_number=47,
        sequence=0,
        chain_id="columbus-3-testnet",
        msgs=[multisend],
        fee=StdFee.make(100_000, uluna=1500, usdr=1000),
        memo="1234",
    )

    tx = master_key2.sign_tx(unsigned)

    assert (
        tx.signatures[0].signature ==
        "YA/ToXLxuuAOQlpm5trbIUu2zv5NfBmeHz2jmXgNrt8jP+odukerfri3DUXAJuhETAMHVVV78t7Q4xC0j+CVkA=="
    )
예제 #26
0
def test_sign_tx(master_key):
    unsigned = StdSignMsg(
        msgs=[
            MsgSend(
                from_address=master_key.acc_address,
                to_address="terra1wg2mlrxdmnnkkykgqg4znky86nyrtc45q336yv",
                amount=[Coin("uluna", 100_000_000)],
            )
        ],
        sequence=0,
        account_number=45,
        chain_id="columbus-3-testnet",
        fee=StdFee(gas=46_467, amount=[Coin("uluna", 698)]),
    )
예제 #27
0
    def test_getitem(self):
        """sdk.Coins object should act like a dict, and indexable by denom as key."""

        X = Coins([Coin("A", 1000), Coin("B", 2000), Coin("C", 3000)])
        assert all(isinstance(X[i], Coin) for i in ["A", "B", "C"])
        assert X["A"] == Coin("A", 1000)
        assert X["B"] == Coin("B", 2000)
        assert X["C"] == Coin("C", 3000)
        with pytest.raises(KeyError):
            X["D"]
예제 #28
0
 def from_data(cls, data: dict) -> Proposal:
     final_tally_result = data["final_tally_result"]
     for key in final_tally_result:
         final_tally_result[key] = Coin(uLuna, int(final_tally_result[key]))
     p_type = PROPOSAL_TYPES[data["content"]["type"]]
     content = p_type.from_data(data["content"])
     return cls(
         content=content,
         id=int(data["id"]),
         proposal_status=ProposalStatus(data["proposal_status"]),
         final_tally_result=JiguBox(final_tally_result),
         submit_time=Timestamp.from_data(data["submit_time"]),
         deposit_end_time=Timestamp.from_data(data["deposit_end_time"]),
         total_deposit=Coins.from_data(data["total_deposit"]),
         voting_start_time=Timestamp.from_data(data["voting_start_time"]),
         voting_end_time=Timestamp.from_data(data["voting_end_time"]),
     )
예제 #29
0
    def test_coin_eq(self, x, y, d1, d2):
        """Tests Coin equality against another Coin."""
        assume(x != y)

        coin = Coin(d1, x)
        coin2 = Coin(d1, x)
        assert coin == coin2

        # denoms different
        coin3 = Coin(d1, x)
        coin4 = Coin(d2, x)
        assert coin3 != coin4

        # amount different
        coin5 = Coin(d1, x)
        coin6 = Coin(d1, y)
        assert coin5 != coin6

        # amount type different
        coin7 = Coin(d1, 4)
        coin8 = Coin(d1, "4.2")
        coin9 = Coin(d1, 4.2)
        assert coin7 != coin8
        assert coin8 == coin9
예제 #30
0
 def from_data(cls, data) -> ExchangeRateVote:
     xr = Coin(data["denom"], data["exchange_rate"])
     return cls(exchange_rate=xr, denom=xr.denom, voter=data["voter"])