From 7bc4c944dcc6d0f72a9b5f5868c0060431c45c73 Mon Sep 17 00:00:00 2001 From: SunMi Lee Date: Tue, 1 Jun 2021 12:13:15 -0700 Subject: [PATCH 1/7] Set up Diem ID Domains on mini wallet startup --- diem | 2 +- mini-wallet.md | 2 +- src/diem/jsonrpc/__init__.py | 1 + src/diem/jsonrpc/constants.py | 1 + src/diem/jsonrpc/jsonrpc_pb2.py | 65 ++++++++++++------- src/diem/jsonrpc/jsonrpc_pb2.pyi | 12 ++++ src/diem/testing/cli.py | 16 +++++ src/diem/testing/miniwallet/app/app.py | 26 ++++---- .../testing/miniwallet/app/diem_account.py | 3 + src/diem/testing/miniwallet/app/models.py | 6 ++ src/diem/testing/miniwallet/config.py | 11 +++- src/diem/testing/suites/conftest.py | 7 +- src/diem/testing/suites/envs.py | 5 ++ src/diem/testnet.py | 28 +++++++- src/diem/txnmetadata.py | 20 ++++++ tests/miniwallet/conftest.py | 6 +- tests/test_testing_cli.py | 8 ++- 17 files changed, 171 insertions(+), 48 deletions(-) diff --git a/diem b/diem index 05bdd16f..c3692998 160000 --- a/diem +++ b/diem @@ -1 +1 @@ -Subproject commit 05bdd16f4b940e29be37edb2d75e45ad704403b0 +Subproject commit c369299812a558a366905e3c2c615dfc49a86201 diff --git a/mini-wallet.md b/mini-wallet.md index 39fc5aa9..ee62db65 100644 --- a/mini-wallet.md +++ b/mini-wallet.md @@ -186,7 +186,7 @@ Use the MiniWallet Test Suite to automate testing and checking if your wallet ap `diem.testing.suites` package includes a `conftest.py`, which will be loaded by pytest for setting up test fixtures. -A package scope fixture in the `conftest.py` starts a MiniWallet application named `stub-wallet` as a counterparty service for testing payment with the target server specified by the `--target` option here. +A package scope fixture in the `conftest.py` starts a MiniWallet application named `stubwallet` as a counterparty service for testing payment with the target server specified by the `--target` option here. ### Work with a local testnet diff --git a/src/diem/jsonrpc/__init__.py b/src/diem/jsonrpc/__init__.py index adff9563..50af7b23 100644 --- a/src/diem/jsonrpc/__init__.py +++ b/src/diem/jsonrpc/__init__.py @@ -76,6 +76,7 @@ EVENT_DATA_BASE_URL_ROTATION, EVENT_DATA_CREATE_ACCOUNT, EVENT_DATA_ADMIN_TRANSACTION, + EVENT_DATA_DIEM_ID_DOMAIN, # VMStatus#type field values VM_STATUS_EXECUTED, VM_STATUS_OUT_OF_GAS, diff --git a/src/diem/jsonrpc/constants.py b/src/diem/jsonrpc/constants.py index 5ad5e73a..cc01c6a5 100644 --- a/src/diem/jsonrpc/constants.py +++ b/src/diem/jsonrpc/constants.py @@ -37,6 +37,7 @@ EVENT_DATA_BASE_URL_ROTATION: str = "baseurlrotation" EVENT_DATA_CREATE_ACCOUNT: str = "createaccount" EVENT_DATA_ADMIN_TRANSACTION: str = "admintransaction" +EVENT_DATA_DIEM_ID_DOMAIN: str = "diemiddomain" # VMStatus#type field values diff --git a/src/diem/jsonrpc/jsonrpc_pb2.py b/src/diem/jsonrpc/jsonrpc_pb2.py index 836c8747..edf8dae5 100644 --- a/src/diem/jsonrpc/jsonrpc_pb2.py +++ b/src/diem/jsonrpc/jsonrpc_pb2.py @@ -19,7 +19,7 @@ syntax='proto3', serialized_options=b'\n\020org.diem.jsonrpcB\007JsonRpcZ\027github.com/diem/jsonrpc', create_key=_descriptor._internal_create_key, - serialized_pb=b'\n\rjsonrpc.proto\x12\x07jsonrpc\"*\n\x06\x41mount\x12\x0e\n\x06\x61mount\x18\x01 \x01(\x04\x12\x10\n\x08\x63urrency\x18\x02 \x01(\t\"\xf4\x03\n\x07\x41\x63\x63ount\x12\x0f\n\x07\x61\x64\x64ress\x18\x01 \x01(\t\x12!\n\x08\x62\x61lances\x18\x02 \x03(\x0b\x32\x0f.jsonrpc.Amount\x12(\n\x0fsequence_number\x18\x03 \x01(\x04R\x0fsequence_number\x12.\n\x12\x61uthentication_key\x18\x04 \x01(\tR\x12\x61uthentication_key\x12(\n\x0fsent_events_key\x18\x05 \x01(\tR\x0fsent_events_key\x12\x30\n\x13received_events_key\x18\x06 \x01(\tR\x13received_events_key\x12L\n!delegated_key_rotation_capability\x18\x07 \x01(\x08R!delegated_key_rotation_capability\x12H\n\x1f\x64\x65legated_withdrawal_capability\x18\x08 \x01(\x08R\x1f\x64\x65legated_withdrawal_capability\x12\x32\n\tis_frozen\x18\t \x01(\x08R\x1f\x64\x65legated_withdrawal_capability\x12\"\n\x04role\x18\n \x01(\x0b\x32\x14.jsonrpc.AccountRole\x12\x0f\n\x07version\x18\x0b \x01(\x04\"\xb3\x05\n\x0b\x41\x63\x63ountRole\x12\x0c\n\x04type\x18\x01 \x01(\t\x12\x30\n\x13parent_vasp_address\x18\x02 \x01(\tR\x13parent_vasp_address\x12\x1e\n\nhuman_name\x18\x03 \x01(\tR\nhuman_name\x12\x1a\n\x08\x62\x61se_url\x18\x04 \x01(\tR\x08\x62\x61se_url\x12(\n\x0f\x65xpiration_time\x18\x05 \x01(\x04R\x0f\x65xpiration_time\x12&\n\x0e\x63ompliance_key\x18\x06 \x01(\tR\x0e\x63ompliance_key\x12N\n\"compliance_key_rotation_events_key\x18\x07 \x01(\tR\"compliance_key_rotation_events_key\x12\x42\n\x1c\x62\x61se_url_rotation_events_key\x18\x08 \x01(\tR\x1c\x62\x61se_url_rotation_events_key\x12\"\n\x0cnum_children\x18\t \x01(\x04R\x0cnum_children\x12:\n\x18received_mint_events_key\x18\n \x01(\tR\x18received_mint_events_key\x12;\n\x10preburn_balances\x18\x0b \x03(\x0b\x32\x0f.jsonrpc.AmountR\x10preburn_balances\x12=\n\x0epreburn_queues\x18\x0c \x03(\x0b\x32\x15.jsonrpc.PreburnQueueR\x0epreburn_queues\x12(\n\x0f\x64iem_id_domains\x18\r \x03(\tR\x0f\x64iem_id_domains\x12<\n\x19\x64iem_id_domain_events_key\x18\x0e \x01(\tR\x19\x64iem_id_domain_events_key\"d\n\x0cPreburnQueue\x12\x1a\n\x08\x63urrency\x18\x01 \x01(\tR\x08\x63urrency\x12\x38\n\x08preburns\x18\x02 \x03(\x0b\x32\x1c.jsonrpc.PreburnWithMetadataR\x08preburns\"\\\n\x13PreburnWithMetadata\x12)\n\x07preburn\x18\x01 \x01(\x0b\x32\x0f.jsonrpc.AmountR\x07preburn\x12\x1a\n\x08metadata\x18\x02 \x01(\tR\x08metadata\"\x92\x01\n\x05\x45vent\x12\x0b\n\x03key\x18\x01 \x01(\t\x12(\n\x0fsequence_number\x18\x02 \x01(\x04R\x0fsequence_number\x12\x30\n\x13transaction_version\x18\x03 \x01(\x04R\x13transaction_version\x12 \n\x04\x64\x61ta\x18\x04 \x01(\x0b\x32\x12.jsonrpc.EventData\"\xa7\x05\n\tEventData\x12\x0c\n\x04type\x18\x01 \x01(\t\x12\x1f\n\x06\x61mount\x18\x02 \x01(\x0b\x32\x0f.jsonrpc.Amount\x12(\n\x0fpreburn_address\x18\x03 \x01(\tR\x0fpreburn_address\x12$\n\rcurrency_code\x18\x04 \x01(\tR\rcurrency_code\x12:\n\x18new_to_xdx_exchange_rate\x18\x05 \x01(\x02R\x18new_to_xdx_exchange_rate\x12\x0e\n\x06sender\x18\x06 \x01(\t\x12\x10\n\x08receiver\x18\x07 \x01(\t\x12\x10\n\x08metadata\x18\x08 \x01(\t\x12\r\n\x05\x65poch\x18\n \x01(\x04\x12\r\n\x05round\x18\x0b \x01(\x04\x12\x10\n\x08proposer\x18\x0c \x01(\t\x12$\n\rproposed_time\x18\r \x01(\x04R\rproposed_time\x12\x30\n\x13\x64\x65stination_address\x18\x0e \x01(\tR\x13\x64\x65stination_address\x12<\n\x19new_compliance_public_key\x18\x0f \x01(\tR\x19new_compliance_public_key\x12\"\n\x0cnew_base_url\x18\x10 \x01(\tR\x0cnew_base_url\x12\x32\n\x14time_rotated_seconds\x18\x11 \x01(\x04R\x14time_rotated_seconds\x12(\n\x0f\x63reated_address\x18\x12 \x01(\tR\x0f\x63reated_address\x12\x18\n\x07role_id\x18\x13 \x01(\x04R\x07role_id\x12:\n\x18\x63ommitted_timestamp_secs\x18\x14 \x01(\x04R\x18\x63ommitted_timestamp_secs\x12\r\n\x05\x62ytes\x18\x15 \x01(\t\"\xd2\x02\n\x08Metadata\x12\x0f\n\x07version\x18\x01 \x01(\x04\x12\x11\n\ttimestamp\x18\x02 \x01(\x04\x12\x1a\n\x08\x63hain_id\x18\x03 \x01(\rR\x08\x63hain_id\x12\x36\n\x16script_hash_allow_list\x18\x04 \x03(\tR\x16script_hash_allow_list\x12<\n\x19module_publishing_allowed\x18\x05 \x01(\x08R\x19module_publishing_allowed\x12\"\n\x0c\x64iem_version\x18\x06 \x01(\x04R\x0c\x64iem_version\x12\x34\n\x15\x61\x63\x63umulator_root_hash\x18\x07 \x01(\tR\x15\x61\x63\x63umulator_root_hash\x12\x36\n\x16\x64ual_attestation_limit\x18\x08 \x01(\x04R\x16\x64ual_attestation_limit\"\xd7\x01\n\x0bTransaction\x12\x0f\n\x07version\x18\x01 \x01(\x04\x12-\n\x0btransaction\x18\x02 \x01(\x0b\x32\x18.jsonrpc.TransactionData\x12\x0c\n\x04hash\x18\x03 \x01(\t\x12\r\n\x05\x62ytes\x18\x04 \x01(\t\x12\x1e\n\x06\x65vents\x18\x05 \x03(\x0b\x32\x0e.jsonrpc.Event\x12/\n\tvm_status\x18\x06 \x01(\x0b\x32\x11.jsonrpc.VMStatusR\tvm_status\x12\x1a\n\x08gas_used\x18\x07 \x01(\x04R\x08gas_used\"\x9d\x01\n\x15MoveAbortExplaination\x12\x10\n\x08\x63\x61tegory\x18\x01 \x01(\t\x12\x32\n\x14\x63\x61tegory_description\x18\x02 \x01(\tR\x14\x63\x61tegory_description\x12\x0e\n\x06reason\x18\x03 \x01(\t\x12.\n\x12reason_description\x18\x04 \x01(\tR\x12reason_description\"\xc9\x01\n\x08VMStatus\x12\x0c\n\x04type\x18\x01 \x01(\t\x12\x10\n\x08location\x18\x02 \x01(\t\x12\x1e\n\nabort_code\x18\x03 \x01(\x04R\nabort_code\x12&\n\x0e\x66unction_index\x18\x04 \x01(\rR\x0e\x66unction_index\x12 \n\x0b\x63ode_offset\x18\x05 \x01(\rR\x0b\x63ode_offset\x12\x33\n\x0b\x65xplanation\x18\x06 \x01(\x0b\x32\x1e.jsonrpc.MoveAbortExplaination\"\xf1\x05\n\x0fTransactionData\x12\x0c\n\x04type\x18\x01 \x01(\t\x12(\n\x0ftimestamp_usecs\x18\x02 \x01(\x04R\x0ftimestamp_usecs\x12\x0e\n\x06sender\x18\x03 \x01(\t\x12*\n\x10signature_scheme\x18\x04 \x01(\tR\x10signature_scheme\x12\x11\n\tsignature\x18\x05 \x01(\t\x12\x1e\n\npublic_key\x18\x06 \x01(\tR\npublic_key\x12(\n\x0fsequence_number\x18\x07 \x01(\x04R\x0fsequence_number\x12\x1a\n\x08\x63hain_id\x18\x08 \x01(\rR\x08\x63hain_id\x12&\n\x0emax_gas_amount\x18\t \x01(\x04R\x0emax_gas_amount\x12&\n\x0egas_unit_price\x18\n \x01(\x04R\x0egas_unit_price\x12\"\n\x0cgas_currency\x18\x0b \x01(\tR\x0cgas_currency\x12<\n\x19\x65xpiration_timestamp_secs\x18\x0c \x01(\x04R\x19\x65xpiration_timestamp_secs\x12 \n\x0bscript_hash\x18\r \x01(\tR\x0bscript_hash\x12\"\n\x0cscript_bytes\x18\x0e \x01(\tR\x0cscript_bytes\x12\x1f\n\x06script\x18\x0f \x01(\x0b\x32\x0f.jsonrpc.Script\x12,\n\x11secondary_signers\x18\x10 \x03(\tR\x11secondary_signers\x12@\n\x1bsecondary_signature_schemes\x18\x11 \x03(\tR\x1bsecondary_signature_schemes\x12\x32\n\x14secondary_signatures\x18\x12 \x03(\tR\x14secondary_signatures\x12\x34\n\x15secondary_public_keys\x18\x13 \x03(\tR\x15secondary_public_keys\"\xbf\x02\n\x06Script\x12\x0c\n\x04type\x18\x01 \x01(\t\x12\x0c\n\x04\x63ode\x18\x02 \x01(\t\x12\x11\n\targuments\x18\x03 \x03(\t\x12&\n\x0etype_arguments\x18\x04 \x03(\tR\x0etype_arguments\x12\x10\n\x08receiver\x18\x05 \x01(\t\x12\x0e\n\x06\x61mount\x18\x06 \x01(\x04\x12\x10\n\x08\x63urrency\x18\x07 \x01(\t\x12\x10\n\x08metadata\x18\x08 \x01(\t\x12.\n\x12metadata_signature\x18\t \x01(\tR\x12metadata_signature\x12\x16\n\x0emodule_address\x18\n \x01(\t\x12\x13\n\x0bmodule_name\x18\x0b \x01(\t\x12\x15\n\rfunction_name\x18\x0c \x01(\t\x12$\n\rarguments_bcs\x18\r \x03(\tR\rarguments_bcs\"\xa8\x03\n\x0c\x43urrencyInfo\x12\x0c\n\x04\x63ode\x18\x01 \x01(\t\x12&\n\x0escaling_factor\x18\x02 \x01(\x04R\x0escaling_factor\x12(\n\x0f\x66ractional_part\x18\x03 \x01(\x04R\x0f\x66ractional_part\x12\x32\n\x14to_xdx_exchange_rate\x18\x04 \x01(\x02R\x14to_xdx_exchange_rate\x12(\n\x0fmint_events_key\x18\x05 \x01(\tR\x0fmint_events_key\x12(\n\x0f\x62urn_events_key\x18\x06 \x01(\tR\x0f\x62urn_events_key\x12.\n\x12preburn_events_key\x18\x07 \x01(\tR\x12preburn_events_key\x12\x36\n\x16\x63\x61ncel_burn_events_key\x18\x08 \x01(\tR\x16\x63\x61ncel_burn_events_key\x12H\n\x1f\x65xchange_rate_update_events_key\x18\t \x01(\tR\x1f\x65xchange_rate_update_events_key\"\xba\x01\n\nStateProof\x12@\n\x1bledger_info_with_signatures\x18\x01 \x01(\tR\x1bledger_info_with_signatures\x12.\n\x12\x65poch_change_proof\x18\x02 \x01(\tR\x12\x65poch_change_proof\x12:\n\x18ledger_consistency_proof\x18\x03 \x01(\tR\x18ledger_consistency_proof\"a\n\x15\x41\x63\x63ountStateWithProof\x12\x0f\n\x07version\x18\x01 \x01(\x04\x12\x0c\n\x04\x62lob\x18\x02 \x01(\t\x12)\n\x05proof\x18\x03 \x01(\x0b\x32\x1a.jsonrpc.AccountStateProof\"\xe3\x01\n\x11\x41\x63\x63ountStateProof\x12T\n%ledger_info_to_transaction_info_proof\x18\x01 \x01(\tR%ledger_info_to_transaction_info_proof\x12*\n\x10transaction_info\x18\x02 \x01(\tR\x10transaction_info\x12L\n!transaction_info_to_account_proof\x18\x03 \x01(\tR!transaction_info_to_account_proofB4\n\x10org.diem.jsonrpcB\x07JsonRpcZ\x17github.com/diem/jsonrpcb\x06proto3' + serialized_pb=b'\n\rjsonrpc.proto\x12\x07jsonrpc\"*\n\x06\x41mount\x12\x0e\n\x06\x61mount\x18\x01 \x01(\x04\x12\x10\n\x08\x63urrency\x18\x02 \x01(\t\"\xf4\x03\n\x07\x41\x63\x63ount\x12\x0f\n\x07\x61\x64\x64ress\x18\x01 \x01(\t\x12!\n\x08\x62\x61lances\x18\x02 \x03(\x0b\x32\x0f.jsonrpc.Amount\x12(\n\x0fsequence_number\x18\x03 \x01(\x04R\x0fsequence_number\x12.\n\x12\x61uthentication_key\x18\x04 \x01(\tR\x12\x61uthentication_key\x12(\n\x0fsent_events_key\x18\x05 \x01(\tR\x0fsent_events_key\x12\x30\n\x13received_events_key\x18\x06 \x01(\tR\x13received_events_key\x12L\n!delegated_key_rotation_capability\x18\x07 \x01(\x08R!delegated_key_rotation_capability\x12H\n\x1f\x64\x65legated_withdrawal_capability\x18\x08 \x01(\x08R\x1f\x64\x65legated_withdrawal_capability\x12\x32\n\tis_frozen\x18\t \x01(\x08R\x1f\x64\x65legated_withdrawal_capability\x12\"\n\x04role\x18\n \x01(\x0b\x32\x14.jsonrpc.AccountRole\x12\x0f\n\x07version\x18\x0b \x01(\x04\"\xb3\x05\n\x0b\x41\x63\x63ountRole\x12\x0c\n\x04type\x18\x01 \x01(\t\x12\x30\n\x13parent_vasp_address\x18\x02 \x01(\tR\x13parent_vasp_address\x12\x1e\n\nhuman_name\x18\x03 \x01(\tR\nhuman_name\x12\x1a\n\x08\x62\x61se_url\x18\x04 \x01(\tR\x08\x62\x61se_url\x12(\n\x0f\x65xpiration_time\x18\x05 \x01(\x04R\x0f\x65xpiration_time\x12&\n\x0e\x63ompliance_key\x18\x06 \x01(\tR\x0e\x63ompliance_key\x12N\n\"compliance_key_rotation_events_key\x18\x07 \x01(\tR\"compliance_key_rotation_events_key\x12\x42\n\x1c\x62\x61se_url_rotation_events_key\x18\x08 \x01(\tR\x1c\x62\x61se_url_rotation_events_key\x12\"\n\x0cnum_children\x18\t \x01(\x04R\x0cnum_children\x12:\n\x18received_mint_events_key\x18\n \x01(\tR\x18received_mint_events_key\x12;\n\x10preburn_balances\x18\x0b \x03(\x0b\x32\x0f.jsonrpc.AmountR\x10preburn_balances\x12=\n\x0epreburn_queues\x18\x0c \x03(\x0b\x32\x15.jsonrpc.PreburnQueueR\x0epreburn_queues\x12(\n\x0f\x64iem_id_domains\x18\r \x03(\tR\x0f\x64iem_id_domains\x12<\n\x19\x64iem_id_domain_events_key\x18\x0e \x01(\tR\x19\x64iem_id_domain_events_key\"d\n\x0cPreburnQueue\x12\x1a\n\x08\x63urrency\x18\x01 \x01(\tR\x08\x63urrency\x12\x38\n\x08preburns\x18\x02 \x03(\x0b\x32\x1c.jsonrpc.PreburnWithMetadataR\x08preburns\"\\\n\x13PreburnWithMetadata\x12)\n\x07preburn\x18\x01 \x01(\x0b\x32\x0f.jsonrpc.AmountR\x07preburn\x12\x1a\n\x08metadata\x18\x02 \x01(\tR\x08metadata\"\x92\x01\n\x05\x45vent\x12\x0b\n\x03key\x18\x01 \x01(\t\x12(\n\x0fsequence_number\x18\x02 \x01(\x04R\x0fsequence_number\x12\x30\n\x13transaction_version\x18\x03 \x01(\x04R\x13transaction_version\x12 \n\x04\x64\x61ta\x18\x04 \x01(\x0b\x32\x12.jsonrpc.EventData\"\xf3\x05\n\tEventData\x12\x0c\n\x04type\x18\x01 \x01(\t\x12\x1f\n\x06\x61mount\x18\x02 \x01(\x0b\x32\x0f.jsonrpc.Amount\x12(\n\x0fpreburn_address\x18\x03 \x01(\tR\x0fpreburn_address\x12$\n\rcurrency_code\x18\x04 \x01(\tR\rcurrency_code\x12:\n\x18new_to_xdx_exchange_rate\x18\x05 \x01(\x02R\x18new_to_xdx_exchange_rate\x12\x0e\n\x06sender\x18\x06 \x01(\t\x12\x10\n\x08receiver\x18\x07 \x01(\t\x12\x10\n\x08metadata\x18\x08 \x01(\t\x12\r\n\x05\x65poch\x18\n \x01(\x04\x12\r\n\x05round\x18\x0b \x01(\x04\x12\x10\n\x08proposer\x18\x0c \x01(\t\x12$\n\rproposed_time\x18\r \x01(\x04R\rproposed_time\x12\x30\n\x13\x64\x65stination_address\x18\x0e \x01(\tR\x13\x64\x65stination_address\x12<\n\x19new_compliance_public_key\x18\x0f \x01(\tR\x19new_compliance_public_key\x12\"\n\x0cnew_base_url\x18\x10 \x01(\tR\x0cnew_base_url\x12\x32\n\x14time_rotated_seconds\x18\x11 \x01(\x04R\x14time_rotated_seconds\x12(\n\x0f\x63reated_address\x18\x12 \x01(\tR\x0f\x63reated_address\x12\x18\n\x07role_id\x18\x13 \x01(\x04R\x07role_id\x12:\n\x18\x63ommitted_timestamp_secs\x18\x14 \x01(\x04R\x18\x63ommitted_timestamp_secs\x12\r\n\x05\x62ytes\x18\x15 \x01(\t\x12\x18\n\x07removed\x18\x16 \x01(\x08R\x07removed\x12\x16\n\x06\x64omain\x18\x17 \x01(\tR\x06\x64omain\x12\x18\n\x07\x61\x64\x64ress\x18\x18 \x01(\tR\x07\x61\x64\x64ress\"\xd2\x02\n\x08Metadata\x12\x0f\n\x07version\x18\x01 \x01(\x04\x12\x11\n\ttimestamp\x18\x02 \x01(\x04\x12\x1a\n\x08\x63hain_id\x18\x03 \x01(\rR\x08\x63hain_id\x12\x36\n\x16script_hash_allow_list\x18\x04 \x03(\tR\x16script_hash_allow_list\x12<\n\x19module_publishing_allowed\x18\x05 \x01(\x08R\x19module_publishing_allowed\x12\"\n\x0c\x64iem_version\x18\x06 \x01(\x04R\x0c\x64iem_version\x12\x34\n\x15\x61\x63\x63umulator_root_hash\x18\x07 \x01(\tR\x15\x61\x63\x63umulator_root_hash\x12\x36\n\x16\x64ual_attestation_limit\x18\x08 \x01(\x04R\x16\x64ual_attestation_limit\"\xd7\x01\n\x0bTransaction\x12\x0f\n\x07version\x18\x01 \x01(\x04\x12-\n\x0btransaction\x18\x02 \x01(\x0b\x32\x18.jsonrpc.TransactionData\x12\x0c\n\x04hash\x18\x03 \x01(\t\x12\r\n\x05\x62ytes\x18\x04 \x01(\t\x12\x1e\n\x06\x65vents\x18\x05 \x03(\x0b\x32\x0e.jsonrpc.Event\x12/\n\tvm_status\x18\x06 \x01(\x0b\x32\x11.jsonrpc.VMStatusR\tvm_status\x12\x1a\n\x08gas_used\x18\x07 \x01(\x04R\x08gas_used\"\x9d\x01\n\x15MoveAbortExplaination\x12\x10\n\x08\x63\x61tegory\x18\x01 \x01(\t\x12\x32\n\x14\x63\x61tegory_description\x18\x02 \x01(\tR\x14\x63\x61tegory_description\x12\x0e\n\x06reason\x18\x03 \x01(\t\x12.\n\x12reason_description\x18\x04 \x01(\tR\x12reason_description\"\xc9\x01\n\x08VMStatus\x12\x0c\n\x04type\x18\x01 \x01(\t\x12\x10\n\x08location\x18\x02 \x01(\t\x12\x1e\n\nabort_code\x18\x03 \x01(\x04R\nabort_code\x12&\n\x0e\x66unction_index\x18\x04 \x01(\rR\x0e\x66unction_index\x12 \n\x0b\x63ode_offset\x18\x05 \x01(\rR\x0b\x63ode_offset\x12\x33\n\x0b\x65xplanation\x18\x06 \x01(\x0b\x32\x1e.jsonrpc.MoveAbortExplaination\"\xf1\x05\n\x0fTransactionData\x12\x0c\n\x04type\x18\x01 \x01(\t\x12(\n\x0ftimestamp_usecs\x18\x02 \x01(\x04R\x0ftimestamp_usecs\x12\x0e\n\x06sender\x18\x03 \x01(\t\x12*\n\x10signature_scheme\x18\x04 \x01(\tR\x10signature_scheme\x12\x11\n\tsignature\x18\x05 \x01(\t\x12\x1e\n\npublic_key\x18\x06 \x01(\tR\npublic_key\x12(\n\x0fsequence_number\x18\x07 \x01(\x04R\x0fsequence_number\x12\x1a\n\x08\x63hain_id\x18\x08 \x01(\rR\x08\x63hain_id\x12&\n\x0emax_gas_amount\x18\t \x01(\x04R\x0emax_gas_amount\x12&\n\x0egas_unit_price\x18\n \x01(\x04R\x0egas_unit_price\x12\"\n\x0cgas_currency\x18\x0b \x01(\tR\x0cgas_currency\x12<\n\x19\x65xpiration_timestamp_secs\x18\x0c \x01(\x04R\x19\x65xpiration_timestamp_secs\x12 \n\x0bscript_hash\x18\r \x01(\tR\x0bscript_hash\x12\"\n\x0cscript_bytes\x18\x0e \x01(\tR\x0cscript_bytes\x12\x1f\n\x06script\x18\x0f \x01(\x0b\x32\x0f.jsonrpc.Script\x12,\n\x11secondary_signers\x18\x10 \x03(\tR\x11secondary_signers\x12@\n\x1bsecondary_signature_schemes\x18\x11 \x03(\tR\x1bsecondary_signature_schemes\x12\x32\n\x14secondary_signatures\x18\x12 \x03(\tR\x14secondary_signatures\x12\x34\n\x15secondary_public_keys\x18\x13 \x03(\tR\x15secondary_public_keys\"\xbf\x02\n\x06Script\x12\x0c\n\x04type\x18\x01 \x01(\t\x12\x0c\n\x04\x63ode\x18\x02 \x01(\t\x12\x11\n\targuments\x18\x03 \x03(\t\x12&\n\x0etype_arguments\x18\x04 \x03(\tR\x0etype_arguments\x12\x10\n\x08receiver\x18\x05 \x01(\t\x12\x0e\n\x06\x61mount\x18\x06 \x01(\x04\x12\x10\n\x08\x63urrency\x18\x07 \x01(\t\x12\x10\n\x08metadata\x18\x08 \x01(\t\x12.\n\x12metadata_signature\x18\t \x01(\tR\x12metadata_signature\x12\x16\n\x0emodule_address\x18\n \x01(\t\x12\x13\n\x0bmodule_name\x18\x0b \x01(\t\x12\x15\n\rfunction_name\x18\x0c \x01(\t\x12$\n\rarguments_bcs\x18\r \x03(\tR\rarguments_bcs\"\xa8\x03\n\x0c\x43urrencyInfo\x12\x0c\n\x04\x63ode\x18\x01 \x01(\t\x12&\n\x0escaling_factor\x18\x02 \x01(\x04R\x0escaling_factor\x12(\n\x0f\x66ractional_part\x18\x03 \x01(\x04R\x0f\x66ractional_part\x12\x32\n\x14to_xdx_exchange_rate\x18\x04 \x01(\x02R\x14to_xdx_exchange_rate\x12(\n\x0fmint_events_key\x18\x05 \x01(\tR\x0fmint_events_key\x12(\n\x0f\x62urn_events_key\x18\x06 \x01(\tR\x0f\x62urn_events_key\x12.\n\x12preburn_events_key\x18\x07 \x01(\tR\x12preburn_events_key\x12\x36\n\x16\x63\x61ncel_burn_events_key\x18\x08 \x01(\tR\x16\x63\x61ncel_burn_events_key\x12H\n\x1f\x65xchange_rate_update_events_key\x18\t \x01(\tR\x1f\x65xchange_rate_update_events_key\"\xba\x01\n\nStateProof\x12@\n\x1bledger_info_with_signatures\x18\x01 \x01(\tR\x1bledger_info_with_signatures\x12.\n\x12\x65poch_change_proof\x18\x02 \x01(\tR\x12\x65poch_change_proof\x12:\n\x18ledger_consistency_proof\x18\x03 \x01(\tR\x18ledger_consistency_proof\"a\n\x15\x41\x63\x63ountStateWithProof\x12\x0f\n\x07version\x18\x01 \x01(\x04\x12\x0c\n\x04\x62lob\x18\x02 \x01(\t\x12)\n\x05proof\x18\x03 \x01(\x0b\x32\x1a.jsonrpc.AccountStateProof\"\xe3\x01\n\x11\x41\x63\x63ountStateProof\x12T\n%ledger_info_to_transaction_info_proof\x18\x01 \x01(\tR%ledger_info_to_transaction_info_proof\x12*\n\x10transaction_info\x18\x02 \x01(\tR\x10transaction_info\x12L\n!transaction_info_to_account_proof\x18\x03 \x01(\tR!transaction_info_to_account_proofB4\n\x10org.diem.jsonrpcB\x07JsonRpcZ\x17github.com/diem/jsonrpcb\x06proto3' ) @@ -568,6 +568,27 @@ message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='removed', full_name='jsonrpc.EventData.removed', index=20, + number=22, type=8, cpp_type=7, label=1, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, json_name='removed', file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='domain', full_name='jsonrpc.EventData.domain', index=21, + number=23, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, json_name='domain', file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='address', full_name='jsonrpc.EventData.address', index=22, + number=24, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, json_name='address', file=DESCRIPTOR, create_key=_descriptor._internal_create_key), ], extensions=[ ], @@ -581,7 +602,7 @@ oneofs=[ ], serialized_start=1613, - serialized_end=2292, + serialized_end=2368, ) @@ -661,8 +682,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=2295, - serialized_end=2633, + serialized_start=2371, + serialized_end=2709, ) @@ -735,8 +756,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=2636, - serialized_end=2851, + serialized_start=2712, + serialized_end=2927, ) @@ -788,8 +809,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=2854, - serialized_end=3011, + serialized_start=2930, + serialized_end=3087, ) @@ -855,8 +876,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=3014, - serialized_end=3215, + serialized_start=3090, + serialized_end=3291, ) @@ -1013,8 +1034,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=3218, - serialized_end=3971, + serialized_start=3294, + serialized_end=4047, ) @@ -1129,8 +1150,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=3974, - serialized_end=4293, + serialized_start=4050, + serialized_end=4369, ) @@ -1217,8 +1238,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=4296, - serialized_end=4720, + serialized_start=4372, + serialized_end=4796, ) @@ -1263,8 +1284,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=4723, - serialized_end=4909, + serialized_start=4799, + serialized_end=4985, ) @@ -1309,8 +1330,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=4911, - serialized_end=5008, + serialized_start=4987, + serialized_end=5084, ) @@ -1355,8 +1376,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=5011, - serialized_end=5238, + serialized_start=5087, + serialized_end=5314, ) _ACCOUNT.fields_by_name['balances'].message_type = _AMOUNT diff --git a/src/diem/jsonrpc/jsonrpc_pb2.pyi b/src/diem/jsonrpc/jsonrpc_pb2.pyi index 800cc55b..788d2fdd 100644 --- a/src/diem/jsonrpc/jsonrpc_pb2.pyi +++ b/src/diem/jsonrpc/jsonrpc_pb2.pyi @@ -278,6 +278,9 @@ class EventData(google___protobuf___message___Message): role_id: builtin___int = ... committed_timestamp_secs: builtin___int = ... bytes: typing___Text = ... + removed: builtin___bool = ... + domain: typing___Text = ... + address: typing___Text = ... @property def amount(self) -> type___Amount: ... def __init__( @@ -303,11 +306,16 @@ class EventData(google___protobuf___message___Message): role_id: typing___Optional[builtin___int] = None, committed_timestamp_secs: typing___Optional[builtin___int] = None, bytes: typing___Optional[typing___Text] = None, + removed: typing___Optional[builtin___bool] = None, + domain: typing___Optional[typing___Text] = None, + address: typing___Optional[typing___Text] = None, ) -> None: ... def HasField(self, field_name: typing_extensions___Literal["amount", b"amount"]) -> builtin___bool: ... def ClearField( self, field_name: typing_extensions___Literal[ + "address", + b"address", "amount", b"amount", "bytes", @@ -320,6 +328,8 @@ class EventData(google___protobuf___message___Message): b"currency_code", "destination_address", b"destination_address", + "domain", + b"domain", "epoch", b"epoch", "metadata", @@ -338,6 +348,8 @@ class EventData(google___protobuf___message___Message): b"proposer", "receiver", b"receiver", + "removed", + b"removed", "role_id", b"role_id", "round", diff --git a/src/diem/testing/cli.py b/src/diem/testing/cli.py index 88e4a09a..c4059457 100644 --- a/src/diem/testing/cli.py +++ b/src/diem/testing/cli.py @@ -43,6 +43,12 @@ def main() -> None: default=None, help="The address that will be used for offchain callbacks. Defaults to http://localhost:{port}", ) +@click.option( + "--diem-id-domain", + "-d", + default=None, + help="Domain ID for the wallet", +) @click.option("--jsonrpc", "-j", default=testnet.JSON_RPC_URL, help="Diem fullnode JSON-RPC URL.") @click.option("--faucet", "-f", default=testnet.FAUCET_URL, help="Testnet faucet URL.") @click.option("--disable-events-api", "-o", default=False, help="Disable account events API.", type=bool, is_flag=True) @@ -74,6 +80,7 @@ def start_server( import_diem_account_config_file: Optional[TextIO], logfile: Optional[str], hrp: str, + diem_id_domain: Optional[str], ) -> None: logging.basicConfig(level=logging.INFO, format=log_format, filename=logfile) configure_testnet(jsonrpc, faucet) @@ -82,6 +89,7 @@ def start_server( name=name, server_conf=ServerConfig(host=host, port=port, base_url=diem_account_base_url or ""), disable_events_api=disable_events_api, + diem_id_domain=diem_id_domain, ) if import_diem_account_config_file: conf.account_config = json.load(import_diem_account_config_file) @@ -126,6 +134,13 @@ def start_server( callback=set_env(envs.DMW_STUB_DIEM_ACCOUNT_BASE_URL), help="The address that will be used for offchain callbacks. Defaults to http://localhost:{port}", ) +@click.option( + "--stub-diem-id-domain", + "-d", + default=None, + callback=set_env(envs.DMW_STUB_DIEM_ID_DOMAIN), + help="Domain ID for the wallet", +) @click.option("--jsonrpc", "-j", default=testnet.JSON_RPC_URL, help="Diem fullnode JSON-RPC URL.") @click.option( "--match-keywords", @@ -178,6 +193,7 @@ def test( stub_bind_host: Optional[str], stub_bind_port: Optional[int], stub_diem_account_base_url: Optional[str], + stub_diem_id_domain: str, jsonrpc: str, match_keywords: str, faucet: str, diff --git a/src/diem/testing/miniwallet/app/app.py b/src/diem/testing/miniwallet/app/app.py index 6cd4a229..1e8a9008 100644 --- a/src/diem/testing/miniwallet/app/app.py +++ b/src/diem/testing/miniwallet/app/app.py @@ -17,12 +17,12 @@ class App: def __init__( - self, - account: LocalAccount, - child_accounts: List[LocalAccount], - client: jsonrpc.Client, - name: str, - logger: logging.Logger, + self, + account: LocalAccount, + child_accounts: List[LocalAccount], + client: jsonrpc.Client, + name: str, + logger: logging.Logger, ) -> None: self.logger = logger self.diem_account = DiemAccount(account, child_accounts, client) @@ -178,13 +178,13 @@ def _start_external_payment_txn(self, txn: Transaction) -> None: self.dual_attestation_txn_senders["v2"](txn) def _create_transaction( - self, - account_id: str, - status: str, - data: JsonInput, - type: Transaction.Type, - payee: Optional[str] = None, - subaddress_hex: Optional[str] = None, + self, + account_id: str, + status: str, + data: JsonInput, + type: Transaction.Type, + payee: Optional[str] = None, + subaddress_hex: Optional[str] = None, ) -> Transaction: return self.store.create( Transaction, diff --git a/src/diem/testing/miniwallet/app/diem_account.py b/src/diem/testing/miniwallet/app/diem_account.py index c71c390d..d7193c46 100644 --- a/src/diem/testing/miniwallet/app/diem_account.py +++ b/src/diem/testing/miniwallet/app/diem_account.py @@ -39,6 +39,9 @@ def travel_metadata(self, cmd: offchain.PaymentCommand) -> Tuple[bytes, bytes]: metadata = cmd.travel_rule_metadata(self.hrp) return (metadata, bytes.fromhex(str(cmd.payment.recipient_signature))) + def payment_metadata(self, reference_id: str) -> Tuple[bytes, bytes]: + return (txnmetadata.payment_metadata(reference_id), b"") + def submit_p2p( self, txn: Transaction, diff --git a/src/diem/testing/miniwallet/app/models.py b/src/diem/testing/miniwallet/app/models.py index c6a25791..b8950d8b 100644 --- a/src/diem/testing/miniwallet/app/models.py +++ b/src/diem/testing/miniwallet/app/models.py @@ -129,3 +129,9 @@ def to_offchain_command(self) -> offchain.PaymentCommand: inbound=self.is_inbound, cid=self.cid, ) + + +@dataclass +class DiemId(Base): + domain: str + account_onchain_address: str diff --git a/src/diem/testing/miniwallet/config.py b/src/diem/testing/miniwallet/config.py index abfdaa70..968eb3db 100644 --- a/src/diem/testing/miniwallet/config.py +++ b/src/diem/testing/miniwallet/config.py @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 from dataclasses import dataclass, field, asdict -from typing import Dict, Any, List, Tuple +from typing import Dict, Any, List, Tuple, Optional from .client import RestClient from .app import App, falcon_api from .. import LocalAccount @@ -31,6 +31,7 @@ class AppConfig: initial_amount: int = field(default=3_000_000_000_000) initial_currency: str = field(default=testnet.TEST_CURRENCY_CODE) child_account_size: int = field(default=2) + diem_id_domain: Optional[str] = field(default=None) @property def logger(self) -> logging.Logger: @@ -55,7 +56,13 @@ def create_client(self) -> RestClient: def setup_account(self, client: jsonrpc.Client) -> None: self.logger.info("faucet: mint %s", self.account.account_address.to_hex()) faucet = testnet.Faucet(client) - faucet.mint(self.account.auth_key.hex(), self.initial_amount, self.initial_currency) + faucet.mint( + self.account.auth_key.hex(), + self.initial_amount, + self.initial_currency, + diem_id_domain=self.diem_id_domain, + is_remove_domain=False, + ) self.logger.info("rotate dual attestation info for %s", self.account.account_address.to_hex()) self.logger.info("set base url to: %s", self.server_url) diff --git a/src/diem/testing/suites/conftest.py b/src/diem/testing/suites/conftest.py index ebb1e83e..9e06e12e 100644 --- a/src/diem/testing/suites/conftest.py +++ b/src/diem/testing/suites/conftest.py @@ -12,6 +12,7 @@ dmw_stub_server, dmw_stub_diem_account_config, dmw_stub_diem_account_hrp, + dmw_stub_diem_id_domain, ) from typing import Optional, Tuple, Dict, Any, Generator, Callable from dataclasses import asdict @@ -21,7 +22,7 @@ @pytest.fixture(scope="package") def target_client(diem_client: jsonrpc.Client) -> RestClient: if is_self_check(): - conf = AppConfig(name="target-wallet") + conf = AppConfig(name="target-wallet", diem_id_domain="targetdomain") print("self-checking, launch target app with config %s" % conf) conf.start(diem_client) return conf.create_client() @@ -48,7 +49,9 @@ def stub_wallet_app(start_stub_wallet: Tuple[AppConfig, App]) -> App: @pytest.fixture(scope="package") def start_stub_wallet(diem_client: jsonrpc.Client) -> Tuple[AppConfig, App]: - conf = AppConfig(name="stub-wallet", server_conf=ServerConfig(**dmw_stub_server())) + conf = AppConfig( + name="stubwallet", server_conf=ServerConfig(**dmw_stub_server()), diem_id_domain=dmw_stub_diem_id_domain() + ) account_conf = dmw_stub_diem_account_config() if account_conf: print("loads stub account config: %s" % account_conf) diff --git a/src/diem/testing/suites/envs.py b/src/diem/testing/suites/envs.py index e26d0c0c..60dde689 100644 --- a/src/diem/testing/suites/envs.py +++ b/src/diem/testing/suites/envs.py @@ -13,6 +13,7 @@ DMW_STUB_DIEM_ACCOUNT_BASE_URL: str = "DMW_STUB_DIEM_ACCOUNT_BASE_URL" DMW_STUB_DIEM_ACCOUNT_CONFIG: str = "DMW_STUB_DIEM_ACCOUNT_CONFIG" DMW_STUB_DIEM_ACCOUNT_HRP: str = "DMW_STUB_DIEM_ACCOUNT_HRP" +DMW_STUB_DIEM_ID_DOMAIN: str = "DMW_STUB_DIEM_ID_DOMAIN" def dmw_stub_diem_account_config() -> Optional[str]: @@ -27,6 +28,10 @@ def dmw_stub_diem_account_base_url() -> Optional[str]: return getenv(DMW_STUB_DIEM_ACCOUNT_BASE_URL) +def dmw_stub_diem_id_domain() -> Optional[str]: + return getenv(DMW_STUB_DIEM_ID_DOMAIN) + + def dmw_stub_server() -> Dict[str, Any]: return { k: v diff --git a/src/diem/testnet.py b/src/diem/testnet.py index 2427cb13..4c5583c7 100644 --- a/src/diem/testnet.py +++ b/src/diem/testnet.py @@ -89,10 +89,30 @@ def gen_account(self, currency_code: str = TEST_CURRENCY_CODE, dd_account: bool self.mint(account.auth_key.hex(), 100_000_000_000, currency_code, dd_account) return account - def mint(self, authkey: str, amount: int, currency_code: str, dd_account: bool = False) -> None: - self._retry.execute(lambda: self._mint_without_retry(authkey, amount, currency_code, dd_account)) + def mint( + self, + authkey: str, + amount: int, + currency_code: str, + dd_account: bool = False, + diem_id_domain: typing.Optional[str] = None, + is_remove_domain: typing.Optional[bool] = False, + ) -> None: + self._retry.execute( + lambda: self._mint_without_retry( + authkey, amount, currency_code, dd_account, diem_id_domain, is_remove_domain + ) + ) - def _mint_without_retry(self, authkey: str, amount: int, currency_code: str, dd_account: bool = False) -> None: + def _mint_without_retry( + self, + authkey: str, + amount: int, + currency_code: str, + dd_account: bool = False, + diem_id_domain: typing.Optional[str] = None, + is_remove_domain: typing.Optional[bool] = False, + ) -> None: response = self._session.post( self._url, params={ @@ -101,6 +121,8 @@ def _mint_without_retry(self, authkey: str, amount: int, currency_code: str, dd_ "currency_code": currency_code, "return_txns": "true", "is_designated_dealer": "true" if dd_account else "false", + "diem_id_domain": diem_id_domain, + "is_remove_domain": "true" if is_remove_domain else "false", }, ) response.raise_for_status() diff --git a/src/diem/txnmetadata.py b/src/diem/txnmetadata.py index bd253247..5d82c9a6 100644 --- a/src/diem/txnmetadata.py +++ b/src/diem/txnmetadata.py @@ -201,3 +201,23 @@ def refund_metadata_from_event(event: jsonrpc.Event) -> typing.Optional[bytes]: raise InvalidEventMetadataForRefundError(f"unknown metadata type: {metadata}") except ValueError as e: raise InvalidEventMetadataForRefundError(f"invalid event metadata for refund: {e}, event: {event}") + + +def payment_metadata( + reference_id: str, +) -> bytes: + """Create payment metadata for peer to peer transaction script + + Use this function to create metadata with a reference ID for peer to peer transfer + under travel rule threshold. + + """ + + metadata = diem_types.Metadata__PaymentMetadata( + value=diem_types.PaymentMetadata__PaymentMetadataVersion0( + value=diem_types.PaymentMetadataV0( # pyre-ignore + reference_id=reference_id, + ) + ) + ) + return metadata.bcs_serialize() diff --git a/tests/miniwallet/conftest.py b/tests/miniwallet/conftest.py index 382106dd..8b4ed3fd 100644 --- a/tests/miniwallet/conftest.py +++ b/tests/miniwallet/conftest.py @@ -9,12 +9,12 @@ @pytest.fixture(scope="package") def target_client(diem_client: jsonrpc.Client) -> RestClient: - return start_app(diem_client, "target-wallet").create_client() + return start_app(diem_client, "targetwallet").create_client() @pytest.fixture(scope="package") def stub_client(diem_client: jsonrpc.Client) -> RestClient: - return start_app(diem_client, "stub-wallet").create_client() + return start_app(diem_client, "stubwallet").create_client() @pytest.fixture(scope="package") @@ -38,7 +38,7 @@ def travel_rule_threshold(diem_client: jsonrpc.Client) -> int: def start_app(diem_client: jsonrpc.Client, app_name: str) -> AppConfig: - conf = AppConfig(name=app_name) + conf = AppConfig(name=app_name, diem_id_domain=app_name) print("launch %s with config %s" % (app_name, conf)) conf.start(diem_client) return conf diff --git a/tests/test_testing_cli.py b/tests/test_testing_cli.py index 3a6e9583..3cd85024 100644 --- a/tests/test_testing_cli.py +++ b/tests/test_testing_cli.py @@ -219,6 +219,8 @@ def start_test(runner: CliRunner, conf: ServerConfig, options: List[str] = []) - stub_conf.port, "--stub-diem-account-base-url", stub_conf.base_url, + "--stub-diem-id-domain", + "stubdomain", ] + options, ) @@ -229,7 +231,7 @@ def start_target_server(runner: CliRunner, options: List[str] = []) -> ServerCon conf.base_url = "http://127.0.0.1:%s" % conf.port def start_server(): - runner.invoke( + ret = runner.invoke( cli.start_server, [ "--jsonrpc", @@ -242,9 +244,13 @@ def start_server(): conf.port, "--diem-account-base-url", conf.base_url, + "--diem-id-domain", + "targetdomain", ] + options, ) + # if ret.exit_code != 0: + # raise Exception(ret) threading.Thread(target=start_server, daemon=True).start() utils.wait_for_port(conf.port) From f2bffe3495edeb69e082190c578adde316b3466e Mon Sep 17 00:00:00 2001 From: SunMi Lee Date: Thu, 3 Jun 2021 17:33:20 -0700 Subject: [PATCH 2/7] comments --- src/diem/testing/cli.py | 6 +-- src/diem/testing/miniwallet/app/models.py | 2 +- src/diem/testing/miniwallet/app/store.py | 19 ++++++- src/diem/testing/miniwallet/config.py | 1 - src/diem/testnet.py | 4 +- tests/test_testing_cli.py | 63 ++++++++++++++++++++--- 6 files changed, 79 insertions(+), 16 deletions(-) diff --git a/src/diem/testing/cli.py b/src/diem/testing/cli.py index c4059457..4a7edce6 100644 --- a/src/diem/testing/cli.py +++ b/src/diem/testing/cli.py @@ -47,7 +47,7 @@ def main() -> None: "--diem-id-domain", "-d", default=None, - help="Domain ID for the wallet", + help="Diem ID domain for the wallet parent VASP account", ) @click.option("--jsonrpc", "-j", default=testnet.JSON_RPC_URL, help="Diem fullnode JSON-RPC URL.") @click.option("--faucet", "-f", default=testnet.FAUCET_URL, help="Testnet faucet URL.") @@ -139,7 +139,7 @@ def start_server( "-d", default=None, callback=set_env(envs.DMW_STUB_DIEM_ID_DOMAIN), - help="Domain ID for the wallet", + help="Diem ID domain for the wallet parent VASP accountstub_diem_id_domain", ) @click.option("--jsonrpc", "-j", default=testnet.JSON_RPC_URL, help="Diem fullnode JSON-RPC URL.") @click.option( @@ -193,7 +193,7 @@ def test( stub_bind_host: Optional[str], stub_bind_port: Optional[int], stub_diem_account_base_url: Optional[str], - stub_diem_id_domain: str, + stub_diem_id_domain: Optional[str], jsonrpc: str, match_keywords: str, faucet: str, diff --git a/src/diem/testing/miniwallet/app/models.py b/src/diem/testing/miniwallet/app/models.py index b8950d8b..34e30bb1 100644 --- a/src/diem/testing/miniwallet/app/models.py +++ b/src/diem/testing/miniwallet/app/models.py @@ -134,4 +134,4 @@ def to_offchain_command(self) -> offchain.PaymentCommand: @dataclass class DiemId(Base): domain: str - account_onchain_address: str + account_address: str diff --git a/src/diem/testing/miniwallet/app/store.py b/src/diem/testing/miniwallet/app/store.py index 020438a3..6bde4dbe 100644 --- a/src/diem/testing/miniwallet/app/store.py +++ b/src/diem/testing/miniwallet/app/store.py @@ -3,7 +3,7 @@ from dataclasses import dataclass, field, asdict from typing import List, Dict, Type, Any, Callable, TypeVar, Generator -from .models import Base, Account, Event +from .models import Base, Account, Event, DiemId from .... import utils import json, time, threading @@ -61,10 +61,18 @@ def update(self, obj: T, before_update: Callable[[T], None] = lambda _: _, **dat self._update(obj) self._record_event(obj, "updated", data) + def remove(self, obj: T, before_remove: Callable[[T], None] = lambda _: _, **data: Any) -> None: + with self.resources_lock: + before_remove(obj) + self._remove(obj) + self._record_event(obj, "removed", data) + def _record_event(self, obj: T, action: str, data: Dict[str, Any]) -> None: if not isinstance(obj, Event): type = "%s_%s" % (action, utils.to_snake(obj)) - account_id = obj.id if isinstance(obj, Account) else obj.account_id # pyre-ignore + account_id = ( + obj.id if isinstance(obj, Account) or isinstance(obj, DiemId) else obj.account_id + ) # pyre-ignore data["id"] = obj.id self._insert(Event, account_id=account_id, type=type, data=json.dumps(data), timestamp=_ts()) @@ -81,6 +89,13 @@ def _insert(self, typ: Type[T], **res: Any) -> Dict[str, Any]: self.resources.setdefault(typ, []).append(asdict(typ(**res))) return res + def _remove(self, obj: T) -> None: + records = self.resources.get(type(obj), []) + index = next(iter([i for i, res in enumerate(records) if res["id"] == obj.id]), None) + if index is None: + raise NotFoundError("could not find resource by id: %s" % obj.id) + del records[index] + def _select(self, typ: Type[T], reverse: bool = False, **conds: Any) -> Generator[T, None, None]: items = reversed(self.resources.get(typ, [])) if reverse else self.resources.get(typ, []) for res in items: diff --git a/src/diem/testing/miniwallet/config.py b/src/diem/testing/miniwallet/config.py index 968eb3db..e9029c1e 100644 --- a/src/diem/testing/miniwallet/config.py +++ b/src/diem/testing/miniwallet/config.py @@ -61,7 +61,6 @@ def setup_account(self, client: jsonrpc.Client) -> None: self.initial_amount, self.initial_currency, diem_id_domain=self.diem_id_domain, - is_remove_domain=False, ) self.logger.info("rotate dual attestation info for %s", self.account.account_address.to_hex()) diff --git a/src/diem/testnet.py b/src/diem/testnet.py index 4c5583c7..2082bece 100644 --- a/src/diem/testnet.py +++ b/src/diem/testnet.py @@ -96,7 +96,7 @@ def mint( currency_code: str, dd_account: bool = False, diem_id_domain: typing.Optional[str] = None, - is_remove_domain: typing.Optional[bool] = False, + is_remove_domain: bool = False, ) -> None: self._retry.execute( lambda: self._mint_without_retry( @@ -111,7 +111,7 @@ def _mint_without_retry( currency_code: str, dd_account: bool = False, diem_id_domain: typing.Optional[str] = None, - is_remove_domain: typing.Optional[bool] = False, + is_remove_domain: bool = False, ) -> None: response = self._session.post( self._url, diff --git a/tests/test_testing_cli.py b/tests/test_testing_cli.py index 3cd85024..d4976902 100644 --- a/tests/test_testing_cli.py +++ b/tests/test_testing_cli.py @@ -202,6 +202,61 @@ def test_wait_timeout_for_target_ready(runner: CliRunner) -> None: assert duration < 2 +# def test_cli_init_with_diem_id_domain(runner: CliRunner) -> None: +# app_config_file = "app.json" +# stub_config_file = "stub.json" +# with runner.isolated_filesystem(): +# LocalAccount().write_to_file(app_config_file) +# LocalAccount().write_to_file(stub_config_file) +# +# conf = start_target_server(runner, ["-i", app_config_file, "--diem-id-domain", "targetdomain"]) +# result = start_test( +# runner, +# conf, +# [ +# "-i", +# stub_config_file, +# "-k", +# "test_create_a_blank_account", +# "--stub-diem-id-domain", +# "stubdomain", +# ], +# ) +# +# assert result.exit_code == 0, result.output + + +# def test_vasp_has_domain(stub_client: RestClient, target_client: RestClient, hrp: str) -> None: +# """ +# Test Plan: +# +# 1. Generate a valid account identifier from receiver account as payee. +# 2. Send a payment to the account identifier. +# 3. Wait for the transaction executed successfully. +# 4. Assert receiver account received the fund. +# +# """ +# +# sender_account = stub_client.create_account() +# receiver_account = target_client.create_account() +# account = target_client.create_account() +# account_identifier = account.generate_account_identifier() +# account_address, _ = identifier.decode_account(account_identifier, hrp) +# assert account_address +# +# client = testnet.create_client() +# account = client.get_account(account_address) + +# try: +# payee = receiver_account.generate_account_identifier() +# pay = sender_account.send_payment(currency=currency, amount=amount, payee=payee) +# wait_for_payment_transaction_complete(sender_account, pay.id) +# wait_for_balance(receiver_account, currency, amount) +# finally: +# receiver_account.log_events() +# sender_account.log_events() + + def start_test(runner: CliRunner, conf: ServerConfig, options: List[str] = []) -> Result: stub_conf = ServerConfig() return runner.invoke( @@ -219,8 +274,6 @@ def start_test(runner: CliRunner, conf: ServerConfig, options: List[str] = []) - stub_conf.port, "--stub-diem-account-base-url", stub_conf.base_url, - "--stub-diem-id-domain", - "stubdomain", ] + options, ) @@ -231,7 +284,7 @@ def start_target_server(runner: CliRunner, options: List[str] = []) -> ServerCon conf.base_url = "http://127.0.0.1:%s" % conf.port def start_server(): - ret = runner.invoke( + runner.invoke( cli.start_server, [ "--jsonrpc", @@ -244,13 +297,9 @@ def start_server(): conf.port, "--diem-account-base-url", conf.base_url, - "--diem-id-domain", - "targetdomain", ] + options, ) - # if ret.exit_code != 0: - # raise Exception(ret) threading.Thread(target=start_server, daemon=True).start() utils.wait_for_port(conf.port) From c0318e5007692ab5ec86a0f245c26aa61a1a1e38 Mon Sep 17 00:00:00 2001 From: SunMi Lee Date: Fri, 4 Jun 2021 10:32:33 -0700 Subject: [PATCH 3/7] After refactor --- diem | 2 +- src/diem/jsonrpc/client.py | 23 +++++- src/diem/jsonrpc/jsonrpc_pb2.py | 42 +++++++++- src/diem/jsonrpc/jsonrpc_pb2.pyi | 14 ++++ src/diem/testing/miniwallet/app/app.py | 28 ++++--- .../testing/miniwallet/app/event_puller.py | 21 +++++ src/diem/testing/miniwallet/app/models.py | 8 +- src/diem/testing/miniwallet/app/store.py | 19 +---- src/diem/testing/miniwallet/config.py | 28 +++++-- src/diem/testnet.py | 7 ++ src/diem/utils.py | 4 + tests/test_testing_cli.py | 81 +++++++------------ 12 files changed, 181 insertions(+), 96 deletions(-) diff --git a/diem b/diem index c3692998..d4470e4c 160000 --- a/diem +++ b/diem @@ -1 +1 @@ -Subproject commit c369299812a558a366905e3c2c615dfc49a86201 +Subproject commit d4470e4c3a6c37c0c6722d52fe701b55776f77a3 diff --git a/src/diem/jsonrpc/client.py b/src/diem/jsonrpc/client.py index 2ad4ef1b..817e6cea 100644 --- a/src/diem/jsonrpc/client.py +++ b/src/diem/jsonrpc/client.py @@ -413,6 +413,28 @@ def get_account_state_with_proof( params = [address, version, ledger_version] return self.execute("get_account_state_with_proof", params, _parse_obj(lambda: rpc.AccountStateWithProof())) + def get_diem_id_domain_map(self) -> typing.Dict[str, str]: + domain_map = {} + event_index = 0 + batch_size = 100 + tc_account = self.get_account(utils.get_treasury_compliance_address()) + event_stream_key = tc_account.role.diem_id_domain_events_key + while True: + events = self.get_events(event_stream_key, event_index, batch_size) + for event in events: + if event.data.removed: + del domain_map[event.data.domain] + else: + domain_map[event.data.domain] = event.data.address + if events.count() < batch_size: + break + event_index += batch_size + return domain_map + + def get_vasp_address_with_domain(self, domain: str) -> typing.Optional[str]: + domain_map = self.get_diem_id_domain_map() + return domain_map.get(domain) + def submit( self, txn: typing.Union[diem_types.SignedTransaction, str], @@ -506,7 +528,6 @@ def wait_for_transaction2( This means the executed transaction is from another process (which submitted transaction with same account address and sequence). """ - max_wait = time.time() + (timeout_secs or DEFAULT_WAIT_FOR_TRANSACTION_TIMEOUT_SECS) while time.time() < max_wait: txn = self.get_account_transaction(address, seq, True) diff --git a/src/diem/jsonrpc/jsonrpc_pb2.py b/src/diem/jsonrpc/jsonrpc_pb2.py index edf8dae5..2274d523 100644 --- a/src/diem/jsonrpc/jsonrpc_pb2.py +++ b/src/diem/jsonrpc/jsonrpc_pb2.py @@ -19,7 +19,7 @@ syntax='proto3', serialized_options=b'\n\020org.diem.jsonrpcB\007JsonRpcZ\027github.com/diem/jsonrpc', create_key=_descriptor._internal_create_key, - serialized_pb=b'\n\rjsonrpc.proto\x12\x07jsonrpc\"*\n\x06\x41mount\x12\x0e\n\x06\x61mount\x18\x01 \x01(\x04\x12\x10\n\x08\x63urrency\x18\x02 \x01(\t\"\xf4\x03\n\x07\x41\x63\x63ount\x12\x0f\n\x07\x61\x64\x64ress\x18\x01 \x01(\t\x12!\n\x08\x62\x61lances\x18\x02 \x03(\x0b\x32\x0f.jsonrpc.Amount\x12(\n\x0fsequence_number\x18\x03 \x01(\x04R\x0fsequence_number\x12.\n\x12\x61uthentication_key\x18\x04 \x01(\tR\x12\x61uthentication_key\x12(\n\x0fsent_events_key\x18\x05 \x01(\tR\x0fsent_events_key\x12\x30\n\x13received_events_key\x18\x06 \x01(\tR\x13received_events_key\x12L\n!delegated_key_rotation_capability\x18\x07 \x01(\x08R!delegated_key_rotation_capability\x12H\n\x1f\x64\x65legated_withdrawal_capability\x18\x08 \x01(\x08R\x1f\x64\x65legated_withdrawal_capability\x12\x32\n\tis_frozen\x18\t \x01(\x08R\x1f\x64\x65legated_withdrawal_capability\x12\"\n\x04role\x18\n \x01(\x0b\x32\x14.jsonrpc.AccountRole\x12\x0f\n\x07version\x18\x0b \x01(\x04\"\xb3\x05\n\x0b\x41\x63\x63ountRole\x12\x0c\n\x04type\x18\x01 \x01(\t\x12\x30\n\x13parent_vasp_address\x18\x02 \x01(\tR\x13parent_vasp_address\x12\x1e\n\nhuman_name\x18\x03 \x01(\tR\nhuman_name\x12\x1a\n\x08\x62\x61se_url\x18\x04 \x01(\tR\x08\x62\x61se_url\x12(\n\x0f\x65xpiration_time\x18\x05 \x01(\x04R\x0f\x65xpiration_time\x12&\n\x0e\x63ompliance_key\x18\x06 \x01(\tR\x0e\x63ompliance_key\x12N\n\"compliance_key_rotation_events_key\x18\x07 \x01(\tR\"compliance_key_rotation_events_key\x12\x42\n\x1c\x62\x61se_url_rotation_events_key\x18\x08 \x01(\tR\x1c\x62\x61se_url_rotation_events_key\x12\"\n\x0cnum_children\x18\t \x01(\x04R\x0cnum_children\x12:\n\x18received_mint_events_key\x18\n \x01(\tR\x18received_mint_events_key\x12;\n\x10preburn_balances\x18\x0b \x03(\x0b\x32\x0f.jsonrpc.AmountR\x10preburn_balances\x12=\n\x0epreburn_queues\x18\x0c \x03(\x0b\x32\x15.jsonrpc.PreburnQueueR\x0epreburn_queues\x12(\n\x0f\x64iem_id_domains\x18\r \x03(\tR\x0f\x64iem_id_domains\x12<\n\x19\x64iem_id_domain_events_key\x18\x0e \x01(\tR\x19\x64iem_id_domain_events_key\"d\n\x0cPreburnQueue\x12\x1a\n\x08\x63urrency\x18\x01 \x01(\tR\x08\x63urrency\x12\x38\n\x08preburns\x18\x02 \x03(\x0b\x32\x1c.jsonrpc.PreburnWithMetadataR\x08preburns\"\\\n\x13PreburnWithMetadata\x12)\n\x07preburn\x18\x01 \x01(\x0b\x32\x0f.jsonrpc.AmountR\x07preburn\x12\x1a\n\x08metadata\x18\x02 \x01(\tR\x08metadata\"\x92\x01\n\x05\x45vent\x12\x0b\n\x03key\x18\x01 \x01(\t\x12(\n\x0fsequence_number\x18\x02 \x01(\x04R\x0fsequence_number\x12\x30\n\x13transaction_version\x18\x03 \x01(\x04R\x13transaction_version\x12 \n\x04\x64\x61ta\x18\x04 \x01(\x0b\x32\x12.jsonrpc.EventData\"\xf3\x05\n\tEventData\x12\x0c\n\x04type\x18\x01 \x01(\t\x12\x1f\n\x06\x61mount\x18\x02 \x01(\x0b\x32\x0f.jsonrpc.Amount\x12(\n\x0fpreburn_address\x18\x03 \x01(\tR\x0fpreburn_address\x12$\n\rcurrency_code\x18\x04 \x01(\tR\rcurrency_code\x12:\n\x18new_to_xdx_exchange_rate\x18\x05 \x01(\x02R\x18new_to_xdx_exchange_rate\x12\x0e\n\x06sender\x18\x06 \x01(\t\x12\x10\n\x08receiver\x18\x07 \x01(\t\x12\x10\n\x08metadata\x18\x08 \x01(\t\x12\r\n\x05\x65poch\x18\n \x01(\x04\x12\r\n\x05round\x18\x0b \x01(\x04\x12\x10\n\x08proposer\x18\x0c \x01(\t\x12$\n\rproposed_time\x18\r \x01(\x04R\rproposed_time\x12\x30\n\x13\x64\x65stination_address\x18\x0e \x01(\tR\x13\x64\x65stination_address\x12<\n\x19new_compliance_public_key\x18\x0f \x01(\tR\x19new_compliance_public_key\x12\"\n\x0cnew_base_url\x18\x10 \x01(\tR\x0cnew_base_url\x12\x32\n\x14time_rotated_seconds\x18\x11 \x01(\x04R\x14time_rotated_seconds\x12(\n\x0f\x63reated_address\x18\x12 \x01(\tR\x0f\x63reated_address\x12\x18\n\x07role_id\x18\x13 \x01(\x04R\x07role_id\x12:\n\x18\x63ommitted_timestamp_secs\x18\x14 \x01(\x04R\x18\x63ommitted_timestamp_secs\x12\r\n\x05\x62ytes\x18\x15 \x01(\t\x12\x18\n\x07removed\x18\x16 \x01(\x08R\x07removed\x12\x16\n\x06\x64omain\x18\x17 \x01(\tR\x06\x64omain\x12\x18\n\x07\x61\x64\x64ress\x18\x18 \x01(\tR\x07\x61\x64\x64ress\"\xd2\x02\n\x08Metadata\x12\x0f\n\x07version\x18\x01 \x01(\x04\x12\x11\n\ttimestamp\x18\x02 \x01(\x04\x12\x1a\n\x08\x63hain_id\x18\x03 \x01(\rR\x08\x63hain_id\x12\x36\n\x16script_hash_allow_list\x18\x04 \x03(\tR\x16script_hash_allow_list\x12<\n\x19module_publishing_allowed\x18\x05 \x01(\x08R\x19module_publishing_allowed\x12\"\n\x0c\x64iem_version\x18\x06 \x01(\x04R\x0c\x64iem_version\x12\x34\n\x15\x61\x63\x63umulator_root_hash\x18\x07 \x01(\tR\x15\x61\x63\x63umulator_root_hash\x12\x36\n\x16\x64ual_attestation_limit\x18\x08 \x01(\x04R\x16\x64ual_attestation_limit\"\xd7\x01\n\x0bTransaction\x12\x0f\n\x07version\x18\x01 \x01(\x04\x12-\n\x0btransaction\x18\x02 \x01(\x0b\x32\x18.jsonrpc.TransactionData\x12\x0c\n\x04hash\x18\x03 \x01(\t\x12\r\n\x05\x62ytes\x18\x04 \x01(\t\x12\x1e\n\x06\x65vents\x18\x05 \x03(\x0b\x32\x0e.jsonrpc.Event\x12/\n\tvm_status\x18\x06 \x01(\x0b\x32\x11.jsonrpc.VMStatusR\tvm_status\x12\x1a\n\x08gas_used\x18\x07 \x01(\x04R\x08gas_used\"\x9d\x01\n\x15MoveAbortExplaination\x12\x10\n\x08\x63\x61tegory\x18\x01 \x01(\t\x12\x32\n\x14\x63\x61tegory_description\x18\x02 \x01(\tR\x14\x63\x61tegory_description\x12\x0e\n\x06reason\x18\x03 \x01(\t\x12.\n\x12reason_description\x18\x04 \x01(\tR\x12reason_description\"\xc9\x01\n\x08VMStatus\x12\x0c\n\x04type\x18\x01 \x01(\t\x12\x10\n\x08location\x18\x02 \x01(\t\x12\x1e\n\nabort_code\x18\x03 \x01(\x04R\nabort_code\x12&\n\x0e\x66unction_index\x18\x04 \x01(\rR\x0e\x66unction_index\x12 \n\x0b\x63ode_offset\x18\x05 \x01(\rR\x0b\x63ode_offset\x12\x33\n\x0b\x65xplanation\x18\x06 \x01(\x0b\x32\x1e.jsonrpc.MoveAbortExplaination\"\xf1\x05\n\x0fTransactionData\x12\x0c\n\x04type\x18\x01 \x01(\t\x12(\n\x0ftimestamp_usecs\x18\x02 \x01(\x04R\x0ftimestamp_usecs\x12\x0e\n\x06sender\x18\x03 \x01(\t\x12*\n\x10signature_scheme\x18\x04 \x01(\tR\x10signature_scheme\x12\x11\n\tsignature\x18\x05 \x01(\t\x12\x1e\n\npublic_key\x18\x06 \x01(\tR\npublic_key\x12(\n\x0fsequence_number\x18\x07 \x01(\x04R\x0fsequence_number\x12\x1a\n\x08\x63hain_id\x18\x08 \x01(\rR\x08\x63hain_id\x12&\n\x0emax_gas_amount\x18\t \x01(\x04R\x0emax_gas_amount\x12&\n\x0egas_unit_price\x18\n \x01(\x04R\x0egas_unit_price\x12\"\n\x0cgas_currency\x18\x0b \x01(\tR\x0cgas_currency\x12<\n\x19\x65xpiration_timestamp_secs\x18\x0c \x01(\x04R\x19\x65xpiration_timestamp_secs\x12 \n\x0bscript_hash\x18\r \x01(\tR\x0bscript_hash\x12\"\n\x0cscript_bytes\x18\x0e \x01(\tR\x0cscript_bytes\x12\x1f\n\x06script\x18\x0f \x01(\x0b\x32\x0f.jsonrpc.Script\x12,\n\x11secondary_signers\x18\x10 \x03(\tR\x11secondary_signers\x12@\n\x1bsecondary_signature_schemes\x18\x11 \x03(\tR\x1bsecondary_signature_schemes\x12\x32\n\x14secondary_signatures\x18\x12 \x03(\tR\x14secondary_signatures\x12\x34\n\x15secondary_public_keys\x18\x13 \x03(\tR\x15secondary_public_keys\"\xbf\x02\n\x06Script\x12\x0c\n\x04type\x18\x01 \x01(\t\x12\x0c\n\x04\x63ode\x18\x02 \x01(\t\x12\x11\n\targuments\x18\x03 \x03(\t\x12&\n\x0etype_arguments\x18\x04 \x03(\tR\x0etype_arguments\x12\x10\n\x08receiver\x18\x05 \x01(\t\x12\x0e\n\x06\x61mount\x18\x06 \x01(\x04\x12\x10\n\x08\x63urrency\x18\x07 \x01(\t\x12\x10\n\x08metadata\x18\x08 \x01(\t\x12.\n\x12metadata_signature\x18\t \x01(\tR\x12metadata_signature\x12\x16\n\x0emodule_address\x18\n \x01(\t\x12\x13\n\x0bmodule_name\x18\x0b \x01(\t\x12\x15\n\rfunction_name\x18\x0c \x01(\t\x12$\n\rarguments_bcs\x18\r \x03(\tR\rarguments_bcs\"\xa8\x03\n\x0c\x43urrencyInfo\x12\x0c\n\x04\x63ode\x18\x01 \x01(\t\x12&\n\x0escaling_factor\x18\x02 \x01(\x04R\x0escaling_factor\x12(\n\x0f\x66ractional_part\x18\x03 \x01(\x04R\x0f\x66ractional_part\x12\x32\n\x14to_xdx_exchange_rate\x18\x04 \x01(\x02R\x14to_xdx_exchange_rate\x12(\n\x0fmint_events_key\x18\x05 \x01(\tR\x0fmint_events_key\x12(\n\x0f\x62urn_events_key\x18\x06 \x01(\tR\x0f\x62urn_events_key\x12.\n\x12preburn_events_key\x18\x07 \x01(\tR\x12preburn_events_key\x12\x36\n\x16\x63\x61ncel_burn_events_key\x18\x08 \x01(\tR\x16\x63\x61ncel_burn_events_key\x12H\n\x1f\x65xchange_rate_update_events_key\x18\t \x01(\tR\x1f\x65xchange_rate_update_events_key\"\xba\x01\n\nStateProof\x12@\n\x1bledger_info_with_signatures\x18\x01 \x01(\tR\x1bledger_info_with_signatures\x12.\n\x12\x65poch_change_proof\x18\x02 \x01(\tR\x12\x65poch_change_proof\x12:\n\x18ledger_consistency_proof\x18\x03 \x01(\tR\x18ledger_consistency_proof\"a\n\x15\x41\x63\x63ountStateWithProof\x12\x0f\n\x07version\x18\x01 \x01(\x04\x12\x0c\n\x04\x62lob\x18\x02 \x01(\t\x12)\n\x05proof\x18\x03 \x01(\x0b\x32\x1a.jsonrpc.AccountStateProof\"\xe3\x01\n\x11\x41\x63\x63ountStateProof\x12T\n%ledger_info_to_transaction_info_proof\x18\x01 \x01(\tR%ledger_info_to_transaction_info_proof\x12*\n\x10transaction_info\x18\x02 \x01(\tR\x10transaction_info\x12L\n!transaction_info_to_account_proof\x18\x03 \x01(\tR!transaction_info_to_account_proofB4\n\x10org.diem.jsonrpcB\x07JsonRpcZ\x17github.com/diem/jsonrpcb\x06proto3' + serialized_pb=b'\n\rjsonrpc.proto\x12\x07jsonrpc\"*\n\x06\x41mount\x12\x0e\n\x06\x61mount\x18\x01 \x01(\x04\x12\x10\n\x08\x63urrency\x18\x02 \x01(\t\"\xf4\x03\n\x07\x41\x63\x63ount\x12\x0f\n\x07\x61\x64\x64ress\x18\x01 \x01(\t\x12!\n\x08\x62\x61lances\x18\x02 \x03(\x0b\x32\x0f.jsonrpc.Amount\x12(\n\x0fsequence_number\x18\x03 \x01(\x04R\x0fsequence_number\x12.\n\x12\x61uthentication_key\x18\x04 \x01(\tR\x12\x61uthentication_key\x12(\n\x0fsent_events_key\x18\x05 \x01(\tR\x0fsent_events_key\x12\x30\n\x13received_events_key\x18\x06 \x01(\tR\x13received_events_key\x12L\n!delegated_key_rotation_capability\x18\x07 \x01(\x08R!delegated_key_rotation_capability\x12H\n\x1f\x64\x65legated_withdrawal_capability\x18\x08 \x01(\x08R\x1f\x64\x65legated_withdrawal_capability\x12\x32\n\tis_frozen\x18\t \x01(\x08R\x1f\x64\x65legated_withdrawal_capability\x12\"\n\x04role\x18\n \x01(\x0b\x32\x14.jsonrpc.AccountRole\x12\x0f\n\x07version\x18\x0b \x01(\x04\"\xb3\x05\n\x0b\x41\x63\x63ountRole\x12\x0c\n\x04type\x18\x01 \x01(\t\x12\x30\n\x13parent_vasp_address\x18\x02 \x01(\tR\x13parent_vasp_address\x12\x1e\n\nhuman_name\x18\x03 \x01(\tR\nhuman_name\x12\x1a\n\x08\x62\x61se_url\x18\x04 \x01(\tR\x08\x62\x61se_url\x12(\n\x0f\x65xpiration_time\x18\x05 \x01(\x04R\x0f\x65xpiration_time\x12&\n\x0e\x63ompliance_key\x18\x06 \x01(\tR\x0e\x63ompliance_key\x12N\n\"compliance_key_rotation_events_key\x18\x07 \x01(\tR\"compliance_key_rotation_events_key\x12\x42\n\x1c\x62\x61se_url_rotation_events_key\x18\x08 \x01(\tR\x1c\x62\x61se_url_rotation_events_key\x12\"\n\x0cnum_children\x18\t \x01(\x04R\x0cnum_children\x12:\n\x18received_mint_events_key\x18\n \x01(\tR\x18received_mint_events_key\x12;\n\x10preburn_balances\x18\x0b \x03(\x0b\x32\x0f.jsonrpc.AmountR\x10preburn_balances\x12=\n\x0epreburn_queues\x18\x0c \x03(\x0b\x32\x15.jsonrpc.PreburnQueueR\x0epreburn_queues\x12(\n\x0f\x64iem_id_domains\x18\r \x03(\tR\x0f\x64iem_id_domains\x12<\n\x19\x64iem_id_domain_events_key\x18\x0e \x01(\tR\x19\x64iem_id_domain_events_key\"d\n\x0cPreburnQueue\x12\x1a\n\x08\x63urrency\x18\x01 \x01(\tR\x08\x63urrency\x12\x38\n\x08preburns\x18\x02 \x03(\x0b\x32\x1c.jsonrpc.PreburnWithMetadataR\x08preburns\"\\\n\x13PreburnWithMetadata\x12)\n\x07preburn\x18\x01 \x01(\x0b\x32\x0f.jsonrpc.AmountR\x07preburn\x12\x1a\n\x08metadata\x18\x02 \x01(\tR\x08metadata\"\x92\x01\n\x05\x45vent\x12\x0b\n\x03key\x18\x01 \x01(\t\x12(\n\x0fsequence_number\x18\x02 \x01(\x04R\x0fsequence_number\x12\x30\n\x13transaction_version\x18\x03 \x01(\x04R\x13transaction_version\x12 \n\x04\x64\x61ta\x18\x04 \x01(\x0b\x32\x12.jsonrpc.EventData\"\xf3\x05\n\tEventData\x12\x0c\n\x04type\x18\x01 \x01(\t\x12\x1f\n\x06\x61mount\x18\x02 \x01(\x0b\x32\x0f.jsonrpc.Amount\x12(\n\x0fpreburn_address\x18\x03 \x01(\tR\x0fpreburn_address\x12$\n\rcurrency_code\x18\x04 \x01(\tR\rcurrency_code\x12:\n\x18new_to_xdx_exchange_rate\x18\x05 \x01(\x02R\x18new_to_xdx_exchange_rate\x12\x0e\n\x06sender\x18\x06 \x01(\t\x12\x10\n\x08receiver\x18\x07 \x01(\t\x12\x10\n\x08metadata\x18\x08 \x01(\t\x12\r\n\x05\x65poch\x18\n \x01(\x04\x12\r\n\x05round\x18\x0b \x01(\x04\x12\x10\n\x08proposer\x18\x0c \x01(\t\x12$\n\rproposed_time\x18\r \x01(\x04R\rproposed_time\x12\x30\n\x13\x64\x65stination_address\x18\x0e \x01(\tR\x13\x64\x65stination_address\x12<\n\x19new_compliance_public_key\x18\x0f \x01(\tR\x19new_compliance_public_key\x12\"\n\x0cnew_base_url\x18\x10 \x01(\tR\x0cnew_base_url\x12\x32\n\x14time_rotated_seconds\x18\x11 \x01(\x04R\x14time_rotated_seconds\x12(\n\x0f\x63reated_address\x18\x12 \x01(\tR\x0f\x63reated_address\x12\x18\n\x07role_id\x18\x13 \x01(\x04R\x07role_id\x12:\n\x18\x63ommitted_timestamp_secs\x18\x14 \x01(\x04R\x18\x63ommitted_timestamp_secs\x12\r\n\x05\x62ytes\x18\x15 \x01(\t\x12\x18\n\x07removed\x18\x16 \x01(\x08R\x07removed\x12\x16\n\x06\x64omain\x18\x17 \x01(\tR\x06\x64omain\x12\x18\n\x07\x61\x64\x64ress\x18\x18 \x01(\tR\x07\x61\x64\x64ress\"\xd2\x02\n\x08Metadata\x12\x0f\n\x07version\x18\x01 \x01(\x04\x12\x11\n\ttimestamp\x18\x02 \x01(\x04\x12\x1a\n\x08\x63hain_id\x18\x03 \x01(\rR\x08\x63hain_id\x12\x36\n\x16script_hash_allow_list\x18\x04 \x03(\tR\x16script_hash_allow_list\x12<\n\x19module_publishing_allowed\x18\x05 \x01(\x08R\x19module_publishing_allowed\x12\"\n\x0c\x64iem_version\x18\x06 \x01(\x04R\x0c\x64iem_version\x12\x34\n\x15\x61\x63\x63umulator_root_hash\x18\x07 \x01(\tR\x15\x61\x63\x63umulator_root_hash\x12\x36\n\x16\x64ual_attestation_limit\x18\x08 \x01(\x04R\x16\x64ual_attestation_limit\"\xd7\x01\n\x0bTransaction\x12\x0f\n\x07version\x18\x01 \x01(\x04\x12-\n\x0btransaction\x18\x02 \x01(\x0b\x32\x18.jsonrpc.TransactionData\x12\x0c\n\x04hash\x18\x03 \x01(\t\x12\r\n\x05\x62ytes\x18\x04 \x01(\t\x12\x1e\n\x06\x65vents\x18\x05 \x03(\x0b\x32\x0e.jsonrpc.Event\x12/\n\tvm_status\x18\x06 \x01(\x0b\x32\x11.jsonrpc.VMStatusR\tvm_status\x12\x1a\n\x08gas_used\x18\x07 \x01(\x04R\x08gas_used\"\x9d\x01\n\x15MoveAbortExplaination\x12\x10\n\x08\x63\x61tegory\x18\x01 \x01(\t\x12\x32\n\x14\x63\x61tegory_description\x18\x02 \x01(\tR\x14\x63\x61tegory_description\x12\x0e\n\x06reason\x18\x03 \x01(\t\x12.\n\x12reason_description\x18\x04 \x01(\tR\x12reason_description\"\xc9\x01\n\x08VMStatus\x12\x0c\n\x04type\x18\x01 \x01(\t\x12\x10\n\x08location\x18\x02 \x01(\t\x12\x1e\n\nabort_code\x18\x03 \x01(\x04R\nabort_code\x12&\n\x0e\x66unction_index\x18\x04 \x01(\rR\x0e\x66unction_index\x12 \n\x0b\x63ode_offset\x18\x05 \x01(\rR\x0b\x63ode_offset\x12\x33\n\x0b\x65xplanation\x18\x06 \x01(\x0b\x32\x1e.jsonrpc.MoveAbortExplaination\"\xf1\x05\n\x0fTransactionData\x12\x0c\n\x04type\x18\x01 \x01(\t\x12(\n\x0ftimestamp_usecs\x18\x02 \x01(\x04R\x0ftimestamp_usecs\x12\x0e\n\x06sender\x18\x03 \x01(\t\x12*\n\x10signature_scheme\x18\x04 \x01(\tR\x10signature_scheme\x12\x11\n\tsignature\x18\x05 \x01(\t\x12\x1e\n\npublic_key\x18\x06 \x01(\tR\npublic_key\x12(\n\x0fsequence_number\x18\x07 \x01(\x04R\x0fsequence_number\x12\x1a\n\x08\x63hain_id\x18\x08 \x01(\rR\x08\x63hain_id\x12&\n\x0emax_gas_amount\x18\t \x01(\x04R\x0emax_gas_amount\x12&\n\x0egas_unit_price\x18\n \x01(\x04R\x0egas_unit_price\x12\"\n\x0cgas_currency\x18\x0b \x01(\tR\x0cgas_currency\x12<\n\x19\x65xpiration_timestamp_secs\x18\x0c \x01(\x04R\x19\x65xpiration_timestamp_secs\x12 \n\x0bscript_hash\x18\r \x01(\tR\x0bscript_hash\x12\"\n\x0cscript_bytes\x18\x0e \x01(\tR\x0cscript_bytes\x12\x1f\n\x06script\x18\x0f \x01(\x0b\x32\x0f.jsonrpc.Script\x12,\n\x11secondary_signers\x18\x10 \x03(\tR\x11secondary_signers\x12@\n\x1bsecondary_signature_schemes\x18\x11 \x03(\tR\x1bsecondary_signature_schemes\x12\x32\n\x14secondary_signatures\x18\x12 \x03(\tR\x14secondary_signatures\x12\x34\n\x15secondary_public_keys\x18\x13 \x03(\tR\x15secondary_public_keys\"\xbf\x02\n\x06Script\x12\x0c\n\x04type\x18\x01 \x01(\t\x12\x0c\n\x04\x63ode\x18\x02 \x01(\t\x12\x11\n\targuments\x18\x03 \x03(\t\x12&\n\x0etype_arguments\x18\x04 \x03(\tR\x0etype_arguments\x12\x10\n\x08receiver\x18\x05 \x01(\t\x12\x0e\n\x06\x61mount\x18\x06 \x01(\x04\x12\x10\n\x08\x63urrency\x18\x07 \x01(\t\x12\x10\n\x08metadata\x18\x08 \x01(\t\x12.\n\x12metadata_signature\x18\t \x01(\tR\x12metadata_signature\x12\x16\n\x0emodule_address\x18\n \x01(\t\x12\x13\n\x0bmodule_name\x18\x0b \x01(\t\x12\x15\n\rfunction_name\x18\x0c \x01(\t\x12$\n\rarguments_bcs\x18\r \x03(\tR\rarguments_bcs\"\xa8\x03\n\x0c\x43urrencyInfo\x12\x0c\n\x04\x63ode\x18\x01 \x01(\t\x12&\n\x0escaling_factor\x18\x02 \x01(\x04R\x0escaling_factor\x12(\n\x0f\x66ractional_part\x18\x03 \x01(\x04R\x0f\x66ractional_part\x12\x32\n\x14to_xdx_exchange_rate\x18\x04 \x01(\x02R\x14to_xdx_exchange_rate\x12(\n\x0fmint_events_key\x18\x05 \x01(\tR\x0fmint_events_key\x12(\n\x0f\x62urn_events_key\x18\x06 \x01(\tR\x0f\x62urn_events_key\x12.\n\x12preburn_events_key\x18\x07 \x01(\tR\x12preburn_events_key\x12\x36\n\x16\x63\x61ncel_burn_events_key\x18\x08 \x01(\tR\x16\x63\x61ncel_burn_events_key\x12H\n\x1f\x65xchange_rate_update_events_key\x18\t \x01(\tR\x1f\x65xchange_rate_update_events_key\"\xba\x01\n\nStateProof\x12@\n\x1bledger_info_with_signatures\x18\x01 \x01(\tR\x1bledger_info_with_signatures\x12.\n\x12\x65poch_change_proof\x18\x02 \x01(\tR\x12\x65poch_change_proof\x12:\n\x18ledger_consistency_proof\x18\x03 \x01(\tR\x18ledger_consistency_proof\"a\n\x15\x41\x63\x63ountStateWithProof\x12\x0f\n\x07version\x18\x01 \x01(\x04\x12\x0c\n\x04\x62lob\x18\x02 \x01(\t\x12)\n\x05proof\x18\x03 \x01(\x0b\x32\x1a.jsonrpc.AccountStateProof\"\xe3\x01\n\x11\x41\x63\x63ountStateProof\x12T\n%ledger_info_to_transaction_info_proof\x18\x01 \x01(\tR%ledger_info_to_transaction_info_proof\x12*\n\x10transaction_info\x18\x02 \x01(\tR\x10transaction_info\x12L\n!transaction_info_to_account_proof\x18\x03 \x01(\tR!transaction_info_to_account_proof\"Y\n\x1b\x41\x63\x63umulatorConsistencyProof\x12:\n\x18ledger_consistency_proof\x18\x01 \x01(\tR\x18ledger_consistency_proofB4\n\x10org.diem.jsonrpcB\x07JsonRpcZ\x17github.com/diem/jsonrpcb\x06proto3' ) @@ -1380,6 +1380,38 @@ serialized_end=5314, ) + +_ACCUMULATORCONSISTENCYPROOF = _descriptor.Descriptor( + name='AccumulatorConsistencyProof', + full_name='jsonrpc.AccumulatorConsistencyProof', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='ledger_consistency_proof', full_name='jsonrpc.AccumulatorConsistencyProof.ledger_consistency_proof', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, json_name='ledger_consistency_proof', file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=5316, + serialized_end=5405, +) + _ACCOUNT.fields_by_name['balances'].message_type = _AMOUNT _ACCOUNT.fields_by_name['role'].message_type = _ACCOUNTROLE _ACCOUNTROLE.fields_by_name['preburn_balances'].message_type = _AMOUNT @@ -1411,6 +1443,7 @@ DESCRIPTOR.message_types_by_name['StateProof'] = _STATEPROOF DESCRIPTOR.message_types_by_name['AccountStateWithProof'] = _ACCOUNTSTATEWITHPROOF DESCRIPTOR.message_types_by_name['AccountStateProof'] = _ACCOUNTSTATEPROOF +DESCRIPTOR.message_types_by_name['AccumulatorConsistencyProof'] = _ACCUMULATORCONSISTENCYPROOF _sym_db.RegisterFileDescriptor(DESCRIPTOR) Amount = _reflection.GeneratedProtocolMessageType('Amount', (_message.Message,), { @@ -1532,6 +1565,13 @@ }) _sym_db.RegisterMessage(AccountStateProof) +AccumulatorConsistencyProof = _reflection.GeneratedProtocolMessageType('AccumulatorConsistencyProof', (_message.Message,), { + 'DESCRIPTOR' : _ACCUMULATORCONSISTENCYPROOF, + '__module__' : 'jsonrpc_pb2' + # @@protoc_insertion_point(class_scope:jsonrpc.AccumulatorConsistencyProof) + }) +_sym_db.RegisterMessage(AccumulatorConsistencyProof) + DESCRIPTOR._options = None # @@protoc_insertion_point(module_scope) diff --git a/src/diem/jsonrpc/jsonrpc_pb2.pyi b/src/diem/jsonrpc/jsonrpc_pb2.pyi index 788d2fdd..accf4c57 100644 --- a/src/diem/jsonrpc/jsonrpc_pb2.pyi +++ b/src/diem/jsonrpc/jsonrpc_pb2.pyi @@ -812,3 +812,17 @@ class AccountStateProof(google___protobuf___message___Message): ) -> None: ... type___AccountStateProof = AccountStateProof + +class AccumulatorConsistencyProof(google___protobuf___message___Message): + DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... + ledger_consistency_proof: typing___Text = ... + def __init__( + self, + *, + ledger_consistency_proof: typing___Optional[typing___Text] = None, + ) -> None: ... + def ClearField( + self, field_name: typing_extensions___Literal["ledger_consistency_proof", b"ledger_consistency_proof"] + ) -> None: ... + +type___AccumulatorConsistencyProof = AccumulatorConsistencyProof diff --git a/src/diem/testing/miniwallet/app/app.py b/src/diem/testing/miniwallet/app/app.py index 1e8a9008..7eb7682a 100644 --- a/src/diem/testing/miniwallet/app/app.py +++ b/src/diem/testing/miniwallet/app/app.py @@ -17,12 +17,12 @@ class App: def __init__( - self, - account: LocalAccount, - child_accounts: List[LocalAccount], - client: jsonrpc.Client, - name: str, - logger: logging.Logger, + self, + account: LocalAccount, + child_accounts: List[LocalAccount], + client: jsonrpc.Client, + name: str, + logger: logging.Logger, ) -> None: self.logger = logger self.diem_account = DiemAccount(account, child_accounts, client) @@ -115,6 +115,8 @@ def txn_metadata(self, txn: Transaction) -> Tuple[bytes, bytes]: return self.diem_account.refund_metadata(txn.refund_diem_txn_version, txn.refund_reason) # pyre-ignore if txn.subaddress_hex: return self.diem_account.general_metadata(txn.subaddress(), str(txn.payee)) + if txn.reference_id is not None: + return self.diem_account.payment_metadata(str(txn.reference_id)) elif txn.reference_id: cmd = self.store.find(PaymentCommand, reference_id=txn.reference_id) return self.diem_account.travel_metadata(cmd.to_offchain_command()) @@ -178,13 +180,13 @@ def _start_external_payment_txn(self, txn: Transaction) -> None: self.dual_attestation_txn_senders["v2"](txn) def _create_transaction( - self, - account_id: str, - status: str, - data: JsonInput, - type: Transaction.Type, - payee: Optional[str] = None, - subaddress_hex: Optional[str] = None, + self, + account_id: str, + status: str, + data: JsonInput, + type: Transaction.Type, + payee: Optional[str] = None, + subaddress_hex: Optional[str] = None, ) -> Transaction: return self.store.create( Transaction, diff --git a/src/diem/testing/miniwallet/app/event_puller.py b/src/diem/testing/miniwallet/app/event_puller.py index 2e3056ea..14d4b74f 100644 --- a/src/diem/testing/miniwallet/app/event_puller.py +++ b/src/diem/testing/miniwallet/app/event_puller.py @@ -26,6 +26,8 @@ def process(self) -> None: for event in self.pull_events(): if event.data.type == jsonrpc.EVENT_DATA_RECEIVED_PAYMENT: self.save_payment_txn(event) + # elif event.data.type == jsonrpc.EVENT_DATA_DIEM_ID_DOMAIN: + # self.update_diem_id_domains(event) def head(self) -> None: state = None @@ -123,3 +125,22 @@ def _create_txn(self, account_id: str, event: jsonrpc.Event, **kwargs: Any) -> N type=Transaction.Type.received_payment, **kwargs, ) + + # def update_diem_id_domains(self, event: jsonrpc.Event) -> None: + # self.logger.info("processing Event:\n%s", event) + # domain = event.data.domain + # removed = event.data.removed + # address = event.data.address + # if removed: + # try: + # diem_id_domain = self.store.find(DiemId, domain=domain) + # if diem_id_domain.account_address == address: + # self.store.remove(diem_id_domain) + # except NotFoundError: + # self.logger.exception("Diem ID domain not found, could not remove domain from storage") + # else: + # try: + # diem_id_domain = self.store.find(DiemId, domain=domain) + # self.store.update(diem_id_domain, account_address=domain) + # except NotFoundError: + # self.store.create(DiemId, domain=domain, account_address=address) diff --git a/src/diem/testing/miniwallet/app/models.py b/src/diem/testing/miniwallet/app/models.py index 34e30bb1..240278d4 100644 --- a/src/diem/testing/miniwallet/app/models.py +++ b/src/diem/testing/miniwallet/app/models.py @@ -131,7 +131,7 @@ def to_offchain_command(self) -> offchain.PaymentCommand: ) -@dataclass -class DiemId(Base): - domain: str - account_address: str +# @dataclass +# class DiemId(Base): +# domain: str +# account_address: str diff --git a/src/diem/testing/miniwallet/app/store.py b/src/diem/testing/miniwallet/app/store.py index 6bde4dbe..020438a3 100644 --- a/src/diem/testing/miniwallet/app/store.py +++ b/src/diem/testing/miniwallet/app/store.py @@ -3,7 +3,7 @@ from dataclasses import dataclass, field, asdict from typing import List, Dict, Type, Any, Callable, TypeVar, Generator -from .models import Base, Account, Event, DiemId +from .models import Base, Account, Event from .... import utils import json, time, threading @@ -61,18 +61,10 @@ def update(self, obj: T, before_update: Callable[[T], None] = lambda _: _, **dat self._update(obj) self._record_event(obj, "updated", data) - def remove(self, obj: T, before_remove: Callable[[T], None] = lambda _: _, **data: Any) -> None: - with self.resources_lock: - before_remove(obj) - self._remove(obj) - self._record_event(obj, "removed", data) - def _record_event(self, obj: T, action: str, data: Dict[str, Any]) -> None: if not isinstance(obj, Event): type = "%s_%s" % (action, utils.to_snake(obj)) - account_id = ( - obj.id if isinstance(obj, Account) or isinstance(obj, DiemId) else obj.account_id - ) # pyre-ignore + account_id = obj.id if isinstance(obj, Account) else obj.account_id # pyre-ignore data["id"] = obj.id self._insert(Event, account_id=account_id, type=type, data=json.dumps(data), timestamp=_ts()) @@ -89,13 +81,6 @@ def _insert(self, typ: Type[T], **res: Any) -> Dict[str, Any]: self.resources.setdefault(typ, []).append(asdict(typ(**res))) return res - def _remove(self, obj: T) -> None: - records = self.resources.get(type(obj), []) - index = next(iter([i for i, res in enumerate(records) if res["id"] == obj.id]), None) - if index is None: - raise NotFoundError("could not find resource by id: %s" % obj.id) - del records[index] - def _select(self, typ: Type[T], reverse: bool = False, **conds: Any) -> Generator[T, None, None]: items = reversed(self.resources.get(typ, [])) if reverse else self.resources.get(typ, []) for res in items: diff --git a/src/diem/testing/miniwallet/config.py b/src/diem/testing/miniwallet/config.py index e9029c1e..197c4231 100644 --- a/src/diem/testing/miniwallet/config.py +++ b/src/diem/testing/miniwallet/config.py @@ -56,12 +56,28 @@ def create_client(self) -> RestClient: def setup_account(self, client: jsonrpc.Client) -> None: self.logger.info("faucet: mint %s", self.account.account_address.to_hex()) faucet = testnet.Faucet(client) - faucet.mint( - self.account.auth_key.hex(), - self.initial_amount, - self.initial_currency, - diem_id_domain=self.diem_id_domain, - ) + + if client.get_account(self.account.account_address) is not None: + if self.diem_id_domain in client.get_account(self.account.account_address).role.diem_id_domains: + faucet.mint( + self.account.auth_key.hex(), + self.initial_amount, + self.initial_currency, + ) + else: + faucet.mint( + self.account.auth_key.hex(), + self.initial_amount, + self.initial_currency, + diem_id_domain=self.diem_id_domain, + ) + else: + faucet.mint( + self.account.auth_key.hex(), + self.initial_amount, + self.initial_currency, + diem_id_domain=self.diem_id_domain, + ) self.logger.info("rotate dual attestation info for %s", self.account.account_address.to_hex()) self.logger.info("set base url to: %s", self.server_url) diff --git a/src/diem/testnet.py b/src/diem/testnet.py index 2082bece..a8ef39c2 100644 --- a/src/diem/testnet.py +++ b/src/diem/testnet.py @@ -98,6 +98,13 @@ def mint( diem_id_domain: typing.Optional[str] = None, is_remove_domain: bool = False, ) -> None: + # print("===========mint here", diem_id_domain, is_remove_domain) + # if self._client.get_vasp_address_with_domain(diem_id_domain) is not None: + # print( + # "domain already added============================", + # self._client.get_vasp_address_with_domain(diem_id_domain), + # ) + # diem_id_domain = None self._retry.execute( lambda: self._mint_without_retry( authkey, amount, currency_code, dd_account, diem_id_domain, is_remove_domain diff --git a/src/diem/utils.py b/src/diem/utils.py index 351f0dbc..bdc7cf68 100644 --- a/src/diem/utils.py +++ b/src/diem/utils.py @@ -207,3 +207,7 @@ def wait_for_port(port: int, host: str = "localhost", timeout: float = 5.0) -> N if time.perf_counter() - start_time >= timeout: raise TimeoutError("waited %s for %s:%s accept connection." % (timeout, host, port)) from e time.sleep(0.01) + + +def get_treasury_compliance_address() -> diem_types.AccountAddress: + return account_address(TREASURY_ADDRESS) diff --git a/tests/test_testing_cli.py b/tests/test_testing_cli.py index d4976902..11429854 100644 --- a/tests/test_testing_cli.py +++ b/tests/test_testing_cli.py @@ -202,59 +202,34 @@ def test_wait_timeout_for_target_ready(runner: CliRunner) -> None: assert duration < 2 -# def test_cli_init_with_diem_id_domain(runner: CliRunner) -> None: -# app_config_file = "app.json" -# stub_config_file = "stub.json" -# with runner.isolated_filesystem(): -# LocalAccount().write_to_file(app_config_file) -# LocalAccount().write_to_file(stub_config_file) -# -# conf = start_target_server(runner, ["-i", app_config_file, "--diem-id-domain", "targetdomain"]) -# result = start_test( -# runner, -# conf, -# [ -# "-i", -# stub_config_file, -# "-k", -# "test_create_a_blank_account", -# "--stub-diem-id-domain", -# "stubdomain", -# ], -# ) -# -# assert result.exit_code == 0, result.output - - -# def test_vasp_has_domain(stub_client: RestClient, target_client: RestClient, hrp: str) -> None: -# """ -# Test Plan: -# -# 1. Generate a valid account identifier from receiver account as payee. -# 2. Send a payment to the account identifier. -# 3. Wait for the transaction executed successfully. -# 4. Assert receiver account received the fund. -# -# """ -# -# sender_account = stub_client.create_account() -# receiver_account = target_client.create_account() -# account = target_client.create_account() -# account_identifier = account.generate_account_identifier() -# account_address, _ = identifier.decode_account(account_identifier, hrp) -# assert account_address -# -# client = testnet.create_client() -# account = client.get_account(account_address) - -# try: -# payee = receiver_account.generate_account_identifier() -# pay = sender_account.send_payment(currency=currency, amount=amount, payee=payee) -# wait_for_payment_transaction_complete(sender_account, pay.id) -# wait_for_balance(receiver_account, currency, amount) -# finally: -# receiver_account.log_events() -# sender_account.log_events() +def test_cli_init_with_diem_id_domain(runner: CliRunner) -> None: + app_config_file = "app.json" + stub_config_file = "stub.json" + with runner.isolated_filesystem(): + target_account = LocalAccount() + stub_account = LocalAccount() + target_account.write_to_file(app_config_file) + stub_account.write_to_file(stub_config_file) + + conf = start_target_server(runner, ["-i", app_config_file, "--diem-id-domain", "targetdomain"]) + result = start_test( + runner, + conf, + [ + "-i", + stub_config_file, + "-k", + "test_create_a_blank_account", + "--stub-diem-id-domain", + "stubdomain", + ], + ) + + client = testnet.create_client() + assert client.get_diem_id_domain_map().get("targetdomain") == target_account.account_address.to_hex() + assert client.get_diem_id_domain_map().get("stubdomain") == stub_account.account_address.to_hex() + + assert result.exit_code == 0, result.output def start_test(runner: CliRunner, conf: ServerConfig, options: List[str] = []) -> Result: From 5f39a9e89fa63facaba8abea8879130dc5ee2ba6 Mon Sep 17 00:00:00 2001 From: SunMi Lee Date: Fri, 11 Jun 2021 02:28:05 -0700 Subject: [PATCH 4/7] Remove storage logic --- src/diem/jsonrpc/client.py | 4 ++-- .../testing/miniwallet/app/event_puller.py | 21 ------------------- src/diem/testing/miniwallet/app/models.py | 6 ------ src/diem/testing/miniwallet/config.py | 6 +++--- src/diem/testnet.py | 7 ------- 5 files changed, 5 insertions(+), 39 deletions(-) diff --git a/src/diem/jsonrpc/client.py b/src/diem/jsonrpc/client.py index 817e6cea..090d9adb 100644 --- a/src/diem/jsonrpc/client.py +++ b/src/diem/jsonrpc/client.py @@ -417,7 +417,7 @@ def get_diem_id_domain_map(self) -> typing.Dict[str, str]: domain_map = {} event_index = 0 batch_size = 100 - tc_account = self.get_account(utils.get_treasury_compliance_address()) + tc_account = self.must_get_account(utils.get_treasury_compliance_address()) event_stream_key = tc_account.role.diem_id_domain_events_key while True: events = self.get_events(event_stream_key, event_index, batch_size) @@ -426,7 +426,7 @@ def get_diem_id_domain_map(self) -> typing.Dict[str, str]: del domain_map[event.data.domain] else: domain_map[event.data.domain] = event.data.address - if events.count() < batch_size: + if len(events) < batch_size: break event_index += batch_size return domain_map diff --git a/src/diem/testing/miniwallet/app/event_puller.py b/src/diem/testing/miniwallet/app/event_puller.py index 14d4b74f..2e3056ea 100644 --- a/src/diem/testing/miniwallet/app/event_puller.py +++ b/src/diem/testing/miniwallet/app/event_puller.py @@ -26,8 +26,6 @@ def process(self) -> None: for event in self.pull_events(): if event.data.type == jsonrpc.EVENT_DATA_RECEIVED_PAYMENT: self.save_payment_txn(event) - # elif event.data.type == jsonrpc.EVENT_DATA_DIEM_ID_DOMAIN: - # self.update_diem_id_domains(event) def head(self) -> None: state = None @@ -125,22 +123,3 @@ def _create_txn(self, account_id: str, event: jsonrpc.Event, **kwargs: Any) -> N type=Transaction.Type.received_payment, **kwargs, ) - - # def update_diem_id_domains(self, event: jsonrpc.Event) -> None: - # self.logger.info("processing Event:\n%s", event) - # domain = event.data.domain - # removed = event.data.removed - # address = event.data.address - # if removed: - # try: - # diem_id_domain = self.store.find(DiemId, domain=domain) - # if diem_id_domain.account_address == address: - # self.store.remove(diem_id_domain) - # except NotFoundError: - # self.logger.exception("Diem ID domain not found, could not remove domain from storage") - # else: - # try: - # diem_id_domain = self.store.find(DiemId, domain=domain) - # self.store.update(diem_id_domain, account_address=domain) - # except NotFoundError: - # self.store.create(DiemId, domain=domain, account_address=address) diff --git a/src/diem/testing/miniwallet/app/models.py b/src/diem/testing/miniwallet/app/models.py index 240278d4..c6a25791 100644 --- a/src/diem/testing/miniwallet/app/models.py +++ b/src/diem/testing/miniwallet/app/models.py @@ -129,9 +129,3 @@ def to_offchain_command(self) -> offchain.PaymentCommand: inbound=self.is_inbound, cid=self.cid, ) - - -# @dataclass -# class DiemId(Base): -# domain: str -# account_address: str diff --git a/src/diem/testing/miniwallet/config.py b/src/diem/testing/miniwallet/config.py index 197c4231..c15f4c6e 100644 --- a/src/diem/testing/miniwallet/config.py +++ b/src/diem/testing/miniwallet/config.py @@ -56,9 +56,9 @@ def create_client(self) -> RestClient: def setup_account(self, client: jsonrpc.Client) -> None: self.logger.info("faucet: mint %s", self.account.account_address.to_hex()) faucet = testnet.Faucet(client) - - if client.get_account(self.account.account_address) is not None: - if self.diem_id_domain in client.get_account(self.account.account_address).role.diem_id_domains: + account = client.get_account(self.account.account_address) + if account is not None: + if self.diem_id_domain in account.role.diem_id_domains: faucet.mint( self.account.auth_key.hex(), self.initial_amount, diff --git a/src/diem/testnet.py b/src/diem/testnet.py index a8ef39c2..2082bece 100644 --- a/src/diem/testnet.py +++ b/src/diem/testnet.py @@ -98,13 +98,6 @@ def mint( diem_id_domain: typing.Optional[str] = None, is_remove_domain: bool = False, ) -> None: - # print("===========mint here", diem_id_domain, is_remove_domain) - # if self._client.get_vasp_address_with_domain(diem_id_domain) is not None: - # print( - # "domain already added============================", - # self._client.get_vasp_address_with_domain(diem_id_domain), - # ) - # diem_id_domain = None self._retry.execute( lambda: self._mint_without_retry( authkey, amount, currency_code, dd_account, diem_id_domain, is_remove_domain From 2b0f2b3cb9283a106f9442d01a9a48994e37b4cb Mon Sep 17 00:00:00 2001 From: SunMi Lee Date: Fri, 11 Jun 2021 17:00:37 -0700 Subject: [PATCH 5/7] Handle faucet domain error --- mini-wallet.md | 2 +- src/diem/jsonrpc/client.py | 9 ++------- src/diem/testing/miniwallet/config.py | 23 ++--------------------- src/diem/testing/suites/conftest.py | 6 ++++-- src/diem/testnet.py | 9 ++++++++- src/diem/utils.py | 4 ---- tests/miniwallet/conftest.py | 9 +++++---- tests/test_testing_cli.py | 5 ----- 8 files changed, 22 insertions(+), 45 deletions(-) diff --git a/mini-wallet.md b/mini-wallet.md index ee62db65..39fc5aa9 100644 --- a/mini-wallet.md +++ b/mini-wallet.md @@ -186,7 +186,7 @@ Use the MiniWallet Test Suite to automate testing and checking if your wallet ap `diem.testing.suites` package includes a `conftest.py`, which will be loaded by pytest for setting up test fixtures. -A package scope fixture in the `conftest.py` starts a MiniWallet application named `stubwallet` as a counterparty service for testing payment with the target server specified by the `--target` option here. +A package scope fixture in the `conftest.py` starts a MiniWallet application named `stub-wallet` as a counterparty service for testing payment with the target server specified by the `--target` option here. ### Work with a local testnet diff --git a/src/diem/jsonrpc/client.py b/src/diem/jsonrpc/client.py index 090d9adb..b821657b 100644 --- a/src/diem/jsonrpc/client.py +++ b/src/diem/jsonrpc/client.py @@ -413,11 +413,10 @@ def get_account_state_with_proof( params = [address, version, ledger_version] return self.execute("get_account_state_with_proof", params, _parse_obj(lambda: rpc.AccountStateWithProof())) - def get_diem_id_domain_map(self) -> typing.Dict[str, str]: + def get_diem_id_domain_map(self, batch_size: int = 100) -> typing.Dict[str, str]: domain_map = {} event_index = 0 - batch_size = 100 - tc_account = self.must_get_account(utils.get_treasury_compliance_address()) + tc_account = self.must_get_account(utils.account_address(utils.TREASURY_ADDRESS)) event_stream_key = tc_account.role.diem_id_domain_events_key while True: events = self.get_events(event_stream_key, event_index, batch_size) @@ -431,10 +430,6 @@ def get_diem_id_domain_map(self) -> typing.Dict[str, str]: event_index += batch_size return domain_map - def get_vasp_address_with_domain(self, domain: str) -> typing.Optional[str]: - domain_map = self.get_diem_id_domain_map() - return domain_map.get(domain) - def submit( self, txn: typing.Union[diem_types.SignedTransaction, str], diff --git a/src/diem/testing/miniwallet/config.py b/src/diem/testing/miniwallet/config.py index c15f4c6e..c296209f 100644 --- a/src/diem/testing/miniwallet/config.py +++ b/src/diem/testing/miniwallet/config.py @@ -57,27 +57,8 @@ def setup_account(self, client: jsonrpc.Client) -> None: self.logger.info("faucet: mint %s", self.account.account_address.to_hex()) faucet = testnet.Faucet(client) account = client.get_account(self.account.account_address) - if account is not None: - if self.diem_id_domain in account.role.diem_id_domains: - faucet.mint( - self.account.auth_key.hex(), - self.initial_amount, - self.initial_currency, - ) - else: - faucet.mint( - self.account.auth_key.hex(), - self.initial_amount, - self.initial_currency, - diem_id_domain=self.diem_id_domain, - ) - else: - faucet.mint( - self.account.auth_key.hex(), - self.initial_amount, - self.initial_currency, - diem_id_domain=self.diem_id_domain, - ) + domain = None if account and self.diem_id_domain in account.role.diem_id_domains else self.diem_id_domain + faucet.mint(self.account.auth_key.hex(), self.initial_amount, self.initial_currency, diem_id_domain=domain) self.logger.info("rotate dual attestation info for %s", self.account.account_address.to_hex()) self.logger.info("set base url to: %s", self.server_url) diff --git a/src/diem/testing/suites/conftest.py b/src/diem/testing/suites/conftest.py index 9e06e12e..1e7cbf07 100644 --- a/src/diem/testing/suites/conftest.py +++ b/src/diem/testing/suites/conftest.py @@ -17,12 +17,14 @@ from typing import Optional, Tuple, Dict, Any, Generator, Callable from dataclasses import asdict import pytest, json, uuid, requests, time, warnings +import secrets @pytest.fixture(scope="package") def target_client(diem_client: jsonrpc.Client) -> RestClient: + domain = "target" + secrets.token_hex(8) if is_self_check(): - conf = AppConfig(name="target-wallet", diem_id_domain="targetdomain") + conf = AppConfig(name="target-wallet", diem_id_domain=domain) print("self-checking, launch target app with config %s" % conf) conf.start(diem_client) return conf.create_client() @@ -50,7 +52,7 @@ def stub_wallet_app(start_stub_wallet: Tuple[AppConfig, App]) -> App: @pytest.fixture(scope="package") def start_stub_wallet(diem_client: jsonrpc.Client) -> Tuple[AppConfig, App]: conf = AppConfig( - name="stubwallet", server_conf=ServerConfig(**dmw_stub_server()), diem_id_domain=dmw_stub_diem_id_domain() + name="stub-wallet", server_conf=ServerConfig(**dmw_stub_server()), diem_id_domain=dmw_stub_diem_id_domain() ) account_conf = dmw_stub_diem_account_config() if account_conf: diff --git a/src/diem/testnet.py b/src/diem/testnet.py index 2082bece..40689e3a 100644 --- a/src/diem/testnet.py +++ b/src/diem/testnet.py @@ -132,4 +132,11 @@ def _mint_without_retry( for i in range(length): txn = de.deserialize_any(diem_types.SignedTransaction) - self._client.wait_for_transaction(txn) + try: + self._client.wait_for_transaction(txn) + except jsonrpc.TransactionExecutionFailed as e: + if txn.vm_status.explanation.reason == "EDOMAIN_ALREADY_EXISTS": + continue + raise e + except Exception as e: + raise e diff --git a/src/diem/utils.py b/src/diem/utils.py index bdc7cf68..351f0dbc 100644 --- a/src/diem/utils.py +++ b/src/diem/utils.py @@ -207,7 +207,3 @@ def wait_for_port(port: int, host: str = "localhost", timeout: float = 5.0) -> N if time.perf_counter() - start_time >= timeout: raise TimeoutError("waited %s for %s:%s accept connection." % (timeout, host, port)) from e time.sleep(0.01) - - -def get_treasury_compliance_address() -> diem_types.AccountAddress: - return account_address(TREASURY_ADDRESS) diff --git a/tests/miniwallet/conftest.py b/tests/miniwallet/conftest.py index 8b4ed3fd..246a53a1 100644 --- a/tests/miniwallet/conftest.py +++ b/tests/miniwallet/conftest.py @@ -1,6 +1,6 @@ # Copyright (c) The Diem Core Contributors # SPDX-License-Identifier: Apache-2.0 - +import secrets from diem import jsonrpc, testnet from diem.testing.miniwallet import RestClient, AppConfig @@ -9,12 +9,12 @@ @pytest.fixture(scope="package") def target_client(diem_client: jsonrpc.Client) -> RestClient: - return start_app(diem_client, "targetwallet").create_client() + return start_app(diem_client, "target-wallet").create_client() @pytest.fixture(scope="package") def stub_client(diem_client: jsonrpc.Client) -> RestClient: - return start_app(diem_client, "stubwallet").create_client() + return start_app(diem_client, "stub-wallet").create_client() @pytest.fixture(scope="package") @@ -38,7 +38,8 @@ def travel_rule_threshold(diem_client: jsonrpc.Client) -> int: def start_app(diem_client: jsonrpc.Client, app_name: str) -> AppConfig: - conf = AppConfig(name=app_name, diem_id_domain=app_name) + domain = "domain" + secrets.token_hex(8) + conf = AppConfig(name=app_name, diem_id_domain=domain) print("launch %s with config %s" % (app_name, conf)) conf.start(diem_client) return conf diff --git a/tests/test_testing_cli.py b/tests/test_testing_cli.py index 11429854..3d652243 100644 --- a/tests/test_testing_cli.py +++ b/tests/test_testing_cli.py @@ -224,11 +224,6 @@ def test_cli_init_with_diem_id_domain(runner: CliRunner) -> None: "stubdomain", ], ) - - client = testnet.create_client() - assert client.get_diem_id_domain_map().get("targetdomain") == target_account.account_address.to_hex() - assert client.get_diem_id_domain_map().get("stubdomain") == stub_account.account_address.to_hex() - assert result.exit_code == 0, result.output From 0c11dc69f06e2e4d8f0a640ff0733987cec43d4d Mon Sep 17 00:00:00 2001 From: SunMi Lee Date: Tue, 15 Jun 2021 15:42:23 -0700 Subject: [PATCH 6/7] Remove CLI functions --- diem | 2 +- src/diem/testing/cli.py | 16 ---------------- src/diem/testing/suites/conftest.py | 13 +++++++------ src/diem/testing/suites/envs.py | 5 ----- src/diem/testnet.py | 2 -- tests/miniwallet/conftest.py | 5 ++--- tests/test_testing_cli.py | 25 ------------------------- 7 files changed, 10 insertions(+), 58 deletions(-) diff --git a/diem b/diem index d4470e4c..6e2bc5a1 160000 --- a/diem +++ b/diem @@ -1 +1 @@ -Subproject commit d4470e4c3a6c37c0c6722d52fe701b55776f77a3 +Subproject commit 6e2bc5a11e1cb96c42e89dd2851ba4ef0171e049 diff --git a/src/diem/testing/cli.py b/src/diem/testing/cli.py index 4a7edce6..88e4a09a 100644 --- a/src/diem/testing/cli.py +++ b/src/diem/testing/cli.py @@ -43,12 +43,6 @@ def main() -> None: default=None, help="The address that will be used for offchain callbacks. Defaults to http://localhost:{port}", ) -@click.option( - "--diem-id-domain", - "-d", - default=None, - help="Diem ID domain for the wallet parent VASP account", -) @click.option("--jsonrpc", "-j", default=testnet.JSON_RPC_URL, help="Diem fullnode JSON-RPC URL.") @click.option("--faucet", "-f", default=testnet.FAUCET_URL, help="Testnet faucet URL.") @click.option("--disable-events-api", "-o", default=False, help="Disable account events API.", type=bool, is_flag=True) @@ -80,7 +74,6 @@ def start_server( import_diem_account_config_file: Optional[TextIO], logfile: Optional[str], hrp: str, - diem_id_domain: Optional[str], ) -> None: logging.basicConfig(level=logging.INFO, format=log_format, filename=logfile) configure_testnet(jsonrpc, faucet) @@ -89,7 +82,6 @@ def start_server( name=name, server_conf=ServerConfig(host=host, port=port, base_url=diem_account_base_url or ""), disable_events_api=disable_events_api, - diem_id_domain=diem_id_domain, ) if import_diem_account_config_file: conf.account_config = json.load(import_diem_account_config_file) @@ -134,13 +126,6 @@ def start_server( callback=set_env(envs.DMW_STUB_DIEM_ACCOUNT_BASE_URL), help="The address that will be used for offchain callbacks. Defaults to http://localhost:{port}", ) -@click.option( - "--stub-diem-id-domain", - "-d", - default=None, - callback=set_env(envs.DMW_STUB_DIEM_ID_DOMAIN), - help="Diem ID domain for the wallet parent VASP accountstub_diem_id_domain", -) @click.option("--jsonrpc", "-j", default=testnet.JSON_RPC_URL, help="Diem fullnode JSON-RPC URL.") @click.option( "--match-keywords", @@ -193,7 +178,6 @@ def test( stub_bind_host: Optional[str], stub_bind_port: Optional[int], stub_diem_account_base_url: Optional[str], - stub_diem_id_domain: Optional[str], jsonrpc: str, match_keywords: str, faucet: str, diff --git a/src/diem/testing/suites/conftest.py b/src/diem/testing/suites/conftest.py index 1e7cbf07..daed7d99 100644 --- a/src/diem/testing/suites/conftest.py +++ b/src/diem/testing/suites/conftest.py @@ -12,7 +12,6 @@ dmw_stub_server, dmw_stub_diem_account_config, dmw_stub_diem_account_hrp, - dmw_stub_diem_id_domain, ) from typing import Optional, Tuple, Dict, Any, Generator, Callable from dataclasses import asdict @@ -22,9 +21,8 @@ @pytest.fixture(scope="package") def target_client(diem_client: jsonrpc.Client) -> RestClient: - domain = "target" + secrets.token_hex(8) if is_self_check(): - conf = AppConfig(name="target-wallet", diem_id_domain=domain) + conf = AppConfig(name="target-wallet", diem_id_domain=generate_diem_id_domain("target")) print("self-checking, launch target app with config %s" % conf) conf.start(diem_client) return conf.create_client() @@ -51,9 +49,8 @@ def stub_wallet_app(start_stub_wallet: Tuple[AppConfig, App]) -> App: @pytest.fixture(scope="package") def start_stub_wallet(diem_client: jsonrpc.Client) -> Tuple[AppConfig, App]: - conf = AppConfig( - name="stub-wallet", server_conf=ServerConfig(**dmw_stub_server()), diem_id_domain=dmw_stub_diem_id_domain() - ) + domain = generate_diem_id_domain("stub") + conf = AppConfig(name="stub-wallet", server_conf=ServerConfig(**dmw_stub_server()), diem_id_domain=domain) account_conf = dmw_stub_diem_account_config() if account_conf: print("loads stub account config: %s" % account_conf) @@ -256,3 +253,7 @@ def wait_for_payment_transaction_complete(account: AccountResource, payment_id: # MiniWallet stub generates `updated_transaction` event when transaction is completed on-chain # Payment id is same with Transaction id. wait_for_event(account, "updated_transaction", status=Transaction.Status.completed, id=payment_id) + + +def generate_diem_id_domain(prefix: str) -> str: + return prefix + secrets.token_hex(8) diff --git a/src/diem/testing/suites/envs.py b/src/diem/testing/suites/envs.py index 60dde689..e26d0c0c 100644 --- a/src/diem/testing/suites/envs.py +++ b/src/diem/testing/suites/envs.py @@ -13,7 +13,6 @@ DMW_STUB_DIEM_ACCOUNT_BASE_URL: str = "DMW_STUB_DIEM_ACCOUNT_BASE_URL" DMW_STUB_DIEM_ACCOUNT_CONFIG: str = "DMW_STUB_DIEM_ACCOUNT_CONFIG" DMW_STUB_DIEM_ACCOUNT_HRP: str = "DMW_STUB_DIEM_ACCOUNT_HRP" -DMW_STUB_DIEM_ID_DOMAIN: str = "DMW_STUB_DIEM_ID_DOMAIN" def dmw_stub_diem_account_config() -> Optional[str]: @@ -28,10 +27,6 @@ def dmw_stub_diem_account_base_url() -> Optional[str]: return getenv(DMW_STUB_DIEM_ACCOUNT_BASE_URL) -def dmw_stub_diem_id_domain() -> Optional[str]: - return getenv(DMW_STUB_DIEM_ID_DOMAIN) - - def dmw_stub_server() -> Dict[str, Any]: return { k: v diff --git a/src/diem/testnet.py b/src/diem/testnet.py index 40689e3a..a49ac168 100644 --- a/src/diem/testnet.py +++ b/src/diem/testnet.py @@ -138,5 +138,3 @@ def _mint_without_retry( if txn.vm_status.explanation.reason == "EDOMAIN_ALREADY_EXISTS": continue raise e - except Exception as e: - raise e diff --git a/tests/miniwallet/conftest.py b/tests/miniwallet/conftest.py index 246a53a1..382106dd 100644 --- a/tests/miniwallet/conftest.py +++ b/tests/miniwallet/conftest.py @@ -1,6 +1,6 @@ # Copyright (c) The Diem Core Contributors # SPDX-License-Identifier: Apache-2.0 -import secrets + from diem import jsonrpc, testnet from diem.testing.miniwallet import RestClient, AppConfig @@ -38,8 +38,7 @@ def travel_rule_threshold(diem_client: jsonrpc.Client) -> int: def start_app(diem_client: jsonrpc.Client, app_name: str) -> AppConfig: - domain = "domain" + secrets.token_hex(8) - conf = AppConfig(name=app_name, diem_id_domain=domain) + conf = AppConfig(name=app_name) print("launch %s with config %s" % (app_name, conf)) conf.start(diem_client) return conf diff --git a/tests/test_testing_cli.py b/tests/test_testing_cli.py index 3d652243..3a6e9583 100644 --- a/tests/test_testing_cli.py +++ b/tests/test_testing_cli.py @@ -202,31 +202,6 @@ def test_wait_timeout_for_target_ready(runner: CliRunner) -> None: assert duration < 2 -def test_cli_init_with_diem_id_domain(runner: CliRunner) -> None: - app_config_file = "app.json" - stub_config_file = "stub.json" - with runner.isolated_filesystem(): - target_account = LocalAccount() - stub_account = LocalAccount() - target_account.write_to_file(app_config_file) - stub_account.write_to_file(stub_config_file) - - conf = start_target_server(runner, ["-i", app_config_file, "--diem-id-domain", "targetdomain"]) - result = start_test( - runner, - conf, - [ - "-i", - stub_config_file, - "-k", - "test_create_a_blank_account", - "--stub-diem-id-domain", - "stubdomain", - ], - ) - assert result.exit_code == 0, result.output - - def start_test(runner: CliRunner, conf: ServerConfig, options: List[str] = []) -> Result: stub_conf = ServerConfig() return runner.invoke( From f12d33f73fc49bbbdee832317c86192527f7d5ac Mon Sep 17 00:00:00 2001 From: SunMi Lee Date: Tue, 15 Jun 2021 17:50:53 -0700 Subject: [PATCH 7/7] Add test --- tests/test_testnet.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/test_testnet.py b/tests/test_testnet.py index a32c47f6..cf1004e7 100644 --- a/tests/test_testnet.py +++ b/tests/test_testnet.py @@ -403,6 +403,32 @@ def test_init_faucet_with_url(): faucet.gen_account() +def test_get_diem_id_domain_map(): + client = testnet.create_client() + faucet = testnet.Faucet(client) + parent_vasp1 = faucet.gen_account() + parent_vasp2 = faucet.gen_account() + domain1 = "domain1" + domain2 = "domain2" + + faucet.mint( + parent_vasp1.auth_key.hex(), 1, testnet.TEST_CURRENCY_CODE, diem_id_domain=domain1, is_remove_domain=False + ) + faucet.mint( + parent_vasp2.auth_key.hex(), 1, testnet.TEST_CURRENCY_CODE, diem_id_domain=domain2, is_remove_domain=False + ) + + domain_map = client.get_diem_id_domain_map() + assert domain_map.get(domain1) == parent_vasp1.account_address.to_hex() + assert domain_map.get(domain2) == parent_vasp2.account_address.to_hex() + + faucet.mint( + parent_vasp1.auth_key.hex(), 1, testnet.TEST_CURRENCY_CODE, diem_id_domain=domain1, is_remove_domain=True + ) + domain_map = client.get_diem_id_domain_map() + assert domain_map.get(domain1) is None + + def create_child_vasp_txn( parent_vasp: LocalAccount, child_vasp: LocalAccount, seq: int = 0 ) -> diem_types.RawTransaction: