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

[Tests only][aptos_framework] chain_id: initialize for test (to specify any chain_id) #4406

Merged
merged 11 commits into from
Sep 26, 2022
Merged
11 changes: 11 additions & 0 deletions aptos-move/framework/aptos-framework/sources/chain_id.move
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,15 @@ module aptos_framework::chain_id {
public fun get(): u8 acquires ChainId {
borrow_global<ChainId>(@aptos_framework).id
}

#[test_only]
Copy link
Contributor

Choose a reason for hiding this comment

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

Why would you ever need to change the chain id in move unit tests? May be you're looking for initialize_for_test so you can initialize the chain id once?

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 don't have to be able to change it, but I would like to specify.
I agree with you, "initialize_for_test" is enough. I fixed. 2560a3e
At first I thought of this flow.

genesis::setup();
chain_id::test_get();

public fun initialize_for_test(aptos_framework: &signer, id: u8) {
initialize(aptos_framework, id);
}

#[test(aptos_framework = @0x1)]
fun test_get(aptos_framework: &signer) acquires ChainId {
initialize_for_test(aptos_framework, 1u8);
assert!(get() == 1u8, 1);
}
}