dapphub / ds-test Goto Github PK
View Code? Open in Web Editor NEWAssertions, equality checks and other test helpers
License: GNU General Public License v3.0
Assertions, equality checks and other test helpers
License: GNU General Public License v3.0
Could we add equality assertions that allow for very tiny deviations (due to rounding of different order of fixed math lib operations in expected test values vs source code values) which would be specified in the assert function signature?
For example something like this:
function assertEqWithDeviation(
uint256 a,
uint256 b,
uint256 allowedDeviation
) internal {
if (a != b) {
if (a > b) {
if (a - b > allowedDeviation) {
fail();
}
}
if (a < b) {
if (b-a > allowedDeviation) {
fail();
}
}
}
}
It would be a massive improvement for compatibility with NPM if ds-test had a package.json file. This would make it possible to import ds-test as a GitHub dependency without npm install
breaking. This would not require actually publishing ds-test to NPM or dealing with the NPM ecosystem beyond just including the one file. forge-std recently made this addition, for what it's worth.
See here for the package.json that forge-std added for reference: https://github.com/foundry-rs/forge-std/blob/master/package.json
Currently, there are no releases or changelog for DS-Test which when pulling in the latest version of DS-Test can break repos especially when using main-tracked submodules with forge/foundry.
This is a suggestion to add a CHANGELOG.md file and create releases for breaking changes that allow users to install versioned release tags for future-proofing repos.
Am I doing something wrong?
e.g.
My.sol
:
contract My {
function myFunc(address[] addrs) returns (uint) {
return 0;
}
}
My.t.sol
:
import "ds-test/test.sol";
import "./My.sol";
contract MyTest is DSTest {
My contractInstance;
function setUp() {
contractInstance = new My();
}
function testFunc() {
address[] addrs;
addrs.push(this);
contractInstance.myFunc(addrs); // hangs here
}
}
$ solc --version
solc, the solidity compiler commandline interface
Version: 0.4.17+commit.bdeb9e52.Linux.g++
$ dapp --version
dapp 0.5.6
Running this file it fails on the linked line, when uncommented.
Output like this:
+ dapp quicktest out out/simpleAdapter.bin out/rewards.bin out/safeMath.bin
Secp256k1 bindings are not compiled. Pure JS implementation will be used.
Trying out/DataFeedTest, out/assets/AssetTest, out/datafeeds/DataFeedTest, out/participation/ParticipationTest, out/version/VersionTest...
....thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Invalid character '_' at position 47616', /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore
/result.rs:868
note: Run with `RUST_BACKTRACE=1` for a backtrace.
undefined:1
SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at handleTestOutput (/home/travis/prg/dapp/libexec/dapp/dapp-quicktest:172:23)
at Socket.child.stdout.on (/home/travis/prg/dapp/libexec/dapp/dapp-quicktest:163:32)
at emitNone (events.js:110:20)
at Socket.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1059:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
thread 'main' panicked at 'failed printing to stdout: Broken pipe (os error 32)', /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/io/stdio.rs:693
note: Run with `RUST_BACKTRACE=1` for a backtrace.
thread 'main' panicked at 'failed printing to stdout: Broken pipe (os error 32)', /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/io/stdio.rs:693
note: Run with `RUST_BACKTRACE=1` for a backtrace.
thread 'main' panicked at 'failed printing to stdout: Broken pipe (os error 32)', /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/io/stdio.rs:693
note: Run with `RUST_BACKTRACE=1` for a backtrace.
thread 'main' panicked at 'failed printing to stdout: Broken pipe (os error 32)', /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/io/stdio.rs:693
note: Run with `RUST_BACKTRACE=1` for a backtrace.
thread 'main' panicked at 'failed printing to stdout: Broken pipe (os error 32)', /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/io/stdio.rs:693
note: Run with `RUST_BACKTRACE=1` for a backtrace.
Not sure what this stack trace means exactly, but the Err value: Invalid character '_' at position 47616'
makes me wonder whether it's due to some unlinked library (__libnameEtc__
still in the bytecode).
Just a guess though.
This looks like a stale modifier. What can it be used for?
Line 44 in 9310e87
This is for new solc
compiler (after updating with nix-channel).
solc
version
solc --version
solc, the solidity compiler commandline interface
Version: 0.4.21+commit.dfe3193c.Linux.g++
A bunch of warnings when building
~/ds-test$ make
dapp build
+ dapp clean
+ rm -rf out
+ solc --overwrite --abi --bin --bin-runtime = -o out/ src/test.sol
src/test.sol:44:9: Warning: Invoking events without "emit" prefix is deprecated.
eventListener(target, true);
^-------------------------^
src/test.sol:51:9: Warning: Invoking events without "emit" prefix is deprecated.
log_named_uint("gas", startGas - endGas);
^--------------------------------------^
src/test.sol:56:13: Warning: Invoking events without "emit" prefix is deprecated.
log_bytes32("Assertion failed");
^-----------------------------^
src/test.sol:63:13: Warning: Invoking events without "emit" prefix is deprecated.
log_bytes32("Error: Wrong `address' value");
^-----------------------------------------^
src/test.sol:64:13: Warning: Invoking events without "emit" prefix is deprecated.
log_named_address(" Expected", b);
^--------------------------------^
src/test.sol:65:13: Warning: Invoking events without "emit" prefix is deprecated.
log_named_address(" Actual", a);
....
When writing tests and experimenting, sometimes it is beneficial to let fail()
quit as soon as the first test fails. This helps debugging and avoid a lot of logs on screen.
Something like this
function fail() internal {
revert();
}
Marking this function virtual
allows us to update this function as necessary.
EtherToken.sol contract
Asset.t.sol tests
When I run dapp test -v
I get this crash error in the output:
+ dapp quicktest -v out out/simpleAdapter.bin out/rewards.bin out/safeMath.bin
Secp256k1 bindings are not compiled. Pure JS implementation will be used.
Trying out/assets/AssetTest...
.F.
[CRASH] testWithdraw
-> <out/assets/AssetTest#ee35>.testWithdraw() => BadInstruction
<out/assets/AssetTest#ee35> -> <out/assets/EtherToken#db93>.balanceOf(<out/assets/AssetTest#ee35>) => (1e+28)
<out/assets/AssetTest#ee35> -> <out/assets/EtherToken#db93>.withdraw(0.5 ether) => BadInstruction
2 tests passed, 1 failed
Took 0.200s
When I remove the assert on L45 here I don't get this crash.
Could it be something to do with overshadowing solidity's native assert
function?
Hi! Cloning this repo fails on Windows because one of the directories is called aux
. aux
is a reserved file name and one can't create a file or dir with this name under any circumstances.
Git yields an invalid path
error and the clone fails.
I know that this is very stupid and should really be considered a bug in Windows. Having said this, to the best of my understanding, this makes it all but impossible to even save a full copy of the DAI source code on Windows, which may not be ideal from an inclusiveness standpoint.
That's why I suggest to rename the aux
directory to something else, as ridiculous as it may be.
As far as I'm aware, there are only two workarounds for Windows users:
Note in particular that setting core.protectNTFS=false
in git does not help.
Issue described in detail here.
Many of use would like to use Foundry + Hardhat, which still has tons of use cases (integration testing, complex deployment scripts, etc) and should really not be treated as a direct competitor. However, there are some small inconveniences that we have found when trying to do this.
As shown in the issue, it can almost be tidied up into one source of truth for all dependencies by mapping the paths the Forge uses to node_modules
. But since ds-test
and forge-std
do not have NPM modules, you still need to maintain a ./lib
directory and remappings.txt
.
The simplest fix would probably be to wrap these dependencies in NPM modules. This probably has use-cases outside just the one described above, but would help immensely for all the Hardhat folks that want to give Foundry a go.
forge-std will do this but they need help with ds-test NPM package: foundry-rs/forge-std#39 (comment)
Thanks! ๐
Just spent some time trying to figure out why the asserts in my test weren't getting triggered. "Crashes" have precedence over "assertion failures" in dapp
, so all I was seeing was a "crash" from later in my code, rather than the "crash" was expecting from the assert
s. It looked like assert(false)
was failing to throw, which was driving me a little crazy for a second there.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.