Commit graph

59 commits

Author SHA1 Message Date
Andreas Schildbach
47660f6418 build.gradle: migrate from protobuf-java to protobuf-javalite
This commit contains rather hard to review diffs to the protobuf test datasets in .txt format.
To aid the review, this Python script can be used to convert the data from the old to the new
format:

```
import sys

file = open(sys.argv[1])
outfile = open(sys.argv[1] + ".lite", "w")
line = file.readline()
lines = []

def sortAndPrint(group, removeLastLB=False, removeFirstLB=False):
    group.sort()
    if removeFirstLB and group[0] == "\n":
        group.remove("\n")
    for i in range(len(group)):
        if i == len(group) - 1 and removeLastLB:
            group[i] = group[i].rstrip()
        print(group[i], end="", file=outfile)

def sign32neg(value):
    if 0x80000000 <= value <= 0xFFFFFFFF:
        value &= 0x7FFFFFFF
        value = int(value)
        value = ~value
        value ^= 0x7FFFFFFF
    return value

def processPath(path):
    parts = path.rstrip().split(":")
    number = int(parts[1].lstrip())
    if number >= 0x80000000:
        number = sign32neg(number)
    return parts[0] + ": " + str(number) + "\n"

groupcount = 0
while len(line) > 0:
    if line.startswith("type:"):
        if len(lines):
            sortAndPrint(lines, removeFirstLB=groupcount==0)
            groupcount += 1
        lines.clear()
        lines.append(line)
    elif line.find("deterministic_key {") != -1:
        structure = line
        innerlines = []
        line = file.readline()
        while not line.startswith('}'):
            if line.find("path") != -1:  # preserve order of paths
                pathlines = processPath(line)
                line = file.readline()
                if line.startswith('}'):
                    innerlines.append(pathlines)
                    continue
                while line.find("path") != -1:
                    pathlines += processPath(line)
                    line = file.readline()
                innerlines.append(pathlines)
                if line.startswith('}'):
                    continue
            if line.startswith("  sigsRequiredToSpend"):
                line = line.replace("sigsRequiredToSpend", "sigs_required_to_spend")
            innerlines.append(line)
            line = file.readline()
        innerlines.sort()
        for l in innerlines:
            structure += l
        structure += line.rstrip() + "\n"
        lines.append(structure)
    elif line.find("path") != -1:  # preserve order of paths
        accountpathlines = processPath(line)
        line = file.readline()
        while line.find("path") != -1:
            accountpathlines += processPath(line)
            line = file.readline()
        lines.append(accountpathlines)
        lines.append(line)
    else:
        lines.append(line)
    line = file.readline()
print(file=outfile)
sortAndPrint(lines, removeLastLB=True)
file.close()
outfile.close()
```
2021-09-25 11:00:42 +02:00
Andreas Schildbach
f1ff9a05ca Script: Cut short script execution in correctlySpends() for the standard P2PK case. 2021-03-16 17:23:05 +01:00
Andreas Schildbach
df7035c0bf Script: Cut short script execution in correctlySpends() for the standard P2PKH case. 2021-03-16 17:23:05 +01:00
Matthew Leon
73ddffb38f Script: Ensure that non-canonical sigs result in script failure. 2019-04-17 16:17:02 +02:00
Andreas Schildbach
bfe2a195b6 Receive to and send from native segwit addresses
- Hierarchical-deterministic derivation of native segwit addresses.
- Receive payments to native segwit addresses.
- Spend and sign payments from native segwit addresses.
- Watch-only wallets with native segwit addresses (zpub/vpub).
- WalletAppKit, Wallet-tool and Wallet-template are taught to deal with segwit-enabled wallets.

Be aware this adds a new field in the wallet protobuf: output_script_type in Key, which keeps track
of the script type of DeterministicKeyChains. Protobufs will be migrated; old DeterministicKeyChains
are assumed to be of type P2PKH.

Includes some code by Fabrice Drouin.
2019-02-11 16:48:37 +01:00
BigAdam2005
49ea1de34b LegacyAddressTest: Extend test dataset and move it to a classpath resource. 2018-07-27 14:19:17 +02:00
Andreas Schildbach
b08cfe3f54 Remove TestNet2. 2018-04-18 16:40:51 +02:00
Andreas Schildbach
648655da99 Transaction can serialize and deserialize according to Segwit (BIP144). This adds TransactionWitnesses to the wallet protobuf, too.
The goal of this commit is to fix loading blk*.dat files by BlockFileLoader. Bitcoinj cannot yet
create segwit transactions nor does it correctly process them.

Based on code by:
  NicolasDorier <nicolas.dorier@gmail.com>
  Oscar Guindzberg <oscar.guindzberg@gmail.com>
  sstone <sstone@users.noreply.github.com>
