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

Add UT for Transaction PreExecute() #1852

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

RodrigoVillar
Copy link
Contributor

No description provided.

@@ -252,3 +334,146 @@ func TestSignRawActionBytesTx(t *testing.T) {
require.NoError(err)
require.Equal(signedTx.Bytes(), rawSignedTxBytes)
}

func TestPreExecute(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(could be split to separate PR) - we should write unit tests for the pre executor type itself as well, since that is how PreExecute will be called from outside this package

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack

chain/transaction_test.go Show resolved Hide resolved
Comment on lines 158 to 160
func (*auth1) ValidRange(_ chain.Rules) (int64, int64) {
return 1 * consts.MillisecondsPerSecond, 1 * consts.MillisecondsPerSecond
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we set the valid range start/end as fields on auth1 and same for action3 ? This will make it easier to look at each individual test case and see immediately the start/end values rather than needing to know the start/end on the implementation above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

panic("unimplemented")
}

type mockAuth struct{}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we rename this abstractMockAuth to match the implementation of the base mockAction above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

tx: &chain.Transaction{
TransactionData: chain.TransactionData{
Base: &chain.Base{
Timestamp: 62 * consts.MillisecondsPerSecond,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we set testRules above declaring the test cases and use (testRules.ValidityWindow + 1) * consts.MillisecondsPerSecond ?

This should make the test case more clear in that it's setting the timestamp to greater than the validity window rather than the reader needing to know the default value of 60

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

chain/transaction_test.go Outdated Show resolved Hide resolved
TransactionData: chain.TransactionData{
Base: &chain.Base{},
Actions: func() []chain.Action {
actions := make([]chain.Action, 17)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use a variable for the maximum number of actions here rather than requiring the reader to know that 16 is the maximum?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@RodrigoVillar RodrigoVillar linked an issue Jan 7, 2025 that may be closed by this pull request
@RodrigoVillar RodrigoVillar marked this pull request as ready for review January 7, 2025 21:19
chain/transaction_test.go Outdated Show resolved Hide resolved
chain/transaction_test.go Outdated Show resolved Hide resolved
chain/transaction_test.go Outdated Show resolved Hide resolved
chain/transaction_test.go Outdated Show resolved Hide resolved
panic("unimplemented")
}

type auth1 struct {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(optional for this PR) - the pattern of extending an abstract type that panics for every function is a bit annoying especially when we implement a new authX type for each new test.

Could we switch to use a single mock or test action/auth type that allows tests to set arbitrary values?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to the following issue: #1860

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a single mock/auth type; kept mockTransferAction and action2 instead of solely using mockAction since these types have additional field required for codec-related tests

@RodrigoVillar RodrigoVillar linked an issue Jan 9, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Singular Mock Action/Auth Type Add UTs for transaction.PreExecute()
2 participants