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

Testing sent founds visibility in multi-test #363

Merged
merged 1 commit into from
Jul 29, 2021

Conversation

hashedone
Copy link
Contributor

closes #347

@hashedone hashedone requested review from ethanfrey and maurolacy July 29, 2021 11:01
@hashedone hashedone marked this pull request as draft July 29, 2021 11:01
@hashedone hashedone changed the title WIP: Testing sent founds visibility in multi-test Testing sent founds visibility in multi-test Jul 29, 2021
Copy link
Member

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

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

Nice start with code reorg.
Maybe you finish this (if more there) and merge this in just as a reorg.

And do the sent funds tests as a new PR

PayoutCountResponse, PayoutInitMessage, PayoutQueryMsg, PayoutSudoMsg, ReflectMessage,
ReflectQueryMsg,
};
use crate::test_helpers::contracts::{payout, reflect};
Copy link
Member

Choose a reason for hiding this comment

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

Nice reorg

@@ -0,0 +1,94 @@
use schemars::JsonSchema;
Copy link
Member

Choose a reason for hiding this comment

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

nice idea pulling these into another file

SetName { name: String },
SetAge { age: u32 },
}

fn instantiate_error(
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason you left error top level and didn't pull it into a separate file like payout and reflect?

I know it is smaller, but was there another reason?
(I like your reorg)

Copy link
Contributor Author

@hashedone hashedone Jul 29, 2021

Choose a reason for hiding this comment

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

I decided that those functions are just not part of specific contracts, they are generic to be used in other contracts which doesn't implement centrain functionality. I actually used query_error this way in my new contract (not yet here). One thing I am not sure is a COUNTitem - I left it here, but I debate if it belongs to payout contract.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Forget it - I just missed there is whole contract for errors. I am blind.

@@ -492,9 +489,9 @@ mod test {
assert_eq!(funds, coins(5, "eth"));

// reflect count updated
let qres: PayoutCountResponse = app
let qres: payout::CountResponse = app
Copy link
Member

Choose a reason for hiding this comment

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

All of these type names get better

Copy link
Contributor Author

@hashedone hashedone Jul 29, 2021

Choose a reason for hiding this comment

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

My hint: if you have 3+ names in your file/module with exactly the same prefix, you want to have a submodule ;) Extrapolation of famous Djiskstra words: "Two or more - use a for".

@hashedone
Copy link
Contributor Author

I agree with merging those refactor in separate PR, but I prefer this one to be the feature one (better name, better tracking), so I just created separate one with those changes only: #365

@hashedone hashedone marked this pull request as ready for review July 29, 2021 14:34
@hashedone hashedone force-pushed the 347-test-sent-founds-visibility branch from fba9f32 to 02f4aad Compare July 29, 2021 14:35
@hashedone hashedone force-pushed the 347-test-sent-founds-visibility branch from 02f4aad to 0b2c4ba Compare July 29, 2021 15:37
@ethanfrey
Copy link
Member

Please ping me on discord when ready for the final review

Copy link
Member

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

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

Good stuff

_info: MessageInfo,
_msg: EmptyMsg,
) -> Result<Response, StdError> {
let init = HACKATOM.load(deps.storage)?;
Copy link
Member

Choose a reason for hiding this comment

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

Nice and simple. Anyone can pay out.
Does the job for the test and no other frills.
I like it.

Ok(resp)
}

fn query(_deps: Deps, _env: Env, msg: EmptyMsg) -> Result<Binary, StdError> {
Copy link
Member

Choose a reason for hiding this comment

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

I would just return an error here if you don't support any queries.

I would actually add a query to return the beneficiary / InitMsg

to_binary(&msg)
}

pub fn contract() -> Box<dyn Contract<Empty>> {
Copy link
Member

Choose a reason for hiding this comment

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

👍


// Check balance of all accounts to ensure no tokens where burned or created, and they are
// in correct places
assert_eq!(get_balance(&app, &owner), &[]);
Copy link
Member

Choose a reason for hiding this comment

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

Awesome work.

I would usually add such asserts at the state between instantiate and execute, but you are correct, those are totally not needed for such a BDD test like this. If these failed for some reason, I would add some intermediary checks, otherwise it is just noise.

Looks good to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just try to find a balance between checking everything, and deciding what is relevant to case. Basically it is nice when you can understand the test just looking at it quickly. It would be ideal to test everything (like even to check if some side state didn't change - which there is no reason to happen, but for sake of completeness), but I found this checks should actually cover test case.

@ethanfrey ethanfrey merged commit 65b4cd9 into main Jul 29, 2021
@ethanfrey ethanfrey deleted the 347-test-sent-founds-visibility branch July 29, 2021 18:24
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.

multitest: Ensure Warm sent funds visible to querier
2 participants