Skip to content

Commit

Permalink
make models work again
Browse files Browse the repository at this point in the history
  • Loading branch information
mvadari committed Jun 16, 2022
1 parent 84cc498 commit 928d990
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
32 changes: 13 additions & 19 deletions tests/unit/models/test_base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"30450221008CC9842A6855A37131FE7FB978675DCF329AC5CD7C881FAF6D13CDC23363059F02203A1"
"0475640C2C09541A55098109BB3326D3F49E2304710736A4E3C2773539B01"
)
public_key = "03ADB44CA8E56F78A0096825E5667C450ABD5C24C34E027BC1AAF7E5BD114CB5B5"
signing_key = "03ADB44CA8E56F78A0096825E5667C450ABD5C24C34E027BC1AAF7E5BD114CB5B5"


class TestBaseModel(TestCase):
Expand Down Expand Up @@ -131,7 +131,7 @@ def test_from_dict_recursive_transaction(self):

expected_dict = {
**sign_dict,
"tx_json": transaction.to_dict(),
"tx_json": transaction.to_xrpl(),
"method": "sign",
"fee_mult_max": 10,
"fee_div_max": 1,
Expand All @@ -147,7 +147,7 @@ def test_from_dict_recursive_transaction_tx_json(self):

expected_dict = {
**sign_dict,
"tx_json": transaction.to_dict(),
"tx_json": transaction.to_xrpl(),
"method": "sign",
"fee_mult_max": 10,
"fee_div_max": 1,
Expand Down Expand Up @@ -518,7 +518,7 @@ def test_from_xrpl_xchain_claim(self):
"Account": "r9A8UyNpW3X46FUc6P7JZqgn6WgAPjBwPg",
"Destination": "rKT9gDkaedAosiHyHZTjyZs2HvXpzuiGmC",
"Flags": 2147483648,
"TransactionType": "XChainClaim",
"TransactionType": "SidechainXChainClaim",
"XChainClaimProof": {
"amount": "1000000000",
"sidechain": {
Expand All @@ -529,22 +529,16 @@ def test_from_xrpl_xchain_claim(self):
},
"signatures": [
{
"XChainProofSig": {
"Signature": signature,
"PublicKey": public_key,
}
"signature": signature,
"signing_key": signing_key,
},
{
"XChainProofSig": {
"Signature": signature,
"PublicKey": public_key,
}
"signature": signature,
"signing_key": signing_key,
},
{
"XChainProofSig": {
"Signature": signature,
"PublicKey": public_key,
}
"signature": signature,
"signing_key": signing_key,
},
],
"was_src_chain_send": True,
Expand All @@ -565,9 +559,9 @@ def test_from_xrpl_xchain_claim(self):
src_chain_issue="XRP",
),
signatures=[
XChainProofSig(signature=signature, public_key=public_key),
XChainProofSig(signature=signature, public_key=public_key),
XChainProofSig(signature=signature, public_key=public_key),
XChainProofSig(signature=signature, signing_key=signing_key),
XChainProofSig(signature=signature, signing_key=signing_key),
XChainProofSig(signature=signature, signing_key=signing_key),
],
was_src_chain_send=True,
xchain_seq=1,
Expand Down
20 changes: 18 additions & 2 deletions xrpl/models/transactions/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,11 @@ def from_dict(cls: Type[T], value: Dict[str, Any]) -> T:
return correct_type.from_dict(value) # type: ignore
else:
if "transaction_type" in value:
if value["transaction_type"] != cls.__name__:
# TODO: remove sidechain caveat once renames happen
if (
value["transaction_type"] != cls.__name__
and "Sidechain" not in value["transaction_type"]
):
transaction_type = value["transaction_type"]
raise XRPLModelException(
f"Using wrong constructor: using {cls.__name__} constructor "
Expand Down Expand Up @@ -480,8 +484,20 @@ def get_transaction_type(
import xrpl.models.transactions as transaction_models
import xrpl.models.transactions.pseudo_transactions as pseudo_transaction_models

# TODO: remove once renames happen
exceptions = {
"SidechainXChainClaim": "XChainClaim",
"SidechainCreate": "XChainDoorCreate",
"SidechainXChainSeqNumCreate": "XChainSeqNumCreate",
"SidechainXChainTransfer": "XChainTransfer",
}

transaction_types: Dict[str, Type[Transaction]] = {
t.value: getattr(transaction_models, t)
t.value: (
getattr(transaction_models, t)
if t.value not in exceptions
else getattr(transaction_models, exceptions[t])
)
for t in transaction_models.types.TransactionType
}
if transaction_type in transaction_types:
Expand Down

0 comments on commit 928d990

Please sign in to comment.