-
-
Save dermoth/843eec52e99346b841bc70d53303538a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright(C) 2017 by Abe developers. | |
# test_chain.py: test Abe Chain code with static data | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU Affero General Public License as | |
# published by the Free Software Foundation, either version 3 of the | |
# License, or (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, but | |
# WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
# Affero General Public License for more details. | |
# | |
# You should have received a copy of the GNU Affero General Public | |
# License along with this program. If not, see | |
# <http://www.gnu.org/licenses/agpl.html>. | |
import pytest | |
import os | |
import json | |
import Abe.Chain | |
CHAINNAMES = ["Bitcoin"] | |
CHAINS = {} | |
for chain in CHAINNAMES: | |
CHAINS[chain] = Abe.Chain.create(chain) | |
def txparams(): | |
for chainname, chain in CHAINS.iteritems(): | |
txfile = os.path.join(os.path.split(__file__)[0], | |
"data", "%s_tx.json" % chainname) | |
with open(txfile, 'r') as fd: | |
txdata = json.load(fd) | |
for tx in txdata: | |
rawtx = tx[0].decode('hex') | |
yield (chain.parse_transaction(rawtx), | |
tx[1], | |
chain.transaction_vlength(rawtx), | |
chain.transaction_hash(rawtx, sw=False), # tx Hash | |
chain.transaction_hash(rawtx)) # txid | |
@pytest.fixture(scope="module", params=txparams()) | |
def txdata(request): | |
yield request.param | |
def test_tx_version(txdata): | |
assert txdata[0]['version'] == txdata[1]['version'] | |
def test_tx_locktime(txdata): | |
assert txdata[0]['lockTime'] == txdata[1]['locktime'] | |
def test_tx_txin_cnt(txdata): | |
assert len(txdata[0]['txIn']) == len(txdata[1]['vin']) | |
def test_tx_txout_cnt(txdata): | |
assert len(txdata[0]['txOut']) == len(txdata[1]['vout']) | |
def test_tx_txins(txdata): | |
for txin in xrange(len(txdata[0]['txIn'])): | |
assert txdata[0]['txIn'][txin]['prevout_hash'] == \ | |
txdata[1]['vin'][txin]['txid'].decode('hex')[::-1] | |
assert txdata[0]['txIn'][txin]['prevout_n'] == \ | |
txdata[1]['vin'][txin]['vout'] | |
assert txdata[0]['txIn'][txin]['sequence'] == \ | |
txdata[1]['vin'][txin]['sequence'] | |
def test_tx_txouts(txdata): | |
for txout in xrange(len(txdata[0]['txOut'])): | |
assert txdata[0]['txOut'][txout]['scriptPubKey'] == \ | |
txdata[1]['vout'][txout]['scriptPubKey']['hex'].decode('hex') | |
assert txdata[0]['txOut'][txout]['value'] == \ | |
int(txdata[1]['vout'][txout]['value'] * 10e7) | |
def test_tx_txWitness(txdata): | |
for txin in xrange(len(txdata[0]['txIn'])): | |
print txdata[0] | |
assert len(txdata[0]['txWitness'][txin]) == \ | |
len(txdata[1]['vin'][txin]['txinwitness']) | |
for wit in xrange(len(txdata[0]['txWitness'][txin])): | |
assert txdata[0]['txWitness'][txin][wit] == \ | |
txdata[1]['vin'][txin]['txinwitness'][wit].decode('hex') | |
def test_tx_txLen(txdata): | |
assert len(txdata[0]['__data__']) == txdata[1]['size'] | |
#def test_tx_txVlen(txdata): # TODO | |
# assert txdata[2] == txdata[1]['vsize'] | |
def test_tx_txHash(txdata): | |
assert txdata[3] == txdata[1]['hash'].decode('hex')[::-1] | |
#def test_tx_txId(txdata): # TODO | |
# assert txdata[4] == txdata[1]['txid'].decode('hex')[::-1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment