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

refactor(auth): refactor auth/tx to use x/tx #19224

Merged
merged 40 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
d2b76b9
move x/auth/tx to use x/tx
testinginprod Jan 24, 2024
07484e1
checkpoint
testinginprod Jan 24, 2024
48b9733
more fixes
testinginprod Jan 24, 2024
9bf545d
more fixes2
testinginprod Jan 24, 2024
ec74255
add more fixes
testinginprod Jan 24, 2024
d9eaa3c
apply fix
testinginprod Jan 24, 2024
25b909e
fix e2e with gov changes
testinginprod Jan 24, 2024
4769b4c
more tests adjustments
testinginprod Jan 24, 2024
0a635cc
yet another fix
testinginprod Jan 24, 2024
a96c267
closer
testinginprod Jan 24, 2024
3b59cad
yet another fix
testinginprod Jan 24, 2024
09dfb53
we keep rocking
testinginprod Jan 24, 2024
fccfb9c
we keep rocking part2
testinginprod Jan 24, 2024
33af7d9
another test fix
testinginprod Jan 24, 2024
0365de7
another test fix2
testinginprod Jan 24, 2024
1609e38
another test fix3
testinginprod Jan 24, 2024
3a558ae
remove redundant test
testinginprod Jan 24, 2024
42fb249
change textual e2e to match latest updates in API
testinginprod Jan 24, 2024
2dc646f
another one bites the dust
testinginprod Jan 24, 2024
fb32826
tmp commit
testinginprod Jan 25, 2024
3a8e81e
another galaxy brain fix
testinginprod Jan 25, 2024
093748a
fix decoding fuzz testing
testinginprod Jan 25, 2024
9f1512f
fix
testinginprod Jan 25, 2024
7ef2dec
fix slashing test
testinginprod Jan 25, 2024
73c7664
gg
testinginprod Jan 25, 2024
5851942
Merge branch 'main' into tip/auth/use_x_tx
testinginprod Jan 25, 2024
7ff9dd9
thanks @julienrbrt
testinginprod Jan 25, 2024
77d7111
lint
testinginprod Jan 25, 2024
e0fda8e
fix service_test.go
testinginprod Jan 25, 2024
98a42e8
revert lint
testinginprod Jan 25, 2024
a298c74
lint happy again
testinginprod Jan 25, 2024
2227e7d
fix conflicts
facundomedica Feb 14, 2024
6bbcdcd
remove MergedProtoRegistry (#19484)
kocubinski Feb 20, 2024
9fed787
fix
facundomedica Feb 20, 2024
e879571
Merge branch 'main' into tip/auth/use_x_tx
facundomedica Feb 20, 2024
944ed5b
fix
facundomedica Feb 20, 2024
d725e5f
Merge branch 'tip/auth/use_x_tx' of https://github.com/cosmos/cosmos-…
facundomedica Feb 20, 2024
fb47eac
go mod tidy all
facundomedica Feb 20, 2024
4c0d6c7
more fixes
facundomedica Feb 20, 2024
fe91f3a
skip aux test
facundomedica Feb 20, 2024
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
13 changes: 0 additions & 13 deletions baseapp/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -930,19 +930,6 @@ func TestABCI_InvalidTransaction(t *testing.T) {
require.EqualValues(t, sdkerrors.ErrUnknownRequest.Codespace(), space, err)
require.EqualValues(t, sdkerrors.ErrUnknownRequest.ABCICode(), code, err)
}

// Transaction with an unregistered message
{
txBuilder := suite.txConfig.NewTxBuilder()
err = txBuilder.SetMsgs(&testdata.MsgCreateDog{})
require.NoError(t, err)
tx := txBuilder.GetTx()

_, _, err := suite.baseApp.SimDeliver(suite.txConfig.TxEncoder(), tx)
space, code, _ := errorsmod.ABCIInfo(err, false)
require.EqualValues(t, sdkerrors.ErrTxDecode.ABCICode(), code)
require.EqualValues(t, sdkerrors.ErrTxDecode.Codespace(), space)
}
}

