-
-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1360 from firoorg/spark
Spark
- Loading branch information
Showing
233 changed files
with
20,697 additions
and
1,052 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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() |
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
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() |
Oops, something went wrong.