Questions tagged [unittesting]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
0answers
30 views

How to fix? Tx nonce go out of sync when using multiple unit tests on the same contract under Ganache+Truffle

Here is my example contract (ignore the fact this could be pure, this is a simplified example and my real example is not a pure function, it changes state, but I can reproduce the bug with this simple ...
0
votes
1answer
36 views

Calling Smart Contract function returns tx object instead of expected return value in Truffle test

I have started writing a smart contract for a gift registry. When I write tests using the Truffle Framework I get unexpected return values. For example, when calling the offerGift function from ...
0
votes
1answer
191 views

How to access in JavaScript multiple return values returned from a solidity function

My contract function returns two values. How to access the multiple return values in JavaScript from a mocha testcase? contract X { function a() pure public returns(uint,uint) { uint p=10; ...
1
vote
1answer
40 views

Unit test compilation failed due member not found or not visible

I have written an unit test but when I launch it I get following error: Test.sol:25:22: TypeError: Member "val1" not found or not visible after argument-dependent lookup in function () view external ...
3
votes
1answer
164 views

solidity-coverage adds extra events which make unit-test fail

It seems that when using the latest solidity-coverage (0.5.11), truffle (5.0.0-next.25) ganache-cli (6.2.4-beta.1) and solc (0.5.0) additional events / logs are emitted during tests which make the ...
1
vote
1answer
156 views

Using the Truffle command line debugger

I'm writing a contract in solidity, in which a test case fails. I want to step through the code to find what's going wrong. I'm using truffle for development. This is what I do after making changes to ...
1
vote
0answers
64 views

How to write a mock method for getting ether balance using Web3j Api. I am trying to mock Web3j and callig EthGetBalance method but I am getting Null

public static BigInteger OriginalMethod(){ // connect to node Web3j web3 = Web3j.build(new HttpService()); // defaults to http://localhost:8545/ // send asynchronous requests to get balance ...
1
vote
1answer
43 views

Has Truffle's call() function stopped working as expected?

I recently upgraded ganache-cli and many of my truffle tests stopped working. In particular, there were tests where I make a contract method invocation with .call() in order to get the return value ...
0
votes
2answers
37 views

Switch between accounts to run smart contracts

I'm using truffle develop to test my smart contracts. I've tried to switch between different accounts using web3.eth.defaultAccount = web3.eth.accounts[1] but had no success. How do I accomplish that?
0
votes
1answer
208 views

Mocking msg.sender during unit test [duplicate]

I am currently trying to push my unit testing far in order to achieve a complete coverage over my code. I am using Open Zepplin's Ownable.sol contract and I cannot find in the documentation something ...
3
votes
1answer
114 views

Is there a way to test an onlyOwner function from a Truffle/Solidity unit test?

I have a contract with a function marked as onlyOwner (from OpenZeppelin, so only the address that deployed the contract can call it). pragma solidity ^0.4.17; import "./Ownable.sol"; contract ...
0
votes
1answer
115 views

Create unit tests to validate the string[] returned from a solidity function

I have a solidity function like the one below, pragma solidity ^0.4.24; pragma experimental ABIEncoderV2; contract Funding { function sum(uint input1, uint input2) public returns (uint) { ...
0
votes
2answers
105 views

How to test the following contract

I read a research paper for verification and validation of solidity code Here's a link:)! The code is given below: contract MyBank { mapping (address)uint) balances; function Deposit() { ...
2
votes
0answers
66 views

How to run a test file (.go) from ethereum source?

I have download the ethereum source from github and store the source in directory "~/EthereumSource/go-ethereum". I have install all required software to build the source and successfully build the ...
0
votes
0answers
188 views

External js file not getting load in Truffle test

I'm writing up test cases for my smart contract. Here is the folder structure: - bin - build - contracts - mytestfile.sol - modules - mymodule.js - test - mytestfile.js truffle.js I want ...
1
vote
2answers
925 views

How do you create a new contract instance with an address *and* arguments?

There is the standard way of creating contract instances with the new keyword where you pass arguments like: MyContract mine = new MyContract(arg1, arg2); Then there is another way, like in this ...
0
votes
1answer
106 views

Basic token transfer and unit test

I am having trouble testing a very naive transfer method for my coin, based off of the ethereum.org demo coin. I've simplified it down into the essentials, yet my solidity unit test keeps failing. ...
0
votes
1answer
98 views

Expect Error: transaction in Truffle [duplicate]

Im testing wheter a require function does its job by reverting and want to test in within a truffle test. it("The URI should be unique", async () =>{ const dupURI = await token....
1
vote
1answer
83 views

Double voting unit test failing on Election dApp

I am working through DApp University's election dApp tutorial. I made unit tests for invalid candidate, and double voting. My double voting unit test is failing, saying: 1) Contract: Election ...
0
votes
1answer
88 views

Why does triggering a send on a contract method work, while call doesn't?

I'm still somewhat new to web development and solidity, so do correct any of my misunderstandings. I've been working with web3 on the front end, but now I'm trying to set up a server side web3 ...
1
vote
1answer
148 views

Unable to read contract instance variable from deployed contract with truffle test

I am attempting to write some unit tests as I'm working on the development of some smart contracts, but I've run into an issue that's preventing me from continuing. I'm attempting to check the address ...
3
votes
2answers
441 views

Mock Smart Contract For Unit Testing

I'm new to Ethereum and solidity, I'm developing a simple decentralized application using Truffle where I have an abstract contract Storage and another contract Reader which uses storage. contract ...
1
vote
0answers
25 views

Is there a 'simnet mode' for Ethereum?

simnet is a feature of the Bitcoin client btcd, which allows a user to create a virtual test network where he can create blocks at ease. Is there a similar feature for Ethereum/geth? What's the ...
2
votes
0answers
415 views

Truffle test - No events were emitted + TypeError: test.titlePath is not a function

1) test_initial_badge_creation > No events were emitted 2 passing (2s) 1 failing /usr/local/lib/node_modules/truffle/node_modules/mocha/lib/reporters/base.js:178 failures.forEach(...
0
votes
1answer
161 views

Solidity unit tests for contracts with a dynamic array return type

I am writing a simple smart contract for storing an array of bytes32, pushing to it, and retrieving it: contract SimpleStorage { bytes32[] public items; event ItemAdded(bytes32 contents); ...
3
votes
1answer
324 views

Truffle Test: How to test SafeMath Library for overflow

How can I test if a function is resistant against overflow with truffle test? contract SafeMath{ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b;...
2
votes
1answer
165 views

How do I send tokens with EthereumTesterProvider?

I have a solidity contract like the following: contract MyToken { string public symbol; string public name; uint8 public decimals; uint public _totalSupply; mapping(address => ...
4
votes
3answers
290 views

Mocking blockchain for unit test quorum

Is there a way so that I can mock blockchain for unit test in quorum. I do not want to set up a test blockchain for unit testing. Is there any possibility.
2
votes
1answer
227 views

Dealing with block delays in unit tests

Consider the following Truffle Unit Test written in JavaScript: const Lease = artifacts.require("./Lease.sol"); contract("Lease", async (accounts) ...
2
votes
0answers
151 views

How to get meaningful error msg from truffle unit test?

I am writing unit tests in truffle. No matter it's solidity unit tests or js unit tests, all of the error msg I can get is: Error: VM Exception while processing transaction: revert at Object....
0
votes
1answer
825 views

msg.sender.transfer(purchaseExcess); failure in solidity test

Got an exception at the line msg.sender.transfer(purchaseExcess); in my truffle solidity unit test. Any idea the reason? my contract code: function purchase(uint256 _tokenId) public payable { ...
0
votes
2answers
68 views

Having trouble figuring out Truffle testing with Javascript

I've started unit testing my contracts with Truffle (using Javascript). I'm fairly new to Truffle and Mocha both, and while I've tried to follow the tutorials, I'm struggling to follow exactly what's ...
3
votes
1answer
1k views

Transaction gas cost in truffle test case

Below is from a truffle test cases in javascript, where I was trying to add the gas cost to an account balance to confirm the sum of transaction, where the sum should be equal to the previous balance. ...
1
vote
1answer
201 views

Truffle test case to unit test withdrawal pattern

How can I test the withdraw() function in a truffle javascript test case for the below contract? The problem is, If I use the msg.sender from the same contract, the before and after balance will be ...
1
vote
2answers
807 views

How to Compare Two Arrays in Solidity

How can I compare two arrays in Solidity (with Truffle test framework)? MyContract.sol -- pragma solidity 0.4.19; contract MyContract { uint[] public myArr; MyContract(uint[] _initArr) ...
4
votes
1answer
307 views

Truffle test fails to call the base function, wants the override

I have an extended ERC20 contract with ERC827 functions, which are overrides of ERC20 with an extra callback parameter. I have these two pairs of base/override functions: Base: function ...
2
votes
1answer
777 views

Calling event.watch() and event.get() prevents truffle JS tests to terminate

My contract is contract SimpleContract { uint storedData; event SimpleEvent(uint p); // EVENT function set(uint x) public { storedData = x; SimpleEvent(x); // TRIGGER ...
0
votes
1answer
176 views

How to verify contract field changes in a truffle test

My contract is contract SimpleContract { uint storedData; function set(uint x) public { storedData = x; } function get() public returns (uint) { return storedData; } } This test doesn't ...
1
vote
0answers
265 views

Testing smart contracts in Solidity

Testing smart contract Via another Testing Smart contract - X.sol contract X{ function reservePlace(string _name) public payable returns (bool isNotReserved) { // use _name to reserve it ...
6
votes
1answer
400 views

Reset balance in truffle test accounts after each test

I am writing unit tests for a function where I am sending tokens from one address to other in exchange of ether. I ran these tests a few times and now I am left with 0 ether in one account. I tried ...
0
votes
1answer
165 views

How do define the account addresses when running truffle test?

By default truffle uses testrpc / truffle develop which has a list of predefined addresses: Truffle Develop started at http://localhost:9545/ Accounts: (0) 0x627306090abab3a6e1400e9345bc60c78a8bef57 ...
3
votes
1answer
239 views

How to include an other contract from a different folder while unit-testing with truffle?

The folder structure is as follows: Examples | +- Multiply | +- Solidity | +- contracts | +- MultiplyContract.sol | +- UUIDProvider ...
1
vote
0answers
244 views

Invalid number of arguments to Solidity function when calling call from unit test

I have a problematic unit test in a suite. It's pretty simple: it("SapienToken deployed with SPN symbol", async function() { let SPN = await SapienToken.new(TokenController.address, Owned.address)...
0
votes
3answers
328 views

How to test a contract which needs the address of a previously deployed contract first?

I am having trouble with my JS tests for a Contract which depends on the deployment of another Contract first. Contract A needs to be deployed, then pass it's address to Contract B. I have already ...
4
votes
2answers
2k views

Unit tests written in Solidity, how to change msg.sender address, msg.value,

I would like to know if it's possible to change the address of the message sender of contract's function call when writing unit tests in solidity. It really should be, I was trying to find out how but ...
2
votes
1answer
560 views

Always getting an empty address (0x) returned from a contract

I have the following method on a contract: function addNode(address _address) constant returns (address) { nodes[_address] = Node(_address, balanceOf(_address), 0); return _address; } Here's ...
2
votes
2answers
339 views

Is there a way to unit test Solidity contracts without running ethereum node?

I don't want to run an ethereum node on my local machine, but for my project I need to tests solidity contracts. Are there any tools that allow such thing?
0
votes
1answer
87 views

Populus Unittesting: How to test a contract's fallback function?

How can I test the invocation of the fallback function by an external account of a contract using the Populus framework? For example, this runs forever: chain.wait.for_receipt(mycontract.transact({'...
3
votes
1answer
268 views

Full Integration Testing smart contracts

What is the most agile way to fully integration test smart contract code? I've seen people use shell, etc. Is there a golden standard somewhere?
3
votes
2answers
475 views

unit test with truffle, solidity or mocha?

Truffle allows either one or the other. Now I wonder which I shall use to test my code. I'm not a big fan of mocha. When I see code like contract('MetaCoin', function(accounts) { it("should put ...