Questions tagged [assert]

An assertion is a statement, which aborts a program when it evaluates to false. Assert is typically used for debugging and situations which should never happen.

Filter by
Sorted by
Tagged with
0 votes
1 answer
79 views

assertEq is showing error when written in the test file foundry

I am writing the test by following the lesson 7 tutorial and got this error, even I imported Test from forge-std Undeclared identifier. Did you mean "assert"? this is the actual error // ...
Sardar Ahmed Khan's user avatar
0 votes
1 answer
22 views

How to assert that a BigNumber is included in a list of numbers?

I am trying to assert a uint256 the following way: expect(tokenType).to.be.oneOf([1, 2, 3, 4]); I just want to check that its value is any of the ones on that list, as I am using a ...
Falcon Stakepool's user avatar
2 votes
2 answers
262 views

How does the EVM internally revert the contract to the initial state when exceptions are present?

In error handling, assert and require statements revert the state of the contract to the initial state and then the transaction passes or fails depending on the code. I'm trying to understand how this ...
GimmeGinNtonic's user avatar
0 votes
0 answers
349 views

to.be.reverted function showing invalid chai property

it("money",async()=>{ console.log(await instance.hasRole("0xc5d48d6799b0d7d7cdfebe6afd6fac6dff6746359d2e02d434f8172e9a93fe97",accounts[8])); console.log(await ...
Yakshesh Gupta's user avatar
1 vote
0 answers
38 views

Send ETH on echidna test

How do I make msg.value something (aka send some ETH) on the beginning of an Echidna test? For example, if I have this function: function test() external payable { if (msg.value > 0) { ...
dNyrM's user avatar
  • 675
2 votes
1 answer
130 views

assert function

Can anyone please explain me the meaning of this line "assert(balanceReceived[msg.sender] + msg.value >= balanceReceived[msg.sender]);" in the below code in the function receiveMoney and ...
Abhishek Bhagat's user avatar
1 vote
1 answer
126 views

Testing address(this) generates exception, how to obtain the correct value for address(this)

I have modified the following code from a michalzalecki website https://michalzalecki.com/ethereum-test-driven-introduction-to-solidity/ to test address(this): pragma solidity 0.5.16; import "...
zak100's user avatar
  • 1,406
0 votes
1 answer
927 views

Fail with error 'TransferHelper: TRANSFER_FROM_FAILED', all gas used up

I'm trying to buy some CHY with USDT on Uniswap main net, fails with error 'TransferHelper: TRANSFER_FROM_FAILED', This is my failed tx link. This is a successful tx link from someone else. I notice ...
aj3423's user avatar
  • 251
0 votes
2 answers
179 views

Truffle script: how to run multiple assertions without stopping the program?

I am trying to run multiple assertion using a single script. My script stops after the first assertion: My output is: t$ truffle exec ts4_for_forum.js Using network 'development'. acc2 balance ...
zak100's user avatar
  • 1,406
0 votes
1 answer
155 views

address payable[] public causing SWC 110 and execption state

This is the output of mythril ==== Exception State ==== SWC ID: 110 Severity: Medium Contract: XXXXXXX Function name: recipients(uint256) PC address: 2067 Estimated Gas Usage: 1089 - 1184 An assertion ...
hack3r-0m's user avatar
  • 1,861
0 votes
1 answer
558 views

I want to understand something with BigNumber assertions

I have create a truffle project with a smartcontract and a test file. Here is an extract of the test file: expect(ret).to.be.bignumber.equal(new BN('42')); ret is a value returned by a smartcontract'...
Bob5421's user avatar
  • 1,433
0 votes
1 answer
551 views

Truffle console: assert.equal, how to use exception for testing purposes?

I want to check the value returned by getName() function: pragma solidity >= 0.5.0 < 0.7.0; contract SimpleContract { string public name; constructor() public { name = 'abs'; } ...
zak100's user avatar
  • 1,406
0 votes
0 answers
73 views

Are assertions removed in release build?

Are assert() removed in release build? Please show an authoritative document documenting that they are removed or no removed.
porton's user avatar
  • 1,714
4 votes
2 answers
2k views

Read message of require / revert statement in app.js

In my App.js I have called the smart contract function and the require statement in the function is not satisfied, so how do I get the message of that require statement in my App.js?
Shivam Raina's user avatar
2 votes
1 answer
1k views

How to handle require/revert/assert errors properly

I'm trying to find an easy pattern to revert/rollback a write transaction. The first idea was to log a GenericErrorEvent but then I noticed that it will never be emited if any require/revert/assert ...
earizon's user avatar
  • 596
3 votes
1 answer
166 views

Access require message

I am using JavaScript to run some tests on my solidity contract. Since solidity ^0.4.22 you can have a message in require such as: function Hello { require(msg.sender == 0x001234, "msg.sender ...
Iulian's user avatar
  • 638
1 vote
1 answer
602 views

How to use require() with stings

I am trying to run this code on remix IDE: pragma solidity ^0.4.24; contract Aa { string public result; function feedData(string _result) public { require(_result = "e" , "...
YulePale's user avatar
  • 1,783
3 votes
1 answer
57 views

Contract design by contract -> correctness and maximum gas consumption

This question is a general design question that regards contract correctness and the functions I list here are just examples. As I develop on Ethereum, it becomes aparent to me that it might be ...
matthias_buehlmann's user avatar
1 vote
1 answer
892 views

Better ways to test bytes32 type using truffle testing framework

small quick question, when I store a bytes32 and retrieve it from truffle console, why is it showing in 64 bits? Ex: 0x74657374737472696e6700000000000000000000000000000000000000000000 because this ...
bbusdriver's user avatar
  • 1,084
6 votes
2 answers
1k views

Why not use require() in place of assert()?

Even though require() is used substantially more than assert(), there are places where assert() gets used. One example would be in the widely adopted SafeMath library by OpenZeppelin: function add(...
Zhen Hong's user avatar
  • 118
1 vote
2 answers
1k views

Handling require/assert failure errors correctly from a Node.JS app?

I have a getter function in my smart contract that returns one of the string values in statically defined string array. Upon entry to the function, it does a bounds check on the incoming index using ...
Robert Oschler's user avatar
3 votes
1 answer
315 views

Call a zero-initialized variable of internal function type

I was reading solidity documentation about when an assert-style exception is generated. In the 6th point it says: "If you call a zero-initialized variable of internal function type." I don't ...
NachoPal's user avatar
  • 167
0 votes
1 answer
203 views

Issue with Assert statement in solidity

I am probably missing something very obvious but I cannot get the simplest assert statement to work! What am I doing wrong? My goal is to simply confirm that I am within a start date and end date ...
wardsback's user avatar
  • 399
0 votes
1 answer
1k views

Remix Warning : Assert

I am trying to compile a contract on remix and have run into the following warning : Use assert(x) if you never ever want x to be false, not in any circumstance (apart from a bug in your code). ...
0xsegfault's user avatar
  • 1,230
4 votes
4 answers
974 views

Why using assert, since it would consume all gas

Since assert would consume all gas and require would return all gas, is there any reason to use assert not require? Using require to refund gas seems always a better choice than consuming them? I saw ...
Ilake Chang's user avatar
0 votes
1 answer
146 views

'Assert' and 'require' atomicity while internally calling another contract

contract one{ unint number; function saveNumber(unint _number){ number = _number; } } contract two{ function callOtherFunctionAndAlsoTransferFunds(){ oneContract = one('contractaddress'); ...
vignesh's user avatar
  • 123
0 votes
1 answer
310 views

Control structure with truffle (assert and require)

When I'm trying to deploy contracts that contain assert and require using truffle I receive Error: Undeclared identifier. e.g: pragma solidity ^0.4.8; contract Owned{ address public owner = ...
shultz's user avatar
  • 1,091
104 votes
5 answers
43k views

Difference between require and assert and the difference between revert and throw

I was looking at the docs and I'm looking for clarification on the difference between require and assert and throw and revert. assert(bool condition): abort execution and revert state changes if ...
Daniel Kobe's user avatar
  • 1,581