@@ -5,13 +5,17 @@ package tx_test
5
5
import (
6
6
"context"
7
7
"fmt"
8
+ "strings"
8
9
"testing"
9
10
10
- "github.com/stretchr/testify/suite"
11
-
12
11
"github.com/cosmos/cosmos-sdk/client"
13
12
"github.com/cosmos/cosmos-sdk/client/flags"
14
13
clienttx "github.com/cosmos/cosmos-sdk/client/tx"
14
+ "github.com/cosmos/cosmos-sdk/crypto/hd"
15
+ "github.com/cosmos/cosmos-sdk/crypto/keyring"
16
+ kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
17
+ cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
18
+ "github.com/cosmos/cosmos-sdk/testutil"
15
19
"github.com/cosmos/cosmos-sdk/testutil/network"
16
20
"github.com/cosmos/cosmos-sdk/testutil/testdata"
17
21
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -21,8 +25,10 @@ import (
21
25
"github.com/cosmos/cosmos-sdk/types/tx"
22
26
"github.com/cosmos/cosmos-sdk/types/tx/signing"
23
27
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
28
+ authtest "github.com/cosmos/cosmos-sdk/x/auth/client/testutil"
24
29
bankcli "github.com/cosmos/cosmos-sdk/x/bank/client/testutil"
25
30
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
31
+ "github.com/stretchr/testify/suite"
26
32
)
27
33
28
34
type IntegrationTestSuite struct {
@@ -466,6 +472,96 @@ func (s IntegrationTestSuite) TestBroadcastTx_GRPCGateway() {
466
472
}
467
473
}
468
474
475
+ func (s * IntegrationTestSuite ) TestSimMultiSigTx () {
476
+ val1 := * s .network .Validators [0 ]
477
+
478
+ kr := val1 .ClientCtx .Keyring
479
+
480
+ account1 , _ , err := kr .NewMnemonic ("newAccount1" , keyring .English , sdk .FullFundraiserPath , keyring .DefaultBIP39Passphrase , hd .Secp256k1 )
481
+ s .Require ().NoError (err )
482
+
483
+ account2 , _ , err := kr .NewMnemonic ("newAccount2" , keyring .English , sdk .FullFundraiserPath , keyring .DefaultBIP39Passphrase , hd .Secp256k1 )
484
+ s .Require ().NoError (err )
485
+
486
+ multi := kmultisig .NewLegacyAminoPubKey (2 , []cryptotypes.PubKey {account1 .GetPubKey (), account2 .GetPubKey ()})
487
+ _ , err = kr .SaveMultisig ("multi" , multi )
488
+ s .Require ().NoError (err )
489
+
490
+ _ , err = s .network .WaitForHeight (1 )
491
+ s .Require ().NoError (err )
492
+
493
+ multisigInfo , err := val1 .ClientCtx .Keyring .Key ("multi" )
494
+ s .Require ().NoError (err )
495
+
496
+ height , err := s .network .LatestHeight ()
497
+ _ , err = s .network .WaitForHeight (height + 1 )
498
+ s .Require ().NoError (err )
499
+
500
+ // Send coins from validator to multisig.
501
+ coins := sdk .NewInt64Coin (s .cfg .BondDenom , 15 )
502
+ _ , err = bankcli .MsgSendExec (
503
+ val1 .ClientCtx ,
504
+ val1 .Address ,
505
+ multisigInfo .GetAddress (),
506
+ sdk .NewCoins (coins ),
507
+ fmt .Sprintf ("--%s=true" , flags .FlagSkipConfirmation ),
508
+ fmt .Sprintf ("--%s=%s" , flags .FlagBroadcastMode , flags .BroadcastBlock ),
509
+ fmt .Sprintf ("--%s=%s" , flags .FlagFees , sdk .NewCoins (sdk .NewCoin (s .cfg .BondDenom , sdk .NewInt (10 ))).String ()),
510
+ fmt .Sprintf ("--gas=%d" , flags .DefaultGasLimit ),
511
+ )
512
+
513
+ height , err = s .network .LatestHeight ()
514
+ _ , err = s .network .WaitForHeight (height + 1 )
515
+ s .Require ().NoError (err )
516
+
517
+ // Generate multisig transaction.
518
+ multiGeneratedTx , err := bankcli .MsgSendExec (
519
+ val1 .ClientCtx ,
520
+ multisigInfo .GetAddress (),
521
+ val1 .Address ,
522
+ sdk .NewCoins (
523
+ sdk .NewInt64Coin (s .cfg .BondDenom , 5 ),
524
+ ),
525
+ fmt .Sprintf ("--%s=true" , flags .FlagSkipConfirmation ),
526
+ fmt .Sprintf ("--%s=%s" , flags .FlagBroadcastMode , flags .BroadcastBlock ),
527
+ fmt .Sprintf ("--%s=%s" , flags .FlagFees , sdk .NewCoins (sdk .NewCoin (s .cfg .BondDenom , sdk .NewInt (10 ))).String ()),
528
+ fmt .Sprintf ("--%s=true" , flags .FlagGenerateOnly ),
529
+ fmt .Sprintf ("--%s=foobar" , flags .FlagMemo ),
530
+ )
531
+ s .Require ().NoError (err )
532
+
533
+ // Save tx to file
534
+ multiGeneratedTxFile := testutil .WriteToNewTempFile (s .T (), multiGeneratedTx .String ())
535
+
536
+ // Sign with account1
537
+ val1 .ClientCtx .HomeDir = strings .Replace (val1 .ClientCtx .HomeDir , "simd" , "simcli" , 1 )
538
+ account1Signature , err := authtest .TxSignExec (val1 .ClientCtx , account1 .GetAddress (), multiGeneratedTxFile .Name (), "--multisig" , multisigInfo .GetAddress ().String ())
539
+ s .Require ().NoError (err )
540
+ sign1File := testutil .WriteToNewTempFile (s .T (), account1Signature .String ())
541
+
542
+ // Sign with account2
543
+ account2Signature , err := authtest .TxSignExec (val1 .ClientCtx , account2 .GetAddress (), multiGeneratedTxFile .Name (), "--multisig" , multisigInfo .GetAddress ().String ())
544
+ s .Require ().NoError (err )
545
+ sign2File := testutil .WriteToNewTempFile (s .T (), account2Signature .String ())
546
+
547
+ // multisign tx
548
+ val1 .ClientCtx .Offline = false
549
+ multiSigWith2Signatures , err := authtest .TxMultiSignExec (val1 .ClientCtx , multisigInfo .GetName (), multiGeneratedTxFile .Name (), sign1File .Name (), sign2File .Name ())
550
+ s .Require ().NoError (err )
551
+
552
+ // convert from protoJSON to protoBinary for sim
553
+ sdkTx , err := val1 .ClientCtx .TxConfig .TxJSONDecoder ()(multiSigWith2Signatures .Bytes ())
554
+ txBytes , err := val1 .ClientCtx .TxConfig .TxEncoder ()(sdkTx )
555
+
556
+ // simulate tx
557
+ sim := & tx.SimulateRequest {TxBytes : txBytes }
558
+ res , err := s .queryClient .Simulate (context .Background (), sim )
559
+ s .Require ().NoError (err )
560
+
561
+ // make sure gas was used
562
+ s .Require ().Greater (res .GasInfo .GasUsed , uint64 (0 ))
563
+ }
564
+
469
565
func TestIntegrationTestSuite (t * testing.T ) {
470
566
suite .Run (t , new (IntegrationTestSuite ))
471
567
}
0 commit comments