def test_constructor_validates_addresses(self, acc_address, val_address, other): """MsgExchangeRateVote should validate `feeder` to be AccAddress and `validator` to be ValAddress. """ assume(not is_val_address(other) and not is_acc_address(other)) with pytest.raises(InvalidAccAddress): MsgExchangeRateVote( exchange_rate=Coin("ukrw", 1000), salt="", denom="ukrw", feeder=other, validator=val_address, ) with pytest.raises(InvalidValAddress): MsgExchangeRateVote( exchange_rate=Coin("ukrw", 1000), salt="", denom="ukrw", feeder=acc_address, validator=other, ) A = MsgExchangeRateVote( exchange_rate=Coin("ukrw", 1000), salt="", denom="ukrw", feeder=acc_address, validator=val_address, ) assert A.feeder == acc_address assert A.validator == val_address
def test_constructor_validates_addresses(self, acc_address, other): """MsgSwap should validate `trader` to be AccAddress. """ assume(not is_acc_address(other)) with pytest.raises(InvalidAccAddress): MsgSwap(trader=other, offer_coin=Coin("uluna", 100), ask_denom="umnt") A = MsgSwap(trader=acc_address, offer_coin=Coin("uluna", 100), ask_denom="umnt") assert A.trader == acc_address
def test_constructor_canonizes_amount_to_coins(self, acc_address): """MsgDeposit should convert List[Coins] to sdk.Coins """ amnt = [Coin("ukrw", 1000)] A = MsgDeposit(proposal_id=1, depositor=acc_address, amount=amnt) assert isinstance(A.amount, Coins) assert A.amount == amnt
def test_constructor_amount_canonizes_list_to_coins(self, acc_address): """Creating a MsgSend object directly through its constructor should be conveniently achievable with either a sdk.Coins object or List[Coin]. """ c = [Coin("uluna", 130000), Coin("ukrw", 12000000)] A = MsgSend(from_address=acc_address, to_address=acc_address, amount=c) B = MsgSend(from_address=acc_address, to_address=acc_address, amount=Coins(c)) assert A == B C = MsgSend(from_address=acc_address, to_address=acc_address, amount=[]) D = MsgSend(from_address=acc_address, to_address=acc_address, amount=Coins()) assert C == D assert isinstance(A.amount, Coins) assert isinstance(C.amount, Coins)
def test_constructor_canonizes_initial_deposit_to_coins(self, acc_address): """MsgSubmitProposal should convert initial_deposit List[Coins] to sdk.Coins """ amnt = [Coin("ukrw", 1000)] A = MsgSubmitProposal(content=None, initial_deposit=amnt, proposer=acc_address) assert isinstance(A.initial_deposit, Coins) assert A.initial_deposit == amnt
def test_vote_hash(self): msg1 = MsgExchangeRateVote( exchange_rate=Coin("umnt", "603.899000000000000000"), salt="0dff", denom="umnt", feeder="terra13ld7qfuq37328mw6f5kunez3e2ygqumxfcysms", validator="terravaloper1vqnhgc6d0jyggtytzqrnsc40r4zez6tx99382w", ) assert msg1.vote_hash == "b338c8a65a132edcf3e9a13013997cdf1e2b283d"
def test_exchange_rate_wrong_denom(self, acc_address, val_address): """Passing in `exchange_rate` as `Coin` will require both the `Coin.denom` and `denom` parameter to match. """ with pytest.raises(ValidationError): MsgExchangeRateVote( exchange_rate=Coin("ukrw", 1000), salt="", denom="uusd", feeder=acc_address, validator=val_address, ) A = MsgExchangeRateVote( exchange_rate=Coin("ukrw", 1000), salt="", denom="ukrw", feeder=acc_address, validator=val_address, ) assert A.exchange_rate.denom == A.denom
class TestMsgExchangeRateVote: def test_schema_valid(self, msg_examples): for m in msg_examples[MsgExchangeRateVote]: assert_serdes_consistent(MsgExchangeRateVote, m) assert_serdes_exact(MsgExchangeRateVote, m) @pytest.mark.serdes @pytest.mark.slow @settings(suppress_health_check=[ HealthCheck.too_slow, HealthCheck.filter_too_much ]) @given(m=from_schema(MsgExchangeRateVote.__schema__)) def test_serdes_consistent(self, m): assert_serdes_consistent(MsgExchangeRateVote, m) def test_matches_meta(self): assert MsgExchangeRateVote.type == "oracle/MsgExchangeRateVote" assert MsgExchangeRateVote.action == "exchangeratevote" @given(other=st.text()) def test_constructor_validates_addresses(self, acc_address, val_address, other): """MsgExchangeRateVote should validate `feeder` to be AccAddress and `validator` to be ValAddress. """ assume(not is_val_address(other) and not is_acc_address(other)) with pytest.raises(InvalidAccAddress): MsgExchangeRateVote( exchange_rate=Coin("ukrw", 1000), salt="", denom="ukrw", feeder=other, validator=val_address, ) with pytest.raises(InvalidValAddress): MsgExchangeRateVote( exchange_rate=Coin("ukrw", 1000), salt="", denom="ukrw", feeder=acc_address, validator=other, ) A = MsgExchangeRateVote( exchange_rate=Coin("ukrw", 1000), salt="", denom="ukrw", feeder=acc_address, validator=val_address, ) assert A.feeder == acc_address assert A.validator == val_address @pytest.mark.parametrize( "t", [int, Dec, Decimal, str, lambda x: Coin("ukrw", x)]) def test_constructor_canonizes_exchange_rate_to_coin( self, acc_address, val_address, t): A = MsgExchangeRateVote( exchange_rate=t(1000), salt="", denom="ukrw", feeder=acc_address, validator=val_address, ) assert isinstance(A.exchange_rate, Coin) assert A.exchange_rate.denom == "ukrw" def test_exchange_rate_wrong_denom(self, acc_address, val_address): """Passing in `exchange_rate` as `Coin` will require both the `Coin.denom` and `denom` parameter to match. """ with pytest.raises(ValidationError): MsgExchangeRateVote( exchange_rate=Coin("ukrw", 1000), salt="", denom="uusd", feeder=acc_address, validator=val_address, ) A = MsgExchangeRateVote( exchange_rate=Coin("ukrw", 1000), salt="", denom="ukrw", feeder=acc_address, validator=val_address, ) assert A.exchange_rate.denom == A.denom def test_vote_hash(self): msg1 = MsgExchangeRateVote( exchange_rate=Coin("umnt", "603.899000000000000000"), salt="0dff", denom="umnt", feeder="terra13ld7qfuq37328mw6f5kunez3e2ygqumxfcysms", validator="terravaloper1vqnhgc6d0jyggtytzqrnsc40r4zez6tx99382w", ) assert msg1.vote_hash == "b338c8a65a132edcf3e9a13013997cdf1e2b283d"
def make(cls, gas: int = 0, **denoms): amount = Coins() for denom in denoms: amount += Coin(denom, denoms[denom]) return cls(gas=gas, amount=amount)