Skip to content

Commit

Permalink
Merge pull request #1360 from firoorg/spark
Browse files Browse the repository at this point in the history
Spark
  • Loading branch information
levonpetrosyan93 authored Nov 21, 2023
2 parents 87f1d68 + d3e579f commit 054b065
Show file tree
Hide file tree
Showing 233 changed files with 20,697 additions and 1,052 deletions.
30 changes: 25 additions & 5 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 0)
define(_CLIENT_VERSION_MINOR, 14)
define(_CLIENT_VERSION_REVISION, 12)
define(_CLIENT_VERSION_BUILD, 1)
define(_CLIENT_VERSION_BUILD, 6)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2023)
define(_COPYRIGHT_HOLDERS,[The %s developers])
Expand Down Expand Up @@ -92,7 +92,18 @@ AC_PATH_TOOL(OBJCOPY, objcopy)
AC_ARG_VAR(PYTHONPATH, Augments the default search path for python module files)

# Enable wallet
enable_wallet=yes
AC_ARG_ENABLE([wallet],
[AS_HELP_STRING([--disable-wallet],
[disable wallet (enabled by default)])],
[enable_wallet=$enableval],
[enable_wallet=yes])

AC_ARG_WITH([bdb],
[AS_HELP_STRING([--without-bdb],
[disable bdb wallet support (default is enabled if wallet is enabled)])],
[use_bdb=$withval],
[use_bdb=auto])


AC_ARG_ENABLE([elysium],
[AS_HELP_STRING([--enable-elysium],[enable elysium (disabled by default)])],
Expand Down Expand Up @@ -651,9 +662,11 @@ AC_SUBST(LEVELDB_CPPFLAGS)
AC_SUBST(LIBLEVELDB)
AC_SUBST(LIBMEMENV)

if test x$enable_wallet != xno; then
dnl Check for libdb_cxx only if wallet enabled
BITCOIN_FIND_BDB48
if test "$enable_wallet" != "no"; then
dnl Check for libdb_cxx only if wallet enabled
if test "$use_bdb" != "no"; then
BITCOIN_FIND_BDB48
fi
fi

dnl Check for libminiupnpc (optional)
Expand Down Expand Up @@ -1168,6 +1181,7 @@ AM_CONDITIONAL([USE_LCOV],[test x$use_lcov = xyes])
AM_CONDITIONAL([GLIBC_BACK_COMPAT],[test x$use_glibc_compat = xyes])
AM_CONDITIONAL([HARDEN],[test x$use_hardening = xyes])
AM_CONDITIONAL([ENABLE_SSE42],[test x$enable_sse42 = xyes])
AM_CONDITIONAL([USE_BDB], [test "$use_bdb" = "yes"])

AC_DEFINE(CLIENT_VERSION_MAJOR, _CLIENT_VERSION_MAJOR, [Major version])
AC_DEFINE(CLIENT_VERSION_MINOR, _CLIENT_VERSION_MINOR, [Minor version])
Expand Down Expand Up @@ -1222,6 +1236,7 @@ AC_SUBST(ZMQ_LIBS)
AC_SUBST(PROTOBUF_LIBS)
AC_SUBST(QR_LIBS)
AC_SUBST(DSYMUTIL_FLAT)
AC_SUBST(USE_BDB)
AC_CONFIG_FILES([Makefile src/Makefile share/setup.nsi share/qt/Info.plist src/test/buildenv.py])
AC_CONFIG_FILES([qa/pull-tester/tests_config.py],[chmod +x qa/pull-tester/tests_config.py])
AC_CONFIG_FILES([contrib/devtools/split-debug.sh],[chmod +x contrib/devtools/split-debug.sh])
Expand Down Expand Up @@ -1291,6 +1306,11 @@ if test x$bitcoin_enable_qt != xno; then
echo " qt version = $bitcoin_qt_got_major_vers"
echo " with qr = $use_qr"
fi

if test "$enable_wallet" != "no"; then
echo " with bdb = $use_bdb"
fi

echo " with zmq = $use_zmq"
echo " with test = $use_tests"
echo " with bench = $use_bench"
Expand Down
5 changes: 4 additions & 1 deletion qa/pull-tester/rpc-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,16 @@
raise

testScripts = [
'spark_mint.py',
'spark_spend_gettransaction.py',
'spark_setmintstatus_validation.py',
'lelantus_mint.py',
'lelantus_setmintstatus_validation.py',
'lelantus_mintspend.py',
'lelantus_spend_gettransaction.py',
'elysium_create_denomination.py',
'elysium_property_creation_fee.py',
'elysium_sendmint.py',
# 'elysium_sendmint.py',
'elysium_sendmint_wallet_encryption.py',
'elysium_sendspend.py',
'elysium_sendspend_wallet_encryption.py',
Expand Down
2 changes: 1 addition & 1 deletion qa/rpc-tests/bip47-sendreceive.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def setup_network(self, split=False):

def run_test(self):

self.nodes[1].generate(1010)
self.nodes[1].generate(410)
node0_pcode = self.nodes[0].createrapaddress("node0-pcode0")

try:
Expand Down
2 changes: 1 addition & 1 deletion qa/rpc-tests/lelantus_mint.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def run_test(self):

assert_raises_message(
JSONRPCException,
"Lelantus is not activated yet",
"Lelantus is not active",
self.nodes[0].mintlelantus, 1)

self.nodes[0].generate(activation_block - self.nodes[0].getblockcount())
Expand Down
2 changes: 1 addition & 1 deletion qa/rpc-tests/lelantus_mintspend.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self):
def run_test(self):
# Decimal formating: 6 digits for balance will be enought 000.000
getcontext().prec = 6
self.nodes[0].generate(401)
self.nodes[0].generate(201)
self.sync_all()

start_bal = self.nodes[0].getbalance()
Expand Down
2 changes: 1 addition & 1 deletion qa/rpc-tests/llmq-cl-evospork.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def run_test(self):
self.nodes[0].sendtoaddress(self.payment_address, 1)

# mine many blocks, wait for chainlock
while self.nodes[0].getblockcount() < 1000:
while self.nodes[0].getblockcount() < 800:
self.nodes[0].generate(20)
self.wait_for_chainlock_tip_all_nodes()

Expand Down
2 changes: 1 addition & 1 deletion qa/rpc-tests/llmq-is-lelantus.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def run_test(self):
self.mine_quorum()
self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash())

