Skip to content

Commit

Permalink
dumbwallet: don't segv when handed a key for setup.
Browse files Browse the repository at this point in the history
Untested code is buggy code!

Fixes: #20
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Aug 7, 2014
1 parent b0a978a commit da9d682
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
3 changes: 1 addition & 2 deletions dumbwallet.c
Expand Up @@ -75,9 +75,8 @@ static void create_wallet(const char *privkey)
len = i2o_ECPublicKey(priv, &p);
assert(len == sizeof(pubkey));
pubkey_to_addr(&pubkey, &addr);

keystr = key_to_base58(NULL, true, priv, false);
}
keystr = key_to_base58(NULL, true, priv, false);

fd = open("dumbwallet.key", O_WRONLY|O_CREAT|O_EXCL, 0400);
if (fd < 0)
Expand Down
3 changes: 2 additions & 1 deletion test/blackbox/Makefile
Expand Up @@ -4,4 +4,5 @@ TESTS:=$(ALL:%=check-%)
check: $(TESTS)

check-%:
./$*
$(RM) -r $*-dir
ulimit -c unlimited && mkdir $*-dir && ./$* $*-dir
36 changes: 16 additions & 20 deletions test/blackbox/test-01-sync.sh
Expand Up @@ -2,51 +2,47 @@

set -em

rm -rf test-01-dir
mkdir test-01-dir test-01-dir/p1 test-01-dir/p2
mkdir $1/p1 $1/p2

NEWBLOCK=100100000800000000000000010002dcf2b3ff756f4c39c16a417e69138d79ce03488dda58e4f53cf640b3a99b91de4e8561afa441badda92600000028000000521f00001201212a5b494784a924f2e0249bf4c268af1d0e000000006d07571dee2e35e1378bc43a8e1388d2fef6b3021cc9924b885d53b2ce390ea86d07571dee2e35e1378bc43a8e1388d2fef6b3021cc9924b885d53b2ce390ea86d07571dee2e35e1378bc43a8e1388d2fef6b3021cc9924b885d53b2ce390ea86d07571dee2e35e1378bc43a8e1388d2fef6b3021cc9924b885d53b2ce390ea83e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e449ee153c4ff3b1d7a7f0901

# Unpack their blockfiles.
xzcat test-01-blockfile1.xz > test-01-dir/p1/blockfile
xzcat test-01-blockfile2.xz > test-01-dir/p2/blockfile
xzcat test-01-blockfile1.xz > $1/p1/blockfile
xzcat test-01-blockfile2.xz > $1/p2/blockfile

# Make sure they find each other.
touch test-01-dir/addresses
ln -sf ../addresses test-01-dir/p1/addresses
ln -sf ../addresses test-01-dir/p2/addresses
touch $1/addresses
ln -sf ../addresses $1/p1/addresses
ln -sf ../addresses $1/p2/addresses

# Core dumps please!
ulimit -c unlimited

../../pettycoin --seeding --developer-test --pettycoin-dir=test-01-dir/p1 > test-01-dir/p1.log 2>&1 &
../../pettycoin --seeding --developer-test --pettycoin-dir=test-01-dir/p2 > test-01-dir/p2.log 2>&1 &
../../pettycoin --seeding --developer-test --pettycoin-dir=$1/p1 > $1/p1.log 2>&1 &
../../pettycoin --seeding --developer-test --pettycoin-dir=$1/p2 > $1/p2.log 2>&1 &

# They should complete within 1 minute.
END=$(( $(date +%s) + 60 ))

# Wait for startup
while [ $(date +%s) -lt $END ]; do
if ../../pettycoin-query --pettycoin-dir=test-01-dir/p1 help >/dev/null 2>&1 && ../../pettycoin-query --pettycoin-dir=test-01-dir/p2 help >/dev/null 2>&1; then
if ../../pettycoin-query --pettycoin-dir=$1/p1 help >/dev/null 2>&1 && ../../pettycoin-query --pettycoin-dir=$1/p2 help >/dev/null 2>&1; then
break;
fi
sleep 5
done

# Give P1 new block, will trigger P2 to ask.
../../pettycoin-query --pettycoin-dir=test-01-dir/p1 submitblock $NEWBLOCK
../../pettycoin-query --pettycoin-dir=$1/p1 submitblock $NEWBLOCK

while [ $(date +%s) -lt $END ]; do
DEPTH1=`../../pettycoin-query --pettycoin-dir=test-01-dir/p1 getinfo | sed -n 's/.*"height" : \([0-9]\+\) .*num_todos.*/\1/p'`
DEPTH2=`../../pettycoin-query --pettycoin-dir=test-01-dir/p2 getinfo | sed -n 's/.*"height" : \([0-9]\+\) .*num_todos.*/\1/p'`
DEPTH1=`../../pettycoin-query --pettycoin-dir=$1/p1 getinfo | sed -n 's/.*"height" : \([0-9]\+\) .*num_todos.*/\1/p'`
DEPTH2=`../../pettycoin-query --pettycoin-dir=$1/p2 getinfo | sed -n 's/.*"height" : \([0-9]\+\) .*num_todos.*/\1/p'`
if [ "$DEPTH1" = "$DEPTH2" ]; then
../../pettycoin-query --pettycoin-dir=test-01-dir/p1 stop
../../pettycoin-query --pettycoin-dir=test-01-dir/p2 stop
../../pettycoin-query --pettycoin-dir=$1/p1 stop
../../pettycoin-query --pettycoin-dir=$1/p2 stop
exit 0
fi
sleep 5
done
echo Timeout >&2
../../pettycoin-query --pettycoin-dir=test-01-dir/p1 stop
../../pettycoin-query --pettycoin-dir=test-01-dir/p2 stop
../../pettycoin-query --pettycoin-dir=$1/p1 stop
../../pettycoin-query --pettycoin-dir=$1/p2 stop
exit 1
8 changes: 8 additions & 0 deletions test/blackbox/test-issue-20-dumbwallet-import.sh
@@ -0,0 +1,8 @@
#! /bin/sh

set -e

OUT=`../../dumbwallet --pettycoin-dir=$1 setup P-cNkMqSEm5FsNGTPcKUaUjoVA8adAm9tezdAjsAeGfxtxjhps76M8`
# Should give correct address.
echo "$OUT" | grep P-mfWxJ45yp2SFn7UciZyNpvDPSyTBhii6PH > /dev/null

0 comments on commit da9d682

Please sign in to comment.