Skip to content

Commit 7657043

Browse files
Problem: multi-sign batch command is not exposed and tested (#422)
1 parent 47e0b6d commit 7657043

File tree

5 files changed

+130
-0
lines changed

5 files changed

+130
-0
lines changed

cmd/chain-maind/app/app.go

+1
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ func txCommand() *cobra.Command {
221221
authcmd.GetSignCommand(),
222222
authcmd.GetSignBatchCommand(),
223223
authcmd.GetMultiSignCommand(),
224+
authcmd.GetMultiSignBatchCmd(),
224225
authcmd.GetValidateSignaturesCommand(),
225226
flags.LineBreak,
226227
authcmd.GetBroadcastCommand(),

integration_tests/configs/default.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ chaintest:
2121
coins: 10000cro
2222
- name: signer2
2323
coins: 2000cro
24+
- name: msigner1
25+
coins: 2000cro
26+
- name: msigner2
27+
coins: 2000cro
2428
genesis:
2529
app_state:
2630
staking:

integration_tests/test_multisig.py

+69
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import json
22

3+
from pystarport import ports
4+
from pystarport.proto_python.api_util import ApiUtil
5+
36
from .utils import wait_for_new_blocks
47

58

@@ -38,3 +41,69 @@ def test_multi_signature(cluster, tmp_path):
3841
assert 125 == multi_balance
3942
# check singer2 balance
4043
assert cluster.balance(signer2_addr) == signer2_balance + 80
44+
45+
46+
def test_multi_signature_batch(cluster, tmp_path):
47+
# prepare files
48+
m_txt = tmp_path / "bm.txt"
49+
p1_txt = tmp_path / "bp1.txt"
50+
p2_txt = tmp_path / "bp2.txt"
51+
tx_txt = tmp_path / "btx.txt"
52+
multi_wallet_name = "multitest2"
53+
54+
# make multi-sig
55+
cluster.make_multisig(multi_wallet_name, "msigner1", "msigner2")
56+
multi_addr = cluster.address(multi_wallet_name)
57+
signer1_addr = cluster.address("msigner1")
58+
signer2_addr = cluster.address("msigner2")
59+
# send amount to multi-sig
60+
cluster.transfer(signer1_addr, multi_addr, "500basecro")
61+
wait_for_new_blocks(cluster, 1)
62+
multi_balance = cluster.balance(multi_addr)
63+
assert 500 == multi_balance
64+
signer1_balance = cluster.balance(signer1_addr)
65+
signer2_balance = cluster.balance(signer2_addr)
66+
# send amount from multisig to signer2
67+
with open(m_txt, "a") as f:
68+
multi_tx = cluster.transfer(
69+
multi_addr, signer1_addr, "100basecro", generate_only=True
70+
)
71+
f.write(json.dumps(multi_tx))
72+
f.write("\n")
73+
multi_tx = cluster.transfer(
74+
multi_addr, signer2_addr, "100basecro", generate_only=True
75+
)
76+
f.write(json.dumps(multi_tx))
77+
78+
# multisign the tx
79+
port = ports.api_port(cluster.base_port(0))
80+
api = ApiUtil(port)
81+
multi_account_info = api.account_info(multi_addr)
82+
account_num = multi_account_info["account_num"]
83+
sequence = multi_account_info["sequence"]
84+
signature2 = cluster.sign_batch_multisig_tx(
85+
m_txt, multi_addr, "msigner1", account_num, sequence
86+
)
87+
with open(p1_txt, "w") as f:
88+
f.write(signature2)
89+
signature3 = cluster.sign_batch_multisig_tx(
90+
m_txt, multi_addr, "msigner2", account_num, sequence
91+
)
92+
with open(p2_txt, "w") as f:
93+
f.write(signature3)
94+
95+
final_multi_tx = cluster.combine_batch_multisig_tx(
96+
m_txt, multi_wallet_name, p1_txt, p2_txt
97+
)
98+
for line in final_multi_tx.splitlines():
99+
with open(tx_txt, "w") as f:
100+
f.write(line)
101+
assert len(line) > 0
102+
cluster.broadcast_tx(tx_txt)
103+
# check multisig balance
104+
multi_balance = cluster.balance(multi_addr)
105+
wait_for_new_blocks(cluster, 4)
106+
assert 300 == multi_balance
107+
# check singer2 balance
108+
assert cluster.balance(signer1_addr) == signer1_balance + 100
109+
assert cluster.balance(signer2_addr) == signer2_balance + 100

pystarport/pystarport/cluster.py

+20
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,9 @@ def staking_params(self, i=0):
340340
def staking_pool(self, bonded=True, i=0):
341341
return self.cosmos_cli(i).staking_pool(bonded)
342342

343+
def transfer_offline(self, from_, to, coins, sequence, i=0, fees=None):
344+
return self.cosmos_cli(i).transfer_offline(from_, to, coins, sequence, fees)
345+
343346
def transfer(self, from_, to, coins, i=0, generate_only=False, fees=None):
344347
return self.cosmos_cli(i).transfer(from_, to, coins, generate_only, fees)
345348

@@ -384,6 +387,13 @@ def make_multisig(self, name, signer1, signer2, i=0):
384387
def sign_multisig_tx(self, tx_file, multi_addr, signer_name, i=0):
385388
return self.cosmos_cli(i).sign_multisig_tx(tx_file, multi_addr, signer_name)
386389

390+
def sign_batch_multisig_tx(
391+
self, tx_file, multi_addr, signer_name, account_num, sequence, i=0
392+
):
393+
return self.cosmos_cli(i).sign_batch_multisig_tx(
394+
tx_file, multi_addr, signer_name, account_num, sequence
395+
)
396+
387397
def encode_signed_tx(self, signed_tx, i=0):
388398
return self.cosmos_cli(i).encode_signed_tx(signed_tx)
389399

@@ -398,6 +408,16 @@ def combine_multisig_tx(self, tx_file, multi_name, signer1_file, signer2_file, i
398408
signer2_file,
399409
)
400410

411+
def combine_batch_multisig_tx(
412+
self, tx_file, multi_name, signer1_file, signer2_file, i=0
413+
):
414+
return self.cosmos_cli(i).combine_batch_multisig_tx(
415+
tx_file,
416+
multi_name,
417+
signer1_file,
418+
signer2_file,
419+
)
420+
401421
def broadcast_tx(self, tx_file, i=0):
402422
return self.cosmos_cli(i).broadcast_tx(tx_file)
403423

pystarport/pystarport/cosmoscli.py

+36
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,25 @@ def sign_multisig_tx(self, tx_file, multi_addr, signer_name):
458458
)
459459
)
460460

