Skip to content

Commit

Permalink
refactor(auth): refactor auth/tx to use x/tx (#19224)
Browse files Browse the repository at this point in the history
Co-authored-by: Facundo <[email protected]>
Co-authored-by: Matt Kocubinski <[email protected]>
Co-authored-by: Facundo Medica <[email protected]>
  • Loading branch information
4 people authored Feb 21, 2024
1 parent 0cf0c28 commit e846eca
Show file tree
Hide file tree
Showing 46 changed files with 2,914 additions and 1,801 deletions.
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
36 changes: 21 additions & 15 deletions baseapp/abci_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,15 +469,15 @@ func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_PriorityNonceMempoolTxSe
testTxs[i].size = int(cmttypes.ComputeProtoSizeForTxs([]cmttypes.Tx{bz}))
}

s.Require().Equal(testTxs[0].size, 111)
s.Require().Equal(testTxs[1].size, 121)
s.Require().Equal(testTxs[2].size, 112)
s.Require().Equal(testTxs[3].size, 112)
s.Require().Equal(testTxs[4].size, 195)
s.Require().Equal(testTxs[5].size, 205)
s.Require().Equal(testTxs[6].size, 196)
s.Require().Equal(testTxs[7].size, 196)
s.Require().Equal(testTxs[8].size, 196)
s.Require().Equal(180, testTxs[0].size)
s.Require().Equal(190, testTxs[1].size)
s.Require().Equal(181, testTxs[2].size)
s.Require().Equal(181, testTxs[3].size)
s.Require().Equal(263, testTxs[4].size)
s.Require().Equal(273, testTxs[5].size)
s.Require().Equal(264, testTxs[6].size)
s.Require().Equal(264, testTxs[7].size)
s.Require().Equal(264, testTxs[8].size)

testCases := map[string]struct {
ctx sdk.Context
Expand All @@ -490,15 +490,15 @@ func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_PriorityNonceMempoolTxSe
ctx: s.ctx,
txInputs: []testTx{testTxs[0], testTxs[1], testTxs[2], testTxs[3]},
req: &abci.RequestPrepareProposal{
MaxTxBytes: 111 + 112,
MaxTxBytes: 180 + 181,
},
expectedTxs: []int{0, 3},
},
"skip multi-signers msg non-sequential sequence": {
ctx: s.ctx,
txInputs: []testTx{testTxs[4], testTxs[5], testTxs[6], testTxs[7], testTxs[8]},
req: &abci.RequestPrepareProposal{
MaxTxBytes: 195 + 196,
MaxTxBytes: 263 + 264,
},
expectedTxs: []int{4, 8},
},
Expand All @@ -507,7 +507,7 @@ func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_PriorityNonceMempoolTxSe
ctx: s.ctx,
txInputs: []testTx{testTxs[9], testTxs[10], testTxs[11]},
req: &abci.RequestPrepareProposal{
MaxTxBytes: 195 + 196,
MaxTxBytes: 263 + 264,
},
expectedTxs: []int{9},
},
Expand Down Expand Up @@ -571,9 +571,7 @@ func marshalDelimitedFn(msg proto.Message) ([]byte, error) {
func buildMsg(t *testing.T, txConfig client.TxConfig, value []byte, secrets [][]byte, nonces []uint64) sdk.Tx {
t.Helper()
builder := txConfig.NewTxBuilder()
_ = builder.SetMsgs(
&baseapptestutil.MsgKeyValue{Value: value},
)

require.Equal(t, len(secrets), len(nonces))
signatures := make([]signingtypes.SignatureV2, 0)
for index, secret := range secrets {
Expand All @@ -586,6 +584,14 @@ func buildMsg(t *testing.T, txConfig client.TxConfig, value []byte, secrets [][]
Data: &signingtypes.SingleSignatureData{},
})
}

_ = builder.SetMsgs(
&baseapptestutil.MsgKeyValue{
Signer: sdk.AccAddress(signatures[0].PubKey.Bytes()).String(),
Value: value,
},
)

setTxSignatureWithSecret(t, builder, signatures...)
return builder.GetTx()
}
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
Loading

0 comments on commit e846eca

Please sign in to comment.