Skip to content

Commit

Permalink
Add test for instantiation failure too
Browse files Browse the repository at this point in the history
  • Loading branch information
HCastano committed Dec 7, 2022
1 parent 75cad9e commit cf2516f
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions examples/lang-err-integration-tests/contract-ref/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ mod contract_ref {
}

#[ink(constructor)]
pub fn try_new(version: u32, flipper_code_hash: Hash) -> Self {
pub fn try_new(version: u32, flipper_code_hash: Hash, succeed: bool) -> Self {
let salt = version.to_le_bytes();
let flipper = FlipperRef::try_new(true)
let flipper = FlipperRef::try_new(succeed)
.endowment(0)
.code_hash(flipper_code_hash)
.salt_bytes(salt)
Expand Down Expand Up @@ -137,7 +137,8 @@ mod contract_ref {
.expect("uploading `flipper` failed")
.code_hash;

let constructor = ContractRefRef::try_new(0, flipper_hash);
let succeed = true;
let constructor = ContractRefRef::try_new(0, flipper_hash, succeed);
let contract_acc_id = client
.instantiate("contract_ref", &ink_e2e::bob(), constructor, 0, None)
.await
Expand All @@ -157,5 +158,44 @@ mod contract_ref {

Ok(())
}

#[ink_e2e::test(additional_contracts = "../integration-flipper/Cargo.toml")]
async fn e2e_fallible_ref_fails_to_be_instantiated(
mut client: ink_e2e::Client<C, E>,
) -> E2EResult<()> {
let flipper_hash = client
.upload("integration_flipper", &ink_e2e::charlie(), None)
.await
.expect("uploading `flipper` failed")
.code_hash;

let succeed = false;
let constructor = ContractRefRef::try_new(0, flipper_hash, succeed);
let instantiate_result = client
.instantiate("contract_ref", &ink_e2e::charlie(), constructor, 0, None)
.await;
// .expect("instantiate failed")
// .account_id;

assert!(
instantiate_result.is_err(),
"Call execution should've failed, but didn't."
);

let contains_err_msg = match instantiate_result.unwrap_err() {
ink_e2e::Error::InstantiateDryRun(dry_run) => {
String::from_utf8_lossy(&dry_run.debug_message).contains(
"Received an error from the Flipper constructor while instantiating Flipper FlipperError"
)
}
_ => false,
};
assert!(
contains_err_msg,
"Call execution failed for an unexpected reason."
);

Ok(())
}
}
}

0 comments on commit cf2516f

Please sign in to comment.