-
Notifications
You must be signed in to change notification settings - Fork 42
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
Add test to check custom AddressGenerator implementation #110
Add test to check custom AddressGenerator implementation #110
Conversation
Hi @epanchee, Since version 0.18.0, the function #[test]
fn custom_address_generator_should_work() {
struct CustomAddressGenerator;
impl AddressGenerator for CustomAddressGenerator {
// deprecated from version 0.18.0
fn next_address(&self, _storage: &mut dyn Storage) -> Addr {
Addr::unchecked("deprecated")
}
// use this function instead of next_address
fn contract_address(
&self,
_api: &dyn Api,
_storage: &mut dyn Storage,
_code_id: u64,
_instance_id: u64,
) -> AnyResult<Addr> {
Ok(Addr::unchecked("test_address"))
}
}
// prepare wasm module with custom address generator
let wasm_keeper = WasmKeeper::new().with_address_generator(CustomAddressGenerator);
let mut app = AppBuilder::default().with_wasm(wasm_keeper).build(no_init);
// store contract's code
let code_id = app.store_code(test_contracts::counter::contract());
let contract_addr = app
.instantiate_contract(
code_id,
Addr::unchecked("owner"),
&Empty {},
&[],
"Counter",
None,
)
.unwrap();
// make sure that contract address equals to "test_address" generated by custom address generator
assert_eq!(contract_addr.as_str(), "test_address");
}
|
Ahh, missed default function implementation in AddressGenerator trait. My bad, sorry! Updated test accordingly. Also as |
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!
Hi @DariuszDepta,
This PR contains failing test showing custom address generator is broken. Could you check why custom address generator no longer updated in app builder? Figured this out when was migrating from cw-multi-test:v0.16.5 to the latest version (v0.19.0).
I briefly checked via Clion debugger and it seems that this function actually does update Box pointer here. However, vtable still points to the default address generator implementation. No clue why