Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: multisig account failed on threshold encode after send tx #532

Merged
merged 5 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,10 @@ require (

replace (
// release/v0.50.x
cosmossdk.io/client/v2 => github.com/crypto-org-chain/cosmos-sdk/client/v2 v2.0.0-20240911084450-6870ba130be2
cosmossdk.io/store => github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20240911084450-6870ba130be2
cosmossdk.io/x/tx => github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20240911084450-6870ba130be2
github.com/cosmos/cosmos-sdk => github.com/crypto-org-chain/cosmos-sdk v0.50.6-0.20240911084450-6870ba130be2
cosmossdk.io/client/v2 => github.com/crypto-org-chain/cosmos-sdk/client/v2 v2.0.0-20240927054437-c2a1e0678f4b
cosmossdk.io/store => github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20240927054437-c2a1e0678f4b
cosmossdk.io/x/tx => github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20240927054437-c2a1e0678f4b
github.com/cosmos/cosmos-sdk => github.com/crypto-org-chain/cosmos-sdk v0.50.6-0.20240927054437-c2a1e0678f4b
)

replace (
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,14 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/crypto-org-chain/btree v0.0.0-20240406140148-2687063b042c h1:MOgfS4+FBB8cMkDE2j2VBVsbY+HCkPIu0YsJ/9bbGeQ=
github.com/crypto-org-chain/btree v0.0.0-20240406140148-2687063b042c/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY=
github.com/crypto-org-chain/cosmos-sdk v0.50.6-0.20240911084450-6870ba130be2 h1:4SoAvnxDaiIWcgm6XOmPDIdCf4/WNhNYLXGbij1eaA0=
github.com/crypto-org-chain/cosmos-sdk v0.50.6-0.20240911084450-6870ba130be2/go.mod h1:Rb43DdB0i/rKcCN69Tg2X3+zA4WhJ7MC8K3a6Ezh38E=
github.com/crypto-org-chain/cosmos-sdk/client/v2 v2.0.0-20240911084450-6870ba130be2 h1:5oGZtOUcauk9dtv+8BCfj2PEQyXEEEV+K3sP4OSvBmg=
github.com/crypto-org-chain/cosmos-sdk/client/v2 v2.0.0-20240911084450-6870ba130be2/go.mod h1:W5sR4asmVDUhJpEmuXTUBkk/yEefKlXTjVWcNciVSR0=
github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20240911084450-6870ba130be2 h1:CGh5I0L6IYhe0AJevb4vf5TE3ru+qAgMs437BlWCwo8=
github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20240911084450-6870ba130be2/go.mod h1:gjE3DZe4t/+VeIk6CmrouyqiuDbZ7QOVDDq3nLqBTpg=
github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20240911084450-6870ba130be2 h1:mxlOSCru7YgmX055rrlkCSUu0D8lAqJ8Dnhp0yXCBuM=
github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20240911084450-6870ba130be2/go.mod h1:RTiTs4hkXG6IvYGknvB8p79YgjYJdcbzLUOGJChsPnY=
github.com/crypto-org-chain/cosmos-sdk v0.50.6-0.20240927054437-c2a1e0678f4b h1:praAPgsPxIr/bcnUalyH6i+VG7o4tbNc5hhqJsUVBEU=
github.com/crypto-org-chain/cosmos-sdk v0.50.6-0.20240927054437-c2a1e0678f4b/go.mod h1:Rb43DdB0i/rKcCN69Tg2X3+zA4WhJ7MC8K3a6Ezh38E=
github.com/crypto-org-chain/cosmos-sdk/client/v2 v2.0.0-20240927054437-c2a1e0678f4b h1:fBJcK1IbrS/GKfPAKNFBdm2aY59Zuruop+8jf2dOFP4=
github.com/crypto-org-chain/cosmos-sdk/client/v2 v2.0.0-20240927054437-c2a1e0678f4b/go.mod h1:W5sR4asmVDUhJpEmuXTUBkk/yEefKlXTjVWcNciVSR0=
github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20240927054437-c2a1e0678f4b h1:DsLD76+ndjkh/yIXD3l9t0l+6H8ZLUK7d8q3Avi3gEo=
github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20240927054437-c2a1e0678f4b/go.mod h1:gjE3DZe4t/+VeIk6CmrouyqiuDbZ7QOVDDq3nLqBTpg=
github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20240927054437-c2a1e0678f4b h1:qwJufXFJ8dt+swi5p8SmTgLTr9ClHIO9GZh1XlO78mE=
github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20240927054437-c2a1e0678f4b/go.mod h1:RTiTs4hkXG6IvYGknvB8p79YgjYJdcbzLUOGJChsPnY=
github.com/crypto-org-chain/go-block-stm v0.0.0-20240912024944-1cd89976aa5e h1:FFpE6+Y4o5GxkeGwUcETM6amgohh7msWvWf1MDqueVc=
github.com/crypto-org-chain/go-block-stm v0.0.0-20240912024944-1cd89976aa5e/go.mod h1:iwQTX9xMX8NV9k3o2BiWXA0SswpsZrDk5q3gA7nWYiE=
github.com/crypto-org-chain/go-ethereum v1.10.20-0.20240925072350-e05e994a492f h1:jR3nEDZMhGtZODqWFVbaTJ2X26k5r7nkiRk39i+SJ10=
Expand Down
12 changes: 6 additions & 6 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ schema = 3
version = "v0.7.5"
hash = "sha256-Nuw697sJr56kU3EU7DV1eYNkyI76psznIVqYAV6RfbQ="
[mod."cosmossdk.io/client/v2"]
version = "v2.0.0-20240911084450-6870ba130be2"
version = "v2.0.0-20240927054437-c2a1e0678f4b"
hash = "sha256-60hmufv3Ml4Pv3zNwgn8eeqlEINOR6n9MKr2QHddoxo="
replaced = "github.com/crypto-org-chain/cosmos-sdk/client/v2"
[mod."cosmossdk.io/collections"]
Expand All @@ -42,7 +42,7 @@ schema = 3
version = "v1.3.0"
hash = "sha256-EEFK43Cr0g0ndhQhkIKher0FqV3mvkmE9z0sP7uVSHg="
[mod."cosmossdk.io/store"]
version = "v0.0.0-20240911084450-6870ba130be2"
version = "v0.0.0-20240927054437-c2a1e0678f4b"
hash = "sha256-Dm3sSZNJBcnBF33PULoTpK4rkNQbsZl0DfTqH1GPCQM="
replaced = "github.com/crypto-org-chain/cosmos-sdk/store"
[mod."cosmossdk.io/tools/confix"]
Expand All @@ -55,8 +55,8 @@ schema = 3
version = "v0.1.0"
hash = "sha256-/gWvrqvy6bW90+NU66T+9QysYgvG1VbwfYJZ8tkqpeA="
[mod."cosmossdk.io/x/tx"]
version = "v0.0.0-20240911084450-6870ba130be2"
hash = "sha256-xT5IdapEx1h46ofBpxcBQfzGF2EntmC8xZl7aym/6xE="
version = "v0.0.0-20240927054437-c2a1e0678f4b"
hash = "sha256-5HPcm3oCWAC9oKOGMP+PVMdCPF7ELVHmxpN1FasUgAY="
replaced = "github.com/crypto-org-chain/cosmos-sdk/x/tx"
[mod."cosmossdk.io/x/upgrade"]
version = "v0.1.1"
Expand Down Expand Up @@ -163,8 +163,8 @@ schema = 3
version = "v1.0.0-beta.5"
hash = "sha256-Fy/PbsOsd6iq0Njy3DVWK6HqWsogI+MkE8QslHGWyVg="
[mod."github.com/cosmos/cosmos-sdk"]
version = "v0.50.6-0.20240911084450-6870ba130be2"
hash = "sha256-kl2sLe8vITIguRGtdeviDeP3R5JIbRg+eDsheGd4PqM="
version = "v0.50.6-0.20240927054437-c2a1e0678f4b"
hash = "sha256-/5W/4n6getoWtj/MIotvel86dcJUD7jm9a4aDdDD95w="
replaced = "github.com/crypto-org-chain/cosmos-sdk"
[mod."github.com/cosmos/go-bip39"]
version = "v1.0.0"
Expand Down
64 changes: 61 additions & 3 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 @@ -498,9 +513,12 @@ def combine_batch_multisig_tx(
def broadcast_tx(self, tx_file, **kwargs):
kwargs.setdefault("broadcast_mode", "sync")
kwargs.setdefault("output", "json")
return json.loads(
rsp = json.loads(
self.raw("tx", "broadcast", tx_file, node=self.node_rpc, **kwargs)
)
if rsp["code"] == 0:
rsp = self.event_query_tx_for(rsp["txhash"])
return rsp

def broadcast_tx_json(self, tx, **kwargs):
with tempfile.NamedTemporaryFile("w") as fp:
Expand Down Expand Up @@ -857,3 +875,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
47 changes: 47 additions & 0 deletions tests/integration_tests/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,50 @@ 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")
denom = "aphoton"
amt = 2000000000000000000
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)["account"]["value"]["base_account"]
res = cli.account_by_num(acc["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
signer2 = cli.address("signer2")
multi_tx = cli.transfer(
multi_addr,
signer2,
f"{amt}{denom}",
generate_only=True,
)
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"]
assert (
cli.account(multi_addr)["account"]["value"]["base_account"]["address"]
== acc["address"]
)
21 changes: 20 additions & 1 deletion types/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/suite"

"cosmossdk.io/x/tx/signing/aminojson"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

cryptocodec "github.com/evmos/ethermint/crypto/codec"
"github.com/evmos/ethermint/crypto/ethsecp256k1"
ethermintcodec "github.com/evmos/ethermint/encoding/codec"
"github.com/evmos/ethermint/types"
ethermint "github.com/evmos/ethermint/types"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/anypb"
)

func init() {
Expand Down Expand Up @@ -56,3 +59,19 @@ func (suite *AccountTestSuite) TestAccountType() {
suite.account.CodeHash = common.BytesToHash(crypto.Keccak256([]byte{1, 2, 3})).Hex()
suite.Require().Equal(types.AccountTypeContract, suite.account.Type())
}

func TestAminoMarshal(t *testing.T) {
registry := codectypes.NewInterfaceRegistry()
ethermint.RegisterInterfaces(registry)
value := "\n\x86\x02\n+tcrc1l8h07yxmwvc963tg08at7k9882d5ha4t34guxe\x12\xd2\x01\n)/cosmos.crypto.multisig.LegacyAminoPubKey\x12\xa4\x01\x08\x02\x12O\n(/ethermint.crypto.v1.ethsecp256k1.PubKey\x12#\n!\x03һ\xfb\x81\x1a\xb40E\xc0\x16\xf4\x17\xfba\xe5V\x10\xfd]\x8d\x19m\x08\xe0\xc6i\x83\xf9S\x9e\x1b\xd8\x12O\n(/ethermint.crypto.v1.ethsecp256k1.PubKey\x12#\n!\x02\x19]\xed\xa5\x84:\xae\xa2\x0fȌ\xb6MKR\xfc\xc5\xc8SD1\x0cSn\x83|P\xad'\xf7\xa8\x8d\x18\x12 \x02\x12B0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
msg := &anypb.Any{
TypeUrl: "/ethermint.types.v1.EthAccount",
Value: []byte(value),
}
aj := aminojson.NewEncoder(aminojson.EncoderOptions{
FileResolver: registry,
Indent: " ",
})
_, err := aj.Marshal(msg)
require.NoError(t, err)
}
Loading