Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve nix flake. Add test suite with bash tinytestlib library to en… #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ keyconv
results.txt
oclvanitygen++
vanitygen++
run_tests
run_tests
result
25 changes: 18 additions & 7 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
with import <nixpkgs> {};
# To run this on nix/nixos, just run `nix-build` in the directory containing this file
# and then run any executable in the result/bin directory,
# e.g. `./result/bin/vanitygen++ -h`
# Or, if there is a corresponding flake.nix file and you have "flakes" enabled,
# you can just run "nix run" and it will run the default executable ("vanitygen++").
# If you want to pass arguments to it or run a different executable, run it these ways:
# nix run .#oclvanitygen -- 1BTC # put the arguments to be passed to the executable after the --

{ pkgs ? import <nixpkgs> {}}:
with pkgs;
# fastStdenv.mkDerivation { # for faster running times (8-12%) BUT... nondeterministic builds :(
stdenv.mkDerivation {
name = "vanitygen++";
src = ./.;

enableParallelBuilding = true;

nativeBuildInputs = [ pkg-config ];
# any dependencies/build tools needed at compilation/build time here
nativeBuildInputs = [ pkg-config gcc opencl-clhpp ocl-icd curlpp ];

buildInputs = [ gcc pcre openssl opencl-clhpp ocl-icd curl curlpp ];
# any runtime dependencies here
buildInputs = [ pcre openssl curl ];

# the bash shell steps to build it
buildPhase = ''
make all
'';

# for a generic copy of all compiled executables:
# cp $(find * -maxdepth 1 -executable -type f) $out/bin/
# to copy specific build outputs:
# cp keyconv oclvanitygen++ oclvanityminer vanitygen++ $out/bin/
installPhase = ''
mkdir -p $out/bin
cp keyconv oclvanitygen++ oclvanityminer vanitygen++ $out/bin/
cp $(find * -maxdepth 1 -executable -type f) $out/bin/
'';
}
# to run this on nix/nixos, just run `nix-build` in the directory containing this file
# and then run any executable in the result/bin directory
# e.g. `./result/bin/vanitygen++ -h`
41 changes: 41 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# If you run with Nix and you have "flakes" enabled,
# you can just run "nix run" in this directory, and it will run the default executable here ("vanitygen++").
# Also see the note(s) at the top of default.nix.
{
inputs = {
# nixpkgs.url = github:NixOS/nixpkgs/nixos-21.11;
nixpkgs.url = "nixpkgs";
flake-utils.url = github:numtide/flake-utils;
};

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
rec {
packages.default = (import ./default.nix)
{ pkgs = nixpkgs.legacyPackages.${system}; };

apps = rec {
default = vanitygen;
vanitygen = {
type = "app";
program = "${self.packages.${system}.default}/bin/vanitygen++";
};
oclvanitygen = {
type = "app";
program = "${self.packages.${system}.default}/bin/oclvanitygen++";
};
keyconv = {
type = "app";
program = "${self.packages.${system}.default}/bin/keyconv";
};
oclvanityminer = {
type = "app";
program = "${self.packages.${system}.default}/bin/oclvanityminer";
};
};
}
);
}
33 changes: 33 additions & 0 deletions test/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

source_relative() {
PATH="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source "$1"
}

source_relative tinytestlib

_vanitygen_test() {
begin_test_suite
local current_output
declare -A outs # this associative array will hold any state changes captured by "capture", below
ASSERTION="'nix run' should run vanitygen++ by default, output help and exit 1" \
capture outs nix run # runs vanitygen++ by default and returns its help with error code 1
assert "${outs[stderr]}\n${outs[stdout]}" =~ "PLUS PLUS"
assert "${outs[retval]}" == "1"
# assert_success "nix run . -- -h" # Specifically asking for help SHOULD exit 0, but doesn't
capture outs nix run .\#vanitygen -- -q -z -a 1 1BTC
ASSERTION="When running 'vanitygen++ 1BTC', '1BTC' should be part of the generated address in the stderr output" \
assert "${outs[stderr]} ${outs[stdout]}" =~ "1BTC[[:alnum:]]{30}" # why is it outputting on stderr and not stdout? No idea.
# ASSERTION="vanitygen++ should not segfault or error if successful" \
# assert "${outs[retval]}" == "0"
capture outs nix run .\#oclvanitygen -- -q -z -a 1 1BTC
ASSERTION="When running 'oclvanitygen++ 1BTC', '1BTC' should be part of the generated address in the stderr output" \
assert "${outs[stderr]} ${outs[stdout]}" =~ "1BTC[[:alnum:]]{30}" # why is it outputting on stderr and not stdout? No idea.
# ASSERTION="oclvanitygen++ should not segfault or error if successful" \
# assert "${outs[retval]}" == "0"

# feel free to add more tests here. you can see example usage here: https://github.com/pmarreck/tinytestlib/blob/yolo/test

end_test_suite # this triggers the report output
}
_vanitygen_test
Loading