-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Table-Driven Bank Module Unit Tests #1764
Conversation
81c86df
to
49b7a4a
Compare
x/bank/app_test.go
Outdated
privKeys: []crypto.PrivKey{priv1}, | ||
}, | ||
{ | ||
addr: addr1, |
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.
Any particular reason you have a switch case to check the expected state transition, instead of having a different field in the appTestCase
struct for expected outcome? Putting it in the appTestCase
struct seems more optimal to me.
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.
You mean why do I leverage the mock#*
calls? No particular reason. This was the original code and figured I'd leave it this way to leverage existing functionality. I can take a look at those function calls and put the require
statements directly in here if that's what you'd prefer?
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.
No, I mean that the struct has a "simBlock" flag. When that is true, it runs a block, when its false, it tests that the expected action happened.
I think it would be easier if we had a list of expected address / coin amounts after running the tx, and we put those directly in the struct. this would mean adding a new struct type:
expectedAddressCoinAmount {Address, Coins}
(better name probably exists)
and then adding to the appTestCase
struct, an []expectedAddressCoinAmount
and removing simBlock
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.
I see, yeah we can do that for sure 👍
Can we do this without mock ? |
Codecov Report
@@ Coverage Diff @@
## develop #1764 +/- ##
==========================================
Coverage ? 62.77%
==========================================
Files ? 122
Lines ? 7125
Branches ? 0
==========================================
Hits ? 4473
Misses ? 2390
Partials ? 262 |
Yeah, I'll see if we can do this without |
c6d187f
to
a323a68
Compare
a323a68
to
63ccb2c
Compare
@ValarDragon updated to address your concern. @ebuchman I can remove the dependency on Thoughts on moving those helpers to |
I think the |
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.
LGTM, thanks for doing this!
One minor comment re order of expected balance
privKeys: []crypto.PrivKey{priv1, priv4}, | ||
expectedBalances: []expectedBalance{ | ||
expectedBalance{addr1, sdk.Coins{sdk.NewCoin("foocoin", 32)}}, | ||
expectedBalance{addr4, sdk.Coins{sdk.NewCoin("foocoin", 32)}}, |
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.
minor nitpick, can the addresses be sorted? i.e. addr1, addr2, addr3 then 4
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.
Sure! I had them originally as they were implemented, but I can certainly order them by address.
mock.CheckBalance(t, mapp, addr2, sdk.Coins{sdk.NewCoin("foocoin", 52)}) | ||
mock.CheckBalance(t, mapp, addr3, sdk.Coins{sdk.NewCoin("foocoin", 10)}) | ||
for _, eb := range tc.expectedBalances { | ||
mock.CheckBalance(t, mapp, eb.addr, eb.coins) |
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.
This should be left for a seperate PR, but perhaps mock.CheckBalance should take in a message parameter, so that we can have error messages as described in https://github.com/cosmos/cosmos-sdk/blob/develop/CONTRIBUTING.md#testing
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.
Definitely worthy for another PR :-)
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.
utACK, agreed on removing mock, needs to be discussed.
Changes
x/bank
app unit tests to be (mostly) table-drivencloses: #1546
docs/
)CHANGELOG.md
cmd/gaia
andexamples/
For Admin Use: