forked from crypto-org-chain/chain-main
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_fee_payer.py
51 lines (40 loc) · 1.7 KB
/
test_fee_payer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import json
import pytest
from .utils import sign_single_tx_with_options
pytestmark = pytest.mark.normal
def test_different_fee_payer(cluster, tmp_path):
transaction_coins = 100
fee_coins = 1
receiver_addr = cluster.address("community")
sender_addr = cluster.address("signer1")
fee_payer_addr = cluster.address("signer2")
unsigned_tx_txt = tmp_path / "unsigned_tx.txt"
partial_sign_txt = tmp_path / "partial_sign.txt"
signed_txt = tmp_path / "signed.txt"
receiver_balance = cluster.balance(receiver_addr)
sender_balance = cluster.balance(sender_addr)
fee_payer_balance = cluster.balance(fee_payer_addr)
unsigned_tx_msg = cluster.transfer(
sender_addr,
receiver_addr,
"%sbasecro" % transaction_coins,
generate_only=True,
fees="%sbasecro" % fee_coins,
)
unsigned_tx_msg["auth_info"]["fee"]["payer"] = fee_payer_addr
with open(unsigned_tx_txt, "w") as opened_file:
json.dump(unsigned_tx_msg, opened_file)
partial_sign_tx_msg = sign_single_tx_with_options(
cluster, unsigned_tx_txt, "signer1", sign_mode="amino-json"
)
with open(partial_sign_txt, "w") as opened_file:
json.dump(partial_sign_tx_msg, opened_file)
signed_tx_msg = sign_single_tx_with_options(
cluster, partial_sign_txt, "signer2", sign_mode="amino-json"
)
with open(signed_txt, "w") as opened_file:
json.dump(signed_tx_msg, opened_file)
cluster.broadcast_tx(signed_txt)
assert cluster.balance(receiver_addr) == receiver_balance + transaction_coins
assert cluster.balance(sender_addr) == sender_balance - transaction_coins
assert cluster.balance(fee_payer_addr) == fee_payer_balance - fee_coins