461+
def sign_batch_multisig_tx(
462+
self, tx_file, multi_addr, signer_name, account_number, sequence_number
463+
):
464+
r = self.raw(
465+
"tx",
466+
"sign-batch",
467+
"--offline",
468+
tx_file,
469+
account_number=account_number,
470+
sequence=sequence_number,
471+
from_=signer_name,
472+
multisig=multi_addr,
473+
home=self.data_dir,
474+
keyring_backend="test",
475+
chain_id=self.chain_id,
476+
node=self.node_rpc,
477+
)
478+
return r.decode("utf-8")
479+
461480
def encode_signed_tx(self, signed_tx):
462481
return self.raw(
463482
"tx",
@@ -495,6 +514,23 @@ def combine_multisig_tx(self, tx_file, multi_name, signer1_file, signer2_file):
495514
)
496515
)
497516

517+
def combine_batch_multisig_tx(
518+
self, tx_file, multi_name, signer1_file, signer2_file
519+
):
520+
r = self.raw(
521+
"tx",
522+
"multisign-batch",
523+
tx_file,
524+
multi_name,
525+
signer1_file,
526+
signer2_file,
527+
home=self.data_dir,
528+
keyring_backend="test",
529+
chain_id=self.chain_id,
530+
node=self.node_rpc,
531+
)
532+
return r.decode("utf-8")
533+
498534
def broadcast_tx(self, tx_file):
499535
return json.loads(self.raw("tx", "broadcast", tx_file, node=self.node_rpc))
500536

0 commit comments

Comments
 (0)