self.nodes[0].generate(1000 - self.nodes[0].getblockcount())
self.nodes[0].generate(401 - self.nodes[0].getblockcount())
for i in range(0, 3):
mintTxids = self.nodes[0].mintlelantus(1)

Expand Down
58 changes: 58 additions & 0 deletions qa/rpc-tests/llmq-is-spark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env python3
# Copyright (c) 2015-2018 The Dash Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

from test_framework.mininode import *
from test_framework.test_framework import EvoZnodeTestFramework
from test_framework.util import sync_blocks, set_node_times, \
isolate_node, reconnect_isolated_node, set_mocktime, get_mocktime
from test_framework.util import assert_equal, assert_raises_jsonrpc, \
bitcoind_processes, start_nodes, start_node, connect_nodes_bi

from decimal import Decimal

'''
llmq-is-spark.py
Testing Instantsend for Spark transactions
'''

class LLMQ_IS_Lelantus(EvoZnodeTestFramework):
def __init__(self):
super().__init__(6, 5, extra_args=[['-debug=instantsend']] * 6 )
self.sporkprivkey = "cW2YM2xaeCaebfpKguBahUAgEzLXgSserWRuD29kSyKHq1TTgwRQ"

def run_test(self):
self.sporkAddress = self.nodes[0].getaccountaddress("")
self.mine_quorum()
self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash())

self.nodes[0].generate(1001 - self.nodes[0].getblockcount())

sparkaddress = self.nodes[0].getnewsparkaddress()[0]
for i in range(0, 3):
mintTxids = self.nodes[0].mintspark({sparkaddress: {"amount": 1, "memo":"Test memo"}})

for mintTxid in mintTxids:
mintTx = self.nodes[0].getrawtransaction(mintTxid, 1)
val = 0
for vi in mintTx['vin']:
val += vi['valueSat']
if val > 10000:
break;
val = Decimal((val - 10000) / 1e+8).quantize(Decimal('1e-7'))

