From 7cf298a721467d9677ac9b3a8e70eb8c31e405f9 Mon Sep 17 00:00:00 2001 From: zwanga Date: Wed, 15 Jan 2025 00:12:39 +0200 Subject: [PATCH] refactor: refactor mebibyte in the test files --- app/default_overrides_test.go | 9 ++++----- app/test/big_blob_test.go | 4 ++-- app/test/integration_test.go | 2 +- app/test/unit_test.go | 1 - test/util/testnode/comet_node_test.go | 2 +- test/util/testnode/config.go | 2 +- x/blob/ante/blob_share_decorator_test.go | 9 ++++----- x/blob/ante/max_total_blob_size_ante_test.go | 7 ++++--- 8 files changed, 17 insertions(+), 19 deletions(-) diff --git a/app/default_overrides_test.go b/app/default_overrides_test.go index 69d3c876a6..0afdabbc48 100644 --- a/app/default_overrides_test.go +++ b/app/default_overrides_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "github.com/celestiaorg/celestia-app/v3/app" "github.com/celestiaorg/celestia-app/v3/app/encoding" "github.com/cosmos/cosmos-sdk/types" distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" @@ -65,8 +66,7 @@ func TestDefaultAppConfig(t *testing.T) { assert.Equal(t, uint32(2), cfg.StateSync.SnapshotKeepRecent) assert.Equal(t, "0.002utia", cfg.MinGasPrices) - mebibyte := 1048576 - assert.Equal(t, 20*mebibyte, cfg.GRPC.MaxRecvMsgSize) + assert.Equal(t, 20*app.Mebibyte, cfg.GRPC.MaxRecvMsgSize) } func TestDefaultConsensusConfig(t *testing.T) { @@ -93,9 +93,8 @@ func TestDefaultConsensusConfig(t *testing.T) { assert.Equal(t, want, *got.Mempool) }) t.Run("p2p overrides", func(t *testing.T) { - const mebibyte = 1048576 - assert.Equal(t, int64(10*mebibyte), got.P2P.SendRate) - assert.Equal(t, int64(10*mebibyte), got.P2P.RecvRate) + assert.Equal(t, int64(10*app.Mebibyte), got.P2P.SendRate) + assert.Equal(t, int64(10*app.Mebibyte), got.P2P.RecvRate) }) } diff --git a/app/test/big_blob_test.go b/app/test/big_blob_test.go index bbce473016..2909980de6 100644 --- a/app/test/big_blob_test.go +++ b/app/test/big_blob_test.go @@ -39,10 +39,10 @@ func (s *BigBlobSuite) SetupSuite() { s.accounts = testfactory.GenerateAccounts(1) tmConfig := testnode.DefaultTendermintConfig() - tmConfig.Mempool.MaxTxBytes = 10 * mebibyte + tmConfig.Mempool.MaxTxBytes = 10 * app.Mebibyte cParams := testnode.DefaultConsensusParams() - cParams.Block.MaxBytes = 10 * mebibyte + cParams.Block.MaxBytes = 10 * app.Mebibyte cfg := testnode.DefaultConfig(). WithFundedAccounts(s.accounts...). diff --git a/app/test/integration_test.go b/app/test/integration_test.go index 7ee8e08d2d..6acabc783f 100644 --- a/app/test/integration_test.go +++ b/app/test/integration_test.go @@ -128,7 +128,7 @@ func (s *IntegrationTestSuite) TestMaxBlockSize() { 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) + require.LessOrEqual(t, len(tx), 1*app.Mebibyte) res, err := s.cctx.Context.BroadcastTxSync(tx) require.NoError(t, err) diff --git a/app/test/unit_test.go b/app/test/unit_test.go index 83fa292438..63c9fa5483 100644 --- a/app/test/unit_test.go +++ b/app/test/unit_test.go @@ -2,5 +2,4 @@ package app_test const ( kibibyte = 1024 - mebibyte = 1024 * kibibyte ) diff --git a/test/util/testnode/comet_node_test.go b/test/util/testnode/comet_node_test.go index 63222ca66e..741dcec881 100644 --- a/test/util/testnode/comet_node_test.go +++ b/test/util/testnode/comet_node_test.go @@ -46,7 +46,7 @@ func customTendermintConfig() *tmconfig.Config { // Override the MaxBodyBytes to allow the testnode to accept very large // transactions and respond to queries with large responses (200 MiB was // chosen only as an arbitrary large number). - tmCfg.RPC.MaxBodyBytes = 200 * mebibyte + tmCfg.RPC.MaxBodyBytes = 200 * Mebibyte tmCfg.RPC.TimeoutBroadcastTxCommit = time.Minute return tmCfg diff --git a/test/util/testnode/config.go b/test/util/testnode/config.go index 32b94a3a9c..2cc3b903a6 100644 --- a/test/util/testnode/config.go +++ b/test/util/testnode/config.go @@ -22,7 +22,7 @@ import ( const ( kibibyte = 1024 // bytes - mebibyte = 1_048_576 // bytes + Mebibyte = 1_048_576 // bytes DefaultValidatorAccountName = "validator" DefaultInitialBalance = genesis.DefaultInitialBalance ) diff --git a/x/blob/ante/blob_share_decorator_test.go b/x/blob/ante/blob_share_decorator_test.go index e65dca6c3f..27de086ab1 100644 --- a/x/blob/ante/blob_share_decorator_test.go +++ b/x/blob/ante/blob_share_decorator_test.go @@ -24,7 +24,6 @@ import ( ) const ( - mebibyte = 1_048_576 // 1 MiB squareSize = 64 ) @@ -42,7 +41,7 @@ func TestBlobShareDecorator(t *testing.T) { { name: "want no error if appVersion v1 and 8 MiB blob", blobsPerPFB: 1, - blobSize: 8 * mebibyte, + blobSize: 8 * testnode.Mebibyte, appVersion: v1.Version, }, { @@ -54,13 +53,13 @@ func TestBlobShareDecorator(t *testing.T) { { name: "PFB with 1 blob that is 1 MiB", blobsPerPFB: 1, - blobSize: 1 * mebibyte, + blobSize: 1 * testnode.Mebibyte, appVersion: v2.Version, }, { name: "PFB with 1 blob that is 2 MiB", blobsPerPFB: 1, - blobSize: 2 * mebibyte, + blobSize: 2 * testnode.Mebibyte, appVersion: v2.Version, // This test case should return an error because a square size of 64 // has exactly 2 MiB of total capacity so the total blob capacity @@ -76,7 +75,7 @@ func TestBlobShareDecorator(t *testing.T) { { name: "PFB with 2 blobs that are 1 MiB each", blobsPerPFB: 2, - blobSize: 1 * mebibyte, + blobSize: 1 * testnode.Mebibyte, appVersion: v2.Version, // This test case should return an error for the same reason a // single blob that is 2 MiB returns an error. diff --git a/x/blob/ante/max_total_blob_size_ante_test.go b/x/blob/ante/max_total_blob_size_ante_test.go index 5156bc89a7..18089e7faa 100644 --- a/x/blob/ante/max_total_blob_size_ante_test.go +++ b/x/blob/ante/max_total_blob_size_ante_test.go @@ -7,6 +7,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/app/encoding" v1 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v1" v2 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v2" + "github.com/celestiaorg/celestia-app/v3/test/util/testnode" ante "github.com/celestiaorg/celestia-app/v3/x/blob/ante" blob "github.com/celestiaorg/celestia-app/v3/x/blob/types" "github.com/celestiaorg/go-square/v2/share" @@ -43,14 +44,14 @@ func TestMaxTotalBlobSizeDecorator(t *testing.T) { { name: "PFB with 1 blob that is 1 MiB", pfb: &blob.MsgPayForBlobs{ - BlobSizes: []uint32{mebibyte}, + BlobSizes: []uint32{testnode.Mebibyte}, }, appVersion: v1.Version, }, { name: "PFB with 1 blob that is 2 MiB", pfb: &blob.MsgPayForBlobs{ - BlobSizes: []uint32{2 * mebibyte}, + BlobSizes: []uint32{2 * testnode.Mebibyte}, }, appVersion: v1.Version, // This test case should return an error because a square size of 64 @@ -68,7 +69,7 @@ func TestMaxTotalBlobSizeDecorator(t *testing.T) { { name: "PFB with 2 blobs that are 1 MiB each", pfb: &blob.MsgPayForBlobs{ - BlobSizes: []uint32{mebibyte, mebibyte}, + BlobSizes: []uint32{testnode.Mebibyte, testnode.Mebibyte}, }, appVersion: v1.Version, // This test case should return an error for the same reason a