-
Notifications
You must be signed in to change notification settings - Fork 54
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
base: main
Are you sure you want to change the base?
Conversation
@@ -88,18 +88,112 @@ func TestInsertAndDeleteEVMEvents(t *testing.T) { | |||
} | |||
} | |||
|
|||
func TestHappyPathDelivery(t *testing.T) { | |||
func TestDeliveryWithBrokenServer(t *testing.T) { |
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.
Need godocs for all tests
|
||
for _, event := range events { | ||
err := keeper.parseAndDeliver(ctx, &event) | ||
require.True(t, strings.Contains(err.Error(), sServer.err.Error())) |
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.
nit: Incorrect syntax usage of require , update all usages.
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.
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.
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. |
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.
// 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) { |
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.
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) { |
m.validators[hexAddr] = true | ||
|
||
return stypes.Validator{}, errors.New("validator does not exist") |
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.
A bit confused by this, we set the validator to true but we return an error?
More unit tests for unhappy paths.
issue: #2525