inkdevhub / drink

De-chained Ready-to-play ink! playground
Apache License 2.0
69 stars 15 forks source link

bug: `ContractTrapped` error throw when edowment is provided #126

Closed chungquantin closed 1 month ago

chungquantin commented 1 month ago

How to reproduce?

In one of the examples (I tried with flipper), replace None in the deploy_bundle with Some(1_000) (any number that makes sense, less than INIT_BALANCE), the test will throw ContractTrapped on execution.

 #[drink::test]
    fn initialization(mut session: Session) -> Result<(), Box<dyn Error>> {
        let contract = BundleProvider::local()?;
        let init_value: bool = session
-   .deploy_bundle_and(contract, "new", &["true"], NO_SALT, None)?
+   .deploy_bundle_and(contract, "new", &["true"], NO_SALT, Some(1_000))?
            .call_and("get", NO_ARGS, None)?
            .record()
            .last_call_return_decoded()?
            .expect("Call was successful");

        assert_eq!(init_value, true);

        Ok(())
    }

This feels strange to me because the provided endowment was much less than the INIT_BALANCE of the default actor, so it must work. Below is the error thrown:

running 2 tests
test tests::initialization ... FAILED
test tests::flipping ... ok

failures:

---- tests::initialization stdout ----
Error: DeploymentFailed(Module(ModuleError { index: 3, error: [12, 0, 0, 0], message: Some("ContractTrapped") }))
pmikolajczyk41 commented 1 month ago

I would say that this is because the constructor is not payable, can you check if adding this attribute fixes the problem?

chungquantin commented 1 month ago

@pmikolajczyk41 It solves my issue. Thank you!