Looks like function overrides are not supported by test framework
See original GitHub issue- I’ve asked for help in the Truffle Gitter before filing this issue.
Issue
If a contract has an override function, unit tests for that function break.
Steps to Reproduce
Simplest example I could create to reproduce the issue
Contract:
pragma solidity ^0.4.18;
contract BaseExample {
function approve(address _spender, uint _value) public returns (bool) {
return true;
}
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
return true;
}
}
contract OverrideExample is BaseExample {
function approve(address _spender, uint _value, bytes _data) public returns (bool) {
return true;
}
function increaseApproval(address _spender, uint _addedValue, bytes _data) public returns (bool) {
return true;
}
}
Unit test:
const OverrideExample = artifacts.require("OverrideExample");
contract("OverrideExample", (accounts) => {
let instance;
before(async () => {
instance = await OverrideExample.deployed();
})
it("Test lowercase method - base", async () => {
await instance.approve(0x0, 1);
});
it("Test lowercase method - override", async () => {
await instance.approve(0x0, 1, 0x0); // BREAKS
});
it("Test camelCase method - base", async () => {
await instance.increaseApproval(0x0, 1); // BREAKS
});
it("Test camelCase method - override", async () => {
await instance.increaseApproval(0x0, 1, 0x0);
});
})
Run truffle migrate
and then truffle test
.
Expected Behavior
No errors, all tests pass
Actual Results
When I run truffle migrate
and then truffle test
, I get the following error:
1) Contract: OverrideExample Test lowercase method - override:
Error: Invalid number of arguments to Solidity function
at Object.InvalidNumberOfSolidityArgs (/Users/leyboan1/.local/share/npm/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/errors.js:25:1)
at SolidityFunction.validateArgs (/Users/leyboan1/.local/share/npm/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/function.js:74:1)
at SolidityFunction.toPayload (/Users/leyboan1/.local/share/npm/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/function.js:90:1)
at SolidityFunction.sendTransaction (/Users/leyboan1/.local/share/npm/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/function.js:163:1)
at SolidityFunction.execute (/Users/leyboan1/.local/share/npm/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/function.js:256:1)
at /Users/leyboan1/.local/share/npm/lib/node_modules/truffle/build/webpack:/~/truffle-contract/contract.js:202:1
at /Users/leyboan1/.local/share/npm/lib/node_modules/truffle/build/webpack:/~/truffle-contract/contract.js:155:1
at process._tickCallback (internal/process/next_tick.js:109:7)
2) Contract: OverrideExample Test camelCase method - base:
Error: Invalid number of arguments to Solidity function
at Object.InvalidNumberOfSolidityArgs (/Users/leyboan1/.local/share/npm/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/errors.js:25:1)
at SolidityFunction.validateArgs (/Users/leyboan1/.local/share/npm/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/function.js:74:1)
at SolidityFunction.toPayload (/Users/leyboan1/.local/share/npm/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/function.js:90:1)
at SolidityFunction.sendTransaction (/Users/leyboan1/.local/share/npm/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/function.js:163:1)
at SolidityFunction.execute (/Users/leyboan1/.local/share/npm/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/function.js:256:1)
at /Users/leyboan1/.local/share/npm/lib/node_modules/truffle/build/webpack:/~/truffle-contract/contract.js:202:1
at /Users/leyboan1/.local/share/npm/lib/node_modules/truffle/build/webpack:/~/truffle-contract/contract.js:155:1
at process._tickCallback (internal/process/next_tick.js:109:7)
Environment
- Operating System: Mac OSX
- Ethereum client: Ganache
- Truffle version (
truffle version
): 4.0.7 - node version (
node --version
): 7.7.3 - npm version (
npm --version
): 4.0.3
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
java - How to override a method in unit tests that is called ...
When I am testing func1 in its unit tests, I don't want func2 to get called. So I am trying to do something...
Read more >Override component test actions
Change the testing properties of a particular page component using -specific HTML attributes.
Read more >Testing Your Application
Writing a Profile. All these methods have default implementations so just override the ones you need to override. Now we have defined our...
Read more >unittest — Unit testing framework
Unittest supports skipping individual test methods and even whole classes of tests. In addition, it supports marking a test as an “expected failure,”...
Read more >Testing
True unit tests typically run extremely quickly, as there is no runtime ... the Spring Framework provides mock objects and testing support ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is the only thing that worked for me:
Ok, I’ll keep an eye. You can close it as a duplicate. Thank you!