Skip to content

Commit

Permalink
chore: rebase bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vidhanarya committed Nov 29, 2022
1 parent f30429a commit 47ceb96
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 41 deletions.
8 changes: 4 additions & 4 deletions app/estimate_square_size_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func Test_estimateSquareSize(t *testing.T) {
signer := types.GenerateKeyringSigner(t, testEstimateKey)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
txs := GenerateManyRawWirePFBTxs(t, encConf.TxConfig, signer, tt.wPFBCount, tt.messgeSize)
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 Expand Up @@ -76,7 +76,7 @@ func Test_pruning(t *testing.T) {
encConf := encoding.MakeConfig(ModuleEncodingRegisters...)
signer := types.GenerateKeyringSigner(t, testEstimateKey)
txs := GenerateManyRawSendTxs(t, encConf.TxConfig, signer, 10)
txs = append(txs, GenerateManyRawWirePFBTxs(t, encConf.TxConfig, signer, 10, 1000)...)
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 @@ -131,7 +131,7 @@ func Test_overEstimateMalleatedTxSize(t *testing.T) {
encConf := encoding.MakeConfig(ModuleEncodingRegisters...)
signer := types.GenerateKeyringSigner(t, testEstimateKey)
for _, tt := range tests {
wpfbTx := generateRawWirePFBTx(
wpfbTx := generateRawWirePFB(
t,
encConf.TxConfig,
namespace.RandomBlobNamespace(),
Expand Down Expand Up @@ -170,7 +170,7 @@ func Test_calculateCompactShareCount(t *testing.T) {
signer := types.GenerateKeyringSigner(t, testEstimateKey)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
txs := GenerateManyRawWirePFBTxs(t, encConf.TxConfig, signer, tt.wPFBCount, tt.messgeSize)
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)
Expand Down
2 changes: 1 addition & 1 deletion app/test/fuzz_abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestFuzzPrepareProcessProposal(t *testing.T) {
return
default:
t.Run("randomized inputs to Prepare and Process Proposal", func(t *testing.T) {
pfbTxs := app.GenerateManyRawWirePFBTxs(t, encConf.TxConfig, signer, tmrand.Intn(100), -1)
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{
Expand Down
8 changes: 4 additions & 4 deletions app/test/prepare_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,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 := app.GenerateRawWirePFBTxs(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 := app.GenerateRawWirePFBTxs(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 := app.GenerateRawWirePFBTxs(t, encCfg.TxConfig, thirdNamespace, thirdBlob, signer)
thirdRawTx := app.GenerateRawWirePFB(t, encCfg.TxConfig, thirdNamespace, thirdBlob, signer)

tests := []test{
{
Expand Down Expand Up @@ -126,7 +126,7 @@ func TestPrepareProposalWithReservedNamespaces(t *testing.T) {

for _, tt := range tests {
blob := []byte{1}
tx := app.GenerateRawWirePFBTxs(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 Down
2 changes: 1 addition & 1 deletion app/test/process_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestBlobInclusionCheck(t *testing.T) {
// block with all blobs included
validData := func() *core.Data {
return &core.Data{
Txs: app.GenerateManyRawWirePFBTxs(t, encConf.TxConfig, signer, 4, 1000),
Txs: app.GenerateManyRawWirePFB(t, encConf.TxConfig, signer, 4, 1000),
}
}

Expand Down
16 changes: 8 additions & 8 deletions app/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func GenerateManyRawWirePFB(t *testing.T, txConfig client.TxConfig, signer *type
if size < 0 || size > 3000000 {
size = tmrand.Intn(1000000)
}
wpfbTx := generateRawWirePFBTx(
wpfbTx := generateRawWirePFB(
t,
txConfig,
namespace.RandomBlobNamespace(),
Expand All @@ -85,7 +85,7 @@ func GenerateManyRawWirePFB(t *testing.T, txConfig client.TxConfig, signer *type
return txs
}

func GenerateRawWirePFBTxs(t *testing.T, txConfig client.TxConfig, ns, message []byte, signer *types.KeyringSigner) (rawTx []byte) {
func GenerateRawWirePFB(t *testing.T, txConfig client.TxConfig, ns, blob []byte, signer *types.KeyringSigner) (rawTx []byte) {
coin := sdk.Coin{
Denom: BondDenom,
Amount: sdk.NewInt(10),
Expand All @@ -96,19 +96,19 @@ func GenerateRawWirePFBTxs(t *testing.T, txConfig client.TxConfig, ns, message [
types.SetGasLimit(10000000),
}

return generateRawWirePFBTx(
return generateRawWirePFB(
t,
txConfig,
ns,
message,
blob,
appconsts.ShareVersionZero,
signer,
opts...,
)
}

func GenerateSignedWirePayForBlob(t *testing.T, ns []byte, message []byte, shareVersion uint8, signer *types.KeyringSigner, options []types.TxBuilderOption) *types.MsgWirePayForBlob {
msg, err := types.NewWirePayForBlob(ns, message, shareVersion)
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)
}
Expand Down Expand Up @@ -157,9 +157,9 @@ func generateRawSendTx(t *testing.T, txConfig client.TxConfig, signer *types.Key
return genrateRawTx(t, txConfig, msg, signer, opts...)
}

// generateRawWirePFBTx creates a tx with a single MsgWirePayForBlob using
// generateRawWirePFB creates a tx with a single MsgWirePayForBlob using
// the provided namespace, blob, and shareVersion
func generateRawWirePFBTx(t *testing.T, txConfig client.TxConfig, ns []byte, blob []byte, shareVersion uint8, signer *types.KeyringSigner, opts ...types.TxBuilderOption) (rawTx []byte) {
func generateRawWirePFB(t *testing.T, txConfig client.TxConfig, ns []byte, blob []byte, shareVersion uint8, signer *types.KeyringSigner, opts ...types.TxBuilderOption) (rawTx []byte) {
msg := GenerateSignedWirePayForBlob(t, ns, blob, shareVersion, signer, opts)
return genrateRawTx(t, txConfig, msg, signer, opts...)
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/prove/proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (

func TestTxInclusion(t *testing.T) {
typicalBlockData := types.Data{
Txs: testfactory.GenerateRandomlySizedTransactions(100, 500),
Txs: testfactory.GenerateRandomlySizedTxs(100, 500),
Blobs: testfactory.GenerateRandomlySizedBlobs(40, 16000),
SquareSize: 64,
}
lotsOfTxsNoBlobs := types.Data{
Txs: testfactory.GenerateRandomlySizedTransactions(1000, 500),
Txs: testfactory.GenerateRandomlySizedTxs(1000, 500),
SquareSize: 64,
}
overlappingSquareSize := 16
Expand Down Expand Up @@ -79,30 +79,30 @@ func TestTxSharePosition(t *testing.T) {
tests := []test{
{
name: "typical",
txs: testfactory.GenerateRandomlySizedTransactions(44, 200),
txs: testfactory.GenerateRandomlySizedTxs(44, 200),
},
{
name: "many small tx",
txs: testfactory.GenerateRandomlySizedTransactions(444, 100),
txs: testfactory.GenerateRandomlySizedTxs(444, 100),
},
{
// this is a concrete output from factory.GenerateRandomlySizedTransactions(444, 100)
// this is a concrete output from testfactory.GenerateRandomlySizedTxs(444, 100)
// that surfaced a bug in txSharePositions so it is included here to
// prevent regressions
name: "many small tx (without randomness)",
txs: manySmallTxsWithoutRandomness,
},
{
name: "one small tx",
txs: testfactory.GenerateRandomlySizedTransactions(1, 200),
txs: testfactory.GenerateRandomlySizedTxs(1, 200),
},
{
name: "one large tx",
txs: testfactory.GenerateRandomlySizedTransactions(1, 2000),
txs: testfactory.GenerateRandomlySizedTxs(1, 2000),
},
{
name: "many large txs",
txs: testfactory.GenerateRandomlySizedTransactions(100, 2000),
txs: testfactory.GenerateRandomlySizedTxs(100, 2000),
},
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/shares/compact_shares_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestCompactShareWriter(t *testing.T) {
// note that this test is mainly for debugging purposes, the main round trip
// tests occur in TestMerge and Test_processCompactShares
w := NewCompactShareSplitter(appconsts.TxNamespaceID, appconsts.ShareVersionZero)
txs := testfactory.GenerateRandomTransactions(33, 200)
txs := testfactory.GenerateRandomTxs(33, 200)
for _, tx := range txs {
rawTx, _ := MarshalDelimitedTx(tx)
w.WriteBytes(rawTx)
Expand Down Expand Up @@ -75,7 +75,7 @@ func Test_processCompactShares(t *testing.T) {

// run the tests with identically sized txs
t.Run(fmt.Sprintf("%s idendically sized", tc.name), func(t *testing.T) {
txs := testfactory.GenerateRandomTransactions(tc.txCount, tc.txSize)
txs := testfactory.GenerateRandomTxs(tc.txCount, tc.txSize)

shares := SplitTxs(txs)
rawShares := ToBytes(shares)
Expand All @@ -93,7 +93,7 @@ func Test_processCompactShares(t *testing.T) {

// run the same tests using randomly sized txs with caps of tc.txSize
t.Run(fmt.Sprintf("%s randomly sized", tc.name), func(t *testing.T) {
txs := testfactory.GenerateRandomlySizedTransactions(tc.txCount, tc.txSize)
txs := testfactory.GenerateRandomlySizedTxs(tc.txCount, tc.txSize)

shares := SplitTxs(txs)
rawShares := ToBytes(shares)
Expand All @@ -113,7 +113,7 @@ func Test_processCompactShares(t *testing.T) {

func TestCompactShareContainsInfoByte(t *testing.T) {
css := NewCompactShareSplitter(appconsts.TxNamespaceID, appconsts.ShareVersionZero)
txs := testfactory.GenerateRandomTransactions(1, appconsts.ContinuationCompactShareContentSize/4)
txs := testfactory.GenerateRandomTxs(1, appconsts.ContinuationCompactShareContentSize/4)

for _, tx := range txs {
css.WriteTx(tx)
Expand All @@ -133,7 +133,7 @@ func TestCompactShareContainsInfoByte(t *testing.T) {

func TestContiguousCompactShareContainsInfoByte(t *testing.T) {
css := NewCompactShareSplitter(appconsts.TxNamespaceID, appconsts.ShareVersionZero)
txs := testfactory.GenerateRandomTransactions(1, appconsts.ContinuationCompactShareContentSize*4)
txs := testfactory.GenerateRandomTxs(1, appconsts.ContinuationCompactShareContentSize*4)

for _, tx := range txs {
css.WriteTx(tx)
Expand All @@ -157,7 +157,7 @@ func Test_parseCompactSharesErrors(t *testing.T) {
rawShares [][]byte
}

txs := testfactory.GenerateRandomTransactions(2, appconsts.ContinuationCompactShareContentSize*4)
txs := testfactory.GenerateRandomTxs(2, appconsts.ContinuationCompactShareContentSize*4)
shares := SplitTxs(txs)
rawShares := ToBytes(shares)

Expand Down
2 changes: 1 addition & 1 deletion pkg/shares/shares_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestFuzz_Merge(t *testing.T) {

// generateRandomBlockData returns randomly generated block data for testing purposes
func generateRandomBlockData(txCount, evdCount, blobCount, maxSize int) (data coretypes.Data) {
data.Txs = testfactory.GenerateRandomlySizedTransactions(txCount, maxSize)
data.Txs = testfactory.GenerateRandomlySizedTxs(txCount, maxSize)
data.Evidence = generateIdenticalEvidence(evdCount)
data.Blobs = testfactory.GenerateRandomlySizedBlobs(blobCount, maxSize)
data.SquareSize = appconsts.MaxSquareSize
Expand Down
8 changes: 4 additions & 4 deletions pkg/shares/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
)

func FuzzBlobSharesUsed(f *testing.F) {
f.Add(int(1))
f.Add(1)
f.Fuzz(func(t *testing.T, a int) {
if a < 1 {
t.Skip()
}
ml := BlobSharesUsed(int(a))
blob := testfactory.GenerateRandomBlob(int(a))
ml := BlobSharesUsed(a)
blob := testfactory.GenerateRandomBlob(a)
rawShares, err := SplitBlobs(0, nil, []types.Blob{blob}, false)
require.NoError(t, err)
require.Equal(t, len(rawShares), ml)
Expand Down Expand Up @@ -55,7 +55,7 @@ func Test_zeroPadIfNecessary(t *testing.T) {

func TestParseDelimiter(t *testing.T) {
for i := uint64(0); i < 100; i++ {
tx := testfactory.GenerateRandomTransactions(1, int(i))[0]
tx := testfactory.GenerateRandomTxs(1, int(i))[0]
input, err := MarshalDelimitedTx(tx)
if err != nil {
panic(err)
Expand Down
Empty file removed testutil/blob/testutil.go
Empty file.
2 changes: 1 addition & 1 deletion testutil/test_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func AddGenesisAccount(addr sdk.AccAddress, appState app.GenesisState, cdc codec
return appState, nil
}

// SetupWithGenesisValSet initializes GenesisState with a single validator and genesis accounts
// GenesisStateWithSingleValidator initializes GenesisState with a single validator and genesis accounts
// that also act as delegators.
func GenesisStateWithSingleValidator(t *testing.T, testApp *app.App) (app.GenesisState, *tmtypes.ValidatorSet) {
t.Helper()
Expand Down
6 changes: 3 additions & 3 deletions testutil/testfactory/txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import (
"github.com/tendermint/tendermint/types"
)

func GenerateRandomlySizedTransactions(count, maxSize int) types.Txs {
func GenerateRandomlySizedTxs(count, maxSize int) types.Txs {
txs := make(types.Txs, count)
for i := 0; i < count; i++ {
size := mrand.Intn(maxSize)
if size == 0 {
size = 1
}
txs[i] = GenerateRandomTransactions(1, size)[0]
txs[i] = GenerateRandomTxs(1, size)[0]
}
return txs
}

func GenerateRandomTransactions(count, size int) types.Txs {
func GenerateRandomTxs(count, size int) types.Txs {
txs := make(types.Txs, count)
for i := 0; i < count; i++ {
tx := make([]byte, size)
Expand Down

0 comments on commit 47ceb96

Please sign in to comment.