ElementsProject / libwally-core

Useful primitives for wallets
Other
281 stars 135 forks source link

test/test_transaction.py: test_hash_prevouts fails if libwallycore is built without SWIG and WASM #385

Closed whitslack closed 1 year ago

whitslack commented 1 year ago
./configure \
    --prefix=/usr --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu \
    --mandir=/usr/share/man --infodir=/usr/share/info --datadir=/usr/share \
    --sysconfdir=/etc --localstatedir=/var/lib \
    --disable-dependency-tracking --disable-silent-rules \
    --docdir=/usr/share/doc/libwally-core-0.8.9 \
    --htmldir=/usr/share/doc/libwally-core-0.8.9/html \
    --with-sysroot=/ \
    --libdir=/usr/lib64 --includedir=/usr/include/libwally \
    --enable-export-all --enable-tests --enable-elements \
    --disable-standard-secp --disable-minimal --enable-asm \
    --disable-swig-java --disable-swig-python

make

make -C src check-TESTS check-libwallycore PYTHON=python3.11

PYTHONDONTWRITEBYTECODE=1 python3.11 test/test_transaction.py
...E.....
======================================================================
ERROR: test_hash_prevouts (__main__.TransactionTests.test_hash_prevouts)
Test functions computing hash_prevouts
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/net-libs/libwally-core-0.8.9/work/libwally-core-release_0.8.9/src/test/test_transaction.py", line 278, in test_hash_prevouts
    _, num_inputs = wally_tx_get_num_inputs(tx)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/tmp/portage/net-libs/libwally-core-0.8.9/work/libwally-core-release_0.8.9/src/test/util.py", line 1062, in <lambda>
    def mksize_t(f): return lambda *args: size_t_fn_wrapper(f, *args)
                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/tmp/portage/net-libs/libwally-core-0.8.9/work/libwally-core-release_0.8.9/src/test/util.py", line 1031, in size_t_fn_wrapper
    ret = fn(*new_args)
          ^^^^^^^^^^^^^
TypeError: 'NoneType' object is not callable

The problem is that the TransactionTests.test_hash_prevouts unit test calls a function wally_tx_get_num_inputs that is only defined if the following preprocessor condition holds:

https://github.com/ElementsProject/libwally-core/blob/9f2f42df357f5b76d6273ab3165fb9ca671841d8/src/transaction.c#L3417

So when none of --enable-swig-java, --enable-swig-python, and --enable-wasm-interface are passed to configure, then the needed function is not defined in transaction.c, and so no such symbol appears in libwallycore_la-transaction.o. (The --enable-export-all option is irrelevant since the needed symbol is never defined, even internally.)

I'm working around the failure by adding a @skipUnless to test_hash_prevouts:

@unittest.skipUnless(hasattr(libwally, 'wally_tx_get_num_inputs'), 'requires SWIG/WASM build')
jgriffiths commented 1 year ago

@whitslack My bad, I've pushed a fix to master. At some stage these functions should be made available to all builds. And I need to set up a github action to run the tests in various build configs.

whitslack commented 1 year ago

@jgriffiths: Is the test actually passing for you now with your patch? Now I'm getting:

PYTHONDONTWRITEBYTECODE=1 python3.11 test/test_transaction.py
...E.....
======================================================================
ERROR: test_hash_prevouts (__main__.TransactionTests.test_hash_prevouts)
Test functions computing hash_prevouts
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/net-libs/libwally-core-0.8.9/work/libwally-core-release_0.8.9/src/test/test_transaction.py", line 291, in test_hash_prevouts
    wally_tx_get_input_txhash(tx, i, out, out_len)
TypeError: 'NoneType' object is not callable

----------------------------------------------------------------------
Ran 9 tests in 0.009s

It's not only wally_tx_get_num_inputs that is gated by those enable flags.

jgriffiths commented 1 year ago

Should be fixed properly now, tests are passing for me.