truffle-assertions | Assertions and utilities for testing Ethereum smart | Cryptocurrency library
kandi X-RAY | truffle-assertions Summary
kandi X-RAY | truffle-assertions Summary
Assertions and utilities for testing Ethereum smart contracts with Truffle unit tests
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of truffle-assertions
truffle-assertions Key Features
truffle-assertions Examples and Code Snippets
Community Discussions
Trending Discussions on truffle-assertions
QUESTION
I am new to Solidity, and I am trying to create my first smart contract following the ERC-20 token standard. As the standard requires, I have a transfer
function which looks like following:
ANSWER
Answered 2021-May-24 at 13:46Solidity introduced automatic exception on integer overflow/underflow in version 0.8.0.
Arithmetic operations revert on underflow and overflow. You can use
unchecked { ... }
to use the previous wrapping behaviour.
Source: docs
If you're using Solidity ^0.8, it's still going to throw on balanceOf[msg.sender] -= _value;
(assuming value
is larger than balanceOf[msg.sender]
), because otherwise the balanceOf[msg.sender]
value would underflow.
You'll see this exact check using the require statement in many sources because they were either created before the version 0.8, or their authors might have not been aware of this new feature. Or they maybe wanted to pass a custom error message using the second argument of require(false, 'error message')
(the auto exception doesn't give any message). But since 0.8, it's not needed anymore.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install truffle-assertions
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page