From 1863c5fe379c5b8c9645b86c84822047f11186d1 Mon Sep 17 00:00:00 2001 From: John Newby Date: Thu, 1 Aug 2019 15:58:21 +0200 Subject: [PATCH] Tidied up a little --- Makefile | 1 + README.md | 12 ++++++++++++ src/test.c | 5 +++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 3b01bad..f048b8f 100644 --- a/Makefile +++ b/Makefile @@ -10,3 +10,4 @@ LDPATH = -Ltarget/debug test: src/test.c include/ecrecover.h target/debug/libecrecover.so $(CC) -o $@ $^ $(CFLAGS) $(LDPATH) + ./test diff --git a/README.md b/README.md index 5efd689..7259f0b 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,14 @@ # ecrecover FFI export of Ethereum's ecrecover + +prerequisite: +- a checked out copy of parity-ethereum (https://github.com/paritytech/parity-ethereum) checked out in the same directory this is + +to compile: +`cargo build` + +to test: +`make` (requires gcc) +./test + +(if you don't see `Test passed` then something went wrong). \ No newline at end of file diff --git a/src/test.c b/src/test.c index 47e8d45..c2f5e24 100644 --- a/src/test.c +++ b/src/test.c @@ -2,22 +2,23 @@ #include #include #include +#include #include "../include/ecrecover.h" - char *bin2hex(unsigned char*, int); - unsigned char *hex2bin(const char*); #define OUTPUT_LENGTH 32 int main(int arc, char **argv) { + // copied from Ethereum tests unsigned char *input = hex2bin("47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad000000000000000000000000000000000000000000000000000000000000001b650acf9d3f5f0a2c799776a1254355d5f4061762a237396a99a0e0e3fc2bcd6729514a0dacb2e623ac4abd157cb18163ff942280db4d5caad66ddf941ba12e03"); unsigned char *expected = "000000000000000000000000c08b5542d177ac6686946920409741463a15dddb"; unsigned char *output = malloc(OUTPUT_LENGTH * sizeof(unsigned char)); ecrecover(input, output); assert(strcmp(bin2hex(output, OUTPUT_LENGTH), expected) == 0); + printf("Test passed\n"); }