Output.from_dict accepts string

This commit is contained in:
Scott Sadler 2017-03-15 10:00:00 +01:00
parent 56b81f9d8d
commit f23bfa52d1
2 changed files with 10 additions and 6 deletions

View File

@ -264,7 +264,7 @@ class Output(object):
output = {
'public_keys': self.public_keys,
'condition': condition,
'amount': self.amount
'amount': str(self.amount),
}
return output
@ -381,7 +381,11 @@ class Output(object):
except KeyError:
# NOTE: Hashlock condition case
fulfillment = data['condition']['uri']
return cls(fulfillment, data['public_keys'], data['amount'])
try:
amount = int(data['amount'])
except ValueError:
raise AmountError('Invalid amount: %s' % amount)
return cls(fulfillment, data['public_keys'], amount)
class Transaction(object):

View File

@ -83,7 +83,7 @@ def test_output_serialization(user_Ed25519, user_pub):
'details': user_Ed25519.to_dict(),
},
'public_keys': [user_pub],
'amount': 1,
'amount': '1',
}
cond = Output(user_Ed25519, [user_pub], 1)
@ -101,7 +101,7 @@ def test_output_deserialization(user_Ed25519, user_pub):
'details': user_Ed25519.to_dict()
},
'public_keys': [user_pub],
'amount': 1,
'amount': '1',
}
cond = Output.from_dict(cond)
@ -120,7 +120,7 @@ def test_output_hashlock_serialization():
'uri': hashlock,
},
'public_keys': None,
'amount': 1,
'amount': '1',
}
cond = Output(hashlock, amount=1)
@ -140,7 +140,7 @@ def test_output_hashlock_deserialization():
'uri': hashlock
},
'public_keys': None,
'amount': 1,
'amount': '1',
}
cond = Output.from_dict(cond)