func TestABCI_TxGasLimits(t *testing.T) {
Expand Down
5 changes: 4 additions & 1 deletion baseapp/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ func setFailOnHandler(t *testing.T, cfg client.TxConfig, tx signing.Tx, fail boo
msgs[i] = &baseapptestutil.MsgCounter{
Counter: msg.(*baseapptestutil.MsgCounter).Counter,
FailOnHandler: fail,
Signer: sdk.AccAddress("addr").String(),
}
}

Expand All @@ -367,7 +368,9 @@ func wonkyMsg(t *testing.T, cfg client.TxConfig, tx signing.Tx) signing.Tx {
builder.SetMemo(tx.GetMemo())

msgs := tx.GetMsgs()
msgs = append(msgs, &baseapptestutil.MsgCounter2{})
msgs = append(msgs, &baseapptestutil.MsgCounter2{
Signer: sdk.AccAddress("wonky").String(),
})

err := builder.SetMsgs(msgs...)
require.NoError(t, err)
Expand Down
6 changes: 4 additions & 2 deletions client/tx/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,14 +417,16 @@ func TestPreprocessHook(t *testing.T) {
err = txfDirect.PreprocessTx(from, txb)
requireT.NoError(err)

hasExtOptsTx, ok := txb.(ante.HasExtensionOptionsTx)
tx := txb.GetTx()
hasExtOptsTx, ok := tx.(ante.HasExtensionOptionsTx)
requireT.True(ok)

hasOneExt := len(hasExtOptsTx.GetExtensionOptions()) == 1
requireT.True(hasOneExt)

opt := hasExtOptsTx.GetExtensionOptions()[0]
requireT.Equal(opt, extAny)
requireT.Equal(opt.TypeUrl, extAny.TypeUrl)
requireT.Equal(opt.Value, extAny.Value)
}

func testSigners(require *require.Assertions, tr signing.Tx, pks ...cryptotypes.PubKey) []signingtypes.SignatureV2 {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/tx/benchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func BenchmarkTx(b *testing.B) {
val := s.network.GetValidators()[0]
txBuilder := mkTxBuilder(b, s)
// Convert the txBuilder to a tx.Tx.
protoTx, err := txBuilderToProtoTx(txBuilder)
protoTx, err := txBuilder.GetTx().(interface{ AsTx() (*tx.Tx, error) }).AsTx()
assert.NilError(b, err)
// Encode the txBuilder to txBytes.
txBytes, err := val.GetClientCtx().TxConfig.TxEncoder()(txBuilder.GetTx())
Expand Down
65 changes: 33 additions & 32 deletions tests/e2e/tx/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import (
"strings"
"testing"

"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

errorsmod "cosmossdk.io/errors"
"cosmossdk.io/math"
"cosmossdk.io/simapp"
authclient "cosmossdk.io/x/auth/client"
authtest "cosmossdk.io/x/auth/client/testutil"
"cosmossdk.io/x/auth/migrations/legacytx"
authtx "cosmossdk.io/x/auth/tx"
banktypes "cosmossdk.io/x/bank/types"

"github.com/cosmos/cosmos-sdk/client"
Expand All @@ -30,7 +29,6 @@ import (
"github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/cosmos-sdk/types/tx"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
Expand Down Expand Up @@ -158,7 +156,7 @@ func (s *E2ETestSuite) TestSimulateTx_GRPC() {
val := s.network.GetValidators()[0]
txBuilder := s.mkTxBuilder()
// Convert the txBuilder to a tx.Tx.
protoTx, err := txBuilderToProtoTx(txBuilder)
protoTx, err := txBuilder.GetTx().(interface{ AsTx() (*tx.Tx, error) }).AsTx()
testinginprod marked this conversation as resolved.
Show resolved Hide resolved
s.Require().NoError(err)
// Encode the txBuilder to txBytes.
txBytes, err := val.GetClientCtx().TxConfig.TxEncoder()(txBuilder.GetTx())
Expand Down Expand Up @@ -205,7 +203,7 @@ func (s *E2ETestSuite) TestSimulateTx_GRPCGateway() {
val := s.network.GetValidators()[0]
txBuilder := s.mkTxBuilder()
// Convert the txBuilder to a tx.Tx.
protoTx, err := txBuilderToProtoTx(txBuilder)
protoTx, err := txBuilder.GetTx().(interface{ AsTx() (*tx.Tx, error) }).AsTx()
testinginprod marked this conversation as resolved.
Show resolved Hide resolved
s.Require().NoError(err)
// Encode the txBuilder to txBytes.
txBytes, err := val.GetClientCtx().TxConfig.TxEncoder()(txBuilder.GetTx())
Expand Down Expand Up @@ -759,7 +757,7 @@ func (s *E2ETestSuite) TestGetBlockWithTxs_GRPCGateway() {
func (s *E2ETestSuite) TestTxEncode_GRPC() {
val := s.network.GetValidators()[0]
txBuilder := s.mkTxBuilder()
protoTx, err := txBuilderToProtoTx(txBuilder)
protoTx, err := txBuilder.GetTx().(interface{ AsTx() (*tx.Tx, error) }).AsTx()
testinginprod marked this conversation as resolved.
Show resolved Hide resolved
s.Require().NoError(err)

testCases := []struct {
Expand Down Expand Up @@ -796,7 +794,7 @@ func (s *E2ETestSuite) TestTxEncode_GRPC() {
func (s *E2ETestSuite) TestTxEncode_GRPCGateway() {
val := s.network.GetValidators()[0]
txBuilder := s.mkTxBuilder()
protoTx, err := txBuilderToProtoTx(txBuilder)
protoTx, err := txBuilder.GetTx().(interface{ AsTx() (*tx.Tx, error) }).AsTx()
testinginprod marked this conversation as resolved.
Show resolved Hide resolved
s.Require().NoError(err)

testCases := []struct {
Expand Down Expand Up @@ -835,7 +833,8 @@ func (s *E2ETestSuite) TestTxDecode_GRPC() {
val := s.network.GetValidators()[0]
txBuilder := s.mkTxBuilder()

encodedTx, err := val.GetClientCtx().TxConfig.TxEncoder()(txBuilder.GetTx())
goodTx := txBuilder.GetTx()
encodedTx, err := val.GetClientCtx().TxConfig.TxEncoder()(goodTx)
s.Require().NoError(err)

invalidTxBytes := append(encodedTx, byte(0o00))
Expand Down Expand Up @@ -864,15 +863,35 @@ func (s *E2ETestSuite) TestTxDecode_GRPC() {
s.Require().NoError(err)
s.Require().NotEmpty(res.GetTx())

txb := authtx.WrapTx(res.Tx)
tx, err := val.GetClientCtx().TxConfig.TxEncoder()(txb.GetTx())
txb := wrapTx(s.T(), s.cfg.TxConfig, res.Tx)
gotTx := txb.GetTx()
gotEncoded, err := val.GetClientCtx().TxConfig.TxEncoder()(gotTx)
s.Require().NoError(err)
s.Require().Equal(encodedTx, tx)
s.Require().Equal(encodedTx, gotEncoded)
}
})
}
}

func wrapTx(t *testing.T, conf client.TxConfig, dTx *tx.Tx) client.TxBuilder {
t.Helper()
bodyBytes, err := dTx.Body.Marshal()
require.NoError(t, err)
authInfoBytes, err := dTx.AuthInfo.Marshal()
require.NoError(t, err)
rawTxBytes, err := (&tx.TxRaw{
BodyBytes: bodyBytes,
AuthInfoBytes: authInfoBytes,
Signatures: dTx.Signatures,
}).Marshal()
require.NoError(t, err)
dec, err := conf.TxDecoder()(rawTxBytes)
require.NoError(t, err)
bld, err := conf.WrapTxBuilder(dec)
require.NoError(t, err)
return bld
}

func (s *E2ETestSuite) TestTxDecode_GRPCGateway() {
val := s.network.GetValidators()[0]
txBuilder := s.mkTxBuilder()
Expand Down Expand Up @@ -907,9 +926,10 @@ func (s *E2ETestSuite) TestTxDecode_GRPCGateway() {
err := val.GetClientCtx().Codec.UnmarshalJSON(res, &result)
s.Require().NoError(err)

txb := authtx.WrapTx(result.Tx)
txb := wrapTx(s.T(), s.cfg.TxConfig, result.Tx)
tx, err := val.GetClientCtx().TxConfig.TxEncoder()(txb.GetTx())
s.Require().NoError(err)
s.T().Log(len(tx), len(encodedTxBytes))
s.Require().Equal(encodedTxBytes, tx)
}
})
Expand Down Expand Up @@ -1111,6 +1131,7 @@ func (s *E2ETestSuite) mkTxBuilder() client.TxBuilder {
txBuilder.SetFeeAmount(feeAmount)
txBuilder.SetGasLimit(gasLimit)
txBuilder.SetMemo("foobar")
txBuilder.SetFeePayer(val.GetAddress())
signers, err := txBuilder.GetTx().GetSigners()
s.Require().NoError(err)
s.Require().Equal([][]byte{val.GetAddress()}, signers)
Expand All @@ -1128,23 +1149,3 @@ func (s *E2ETestSuite) mkTxBuilder() client.TxBuilder {

return txBuilder
}

// protoTxProvider is a type which can provide a proto transaction. It is a
// workaround to get access to the wrapper TxBuilder's method GetProtoTx().
// Deprecated: It's only used for testing the deprecated Simulate gRPC endpoint
// using a proto Tx field.
type protoTxProvider interface {
GetProtoTx() *tx.Tx
}

// txBuilderToProtoTx converts a txBuilder into a proto tx.Tx.
// Deprecated: It's used for testing the deprecated Simulate gRPC endpoint
// using a proto Tx field and for testing the TxEncode endpoint.
func txBuilderToProtoTx(txBuilder client.TxBuilder) (*tx.Tx, error) {
protoProvider, ok := txBuilder.(protoTxProvider)
if !ok {
return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidType, "expected proto tx builder, got %T", txBuilder)
}

return protoProvider.GetProtoTx(), nil
}
1 change: 1 addition & 0 deletions tests/integration/auth/client/cli/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,7 @@ func (s *CLITestSuite) TestSignWithMultiSignersAminoJSON() {
}

func (s *CLITestSuite) TestAuxSigner() {
s.T().Skip("re-enable this when we bring back sign mode aux client testing")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's rationale for disabling this test?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was left out of scope for this PR and was removed from the builder. This needs to be added to client/v2, just created an issue: #19433.
cc: @testinginprod

val0Coin := sdk.NewCoin("testtoken", math.NewInt(10))

testCases := []struct {
Expand Down
34 changes: 18 additions & 16 deletions tests/integration/bank/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
_ "cosmossdk.io/x/staking"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/runtime"
Expand Down Expand Up @@ -100,6 +101,7 @@ type suite struct {
AccountKeeper types.AccountKeeper
DistributionKeeper distrkeeper.Keeper
App *runtime.App
TxConfig client.TxConfig
}

func createTestSuite(t *testing.T, genesisAccounts []authtypes.GenesisAccount) suite {
Expand Down Expand Up @@ -128,7 +130,7 @@ func createTestSuite(t *testing.T, genesisAccounts []authtypes.GenesisAccount) s
),
depinject.Supply(log.NewNopLogger()),
),
startupCfg, &res.BankKeeper, &res.AccountKeeper, &res.DistributionKeeper)
startupCfg, &res.BankKeeper, &res.AccountKeeper, &res.DistributionKeeper, &res.TxConfig)

res.App = app

Expand Down Expand Up @@ -223,7 +225,7 @@ func TestMsgMultiSendWithAccounts(t *testing.T) {
},
{
desc: "wrong accNum should pass Simulate, but not Deliver",
msgs: []sdk.Msg{multiSendMsg1, multiSendMsg2},
msgs: []sdk.Msg{multiSendMsg1},
accNums: []uint64{1}, // wrong account number
accSeqs: []uint64{1},
expSimPass: true, // doesn't check signature
Expand Down Expand Up @@ -251,19 +253,20 @@ func TestMsgMultiSendWithAccounts(t *testing.T) {
}

for _, tc := range testCases {
t.Logf("testing %s", tc.desc)
header := header.Info{Height: baseApp.LastBlockHeight() + 1}
txConfig := moduletestutil.MakeTestTxConfig()
_, _, err := simtestutil.SignCheckDeliver(t, txConfig, baseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...)
if tc.expPass {
require.NoError(t, err)
} else {
require.Error(t, err)
}
t.Run(tc.desc, func(t *testing.T) {
header := header.Info{Height: baseApp.LastBlockHeight() + 1}
txConfig := moduletestutil.MakeTestTxConfig()
_, _, err := simtestutil.SignCheckDeliver(t, txConfig, baseApp, header, tc.msgs, "", tc.accNums, tc.accSeqs, tc.expSimPass, tc.expPass, tc.privKeys...)
if tc.expPass {
require.NoError(t, err)
} else {
require.Error(t, err)
}

for _, eb := range tc.expectedBalances {
checkBalance(t, baseApp, eb.addr, eb.coins, s.BankKeeper)
}
for _, eb := range tc.expectedBalances {
checkBalance(t, baseApp, eb.addr, eb.coins, s.BankKeeper)
}
})
}
}

Expand Down Expand Up @@ -438,8 +441,7 @@ func TestMsgSetSendEnabled(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(tt *testing.T) {
header := header.Info{Height: s.App.LastBlockHeight() + 1}
txGen := moduletestutil.MakeTestTxConfig()
_, _, err = simtestutil.SignCheckDeliver(tt, txGen, s.App.BaseApp, header, tc.msgs, "", []uint64{0}, tc.accSeqs, tc.expSimPass, tc.expPass, priv1)
_, _, err = simtestutil.SignCheckDeliver(tt, s.TxConfig, s.App.BaseApp, header, tc.msgs, "", []uint64{0}, tc.accSeqs, tc.expSimPass, tc.expPass, priv1)
if len(tc.expInError) > 0 {
require.Error(tt, err)
for _, exp := range tc.expInError {
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/slashing/slashing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import (
stakingkeeper "cosmossdk.io/x/staking/keeper"
stakingtypes "cosmossdk.io/x/staking/types"

"github.com/cosmos/cosmos-sdk/client"
codecaddress "github.com/cosmos/cosmos-sdk/codec/address"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/testutil/configurator"
"github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
)

var (
Expand Down Expand Up @@ -56,6 +56,7 @@ func TestSlashingMsgs(t *testing.T) {
stakingKeeper *stakingkeeper.Keeper
bankKeeper bankkeeper.Keeper
slashingKeeper keeper.Keeper
txConfig client.TxConfig
)

app, err := sims.SetupWithConfiguration(
Expand All @@ -70,7 +71,7 @@ func TestSlashingMsgs(t *testing.T) {
),
depinject.Supply(log.NewNopLogger()),
),
startupCfg, &stakingKeeper, &bankKeeper, &slashingKeeper)
startupCfg, &stakingKeeper, &bankKeeper, &slashingKeeper, &txConfig)
require.NoError(t, err)

baseApp := app.BaseApp
Expand All @@ -91,7 +92,6 @@ func TestSlashingMsgs(t *testing.T) {
require.NoError(t, err)

headerInfo := header.Info{Height: app.LastBlockHeight() + 1}
txConfig := moduletestutil.MakeTestTxConfig()
_, _, err = sims.SignCheckDeliver(t, txConfig, app.BaseApp, headerInfo, []sdk.Msg{createValidatorMsg}, "", []uint64{0}, []uint64{0}, true, true, priv1)
require.NoError(t, err)
require.True(t, sdk.Coins{genCoin.Sub(bondCoin)}.Equal(bankKeeper.GetAllBalances(ctxCheck, addr1)))
Expand Down
14 changes: 14 additions & 0 deletions tests/integration/tx/aminojson/aminojson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"reflect"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -115,6 +116,19 @@ func TestAminoJSON_Equivalence(t *testing.T) {

msg := gen.Draw(t, "msg")
postFixPulsarMessage(msg)
// txBuilder.GetTx will fail if the msg has no signers
// so it does not make sense to run these cases, apparently.
signers, err := encCfg.TxConfig.SigningContext().GetSigners(msg)
if len(signers) == 0 {
// skip
return
}
if err != nil {
if strings.Contains(err.Error(), "empty address string is not allowed") {
return
}
require.NoError(t, err)
}

gogo := tt.Gogo
sanity := tt.Pulsar
Expand Down
11 changes: 11 additions & 0 deletions tests/integration/tx/decode_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tx

import (
"strings"
"testing"

"github.com/cosmos/cosmos-proto/rapidproto"
Expand Down Expand Up @@ -83,6 +84,16 @@ func TestDecode(t *testing.T) {
gen := rapidproto.MessageGenerator(tt.Pulsar, tt.Opts)
rapid.Check(t, func(t *rapid.T) {
msg := gen.Draw(t, "msg")
signers, err := encCfg.TxConfig.SigningContext().GetSigners(msg)
if len(signers) == 0 {
return
}
if err != nil {
if strings.Contains(err.Error(), "empty address string is not allowed") {
return
}
require.NoError(t, err)
}
gogo := tt.Gogo
sanity := tt.Pulsar

Expand Down
Loading
Loading