From 8a6858946b568ba01563941aa713aaa97c4764f1 Mon Sep 17 00:00:00 2001 From: plebhash Date: Wed, 12 Jun 2024 16:02:24 +0200 Subject: [PATCH] add MG test for #912 --- .../jds-config.toml | 20 +++ ...ock-for-jds-receive-block-missing-txs.json | 121 ++++++++++++++++++ .../jds-receive-block-missing-txs.json | 79 ++++++++++++ .../jds-receive-block-missing-txs.sh | 9 ++ .../src/parser/sv2_messages.rs | 3 + 5 files changed, 232 insertions(+) create mode 100644 test/config/jds-receive-block-missing-txs/jds-config.toml create mode 100644 test/message-generator/mock/jdc-mock-for-jds-receive-block-missing-txs.json create mode 100644 test/message-generator/test/jds-receive-block-missing-txs/jds-receive-block-missing-txs.json create mode 100755 test/message-generator/test/jds-receive-block-missing-txs/jds-receive-block-missing-txs.sh diff --git a/test/config/jds-receive-block-missing-txs/jds-config.toml b/test/config/jds-receive-block-missing-txs/jds-config.toml new file mode 100644 index 0000000000..ab3c134e65 --- /dev/null +++ b/test/config/jds-receive-block-missing-txs/jds-config.toml @@ -0,0 +1,20 @@ +# SRI Pool config +authority_public_key = "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72" +authority_secret_key = "mkDLTBBRxdBv998612qipDYoTK3YUrqLe8uWw7gu3iXbSrn2n" +cert_validity_sec = 3600 + +# list of compressed or uncompressed pubkeys for coinbase payout (only supports 1 item in the array at this point) +coinbase_outputs = [ + { output_script_type = "P2WPKH", output_script_value = "036adc3bdf21e6f9a0f0fb0066bf517e5b7909ed1563d6958a10993849a7554075" }, +] + +listen_jd_address = "127.0.0.1:34264" + +core_rpc_url = "http://75.119.150.111" +core_rpc_port = 48332 +core_rpc_user = "username" +core_rpc_pass = "password" +# Time interval used for JDS mempool update +[mempool_update_interval] +unit = "secs" +value = 1 \ No newline at end of file diff --git a/test/message-generator/mock/jdc-mock-for-jds-receive-block-missing-txs.json b/test/message-generator/mock/jdc-mock-for-jds-receive-block-missing-txs.json new file mode 100644 index 0000000000..842d543938 --- /dev/null +++ b/test/message-generator/mock/jdc-mock-for-jds-receive-block-missing-txs.json @@ -0,0 +1,121 @@ +{ + "version": "2", + "doc": [ + "This test does", + "Mock JDC", + "Send SetupConnection and await for SetupConnection.Success", + "Send AllocateMiningJobToken and await for AllocateMiningJobToken.Success", + "Send DeclareMiningJob and await for ProvideMissingTransactions", + "Send SubmitSolution and xxx" + ], + "job_declaration_messages": [ + { + "message": { + "type": "AllocateMiningJobToken", + "user_identifier": "", + "request_id": 0, + "coinbase_tx_outputs": [] + }, + "id": "allocate_mining_job_token" + }, + { + "message": { + "type": "DeclareMiningJob", + "request_id": 0, + "mining_job_token": [1, 0, 0, 0], + "version": 0, + "coinbase_prefix": [2, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 55, 2, 128, 121, 0, 83, 116, 114, 97, 116, 117, 109, 32, 118, 50, 32, 83, 82, 73, 32, 80, 111, 111, 108], + "coinbase_suffix": [255, 255, 255, 255, 2, 168, 247, 5, 42, 1, 0, 0, 0, 22, 0, 20, 235, 225, 183, 220, 194, 147, 204, 170, 14, 231, 67, 168, 111, 137, 223, 130, 88, 194, 8, 252, 0, 0, 0, 0, 0, 0, 0, 0, 38, 106, 36, 170, 33, 169, 237, 226, 201, 13, 62, 213, 94, 164, 53, 216, 76, 246, 14, 110, 125, 255, 48, 66, 12, 220, 90, 217, 209, 75, 129, 37, 185, 117, 116, 254, 30, 81, 159, 1, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + "tx_short_hash_nonce": 0, + "tx_short_hash_list": [[95, 135, 113, 8, 147, 179]], + "tx_hash_list_hash": [133, 189, 184, 91, 252, 203, 225, 42, 233, 16, 77, 119, 76, 134, 93, 189, 192, 159, 221, 130, 150, 196, 18, 32, 54, 212, 138, 255, 57, 63, 118, 74], + "excess_data": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + }, + "id": "declare_mining_job" + }, + { + "message": { + "type": "SubmitSolution", + "extranonce": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0], + "prev_hash": [184, 103, 138, 88, 153, 105, 236, 29, 123, 246, 107, 203, 1, 33, 10, 122, 188, 139, 218, 141, 62, 177, 158, 101, 125, 92, 214, 150, 199, 220, 29, 8], + "ntime": 0, + "nonce": 0, + "nbits": 0, + "version": 0 + }, + "id": "submit_solution" + } + ], + "frame_builders": [ + { + "type": "automatic", + "message_id": "test/message-generator/messages/common_messages.json::setup_connection_job_declarator" + }, + { + "type": "automatic", + "message_id": "allocate_mining_job_token" + }, + { + "type": "automatic", + "message_id": "declare_mining_job" + }, + { + "type": "automatic", + "message_id": "submit_solution" + } + ], + "actions": [ + { + "message_ids": ["setup_connection_job_declarator"], + "role": "client", + "results": [ + { + "type": "match_message_type", + "value": "0x01" + } + ], + "actiondoc": "This action sends SetupConnection and awaits for a SetupConnection.Success" + }, + { + "message_ids": ["allocate_mining_job_token"], + "role": "client", + "results": [ + { + "type": "match_message_type", + "value": "0x51" + } + ], + "actiondoc": "This action sends AllocateMiningJobToken and awaits for a AllocateMiningJobToken.Success" + }, + { + "message_ids": ["declare_mining_job"], + "role": "client", + "results": [ + { + "type": "match_message_type", + "value": "0x55" + } + ], + "actiondoc": "This action sends DeclareMiningJob and awaits for a ProvideMissingTransactions" + }, + { + "message_ids": ["submit_solution"], + "role": "client", + "results": [ + { + "type": "sustain_connection" + } + ], + "actiondoc": "This action sends SubmitSolution and awaits for xxx" + } + ], + "setup_commands": [], + "execution_commands": [], + "cleanup_commands": [], + "role": "client", + "downstream": { + "ip": "127.0.0.1", + "port": 34264, + "pub_key": "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72" + } +} \ No newline at end of file diff --git a/test/message-generator/test/jds-receive-block-missing-txs/jds-receive-block-missing-txs.json b/test/message-generator/test/jds-receive-block-missing-txs/jds-receive-block-missing-txs.json new file mode 100644 index 0000000000..3492a737ec --- /dev/null +++ b/test/message-generator/test/jds-receive-block-missing-txs/jds-receive-block-missing-txs.json @@ -0,0 +1,79 @@ +{ + "version": "2", + "doc": [ + "This test does", + "Launch real JDS", + "Mock a JDC that sends SubmitSolution before ProvideMissingTransactionsSuccess" + ], + "frame_builders": [ + ], + "actions": [ + ], + "setup_commands": [ + { + "command": "cargo", + "args": [ + "llvm-cov", + "--no-report", + "run", + "-p", + "jd_server", + "--", + "-c", + "../test/config/jds-receive-block-missing-txs/jds-config.toml" + ], + "conditions": { + "WithConditions": { + "conditions": [ + { + "output_string": "JD INITIALIZED", + "output_location": "StdOut", + "late_condition": false, + "condition": true + } + ], + "timer_secs": 300, + "warn_no_panic": false + } + } + }, + { + "command": "cargo", + "args": [ + "run", + "../../test/message-generator/mock/jdc-mock-for-jds-receive-block-missing-txs.json" + ], + + "conditions": { + "WithConditions": { + "conditions": [ + { + "output_string": "TEST FAIL", + "output_location": "StdErr", + "condition": false, + "late_condition": false + } + ], + "timer_secs": 600, + "warn_no_panic": true + } + } + }, + { + "command": "sleep", + "args": ["1000"], + "conditions": "None" + } + ], + "execution_commands": [ + ], + "cleanup_commands": [ + { + "command": "pkill", + "args": ["-f", "jd_server", "-SIGINT"], + "late_condition": false, + "conditions": "None" + } + ], + "role": "none" +} diff --git a/test/message-generator/test/jds-receive-block-missing-txs/jds-receive-block-missing-txs.sh b/test/message-generator/test/jds-receive-block-missing-txs/jds-receive-block-missing-txs.sh new file mode 100755 index 0000000000..186268067e --- /dev/null +++ b/test/message-generator/test/jds-receive-block-missing-txs/jds-receive-block-missing-txs.sh @@ -0,0 +1,9 @@ +cd roles +cargo llvm-cov --no-report -p jd_server + +cd ../utils/message-generator/ +cargo build + +RUST_LOG=debug cargo run ../../test/message-generator/test/jds-receive-block-missing-txs/jds-receive-block-missing-txs.json || { echo 'mg test failed' ; exit 1; } + +sleep 10 diff --git a/utils/message-generator/src/parser/sv2_messages.rs b/utils/message-generator/src/parser/sv2_messages.rs index 4919fc324f..091d0c58cc 100644 --- a/utils/message-generator/src/parser/sv2_messages.rs +++ b/utils/message-generator/src/parser/sv2_messages.rs @@ -372,6 +372,8 @@ pub enum JobDeclaration<'a> { ProvideMissingTransactions(ProvideMissingTransactions<'a>), #[serde(borrow)] ProvideMissingTransactionsSuccess(ProvideMissingTransactionsSuccess<'a>), + #[serde(borrow)] + SubmitSolution(SubmitSolutionJd<'a>), } impl<'a> From> for roles_logic_sv2::parsers::JobDeclaration<'a> { @@ -390,6 +392,7 @@ impl<'a> From> for roles_logic_sv2::parsers::JobDeclaration<' JobDeclaration::ProvideMissingTransactionsSuccess(m) => { Self::ProvideMissingTransactionsSuccess(m) } + JobDeclaration::SubmitSolution(m) => Self::SubmitSolution(m), } } }