Skip to content

Commit

Permalink
Remove a couple gov TODOs and fix Tx signing in the msgfees query ser…
Browse files Browse the repository at this point in the history
…ver test. (#2010)

* Properly sign tx data in the msgfees query server tests.

* Remove a couple TODOs that are no longer a concern.
  • Loading branch information
SpicyLemon authored Jun 5, 2024
1 parent cb8fcac commit 30759c2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
3 changes: 1 addition & 2 deletions cmd/provenanced/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,8 @@ func createAndExportGenesisFile(
appGenState[moduleName] = cdc.MustMarshalJSON(&crisisGenState)
}

// Set the gov deposit denom
// Set the gov deposit.
{
// TODO[1760]: gov: Verify that these changes are okay and nothing else is needed.
moduleName := govtypes.ModuleName
var govGenState govtypesv1.GenesisState
cdc.MustUnmarshalJSON(appGenState[moduleName], &govGenState)
Expand Down
3 changes: 1 addition & 2 deletions cmd/provenanced/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,7 @@ func initGenFiles(
crisisGenState.ConstantFee.Denom = chainDenom
appGenState[crisistypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&crisisGenState)

// Set the gov depost denom
// TODO[1760]: gov: Verify that these changes are okay and nothing else is needed.
// Set the gov deposit and shorten the voting period.
var govGenState govtypesv1.GenesisState
clientCtx.Codec.MustUnmarshalJSON(appGenState[govtypes.ModuleName], &govGenState)
govGenState.Params.MinDeposit = sdk.NewCoins(sdk.NewInt64Coin(chainDenom, 10000000))
Expand Down
39 changes: 20 additions & 19 deletions x/msgfees/keeper/query_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
sdksigning "github.com/cosmos/cosmos-sdk/types/tx/signing"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/authz"
banktestutil "github.com/cosmos/cosmos-sdk/x/bank/testutil"
Expand Down Expand Up @@ -202,31 +203,31 @@ func (s *QueryServerTestSuite) createTxFeesRequest(pubKey cryptotypes.PubKey, pr
}
}

func (s *QueryServerTestSuite) signTx(theTx client.TxBuilder, pubKey cryptotypes.PubKey, privKey cryptotypes.PrivKey, acct sdk.AccountI) {
accountSig := sdksigning.SignatureV2{
PubKey: pubKey,
Data: &sdksigning.SingleSignatureData{
SignMode: sdksigning.SignMode(s.cfg.TxConfig.SignModeHandler().DefaultMode()),
},
Sequence: acct.GetSequence(),
}
func (s *QueryServerTestSuite) signTx(txb client.TxBuilder, pubKey cryptotypes.PubKey, privKey cryptotypes.PrivKey, acct sdk.AccountI) {
signerData := signing.SignerData{
ChainID: s.cfg.ChainID,
AccountNumber: acct.GetAccountNumber(),
Sequence: acct.GetSequence(),
}
txData := signing.TxData{} // TODO[1760]: signing: Base this off of theTx.GetTx().
theTx := txb.GetTx()
adaptableTx, ok := theTx.(authsigning.V2AdaptableTx)
s.Require().True(ok, "%T does not implement the authsigning.V2AdaptableTx interface", theTx)

txData := adaptableTx.GetSigningTxData()
signBytes, err := s.cfg.TxConfig.SignModeHandler().GetSignBytes(s.ctx, s.cfg.TxConfig.SignModeHandler().DefaultMode(), signerData, txData)
if err != nil {
panic(err)
}
s.Require().NoError(err, "GetSignBytes")

sig, err := privKey.Sign(signBytes)
if err != nil {
panic(err)
}
accountSig.Data.(*sdksigning.SingleSignatureData).Signature = sig
err = theTx.SetSignatures(accountSig)
if err != nil {
panic(err)
s.Require().NoError(err, "privKey.Sign(signBytes)")

accountSig := sdksigning.SignatureV2{
PubKey: pubKey,
Data: &sdksigning.SingleSignatureData{
SignMode: sdksigning.SignMode(s.cfg.TxConfig.SignModeHandler().DefaultMode()),
Signature: sig,
},
Sequence: acct.GetSequence(),
}
err = txb.SetSignatures(accountSig)
s.Require().NoError(err, "SetSignatures")
}

0 comments on commit 30759c2

Please sign in to comment.