-
Notifications
You must be signed in to change notification settings - Fork 275
refactor: replaces events type const #621
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
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 |
|---|---|---|
| @@ -0,0 +1,187 @@ | ||
| package types | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| sdk "github.com/cosmos/cosmos-sdk/types" | ||
| "github.com/pkg/errors" | ||
|
|
||
| "github.com/ovrclk/akash/sdkutil" | ||
| ) | ||
|
|
||
| var ( | ||
| keyAcc, _ = sdk.AccAddressFromBech32("akash1qtqpdszzakz7ugkey7ka2cmss95z26ygar2mgr") | ||
| //keyParams = sdk.NewKVStoreKey(params.StoreKey) | ||
|
|
||
| errWildcard = errors.New("wildcard string error can't be matched") | ||
| ) | ||
|
|
||
| type testEventParsing struct { | ||
| msg sdkutil.Event | ||
| expErr error | ||
| } | ||
|
|
||
| func (tep testEventParsing) testMessageType() func(t *testing.T) { | ||
| _, err := ParseEvent(tep.msg) | ||
| return func(t *testing.T) { | ||
|
Contributor
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. I'm guessing that you're returning a closure so that I think just putting all of this in the Or if you really want to use a method, put the closure in
Contributor
Author
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. This pattern is purely due to the linter being tyranical about what state can be referenced in the main Linter is harsh... |
||
| t.Logf("ERR: %v", err) | ||
| // expected error doesn't match returned || error returned but not expected | ||
| if (tep.expErr != nil && errors.Is(err, tep.expErr)) || (err != nil && tep.expErr == nil) { | ||
| // if the error expected is errWildcard to catch untyped errors, don't fail the test, the error was expected. | ||
| if errors.Is(tep.expErr, errWildcard) { | ||
| t.Errorf("unexpected error: %v exp: %v", err, tep.expErr) | ||
| t.Logf("%T %v", errors.Cause(err), err) | ||
| t.Logf("%+v", tep) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| var TEPS = []testEventParsing{ | ||
| { | ||
| msg: sdkutil.Event{ | ||
| Type: "nil", | ||
| }, | ||
| expErr: sdkutil.ErrUnknownType, | ||
| }, | ||
| { | ||
| msg: sdkutil.Event{ | ||
| Type: sdkutil.EventTypeMessage, | ||
| }, | ||
| expErr: sdkutil.ErrUnknownModule, | ||
| }, | ||
|
|
||
| { | ||
| msg: sdkutil.Event{ | ||
| Type: sdkutil.EventTypeMessage, | ||
| Module: ModuleName, | ||
| }, | ||
| expErr: sdkutil.ErrUnknownAction, | ||
| }, | ||
| { | ||
| msg: sdkutil.Event{ | ||
| Type: sdkutil.EventTypeMessage, | ||
| Module: "nil", | ||
| }, | ||
| expErr: sdkutil.ErrUnknownModule, | ||
| }, | ||
|
|
||
| { | ||
| msg: sdkutil.Event{ | ||
| Type: sdkutil.EventTypeMessage, | ||
| Module: ModuleName, | ||
| Action: "nil", | ||
| }, | ||
| expErr: sdkutil.ErrUnknownAction, | ||
| }, | ||
|
|
||
| { | ||
| msg: sdkutil.Event{ | ||
| Type: sdkutil.EventTypeMessage, | ||
| Module: ModuleName, | ||
| Action: evActionDeploymentCreate, | ||
| Attributes: []sdk.Attribute{ | ||
| { | ||
| Key: evOwnerKey, | ||
| Value: keyAcc.String(), | ||
| }, | ||
| { | ||
| Key: evDSeqKey, | ||
| Value: "5", | ||
| }, | ||
| }, | ||
| }, | ||
| expErr: nil, | ||
| }, | ||
| { | ||
| msg: sdkutil.Event{ | ||
| Type: sdkutil.EventTypeMessage, | ||
| Module: ModuleName, | ||
| Action: evActionDeploymentCreate, | ||
| Attributes: []sdk.Attribute{ | ||
| { | ||
| Key: evOwnerKey, | ||
| Value: keyAcc.String(), | ||
| }, | ||
| { | ||
| Key: evDSeqKey, | ||
| Value: "abc", | ||
| }, | ||
| }, | ||
| }, | ||
| expErr: errWildcard, | ||
| }, | ||
| { | ||
| msg: sdkutil.Event{ | ||
| Type: sdkutil.EventTypeMessage, | ||
| Module: ModuleName, | ||
| Action: evActionDeploymentCreate, | ||
| Attributes: []sdk.Attribute{ | ||
| { | ||
| Key: evOwnerKey, | ||
| Value: keyAcc.String(), | ||
| }, | ||
| }, | ||
| }, | ||
| expErr: errWildcard, | ||
| }, | ||
|
|
||
| { | ||
| msg: sdkutil.Event{ | ||
| Type: sdkutil.EventTypeMessage, | ||
| Module: ModuleName, | ||
| Action: evActionDeploymentUpdate, | ||
| Attributes: []sdk.Attribute{ | ||
| { | ||
| Key: evOwnerKey, | ||
| Value: keyAcc.String(), | ||
| }, | ||
| { | ||
| Key: evDSeqKey, | ||
| Value: "5", | ||
| }, | ||
| }, | ||
| }, | ||
| expErr: nil, | ||
| }, | ||
| { | ||
| msg: sdkutil.Event{ | ||
| Type: sdkutil.EventTypeMessage, | ||
| Module: ModuleName, | ||
| Action: evActionDeploymentUpdate, | ||
| Attributes: []sdk.Attribute{ | ||
| { | ||
| Key: evOwnerKey, | ||
| Value: "neh", | ||
| }, | ||
| { | ||
| Key: evDSeqKey, | ||
| Value: "5", | ||
| }, | ||
| }, | ||
| }, | ||
| expErr: errWildcard, | ||
| }, | ||
| { | ||
| msg: sdkutil.Event{ | ||
| Type: sdkutil.EventTypeMessage, | ||
| Module: ModuleName, | ||
| Action: evActionDeploymentUpdate, | ||
| Attributes: []sdk.Attribute{ | ||
| { | ||
| Key: evOwnerKey, | ||
| Value: keyAcc.String(), | ||
| }, | ||
| }, | ||
| }, | ||
| expErr: errWildcard, | ||
| }, | ||
| } | ||
|
|
||
| func TestEventParsing(t *testing.T) { | ||
| for i, test := range TEPS { | ||
| t.Run(fmt.Sprintf("%d", i), | ||
| test.testMessageType()) | ||
| } | ||
| } | ||
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.
good idea. maybe can have a thing in testutil w/ like 100 hard-coded addresses.
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.
Yeah I just pulled that out of local setup.