Skip to content

Commit

Permalink
improvement: move sealing to init function (#1348)
Browse files Browse the repository at this point in the history
## Overview
Closes celestiaorg/celestia-app#1331

## Checklist

<!-- 
Please complete the checklist to ensure that the PR is ready to be
reviewed.

IMPORTANT:
PRs should be left in Draft until the below checklist is completed.
-->

- [x] New and updated code has appropriate documentation
- [x] New and updated code has new and/or updated testing
- [x] Required CI checks are passing
- [x] Visual proof for any user facing features like CLI or
documentation updates
- [x] Linked issues closed with keywords
  • Loading branch information
vgonkivs authored Feb 8, 2023
1 parent 40ce231 commit 4ea0418
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
13 changes: 13 additions & 0 deletions app/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package app

import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

func init() {
cfg := sdk.GetConfig()
cfg.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub)
cfg.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub)
cfg.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub)
cfg.Seal()
}
17 changes: 9 additions & 8 deletions app/estimate_square_size_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ package app
import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
coretypes "github.com/tendermint/tendermint/types"

"github.com/celestiaorg/celestia-app/app/encoding"
"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/pkg/shares"
"github.com/celestiaorg/celestia-app/testutil/blobfactory"
"github.com/celestiaorg/celestia-app/testutil/namespace"
"github.com/celestiaorg/celestia-app/testutil/testfactory"
blobtypes "github.com/celestiaorg/celestia-app/x/blob/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
coretypes "github.com/tendermint/tendermint/types"
)

func Test_estimateSquareSize(t *testing.T) {
Expand Down Expand Up @@ -146,18 +147,18 @@ func Test_estimatePFBTxSharesUsed(t *testing.T) {
}

func Test_estimateTxSharesUsed(t *testing.T) {
require.Equal(t, 312, len(generateNormalTxs(3)[2]))
require.Equal(t, 316, len(generateNormalTxs(3)[2]))
type testCase struct {
name string
txs [][]byte
want int
}
testCases := []testCase{
{"empty", [][]byte{}, 0},
{"one tx", generateNormalTxs(1), 1}, // 1 tx is approximately 312 bytes which fits in 1 share
{"two txs", generateNormalTxs(2), 2}, // 2 txs is approximately 624 bytes which fits in 2 shares
{"ten txs", generateNormalTxs(10), 7}, // 10 txs is approximately 3120 bytes which fits in 7 shares
{"one hundred txs", generateNormalTxs(100), 63}, // 100 txs is approximately 31200 bytes which fits in 63 share
{"one tx", generateNormalTxs(1), 1}, // 1 tx is approximately 316 bytes which fits in 1 share
{"two txs", generateNormalTxs(2), 2}, // 2 txs is approximately 632 bytes which fits in 2 shares
{"ten txs", generateNormalTxs(10), 7}, // 10 txs is approximately 3160 bytes which fits in 7 shares
{"one hundred txs", generateNormalTxs(100), 64}, // 100 txs is approximately 31600 bytes which fits in 64 share
}
for _, tc := range testCases {
got := estimateTxSharesUsed(tc.txs)
Expand Down
6 changes: 0 additions & 6 deletions cmd/celestia-appd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ const EnvPrefix = "CELESTIA"
func NewRootCmd() *cobra.Command {
encodingConfig := encoding.MakeConfig(app.ModuleEncodingRegisters...)

cfg := sdk.GetConfig()
cfg.SetBech32PrefixForAccount(app.Bech32PrefixAccAddr, app.Bech32PrefixAccPub)
cfg.SetBech32PrefixForValidator(app.Bech32PrefixValAddr, app.Bech32PrefixValPub)
cfg.SetBech32PrefixForConsensusNode(app.Bech32PrefixConsAddr, app.Bech32PrefixConsPub)
cfg.Seal()

initClientCtx := client.Context{}.
WithCodec(encodingConfig.Codec).
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
Expand Down

0 comments on commit 4ea0418

Please sign in to comment.