Co-authored-by: Julián Toledano <JulianToledano@users.noreply.github.com> Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
parent
3cdae66416
commit
3e88fa6b47
@ -598,7 +598,7 @@ func TestABCI_CheckTx(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
for i := int64(0); i < nTxs; i++ {
|
||||
tx := newTxCounter(t, suite.txConfig, i, 0) // no messages
|
||||
tx := newTxCounter(t, suite.txConfig, suite.ac, i, 0) // no messages
|
||||
txBytes, err := suite.txConfig.TxEncoder()(tx)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -653,7 +653,7 @@ func TestABCI_FinalizeBlock_DeliverTx(t *testing.T) {
|
||||
txs := [][]byte{}
|
||||
for i := 0; i < txPerHeight; i++ {
|
||||
counter := int64(blockN*txPerHeight + i)
|
||||
tx := newTxCounter(t, suite.txConfig, counter, counter)
|
||||
tx := newTxCounter(t, suite.txConfig, suite.ac, counter, counter)
|
||||
|
||||
txBytes, err := suite.txConfig.TxEncoder()(tx)
|
||||
require.NoError(t, err)
|
||||
@ -701,7 +701,7 @@ func TestABCI_FinalizeBlock_MultiMsg(t *testing.T) {
|
||||
|
||||
// run a multi-msg tx
|
||||
// with all msgs the same route
|
||||
tx := newTxCounter(t, suite.txConfig, 0, 0, 1, 2)
|
||||
tx := newTxCounter(t, suite.txConfig, suite.ac, 0, 0, 1, 2)
|
||||
txBytes, err := suite.txConfig.TxEncoder()(tx)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -722,13 +722,15 @@ func TestABCI_FinalizeBlock_MultiMsg(t *testing.T) {
|
||||
require.Equal(t, int64(3), msgCounter)
|
||||
|
||||
// replace the second message with a Counter2
|
||||
tx = newTxCounter(t, suite.txConfig, 1, 3)
|
||||
tx = newTxCounter(t, suite.txConfig, suite.ac, 1, 3)
|
||||
|
||||
builder := suite.txConfig.NewTxBuilder()
|
||||
msgs := tx.GetMsgs()
|
||||
_, _, addr := testdata.KeyTestPubAddr()
|
||||
msgs = append(msgs, &baseapptestutil.MsgCounter2{Counter: 0, Signer: addr.String()})
|
||||
msgs = append(msgs, &baseapptestutil.MsgCounter2{Counter: 1, Signer: addr.String()})
|
||||
addrStr, err := suite.ac.BytesToString(addr)
|
||||
require.NoError(t, err)
|
||||
msgs = append(msgs, &baseapptestutil.MsgCounter2{Counter: 0, Signer: addrStr})
|
||||
msgs = append(msgs, &baseapptestutil.MsgCounter2{Counter: 1, Signer: addrStr})
|
||||
|
||||
err = builder.SetMsgs(msgs...)
|
||||
require.NoError(t, err)
|
||||
@ -781,7 +783,7 @@ func TestABCI_Query_SimulateTx(t *testing.T) {
|
||||
for blockN := 0; blockN < nBlocks; blockN++ {
|
||||
count := int64(blockN + 1)
|
||||
|
||||
tx := newTxCounter(t, suite.txConfig, count, count)
|
||||
tx := newTxCounter(t, suite.txConfig, suite.ac, count, count)
|
||||
|
||||
txBytes, err := suite.txConfig.TxEncoder()(tx)
|
||||
require.Nil(t, err)
|
||||
@ -872,14 +874,14 @@ func TestABCI_InvalidTransaction(t *testing.T) {
|
||||
tx signing.Tx
|
||||
fail bool
|
||||
}{
|
||||
{newTxCounter(t, suite.txConfig, 0, 0), false},
|
||||
{newTxCounter(t, suite.txConfig, -1, 0), false},
|
||||
{newTxCounter(t, suite.txConfig, 100, 100), false},
|
||||
{newTxCounter(t, suite.txConfig, 100, 5, 4, 3, 2, 1), false},
|
||||
{newTxCounter(t, suite.txConfig, suite.ac, 0, 0), false},
|
||||
{newTxCounter(t, suite.txConfig, suite.ac, -1, 0), false},
|
||||
{newTxCounter(t, suite.txConfig, suite.ac, 100, 100), false},
|
||||
{newTxCounter(t, suite.txConfig, suite.ac, 100, 5, 4, 3, 2, 1), false},
|
||||
|
||||
{newTxCounter(t, suite.txConfig, 0, -1), true},
|
||||
{newTxCounter(t, suite.txConfig, 0, 1, -2), true},
|
||||
{newTxCounter(t, suite.txConfig, 0, 1, 2, -10, 5), true},
|
||||
{newTxCounter(t, suite.txConfig, suite.ac, 0, -1), true},
|
||||
{newTxCounter(t, suite.txConfig, suite.ac, 0, 1, -2), true},
|
||||
{newTxCounter(t, suite.txConfig, suite.ac, 0, 1, 2, -10, 5), true},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
@ -902,7 +904,9 @@ func TestABCI_InvalidTransaction(t *testing.T) {
|
||||
{
|
||||
txBuilder := suite.txConfig.NewTxBuilder()
|
||||
_, _, addr := testdata.KeyTestPubAddr()
|
||||
err = txBuilder.SetMsgs(&baseapptestutil.MsgCounter2{Signer: addr.String()})
|
||||
addrStr, err := suite.ac.BytesToString(addr)
|
||||
require.NoError(t, err)
|
||||
err = txBuilder.SetMsgs(&baseapptestutil.MsgCounter2{Signer: addrStr})
|
||||
require.NoError(t, err)
|
||||
setTxSignature(t, txBuilder, 0)
|
||||
unknownRouteTx := txBuilder.GetTx()
|
||||
@ -917,8 +921,8 @@ func TestABCI_InvalidTransaction(t *testing.T) {
|
||||
|
||||
txBuilder = suite.txConfig.NewTxBuilder()
|
||||
err = txBuilder.SetMsgs(
|
||||
&baseapptestutil.MsgCounter{Signer: addr.String()},
|
||||
&baseapptestutil.MsgCounter2{Signer: addr.String()},
|
||||
&baseapptestutil.MsgCounter{Signer: addrStr},
|
||||
&baseapptestutil.MsgCounter2{Signer: addrStr},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
setTxSignature(t, txBuilder, 0)
|
||||
@ -983,19 +987,19 @@ func TestABCI_TxGasLimits(t *testing.T) {
|
||||
gasUsed int64
|
||||
fail bool
|
||||
}{
|
||||
{newTxCounter(t, suite.txConfig, 0, 0), 0, false},
|
||||
{newTxCounter(t, suite.txConfig, 1, 1), 2, false},
|
||||
{newTxCounter(t, suite.txConfig, 9, 1), 10, false},
|
||||
{newTxCounter(t, suite.txConfig, 1, 9), 10, false},
|
||||
{newTxCounter(t, suite.txConfig, 10, 0), 10, false},
|
||||
{newTxCounter(t, suite.txConfig, suite.ac, 0, 0), 0, false},
|
||||
{newTxCounter(t, suite.txConfig, suite.ac, 1, 1), 2, false},
|
||||
{newTxCounter(t, suite.txConfig, suite.ac, 9, 1), 10, false},
|
||||
{newTxCounter(t, suite.txConfig, suite.ac, 1, 9), 10, false},
|
||||
{newTxCounter(t, suite.txConfig, suite.ac, 10, 0), 10, false},
|
||||
|
||||
{newTxCounter(t, suite.txConfig, 9, 2), 11, true},
|
||||
{newTxCounter(t, suite.txConfig, 2, 9), 11, true},
|
||||
// {newTxCounter(t, suite.txConfig, 9, 1, 1), 11, true},
|
||||
// {newTxCounter(t, suite.txConfig, 1, 8, 1, 1), 11, true},
|
||||
// {newTxCounter(t, suite.txConfig, 11, 0), 11, true},
|
||||
// {newTxCounter(t, suite.txConfig, 0, 11), 11, true},
|
||||
// {newTxCounter(t, suite.txConfig, 0, 5, 11), 16, true},
|
||||
{newTxCounter(t, suite.txConfig, suite.ac, 9, 2), 11, true},
|
||||
{newTxCounter(t, suite.txConfig, suite.ac, 2, 9), 11, true},
|
||||
// {newTxCounter(t, suite.txConfig, suite.ac, 9, 1, 1), 11, true},
|
||||
// {newTxCounter(t, suite.txConfig, suite.ac, 1, 8, 1, 1), 11, true},
|
||||
// {newTxCounter(t, suite.txConfig, suite.ac, 11, 0), 11, true},
|
||||
// {newTxCounter(t, suite.txConfig, suite.ac, 0, 11), 11, true},
|
||||
// {newTxCounter(t, suite.txConfig, suite.ac, 0, 5, 11), 16, true},
|
||||
}
|
||||
|
||||
txs := [][]byte{}
|
||||
@ -1076,16 +1080,16 @@ func TestABCI_MaxBlockGasLimits(t *testing.T) {
|
||||
fail bool
|
||||
failAfterDeliver int
|
||||
}{
|
||||
{newTxCounter(t, suite.txConfig, 0, 0), 0, 0, false, 0},
|
||||
{newTxCounter(t, suite.txConfig, 9, 1), 2, 10, false, 0},
|
||||
{newTxCounter(t, suite.txConfig, 10, 0), 3, 10, false, 0},
|
||||
{newTxCounter(t, suite.txConfig, 10, 0), 10, 10, false, 0},
|
||||
{newTxCounter(t, suite.txConfig, 2, 7), 11, 9, false, 0},
|
||||
// {newTxCounter(t, suite.txConfig, 10, 0), 10, 10, false, 0}, // hit the limit but pass
|
||||
{newTxCounter(t, suite.txConfig, suite.ac, 0, 0), 0, 0, false, 0},
|
||||
{newTxCounter(t, suite.txConfig, suite.ac, 9, 1), 2, 10, false, 0},
|
||||
{newTxCounter(t, suite.txConfig, suite.ac, 10, 0), 3, 10, false, 0},
|
||||
{newTxCounter(t, suite.txConfig, suite.ac, 10, 0), 10, 10, false, 0},
|
||||
{newTxCounter(t, suite.txConfig, suite.ac, 2, 7), 11, 9, false, 0},
|
||||
// {newTxCounter(t, suite.txConfig, suite.ac, 10, 0), 10, 10, false, 0}, // hit the limit but pass
|
||||
|
||||
// {newTxCounter(t, suite.txConfig, 10, 0), 11, 10, true, 10},
|
||||
// {newTxCounter(t, suite.txConfig, 10, 0), 15, 10, true, 10},
|
||||
// {newTxCounter(t, suite.txConfig, 9, 0), 12, 9, true, 11}, // fly past the limit
|
||||
// {newTxCounter(t, suite.txConfig, suite.ac, 10, 0), 11, 10, true, 10},
|
||||
// {newTxCounter(t, suite.txConfig, suite.ac, 10, 0), 15, 10, true, 10},
|
||||
// {newTxCounter(t, suite.txConfig, suite.ac, 9, 0), 12, 9, true, 11}, // fly past the limit
|
||||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
@ -1167,13 +1171,13 @@ func TestABCI_GasConsumptionBadTx(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
tx := newTxCounter(t, suite.txConfig, 5, 0)
|
||||
tx := newTxCounter(t, suite.txConfig, suite.ac, 5, 0)
|
||||
tx = setFailOnAnte(t, suite.txConfig, tx, true)
|
||||
txBytes, err := suite.txConfig.TxEncoder()(tx)
|
||||
require.NoError(t, err)
|
||||
|
||||
// require next tx to fail due to black gas limit
|
||||
tx = newTxCounter(t, suite.txConfig, 5, 0)
|
||||
tx = newTxCounter(t, suite.txConfig, suite.ac, 5, 0)
|
||||
txBytes2, err := suite.txConfig.TxEncoder()(tx)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -1209,7 +1213,7 @@ func TestABCI_Query(t *testing.T) {
|
||||
Path: "/store/key1/key",
|
||||
Data: key,
|
||||
}
|
||||
tx := newTxCounter(t, suite.txConfig, 0, 0)
|
||||
tx := newTxCounter(t, suite.txConfig, suite.ac, 0, 0)
|
||||
|
||||
// query is empty before we do anything
|
||||
res, err := suite.baseApp.Query(context.TODO(), &query)
|
||||
@ -1420,7 +1424,7 @@ func TestABCI_Proposal_HappyPath(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
tx := newTxCounter(t, suite.txConfig, 0, 1)
|
||||
tx := newTxCounter(t, suite.txConfig, suite.ac, 0, 1)
|
||||
txBytes, err := suite.txConfig.TxEncoder()(tx)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -1431,7 +1435,7 @@ func TestABCI_Proposal_HappyPath(t *testing.T) {
|
||||
_, err = suite.baseApp.CheckTx(&reqCheckTx)
|
||||
require.NoError(t, err)
|
||||
|
||||
tx2 := newTxCounter(t, suite.txConfig, 1, 1)
|
||||
tx2 := newTxCounter(t, suite.txConfig, suite.ac, 1, 1)
|
||||
|
||||
tx2Bytes, err := suite.txConfig.TxEncoder()(tx2)
|
||||
require.NoError(t, err)
|
||||
@ -1601,7 +1605,7 @@ func TestABCI_PrepareProposal_ReachedMaxBytes(t *testing.T) {
|
||||
var expectedTxBytes int64
|
||||
|
||||
for i := 0; i < 100; i++ {
|
||||
tx2 := newTxCounter(t, suite.txConfig, int64(i), int64(i))
|
||||
tx2 := newTxCounter(t, suite.txConfig, suite.ac, int64(i), int64(i))
|
||||
err := pool.Insert(sdk.Context{}, tx2)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -1637,7 +1641,7 @@ func TestABCI_PrepareProposal_BadEncoding(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
tx := newTxCounter(t, suite.txConfig, 0, 0)
|
||||
tx := newTxCounter(t, suite.txConfig, suite.ac, 0, 0)
|
||||
err = pool.Insert(sdk.Context{}, tx)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -1665,8 +1669,10 @@ func TestABCI_PrepareProposal_OverGasUnderBytes(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
// insert 100 txs, each with a gas limit of 10
|
||||
_, _, addr := testdata.KeyTestPubAddr()
|
||||
addrStr, err := suite.ac.BytesToString(addr)
|
||||
require.NoError(t, err)
|
||||
for i := int64(0); i < 100; i++ {
|
||||
msg := &baseapptestutil.MsgCounter{Counter: i, FailOnHandler: false, Signer: addr.String()}
|
||||
msg := &baseapptestutil.MsgCounter{Counter: i, FailOnHandler: false, Signer: addrStr}
|
||||
msgs := []sdk.Msg{msg}
|
||||
|
||||
builder := suite.txConfig.NewTxBuilder()
|
||||
@ -1705,8 +1711,10 @@ func TestABCI_PrepareProposal_MaxGas(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
// insert 100 txs, each with a gas limit of 10
|
||||
_, _, addr := testdata.KeyTestPubAddr()
|
||||
addrStr, err := suite.ac.BytesToString(addr)
|
||||
require.NoError(t, err)
|
||||
for i := int64(0); i < 100; i++ {
|
||||
msg := &baseapptestutil.MsgCounter{Counter: i, FailOnHandler: false, Signer: addr.String()}
|
||||
msg := &baseapptestutil.MsgCounter{Counter: i, FailOnHandler: false, Signer: addrStr}
|
||||
msgs := []sdk.Msg{msg}
|
||||
|
||||
builder := suite.txConfig.NewTxBuilder()
|
||||
@ -1744,7 +1752,7 @@ func TestABCI_PrepareProposal_Failures(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
tx := newTxCounter(t, suite.txConfig, 0, 0)
|
||||
tx := newTxCounter(t, suite.txConfig, suite.ac, 0, 0)
|
||||
txBytes, err := suite.txConfig.TxEncoder()(tx)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -1756,7 +1764,7 @@ func TestABCI_PrepareProposal_Failures(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.True(t, checkTxRes.IsOK())
|
||||
|
||||
failTx := newTxCounter(t, suite.txConfig, 1, 1)
|
||||
failTx := newTxCounter(t, suite.txConfig, suite.ac, 1, 1)
|
||||
failTx = setFailOnAnte(t, suite.txConfig, failTx, true)
|
||||
|
||||
err = pool.Insert(sdk.Context{}, failTx)
|
||||
@ -1813,7 +1821,7 @@ func TestABCI_PrepareProposal_VoteExtensions(t *testing.T) {
|
||||
pk, err := cryptocodec.FromCmtProtoPublicKey(tmPk)
|
||||
require.NoError(t, err)
|
||||
|
||||
consAddr := sdk.ConsAddress(addr.String())
|
||||
consAddr := sdk.ConsAddress(addr)
|
||||
valStore.EXPECT().GetPubKeyByConsAddr(gomock.Any(), consAddr.Bytes()).Return(pk, nil)
|
||||
|
||||
// set up baseapp
|
||||
@ -2395,7 +2403,7 @@ func TestOptimisticExecution(t *testing.T) {
|
||||
|
||||
// run 50 blocks
|
||||
for i := 0; i < 50; i++ {
|
||||
tx := newTxCounter(t, suite.txConfig, 0, 1)
|
||||
tx := newTxCounter(t, suite.txConfig, suite.ac, 0, 1)
|
||||
txBytes, err := suite.txConfig.TxEncoder()(tx)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -2453,7 +2461,7 @@ func TestABCI_Proposal_FailReCheckTx(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
tx := newTxCounter(t, suite.txConfig, 0, 1)
|
||||
tx := newTxCounter(t, suite.txConfig, suite.ac, 0, 1)
|
||||
txBytes, err := suite.txConfig.TxEncoder()(tx)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -2464,7 +2472,7 @@ func TestABCI_Proposal_FailReCheckTx(t *testing.T) {
|
||||
_, err = suite.baseApp.CheckTx(&reqCheckTx)
|
||||
require.NoError(t, err)
|
||||
|
||||
tx2 := newTxCounter(t, suite.txConfig, 1, 1)
|
||||
tx2 := newTxCounter(t, suite.txConfig, suite.ac, 1, 1)
|
||||
|
||||
tx2Bytes, err := suite.txConfig.TxEncoder()(tx2)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -304,9 +304,10 @@ func (h *DefaultProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHan
|
||||
shouldAdd := true
|
||||
txSignersSeqs := make(map[string]uint64)
|
||||
for _, signer := range signerData {
|
||||
seq, ok := selectedTxsSignersSeqs[signer.Signer.String()]
|
||||
signerKey := string(signer.Signer)
|
||||
seq, ok := selectedTxsSignersSeqs[signerKey]
|
||||
if !ok {
|
||||
txSignersSeqs[signer.Signer.String()] = signer.Sequence
|
||||
txSignersSeqs[signerKey] = signer.Sequence
|
||||
continue
|
||||
}
|
||||
|
||||
@ -317,7 +318,7 @@ func (h *DefaultProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHan
|
||||
shouldAdd = false
|
||||
break
|
||||
}
|
||||
txSignersSeqs[signer.Signer.String()] = signer.Sequence
|
||||
txSignersSeqs[signerKey] = signer.Sequence
|
||||
}
|
||||
if !shouldAdd {
|
||||
return true
|
||||
|
||||
@ -18,6 +18,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"cosmossdk.io/core/address"
|
||||
"cosmossdk.io/core/comet"
|
||||
"cosmossdk.io/core/header"
|
||||
"cosmossdk.io/log"
|
||||
@ -485,9 +486,11 @@ func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_NoOpMempoolTxSelection()
|
||||
|
||||
// build a tx
|
||||
_, _, addr := testdata.KeyTestPubAddr()
|
||||
addrStr, err := signingCtx.AddressCodec().BytesToString(addr)
|
||||
require.NoError(s.T(), err)
|
||||
builder := txConfig.NewTxBuilder()
|
||||
s.Require().NoError(builder.SetMsgs(
|
||||
&baseapptestutil.MsgCounter{Counter: 0, FailOnHandler: false, Signer: addr.String()},
|
||||
&baseapptestutil.MsgCounter{Counter: 0, FailOnHandler: false, Signer: addrStr},
|
||||
))
|
||||
builder.SetGasLimit(100)
|
||||
setTxSignature(s.T(), builder, 0)
|
||||
@ -592,24 +595,24 @@ func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_PriorityNonceMempoolTxSe
|
||||
|
||||
testTxs := []testTx{
|
||||
// test 1
|
||||
{tx: buildMsg(s.T(), txConfig, []byte(`0`), [][]byte{secret1}, []uint64{1}), priority: 10},
|
||||
{tx: buildMsg(s.T(), txConfig, []byte(`12345678910`), [][]byte{secret1}, []uint64{2}), priority: 10},
|
||||
{tx: buildMsg(s.T(), txConfig, []byte(`22`), [][]byte{secret1}, []uint64{3}), priority: 10},
|
||||
{tx: buildMsg(s.T(), txConfig, []byte(`32`), [][]byte{secret2}, []uint64{1}), priority: 8},
|
||||
{tx: buildMsg(s.T(), txConfig, signingCtx.AddressCodec(), []byte(`0`), [][]byte{secret1}, []uint64{1}), priority: 10},
|
||||
{tx: buildMsg(s.T(), txConfig, signingCtx.AddressCodec(), []byte(`12345678910`), [][]byte{secret1}, []uint64{2}), priority: 10},
|
||||
{tx: buildMsg(s.T(), txConfig, signingCtx.AddressCodec(), []byte(`22`), [][]byte{secret1}, []uint64{3}), priority: 10},
|
||||
{tx: buildMsg(s.T(), txConfig, signingCtx.AddressCodec(), []byte(`32`), [][]byte{secret2}, []uint64{1}), priority: 8},
|
||||
// test 2
|
||||
{tx: buildMsg(s.T(), txConfig, []byte(`4`), [][]byte{secret1, secret2}, []uint64{3, 3}), priority: 10},
|
||||
{tx: buildMsg(s.T(), txConfig, []byte(`52345678910`), [][]byte{secret1, secret3}, []uint64{4, 3}), priority: 10},
|
||||
{tx: buildMsg(s.T(), txConfig, []byte(`62`), [][]byte{secret1, secret4}, []uint64{5, 3}), priority: 8},
|
||||
{tx: buildMsg(s.T(), txConfig, []byte(`72`), [][]byte{secret3, secret5}, []uint64{4, 3}), priority: 8},
|
||||
{tx: buildMsg(s.T(), txConfig, []byte(`82`), [][]byte{secret2, secret6}, []uint64{4, 3}), priority: 8},
|
||||
{tx: buildMsg(s.T(), txConfig, signingCtx.AddressCodec(), []byte(`4`), [][]byte{secret1, secret2}, []uint64{3, 3}), priority: 10},
|
||||
{tx: buildMsg(s.T(), txConfig, signingCtx.AddressCodec(), []byte(`52345678910`), [][]byte{secret1, secret3}, []uint64{4, 3}), priority: 10},
|
||||
{tx: buildMsg(s.T(), txConfig, signingCtx.AddressCodec(), []byte(`62`), [][]byte{secret1, secret4}, []uint64{5, 3}), priority: 8},
|
||||
{tx: buildMsg(s.T(), txConfig, signingCtx.AddressCodec(), []byte(`72`), [][]byte{secret3, secret5}, []uint64{4, 3}), priority: 8},
|
||||
{tx: buildMsg(s.T(), txConfig, signingCtx.AddressCodec(), []byte(`82`), [][]byte{secret2, secret6}, []uint64{4, 3}), priority: 8},
|
||||
// test 3
|
||||
{tx: buildMsg(s.T(), txConfig, []byte(`9`), [][]byte{secret3, secret4}, []uint64{3, 3}), priority: 10},
|
||||
{tx: buildMsg(s.T(), txConfig, []byte(`1052345678910`), [][]byte{secret1, secret2}, []uint64{4, 4}), priority: 8},
|
||||
{tx: buildMsg(s.T(), txConfig, []byte(`11`), [][]byte{secret1, secret2}, []uint64{5, 5}), priority: 8},
|
||||
{tx: buildMsg(s.T(), txConfig, signingCtx.AddressCodec(), []byte(`9`), [][]byte{secret3, secret4}, []uint64{3, 3}), priority: 10},
|
||||
{tx: buildMsg(s.T(), txConfig, signingCtx.AddressCodec(), []byte(`1052345678910`), [][]byte{secret1, secret2}, []uint64{4, 4}), priority: 8},
|
||||
{tx: buildMsg(s.T(), txConfig, signingCtx.AddressCodec(), []byte(`11`), [][]byte{secret1, secret2}, []uint64{5, 5}), priority: 8},
|
||||
// test 4
|
||||
{tx: buildMsg(s.T(), txConfig, []byte(`1252345678910`), [][]byte{secret1}, []uint64{3}), priority: 10},
|
||||
{tx: buildMsg(s.T(), txConfig, []byte(`13`), [][]byte{secret1}, []uint64{5}), priority: 10},
|
||||
{tx: buildMsg(s.T(), txConfig, []byte(`14`), [][]byte{secret1}, []uint64{6}), priority: 8},
|
||||
{tx: buildMsg(s.T(), txConfig, signingCtx.AddressCodec(), []byte(`1252345678910`), [][]byte{secret1}, []uint64{3}), priority: 10},
|
||||
{tx: buildMsg(s.T(), txConfig, signingCtx.AddressCodec(), []byte(`13`), [][]byte{secret1}, []uint64{5}), priority: 10},
|
||||
{tx: buildMsg(s.T(), txConfig, signingCtx.AddressCodec(), []byte(`14`), [][]byte{secret1}, []uint64{6}), priority: 8},
|
||||
}
|
||||
|
||||
for i := range testTxs {
|
||||
@ -718,7 +721,7 @@ func marshalDelimitedFn(msg proto.Message) ([]byte, error) {
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func buildMsg(t *testing.T, txConfig client.TxConfig, value []byte, secrets [][]byte, nonces []uint64) sdk.Tx {
|
||||
func buildMsg(t *testing.T, txConfig client.TxConfig, ac address.Codec, value []byte, secrets [][]byte, nonces []uint64) sdk.Tx {
|
||||
t.Helper()
|
||||
builder := txConfig.NewTxBuilder()
|
||||
|
||||
@ -735,9 +738,12 @@ func buildMsg(t *testing.T, txConfig client.TxConfig, value []byte, secrets [][]
|
||||
})
|
||||
}
|
||||
|
||||
addr, err := ac.BytesToString(signatures[0].PubKey.Bytes())
|
||||
require.NoError(t, err)
|
||||
|
||||
_ = builder.SetMsgs(
|
||||
&baseapptestutil.MsgKeyValue{
|
||||
Signer: sdk.AccAddress(signatures[0].PubKey.Bytes()).String(),
|
||||
Signer: addr,
|
||||
Value: value,
|
||||
},
|
||||
)
|
||||
|
||||
@ -14,6 +14,7 @@ import (
|
||||
dbm "github.com/cosmos/cosmos-db"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"cosmossdk.io/core/address"
|
||||
corestore "cosmossdk.io/core/store"
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
"cosmossdk.io/log"
|
||||
@ -50,6 +51,7 @@ type (
|
||||
cdc *codec.ProtoCodec
|
||||
txConfig client.TxConfig
|
||||
logBuffer *bytes.Buffer
|
||||
ac address.Codec
|
||||
}
|
||||
|
||||
SnapshotsConfig struct {
|
||||
@ -91,6 +93,7 @@ func NewBaseAppSuite(t *testing.T, opts ...func(*baseapp.BaseApp)) *BaseAppSuite
|
||||
cdc: cdc,
|
||||
txConfig: txConfig,
|
||||
logBuffer: logBuffer,
|
||||
ac: cdc.InterfaceRegistry().SigningContext().AddressCodec(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,7 +155,10 @@ func NewBaseAppSuiteWithSnapshots(t *testing.T, cfg SnapshotsConfig, opts ...fun
|
||||
_, err := r.Read(value)
|
||||
require.NoError(t, err)
|
||||
|
||||
msgs = append(msgs, &baseapptestutil.MsgKeyValue{Key: key, Value: value, Signer: addr.String()})
|
||||
addrStr, err := suite.ac.BytesToString(addr)
|
||||
require.NoError(t, err)
|
||||
|
||||
msgs = append(msgs, &baseapptestutil.MsgKeyValue{Key: key, Value: value, Signer: addrStr})
|
||||
keyCounter++
|
||||
}
|
||||
|
||||
@ -226,7 +232,7 @@ func TestAnteHandlerGasMeter(t *testing.T) {
|
||||
deliverKey := []byte("deliver-key")
|
||||
baseapptestutil.RegisterCounterServer(suite.baseApp.MsgServiceRouter(), CounterServerImpl{t, capKey1, deliverKey})
|
||||
|
||||
tx := newTxCounter(t, suite.txConfig, 0, 0)
|
||||
tx := newTxCounter(t, suite.txConfig, suite.ac, 0, 0)
|
||||
txBytes, err := suite.txConfig.TxEncoder()(tx)
|
||||
require.NoError(t, err)
|
||||
_, err = suite.baseApp.FinalizeBlock(&abci.FinalizeBlockRequest{Height: 1, Txs: [][]byte{txBytes}})
|
||||
@ -508,7 +514,7 @@ func TestTxDecoder(t *testing.T) {
|
||||
// patch in TxConfig instead of using an output from x/auth/tx
|
||||
txConfig := authtx.NewTxConfig(cdc, signingCtx.AddressCodec(), signingCtx.ValidatorAddressCodec(), authtx.DefaultSignModes)
|
||||
|
||||
tx := newTxCounter(t, txConfig, 1, 0)
|
||||
tx := newTxCounter(t, txConfig, signingCtx.AddressCodec(), 1, 0)
|
||||
txBytes, err := txConfig.TxEncoder()(tx)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -552,7 +558,7 @@ func TestCustomRunTxPanicHandler(t *testing.T) {
|
||||
|
||||
// transaction should panic with custom handler above
|
||||
{
|
||||
tx := newTxCounter(t, suite.txConfig, 0, 0)
|
||||
tx := newTxCounter(t, suite.txConfig, suite.ac, 0, 0)
|
||||
|
||||
require.PanicsWithValue(t, customPanicMsg, func() {
|
||||
bz, err := suite.txConfig.TxEncoder()(tx)
|
||||
@ -582,7 +588,7 @@ func TestBaseAppAnteHandler(t *testing.T) {
|
||||
//
|
||||
// NOTE: State should not be mutated here. This will be implicitly checked by
|
||||
// the next txs ante handler execution (anteHandlerTxTest).
|
||||
tx := newTxCounter(t, suite.txConfig, 0, 0)
|
||||
tx := newTxCounter(t, suite.txConfig, suite.ac, 0, 0)
|
||||
tx = setFailOnAnte(t, suite.txConfig, tx, true)
|
||||
|
||||
txBytes, err := suite.txConfig.TxEncoder()(tx)
|
||||
@ -599,8 +605,8 @@ func TestBaseAppAnteHandler(t *testing.T) {
|
||||
|
||||
// execute at tx that will pass the ante handler (the checkTx state should
|
||||
// mutate) but will fail the message handler
|
||||
tx = newTxCounter(t, suite.txConfig, 0, 0)
|
||||
tx = setFailOnHandler(t, suite.txConfig, tx, true)
|
||||
tx = newTxCounter(t, suite.txConfig, suite.ac, 0, 0)
|
||||
tx = setFailOnHandler(t, suite.txConfig, suite.ac, tx, true)
|
||||
|
||||
txBytes, err = suite.txConfig.TxEncoder()(tx)
|
||||
require.NoError(t, err)
|
||||
@ -617,7 +623,7 @@ func TestBaseAppAnteHandler(t *testing.T) {
|
||||
|
||||
// Execute a successful ante handler and message execution where state is
|
||||
// implicitly checked by previous tx executions.
|
||||
tx = newTxCounter(t, suite.txConfig, 1, 0)
|
||||
tx = newTxCounter(t, suite.txConfig, suite.ac, 1, 0)
|
||||
|
||||
txBytes, err = suite.txConfig.TxEncoder()(tx)
|
||||
require.NoError(t, err)
|
||||
@ -657,7 +663,7 @@ func TestBaseAppPostHandler(t *testing.T) {
|
||||
//
|
||||
// NOTE: State should not be mutated here. This will be implicitly checked by
|
||||
// the next txs ante handler execution (anteHandlerTxTest).
|
||||
tx := newTxCounter(t, suite.txConfig, 0, 0)
|
||||
tx := newTxCounter(t, suite.txConfig, suite.ac, 0, 0)
|
||||
txBytes, err := suite.txConfig.TxEncoder()(tx)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -671,7 +677,7 @@ func TestBaseAppPostHandler(t *testing.T) {
|
||||
|
||||
// It should also run on failed message execution
|
||||
postHandlerRun = false
|
||||
tx = setFailOnHandler(t, suite.txConfig, tx, true)
|
||||
tx = setFailOnHandler(t, suite.txConfig, suite.ac, tx, true)
|
||||
txBytes, err = suite.txConfig.TxEncoder()(tx)
|
||||
require.NoError(t, err)
|
||||
res, err = suite.baseApp.FinalizeBlock(&abci.FinalizeBlockRequest{Height: 1, Txs: [][]byte{txBytes}})
|
||||
@ -682,7 +688,7 @@ func TestBaseAppPostHandler(t *testing.T) {
|
||||
require.True(t, postHandlerRun)
|
||||
|
||||
// regression test, should not panic when runMsgs fails
|
||||
tx = wonkyMsg(t, suite.txConfig, tx)
|
||||
tx = wonkyMsg(t, suite.txConfig, suite.ac, tx)
|
||||
txBytes, err = suite.txConfig.TxEncoder()(tx)
|
||||
require.NoError(t, err)
|
||||
_, err = suite.baseApp.FinalizeBlock(&abci.FinalizeBlockRequest{Height: 1, Txs: [][]byte{txBytes}})
|
||||
@ -903,7 +909,7 @@ func TestABCI_FinalizeWithInvalidTX(t *testing.T) {
|
||||
_, err := suite.baseApp.InitChain(&abci.InitChainRequest{ConsensusParams: &cmtproto.ConsensusParams{}})
|
||||
require.NoError(t, err)
|
||||
|
||||
tx := newTxCounter(t, suite.txConfig, 0, 0)
|
||||
tx := newTxCounter(t, suite.txConfig, suite.ac, 0, 0)
|
||||
bz, err := suite.txConfig.TxEncoder()(tx)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
@ -155,9 +155,11 @@ func TestMsgService(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, addr := testdata.KeyTestPubAddr()
|
||||
addrStr, err := signingCtx.AddressCodec().BytesToString(addr)
|
||||
require.NoError(t, err)
|
||||
msg := testdata.MsgCreateDog{
|
||||
Dog: &testdata.Dog{Name: "Spot"},
|
||||
Owner: addr.String(),
|
||||
Owner: addrStr,
|
||||
}
|
||||
|
||||
txBuilder := txConfig.NewTxBuilder()
|
||||
|
||||
@ -74,7 +74,7 @@ func TestABCI_MultiListener_StateChanges(t *testing.T) {
|
||||
|
||||
for i := 0; i < txPerHeight; i++ {
|
||||
counter := int64(blockN*txPerHeight + i)
|
||||
tx := newTxCounter(t, suite.txConfig, counter, counter)
|
||||
tx := newTxCounter(t, suite.txConfig, suite.ac, counter, counter)
|
||||
|
||||
txBytes, err := suite.txConfig.TxEncoder()(tx)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -294,17 +294,19 @@ func parseTxMemo(t *testing.T, tx sdk.Tx) (counter int64, failOnAnte bool) {
|
||||
return counter, failOnAnte
|
||||
}
|
||||
|
||||
func newTxCounter(t *testing.T, cfg client.TxConfig, counter int64, msgCounters ...int64) signing.Tx {
|
||||
func newTxCounter(t *testing.T, cfg client.TxConfig, ac address.Codec, counter int64, msgCounters ...int64) signing.Tx {
|
||||
t.Helper()
|
||||
_, _, addr := testdata.KeyTestPubAddr()
|
||||
addrStr, err := ac.BytesToString(addr)
|
||||
require.NoError(t, err)
|
||||
msgs := make([]sdk.Msg, 0, len(msgCounters))
|
||||
for _, c := range msgCounters {
|
||||
msg := &baseapptestutil.MsgCounter{Counter: c, FailOnHandler: false, Signer: addr.String()}
|
||||
msg := &baseapptestutil.MsgCounter{Counter: c, FailOnHandler: false, Signer: addrStr}
|
||||
msgs = append(msgs, msg)
|
||||
}
|
||||
|
||||
builder := cfg.NewTxBuilder()
|
||||
err := builder.SetMsgs(msgs...)
|
||||
err = builder.SetMsgs(msgs...)
|
||||
require.NoError(t, err)
|
||||
builder.SetMemo("counter=" + strconv.FormatInt(counter, 10) + "&failOnAnte=false")
|
||||
setTxSignature(t, builder, uint64(counter))
|
||||
@ -342,37 +344,41 @@ func setFailOnAnte(t *testing.T, cfg client.TxConfig, tx signing.Tx, failOnAnte
|
||||
return builder.GetTx()
|
||||
}
|
||||
|
||||
func setFailOnHandler(t *testing.T, cfg client.TxConfig, tx signing.Tx, fail bool) signing.Tx {
|
||||
func setFailOnHandler(t *testing.T, cfg client.TxConfig, ac address.Codec, tx signing.Tx, fail bool) signing.Tx {
|
||||
t.Helper()
|
||||
builder := cfg.NewTxBuilder()
|
||||
builder.SetMemo(tx.GetMemo())
|
||||
|
||||
msgs := tx.GetMsgs()
|
||||
addr, err := ac.BytesToString(sdk.AccAddress("addr"))
|
||||
require.NoError(t, err)
|
||||
for i, msg := range msgs {
|
||||
msgs[i] = &baseapptestutil.MsgCounter{
|
||||
Counter: msg.(*baseapptestutil.MsgCounter).Counter,
|
||||
FailOnHandler: fail,
|
||||
Signer: sdk.AccAddress("addr").String(),
|
||||
Signer: addr,
|
||||
}
|
||||
}
|
||||
|
||||
err := builder.SetMsgs(msgs...)
|
||||
err = builder.SetMsgs(msgs...)
|
||||
require.NoError(t, err)
|
||||
return builder.GetTx()
|
||||
}
|
||||
|
||||
// wonkyMsg is to be used to run a MsgCounter2 message when the MsgCounter2 handler is not registered.
|
||||
func wonkyMsg(t *testing.T, cfg client.TxConfig, tx signing.Tx) signing.Tx {
|
||||
func wonkyMsg(t *testing.T, cfg client.TxConfig, ac address.Codec, tx signing.Tx) signing.Tx {
|
||||
t.Helper()
|
||||
builder := cfg.NewTxBuilder()
|
||||
builder.SetMemo(tx.GetMemo())
|
||||
|
||||
msgs := tx.GetMsgs()
|
||||
addr, err := ac.BytesToString(sdk.AccAddress("wonky"))
|
||||
require.NoError(t, err)
|
||||
msgs = append(msgs, &baseapptestutil.MsgCounter2{
|
||||
Signer: sdk.AccAddress("wonky").String(),
|
||||
Signer: addr,
|
||||
})
|
||||
|
||||
err := builder.SetMsgs(msgs...)
|
||||
err = builder.SetMsgs(msgs...)
|
||||
require.NoError(t, err)
|
||||
return builder.GetTx()
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user