Skip to content

Commit

Permalink
test multisig
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Sep 26, 2024
1 parent 3721b02 commit f2181f7
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tests/integration_tests/configs/default.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
mnemonic: '${COMMUNITY_MNEMONIC}',
}, {
name: 'signer1',
coins: '20000000000000000000000aphoton',
coins: '100multi,20000000000000000000000aphoton',
mnemonic: '${SIGNER1_MNEMONIC}',
}, {
name: 'signer2',
Expand Down
59 changes: 57 additions & 2 deletions tests/integration_tests/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,18 @@ def account(self, addr):
)
)

def account_by_num(self, num):
return json.loads(
self.raw(
"q",
"auth",
"address-by-acc-num",
num,
output="json",
node=self.node_rpc,
)
)

def tx_search(self, events: str):
"/tx_search"
return json.loads(
Expand Down Expand Up @@ -264,7 +276,7 @@ def staking_pool(self, bonded=True):

def transfer(self, from_, to, coins, generate_only=False, **kwargs):
kwargs.setdefault("gas_prices", DEFAULT_GAS_PRICE)
return json.loads(
rsp = json.loads(
self.raw(
"tx",
"bank",
Expand All @@ -278,6 +290,9 @@ def transfer(self, from_, to, coins, generate_only=False, **kwargs):
**kwargs,
)
)
if not generate_only and rsp["code"] == 0:
rsp = self.event_query_tx_for(rsp["txhash"])
return rsp

def get_delegated_amount(self, which_addr):
return json.loads(
Expand Down Expand Up @@ -384,7 +399,7 @@ def withdraw_all_rewards(self, from_delegator):
)

def make_multisig(self, name, signer1, signer2):
self.raw(
return self.raw(
"keys",
"add",
name,
Expand Down Expand Up @@ -857,3 +872,43 @@ def submit_gov_proposal(self, proposal, **kwargs):
**(default_kwargs | kwargs),
)
)

def query_grant(self, granter, grantee):
"query grant details by granter and grantee addresses"
res = json.loads(
self.raw(
"query",
"feegrant",
"grant",
granter,
grantee,
home=self.data_dir,
node=self.node_rpc,
output="json",
)
)
res = res.get("allowance") or res
return res

def grant(self, granter, grantee, limit, **kwargs):
default_kwargs = self.get_default_kwargs()
rsp = json.loads(
self.raw(
"tx",
"feegrant",
"grant",
granter,
grantee,
"--period",
"60",
"--period-limit",
limit,
"-y",
home=self.data_dir,
stderr=subprocess.DEVNULL,
**(default_kwargs | kwargs),
)
)
if rsp["code"] == 0:
rsp = self.event_query_tx_for(rsp["txhash"])
return rsp
53 changes: 53 additions & 0 deletions tests/integration_tests/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,56 @@ def test_batch_tx(ethermint):
txs = w3.eth.get_block(receipts[0].blockNumber, True).transactions
for i in range(3):
assert txs[i].transactionIndex == i


def test_multisig(ethermint, tmp_path):
cli = ethermint.cosmos_cli()
cli.make_multisig("multitest1", "signer1", "signer2")
multi_addr = cli.address("multitest1")
signer1 = cli.address("signer1")
signer2 = cli.address("signer2")
max_gas = 1000000
gas_price = 10000000000000000
limit = f"{max_gas*gas_price*2}aphoton"
rsp = cli.grant(signer1, multi_addr, limit)
assert rsp["code"] == 0, rsp["raw_log"]
grant_detail = cli.query_grant(signer1, multi_addr)
assert grant_detail["granter"] == signer1
assert grant_detail["grantee"] == multi_addr

denom = "multi"
amt = 10
rsp = cli.transfer(signer1, multi_addr, f"{amt}{denom}")
assert rsp["code"] == 0, rsp["raw_log"]
assert cli.balance(multi_addr, denom=denom) == amt

acc = cli.account(multi_addr)
res = cli.account_by_num(acc["account"]["value"]["base_account"]["account_number"])
assert res["account_address"] == multi_addr

m_txt = tmp_path / "m.txt"
p1_txt = tmp_path / "p1.txt"
p2_txt = tmp_path / "p2.txt"
tx_txt = tmp_path / "tx.txt"
amt = 1
multi_tx = cli.transfer(
multi_addr,
signer2,
f"{amt}{denom}",
generate_only=True,
fee_granter=signer1,
)
json.dump(multi_tx, m_txt.open("w"))
signature1 = cli.sign_multisig_tx(m_txt, multi_addr, "signer1")
json.dump(signature1, p1_txt.open("w"))
signature2 = cli.sign_multisig_tx(m_txt, multi_addr, "signer2")
json.dump(signature2, p2_txt.open("w"))
final_multi_tx = cli.combine_multisig_tx(
m_txt,
"multitest1",
p1_txt,
p2_txt,
)
json.dump(final_multi_tx, tx_txt.open("w"))
rsp = cli.broadcast_tx(tx_txt)
assert rsp["code"] == 0, rsp["raw_log"]

0 comments on commit f2181f7

Please sign in to comment.