Skip to content

Commit

Permalink
(feat) Refactored composer unit tests to always compare the construct…
Browse files Browse the repository at this point in the history
…ed message in JSON representation
  • Loading branch information
aarmoa committed Jul 5, 2024
1 parent c513f80 commit 987f25b
Showing 1 changed file with 91 additions and 29 deletions.
120 changes: 91 additions & 29 deletions tests/test_composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,18 @@ def test_msg_create_denom(self, basic_composer: Composer):
symbol=symbol,
)

assert message.sender == sender
assert message.subdenom == subdenom
assert message.name == name
assert message.symbol == symbol
expected_message = {
"sender": sender,
"subdenom": subdenom,
"name": name,
"symbol": symbol,
}
dict_message = json_format.MessageToDict(
message=message,
always_print_fields_with_no_presence=True,
)

assert dict_message == expected_message

def test_msg_mint(self, basic_composer: Composer):
sender = "inj1apmvarl2xyv6kecx2ukkeymddw3we4zkygjyc0"
Expand All @@ -86,8 +94,19 @@ def test_msg_mint(self, basic_composer: Composer):
amount=amount,
)

assert message.sender == sender
assert message.amount == amount
expected_message = {
"sender": sender,
"amount": {
"amount": str(amount.amount),
"denom": amount.denom,
},
}
dict_message = json_format.MessageToDict(
message=message,
always_print_fields_with_no_presence=True,
)

assert dict_message == expected_message

def test_msg_burn(self, basic_composer: Composer):
sender = "inj1apmvarl2xyv6kecx2ukkeymddw3we4zkygjyc0"
Expand All @@ -101,8 +120,19 @@ def test_msg_burn(self, basic_composer: Composer):
amount=amount,
)

assert message.sender == sender
assert message.amount == amount
expected_message = {
"sender": sender,
"amount": {
"amount": str(amount.amount),
"denom": amount.denom,
},
}
dict_message = json_format.MessageToDict(
message=message,
always_print_fields_with_no_presence=True,
)

assert dict_message == expected_message

def test_msg_set_denom_metadata(self, basic_composer: Composer):
sender = "inj1apmvarl2xyv6kecx2ukkeymddw3we4zkygjyc0"
Expand All @@ -127,20 +157,36 @@ def test_msg_set_denom_metadata(self, basic_composer: Composer):
uri_hash=uri_hash,
)

assert message.sender == sender
assert message.metadata.description == description
assert message.metadata.denom_units[0].denom == denom
assert message.metadata.denom_units[0].exponent == 0
assert message.metadata.denom_units[0].aliases == [f"micro{subdenom}"]
assert message.metadata.denom_units[1].denom == subdenom
assert message.metadata.denom_units[1].exponent == token_decimals
assert message.metadata.denom_units[1].aliases == [subdenom]
assert message.metadata.base == denom
assert message.metadata.display == subdenom
assert message.metadata.name == name
assert message.metadata.symbol == symbol
assert message.metadata.uri == uri
assert message.metadata.uri_hash == uri_hash
expected_message = {
"sender": sender,
"metadata": {
"base": denom,
"denomUnits": [
{
"denom": denom,
"exponent": 0,
"aliases": [f"micro{subdenom}"],
},
{
"denom": subdenom,
"exponent": token_decimals,
"aliases": [subdenom],
},
],
"description": description,
"name": name,
"symbol": symbol,
"display": subdenom,
"uri": uri,
"uriHash": uri_hash,
},
}
dict_message = json_format.MessageToDict(
message=message,
always_print_fields_with_no_presence=True,
)

assert dict_message == expected_message

def test_msg_change_admin(self, basic_composer):
sender = "inj1apmvarl2xyv6kecx2ukkeymddw3we4zkygjyc0"
Expand All @@ -153,9 +199,17 @@ def test_msg_change_admin(self, basic_composer):
new_admin=new_admin,
)

assert message.sender == sender
assert message.denom == denom
assert message.new_admin == new_admin
expected_message = {
"sender": sender,
"denom": denom,
"newAdmin": new_admin,
}
dict_message = json_format.MessageToDict(
message=message,
always_print_fields_with_no_presence=True,
)

assert dict_message == expected_message

def test_msg_execute_contract_compat(self, basic_composer):
sender = "inj1apmvarl2xyv6kecx2ukkeymddw3we4zkygjyc0"
Expand All @@ -170,10 +224,18 @@ def test_msg_execute_contract_compat(self, basic_composer):
funds=funds,
)

assert message.sender == sender
assert message.contract == contract
assert message.msg == msg
assert message.funds == funds
expected_message = {
"sender": sender,
"contract": contract,
"msg": msg,
"funds": funds,
}
dict_message = json_format.MessageToDict(
message=message,
always_print_fields_with_no_presence=True,
)

assert dict_message == expected_message

def test_msg_deposit(self, basic_composer):
sender = "inj1apmvarl2xyv6kecx2ukkeymddw3we4zkygjyc0"
Expand Down

0 comments on commit 987f25b

Please sign in to comment.