Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: consolidate duplicate test methods #1074

Merged
merged 12 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions app/estimate_square_size_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import (
coretypes "github.com/tendermint/tendermint/types"
)

const (
testEstimateKey = "estimate-key"
)

func Test_estimateSquareSize(t *testing.T) {
type test struct {
name string
Expand All @@ -36,11 +40,11 @@ func Test_estimateSquareSize(t *testing.T) {
{"one over the perfect estimation edge case", 10, 1, appconsts.SparseShareContentSize * 10, 8},
}
encConf := encoding.MakeConfig(ModuleEncodingRegisters...)
signer := generateKeyringSigner(t, "estimate-key")
signer := types.GenerateKeyringSigner(t, testEstimateKey)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
txs := generateManyRawWirePFB(t, encConf.TxConfig, signer, tt.wPFBCount, tt.messgeSize)
txs = append(txs, generateManyRawSendTxs(t, encConf.TxConfig, signer, tt.normalTxs)...)
txs := GenerateManyRawWirePFB(t, encConf.TxConfig, signer, tt.wPFBCount, tt.messgeSize)
txs = append(txs, GenerateManyRawSendTxs(t, encConf.TxConfig, signer, tt.normalTxs)...)
parsedTxs := parseTxs(encConf.TxConfig, txs)
squareSize, totalSharesUsed := estimateSquareSize(parsedTxs, core.EvidenceList{})
assert.Equal(t, tt.expectedSize, squareSize)
Expand Down Expand Up @@ -70,9 +74,9 @@ func Test_estimateSquareSize(t *testing.T) {

func Test_pruning(t *testing.T) {
encConf := encoding.MakeConfig(ModuleEncodingRegisters...)
signer := generateKeyringSigner(t, "estimate-key")
txs := generateManyRawSendTxs(t, encConf.TxConfig, signer, 10)
txs = append(txs, generateManyRawWirePFB(t, encConf.TxConfig, signer, 10, 1000)...)
signer := types.GenerateKeyringSigner(t, testEstimateKey)
txs := GenerateManyRawSendTxs(t, encConf.TxConfig, signer, 10)
txs = append(txs, GenerateManyRawWirePFB(t, encConf.TxConfig, signer, 10, 1000)...)
parsedTxs := parseTxs(encConf.TxConfig, txs)
ss, total := estimateSquareSize(parsedTxs, core.EvidenceList{})
nextLowestSS := ss / 2
Expand Down Expand Up @@ -125,9 +129,9 @@ func Test_overEstimateMalleatedTxSize(t *testing.T) {
}

encConf := encoding.MakeConfig(ModuleEncodingRegisters...)
signer := generateKeyringSigner(t, "estimate-key")
signer := types.GenerateKeyringSigner(t, testEstimateKey)
for _, tt := range tests {
wpfbTx := generateRawWirePFBTx(
wpfbTx := generateRawWirePFB(
t,
encConf.TxConfig,
namespace.RandomBlobNamespace(),
Expand Down Expand Up @@ -163,11 +167,11 @@ func Test_calculateCompactShareCount(t *testing.T) {
{"one over the perfect estimation edge case", 10, 1, totalBlobSize(appconsts.SparseShareContentSize + 1)},
}
encConf := encoding.MakeConfig(ModuleEncodingRegisters...)
signer := generateKeyringSigner(t, "estimate-key")
signer := types.GenerateKeyringSigner(t, testEstimateKey)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
txs := generateManyRawWirePFB(t, encConf.TxConfig, signer, tt.wPFBCount, tt.messgeSize)
txs = append(txs, generateManyRawSendTxs(t, encConf.TxConfig, signer, tt.normalTxs)...)
txs := GenerateManyRawWirePFB(t, encConf.TxConfig, signer, tt.wPFBCount, tt.messgeSize)
txs = append(txs, GenerateManyRawSendTxs(t, encConf.TxConfig, signer, tt.normalTxs)...)

parsedTxs := parseTxs(encConf.TxConfig, txs)
squareSize, totalSharesUsed := estimateSquareSize(parsedTxs, core.EvidenceList{})
Expand Down
8 changes: 4 additions & 4 deletions app/test/fuzz_abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/celestiaorg/celestia-app/app"
"github.com/celestiaorg/celestia-app/app/encoding"
"github.com/celestiaorg/celestia-app/testutil"
paytestutil "github.com/celestiaorg/celestia-app/testutil/blob"
"github.com/celestiaorg/celestia-app/x/blob/types"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
tmrand "github.com/tendermint/tendermint/libs/rand"
Expand All @@ -23,7 +23,7 @@ import (
// when fuzzing.
func TestFuzzPrepareProcessProposal(t *testing.T) {
encConf := encoding.MakeConfig(app.ModuleEncodingRegisters...)
signer := testutil.GenerateKeyringSigner(t, testAccName)
signer := types.GenerateKeyringSigner(t, types.TestAccName)
testApp := testutil.SetupTestAppWithGenesisValSet(t)
timer := time.After(time.Second * 30)
for {
Expand All @@ -32,8 +32,8 @@ func TestFuzzPrepareProcessProposal(t *testing.T) {
return
default:
t.Run("randomized inputs to Prepare and Process Proposal", func(t *testing.T) {
pfbTxs := paytestutil.GenerateManyRawWirePFB(t, encConf.TxConfig, signer, tmrand.Intn(100), -1)
txs := paytestutil.GenerateManyRawSendTxs(t, encConf.TxConfig, signer, tmrand.Intn(20))
pfbTxs := app.GenerateManyRawWirePFB(t, encConf.TxConfig, signer, tmrand.Intn(100), -1)
txs := app.GenerateManyRawSendTxs(t, encConf.TxConfig, signer, tmrand.Intn(20))
txs = append(txs, pfbTxs...)
resp := testApp.PrepareProposal(abci.RequestPrepareProposal{
BlockData: &core.Data{
Expand Down
57 changes: 6 additions & 51 deletions app/test/prepare_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"testing"

"github.com/celestiaorg/nmt/namespace"
"github.com/cosmos/cosmos-sdk/client"
sdk "github.com/cosmos/cosmos-sdk/types"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -21,7 +19,7 @@ import (
)

func TestPrepareProposal(t *testing.T) {
signer := testutil.GenerateKeyringSigner(t, testAccName)
signer := types.GenerateKeyringSigner(t, types.TestAccName)

encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...)

Expand All @@ -35,15 +33,15 @@ func TestPrepareProposal(t *testing.T) {

firstNamespace := []byte{2, 2, 2, 2, 2, 2, 2, 2}
firstBlob := bytes.Repeat([]byte{4}, 512)
firstRawTx := generateRawTx(t, encCfg.TxConfig, firstNamespace, firstBlob, signer)
firstRawTx := app.GenerateRawWirePFB(t, encCfg.TxConfig, firstNamespace, firstBlob, signer)

secondNamespace := []byte{1, 1, 1, 1, 1, 1, 1, 1}
secondBlob := []byte{2}
secondRawTx := generateRawTx(t, encCfg.TxConfig, secondNamespace, secondBlob, signer)
secondRawTx := app.GenerateRawWirePFB(t, encCfg.TxConfig, secondNamespace, secondBlob, signer)

thirdNamespace := []byte{3, 3, 3, 3, 3, 3, 3, 3}
thirdBlob := []byte{1}
thirdRawTx := generateRawTx(t, encCfg.TxConfig, thirdNamespace, thirdBlob, signer)
thirdRawTx := app.GenerateRawWirePFB(t, encCfg.TxConfig, thirdNamespace, thirdBlob, signer)

tests := []test{
{
Expand Down Expand Up @@ -109,7 +107,7 @@ func TestPrepareProposalWithReservedNamespaces(t *testing.T) {
testApp := testutil.SetupTestAppWithGenesisValSet(t)
encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...)

signer := testutil.GenerateKeyringSigner(t, testAccName)
signer := types.GenerateKeyringSigner(t, types.TestAccName)

type test struct {
name string
Expand All @@ -128,7 +126,7 @@ func TestPrepareProposalWithReservedNamespaces(t *testing.T) {

for _, tt := range tests {
blob := []byte{1}
tx := generateRawTx(t, encCfg.TxConfig, tt.namespace, blob, signer)
tx := app.GenerateRawWirePFB(t, encCfg.TxConfig, tt.namespace, blob, signer)
input := abci.RequestPrepareProposal{
BlockData: &core.Data{
Txs: [][]byte{tx},
Expand All @@ -138,46 +136,3 @@ func TestPrepareProposalWithReservedNamespaces(t *testing.T) {
assert.Equal(t, tt.expectedBlobs, len(res.BlockData.Blobs))
}
}

func generateRawTx(t *testing.T, txConfig client.TxConfig, ns, blob []byte, signer *types.KeyringSigner) (rawTx []byte) {
coin := sdk.Coin{
Denom: app.BondDenom,
Amount: sdk.NewInt(10),
}

opts := []types.TxBuilderOption{
types.SetFeeAmount(sdk.NewCoins(coin)),
types.SetGasLimit(10000000),
}

msg := generateSignedWirePayForBlob(t, ns, blob, appconsts.ShareVersionZero, signer, opts)

builder := signer.NewTxBuilder(opts...)

tx, err := signer.BuildSignedTx(builder, msg)
require.NoError(t, err)

// encode the tx
rawTx, err = txConfig.TxEncoder()(tx)
require.NoError(t, err)

return rawTx
}

func generateSignedWirePayForBlob(t *testing.T, ns []byte, blob []byte, shareVersion uint8, signer *types.KeyringSigner, options []types.TxBuilderOption) *types.MsgWirePayForBlob {
msg, err := types.NewWirePayForBlob(ns, blob, shareVersion)
if err != nil {
t.Error(err)
}

err = msg.SignShareCommitment(signer, options...)
if err != nil {
t.Error(err)
}

return msg
}

const (
testAccName = "test-account"
)
7 changes: 3 additions & 4 deletions app/test/process_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,20 @@ import (
"github.com/celestiaorg/celestia-app/app/encoding"
"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/testutil"
paytestutil "github.com/celestiaorg/celestia-app/testutil/blob"
"github.com/celestiaorg/celestia-app/x/blob/types"
"github.com/celestiaorg/nmt/namespace"
sdk "github.com/cosmos/cosmos-sdk/types"
)

func TestBlobInclusionCheck(t *testing.T) {
signer := testutil.GenerateKeyringSigner(t, testAccName)
signer := types.GenerateKeyringSigner(t, types.TestAccName)
testApp := testutil.SetupTestAppWithGenesisValSet(t)
encConf := encoding.MakeConfig(app.ModuleEncodingRegisters...)

// block with all blobs included
validData := func() *core.Data {
return &core.Data{
Txs: paytestutil.GenerateManyRawWirePFB(t, encConf.TxConfig, signer, 4, 1000),
Txs: app.GenerateManyRawWirePFB(t, encConf.TxConfig, signer, 4, 1000),
}
}

Expand Down Expand Up @@ -122,7 +121,7 @@ func TestProcessProposalWithParityShareNamespace(t *testing.T) {
testApp := testutil.SetupTestAppWithGenesisValSet(t)
encConf := encoding.MakeConfig(app.ModuleEncodingRegisters...)

signer := testutil.GenerateKeyringSigner(t, testAccName)
signer := types.GenerateKeyringSigner(t, types.TestAccName)

pfb, blobData := genRandMsgPayForBlobForNamespace(t, signer, appconsts.ParitySharesNamespaceID)
input := abci.RequestProcessProposal{
Expand Down
Loading