Skip to content

Commit

Permalink
chore: enable stylecheck (#2005)
Browse files Browse the repository at this point in the history
Closes #1989
  • Loading branch information
rootulp authored and evan-forbes committed Jul 3, 2023
1 parent 2722a5e commit 6218584
Show file tree
Hide file tree
Showing 24 changed files with 73 additions and 93 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ linters:
- nakedret
- revive
- prealloc
- stylecheck

linters-settings:
nakedret:
Expand Down
3 changes: 1 addition & 2 deletions app/test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
appns "github.com/celestiaorg/celestia-app/pkg/namespace"
"github.com/celestiaorg/celestia-app/pkg/square"
"github.com/celestiaorg/celestia-app/x/blob"
"github.com/celestiaorg/celestia-app/x/blob/types"
blobtypes "github.com/celestiaorg/celestia-app/x/blob/types"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -227,7 +226,7 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() {
{
"large random typical",
mustNewBlob(ns1, tmrand.Bytes(350000), appconsts.ShareVersionZero),
[]types.TxBuilderOption{
[]blobtypes.TxBuilderOption{
blobtypes.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(app.BondDenom, sdk.NewInt(10)))),
blobtypes.SetGasLimit(1_000_000_000),
},
Expand Down
51 changes: 25 additions & 26 deletions app/test/process_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
tmrand "github.com/tendermint/tendermint/libs/rand"
core "github.com/tendermint/tendermint/proto/tendermint/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
coretypes "github.com/tendermint/tendermint/types"

Expand Down Expand Up @@ -80,40 +79,40 @@ func TestProcessProposal(t *testing.T) {

type test struct {
name string
input *core.Data
mutator func(*core.Data)
input *tmproto.Data
mutator func(*tmproto.Data)
expectedResult abci.ResponseProcessProposal_Result
}

tests := []test{
{
name: "valid untouched data",
input: validData(),
mutator: func(d *core.Data) {},
mutator: func(d *tmproto.Data) {},
expectedResult: abci.ResponseProcessProposal_ACCEPT,
},
{
name: "removed first blob tx",
input: validData(),
mutator: func(d *core.Data) {
mutator: func(d *tmproto.Data) {
d.Txs = d.Txs[1:]
},
expectedResult: abci.ResponseProcessProposal_REJECT,
},
{
name: "added an extra blob tx",
input: validData(),
mutator: func(d *core.Data) {
mutator: func(d *tmproto.Data) {
d.Txs = append(d.Txs, blobTxs[3])
},
expectedResult: abci.ResponseProcessProposal_REJECT,
},
{
name: "modified a blobTx",
input: validData(),
mutator: func(d *core.Data) {
mutator: func(d *tmproto.Data) {
blobTx, _ := coretypes.UnmarshalBlobTx(blobTxs[0])
blobTx.Blobs[0] = &core.Blob{
blobTx.Blobs[0] = &tmproto.Blob{
NamespaceId: ns1.ID,
Data: data,
NamespaceVersion: uint32(ns1.Version),
Expand All @@ -127,9 +126,9 @@ func TestProcessProposal(t *testing.T) {
{
name: "invalid namespace TailPadding",
input: validData(),
mutator: func(d *core.Data) {
mutator: func(d *tmproto.Data) {
blobTx, _ := coretypes.UnmarshalBlobTx(blobTxs[0])
blobTx.Blobs[0] = &core.Blob{
blobTx.Blobs[0] = &tmproto.Blob{
NamespaceId: appns.TailPaddingNamespace.ID,
Data: data,
NamespaceVersion: uint32(appns.TailPaddingNamespace.Version),
Expand All @@ -143,9 +142,9 @@ func TestProcessProposal(t *testing.T) {
{
name: "invalid namespace TxNamespace",
input: validData(),
mutator: func(d *core.Data) {
mutator: func(d *tmproto.Data) {
blobTx, _ := coretypes.UnmarshalBlobTx(blobTxs[0])
blobTx.Blobs[0] = &core.Blob{
blobTx.Blobs[0] = &tmproto.Blob{
NamespaceId: appns.TxNamespace.ID,
Data: data,
NamespaceVersion: uint32(appns.TxNamespace.Version),
Expand All @@ -159,9 +158,9 @@ func TestProcessProposal(t *testing.T) {
{
name: "invalid namespace ParityShares",
input: validData(),
mutator: func(d *core.Data) {
mutator: func(d *tmproto.Data) {
blobTx, _ := coretypes.UnmarshalBlobTx(blobTxs[0])
blobTx.Blobs[0] = &core.Blob{
blobTx.Blobs[0] = &tmproto.Blob{
NamespaceId: appns.ParitySharesNamespace.ID,
Data: data,
NamespaceVersion: uint32(appns.ParitySharesNamespace.Version),
Expand All @@ -175,9 +174,9 @@ func TestProcessProposal(t *testing.T) {
{
name: "invalid blob namespace",
input: validData(),
mutator: func(d *core.Data) {
mutator: func(d *tmproto.Data) {
blobTx, _ := coretypes.UnmarshalBlobTx(blobTxs[0])
blobTx.Blobs[0] = &core.Blob{
blobTx.Blobs[0] = &tmproto.Blob{
NamespaceId: invalidNamespace.ID,
Data: data,
ShareVersion: uint32(appconsts.ShareVersionZero),
Expand All @@ -191,7 +190,7 @@ func TestProcessProposal(t *testing.T) {
{
name: "pfb namespace version does not match blob",
input: validData(),
mutator: func(d *core.Data) {
mutator: func(d *tmproto.Data) {
blobTx, _ := coretypes.UnmarshalBlobTx(blobTxs[0])
blobTx.Blobs[0].NamespaceVersion = appns.NamespaceVersionMax
blobTxBytes, _ := blobTx.Marshal()
Expand All @@ -203,7 +202,7 @@ func TestProcessProposal(t *testing.T) {
{
name: "invalid namespace in index wrapper tx",
input: validData(),
mutator: func(d *core.Data) {
mutator: func(d *tmproto.Data) {
encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...)
index := 4
tx, blob := blobfactory.IndexWrappedTxWithInvalidNamespace(t, encCfg.TxConfig.TxEncoder(), tmrand.NewRand(), signer, 0, 0, uint32(index))
Expand All @@ -221,7 +220,7 @@ func TestProcessProposal(t *testing.T) {
{
name: "swap blobTxs",
input: validData(),
mutator: func(d *core.Data) {
mutator: func(d *tmproto.Data) {
// swapping the order will cause the data root to be different
d.Txs[0], d.Txs[1], d.Txs[2] = d.Txs[1], d.Txs[2], d.Txs[0]
},
Expand All @@ -230,7 +229,7 @@ func TestProcessProposal(t *testing.T) {
{
name: "PFB without blobTx",
input: validData(),
mutator: func(d *core.Data) {
mutator: func(d *tmproto.Data) {
btx, _ := coretypes.UnmarshalBlobTx(blobTxs[3])
d.Txs = append(d.Txs, btx.Tx)
},
Expand All @@ -239,15 +238,15 @@ func TestProcessProposal(t *testing.T) {
{
name: "undecodable tx",
input: validData(),
mutator: func(d *core.Data) {
mutator: func(d *tmproto.Data) {
d.Txs = append(d.Txs, tmrand.Bytes(300))
},
expectedResult: abci.ResponseProcessProposal_REJECT,
},
{
name: "incorrectly sorted; send tx after pfb",
input: mixedData,
mutator: func(d *core.Data) {
mutator: func(d *tmproto.Data) {
// swap txs at index 2 and 3 (essentially swapping a PFB with a normal tx)
d.Txs[3], d.Txs[2] = d.Txs[2], d.Txs[3]
},
Expand All @@ -256,7 +255,7 @@ func TestProcessProposal(t *testing.T) {
{
name: "included pfb with bad signature",
input: validData(),
mutator: func(d *core.Data) {
mutator: func(d *tmproto.Data) {
d.Txs = append(d.Txs, badSigBlobTx)
d.Hash = calculateNewDataHash(t, d.Txs)
},
Expand All @@ -265,7 +264,7 @@ func TestProcessProposal(t *testing.T) {
{
name: "included pfb with incorrect nonce",
input: validData(),
mutator: func(d *core.Data) {
mutator: func(d *tmproto.Data) {
d.Txs = append(d.Txs, blobTxWithInvalidNonce)
d.Hash = calculateNewDataHash(t, d.Txs)
},
Expand All @@ -276,7 +275,7 @@ func TestProcessProposal(t *testing.T) {
input: &tmproto.Data{
Txs: coretypes.Txs(sendTxs).ToSliceOfBytes(),
},
mutator: func(d *core.Data) {
mutator: func(d *tmproto.Data) {
dataSquare, err := square.Construct(d.Txs, appconsts.LatestVersion, appconsts.DefaultSquareSizeUpperBound)
require.NoError(t, err)

Expand Down Expand Up @@ -307,7 +306,7 @@ func TestProcessProposal(t *testing.T) {
tt.mutator(resp.BlockData)
res := testApp.ProcessProposal(abci.RequestProcessProposal{
BlockData: resp.BlockData,
Header: core.Header{
Header: tmproto.Header{
Height: 1,
DataHash: resp.BlockData.Hash,
},
Expand Down
5 changes: 2 additions & 3 deletions app/validate_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package app
import (
"github.com/cosmos/cosmos-sdk/client"
sdk "github.com/cosmos/cosmos-sdk/types"
core "github.com/tendermint/tendermint/proto/tendermint/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
coretypes "github.com/tendermint/tendermint/types"
)

// separateTxs decodes raw tendermint txs into normal and blob txs.
func separateTxs(_ client.TxConfig, rawTxs [][]byte) ([][]byte, []core.BlobTx) {
func separateTxs(_ client.TxConfig, rawTxs [][]byte) ([][]byte, []tmproto.BlobTx) {
normalTxs := make([][]byte, 0, len(rawTxs))
blobTxs := make([]core.BlobTx, 0, len(rawTxs))
blobTxs := make([]tmproto.BlobTx, 0, len(rawTxs))
for _, rawTx := range rawTxs {
bTx, isBlob := coretypes.UnmarshalBlobTx(rawTx)
if isBlob {
Expand Down
2 changes: 1 addition & 1 deletion pkg/shares/share_sequence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func generateValidShareSequence(t *testing.T) ShareSequence {
}
}

func Fuzz_validSequenceLen(f *testing.F) {
func FuzzValidSequenceLen(f *testing.F) {
f.Fuzz(func(t *testing.T, rawData []byte, rawNamespace []byte) {
share, err := NewShare(rawData)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/shares/split_compact_shares_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"testing"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/pkg/namespace"
appns "github.com/celestiaorg/celestia-app/pkg/namespace"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -39,7 +38,7 @@ func TestCount(t *testing.T) {
}
}

css := NewCompactShareSplitter(namespace.TxNamespace, appconsts.ShareVersionZero)
css := NewCompactShareSplitter(appns.TxNamespace, appconsts.ShareVersionZero)
assert.Equal(t, 0, css.Count())
}

Expand Down
6 changes: 2 additions & 4 deletions pkg/square/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
"github.com/celestiaorg/celestia-app/test/util/testfactory"
"github.com/stretchr/testify/require"
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/types"
core "github.com/tendermint/tendermint/types"
coretypes "github.com/tendermint/tendermint/types"
)

Expand Down Expand Up @@ -216,7 +214,7 @@ func TestBuilderFindTxShareRange(t *testing.T) {

var lastEnd int
for idx, tx := range blockTxs {
blobTx, isBlobTx := types.UnmarshalBlobTx(tx)
blobTx, isBlobTx := coretypes.UnmarshalBlobTx(tx)
if isBlobTx {
tx = blobTx.Tx
}
Expand Down Expand Up @@ -409,7 +407,7 @@ func TestSquareBlobPostions(t *testing.T) {
builder, err := square.NewBuilder(tt.squareSize, appconsts.DefaultSubtreeRootThreshold)
require.NoError(t, err)
for _, tx := range tt.blobTxs {
blobTx, isBlobTx := core.UnmarshalBlobTx(tx)
blobTx, isBlobTx := coretypes.UnmarshalBlobTx(tx)
require.True(t, isBlobTx)
_ = builder.AppendBlobTx(blobTx)
}
Expand Down
11 changes: 5 additions & 6 deletions pkg/square/square_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/celestiaorg/rsmt2d"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/types"
coretypes "github.com/tendermint/tendermint/types"
)

Expand Down Expand Up @@ -53,9 +52,9 @@ func TestSquareTxShareRange(t *testing.T) {
expectErr bool
}

txOne := types.Tx{0x1}
txTwo := types.Tx(bytes.Repeat([]byte{2}, 600))
txThree := types.Tx(bytes.Repeat([]byte{3}, 1000))
txOne := coretypes.Tx{0x1}
txTwo := coretypes.Tx(bytes.Repeat([]byte{2}, 600))
txThree := coretypes.Tx(bytes.Repeat([]byte{3}, 1000))

testCases := []test{
{
Expand Down Expand Up @@ -190,7 +189,7 @@ func TestSquareDeconstruct(t *testing.T) {
})
t.Run("NoPFBs", func(t *testing.T) {
const numTxs = 10
txs := types.Txs(blobfactory.GenerateManyRawSendTxs(encCfg.TxConfig, numTxs)).ToSliceOfBytes()
txs := coretypes.Txs(blobfactory.GenerateManyRawSendTxs(encCfg.TxConfig, numTxs)).ToSliceOfBytes()
dataSquare, err := square.Construct(txs, appconsts.LatestVersion, appconsts.DefaultSquareSizeUpperBound)
require.NoError(t, err)
recomputedTxs, err := square.Deconstruct(dataSquare, encCfg.TxConfig.TxDecoder())
Expand All @@ -208,7 +207,7 @@ func TestSquareDeconstruct(t *testing.T) {
t.Run("EmptySquare", func(t *testing.T) {
tx, err := square.Deconstruct(square.EmptySquare(), encCfg.TxConfig.TxDecoder())
require.NoError(t, err)
require.Equal(t, types.Txs{}, tx)
require.Equal(t, coretypes.Txs{}, tx)
})
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/wrapper/nmt_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"testing"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/pkg/namespace"
appns "github.com/celestiaorg/celestia-app/pkg/namespace"
"github.com/celestiaorg/celestia-app/test/util/testfactory"
"github.com/celestiaorg/nmt"
Expand Down Expand Up @@ -50,7 +49,7 @@ func TestRootErasuredNamespacedMerkleTree(t *testing.T) {
size := 8
data := testfactory.GenerateRandNamespacedRawData(size)
nmtErasured := NewErasuredNamespacedMerkleTree(uint64(size), 0)
nmtStandard := nmt.New(sha256.New(), nmt.NamespaceIDSize(namespace.NamespaceSize), nmt.IgnoreMaxNamespace(true))
nmtStandard := nmt.New(sha256.New(), nmt.NamespaceIDSize(appns.NamespaceSize), nmt.IgnoreMaxNamespace(true))

for _, d := range data {
err := nmtErasured.Push(d)
Expand Down
2 changes: 1 addition & 1 deletion test/txsim/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func Run(
if err == nil { // should never happen
continue
}
if errors.Is(err, EndOfSequence) {
if errors.Is(err, ErrEndOfSequence) {
log.Info().Err(err).Msg("sequence terminated")
continue
}
Expand Down
2 changes: 1 addition & 1 deletion test/txsim/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (s *SendSequence) Init(_ context.Context, _ grpc.ClientConn, allocateAccoun
// Next sumbits a transaction to remove funds from one account to the next
func (s *SendSequence) Next(_ context.Context, _ grpc.ClientConn, rand *rand.Rand) (Operation, error) {
if s.index >= s.numIterations {
return Operation{}, EndOfSequence
return Operation{}, ErrEndOfSequence
}
op := Operation{
Msgs: []types.Msg{
Expand Down
5 changes: 2 additions & 3 deletions test/txsim/sequence.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ const (
DefaultGasLimit = 1000000
)

// EndOfSequence is a special error which indicates that the sequence has been terminated
// nolint: revive
var EndOfSequence = errors.New("end of sequence")
// ErrEndOfSequence is a special error which indicates that the sequence has been terminated
var ErrEndOfSequence = errors.New("end of sequence")

// AccountAllocator reserves and funds a series of accounts to be used exclusively by
// the Sequence.
Expand Down
Loading

0 comments on commit 6218584

Please sign in to comment.