Bitcore port
This commit is contained in:
59
src/test/script_P2PKH_tests.cpp
Normal file
59
src/test/script_P2PKH_tests.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
// Copyright (c) 2012-2015 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "script/script.h"
|
||||
#include "test/test_bitcoin.h"
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(script_P2PKH_tests, BasicTestingSetup)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(IsPayToPublicKeyHash)
|
||||
{
|
||||
// Test CScript::IsPayToPublicKeyHash()
|
||||
uint160 dummy;
|
||||
CScript p2pkh;
|
||||
p2pkh << OP_DUP << OP_HASH160 << ToByteVector(dummy) << OP_EQUALVERIFY << OP_CHECKSIG;
|
||||
BOOST_CHECK(p2pkh.IsPayToPublicKeyHash());
|
||||
|
||||
static const unsigned char direct[] = {
|
||||
OP_DUP, OP_HASH160, 20, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, OP_EQUALVERIFY, OP_CHECKSIG
|
||||
};
|
||||
BOOST_CHECK(CScript(direct, direct+sizeof(direct)).IsPayToPublicKeyHash());
|
||||
|
||||
static const unsigned char notp2pkh1[] = {
|
||||
OP_DUP, OP_HASH160, 20, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, OP_EQUALVERIFY, OP_CHECKSIG, OP_CHECKSIG
|
||||
};
|
||||
BOOST_CHECK(!CScript(notp2pkh1, notp2pkh1+sizeof(notp2pkh1)).IsPayToPublicKeyHash());
|
||||
|
||||
static const unsigned char p2sh[] = {
|
||||
OP_HASH160, 20, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, OP_EQUAL
|
||||
};
|
||||
BOOST_CHECK(!CScript(p2sh, p2sh+sizeof(p2sh)).IsPayToPublicKeyHash());
|
||||
|
||||
static const unsigned char extra[] = {
|
||||
OP_DUP, OP_HASH160, 20, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, OP_EQUALVERIFY, OP_CHECKSIG, OP_CHECKSIG
|
||||
};
|
||||
BOOST_CHECK(!CScript(extra, extra+sizeof(extra)).IsPayToPublicKeyHash());
|
||||
|
||||
static const unsigned char missing[] = {
|
||||
OP_HASH160, 20, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, OP_EQUALVERIFY, OP_CHECKSIG, OP_RETURN
|
||||
};
|
||||
BOOST_CHECK(!CScript(missing, missing+sizeof(missing)).IsPayToPublicKeyHash());
|
||||
|
||||
static const unsigned char missing2[] = {
|
||||
OP_DUP, OP_HASH160, 20, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||
};
|
||||
BOOST_CHECK(!CScript(missing2, missing2+sizeof(missing)).IsPayToPublicKeyHash());
|
||||
|
||||
static const unsigned char tooshort[] = {
|
||||
OP_DUP, OP_HASH160, 2, 0,0, OP_EQUALVERIFY, OP_CHECKSIG
|
||||
};
|
||||
BOOST_CHECK(!CScript(tooshort, tooshort+sizeof(direct)).IsPayToPublicKeyHash());
|
||||
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "key.h"
|
||||
#include "main.h"
|
||||
#include "random.h"
|
||||
#include "chainparamsbase.h"
|
||||
#include "txdb.h"
|
||||
#include "ui_interface.h"
|
||||
#include "util.h"
|
||||
|
||||
61
src/test/wallet-utility.py
Normal file
61
src/test/wallet-utility.py
Normal file
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/python
|
||||
# Copyright 2014 BitPay, Inc.
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
import subprocess
|
||||
import os
|
||||
import json
|
||||
import sys
|
||||
import buildenv
|
||||
import shutil
|
||||
|
||||
def assert_equal(thing1, thing2):
|
||||
if thing1 != thing2:
|
||||
raise AssertionError("%s != %s"%(str(thing1),str(thing2)))
|
||||
|
||||
if __name__ == '__main__':
|
||||
datadir = os.environ["srcdir"] + "/test/data"
|
||||
execprog = './wallet-utility' + buildenv.exeext
|
||||
execargs = '-datadir=' + datadir
|
||||
execrun = execprog + ' ' + execargs
|
||||
|
||||
proc = subprocess.Popen(execrun, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True)
|
||||
try:
|
||||
outs = proc.communicate()
|
||||
except OSError:
|
||||
print("OSError, Failed to execute " + execprog)
|
||||
sys.exit(1)
|
||||
|
||||
output = json.loads(outs[0])
|
||||
|
||||
assert_equal(output[0], "13EngsxkRi7SJPPqCyJsKf34U8FoX9E9Av")
|
||||
assert_equal(output[1], "1FKCLGTpPeYBUqfNxktck8k5nqxB8sjim8")
|
||||
assert_equal(output[2], "13cdtE9tnNeXCZJ8KQ5WELgEmLSBLnr48F")
|
||||
|
||||
execargs = '-datadir=' + datadir + ' -dumppass'
|
||||
execrun = execprog + ' ' + execargs
|
||||
|
||||
proc = subprocess.Popen(execrun, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True)
|
||||
try:
|
||||
outs = proc.communicate()
|
||||
except OSError:
|
||||
print("OSError, Failed to execute " + execprog)
|
||||
sys.exit(1)
|
||||
|
||||
output = json.loads(outs[0])
|
||||
|
||||
assert_equal(output[0]['addr'], "13EngsxkRi7SJPPqCyJsKf34U8FoX9E9Av")
|
||||
assert_equal(output[0]['pkey'], "5Jz5BWE2WQxp1hGqDZeisQFV1mRFR2AVBAgiXCbNcZyXNjD9aUd")
|
||||
assert_equal(output[1]['addr'], "1FKCLGTpPeYBUqfNxktck8k5nqxB8sjim8")
|
||||
assert_equal(output[1]['pkey'], "5HsX2b3v2GjngYQ5ZM4mLp2b2apw6aMNVaPELV1YmpiYR1S4jzc")
|
||||
assert_equal(output[2]['addr'], "13cdtE9tnNeXCZJ8KQ5WELgEmLSBLnr48F")
|
||||
assert_equal(output[2]['pkey'], "5KCWAs1wX2ESiL4PfDR8XYVSSETHFd2jaRGxt1QdanBFTit4XcH")
|
||||
|
||||
if os.path.exists(datadir + '/database'):
|
||||
if os.path.isdir(datadir + '/database'):
|
||||
shutil.rmtree(datadir + '/database')
|
||||
|
||||
if os.path.exists(datadir + '/db.log'):
|
||||
os.remove(datadir + '/db.log')
|
||||
sys.exit(0)
|
||||
Reference in New Issue
Block a user