-
Notifications
You must be signed in to change notification settings - Fork 41
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
Showing
2 changed files
with
94 additions
and
4 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,86 @@ | ||
from pytest import mark, raises | ||
|
||
|
||
class TestThresholdSha256: | ||
|
||
@mark.parametrize('threshold', (0, 0.1, 'a')) | ||
def test_init_with_invalid_threshold(self, threshold): | ||
from cryptoconditions.types.threshold import ThresholdSha256 | ||
with raises(ValueError) as exc: | ||
ThresholdSha256(threshold=threshold) | ||
assert exc.value.args == ( | ||
'Threshold must be a integer greater than zero, was: {}'. | ||
format(threshold), | ||
) | ||
|
||
def test_add_subcondition_type_error(self): | ||
from cryptoconditions.types.threshold import ThresholdSha256 | ||
threshold_obj = ThresholdSha256() | ||
with raises(TypeError) as exc: | ||
threshold_obj.add_subcondition(123) | ||
assert exc.value.args == ( | ||
'Subconditions must be URIs or objects of type Condition',) | ||
|
||
def test_add_subcondition_as_uri(self, minimal_threshold): | ||
from cryptoconditions.types.threshold import ThresholdSha256 | ||
from cryptoconditions.fulfillment import Fulfillment | ||
threshold_obj = ThresholdSha256( | ||
threshold=minimal_threshold.json['threshold']) | ||
subfulfillment = Fulfillment.from_json( | ||
minimal_threshold.json['subfulfillments'][0]) | ||
subcondition_uri = subfulfillment.condition_uri | ||
threshold_obj.add_subcondition(subcondition_uri) | ||
threshold_obj.serialize_uri == minimal_threshold.fulfillment | ||
|
||
def test_add_subcondition_as_object(self, minimal_threshold): | ||
from cryptoconditions.types.threshold import ThresholdSha256 | ||
from cryptoconditions.fulfillment import Fulfillment | ||
threshold_obj = ThresholdSha256( | ||
threshold=minimal_threshold.json['threshold']) | ||
subfulfillment = Fulfillment.from_json( | ||
minimal_threshold.json['subfulfillments'][0]) | ||
subcondition_object = subfulfillment.condition | ||
threshold_obj.add_subcondition(subcondition_object) | ||
threshold_obj.serialize_uri == minimal_threshold.fulfillment | ||
|
||
def test_add_subfulfillment_type_error(self): | ||
from cryptoconditions.types.threshold import ThresholdSha256 | ||
threshold_obj = ThresholdSha256() | ||
with raises(TypeError) as exc: | ||
threshold_obj.add_subfulfillment(123) | ||
assert exc.value.args == ( | ||
'Subfulfillments must be URIs or objects of type Fulfillment',) | ||
|
||
def test_add_subfulfillment_as_uri(self, minimal_threshold): | ||
from cryptoconditions.types.threshold import ThresholdSha256 | ||
from cryptoconditions.fulfillment import Fulfillment | ||
threshold_obj = ThresholdSha256( | ||
threshold=minimal_threshold.json['threshold']) | ||
subfulfillment = Fulfillment.from_json( | ||
minimal_threshold.json['subfulfillments'][0]) | ||
subfulfillment_uri = subfulfillment.serialize_uri() | ||
threshold_obj.add_subfulfillment(subfulfillment_uri) | ||
threshold_obj.serialize_uri == minimal_threshold.fulfillment | ||
|
||
def test_add_subfulfillment_as_object(self, minimal_threshold): | ||
from cryptoconditions.types.threshold import ThresholdSha256 | ||
from cryptoconditions.fulfillment import Fulfillment | ||
threshold_obj = ThresholdSha256( | ||
threshold=minimal_threshold.json['threshold']) | ||
subfulfillment_object = Fulfillment.from_json( | ||
minimal_threshold.json['subfulfillments'][0]) | ||
threshold_obj.add_subfulfillment(subfulfillment_object) | ||
threshold_obj.serialize_uri == minimal_threshold.fulfillment | ||
|
||
def test_asn1_dict_payload(self): | ||
from cryptoconditions.exceptions import ValidationError | ||
from cryptoconditions.types.threshold import ThresholdSha256 | ||
threshold_obj = ThresholdSha256(threshold=1) | ||
with raises(ValidationError) as exc: | ||
threshold_obj.asn1_dict_payload | ||
assert exc.value.args == ('Not enough fulfillments',) | ||
|
||
def test_calculate_worst_case_length(self): | ||
from cryptoconditions.types.threshold import ThresholdSha256 | ||
cost = ThresholdSha256.calculate_worst_case_length(1, ()) | ||
assert cost == float('-inf') |