diff --git a/app/test/block_production_test.go b/app/test/block_production_test.go index f8bfb5435a..2b3418677c 100644 --- a/app/test/block_production_test.go +++ b/app/test/block_production_test.go @@ -1,4 +1,4 @@ -package app +package app_test import ( "testing" diff --git a/app/test/integration_test.go b/app/test/integration_test.go index 775dfff370..ba2d1ab516 100644 --- a/app/test/integration_test.go +++ b/app/test/integration_test.go @@ -7,7 +7,6 @@ import ( "fmt" "os" "testing" - "time" "github.com/celestiaorg/celestia-app/test/util/blobfactory" "github.com/celestiaorg/celestia-app/test/util/testfactory" @@ -16,7 +15,6 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/types/errors" "github.com/stretchr/testify/suite" @@ -31,7 +29,6 @@ import ( "github.com/celestiaorg/celestia-app/pkg/user" blobtypes "github.com/celestiaorg/celestia-app/x/blob/types" - sdk "github.com/cosmos/cosmos-sdk/types" abci "github.com/tendermint/tendermint/abci/types" tmrand "github.com/tendermint/tendermint/libs/rand" coretypes "github.com/tendermint/tendermint/types" @@ -54,12 +51,7 @@ type IntegrationTestSuite struct { func (s *IntegrationTestSuite) SetupSuite() { t := s.T() - - numAccounts := 142 - s.accounts = make([]string, numAccounts) - for i := 0; i < numAccounts; i++ { - s.accounts[i] = tmrand.Str(20) - } + s.accounts = testnode.RandomAccounts(142) cfg := testnode.DefaultConfig().WithFundedAccounts(s.accounts...) @@ -80,47 +72,41 @@ func (s *IntegrationTestSuite) SetupSuite() { func (s *IntegrationTestSuite) TestMaxBlockSize() { t := s.T() - // tendermint's default tx size limit is 1Mb, so we get close to that - equallySized1MbTxGen := func(c client.Context) []coretypes.Tx { + singleBlobTxGen := func(c client.Context) []coretypes.Tx { return blobfactory.RandBlobTxsWithAccounts( s.ecfg, tmrand.NewRand(), s.cctx.Keyring, c.GRPCClient, - 950000, + 600*kibibyte, 1, false, s.accounts[:20], ) } - // Tendermint's default tx size limit is 1 MiB, so we get close to that by - // generating transactions of size 600 KB because 3 blobs per transaction * - // 200,000 bytes each = 600,000 total bytes = 600 KB per transaction. - randMultiBlob1MbTxGen := func(c client.Context) []coretypes.Tx { + // This tx generator generates txs that contain 3 blobs each of 200 KiB so + // 600 KiB total per transaction. + multiBlobTxGen := func(c client.Context) []coretypes.Tx { return blobfactory.RandBlobTxsWithAccounts( s.ecfg, tmrand.NewRand(), s.cctx.Keyring, c.GRPCClient, - 200000, // 200 KB + 200*kibibyte, 3, false, s.accounts[20:40], ) } - // Generate 80 randomly sized txs (max size == 50 KB). Generate these - // transactions using some of the same accounts as the previous generator to - // ensure that the sequence number is being utilized correctly in blob - // txs - randoTxGen := func(c client.Context) []coretypes.Tx { + randomTxGen := func(c client.Context) []coretypes.Tx { return blobfactory.RandBlobTxsWithAccounts( s.ecfg, tmrand.NewRand(), s.cctx.Keyring, c.GRPCClient, - 50000, + 50*kibibyte, 8, true, s.accounts[40:120], @@ -131,20 +117,10 @@ func (s *IntegrationTestSuite) TestMaxBlockSize() { name string txGenerator func(clientCtx client.Context) []coretypes.Tx } - tests := []test{ - { - "20 1Mb txs", - equallySized1MbTxGen, - }, - { - "20 1Mb multiblob txs", - randMultiBlob1MbTxGen, - }, - { - "80 random txs", - randoTxGen, - }, + {"singleBlobTxGen", singleBlobTxGen}, + {"multiBlobTxGen", multiBlobTxGen}, + {"randomTxGen", randomTxGen}, } for _, tc := range tests { s.Run(tc.name, func() { @@ -152,6 +128,10 @@ func (s *IntegrationTestSuite) TestMaxBlockSize() { hashes := make([]string, len(txs)) for i, tx := range txs { + // The default CometBFT mempool MaxTxBytes is 1 MiB so the generators in + // this test must create transactions that are smaller than that. + require.LessOrEqual(t, len(tx), 1*mebibyte) + res, err := s.cctx.Context.BroadcastTxSync(tx) require.NoError(t, err) assert.Equal(t, abci.CodeTypeOK, res.Code, res.RawLog) @@ -167,10 +147,7 @@ func (s *IntegrationTestSuite) TestMaxBlockSize() { for _, hash := range hashes { resp, err := testnode.QueryTx(s.cctx.Context, hash, true) require.NoError(t, err) - assert.NotNil(t, resp) - if resp == nil { - continue - } + require.NotNil(t, resp) require.Equal(t, abci.CodeTypeOK, resp.TxResult.Code, resp.TxResult.Log) heights[resp.Height]++ // ensure that some gas was used @@ -195,7 +172,7 @@ func (s *IntegrationTestSuite) TestMaxBlockSize() { require.EqualValues(t, v2.Version, blockRes.Block.Header.Version.App) sizes = append(sizes, size) - ExtendBlobTest(t, blockRes.Block) + ExtendBlockTest(t, blockRes.Block) } // ensure that at least one of the blocks used the max square size assert.Contains(t, sizes, uint64(appconsts.DefaultGovMaxSquareSize)) @@ -204,71 +181,6 @@ func (s *IntegrationTestSuite) TestMaxBlockSize() { } } -func (s *IntegrationTestSuite) TestSubmitPayForBlob() { - t := s.T() - ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) - - mustNewBlob := func(ns appns.Namespace, data []byte, shareVersion uint8) *blob.Blob { - return blob.New(ns, data, shareVersion) - } - - type test struct { - name string - blob *blob.Blob - opts []user.TxOption - } - - tests := []test{ - { - "small random typical", - mustNewBlob(ns1, tmrand.Bytes(3000), appconsts.ShareVersionZero), - []user.TxOption{ - user.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(app.BondDenom, sdk.NewInt(1)))), - user.SetGasLimit(1_000_000_000), - }, - }, - { - "large random typical", - mustNewBlob(ns1, tmrand.Bytes(350000), appconsts.ShareVersionZero), - []user.TxOption{ - user.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(app.BondDenom, sdk.NewInt(10)))), - user.SetGasLimit(1_000_000_000), - }, - }, - { - "medium random with memo", - mustNewBlob(ns1, tmrand.Bytes(100000), appconsts.ShareVersionZero), - []user.TxOption{ - user.SetMemo("lol I could stick the rollup block here if I wanted to"), - user.SetGasLimit(1_000_000_000), - }, - }, - { - "medium random with timeout height", - mustNewBlob(ns1, tmrand.Bytes(100000), appconsts.ShareVersionZero), - []user.TxOption{ - user.SetTimeoutHeight(10000), - user.SetGasLimit(1_000_000_000), - }, - }, - } - for _, tc := range tests { - s.Run(tc.name, func() { - // occasionally this test will error that the mempool is full (code - // 20) so we wait a few blocks for the txs to clear - require.NoError(t, s.cctx.WaitForBlocks(3)) - - addr := testfactory.GetAddress(s.cctx.Keyring, s.accounts[141]) - signer, err := user.SetupSigner(s.cctx.GoContext(), s.cctx.Keyring, s.cctx.GRPCClient, addr, s.ecfg) - require.NoError(t, err) - res, err := signer.SubmitPayForBlob(context.TODO(), []*blob.Blob{tc.blob, tc.blob}, tc.opts...) - require.NoError(t, err) - require.NotNil(t, res) - require.Equal(t, abci.CodeTypeOK, res.Code, res.Logs) - }) - } -} - func (s *IntegrationTestSuite) TestUnwrappedPFBRejection() { t := s.T() @@ -294,13 +206,12 @@ func (s *IntegrationTestSuite) TestUnwrappedPFBRejection() { func (s *IntegrationTestSuite) TestShareInclusionProof() { t := s.T() - // generate 100 randomly sized txs (max size == 100kb) txs := blobfactory.RandBlobTxsWithAccounts( s.ecfg, tmrand.NewRand(), s.cctx.Keyring, s.cctx.GRPCClient, - 100000, + 100*kibibyte, 1, true, s.accounts[120:140], @@ -348,9 +259,9 @@ func (s *IntegrationTestSuite) TestShareInclusionProof() { } } -// ExtendBlobTest re-extends the block and compares the data roots to ensure +// ExtendBlockTest re-extends the block and compares the data roots to ensure // that the public functions for extending the block are working correctly. -func ExtendBlobTest(t *testing.T, block *coretypes.Block) { +func ExtendBlockTest(t *testing.T, block *coretypes.Block) { eds, err := app.ExtendBlock(block.Data, block.Header.Version.App) require.NoError(t, err) dah, err := da.NewDataAvailabilityHeader(eds) @@ -370,71 +281,12 @@ func (s *IntegrationTestSuite) TestEmptyBlock() { blockRes, err := s.cctx.Client.Block(s.cctx.GoContext(), &h) require.NoError(t, err) require.True(t, app.IsEmptyBlock(blockRes.Block.Data, blockRes.Block.Header.Version.App)) - ExtendBlobTest(t, blockRes.Block) - } -} - -// TestSubmitPayForBlob_blobSizes verifies the tx response ABCI code when -// SubmitPayForBlob is invoked with different blob sizes. -func (s *IntegrationTestSuite) TestSubmitPayForBlob_blobSizes() { - t := s.T() - require.NoError(t, s.cctx.WaitForBlocks(3)) - addr := testfactory.GetAddress(s.cctx.Keyring, s.accounts[141]) - signer, err := user.SetupSigner(s.cctx.GoContext(), s.cctx.Keyring, s.cctx.GRPCClient, addr, s.ecfg) - require.NoError(t, err) - - type testCase struct { - name string - blob *blob.Blob - // txResponseCode is the expected tx response ABCI code. - txResponseCode uint32 - } - testCases := []testCase{ - { - name: "1,000 byte blob", - blob: mustNewBlob(1_000), - txResponseCode: abci.CodeTypeOK, - }, - { - name: "10,000 byte blob", - blob: mustNewBlob(10_000), - txResponseCode: abci.CodeTypeOK, - }, - { - name: "100,000 byte blob", - blob: mustNewBlob(100_000), - txResponseCode: abci.CodeTypeOK, - }, - { - name: "1,000,000 byte blob", - blob: mustNewBlob(1_000_000), - txResponseCode: abci.CodeTypeOK, - }, - { - name: "10,000,000 byte blob returns err tx too large", - blob: mustNewBlob(10_000_000), - txResponseCode: errors.ErrTxTooLarge.ABCICode(), - }, - } - - for _, tc := range testCases { - s.Run(tc.name, func() { - subCtx, cancel := context.WithTimeout(s.cctx.GoContext(), 30*time.Second) - defer cancel() - res, err := signer.SubmitPayForBlob(subCtx, []*blob.Blob{tc.blob}, user.SetGasLimit(1_000_000_000)) - if tc.txResponseCode == abci.CodeTypeOK { - require.NoError(t, err) - } else { - require.Error(t, err) - } - require.NotNil(t, res) - require.Equal(t, tc.txResponseCode, res.Code, res.Logs) - }) + ExtendBlockTest(t, blockRes.Block) } } -func mustNewBlob(blobSize int) *blob.Blob { - ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) - data := tmrand.Bytes(blobSize) - return blob.New(ns1, data, appconsts.ShareVersionZero) +func newBlobWithSize(size int) *blob.Blob { + ns := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) + data := tmrand.Bytes(size) + return blob.New(ns, data, appconsts.ShareVersionZero) } diff --git a/app/test/max_total_blob_size_test.go b/app/test/max_total_blob_size_test.go index 8c7875f2f9..9c9bafcef7 100644 --- a/app/test/max_total_blob_size_test.go +++ b/app/test/max_total_blob_size_test.go @@ -7,22 +7,13 @@ import ( "github.com/celestiaorg/celestia-app/app" "github.com/celestiaorg/celestia-app/app/encoding" - "github.com/celestiaorg/celestia-app/pkg/appconsts" "github.com/celestiaorg/celestia-app/pkg/blob" - "github.com/celestiaorg/celestia-app/pkg/square" "github.com/celestiaorg/celestia-app/pkg/user" "github.com/celestiaorg/celestia-app/test/util/testfactory" "github.com/celestiaorg/celestia-app/test/util/testnode" blobtypes "github.com/celestiaorg/celestia-app/x/blob/types" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - abci "github.com/tendermint/tendermint/abci/types" -) - -const ( - mebibyte = 1_048_576 // one mebibyte in bytes - squareSize = 64 ) func TestMaxTotalBlobSizeSuite(t *testing.T) { @@ -63,9 +54,9 @@ func (s *MaxTotalBlobSizeSuite) SetupSuite() { require.NoError(t, cctx.WaitForNextBlock()) } -// TestSubmitPayForBlob_blobSizes verifies the tx response ABCI code when -// SubmitPayForBlob is invoked with different blob sizes. -func (s *MaxTotalBlobSizeSuite) TestSubmitPayForBlob_blobSizes() { +// TestErrTotalBlobSizeTooLarge verifies that submitting a 2 MiB blob hits +// ErrTotalBlobSizeTooLarge. +func (s *MaxTotalBlobSizeSuite) TestErrTotalBlobSizeTooLarge() { t := s.T() type testCase struct { @@ -75,19 +66,9 @@ func (s *MaxTotalBlobSizeSuite) TestSubmitPayForBlob_blobSizes() { want uint32 } testCases := []testCase{ - { - name: "1 byte blob", - blob: mustNewBlob(1), - want: abci.CodeTypeOK, - }, - { - name: "1 mebibyte blob", - blob: mustNewBlob(mebibyte), - want: abci.CodeTypeOK, - }, { name: "2 mebibyte blob", - blob: mustNewBlob(2 * mebibyte), + blob: newBlobWithSize(2 * mebibyte), want: blobtypes.ErrTotalBlobSizeTooLarge.ABCICode(), }, } @@ -105,16 +86,6 @@ func (s *MaxTotalBlobSizeSuite) TestSubmitPayForBlob_blobSizes() { require.NoError(t, err) require.NotNil(t, res) require.Equal(t, tc.want, res.Code, res.Logs) - - sq, err := square.Construct([][]byte{blobTx}, appconsts.LatestVersion, squareSize) - if tc.want == abci.CodeTypeOK { - // verify that if the tx was accepted, the blob can fit in a square - assert.NoError(t, err) - assert.False(t, sq.IsEmpty()) - } else { - // verify that if the tx was rejected, the blob can not fit in a square - assert.Error(t, err) - } }) } } diff --git a/app/test/square_size_test.go b/app/test/square_size_test.go index 0577cc635d..f2ebd07ca2 100644 --- a/app/test/square_size_test.go +++ b/app/test/square_size_test.go @@ -60,8 +60,7 @@ func (s *SquareSizeIntegrationTest) SetupSuite() { // TestSquareSizeUpperBound sets the app's params to specific sizes, then fills the // block with spam txs to measure that the desired max is getting hit -// The "_Flaky" suffix indicates that the test may fail non-deterministically especially when executed in CI. -func (s *SquareSizeIntegrationTest) TestSquareSizeUpperBound_Flaky() { +func (s *SquareSizeIntegrationTest) TestSquareSizeUpperBound() { t := s.T() type test struct { diff --git a/app/test/unit_test.go b/app/test/unit_test.go new file mode 100644 index 0000000000..83fa292438 --- /dev/null +++ b/app/test/unit_test.go @@ -0,0 +1,6 @@ +package app_test + +const ( + kibibyte = 1024 + mebibyte = 1024 * kibibyte +) diff --git a/pkg/square/square_test.go b/pkg/square/square_test.go index 798955dc3f..b3beb7dcb0 100644 --- a/pkg/square/square_test.go +++ b/pkg/square/square_test.go @@ -13,7 +13,7 @@ import ( "github.com/celestiaorg/celestia-app/pkg/blob" "github.com/celestiaorg/celestia-app/pkg/da" "github.com/celestiaorg/celestia-app/pkg/inclusion" - ns "github.com/celestiaorg/celestia-app/pkg/namespace" + appns "github.com/celestiaorg/celestia-app/pkg/namespace" "github.com/celestiaorg/celestia-app/pkg/shares" "github.com/celestiaorg/celestia-app/pkg/square" "github.com/celestiaorg/celestia-app/test/util/blobfactory" @@ -25,6 +25,10 @@ import ( coretypes "github.com/tendermint/tendermint/types" ) +const ( + mebibyte = 1_048_576 // one mebibyte in bytes +) + func TestSquareConstruction(t *testing.T) { rand := tmrand.NewRand() signer, err := testnode.NewOfflineSigner() @@ -42,6 +46,11 @@ func TestSquareConstruction(t *testing.T) { _, err = square.Construct(coretypes.Txs(pfbTxs).ToSliceOfBytes(), appconsts.LatestVersion, 2) require.Error(t, err) }) + t.Run("construction should fail if a single PFB tx contains a blob that is too large to fit in the square", func(t *testing.T) { + pfbTxs := blobfactory.RandBlobTxs(signer, rand, 1, 1, 2*mebibyte) + _, err := square.Construct(coretypes.Txs(pfbTxs).ToSliceOfBytes(), appconsts.LatestVersion, 64) + require.Error(t, err) + }) } func TestSquareTxShareRange(t *testing.T) { @@ -119,7 +128,7 @@ func TestSquareTxShareRange(t *testing.T) { // len(blobSizes[i]) number of blobs per BlobTx. Note: not suitable for using in // prepare or process proposal, as the signatures will be invalid since this // does not query for relevant account numbers or sequences. -func generateBlobTxsWithNamespaces(t *testing.T, namespaces []ns.Namespace, blobSizes [][]int) [][]byte { +func generateBlobTxsWithNamespaces(t *testing.T, namespaces []appns.Namespace, blobSizes [][]int) [][]byte { encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) const acc = "signer" kr, _ := testnode.NewKeyring(acc) @@ -134,12 +143,10 @@ func generateBlobTxsWithNamespaces(t *testing.T, namespaces []ns.Namespace, blob ) } -// The "_Flaky" suffix indicates that the test may fail non-deterministically especially when executed in CI. -func TestSquareBlobShareRange_Flaky(t *testing.T) { - rand := tmrand.NewRand() +func TestSquareBlobShareRange(t *testing.T) { signer, err := testnode.NewOfflineSigner() require.NoError(t, err) - txs := blobfactory.RandBlobTxsRandomlySized(signer, rand, 10, 1000, 10).ToSliceOfBytes() + txs := blobfactory.RandBlobTxsRandomlySized(signer, tmrand.NewRand(), 10, 1000, 10).ToSliceOfBytes() builder, err := square.NewBuilder(appconsts.DefaultSquareSizeUpperBound, appconsts.LatestVersion, txs...) require.NoError(t, err) @@ -153,6 +160,7 @@ func TestSquareBlobShareRange_Flaky(t *testing.T) { for blobIdx := range blobTx.Blobs { shareRange, err := square.BlobShareRange(txs, pfbIdx, blobIdx, appconsts.LatestVersion) require.NoError(t, err) + require.LessOrEqual(t, shareRange.End, len(dataSquare)) blobShares := dataSquare[shareRange.Start:shareRange.End] blobSharesBytes, err := rawData(blobShares) require.NoError(t, err) diff --git a/test/util/testnode/accounts.go b/test/util/testnode/accounts.go new file mode 100644 index 0000000000..d1eae0251b --- /dev/null +++ b/test/util/testnode/accounts.go @@ -0,0 +1,12 @@ +package testnode + +import tmrand "github.com/tendermint/tendermint/libs/rand" + +// RandomAccounts returns a list of n random accounts +func RandomAccounts(n int) (accounts []string) { + for i := 0; i < n; i++ { + account := tmrand.Str(20) + accounts = append(accounts, account) + } + return accounts +} diff --git a/test/util/testnode/accounts_test.go b/test/util/testnode/accounts_test.go new file mode 100644 index 0000000000..73dbee8687 --- /dev/null +++ b/test/util/testnode/accounts_test.go @@ -0,0 +1,13 @@ +package testnode + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestRandomAccounts(t *testing.T) { + got := RandomAccounts(2) + assert.Len(t, got, 2) + assert.NotEqual(t, got[0], got[1]) +} diff --git a/test/util/testnode/full_node_test.go b/test/util/testnode/full_node_test.go index a2e9dca5d8..7d040a07d6 100644 --- a/test/util/testnode/full_node_test.go +++ b/test/util/testnode/full_node_test.go @@ -19,7 +19,14 @@ import ( coretypes "github.com/tendermint/tendermint/rpc/core/types" ) +const ( + kibibyte = 1024 +) + func TestIntegrationTestSuite(t *testing.T) { + if testing.Short() { + t.Skip("skipping full node integration test in short mode.") + } suite.Run(t, new(IntegrationTestSuite)) } @@ -31,40 +38,31 @@ type IntegrationTestSuite struct { } func (s *IntegrationTestSuite) SetupSuite() { - if testing.Short() { - s.T().Skip("skipping full node integration test in short mode.") - } t := s.T() - - accounts := make([]string, 10) - for i := 0; i < 10; i++ { - accounts[i] = tmrand.Str(10) - } + s.accounts = RandomAccounts(10) ecfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) blobGenState := blobtypes.DefaultGenesis() blobGenState.Params.GovMaxSquareSize = uint64(appconsts.DefaultSquareSizeUpperBound) cfg := DefaultConfig(). - WithFundedAccounts(accounts...). + WithFundedAccounts(s.accounts...). WithModifiers(genesis.SetBlobParams(ecfg.Codec, blobGenState.Params)) cctx, _, _ := NewNetwork(t, cfg) s.cctx = cctx - s.accounts = accounts } -// The "_Flaky" suffix indicates that the test may fail non-deterministically especially when executed in CI. -func (s *IntegrationTestSuite) Test_Liveness_Flaky() { +func (s *IntegrationTestSuite) Test_verifyTimeIotaMs() { require := s.Require() err := s.cctx.WaitForNextBlock() require.NoError(err) - // check that we're actually able to set the consensus params + var params *coretypes.ResultConsensusParams // this query can be flaky with fast block times, so we repeat it multiple // times in attempt to decrease flakiness - for i := 0; i < 40; i++ { - params, err = s.cctx.Client.ConsensusParams(context.TODO(), nil) + for i := 0; i < 100; i++ { + params, err = s.cctx.Client.ConsensusParams(context.Background(), nil) if err == nil && params != nil { break } @@ -73,21 +71,19 @@ func (s *IntegrationTestSuite) Test_Liveness_Flaky() { require.NoError(err) require.NotNil(params) require.Equal(int64(1), params.ConsensusParams.Block.TimeIotaMs) - _, err = s.cctx.WaitForHeight(20) - require.NoError(err) } -func (s *IntegrationTestSuite) Test_PostData() { +func (s *IntegrationTestSuite) TestPostData() { require := s.Require() - _, err := s.cctx.PostData(s.accounts[0], flags.BroadcastBlock, appns.RandomBlobNamespace(), tmrand.Bytes(100000)) + _, err := s.cctx.PostData(s.accounts[0], flags.BroadcastBlock, appns.RandomBlobNamespace(), tmrand.Bytes(kibibyte)) require.NoError(err) } -func (s *IntegrationTestSuite) Test_FillBlock() { +func (s *IntegrationTestSuite) TestFillBlock() { require := s.Require() for squareSize := 2; squareSize <= appconsts.DefaultGovMaxSquareSize; squareSize *= 2 { - resp, err := s.cctx.FillBlock(squareSize, s.accounts, flags.BroadcastSync) + resp, err := s.cctx.FillBlock(squareSize, s.accounts[1], flags.BroadcastSync) require.NoError(err) err = s.cctx.WaitForBlocks(3) @@ -103,7 +99,7 @@ func (s *IntegrationTestSuite) Test_FillBlock() { } } -func (s *IntegrationTestSuite) Test_FillBlock_InvalidSquareSizeError() { +func (s *IntegrationTestSuite) TestFillBlock_InvalidSquareSizeError() { tests := []struct { name string squareSize int @@ -127,7 +123,7 @@ func (s *IntegrationTestSuite) Test_FillBlock_InvalidSquareSizeError() { for _, tc := range tests { s.Run(tc.name, func() { - _, actualErr := s.cctx.FillBlock(tc.squareSize, s.accounts, flags.BroadcastAsync) + _, actualErr := s.cctx.FillBlock(tc.squareSize, s.accounts[2], flags.BroadcastAsync) s.Equal(tc.expectedErr, actualErr) }) } diff --git a/test/util/testnode/node_interaction_api.go b/test/util/testnode/node_interaction_api.go index cf8e2e3bbb..77984ca146 100644 --- a/test/util/testnode/node_interaction_api.go +++ b/test/util/testnode/node_interaction_api.go @@ -277,7 +277,7 @@ func (c *Context) PostData(account, broadcastMode string, ns appns.Namespace, bl // create a square of the desired size. broadcast mode indicates if the tx // should be submitted async, sync, or block. (see flags.BroadcastModeSync). If // broadcast mode is the string zero value, then it will be set to block. -func (c *Context) FillBlock(squareSize int, accounts []string, broadcastMode string) (*sdk.TxResponse, error) { +func (c *Context) FillBlock(squareSize int, account string, broadcastMode string) (*sdk.TxResponse, error) { if squareSize < appconsts.MinSquareSize+1 || (squareSize&(squareSize-1) != 0) { return nil, fmt.Errorf("unsupported squareSize: %d", squareSize) } @@ -291,7 +291,7 @@ func (c *Context) FillBlock(squareSize int, accounts []string, broadcastMode str // we use a formula to guarantee that the tx is the exact size needed to force a specific square size. blobSize := shares.AvailableBytesFromSparseShares(shareCount) - return c.PostData(accounts[0], broadcastMode, appns.RandomBlobNamespace(), tmrand.Bytes(blobSize)) + return c.PostData(account, broadcastMode, appns.RandomBlobNamespace(), tmrand.Bytes(blobSize)) } // HeightForTimestamp returns the block height for the first block after a diff --git a/x/blob/client/testutil/integration_test.go b/x/blob/client/testutil/integration_test.go index 0674189940..886777c4cf 100644 --- a/x/blob/client/testutil/integration_test.go +++ b/x/blob/client/testutil/integration_test.go @@ -1,7 +1,6 @@ package testutil import ( - "bytes" "encoding/hex" "fmt" "strconv" @@ -40,15 +39,10 @@ func NewIntegrationTestSuite(cfg cosmosnet.Config) *IntegrationTestSuite { return &IntegrationTestSuite{cfg: cfg} } -// Note: the SetupSuite may act flaky especially in CI. func (s *IntegrationTestSuite) SetupSuite() { - if testing.Short() { - s.T().Skip("skipping integration test in short mode.") - } s.T().Log("setting up integration test suite") net := network.New(s.T(), s.cfg, username) - s.network = net s.kr = net.Validators[0].ClientCtx.Keyring _, err := s.network.WaitForHeight(1) @@ -62,10 +56,8 @@ func (s *IntegrationTestSuite) TearDownSuite() { func (s *IntegrationTestSuite) TestSubmitPayForBlob() { require := s.Require() - val := s.network.Validators[0] + validator := s.network.Validators[0] hexNamespace := hex.EncodeToString(appns.RandomBlobNamespaceID()) - invalidNamespaceID := hex.EncodeToString(bytes.Repeat([]byte{0}, 8)) // invalid because ID is expected to be 10 bytes - hexBlob := "0204033704032c0b162109000908094d425837422c2116" testCases := []struct { @@ -89,58 +81,14 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() { expectedCode: 0, respType: &sdk.TxResponse{}, }, - { - name: "unsupported share version", - args: []string{ - hexNamespace, - hexBlob, - fmt.Sprintf("--from=%s", username), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2))).String()), - fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=1", paycli.FlagShareVersion), - }, - expectErr: true, - expectedCode: 0, - respType: &sdk.TxResponse{}, - }, - { - name: "invalid namespace ID", - args: []string{ - invalidNamespaceID, - hexBlob, - fmt.Sprintf("--from=%s", username), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2))).String()), - fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - }, - expectErr: true, - expectedCode: 0, - respType: &sdk.TxResponse{}, - }, - { - name: "invalid namespace version", - args: []string{ - hexNamespace, - hexBlob, - fmt.Sprintf("--from=%s", username), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2))).String()), - fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=1", paycli.FlagNamespaceVersion), - }, - expectErr: true, - expectedCode: 0, - respType: &sdk.TxResponse{}, - }, } for _, tc := range testCases { tc := tc - s.Require().NoError(s.network.WaitForNextBlock()) + require.NoError(s.network.WaitForNextBlock()) s.Run(tc.name, func() { cmd := paycli.CmdPayForBlob() - clientCtx := val.ClientCtx + clientCtx := validator.ClientCtx out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { @@ -182,7 +130,9 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() { } } -// The "_Flaky" suffix indicates that the test may fail non-deterministically especially when executed in CI. -func TestIntegrationTestSuite_Flaky(t *testing.T) { +func TestIntegrationTestSuite(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration test in short mode.") + } suite.Run(t, NewIntegrationTestSuite(network.DefaultConfig())) }