This repository has been archived by the owner on Jan 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 124
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 #124 from scottbelden/is_promotable
add is_promotable api
- Loading branch information
Showing
3 changed files
with
65 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class Helpers(object): | ||
""" | ||
Adds additional helper functions that aren't part of the core or extended | ||
API. | ||
""" | ||
|
||
def __init__(self, api): | ||
self.api = api | ||
|
||
def is_promotable(self, tail): | ||
# type: (TransactionHash) -> bool | ||
""" | ||
Determines if a tail transaction is promotable. | ||
:param tail: | ||
Transaction hash. Must be a tail transaction. | ||
""" | ||
return self.api.check_consistency(tails=[tail])['state'] |
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,45 @@ | ||
# coding=utf-8 | ||
from __future__ import absolute_import, division, print_function, \ | ||
unicode_literals | ||
|
||
from unittest import TestCase | ||
|
||
from iota import Iota, TransactionHash | ||
from iota.adapter import MockAdapter | ||
|
||
|
||
class HelpersTestCase(TestCase): | ||
def setUp(self): | ||
super(HelpersTestCase, self).setUp() | ||
|
||
self.api = api = Iota('mock://') | ||
self.api.adapter = MockAdapter() | ||
|
||
# noinspection SpellCheckingInspection | ||
self.transaction = ( | ||
'TESTVALUE9DONTUSEINPRODUCTION99999KPZOTR' | ||
'VDB9GZDJGZSSDCBIX9QOK9PAV9RMDBGDXLDTIZTWQ' | ||
) | ||
|
||
def test_positive_is_promotable(self): | ||
""" | ||
Transaction is promotable | ||
""" | ||
|
||
self.api.adapter.seed_response('checkConsistency', { | ||
'state': True, | ||
}) | ||
|
||
self.assertTrue(self.api.helpers.is_promotable(tail=self.transaction)) | ||
|
||
def test_negative_is_promotable(self): | ||
""" | ||
Transaction is not promotable | ||
""" | ||
|
||
self.api.adapter.seed_response('checkConsistency', { | ||
'state': False, | ||
'info': 'Inconsistent state', | ||
}) | ||
|
||
self.assertFalse(self.api.helpers.is_promotable(tail=self.transaction)) |