Skip to content

SOLOMAN-1/ETH_errorHandling

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

Odd Sum Validator Contract

Description

This Solidity contract, named Error, provides functionalities to validate whether the sum of the digits of a given number is odd. It includes three main functions: testRequirewithsum, testRevert, and testAssert, alongside an internal utility function _sumOfDigits to calculate the sum of digits of a number. This contract is intended for educational and demonstration purposes to illustrate different error handling techniques in Solidity.

Contract Version

  • SPDX-License-Identifier: GPL-3.0
  • pragma solidity >=0.7.0 <0.9.0;

Functions

testRequirewithsum

  • Arguments: uint _num - The number to validate.
  • Returns: string - Confirmation message if the sum of _num's digits is odd.
  • Description: Uses require to check if the sum of digits of _num is odd, reverts the transaction with a message if not.

testRevert

  • Arguments: uint _num - The number to validate.
  • Returns: string - Confirmation message if the sum of _num's digits is odd.
  • Description: Explicitly checks if the sum of digits is odd and uses revert to undo the transaction if the condition is not met.

testAssert

  • Returns: string - Confirmation message that the sum of digits of the contract's Number state variable is odd.
  • Description: Asserts that the sum of digits of Number is odd. It is intended to check invariants and internal errors.

_sumOfDigits

  • Arguments: uint _num - The number to process.
  • Returns: uint - The sum of the digits of _num.
  • Visibility: internal
  • Description: A utility function that calculates the sum of digits of a given number.

Usage

This contract can be used to demonstrate the handling of error conditions in Solidity using require, revert, and assert. It is also an example of how to implement a basic utility function in Solidity for calculating the sum of digits of a number.

State Variables

  • Number: A public uint that holds a number for which the sum of its digits is validated in the testAssert function.

Deployment

To deploy this contract, use a Solidity-compatible development environment like Remix, Truffle, or Hardhat. Ensure that your development environment is set to compile Solidity versions between 0.7.0 and 0.9.0.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors