-
Notifications
You must be signed in to change notification settings - Fork 320
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: version constants for msg limits #3982
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -297,7 +297,7 @@ func TestPrepareProposalCappingNumberOfMessages(t *testing.T) { | |
signers = append(signers, signer) | ||
} | ||
|
||
numberOfPFBs := appconsts.PFBTransactionCap + 500 | ||
numberOfPFBs := appconsts.PFBTransactionCap(testApp.AppVersion()) + 500 | ||
pfbTxs := make([][]byte, 0, numberOfPFBs) | ||
randomBytes := make([]byte, 2000) | ||
_, err := rand.Read(randomBytes) | ||
|
@@ -333,7 +333,7 @@ func TestPrepareProposalCappingNumberOfMessages(t *testing.T) { | |
accountIndex++ | ||
} | ||
|
||
numberOfMsgSends := appconsts.NonPFBTransactionCap + 500 | ||
numberOfMsgSends := appconsts.NonPFBTransactionCap(testApp.AppVersion()) + 500 | ||
msgSendTxs := make([][]byte, 0, numberOfMsgSends) | ||
for i := 0; i < numberOfMsgSends; i++ { | ||
msg := banktypes.NewMsgSend( | ||
|
@@ -354,18 +354,18 @@ func TestPrepareProposalCappingNumberOfMessages(t *testing.T) { | |
}{ | ||
{ | ||
name: "capping only PFB transactions", | ||
inputTransactions: pfbTxs[:appconsts.PFBTransactionCap+50], | ||
expectedTransactions: pfbTxs[:appconsts.PFBTransactionCap], | ||
inputTransactions: pfbTxs[:appconsts.PFBTransactionCap(testApp.AppVersion())+50], | ||
expectedTransactions: pfbTxs[:appconsts.PFBTransactionCap(testApp.AppVersion())], | ||
}, | ||
{ | ||
name: "capping only PFB transactions with multiple messages", | ||
inputTransactions: multiPFBsPerTxs[:appconsts.PFBTransactionCap], | ||
expectedTransactions: multiPFBsPerTxs[:appconsts.PFBTransactionCap/numberOfMsgsPerTx], | ||
inputTransactions: multiPFBsPerTxs[:appconsts.PFBTransactionCap(testApp.AppVersion())], | ||
expectedTransactions: multiPFBsPerTxs[:appconsts.PFBTransactionCap(testApp.AppVersion())/numberOfMsgsPerTx], | ||
}, | ||
{ | ||
name: "capping only msg send transactions", | ||
inputTransactions: msgSendTxs[:appconsts.NonPFBTransactionCap+50], | ||
expectedTransactions: msgSendTxs[:appconsts.NonPFBTransactionCap], | ||
inputTransactions: msgSendTxs[:appconsts.NonPFBTransactionCap(testApp.AppVersion())+50], | ||
expectedTransactions: msgSendTxs[:appconsts.NonPFBTransactionCap(testApp.AppVersion())], | ||
}, | ||
{ | ||
name: "capping msg send after pfb transactions", | ||
|
@@ -376,8 +376,8 @@ func TestPrepareProposalCappingNumberOfMessages(t *testing.T) { | |
return input | ||
}(), | ||
expectedTransactions: func() [][]byte { | ||
expected := make([][]byte, 0, appconsts.NonPFBTransactionCap+100) | ||
expected = append(expected, msgSendTxs[:appconsts.NonPFBTransactionCap]...) | ||
expected := make([][]byte, 0, appconsts.NonPFBTransactionCap(testApp.AppVersion())+100) | ||
expected = append(expected, msgSendTxs[:appconsts.NonPFBTransactionCap(testApp.AppVersion())]...) | ||
Comment on lines
+379
to
+380
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Adjust the capacity of the In lines 379 and 394, the capacity of the expected := make([][]byte, 0, appconsts.NonPFBTransactionCap(testApp.AppVersion()) + 100)
expected := make([][]byte, 0, appconsts.PFBTransactionCap(testApp.AppVersion()) + 100) Since you're appending only up to the transaction cap, the additional capacity may be unnecessary. Consider adjusting the capacity to match the exact number of expected transactions for clarity and to avoid potential misunderstandings. Also applies to: 394-396 |
||
expected = append(expected, pfbTxs[:100]...) | ||
return expected | ||
}(), | ||
|
@@ -391,9 +391,9 @@ func TestPrepareProposalCappingNumberOfMessages(t *testing.T) { | |
return input | ||
}(), | ||
expectedTransactions: func() [][]byte { | ||
expected := make([][]byte, 0, appconsts.PFBTransactionCap+100) | ||
expected := make([][]byte, 0, appconsts.PFBTransactionCap(testApp.AppVersion())+100) | ||
expected = append(expected, msgSendTxs[:100]...) | ||
expected = append(expected, pfbTxs[:appconsts.PFBTransactionCap]...) | ||
expected = append(expected, pfbTxs[:appconsts.PFBTransactionCap(testApp.AppVersion())]...) | ||
return expected | ||
}(), | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,30 @@ func TestVersionedConsts(t *testing.T) { | |
expectedConstant: v3.MaxTxSize, | ||
got: appconsts.MaxTxSize(v3.Version), | ||
}, | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesn't have to be addressed in this pr but we probably need to come up with a more efficient way of testing this before it gets out of hand with all the versions |
||
name: "NonPFBTransactionCap v2", | ||
version: v2.Version, | ||
expectedConstant: v2.NonPFBTransactionCap, | ||
got: appconsts.NonPFBTransactionCap(v2.Version), | ||
}, | ||
{ | ||
name: "NonPFBTransactionCap v3", | ||
version: v3.Version, | ||
expectedConstant: v3.NonPFBTransactionCap, | ||
got: appconsts.NonPFBTransactionCap(v3.Version), | ||
}, | ||
{ | ||
name: "PFBTransactionCap v2", | ||
version: v2.Version, | ||
expectedConstant: v2.PFBTransactionCap, | ||
got: appconsts.PFBTransactionCap(v2.Version), | ||
}, | ||
{ | ||
name: "PFBTransactionCap v3", | ||
version: v3.Version, | ||
expectedConstant: v3.PFBTransactionCap, | ||
got: appconsts.PFBTransactionCap(v3.Version), | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider caching
testApp.AppVersion()
for improved readabilityThe function
testApp.AppVersion()
is called multiple times throughout the test. To enhance readability and avoid redundant function calls, consider storing the application version in a local variable:Then, replace subsequent calls with
appVersion
.Also applies to: 336-336, 357-358, 362-363, 367-368, 379-380, 394-396