assert(self.wait_for_instantlock(mintTxid, self.nodes[0]))

mintDspend = self.nodes[0].createrawtransaction(mintTx['vin'], {self.nodes[0].getnewaddress(): str(val)})
assert_raises_jsonrpc(-26, 'tx-txlock-conflict', self.nodes[0].sendrawtransaction, mintDspend)

self.nodes[0].generate(3)
assert (self.nodes[0].getrawtransaction(mintTxid, True)['confirmations'] > 0)

spendTxid = self.nodes[0].spendspark({self.sporkAddress: {"amount": 0.1, "subtractFee": False}})
assert(self.wait_for_instantlock(spendTxid, self.nodes[0]))

if __name__ == '__main__':
LLMQ_IS_Lelantus().main()
83 changes: 83 additions & 0 deletions qa/rpc-tests/spark_mint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env python3
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_raises_message, JSONRPCException

class SparkMintTest(BitcoinTestFramework):
def __init__(self):
super().__init__()
self.num_nodes = 1
self.setup_clean_chain = False

def run_test(self):
assert_raises_message(
JSONRPCException,
"Spark is not activated yet",
self.nodes[0].mintspark, 1)

self.nodes[0].generate(1001)

# generate coins
amounts = [1, 1.1, 2, 10]

# 10 confirmations
address = self.nodes[0].getnewsparkaddress()[0]
self.nodes[0].mintspark({address: {"amount": amounts[0], "memo":"Test memo"}})
self.nodes[0].mintspark({address: {"amount": amounts[1], "memo": "Test memo"}})
self.nodes[0].generate(5)

# 5 confirmations
self.nodes[0].mintspark({address: {"amount": amounts[2], "memo": "Test memo"}})
self.nodes[0].mintspark({address: {"amount": amounts[3], "memo": "Test memo"}})
self.nodes[0].generate(5)

# get all mints and utxos
mints = self.verify_listsparkmints(amounts)
self.verify_listunspentsparkmints(amounts)
assert_equal([False, False, False, False], list(map(lambda m : m["isUsed"], mints)))

# state modification test
# mark two coins as used
self.nodes[0].setsparkmintstatus(mints[2]["lTagHash"], True)
self.nodes[0].setsparkmintstatus(mints[3]["lTagHash"], True)

mints = self.verify_listsparkmints(amounts)
self.verify_listunspentsparkmints([1, 1.1])
assert_equal([False, False, True, True], list(map(lambda m : m["isUsed"], mints)))

# set a coin as unused
self.nodes[0].setsparkmintstatus(mints[3]["lTagHash"], False)
mints = self.verify_listsparkmints(amounts)
self.verify_listunspentsparkmints([1, 1.1, 10])
assert_equal([False, False, True, False], list(map(lambda m : m["isUsed"], mints)))

self.nodes[0].setsparkmintstatus(mints[0]["lTagHash"], False)
self.nodes[0].setsparkmintstatus(mints[1]["lTagHash"], False)
self.nodes[0].setsparkmintstatus(mints[2]["lTagHash"], False)
self.nodes[0].setsparkmintstatus(mints[3]["lTagHash"], False)

mints = self.verify_listsparkmints(amounts)
self.verify_listunspentsparkmints(amounts)
assert_equal([False, False, False, False], list(map(lambda m : m["isUsed"], mints)))

def verify_listsparkmints(self, expected_amounts):
mints = self.nodes[0].listsparkmints()
mints = sorted(mints, key = lambda u: u['amount'])

assert_equal(
sorted(expected_amounts),
list(map(lambda u: float(u['amount']), mints)))

return mints

def verify_listunspentsparkmints(self, expected_amounts):
mints = self.nodes[0].listunspentsparkmints()
mints = sorted(mints, key = lambda u: float(u['amount']))

assert_equal(
sorted(expected_amounts),
list(map(lambda u: float(u['amount']), mints)))

return mints

if __name__ == '__main__':
SparkMintTest().main()
Loading

0 comments on commit 054b065

Please sign in to comment.