1

I'm tweaking with ink! Smart contracts and deployed some test contracts through https://polkadot.js.org/. However, despite setting conditional statements within smart contracts, calls to them still pass without reverting. Am I doing something wrong with the error handling?

Example code:

  #[ink(message)]
    pub fn withdraw_(&mut self, value: Balance) -> Result<()>  {
        let caller= self.env().caller();
        let contract_address = self.env().account_id();
        let ticket_count = self.tickets_of_or_zero(caller);

    

        if ticket_count <= 0 {
            return  Err(Error::InsufficientTickets)
        }

        self.tickets.insert(caller, ticket_count - 1);

      let transfer_status =  self.transfer_from_to_reentrant(contract_address,caller,value);

      if !transfer_status {
          return Err(Error::UnsucceededTransfer)
      }

        

        Ok(())
    }
  • Did you query the chain state after calling an erroneous contract method? I had a similar "issue" a few days back, where I called a failing method but got a report (in Canvas UI) that the method succeeded. When queried via polkadot.js apps, he chain state did not change though! – tifrel Oct 22 '21 at 20:33
  • @tifrel Yes, it did not change. However, it would've been so much better if it reverted with the "Error" specified in the code. Easier to test. Seems like they are working on it. You can check issues on the main repo. – Timur Guvenkaya Oct 24 '21 at 12:31
  • I totally agree with you. IIRC the contracts return something. If you parse it, you may just see an `Err(Error::YaddaYadda)`, or something like `{error: 4}`, where 4 is the position of the variant of you Error enum in rust/ink. Should you need proper error-handling before it's implemented by Parity, that might do the job for you :) – tifrel Oct 25 '21 at 13:30

0 Answers0