-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Add test with Multi Signers into Robert's TxSign PR #8142
Changes from 1 commit
415b563
ff2acda
97bfbb4
6179476
d2b3d2c
59db0c1
81ababb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,7 @@ func (s *IntegrationTestSuite) SetupSuite() { | |
s.T().Log("setting up integration test suite") | ||
|
||
cfg := network.DefaultConfig() | ||
cfg.NumValidators = 1 | ||
cfg.NumValidators = 2 | ||
|
||
s.cfg = cfg | ||
s.network = network.New(s.T(), cfg) | ||
|
@@ -1024,6 +1024,61 @@ func (s *IntegrationTestSuite) createBankMsg(val *network.Validator, toAddr sdk. | |
return res | ||
} | ||
|
||
func (s *IntegrationTestSuite) TestSignWithMultiSigners() { | ||
val0, val1 := s.network.Validators[0], s.network.Validators[1] | ||
val0Coin := sdk.NewCoin(fmt.Sprintf("%stoken", val0.Moniker), sdk.NewInt(10)) | ||
val1Coin := sdk.NewCoin(fmt.Sprintf("%stoken", val1.Moniker), sdk.NewInt(10)) | ||
_, _, addr1 := testdata.KeyTestPubAddr() | ||
|
||
// Creating a tx with 2 msgs from 2 signers: val0 and val1. | ||
txBuilder := val0.ClientCtx.TxConfig.NewTxBuilder() | ||
txBuilder.SetMsgs( | ||
banktypes.NewMsgSend(val0.Address, addr1, sdk.NewCoins(val0Coin)), | ||
banktypes.NewMsgSend(val1.Address, addr1, sdk.NewCoins(val1Coin)), | ||
) | ||
txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10)))) | ||
txBuilder.SetGasLimit(testdata.NewTestGasLimit()) | ||
// Set signer_infos for both signers. Note: we use the empty signature hack. | ||
// TODO | ||
s.Require().Equal([]sdk.AccAddress{val0.Address, val1.Address}, txBuilder.GetTx().GetSigners()) | ||
|
||
// Write the unsigned tx into a file. | ||
txJSON, err := val0.ClientCtx.TxConfig.TxJSONEncoder()(txBuilder.GetTx()) | ||
amaury1093 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
s.Require().NoError(err) | ||
unsignedTxFile := testutil.WriteToNewTempFile(s.T(), string(txJSON)) | ||
|
||
// Let val0 sign first the file with the unsignedTx. | ||
signedByVal0, err := authtest.TxSignExec(val0.ClientCtx, val0.Address, unsignedTxFile.Name(), "--overwrite") | ||
s.Require().NoError(err) | ||
signedByVal0File := testutil.WriteToNewTempFile(s.T(), signedByVal0.String()) | ||
amaury1093 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Then let val1 sign the file with signedByVal0. | ||
val1AccNum, val1Seq, err := val0.ClientCtx.AccountRetriever.GetAccountNumberSequence(val0.ClientCtx, val1.Address) | ||
s.Require().NoError(err) | ||
signedTx, err := authtest.TxSignExec( | ||
val1.ClientCtx, val1.Address, signedByVal0File.Name(), | ||
"--offline", fmt.Sprintf("--account-number=%d", val1AccNum), fmt.Sprintf("--sequence=%d", val1Seq)) | ||
s.Require().NoError(err) | ||
signedTxFile := testutil.WriteToNewTempFile(s.T(), signedTx.String()) | ||
amaury1093 marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The most anticipated test is:
Note: here the Relayer is a test. |
||
|
||
// Now let's try to send this tx. | ||
amaury1093 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
res, err := authtest.TxBroadcastExec(val0.ClientCtx, signedTxFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock)) | ||
s.Require().NoError(err) | ||
var txRes sdk.TxResponse | ||
s.Require().NoError(val0.ClientCtx.JSONMarshaler.UnmarshalJSON(res.Bytes(), &txRes)) | ||
s.Require().Equal(uint32(0), txRes.Code) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tx fails, because sig verification for val0's signature is wrong. |
||
|
||
// Make sure the addr1's balance got funded. | ||
queryResJSON, err := bankcli.QueryBalancesExec(val0.ClientCtx, addr1) | ||
s.Require().NoError(err) | ||
var queryRes banktypes.QueryAllBalancesResponse | ||
err = val0.ClientCtx.JSONMarshaler.UnmarshalJSON(queryResJSON.Bytes(), &queryRes) | ||
s.Require().NoError(err) | ||
s.Require().Equal(sdk.NewCoins(val0Coin, val1Coin), queryRes.Balances) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not declaring
|
||
|
||
s.Require().False(true) | ||
} | ||
|
||
func TestIntegrationTestSuite(t *testing.T) { | ||
suite.Run(t, new(IntegrationTestSuite)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forgetting the second line is error prone. We should have a single function for doing this. (idea for a new task)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#8149