From e6ab468591c0a71562eedd9d8cbf269ce5a08e68 Mon Sep 17 00:00:00 2001 From: plebhash Date: Thu, 18 Jul 2024 16:25:44 -0300 Subject: [PATCH] fix MG tests for JD SetupConnection flags as already described in the previous commit, we introduced a new JDS config parameter (`async_mining_allowed`) so now, we need 2 separate tests: - a JDS that supports async jobs - a JDS that does not support async jobs and for each test, we need a mock that: - sends a `SetupConnection` with flag 0 and asserts the expected outcome - sends a `SetupConnection` with flag 1 and asserts the expected outcome if JDS does not support async jobs and receives a `SetupConnection` with flag 1, the expected outcome is `SetupConnection.Error` in all other cases, the expected outcome is a `SetupConnection.Success` with the same flag as the original `SetupConnection` --- .../jds-config-with-async-support.toml} | 3 + .../jds-config-without-async-support.toml | 23 +++++ ...flag-0-for-jds-setupconnection-tests.json} | 8 +- ...ds-setupconnection-with-async-support.json | 46 ++++++++++ ...setupconnection-without-async-support.json | 40 ++++++++ ...s-setupconnection-with-async-support.json} | 31 ++++++- ...jds-setupconnection-with-async-support.sh} | 2 +- ...setupconnection-without-async-support.json | 92 +++++++++++++++++++ ...s-setupconnection-without-async-support.sh | 9 ++ 9 files changed, 244 insertions(+), 10 deletions(-) rename test/config/{jds-setup-connection-flag-test/jds-config.toml => jds-setupconnection-flag-test/jds-config-with-async-support.toml} (93%) create mode 100644 test/config/jds-setupconnection-flag-test/jds-config-without-async-support.toml rename test/message-generator/mock/{jdc-mock-jds-setup-connection-mock-invalid-flag.json => jdc-mock-flag-0-for-jds-setupconnection-tests.json} (81%) create mode 100644 test/message-generator/mock/jdc-mock-flag-1-for-jds-setupconnection-with-async-support.json create mode 100644 test/message-generator/mock/jdc-mock-flag-1-for-jds-setupconnection-without-async-support.json rename test/message-generator/test/{jds-setup-connection-flag-test/jds-setup-connection-flag-test.json => jds-setupconnection-with-async-support/jds-setupconnection-with-async-support.json} (62%) rename test/message-generator/test/{jds-setup-connection-flag-test/jds-setup-connection-flag-test.sh => jds-setupconnection-with-async-support/jds-setupconnection-with-async-support.sh} (58%) create mode 100644 test/message-generator/test/jds-setupconnection-without-async-support/jds-setupconnection-without-async-support.json create mode 100755 test/message-generator/test/jds-setupconnection-without-async-support/jds-setupconnection-without-async-support.sh diff --git a/test/config/jds-setup-connection-flag-test/jds-config.toml b/test/config/jds-setupconnection-flag-test/jds-config-with-async-support.toml similarity index 93% rename from test/config/jds-setup-connection-flag-test/jds-config.toml rename to test/config/jds-setupconnection-flag-test/jds-config-with-async-support.toml index acda73227..379fee561 100644 --- a/test/config/jds-setup-connection-flag-test/jds-config.toml +++ b/test/config/jds-setupconnection-flag-test/jds-config-with-async-support.toml @@ -1,3 +1,6 @@ +# Async Job Support +async_mining_allowed = true + # SRI Pool config authority_public_key = "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72" authority_secret_key = "mkDLTBBRxdBv998612qipDYoTK3YUrqLe8uWw7gu3iXbSrn2n" diff --git a/test/config/jds-setupconnection-flag-test/jds-config-without-async-support.toml b/test/config/jds-setupconnection-flag-test/jds-config-without-async-support.toml new file mode 100644 index 000000000..c84655276 --- /dev/null +++ b/test/config/jds-setupconnection-flag-test/jds-config-without-async-support.toml @@ -0,0 +1,23 @@ +# Async Job Support +async_mining_allowed = false + +# 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 = "" +core_rpc_port = 18332 +core_rpc_user = "" +core_rpc_pass = "" +# 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-jds-setup-connection-mock-invalid-flag.json b/test/message-generator/mock/jdc-mock-flag-0-for-jds-setupconnection-tests.json similarity index 81% rename from test/message-generator/mock/jdc-mock-jds-setup-connection-mock-invalid-flag.json rename to test/message-generator/mock/jdc-mock-flag-0-for-jds-setupconnection-tests.json index 633be8d07..e80141297 100644 --- a/test/message-generator/mock/jdc-mock-jds-setup-connection-mock-invalid-flag.json +++ b/test/message-generator/mock/jdc-mock-flag-0-for-jds-setupconnection-tests.json @@ -3,8 +3,8 @@ "doc": [ "This test does", "Soft mock of JDC", - "Connect to JDS", - "Receive Setup Connection Error as incorrect bits are set" + "Connect to JDS (where it doesn't matter if it supports async jobs or not)", + "Send SetupConnection with flag 0 (no async jobs) and expect SetupConnection.Success with flag 0" ], "frame_builders": [ { @@ -25,13 +25,13 @@ [ [ "flags", - {"U32": 1} + { "U32": 0 } ] ] ] } ], - "actiondoc": "This action sends SetupConnection and checks that .Error" + "actiondoc": "This action sends SetupConnection and expects SetupConnection.Success with flag 0" } ], "setup_commands": [], diff --git a/test/message-generator/mock/jdc-mock-flag-1-for-jds-setupconnection-with-async-support.json b/test/message-generator/mock/jdc-mock-flag-1-for-jds-setupconnection-with-async-support.json new file mode 100644 index 000000000..edbd83e13 --- /dev/null +++ b/test/message-generator/mock/jdc-mock-flag-1-for-jds-setupconnection-with-async-support.json @@ -0,0 +1,46 @@ +{ + "version": "2", + "doc": [ + "This test does", + "Soft mock of JDC", + "Connect to JDS (that supports async jobs)", + "Send SetupConnection with flag 1 (async jobs) and expect SetupConnection.Success with flag 1" + ], + "frame_builders": [ + { + "type": "automatic", + "message_id": "test/message-generator/messages/common_messages.json::setup_connection_job_declarator" + } + ], + "actions": [ + { + "message_ids": ["setup_connection_job_declarator"], + "role": "client", + "results": [ + { + "type": "match_message_field", + "value": [ + "CommonMessages", + "SetupConnectionSuccess", + [ + [ + "flags", + { "U32": 1 } + ] + ] + ] + } + ], + "actiondoc": "This action sends SetupConnection and expects SetupConnection.Success with flag 1" + } + ], + "setup_commands": [], + "execution_commands": [], + "cleanup_commands": [], + "role": "client", + "downstream": { + "ip": "127.0.0.1", + "port": 34264, + "pub_key": "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72" + } +} diff --git a/test/message-generator/mock/jdc-mock-flag-1-for-jds-setupconnection-without-async-support.json b/test/message-generator/mock/jdc-mock-flag-1-for-jds-setupconnection-without-async-support.json new file mode 100644 index 000000000..eeaf19ca5 --- /dev/null +++ b/test/message-generator/mock/jdc-mock-flag-1-for-jds-setupconnection-without-async-support.json @@ -0,0 +1,40 @@ +{ + "version": "2", + "doc": [ + "This test does", + "Soft mock of JDC", + "Connect to JDS (that does not support async jobs)", + "Send SetupConnection with flag 1 (async jobs) and expect SetupConnection.Error" + ], + "frame_builders": [ + { + "type": "automatic", + "message_id": "test/message-generator/messages/common_messages.json::setup_connection_job_declarator" + } + ], + "actions": [ + { + "message_ids": ["setup_connection_job_declarator"], + "role": "client", + "results": [ + { + "type": "match_message_type", + "value": "0x02" + }, + { + "type": "close_connection" + } + ], + "actiondoc": "This action sends SetupConnection and expects SetupConnection.Error" + } + ], + "setup_commands": [], + "execution_commands": [], + "cleanup_commands": [], + "role": "client", + "downstream": { + "ip": "127.0.0.1", + "port": 34264, + "pub_key": "9auqWEzQDVyd2oe1JVGFLMLHZtCo2FFqZwtKA5gd9xbuEu7PH72" + } +} diff --git a/test/message-generator/test/jds-setup-connection-flag-test/jds-setup-connection-flag-test.json b/test/message-generator/test/jds-setupconnection-with-async-support/jds-setupconnection-with-async-support.json similarity index 62% rename from test/message-generator/test/jds-setup-connection-flag-test/jds-setup-connection-flag-test.json rename to test/message-generator/test/jds-setupconnection-with-async-support/jds-setupconnection-with-async-support.json index 403b1eb4f..c0d781d69 100644 --- a/test/message-generator/test/jds-setup-connection-flag-test/jds-setup-connection-flag-test.json +++ b/test/message-generator/test/jds-setupconnection-with-async-support/jds-setupconnection-with-async-support.json @@ -19,7 +19,7 @@ "jd_server", "--", "-c", - "../test/config/jds-setup-connection-flag-test/jds-config.toml" + "../test/config/jds-setupconnection-flag-test/jds-config-with-async-support.toml" ], "conditions": { "WithConditions": { @@ -40,16 +40,37 @@ "command": "cargo", "args": [ "run", - "../../test/message-generator/mock/jdc-mock-jds-setup-connection-mock-invalid-flag.json" + "../../test/message-generator/mock/jdc-mock-flag-0-for-jds-setupconnection-tests.json" ], "conditions": { "WithConditions": { "conditions": [ { - "output_string": "MATCHED MESSAGE TYPE 1", - "output_location": "StdOut", + "output_string": "TEST FAILED", + "output_location": "StdErr", "late_condition": false, - "condition": true + "condition": false + } + ], + "timer_secs": 600, + "warn_no_panic": false + } + } + }, + { + "command": "cargo", + "args": [ + "run", + "../../test/message-generator/mock/jdc-mock-flag-1-for-jds-setupconnection-with-async-support.json" + ], + "conditions": { + "WithConditions": { + "conditions": [ + { + "output_string": "TEST FAILED", + "output_location": "StdErr", + "late_condition": false, + "condition": false } ], "timer_secs": 600, diff --git a/test/message-generator/test/jds-setup-connection-flag-test/jds-setup-connection-flag-test.sh b/test/message-generator/test/jds-setupconnection-with-async-support/jds-setupconnection-with-async-support.sh similarity index 58% rename from test/message-generator/test/jds-setup-connection-flag-test/jds-setup-connection-flag-test.sh rename to test/message-generator/test/jds-setupconnection-with-async-support/jds-setupconnection-with-async-support.sh index b32716fe3..87dcf97e9 100755 --- a/test/message-generator/test/jds-setup-connection-flag-test/jds-setup-connection-flag-test.sh +++ b/test/message-generator/test/jds-setupconnection-with-async-support/jds-setupconnection-with-async-support.sh @@ -4,6 +4,6 @@ cargo llvm-cov --no-report -p pool_sv2 cd ../utils/message-generator/ cargo build -RUST_LOG=debug cargo run ../../test/message-generator/test/jds-setup-connection-flag-test/jds-setup-connection-flag-test.json || { echo 'mg test failed' ; exit 1; } +RUST_LOG=debug cargo run ../../test/message-generator/test/jds-setupconnection-with-async-support/jds-setupconnection-with-async-support.json || { echo 'mg test failed' ; exit 1; } sleep 10 diff --git a/test/message-generator/test/jds-setupconnection-without-async-support/jds-setupconnection-without-async-support.json b/test/message-generator/test/jds-setupconnection-without-async-support/jds-setupconnection-without-async-support.json new file mode 100644 index 000000000..15eb2e978 --- /dev/null +++ b/test/message-generator/test/jds-setupconnection-without-async-support/jds-setupconnection-without-async-support.json @@ -0,0 +1,92 @@ +{ + "version": "2", + "doc": [ + "This test does", + "Launch the jd-server" + ], + "frame_builders": [ + ], + "actions": [ + ], + "setup_commands": [ + { + "command": "cargo", + "args": [ + "llvm-cov", + "--no-report", + "run", + "-p", + "jd_server", + "--", + "-c", + "../test/config/jds-setupconnection-flag-test/jds-config-without-async-support.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-flag-0-for-jds-setupconnection-tests.json" + ], + "conditions": { + "WithConditions": { + "conditions": [ + { + "output_string": "TEST FAILED", + "output_location": "StdErr", + "late_condition": false, + "condition": false + } + ], + "timer_secs": 600, + "warn_no_panic": false + } + } + }, + { + "command": "cargo", + "args": [ + "run", + "../../test/message-generator/mock/jdc-mock-flag-1-for-jds-setupconnection-without-async-support.json" + ], + "conditions": { + "WithConditions": { + "conditions": [ + { + "output_string": "TEST FAILED", + "output_location": "StdErr", + "late_condition": false, + "condition": false + } + ], + "timer_secs": 600, + "warn_no_panic": false + } + } + } + ], + "execution_commands": [ + ], + "cleanup_commands": [ + { + "command": "pkill", + "args": ["-f", "jd_server", "-SIGINT"], + "conditions": "None" + } + ], + "role": "none" +} diff --git a/test/message-generator/test/jds-setupconnection-without-async-support/jds-setupconnection-without-async-support.sh b/test/message-generator/test/jds-setupconnection-without-async-support/jds-setupconnection-without-async-support.sh new file mode 100755 index 000000000..151cec4ff --- /dev/null +++ b/test/message-generator/test/jds-setupconnection-without-async-support/jds-setupconnection-without-async-support.sh @@ -0,0 +1,9 @@ +cd roles +cargo llvm-cov --no-report -p pool_sv2 + +cd ../utils/message-generator/ +cargo build + +RUST_LOG=debug cargo run ../../test/message-generator/test/jds-setupconnection-without-async-support/jds-setupconnection-without-async-support.json || { echo 'mg test failed' ; exit 1; } + +sleep 10