2018-04-15 10:31:57 +02:00
Andreas Schildbach
b976205716 ScriptPattern: Add pattern matcher for segwit commitment (in an output of the coinbase transaction).
Adds a test for parsing block 481815, which contains a segwit commitment in its coinbase.
2018-03-21 15:04:03 +01:00
Andreas Schildbach
8ee5e48171 Update to protobuf-java 3.5.1.
In the test data for DeterministicKeyChainTest all occurences of the (often invisible) 0x7f
character is replaced by its numerical literal "\177". This change is needed because a bug of
previous versions was fixed, which caused this character not being printed as text.
2018-03-13 21:55:47 +01:00
HashEngineering
d92dfdfd14 Add ability to import an account key that allows for a wallet to spend from it.
Previous functionality only allowed watching.
Contributor: Nelson MELINA <nelson.melina@mycelium.com>
2018-03-03 12:57:58 +01:00
Andreas Schildbach
f25840309b Rename the org.bitcoinj.core.CheckpointManagerTest test package to lowercase. 2018-02-28 10:02:31 +01:00
HashEngineering
d3dca96a3c Allow watched keys to have account paths of an arbitrary length. 2018-02-07 11:32:43 +01:00
HashEngineering
be382c6800 Remove unnecessary accountPath parameter on watch key methods while preserving that the watched key account path can be arbitrary (does not have to be 0H). 2018-02-07 11:26:13 +01:00
Andreas Schildbach
b6360e0858 CheckpointManagerTest: Fix name of test data directory. 2018-01-02 16:45:39 +01:00
Philip Whitehouse
e9469b3a72 Add test for CheckpointManager. 2018-01-01 13:52:02 +01:00
Nelson MELINA
e036f8174a Allow to create wallets with an arbitrary account path. Adds a test for BIP44 wallets (account zero only).
Authors: Nelson MELINA <nelson.melina@mycelium.com>, Giuseppe Magnotta <giuseppe.magnotta@gmail.com>
2017-11-27 22:22:25 +01:00
Andreas Schildbach
89fb8c3bfa script_tests.json: Two fixes synched from Bitcoin Core. 2017-07-18 19:21:57 +02:00
Nicola Atzei
d8af6b4be7 ScriptError: New error code for use in ScriptException. Script tests use this to assert for specific errors.
This also adds MINIMALDATA tests from Bitcoin Core into script_tests.json.
2017-07-11 18:01:28 +02:00
Nicola Atzei
bb176dab4d Implement the CHECKSEQUENCEVERIFY script operator.
This also adds CSV-related tests from Bitcoin Core into script_tests.json, tx_valid.json and tx_invalid.json.
2017-07-05 18:45:33 +02:00
Andreas Schildbach
e3409e5d6d Merge script_valid.json and script_invalid.json into one script_tests.json.
This also synchs script_tests.json to Bitcoin Core's version as of dde46d3ae1de18700e089bc1861cf1e18649dc5d, minus some of the newer 'invalid' tests which we can't handle yet.

We also need to check 'invalid' tests more specificly for the expected error; the current behaviour mimics how dataDrivenInvalidScripts() used to work.

The buildCreditingTransaction() and buildSpendingTransaction() methods were written by Nicola Atzei.
2017-07-05 14:33:03 +02:00
Andreas Schildbach
428702b50d Don't print log to console if tests are run by Maven.
It got too large for Travis. If you need the log, you can run the failing test locally, e.g. in your IDE.
2016-01-25 23:19:42 +01:00
Ross Nicoll
92bd6d0af1 Add transaction tests for OP_CHECKLOCKTIMEVERIFY 2015-11-23 17:23:43 +01:00
Andreas Schildbach
63a5e3b410 Block: Add convenience methods for BIP conformance (BIP34, BIP66, BIP65, BIP101). Also list BIPs in Block.toString(). 2015-11-23 16:54:43 +01:00
Ross Nicoll
723df867ff Genericise script number encoder
This replaces the limited script number encoder previously used for block
height with a version that matches the exact format generated by Bitcoin
Core (which can include an additional byte for sign in some cases).

With thanks to Kalpesh Parmar for pointing out that some blocks on the
testnet have coinbase transactions with height encoded in 2 bytes.
2015-11-20 18:58:10 +00:00
Ross Nicoll
377d226ef1 Enforce the LOW_S script validation flag 2015-10-31 16:10:48 +01:00
Ross Nicoll
829e147ec7 Add script verification flags for DER format
Add script verification flags for DER format encoding, low-S signatures
and strict encoding.
Pass script verification flags through to signature parser.
Convert block verification flags to a sub-enum of Block.
Remove DER signature format verification flag from block flags.
Add test transaction with a non-standard DER signature, with the verify
flag set/unset accordingly, to tx_invalid.json and tx_valid.json
2015-10-20 13:37:27 +02:00
dexX7
be41d84fb9
Add more script edge condition tests
Original submission:
```
commit 1c54757f8678c9131ec55c128b8f1d5b6c73c2f9
Author: Dave Collins <davec@conformal.com>
Date:   Wed May 6 10:16:18 2015 -0500

    Add more script edge condition tests.

    This commit adds some tests to the script_valid.json and tx_invalid.json
    data which exercise more edge conditions that are not currently being
    tested.
```

