* wip * wip * wip * wip on refactoring adr 031 type URLs * Fix msg_service_router * Fix gov client queries * Fix some modules tests * Remove all instances of "*.Msg/*" * Uncomment code * Remove commented code * // simulation.NewWeightedOperation( * Fix CopyTx * Fix more tests * Fix x/gov test * proto.MessageName->sdk.MsgName * Fix authz tests * Use MsgRoute in feegrant and staking/authz * Fix more tests * Fix sims? * Add norace tag * Add CL * rebuild rosetta api test data * Update ADR * Rename MsgRoute -> MsgTypeURL * Fix codec registration * Remove sdk.GetLegacySignBytes * Update types/tx_msg.go * Update x/authz/simulation/operations.go * Move LegacyMsg to legacytx * Update CHANGELOG.md Co-authored-by: Aaron Craelius <aaron@regen.network> * Remove NewAnyWithCustomTypeURL * Keep support for ServiceMsgs * Fix TxBody UnpackInterfaces * Fix test * Address review * Remove support for ServiceMsg typeURLs * Fix lint * Update changelog * Fix tests * Use sdk.MsgTypeURL everywhere * Fix tests * Fix rosetta, run make rosetta-data * Fix rosetta thanks to froydi * Address reviews * Fix test * Remove stray log * Update CL Co-authored-by: Aaron Craelius <aaronc@users.noreply.github.com> Co-authored-by: Alessio Treglia <alessio@tendermint.com> Co-authored-by: Aaron Craelius <aaron@regen.network>
123 lines
3.7 KiB
Go
123 lines
3.7 KiB
Go
package baseapp_test
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
"github.com/tendermint/tendermint/libs/log"
|
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
|
dbm "github.com/tendermint/tm-db"
|
|
|
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
|
"github.com/cosmos/cosmos-sdk/client/tx"
|
|
"github.com/cosmos/cosmos-sdk/simapp"
|
|
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
|
"github.com/cosmos/cosmos-sdk/types/tx/signing"
|
|
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
|
|
)
|
|
|
|
func TestRegisterMsgService(t *testing.T) {
|
|
db := dbm.NewMemDB()
|
|
|
|
// Create an encoding config that doesn't register testdata Msg services.
|
|
encCfg := simapp.MakeTestEncodingConfig()
|
|
app := baseapp.NewBaseApp("test", log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, encCfg.TxConfig.TxDecoder())
|
|
app.SetInterfaceRegistry(encCfg.InterfaceRegistry)
|
|
require.Panics(t, func() {
|
|
testdata.RegisterMsgServer(
|
|
app.MsgServiceRouter(),
|
|
testdata.MsgServerImpl{},
|
|
)
|
|
})
|
|
|
|
// Register testdata Msg services, and rerun `RegisterService`.
|
|
testdata.RegisterInterfaces(encCfg.InterfaceRegistry)
|
|
require.NotPanics(t, func() {
|
|
testdata.RegisterMsgServer(
|
|
app.MsgServiceRouter(),
|
|
testdata.MsgServerImpl{},
|
|
)
|
|
})
|
|
}
|
|
|
|
func TestRegisterMsgServiceTwice(t *testing.T) {
|
|
// Setup baseapp.
|
|
db := dbm.NewMemDB()
|
|
encCfg := simapp.MakeTestEncodingConfig()
|
|
app := baseapp.NewBaseApp("test", log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, encCfg.TxConfig.TxDecoder())
|
|
app.SetInterfaceRegistry(encCfg.InterfaceRegistry)
|
|
testdata.RegisterInterfaces(encCfg.InterfaceRegistry)
|
|
|
|
// First time registering service shouldn't panic.
|
|
require.NotPanics(t, func() {
|
|
testdata.RegisterMsgServer(
|
|
app.MsgServiceRouter(),
|
|
testdata.MsgServerImpl{},
|
|
)
|
|
})
|
|
|
|
// Second time should panic.
|
|
require.Panics(t, func() {
|
|
testdata.RegisterMsgServer(
|
|
app.MsgServiceRouter(),
|
|
testdata.MsgServerImpl{},
|
|
)
|
|
})
|
|
}
|
|
|
|
func TestMsgService(t *testing.T) {
|
|
priv, _, _ := testdata.KeyTestPubAddr()
|
|
encCfg := simapp.MakeTestEncodingConfig()
|
|
testdata.RegisterInterfaces(encCfg.InterfaceRegistry)
|
|
db := dbm.NewMemDB()
|
|
app := baseapp.NewBaseApp("test", log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, encCfg.TxConfig.TxDecoder())
|
|
app.SetInterfaceRegistry(encCfg.InterfaceRegistry)
|
|
testdata.RegisterMsgServer(
|
|
app.MsgServiceRouter(),
|
|
testdata.MsgServerImpl{},
|
|
)
|
|
_ = app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 1}})
|
|
|
|
msg := testdata.MsgCreateDog{Dog: &testdata.Dog{Name: "Spot"}}
|
|
txBuilder := encCfg.TxConfig.NewTxBuilder()
|
|
txBuilder.SetFeeAmount(testdata.NewTestFeeAmount())
|
|
txBuilder.SetGasLimit(testdata.NewTestGasLimit())
|
|
err := txBuilder.SetMsgs(&msg)
|
|
require.NoError(t, err)
|
|
|
|
// First round: we gather all the signer infos. We use the "set empty
|
|
// signature" hack to do that.
|
|
sigV2 := signing.SignatureV2{
|
|
PubKey: priv.PubKey(),
|
|
Data: &signing.SingleSignatureData{
|
|
SignMode: encCfg.TxConfig.SignModeHandler().DefaultMode(),
|
|
Signature: nil,
|
|
},
|
|
Sequence: 0,
|
|
}
|
|
|
|
err = txBuilder.SetSignatures(sigV2)
|
|
require.NoError(t, err)
|
|
|
|
// Second round: all signer infos are set, so each signer can sign.
|
|
signerData := authsigning.SignerData{
|
|
ChainID: "test",
|
|
AccountNumber: 0,
|
|
Sequence: 0,
|
|
}
|
|
sigV2, err = tx.SignWithPrivKey(
|
|
encCfg.TxConfig.SignModeHandler().DefaultMode(), signerData,
|
|
txBuilder, priv, encCfg.TxConfig, 0)
|
|
require.NoError(t, err)
|
|
err = txBuilder.SetSignatures(sigV2)
|
|
require.NoError(t, err)
|
|
|
|
// Send the tx to the app
|
|
txBytes, err := encCfg.TxConfig.TxEncoder()(txBuilder.GetTx())
|
|
require.NoError(t, err)
|
|
res := app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes})
|
|
require.Equal(t, abci.CodeTypeOK, res.Code, "res=%+v", res)
|
|
}
|