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

Mock Refactor #4851

Closed
wants to merge 4 commits into from
Closed

Mock Refactor #4851

wants to merge 4 commits into from

Conversation

colin-axner
Copy link
Contributor

@colin-axner colin-axner commented Aug 5, 2019

fixes #1555

The aim here is to have mock module return an application with fields for each exported keeper interface, which can be swapped/set by the receiving module for integration testing. The account, param, and supply keeper will be mock'd in mock to provide the base functionality for initializing this application, but should be swapped for fully implemented versions by the receiving application if they are going to be used more extensively.

There is no need to fully mock all the modules since the receiving module will only be using the modules it will already be importing. For example, assume the receiving module uses account, supply, bank, and staking keeper. It will already be importing auth, bank, supply, and staking and so it can simply initialize those keepers and set them in the returned mock app which will have fields for each keeper. A swap function will be added so developers can swap the partially mock'd account/supply/param keepers for their directly imported ones.

The mock module will follow the module spec structure for consistency and readability.

Types/Keepers that are mock'd will have a Mock prefix so developers can easily tell when testing if the type being used comes from the mock module.

This module will not import any x/ packages except for exported

  • Targeted PR against correct branch (see CONTRIBUTING.md)

  • Linked to github-issue with discussion and accepted design OR link to spec that describes this work.

  • Wrote tests

  • Updated relevant documentation (docs/)

  • Added a relevant changelog entry: clog add [section] [-t <tag>] [-m <msg>]

  • Re-reviewed Files changed in the github PR explorer


For Admin Use:

  • Added appropriate labels to PR (ex. wip, ready-for-review, docs)
  • Reviewers Assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@colin-axner colin-axner added the WIP label Aug 5, 2019
// ModuleAccount defines an account for modules that holds coins on a pool
type ModuleAccount struct {
*MockBaseAccount
name string `json:"name" yaml:"name"` // name of the module
Copy link
Contributor

Choose a reason for hiding this comment

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

structtag: struct field name has json tag but is not exported (from govet)

type ModuleAccount struct {
*MockBaseAccount
name string `json:"name" yaml:"name"` // name of the module
permissions []string `json:"permissions" yaml"permissions"` // permissions of module account
Copy link
Contributor

Choose a reason for hiding this comment

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

structtag: struct field tag json:"permissions" yaml"permissions" not compatible with reflect.StructTag.Get: bad syntax for struct tag pair (from govet)

x/mock/types/codec.go Show resolved Hide resolved
)

type Subspace struct {
cdc *codec.Codec
Copy link
Contributor

Choose a reason for hiding this comment

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

U1000: field cdc is unused (from unused)


type Subspace struct {
cdc *codec.Codec
key sdk.StoreKey // []byte -> []byte, stores parameter
Copy link
Contributor

Choose a reason for hiding this comment

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

U1000: field key is unused (from unused)

type Subspace struct {
cdc *codec.Codec
key sdk.StoreKey // []byte -> []byte, stores parameter
tkey sdk.StoreKey // []byte -> bool, stores parameter change
Copy link
Contributor

Choose a reason for hiding this comment

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

U1000: field tkey is unused (from unused)

key sdk.StoreKey // []byte -> []byte, stores parameter
tkey sdk.StoreKey // []byte -> bool, stores parameter change

name []byte
Copy link
Contributor

Choose a reason for hiding this comment

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

U1000: field name is unused (from unused)


name []byte

table KeyTable
Copy link
Contributor

Choose a reason for hiding this comment

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

U1000: field table is unused (from unused)

table KeyTable
}

type attribute struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

U1000: type attribute is unused (from unused)

}

type KeyTable struct {
m map[string]attribute
Copy link
Contributor

Choose a reason for hiding this comment

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

U1000: field m is unused (from unused)

@colin-axner
Copy link
Contributor Author

closing see #4875

@colin-axner colin-axner closed this Aug 8, 2019
@alexanderbez alexanderbez deleted the colin/1555-mock-refactor branch February 25, 2020 19:27
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.

x: can we improve testing by reducing dependence on mock ?
2 participants