From c3758ff830dbfa39262df71b5c04d5d569b53c66 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 10 Nov 2023 14:02:07 +0100 Subject: [PATCH 01/30] test: attempt to unflake max total blob size --- app/test/max_total_blob_size_test.go | 30 +++------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/app/test/max_total_blob_size_test.go b/app/test/max_total_blob_size_test.go index 8c7875f2f9..88c089c3c8 100644 --- a/app/test/max_total_blob_size_test.go +++ b/app/test/max_total_blob_size_test.go @@ -7,17 +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 ( @@ -63,9 +59,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,16 +71,6 @@ 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), @@ -105,16 +91,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) - } }) } } From d29f4b35ff1f70850b4a58f1790f913e36253024 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 10 Nov 2023 14:15:27 +0100 Subject: [PATCH 02/30] refactor: mustNewBlob -> newBlobWithSize --- app/test/integration_test.go | 30 ++++++++++++---------------- app/test/max_total_blob_size_test.go | 2 +- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/app/test/integration_test.go b/app/test/integration_test.go index 4a2e054e71..88827f8e6e 100644 --- a/app/test/integration_test.go +++ b/app/test/integration_test.go @@ -210,10 +210,6 @@ 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 @@ -223,7 +219,7 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() { tests := []test{ { "small random typical", - mustNewBlob(ns1, tmrand.Bytes(3000), appconsts.ShareVersionZero), + blob.New(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), @@ -231,7 +227,7 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() { }, { "large random typical", - mustNewBlob(ns1, tmrand.Bytes(350000), appconsts.ShareVersionZero), + blob.New(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), @@ -239,7 +235,7 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() { }, { "medium random with memo", - mustNewBlob(ns1, tmrand.Bytes(100000), appconsts.ShareVersionZero), + blob.New(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), @@ -247,7 +243,7 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() { }, { "medium random with timeout height", - mustNewBlob(ns1, tmrand.Bytes(100000), appconsts.ShareVersionZero), + blob.New(ns1, tmrand.Bytes(100000), appconsts.ShareVersionZero), []user.TxOption{ user.SetTimeoutHeight(10000), user.SetGasLimit(1_000_000_000), @@ -396,27 +392,27 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob_blobSizes() { testCases := []testCase{ { name: "1,000 byte blob", - blob: mustNewBlob(1_000), + blob: newBlobWithSize(1_000), txResponseCode: abci.CodeTypeOK, }, { name: "10,000 byte blob", - blob: mustNewBlob(10_000), + blob: newBlobWithSize(10_000), txResponseCode: abci.CodeTypeOK, }, { name: "100,000 byte blob", - blob: mustNewBlob(100_000), + blob: newBlobWithSize(100_000), txResponseCode: abci.CodeTypeOK, }, { name: "1,000,000 byte blob", - blob: mustNewBlob(1_000_000), + blob: newBlobWithSize(1_000_000), txResponseCode: abci.CodeTypeOK, }, { name: "10,000,000 byte blob returns err tx too large", - blob: mustNewBlob(10_000_000), + blob: newBlobWithSize(10_000_000), txResponseCode: errors.ErrTxTooLarge.ABCICode(), }, } @@ -437,8 +433,8 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob_blobSizes() { } } -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 88c089c3c8..7d400db8b9 100644 --- a/app/test/max_total_blob_size_test.go +++ b/app/test/max_total_blob_size_test.go @@ -73,7 +73,7 @@ func (s *MaxTotalBlobSizeSuite) TestErrTotalBlobSizeTooLarge() { testCases := []testCase{ { name: "2 mebibyte blob", - blob: mustNewBlob(2 * mebibyte), + blob: newBlobWithSize(2 * mebibyte), want: blobtypes.ErrTotalBlobSizeTooLarge.ABCICode(), }, } From 841cc147e5ba5b4621763e9ae1cc748fd5f044d5 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 10 Nov 2023 14:20:08 +0100 Subject: [PATCH 03/30] refactor: setup accounts --- app/test/integration_test.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/test/integration_test.go b/app/test/integration_test.go index 88827f8e6e..40c038f7ca 100644 --- a/app/test/integration_test.go +++ b/app/test/integration_test.go @@ -51,14 +51,18 @@ type IntegrationTestSuite struct { cctx testnode.Context } -func (s *IntegrationTestSuite) SetupSuite() { - t := s.T() - +func (s *IntegrationTestSuite) setupAccounts() { numAccounts := 142 s.accounts = make([]string, numAccounts) for i := 0; i < numAccounts; i++ { s.accounts[i] = tmrand.Str(20) } +} + +func (s *IntegrationTestSuite) SetupSuite() { + t := s.T() + + s.setupAccounts() cfg := testnode.DefaultConfig().WithFundedAccounts(s.accounts...) From 9f7a4a824e3073d8f1fc3a8fbe2cacb400516169 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 10 Nov 2023 16:23:37 +0100 Subject: [PATCH 04/30] refactor: TestMaxBlockSize --- app/test/integration_test.go | 43 +++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/app/test/integration_test.go b/app/test/integration_test.go index 40c038f7ca..91facbaa81 100644 --- a/app/test/integration_test.go +++ b/app/test/integration_test.go @@ -36,6 +36,11 @@ import ( coretypes "github.com/tendermint/tendermint/types" ) +const ( + Kibibyte = 1024 + Mebibyte = 1_048_576 +) + func TestIntegrationTestSuite(t *testing.T) { if testing.Short() { t.Skip("skipping app/test/integration_test in short mode.") @@ -83,47 +88,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], @@ -137,16 +136,16 @@ func (s *IntegrationTestSuite) TestMaxBlockSize() { tests := []test{ { - "20 1Mb txs", - equallySized1MbTxGen, + "singleBlobTxGen", + singleBlobTxGen, }, { - "20 1Mb multiblob txs", - randMultiBlob1MbTxGen, + "multiBlobTxGen", + multiBlobTxGen, }, { - "80 random txs", - randoTxGen, + "randomTxGen", + randomTxGen, }, } for _, tc := range tests { @@ -155,6 +154,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) From c0e908d78054b443618365b1f2222246da02ce26 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 10 Nov 2023 16:26:10 +0100 Subject: [PATCH 05/30] refactor: remove redundant continue --- app/test/integration_test.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/test/integration_test.go b/app/test/integration_test.go index 91facbaa81..0bac933811 100644 --- a/app/test/integration_test.go +++ b/app/test/integration_test.go @@ -173,10 +173,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 From cb7d88398751480b277954ffdec75325551addaa Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 10 Nov 2023 16:26:26 +0100 Subject: [PATCH 06/30] refactor: remove unnecessary verification --- app/test/integration_test.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/test/integration_test.go b/app/test/integration_test.go index 0bac933811..f9c38e54a0 100644 --- a/app/test/integration_test.go +++ b/app/test/integration_test.go @@ -195,11 +195,6 @@ func (s *IntegrationTestSuite) TestMaxBlockSize() { require.LessOrEqual(t, size, uint64(appconsts.DefaultGovMaxSquareSize)) require.GreaterOrEqual(t, size, uint64(appconsts.MinSquareSize)) - // assert that the app version is correctly set - // FIXME: This should return the latest version but tendermint v0.34.x doesn't copy - // over the version when converting from proto so it disappears - require.EqualValues(t, 0, blockRes.Block.Header.Version.App) - sizes = append(sizes, size) ExtendBlobTest(t, blockRes.Block) } From 9123e6959dd76979ec15001feb41916974381085 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 10 Nov 2023 16:28:56 +0100 Subject: [PATCH 07/30] refactor: collapse vertically --- app/test/integration_test.go | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/app/test/integration_test.go b/app/test/integration_test.go index f9c38e54a0..912c8e1f8a 100644 --- a/app/test/integration_test.go +++ b/app/test/integration_test.go @@ -133,20 +133,10 @@ func (s *IntegrationTestSuite) TestMaxBlockSize() { name string txGenerator func(clientCtx client.Context) []coretypes.Tx } - tests := []test{ - { - "singleBlobTxGen", - singleBlobTxGen, - }, - { - "multiBlobTxGen", - multiBlobTxGen, - }, - { - "randomTxGen", - randomTxGen, - }, + {"singleBlobTxGen", singleBlobTxGen}, + {"multiBlobTxGen", multiBlobTxGen}, + {"randomTxGen", randomTxGen}, } for _, tc := range tests { s.Run(tc.name, func() { @@ -205,6 +195,8 @@ func (s *IntegrationTestSuite) TestMaxBlockSize() { } } +func getSquareSizes() + func (s *IntegrationTestSuite) TestSubmitPayForBlob() { t := s.T() ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) From c08a962cedc2bc0d61af46f93673c8fbdfa2570d Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 10 Nov 2023 16:32:05 +0100 Subject: [PATCH 08/30] refactor: rename to ExtendBlockTest --- app/test/integration_test.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/test/integration_test.go b/app/test/integration_test.go index 912c8e1f8a..80548f7110 100644 --- a/app/test/integration_test.go +++ b/app/test/integration_test.go @@ -186,7 +186,7 @@ func (s *IntegrationTestSuite) TestMaxBlockSize() { require.GreaterOrEqual(t, size, uint64(appconsts.MinSquareSize)) 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)) @@ -195,8 +195,6 @@ func (s *IntegrationTestSuite) TestMaxBlockSize() { } } -func getSquareSizes() - func (s *IntegrationTestSuite) TestSubmitPayForBlob() { t := s.T() ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) @@ -339,9 +337,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) @@ -361,7 +359,7 @@ 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) + ExtendBlockTest(t, blockRes.Block) } } From 18a96328b625b240508eb055729e079131d724de Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 10 Nov 2023 17:03:05 +0100 Subject: [PATCH 09/30] refactor: use sizes --- app/test/integration_test.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/app/test/integration_test.go b/app/test/integration_test.go index 80548f7110..de1cfdcf52 100644 --- a/app/test/integration_test.go +++ b/app/test/integration_test.go @@ -281,13 +281,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], @@ -380,23 +379,23 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob_blobSizes() { } testCases := []testCase{ { - name: "1,000 byte blob", - blob: newBlobWithSize(1_000), + name: "1 kibibyte blob", + blob: newBlobWithSize(Kibibyte), txResponseCode: abci.CodeTypeOK, }, { - name: "10,000 byte blob", - blob: newBlobWithSize(10_000), + name: "10 kibibyte blob", + blob: newBlobWithSize(10 * Kibibyte), txResponseCode: abci.CodeTypeOK, }, { - name: "100,000 byte blob", - blob: newBlobWithSize(100_000), + name: "100 kibibyte blob", + blob: newBlobWithSize(100 * Kibibyte), txResponseCode: abci.CodeTypeOK, }, { - name: "1,000,000 byte blob", - blob: newBlobWithSize(1_000_000), + name: "1 mebibyte blob", + blob: newBlobWithSize(1 * mebibyte), txResponseCode: abci.CodeTypeOK, }, { @@ -408,7 +407,7 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob_blobSizes() { for _, tc := range testCases { s.Run(tc.name, func() { - subCtx, cancel := context.WithTimeout(s.cctx.GoContext(), 30*time.Second) + subCtx, cancel := context.WithTimeout(s.cctx.GoContext(), 60*time.Second) defer cancel() res, err := signer.SubmitPayForBlob(subCtx, []*blob.Blob{tc.blob}, user.SetGasLimit(1_000_000_000)) if tc.txResponseCode == abci.CodeTypeOK { From bf93ad2d321957fe03c9ac52efc51d6ef517c425 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 10 Nov 2023 17:13:33 +0100 Subject: [PATCH 10/30] refactor: extract RandomAccounts() --- app/test/integration_test.go | 11 +---------- test/util/testnode/accounts.go | 12 ++++++++++++ test/util/testnode/accounts_test.go | 13 +++++++++++++ test/util/testnode/full_node_test.go | 15 +++++---------- 4 files changed, 31 insertions(+), 20 deletions(-) create mode 100644 test/util/testnode/accounts.go create mode 100644 test/util/testnode/accounts_test.go diff --git a/app/test/integration_test.go b/app/test/integration_test.go index de1cfdcf52..1d632b5fe6 100644 --- a/app/test/integration_test.go +++ b/app/test/integration_test.go @@ -56,18 +56,9 @@ type IntegrationTestSuite struct { cctx testnode.Context } -func (s *IntegrationTestSuite) setupAccounts() { - numAccounts := 142 - s.accounts = make([]string, numAccounts) - for i := 0; i < numAccounts; i++ { - s.accounts[i] = tmrand.Str(20) - } -} - func (s *IntegrationTestSuite) SetupSuite() { t := s.T() - - s.setupAccounts() + s.accounts = testnode.RandomAccounts(142) cfg := testnode.DefaultConfig().WithFundedAccounts(s.accounts...) 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..bdd7ffbb9a 100644 --- a/test/util/testnode/full_node_test.go +++ b/test/util/testnode/full_node_test.go @@ -20,6 +20,9 @@ import ( ) func TestIntegrationTestSuite(t *testing.T) { + if testing.Short() { + t.Skip("skipping full node integration test in short mode.") + } suite.Run(t, new(IntegrationTestSuite)) } @@ -31,27 +34,19 @@ 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. From d17de928b4f47a1116e7d20dfa12e6a6bb5129d7 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 10 Nov 2023 17:17:59 +0100 Subject: [PATCH 11/30] refactor: rename tests --- test/util/testnode/full_node_test.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/util/testnode/full_node_test.go b/test/util/testnode/full_node_test.go index bdd7ffbb9a..44a4b97b1f 100644 --- a/test/util/testnode/full_node_test.go +++ b/test/util/testnode/full_node_test.go @@ -19,6 +19,10 @@ 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.") @@ -72,13 +76,13 @@ func (s *IntegrationTestSuite) Test_Liveness_Flaky() { 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 { @@ -98,7 +102,7 @@ func (s *IntegrationTestSuite) Test_FillBlock() { } } -func (s *IntegrationTestSuite) Test_FillBlock_InvalidSquareSizeError() { +func (s *IntegrationTestSuite) TestFillBlock_InvalidSquareSizeError() { tests := []struct { name string squareSize int From 50e3282422e25ccd7a3122c45dbbd18da523dfdc Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 10 Nov 2023 17:25:01 +0100 Subject: [PATCH 12/30] refactor: rename test --- test/util/testnode/full_node_test.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/test/util/testnode/full_node_test.go b/test/util/testnode/full_node_test.go index 44a4b97b1f..ca41964cdf 100644 --- a/test/util/testnode/full_node_test.go +++ b/test/util/testnode/full_node_test.go @@ -53,16 +53,15 @@ func (s *IntegrationTestSuite) SetupSuite() { s.cctx = cctx } -// 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++ { + for i := 0; i < 100; i++ { params, err = s.cctx.Client.ConsensusParams(context.TODO(), nil) if err == nil && params != nil { break @@ -72,8 +71,6 @@ 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) TestPostData() { From 2a2cd228b27775c4c67cab9f853390feeb50636d Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 10 Nov 2023 17:30:13 +0100 Subject: [PATCH 13/30] refactor: remove _flaky --- pkg/square/square_test.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pkg/square/square_test.go b/pkg/square/square_test.go index 798955dc3f..0ae844b223 100644 --- a/pkg/square/square_test.go +++ b/pkg/square/square_test.go @@ -134,12 +134,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 +151,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) From 0369f21eadb494e592e19fdee34ce11c0845c4ef Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 10 Nov 2023 17:37:20 +0100 Subject: [PATCH 14/30] test: attempt to differentiate accounts per test Potential solution for https://github.com/celestiaorg/celestia-app/actions/runs/6827269518/job/18569018708#step:4:49 --- test/util/testnode/full_node_test.go | 4 ++-- test/util/testnode/node_interaction_api.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/util/testnode/full_node_test.go b/test/util/testnode/full_node_test.go index ca41964cdf..3b61b491d1 100644 --- a/test/util/testnode/full_node_test.go +++ b/test/util/testnode/full_node_test.go @@ -83,7 +83,7 @@ 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) @@ -123,7 +123,7 @@ func (s *IntegrationTestSuite) TestFillBlock_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 From 4ed02a5a26683edc2857643c95cc262aa64b1243 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 10 Nov 2023 17:55:00 +0100 Subject: [PATCH 15/30] test: remove _flaky suffix --- app/test/square_size_test.go | 3 +-- x/blob/client/testutil/integration_test.go | 17 +++++++---------- 2 files changed, 8 insertions(+), 12 deletions(-) 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/x/blob/client/testutil/integration_test.go b/x/blob/client/testutil/integration_test.go index 0674189940..711b10f6f0 100644 --- a/x/blob/client/testutil/integration_test.go +++ b/x/blob/client/testutil/integration_test.go @@ -40,17 +40,12 @@ 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 + network := network.New(s.T(), s.cfg, username) + s.network = network + s.kr = network.Validators[0].ClientCtx.Keyring _, err := s.network.WaitForHeight(1) s.Require().NoError(err) } @@ -182,7 +177,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())) } From 278fc27c317d35665bd31cb4a79132689e43df10 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 24 Nov 2023 21:10:04 -0500 Subject: [PATCH 16/30] refactor: units --- app/test/integration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/test/integration_test.go b/app/test/integration_test.go index 1d632b5fe6..f230ba60ea 100644 --- a/app/test/integration_test.go +++ b/app/test/integration_test.go @@ -38,7 +38,7 @@ import ( const ( Kibibyte = 1024 - Mebibyte = 1_048_576 + Mebibyte = 1024 * Kibibyte ) func TestIntegrationTestSuite(t *testing.T) { From cf47f2edeb52b6c4e6e986f6c6e3b066d741547a Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 24 Nov 2023 21:32:55 -0500 Subject: [PATCH 17/30] test: remove redundant test cases --- app/test/integration_test.go | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/app/test/integration_test.go b/app/test/integration_test.go index f230ba60ea..95688db08e 100644 --- a/app/test/integration_test.go +++ b/app/test/integration_test.go @@ -369,21 +369,6 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob_blobSizes() { txResponseCode uint32 } testCases := []testCase{ - { - name: "1 kibibyte blob", - blob: newBlobWithSize(Kibibyte), - txResponseCode: abci.CodeTypeOK, - }, - { - name: "10 kibibyte blob", - blob: newBlobWithSize(10 * Kibibyte), - txResponseCode: abci.CodeTypeOK, - }, - { - name: "100 kibibyte blob", - blob: newBlobWithSize(100 * Kibibyte), - txResponseCode: abci.CodeTypeOK, - }, { name: "1 mebibyte blob", blob: newBlobWithSize(1 * mebibyte), From d625910660e25152468be8053734b3e642fe8d62 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 24 Nov 2023 21:35:41 -0500 Subject: [PATCH 18/30] refactor: use units --- app/test/integration_test.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/test/integration_test.go b/app/test/integration_test.go index 95688db08e..51ff7b4826 100644 --- a/app/test/integration_test.go +++ b/app/test/integration_test.go @@ -188,7 +188,6 @@ func (s *IntegrationTestSuite) TestMaxBlockSize() { func (s *IntegrationTestSuite) TestSubmitPayForBlob() { t := s.T() - ns1 := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) type test struct { name string @@ -199,7 +198,7 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() { tests := []test{ { "small random typical", - blob.New(ns1, tmrand.Bytes(3000), appconsts.ShareVersionZero), + newBlobWithSize(3 * Kibibyte), []user.TxOption{ user.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(app.BondDenom, sdk.NewInt(1)))), user.SetGasLimit(1_000_000_000), @@ -207,7 +206,7 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() { }, { "large random typical", - blob.New(ns1, tmrand.Bytes(350000), appconsts.ShareVersionZero), + newBlobWithSize(350 * Kibibyte), []user.TxOption{ user.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(app.BondDenom, sdk.NewInt(10)))), user.SetGasLimit(1_000_000_000), @@ -215,7 +214,7 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() { }, { "medium random with memo", - blob.New(ns1, tmrand.Bytes(100000), appconsts.ShareVersionZero), + newBlobWithSize(100 * Kibibyte), []user.TxOption{ user.SetMemo("lol I could stick the rollup block here if I wanted to"), user.SetGasLimit(1_000_000_000), @@ -223,7 +222,7 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() { }, { "medium random with timeout height", - blob.New(ns1, tmrand.Bytes(100000), appconsts.ShareVersionZero), + newBlobWithSize(100 * Kibibyte), []user.TxOption{ user.SetTimeoutHeight(10000), user.SetGasLimit(1_000_000_000), From e3a9a235506d87374d131fea88e610836ea32e20 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 24 Nov 2023 21:37:35 -0500 Subject: [PATCH 19/30] test: delete submit PFB b/c it is redundant with TestSubmitPayForBlob --- app/test/integration_test.go | 61 ------------------------------------ 1 file changed, 61 deletions(-) diff --git a/app/test/integration_test.go b/app/test/integration_test.go index 51ff7b4826..c73f3341db 100644 --- a/app/test/integration_test.go +++ b/app/test/integration_test.go @@ -30,7 +30,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" @@ -186,66 +185,6 @@ func (s *IntegrationTestSuite) TestMaxBlockSize() { } } -func (s *IntegrationTestSuite) TestSubmitPayForBlob() { - t := s.T() - - type test struct { - name string - blob *blob.Blob - opts []user.TxOption - } - - tests := []test{ - { - "small random typical", - newBlobWithSize(3 * Kibibyte), - []user.TxOption{ - user.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(app.BondDenom, sdk.NewInt(1)))), - user.SetGasLimit(1_000_000_000), - }, - }, - { - "large random typical", - newBlobWithSize(350 * Kibibyte), - []user.TxOption{ - user.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(app.BondDenom, sdk.NewInt(10)))), - user.SetGasLimit(1_000_000_000), - }, - }, - { - "medium random with memo", - newBlobWithSize(100 * Kibibyte), - []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", - newBlobWithSize(100 * Kibibyte), - []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() From 0a3eb0a8419c8d30eef99528dc1a465a60a97e61 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 24 Nov 2023 21:48:27 -0500 Subject: [PATCH 20/30] refactor: extract shared units --- app/test/block_production_test.go | 2 +- app/test/integration_test.go | 13 ++++--------- app/test/max_total_blob_size_test.go | 1 - app/test/unit_test.go | 6 ++++++ 4 files changed, 11 insertions(+), 11 deletions(-) create mode 100644 app/test/unit_test.go 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 c73f3341db..0fb111d950 100644 --- a/app/test/integration_test.go +++ b/app/test/integration_test.go @@ -35,11 +35,6 @@ import ( coretypes "github.com/tendermint/tendermint/types" ) -const ( - Kibibyte = 1024 - Mebibyte = 1024 * Kibibyte -) - func TestIntegrationTestSuite(t *testing.T) { if testing.Short() { t.Skip("skipping app/test/integration_test in short mode.") @@ -84,7 +79,7 @@ func (s *IntegrationTestSuite) TestMaxBlockSize() { tmrand.NewRand(), s.cctx.Keyring, c.GRPCClient, - 600*Kibibyte, + 600*kibibyte, 1, false, s.accounts[:20], @@ -99,7 +94,7 @@ func (s *IntegrationTestSuite) TestMaxBlockSize() { tmrand.NewRand(), s.cctx.Keyring, c.GRPCClient, - 200*Kibibyte, + 200*kibibyte, 3, false, s.accounts[20:40], @@ -112,7 +107,7 @@ func (s *IntegrationTestSuite) TestMaxBlockSize() { tmrand.NewRand(), s.cctx.Keyring, c.GRPCClient, - 50*Kibibyte, + 50*kibibyte, 8, true, s.accounts[40:120], @@ -215,7 +210,7 @@ func (s *IntegrationTestSuite) TestShareInclusionProof() { tmrand.NewRand(), s.cctx.Keyring, s.cctx.GRPCClient, - 100*Kibibyte, + 100*kibibyte, 1, true, s.accounts[120:140], diff --git a/app/test/max_total_blob_size_test.go b/app/test/max_total_blob_size_test.go index 7d400db8b9..21d167966b 100644 --- a/app/test/max_total_blob_size_test.go +++ b/app/test/max_total_blob_size_test.go @@ -17,7 +17,6 @@ import ( ) const ( - mebibyte = 1_048_576 // one mebibyte in bytes squareSize = 64 ) 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 +) From ee5d427a8171b070b4c3e16c971fa791dbc5fa5a Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 24 Nov 2023 22:16:47 -0500 Subject: [PATCH 21/30] remove redundant tests --- x/blob/client/testutil/integration_test.go | 53 ++-------------------- 1 file changed, 3 insertions(+), 50 deletions(-) diff --git a/x/blob/client/testutil/integration_test.go b/x/blob/client/testutil/integration_test.go index 711b10f6f0..8c253736f5 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" @@ -57,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 { @@ -84,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 { From 2c0273fd0f0ec2915e609bfe5a93f6895b8fb3b9 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 24 Nov 2023 22:17:13 -0500 Subject: [PATCH 22/30] refactor: unexport unit --- test/util/testnode/full_node_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/util/testnode/full_node_test.go b/test/util/testnode/full_node_test.go index 3b61b491d1..df195da470 100644 --- a/test/util/testnode/full_node_test.go +++ b/test/util/testnode/full_node_test.go @@ -20,7 +20,7 @@ import ( ) const ( - Kibibyte = 1024 + kibibyte = 1024 ) func TestIntegrationTestSuite(t *testing.T) { @@ -75,7 +75,7 @@ func (s *IntegrationTestSuite) Test_verifyTimeIotaMs() { func (s *IntegrationTestSuite) TestPostData() { require := s.Require() - _, err := s.cctx.PostData(s.accounts[0], flags.BroadcastBlock, appns.RandomBlobNamespace(), tmrand.Bytes(Kibibyte)) + _, err := s.cctx.PostData(s.accounts[0], flags.BroadcastBlock, appns.RandomBlobNamespace(), tmrand.Bytes(kibibyte)) require.NoError(err) } From 39ea8485873fafcbcf582f85a8441f8d0ae27a0c Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 24 Nov 2023 22:37:18 -0500 Subject: [PATCH 23/30] ci: debug lint failure --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 9d8f23c1a3..f69b2b6659 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -26,7 +26,7 @@ jobs: - uses: golangci/golangci-lint-action@v3.7.0 with: version: v1.54.2 - args: --timeout 10m + args: --timeout 10m --verbose github-token: ${{ secrets.github_token }} if: env.GIT_DIFF From 39148f6021eb95d0d392e916b9a2c0f9ee10637f Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 24 Nov 2023 22:41:44 -0500 Subject: [PATCH 24/30] attempt to fix lint --- .github/workflows/lint.yml | 2 +- app/test/max_total_blob_size_test.go | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index f69b2b6659..9d8f23c1a3 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -26,7 +26,7 @@ jobs: - uses: golangci/golangci-lint-action@v3.7.0 with: version: v1.54.2 - args: --timeout 10m --verbose + args: --timeout 10m github-token: ${{ secrets.github_token }} if: env.GIT_DIFF diff --git a/app/test/max_total_blob_size_test.go b/app/test/max_total_blob_size_test.go index 21d167966b..9c9bafcef7 100644 --- a/app/test/max_total_blob_size_test.go +++ b/app/test/max_total_blob_size_test.go @@ -16,10 +16,6 @@ import ( "github.com/stretchr/testify/suite" ) -const ( - squareSize = 64 -) - func TestMaxTotalBlobSizeSuite(t *testing.T) { if testing.Short() { t.Skip("skipping max total blob size suite in short mode.") From 8da4fa5c7253cc06392c6a8d745ac5e79a67f96d Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Sat, 25 Nov 2023 17:36:38 -0500 Subject: [PATCH 25/30] chore: prefer context.Background() https://stackoverflow.com/questions/74239074/context-todo-or-context-background-which-one-should-i-prefer context.Background() seems preferable for this test where the surrounding code is not going to be refactored to accept a parent context --- test/util/testnode/full_node_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/util/testnode/full_node_test.go b/test/util/testnode/full_node_test.go index df195da470..7d040a07d6 100644 --- a/test/util/testnode/full_node_test.go +++ b/test/util/testnode/full_node_test.go @@ -62,7 +62,7 @@ func (s *IntegrationTestSuite) Test_verifyTimeIotaMs() { // this query can be flaky with fast block times, so we repeat it multiple // times in attempt to decrease flakiness for i := 0; i < 100; i++ { - params, err = s.cctx.Client.ConsensusParams(context.TODO(), nil) + params, err = s.cctx.Client.ConsensusParams(context.Background(), nil) if err == nil && params != nil { break } From 144774591facf6452959627f6ed4cb8dc2dc5504 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Mon, 27 Nov 2023 16:05:09 -0500 Subject: [PATCH 26/30] refactor: rename test --- app/test/integration_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/test/integration_test.go b/app/test/integration_test.go index cfc045e22e..6b2fef9745 100644 --- a/app/test/integration_test.go +++ b/app/test/integration_test.go @@ -287,9 +287,9 @@ func (s *IntegrationTestSuite) TestEmptyBlock() { } } -// TestSubmitPayForBlob_blobSizes verifies the tx response ABCI code when +// TestSubmitPayForBlob_txResponseCode verifies the tx response ABCI code when // SubmitPayForBlob is invoked with different blob sizes. -func (s *IntegrationTestSuite) TestSubmitPayForBlob_blobSizes() { +func (s *IntegrationTestSuite) TestSubmitPayForBlob_txResponseCode() { t := s.T() require.NoError(t, s.cctx.WaitForBlocks(3)) addr := testfactory.GetAddress(s.cctx.Keyring, s.accounts[141]) From f4279083719f6f590427423d36919168b392b8fd Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Mon, 27 Nov 2023 16:09:29 -0500 Subject: [PATCH 27/30] refactor: remove ErrTxTooLarge test case --- app/test/integration_test.go | 50 +++++++++--------------------------- 1 file changed, 12 insertions(+), 38 deletions(-) diff --git a/app/test/integration_test.go b/app/test/integration_test.go index 6b2fef9745..0d84bff3eb 100644 --- a/app/test/integration_test.go +++ b/app/test/integration_test.go @@ -16,7 +16,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" @@ -287,48 +286,23 @@ func (s *IntegrationTestSuite) TestEmptyBlock() { } } -// TestSubmitPayForBlob_txResponseCode verifies the tx response ABCI code when -// SubmitPayForBlob is invoked with different blob sizes. -func (s *IntegrationTestSuite) TestSubmitPayForBlob_txResponseCode() { +// TestSubmitPayForBlob verifies the tx response ABCI code when SubmitPayForBlob +// is invoked with a 1 MiB blob. +func (s *IntegrationTestSuite) TestSubmitPayForBlob() { t := s.T() - require.NoError(t, s.cctx.WaitForBlocks(3)) + require.NoError(t, s.cctx.WaitForBlocks(1)) 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 mebibyte blob", - blob: newBlobWithSize(1 * mebibyte), - txResponseCode: abci.CodeTypeOK, - }, - { - name: "10,000,000 byte blob returns err tx too large", - blob: newBlobWithSize(10_000_000), - txResponseCode: errors.ErrTxTooLarge.ABCICode(), - }, - } - - for _, tc := range testCases { - s.Run(tc.name, func() { - subCtx, cancel := context.WithTimeout(s.cctx.GoContext(), 60*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) - }) - } + s.Run("1 mebibyte blob", func() { + subCtx, cancel := context.WithTimeout(s.cctx.GoContext(), 60*time.Second) + defer cancel() + res, err := signer.SubmitPayForBlob(subCtx, []*blob.Blob{newBlobWithSize(1 * mebibyte)}, user.SetGasLimit(1_000_000_000)) + require.NoError(t, err) + require.NotNil(t, res) + require.Equal(t, abci.CodeTypeOK, res.Code, res.Logs) + }) } func newBlobWithSize(size int) *blob.Blob { From efcb52d96ac08009a8b2d92bd00545abdd5667ab Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Mon, 27 Nov 2023 16:09:46 -0500 Subject: [PATCH 28/30] refactor: delete test entirely Duplicative of `TestSubmitPayForBlob` in signer_test.go --- app/test/integration_test.go | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/app/test/integration_test.go b/app/test/integration_test.go index 0d84bff3eb..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" @@ -286,25 +285,6 @@ func (s *IntegrationTestSuite) TestEmptyBlock() { } } -// TestSubmitPayForBlob verifies the tx response ABCI code when SubmitPayForBlob -// is invoked with a 1 MiB blob. -func (s *IntegrationTestSuite) TestSubmitPayForBlob() { - t := s.T() - require.NoError(t, s.cctx.WaitForBlocks(1)) - 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) - - s.Run("1 mebibyte blob", func() { - subCtx, cancel := context.WithTimeout(s.cctx.GoContext(), 60*time.Second) - defer cancel() - res, err := signer.SubmitPayForBlob(subCtx, []*blob.Blob{newBlobWithSize(1 * mebibyte)}, user.SetGasLimit(1_000_000_000)) - require.NoError(t, err) - require.NotNil(t, res) - require.Equal(t, abci.CodeTypeOK, res.Code, res.Logs) - }) -} - func newBlobWithSize(size int) *blob.Blob { ns := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize)) data := tmrand.Bytes(size) From 3e0c90216e81eeb52a3fa91e7044d97d0fe98da6 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Mon, 27 Nov 2023 16:19:31 -0500 Subject: [PATCH 29/30] test: new test case for square construction --- pkg/square/square_test.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/square/square_test.go b/pkg/square/square_test.go index 0ae844b223..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) From 4a9d8e50081a3f64ed2544b4b7a1f0df23f2a3f2 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Mon, 27 Nov 2023 16:22:30 -0500 Subject: [PATCH 30/30] revert: network -> net --- x/blob/client/testutil/integration_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x/blob/client/testutil/integration_test.go b/x/blob/client/testutil/integration_test.go index 8c253736f5..886777c4cf 100644 --- a/x/blob/client/testutil/integration_test.go +++ b/x/blob/client/testutil/integration_test.go @@ -42,9 +42,9 @@ func NewIntegrationTestSuite(cfg cosmosnet.Config) *IntegrationTestSuite { func (s *IntegrationTestSuite) SetupSuite() { s.T().Log("setting up integration test suite") - network := network.New(s.T(), s.cfg, username) - s.network = network - s.kr = network.Validators[0].ClientCtx.Keyring + net := network.New(s.T(), s.cfg, username) + s.network = net + s.kr = net.Validators[0].ClientCtx.Keyring _, err := s.network.WaitForHeight(1) s.Require().NoError(err) }