forked from CounterpartyXCP/counterparty-core
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38d50a4
commit b4e6c42
Showing
4 changed files
with
153 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import apsw | ||
import bson | ||
from counterpartylib.lib.messages.triggers.asset_metadata import asset_metadata_receiver | ||
from counterpartylib.lib.messages import issuance | ||
from counterpartylib.lib import blocks, config, database | ||
|
||
config.DATABASE = ':memory:' | ||
config.BLOCK_FIRST = 1 | ||
config.REGTEST = 0 | ||
config.TESTNET = 0 | ||
block_index = 1 | ||
|
||
db = database.get_connection(read_only=False) | ||
blocks.initialise(db) | ||
cursor = db.cursor() | ||
bindings= { | ||
'tx_index': 0, | ||
'tx_hash': 'target_hash', | ||
'block_index': 0, | ||
'asset': 'XMP', | ||
'quantity': 1, | ||
'divisible': True, | ||
'vendable': True, | ||
'listed': True, | ||
'reassignable': True, | ||
'fungible': True, | ||
'source': 'source', | ||
'issuer': 'source', | ||
'transfer': True, | ||
'callable': False, | ||
'call_date': 0, | ||
'call_price': 0, | ||
'description': 'description', | ||
'fee_paid': 0, | ||
'locked': True, | ||
'status': 'valid', | ||
'asset_longname': 'asset_longname', | ||
} | ||
cursor.execute('''insert into issuances values( | ||
:tx_index, | ||
:tx_hash, | ||
0, | ||
:block_index, | ||
:asset, | ||
:quantity, | ||
:divisible, | ||
:source, | ||
:issuer, | ||
:transfer, | ||
:callable, | ||
:call_date, | ||
:call_price, | ||
:description, | ||
:fee_paid, | ||
:locked, | ||
:status, | ||
:asset_longname, | ||
:listed, | ||
:reassignable, | ||
:vendable,:fungible)''', bindings) | ||
|
||
def test_name(): | ||
receiver = asset_metadata_receiver(db, 'source', 'target_hash', b'hoge') | ||
assert receiver.name == 'asset_metadata' | ||
|
||
def test_target_table_name(): | ||
assert asset_metadata_receiver.target_table_name() == 'issuances' | ||
|
||
def test_compose(): | ||
asset_metadata_receiver.compose(db, 'source', 'target_hash', 'payload', False) | ||
|
||
def test_validate_1(): | ||
receiver = asset_metadata_receiver(db, 'source', 'target_hash', b'') | ||
problems = receiver.validate() | ||
assert problems == ['invalid message length'] | ||
|
||
def test_validate_2(): | ||
receiver = asset_metadata_receiver(db, 'source', 'target_hash', b'broken') | ||
problems = receiver.validate() | ||
assert problems == ['BSON parse failed'] | ||
|
||
def test_validate_3(): | ||
bin = bson.dumps({ 'foo': 1, 'bar': 'baz'}) | ||
receiver = asset_metadata_receiver(db, 'source', 'invalid_hash', b'\00' + bin) | ||
problems = receiver.validate() | ||
assert problems == ['Cannot find target asset'] | ||
|
||
def test_validate_4(): | ||
bin = bson.dumps({ 'foo': 1, 'bar': 'baz'}) | ||
receiver = asset_metadata_receiver(db, 'source', 'target_hash', b'\00' + bin) | ||
problems = receiver.validate() | ||
assert problems == ['failed to parse payload'] | ||
|