Via:
https://github.com/bitcoin/bitcoin/pull/6112
2015-09-30 00:34:08 +02:00
Devrandom
22f0600afe Refactor married keychains
* move handling of following keychains into the leading keychain
* move multisig threshold into the leading keychain
* extract MarriedKeyChain from DeterministicKeyChain
2014-10-07 15:39:04 +02:00
Mike Hearn
0a6f901b23 Renamespace to org.bitcoinj away from com.google.bitcoin, as bitcoinj is no longer a Google project and being namespaced under com.google causes issues with Sonatype/Maven Central.
To fixinate your code:

find . -name '*.java' | xargs sed -i .bak 's/import com.google.bitcoin./import org.bitcoinj./g;s/import static com.google.bitcoin./import static org.bitcoinj./g'
2014-09-30 17:05:07 +02:00
Devrandom
03bacf4fa9 Cache deterministic seed 2014-09-22 15:00:18 +02:00
Andreas Schildbach
57bec6165b Parse verifyFlags from script and tx JSON tests. In addition to P2SH (previously known as enforceP2SH), NULLDUMMY is implemented.
Update all script and tx JSON tests from Bitcoin Core.
2014-09-13 23:28:57 +02:00
Andreas Schildbach
2b80e4cfd1 Update script JSON tests from upstream. 2014-09-08 13:07:03 +02:00
Mike Hearn
e8ba287029 HD wallets: experimental change to not trigger full lookahead when deriving keys. This allows a savvy app to get keys/addresses at startup fast, if they do so before starting up the peergroup (which wants all keys in the zone so it can calculate a Bloom filter). May be reverted if it causes trouble. 2014-08-11 17:53:33 +02:00
Mike Hearn
bab16650f9 HD Wallets: fix key lookahead and auto-advance so it works as intended.
Previously the codepath that was supposed to mark keys as used didn't work, and the lookahead calculation wasn't quite right. Now the current key advances correctly when an inbound tx is found that spends to it, including pending transactions. Additionally the lookahead zone now has the threshold zone after it, not inside it, meaning that if you request a lookahead size of 100 keys you'll actually always have at least 100 keys, never less.
2014-07-15 13:41:45 +02:00
Devrandom
fec6cbc7df Remove support for mnemonic-less keychains 2014-07-10 14:53:42 +02:00
Mike Hearn
dbd6004f1b HD Wallets: redo key rotation, it's no longer automatic and expects the wallet app to poll for maintenance transactions. Deterministic keys now inherit the creation time of their parent. 2014-06-26 16:21:23 +02:00
Mike Hearn
534252de49 HD Wallets: bugfix, ensure we don't store private keys that can be rederived. 2014-05-29 20:11:14 +02:00
Mike Hearn
5638387d3a HD wallets alpha preview 2014-05-29 20:11:13 +02:00
Mike Hearn
d68b3b5108 Update script JSON files with latest changes from Peter Todd. 2014-05-09 14:18:13 +02:00
Andreas Schildbach
40d60306fa Unit tests for signing and verifying both valid and expired payment requests. 2014-04-14 16:40:39 +02:00
Andreas Schildbach
f13c437a54 Fix X509UtilsTest ended up in wrong package. 2014-04-14 16:35:39 +02:00
Andreas Schildbach
e7eec49671 Extract getDisplayNameFromCertificate() into new X509Utils class. Also joins PkiVerificationData.name and .orgName into one .displayName. Adds tests using client/smime certificates of mine. 2014-04-07 12:07:36 +02:00
Andreas Schildbach
b17533f8fb Add script test to prove that OP_0 evaluates as the empty vector, rather than [0]. Also adds debug output in case an script_invalid.json test fails. 2014-03-17 16:14:15 +01:00
Matt Corallo
28b24d0eaa Fix yet another throw-vs-return but in CHECKSIG (resolves #514) 2014-01-30 03:49:37 -05:00
Kevin Greene
3966875e8e Adding support for processing PaymentRequests. 2014-01-28 09:46:51 +01:00
Matt Corallo
0506b1b30c Fix yet another dumb script bug (resolves issue 479) 2013-11-11 03:31:47 -05:00
Matt Corallo
b9363999ae Fix signedness issue reading scripts (resolves issue 478) 2013-11-08 12:32:47 -05:00
Matt Corallo
2d36b89bb9 Update script json tests from upstream 2013-11-01 15:32:41 +01:00
Mike Hearn
3857b0ae05 Sync script test files with bitcoin upstream. 2013-08-13 11:44:46 +02:00