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

feat(halo/evmstaking2) unit tests for unhappy paths #2591

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

Conversation

chmllr
Copy link
Contributor

@chmllr chmllr commented Nov 29, 2024

More unit tests for unhappy paths.

issue: #2525

@@ -88,18 +88,112 @@ func TestInsertAndDeleteEVMEvents(t *testing.T) {
}
}

func TestHappyPathDelivery(t *testing.T) {
func TestDeliveryWithBrokenServer(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Need godocs for all tests

@chmllr chmllr changed the title feat(halo/evmstaking2) more unit tests for unhappy paths feat(halo/evmstaking2) unit tests for unhappy paths Nov 29, 2024
@chmllr chmllr marked this pull request as ready for review November 29, 2024 13:37

for _, event := range events {
err := keeper.parseAndDeliver(ctx, &event)
require.True(t, strings.Contains(err.Error(), sServer.err.Error()))
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Incorrect syntax usage of require , update all usages.

Suggested change
require.True(t, strings.Contains(err.Error(), sServer.err.Error()))
require.Error(t, err)
require.Contains(t, err.Error(),"create validator: pubkey to cosmos")

Using require.Error and require.Contains is preferred as it provides clearer intent, better failure messages, and avoids potential panics if err is nil. It also aligns with idiomatic testing practices for improved readability and debugging.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice! Thanks!

func (m *stakingKeeperStub) GetValidator(context.Context, sdk.ValAddress) (stypes.Validator, error) {
m.calls++
if m.calls == 1 {
// GetValidator memorizes all addresses and returns an error for calls it never seen before.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// GetValidator memorizes all addresses and returns an error for calls it never seen before.
// GetValidator tracks accessed addresses, returning an error for unseen addresses.

m.calls++
if m.calls == 1 {
// GetValidator memorizes all addresses and returns an error for calls it never seen before.
func (m *stakingKeeperStub) GetValidator(ctx context.Context, addr sdk.ValAddress) (stypes.Validator, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func (m *stakingKeeperStub) GetValidator(ctx context.Context, addr sdk.ValAddress) (stypes.Validator, error) {
func (m *stakingKeeperStub) GetValidator(_ context.Context, addr sdk.ValAddress) (stypes.Validator, error) {

Comment on lines +313 to 315
m.validators[hexAddr] = true

return stypes.Validator{}, errors.New("validator does not exist")
Copy link
Contributor

Choose a reason for hiding this comment

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

A bit confused by this, we set the validator to true but we return an error?

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.

2 participants