Skip to content

Commit

Permalink
Refactored tests and introducing python
Browse files Browse the repository at this point in the history
  • Loading branch information
xcthulhu committed Mar 5, 2015
1 parent 0115606 commit f3b07a4
Show file tree
Hide file tree
Showing 17 changed files with 140 additions and 26 deletions.
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
.DS_Store
*/**/*un~
.vagrant/
cpp-build/
go-build/
*.pyc
build/
pyethash.egg-info/
*.so
*~
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
before_install:
# Make sure we use the latest cmake
- sudo apt-get update -qq
- sudo apt-get install -qq wget cmake gcc bash libboost-test-dev nodejs
- sudo apt-get install -qq wget cmake gcc bash libboost-test-dev nodejs python-pip
# Make sure we use the latest cmake
- (cd /tmp && wget http://www.cmake.org/files/v3.1/cmake-3.1.3.tar.gz && tar zxf cmake-3.1.3.tar.gz)
- (cd /tmp/cmake-3.1.3 && cmake . && make && sudo make install) > /dev/null 2>&1

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ endif()
add_subdirectory(libethash)
add_subdirectory(libethash-cl EXCLUDE_FROM_ALL)
add_subdirectory(benchmark EXCLUDE_FROM_ALL)
add_subdirectory(test EXCLUDE_FROM_ALL)
add_subdirectory(test/c EXCLUDE_FROM_ALL)
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
clean:
rm -rf *.so pyethash.egg-info/ build/ test/python/python-virtual-env/ test/c/build/ pythethash/core.so
2 changes: 2 additions & 0 deletions pyethash/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pyethash.egg-info/
*.so
Empty file added pyethash/__init__.py
Empty file.
34 changes: 34 additions & 0 deletions python-src/core.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <Python.h>
#include "../libethash/ethash.h"

static PyObject*
get_params(PyObject* self, PyObject* args)
{
unsigned long block_number;
ethash_params p;

if (!PyArg_ParseTuple(args, "k", &block_number))
Py_RETURN_NONE;

ethash_params_init(&p, block_number);

printf("\nBlock number: %lu\n", block_number);
printf("DAG Size: %lu\n", p.full_size);
printf("Cache Size: %lu\n", p.cache_size);

return Py_BuildValue("{sisi}",
"DAG Size", p.full_size,
"Cache Size", p.cache_size);
}

static PyMethodDef CoreMethods[] =
{
{"get_params", get_params, METH_VARARGS, "Gets the parameters for a given block"},
{NULL, NULL, 0, NULL}
};

PyMODINIT_FUNC
initcore(void)
{
(void) Py_InitModule("core", CoreMethods);
}
8 changes: 8 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[nosetests]
verbosity=1
detailed-errors=1
with-coverage=1
cover-package=nose
debug=nose.loader
pdb=1
pdb-failures=1
16 changes: 16 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python
from distutils.core import setup, Extension

pyethash_core = Extension('pyethash.core',
sources = [
'python-src/core.c',
'libethash/util.c',
'libethash/internal.c',
'libethash/sha3.c'
])

setup (name = 'pyethash',
version = '1.0',
description = 'Python wrappers for ethash, the ethereum proof of work hashing function',
ext_modules = [pyethash_core],
)
2 changes: 1 addition & 1 deletion test/CMakeLists.txt → test/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ENDIF()

IF( Boost_FOUND )
include_directories( ${Boost_INCLUDE_DIR} )
include_directories(..)
include_directories(../..)

link_directories ( ${Boost_LIBRARY_DIRS} )
file(GLOB HEADERS "*.h")
Expand Down
File renamed without changes.
19 changes: 19 additions & 0 deletions test/c/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# Strict mode
set -e

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
TEST_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

rm -rf $TEST_DIR/build
mkdir -p $TEST_DIR/build
cd $TEST_DIR/build ;
cmake ../../.. > /dev/null
make Test
./test/c/Test
1 change: 1 addition & 0 deletions test/python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-virtual-env/
2 changes: 2 additions & 0 deletions test/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pyethereum==0.7.522
nose==1.3.4
20 changes: 20 additions & 0 deletions test/python/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash -x

# Strict mode
set -e

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
TEST_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

# rm -rf $TEST_DIR/python-virtual-env
# virtualenv --system-site-packages $TEST_DIR/python-virtual-env > /dev/null
source $TEST_DIR/python-virtual-env/bin/activate
# pip install -r $TEST_DIR/requirements.txt > /dev/null
pip install -e $TEST_DIR/../..
cd $TEST_DIR
nosetests --with-doctest -v
9 changes: 9 additions & 0 deletions test/python/test_pyethash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pyethash.core

def test_get_params():
block_num = 123456
out = pyethash.core.get_params(block_num)
assert out != None

if __name__ == '__main__':
test_me()
38 changes: 18 additions & 20 deletions test/test.sh
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
#!/bin/bash -x
#!/bin/bash

SOURCE="${BASH_SOURCE[0]}"
# Strict mode
set -e

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done

TEST_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

echo "################# Testing CPP ##################"

( rm -rf $TEST_DIR/../cpp-build ;
mkdir -p $TEST_DIR/../cpp-build ;
cd $TEST_DIR/../cpp-build ;
cmake .. ;
make Test ;
test/Test )
echo -e "\n################# Testing JS ##################"
# TODO: Use mocha and real testing tools instead of rolling our own
cd $TEST_DIR/../libethash-js
node test.js

echo "################# Testing JS ##################"
echo -e "\n################# Testing Python ##################"
$TEST_DIR/python/test.sh

( cd $TEST_DIR/../libethash-js ;
./test.js )
echo -e "\n################# Testing C ##################"
$TEST_DIR/c/test.sh

#echo "################# Testing Go ##################"
#( rm -rf $TEST_DIR/../go-build ;
# export GOPATH=$TEST_DIR/../go-build ;
# export PATH=$PATH:$GOPATH/bin ;
# cd $TEST_DIR/go ;
# go get -dv ;
# go get -v github.com/ethereum/ethash ;
#( rm -rf $TEST_DIR/../go-build
# export GOPATH=$TEST_DIR/../go-build
# export PATH=$PATH:$GOPATH/bin
# cd $TEST_DIR/go
# go get -dv
# go get -v github.com/ethereum/ethash
# go test )

0 comments on commit f3b07a4

Please sign in to comment.