depolymerization

wire gateway for Bitcoin/Ethereum
Log | Files | Refs | Submodules | README | LICENSE

commit 163003d415ab29936d9f5a44640181a1c60f62aa
parent 7a11f7aeffc58f6f180715d2c9cec3bccd7b15fe
Author: Antoine A <>
Date:   Tue, 19 Nov 2024 18:17:28 +0100

Improve instrumentation tests:
reuse the same postgres instance for all tests
generate password once

Diffstat:
MCargo.lock | 495+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------
Minstrumentation/src/btc.rs | 20++++++++++++--------
Minstrumentation/src/eth.rs | 14+++++++-------
Minstrumentation/src/gateway.rs | 6+++---
Minstrumentation/src/main.rs | 11+++++++++--
Minstrumentation/src/utils.rs | 277++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
Mmakefile | 3+++
7 files changed, 586 insertions(+), 240 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -49,9 +49,9 @@ checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" [[package]] name = "anstream" -version = "0.6.15" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" dependencies = [ "anstyle", "anstyle-parse", @@ -64,36 +64,36 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.8" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" [[package]] name = "anstyle-parse" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.1.1" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] name = "anstyle-wincon" -version = "3.0.4" +version = "3.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" +checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125" dependencies = [ "anstyle", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -104,7 +104,7 @@ checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -235,9 +235,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.7.2" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" +checksum = "9ac0150caa2ae65ca5bd83f25c7de183dea78d4d366469f148435e2acfbad0da" [[package]] name = "cast" @@ -247,9 +247,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.1.30" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b16803a61b81d9eabb7eae2588776c4c1e584b738ede45fdbb4c972cec1e9945" +checksum = "fd9de9f2205d5ef3fd67e685b0df337994ddd4495e2a28d185500d0e1edfea47" dependencies = [ "shlex", ] @@ -302,9 +302,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.20" +version = "4.5.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8" +checksum = "fb3b4b9e5a7c7514dfa52869339ee98b3156b0bfb4e8a77c4ff4babb64b1604f" dependencies = [ "clap_builder", "clap_derive", @@ -312,9 +312,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.20" +version = "4.5.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54" +checksum = "b17a95aa67cc7b5ebd32aa5370189aa0d79069ef1c64ce893bd30fb24bff20ec" dependencies = [ "anstream", "anstyle", @@ -331,14 +331,14 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] name = "clap_lex" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" +checksum = "afb84c814227b90d6895e01398aee0d8033c00e7466aca416fb6a8e0eb19d8a7" [[package]] name = "clap_mangen" @@ -362,9 +362,9 @@ dependencies = [ [[package]] name = "colorchoice" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" [[package]] name = "common" @@ -395,7 +395,7 @@ dependencies = [ "encode_unicode", "lazy_static", "libc", - "unicode-width", + "unicode-width 0.1.14", "windows-sys 0.52.0", ] @@ -440,9 +440,9 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "cpufeatures" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +checksum = "0ca741a962e1b0bff6d724a1a0958b686406e853bb14061f218562e1896f95e6" dependencies = [ "libc", ] @@ -535,9 +535,9 @@ dependencies = [ [[package]] name = "csv" -version = "1.3.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac574ff4d437a7b5ad237ef331c17ccca63c46479e5b5453eb8e10bb99a759fe" +checksum = "acdc4883a9c96732e4733212c01447ebd805833b7275a73ca3ee080fd77afdaf" dependencies = [ "csv-core", "itoa", @@ -575,7 +575,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -586,7 +586,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -651,6 +651,17 @@ dependencies = [ ] [[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + +[[package]] name = "dlv-list" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -754,9 +765,9 @@ checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" [[package]] name = "fastrand" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" +checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" [[package]] name = "fixed-hash" @@ -771,9 +782,9 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.34" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1b589b4dc103969ad3cf85c950899926ec64300a1a46d76c03a6072957036f0" +checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c" dependencies = [ "crc32fast", "miniz_oxide", @@ -781,9 +792,9 @@ dependencies = [ [[package]] name = "flexi_logger" -version = "0.29.3" +version = "0.29.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719236bdbcf6033a3395165f797076b31056018e6723ccff616eb25fc9c99de1" +checksum = "d26948e37cfcb1f2c2cd38e0602d3a8ab6b9472c0c6eff4516fc8def9a3124d7" dependencies = [ "chrono", "log", @@ -829,7 +840,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -912,9 +923,9 @@ checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" [[package]] name = "hashbrown" -version = "0.15.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3" [[package]] name = "heck" @@ -997,9 +1008,9 @@ checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "hyper" -version = "0.14.30" +version = "0.14.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a152ddd61dfaec7273fe8419ab357f33aee0d914c5f4efbf0d96fa749eea5ec9" +checksum = "8c08302e8fa335b151b788c775ff56e7a03ae64ff85c548ee820fecb70356e85" dependencies = [ "bytes", "futures-channel", @@ -1055,6 +1066,124 @@ dependencies = [ ] [[package]] +name = "icu_collections" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locid" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locid_transform" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locid_transform_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" + +[[package]] +name = "icu_normalizer" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "utf16_iter", + "utf8_iter", + "write16", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" + +[[package]] +name = "icu_properties" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locid_transform", + "icu_properties_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" + +[[package]] +name = "icu_provider" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_provider_macros" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + +[[package]] name = "ident_case" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1062,12 +1191,23 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "idna" -version = "0.5.0" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" dependencies = [ - "unicode-bidi", - "unicode-normalization", + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" +dependencies = [ + "icu_normalizer", + "icu_properties", ] [[package]] @@ -1097,30 +1237,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", - "hashbrown 0.15.0", + "hashbrown 0.15.1", "serde", ] [[package]] name = "indicatif" -version = "0.17.8" +version = "0.17.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "763a5a8f45087d6bcea4222e7b72c291a054edf80e4ef6efd2a4979878c7bea3" +checksum = "cbf675b85ed934d3c67b5c5469701eec7db22689d0a2139d856e0925fa28b281" dependencies = [ "console", - "instant", "number_prefix", "portable-atomic", - "unicode-width", -] - -[[package]] -name = "instant" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" -dependencies = [ - "cfg-if", + "unicode-width 0.2.0", + "web-time", ] [[package]] @@ -1197,9 +1328,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.159" +version = "0.2.164" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" +checksum = "433bfe06b8c75da9b2e3fbea6e5329ff87748f0b144ef75306e674c3f6f7c13f" [[package]] name = "libdeflate-sys" @@ -1221,9 +1352,9 @@ dependencies = [ [[package]] name = "libm" -version = "0.2.8" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" [[package]] name = "linux-raw-sys" @@ -1243,6 +1374,12 @@ dependencies = [ ] [[package]] +name = "litemap" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "643cb0b8d4fcc284004d5fd0d67ccf61dfffadb7f75e1e71bc420f4688a3a704" + +[[package]] name = "lock_api" version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1413,29 +1550,29 @@ dependencies = [ [[package]] name = "pin-project" -version = "1.1.6" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf123a161dde1e524adf36f90bc5d8d3462824a9c43553ad07a8183161189ec" +checksum = "be57f64e946e500c8ee36ef6331845d40a93055567ec57e8fae13efd33759b95" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.6" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4502d8515ca9f32f1fb543d987f63d95a14934883db45bdb48060b6b69257f8" +checksum = "3c0f5fad0874fc7abcd4d750e76917eaebbecaa2c20bde22e1dbeeba8beb758c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] name = "pin-project-lite" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" [[package]] name = "pin-utils" @@ -1548,9 +1685,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.87" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" +checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" dependencies = [ "unicode-ident", ] @@ -1672,9 +1809,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.11.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", @@ -1684,9 +1821,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" dependencies = [ "aho-corasick", "memchr", @@ -1745,9 +1882,9 @@ checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" [[package]] name = "rustix" -version = "0.38.37" +version = "0.38.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6" dependencies = [ "bitflags", "errno", @@ -1758,9 +1895,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.14" +version = "0.23.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +checksum = "7f1a745511c54ba6d4465e8d5dfbd81b45791756de28d4981af70d6dca128f1e" dependencies = [ "log", "once_cell", @@ -1831,29 +1968,29 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.210" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.210" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] name = "serde_json" -version = "1.0.128" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" dependencies = [ "itoa", "memchr", @@ -1869,7 +2006,7 @@ checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -1911,7 +2048,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -1975,6 +2112,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" [[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] name = "static_assertions" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2016,9 +2159,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.79" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", @@ -2026,10 +2169,21 @@ dependencies = [ ] [[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + +[[package]] name = "tempfile" -version = "3.13.0" +version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" +checksum = "28cce251fcbc87fac86a866eeb0d6c2d536fc16d06f184bb61aeae11aa4cee0c" dependencies = [ "cfg-if", "fastrand", @@ -2049,22 +2203,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.64" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.64" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -2114,6 +2268,16 @@ dependencies = [ ] [[package]] +name = "tinystr" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] name = "tinytemplate" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2140,9 +2304,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.40.0" +version = "1.41.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" +checksum = "22cfb5bee7a6a52939ca9224d6ac897bb669134078daa8735560897f69de4d33" dependencies = [ "backtrace", "bytes", @@ -2162,7 +2326,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -2229,7 +2393,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", ] [[package]] @@ -2311,6 +2475,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" [[package]] +name = "unicode-width" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" + +[[package]] name = "untrusted" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2350,9 +2520,9 @@ dependencies = [ [[package]] name = "url" -version = "2.5.2" +version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +checksum = "8d157f1b96d14500ffdc1f10ba712e780825526c03d9a49b4d0324b0d9113ada" dependencies = [ "form_urlencoded", "idna", @@ -2361,6 +2531,18 @@ dependencies = [ ] [[package]] +name = "utf16_iter" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] name = "utf8parse" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2368,9 +2550,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314" +checksum = "f8c5f0a0af699448548ad1a2fbf920fb4bee257eae39953ba95cb84891a0446a" [[package]] name = "version_check" @@ -2431,7 +2613,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", "wasm-bindgen-shared", ] @@ -2453,7 +2635,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2475,6 +2657,16 @@ dependencies = [ ] [[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] name = "webpki-roots" version = "0.26.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2640,6 +2832,42 @@ dependencies = [ ] [[package]] +name = "write16" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" + +[[package]] +name = "writeable" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" + +[[package]] +name = "yoke" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c5b1314b079b0930c31e3af543d8ee1757b1951ae1e1565ec704403a7240ca5" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28cc31741b18cb6f1d5ff12f5b7523e3d6eb0852bbbad19d73905511d9849b95" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", + "synstructure", +] + +[[package]] name = "zerocopy" version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2657,7 +2885,28 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.87", +] + +[[package]] +name = "zerofrom" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ec111ce797d0e0784a1116d0ddcdbea84322cd79e5d5ad173daeba4f93ab55" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ea7b4a3637ea8669cedf0f1fd5c286a17f3de97b8dd5a70a6c167a1730e63a5" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", + "synstructure", ] [[package]] @@ -2665,3 +2914,25 @@ name = "zeroize" version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" + +[[package]] +name = "zerovec" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] diff --git a/instrumentation/src/btc.rs b/instrumentation/src/btc.rs @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2022 Taler Systems SA + Copyright (C) 2022-2024 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software @@ -263,7 +263,7 @@ impl BtcCtx { let _btc_node = cmd_redirect( "bitcoind", &[&format!("-datadir={}", wire_dir.to_string_lossy())], - &ctx.log("bitcoind"), + ctx.log("bitcoind"), ); // Connect retry(|| { @@ -311,26 +311,26 @@ impl BtcCtx { let btc_node = cmd_redirect( "bitcoind", &[&format!("-datadir={}", ctx.wire_dir.to_string_lossy())], - &ctx.log("bitcoind"), + ctx.log("bitcoind"), ); let _btc_node2 = cmd_redirect( "bitcoind", &[&format!("-datadir={}", ctx.wire2_dir.to_string_lossy())], - &ctx.log("bitcoind2"), + ctx.log("bitcoind2"), ); + let mut common_rpc = retry_opt(|| Rpc::common(&state.btc_config).ok()); ctx.init_db(); // Generate wallet cmd_redirect_ok( &ctx.wire_bin_path, &["-c", ctx.conf.to_str().unwrap(), "initwallet"], - &ctx.log("cmd"), + ctx.log("cmd"), "wire initwallet", ); ctx.run(); // Setup wallets - let mut common_rpc = retry_opt(|| Rpc::common(&state.btc_config).ok()); let node2_addr = format!("127.0.0.1:{btc2_port}"); common_rpc.add_node(&node2_addr).unwrap(); @@ -409,7 +409,7 @@ impl BtcCtx { let datadir = format!("-datadir={}", self.ctx.wire_dir.to_string_lossy()); let mut args = vec![datadir.as_str()]; args.extend_from_slice(additional_args); - self.btc_node = cmd_redirect("bitcoind", &args, &self.ctx.log("bitcoind")); + self.btc_node = cmd_redirect("bitcoind", &args, self.ctx.log("bitcoind")); self.common_rpc = retry_opt(|| Rpc::common(&self.state.btc_config).ok()); self.common_rpc.add_node(&self.node2_addr).unwrap(); for name in ["client", "reserve", "wire"] { @@ -1119,7 +1119,11 @@ pub fn config(ctx: TestCtx) { let config_name = format!("bitcoin_auth{}.conf", n); ctx.step(format!("Config {}", config_name)); BtcCtx::config( - TestCtx::new(&format!("config/{config_name}"), ProgressBar::hidden()), + TestCtx::new( + &format!("config/{config_name}"), + ProgressBar::hidden(), + ctx.db.clone(), + ), &config_name, ); } diff --git a/instrumentation/src/eth.rs b/instrumentation/src/eth.rs @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2022 Taler Systems SA + Copyright (C) 2022-2024 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software @@ -244,7 +244,7 @@ impl EthCtx { "--password", pswd_path.to_str().unwrap(), ], - &ctx.log("geth"), + ctx.log("geth"), "create account", ) } @@ -299,7 +299,7 @@ impl EthCtx { "init", ctx.wire_dir.join("genesis.json").to_str().unwrap(), ], - &ctx.log("geth"), + ctx.log("geth"), "init chain", ); cmd_redirect_ok( @@ -311,7 +311,7 @@ impl EthCtx { "init", ctx.wire_dir.join("genesis.json").to_str().unwrap(), ], - &ctx.log("geth2"), + ctx.log("geth2"), "init chain2", ); let node = cmd_redirect( @@ -328,7 +328,7 @@ impl EthCtx { &unused_port().to_string(), "--rpc.enabledeprecatedpersonal", ], - &ctx.log("geth"), + ctx.log("geth"), ); let mut rpc = retry_opt(|| Rpc::new(&ctx.wire_dir).ok()); ctx.init_db(); @@ -429,7 +429,7 @@ impl EthCtx { "import", path, ], - &self.ctx.log("geth2"), + self.ctx.log("geth2"), "import chain", ); } @@ -451,7 +451,7 @@ impl EthCtx { &unused_port().to_string(), "--rpc.enabledeprecatedpersonal", ], - &self.ctx.log("geth2"), + self.ctx.log("geth2"), ); let mut rpc = retry_opt(|| Rpc::new(&self.ctx.wire2_dir).ok()); Self::_mine(&mut rpc, &self.reserve_addr, length, &self.passwd); diff --git a/instrumentation/src/gateway.rs b/instrumentation/src/gateway.rs @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2022 Taler Systems SA + Copyright (C) 2022-2024 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software @@ -219,7 +219,7 @@ pub fn auth(ctx: TestCtx) { // No auth assert_eq!( - http_code(ureq::get(&format!("{}history.outgoing", ctx.gateway_url)).call()), + http_code(ureq::get(&format!("{}history/outgoing", ctx.gateway_url)).call()), 401 ); @@ -236,7 +236,7 @@ pub fn auth(ctx: TestCtx) { "-a", &format!("{}:0.00042", ctx.taler_conf.currency.to_str()), ], - &ctx.log("client"), + ctx.log("client"), "", ); } diff --git a/instrumentation/src/main.rs b/instrumentation/src/main.rs @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2022 Taler Systems SA + Copyright (C) 2022-2024 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software @@ -27,6 +27,7 @@ use common::{config::TalerConfig, currency::Currency}; use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; use owo_colors::OwoColorize; use thread_local_panic_hook::set_hook; +use utils::TestDb; use crate::utils::{try_cmd_redirect, TestCtx}; @@ -89,6 +90,10 @@ pub fn main() { } p.finish_and_clear(); + // Generate password + let pwd: String = (0..30).map(|_| fastrand::alphanumeric()).collect(); + std::env::set_var("PASSWORD", pwd); + // Run tests let m = MultiProgress::new(); let start_style = @@ -101,6 +106,7 @@ pub fn main() { .unwrap(); let start = Instant::now(); + let db = Arc::new(TestDb::new()); let results: Vec<_> = std::thread::scope(|s| { let tests: Vec<_> = TESTS .iter() @@ -113,9 +119,10 @@ pub fn main() { pb.set_prefix(*name); pb.set_message("Init"); pb.enable_steady_tick(Duration::from_millis(1000)); + let db = db.clone(); let join = s.spawn(move || { let start = Instant::now(); - let ctx: TestCtx = TestCtx::new(name, pb.clone()); + let ctx: TestCtx = TestCtx::new(name, pb.clone(), db); let out = Arc::new(Mutex::new(String::new())); let tmp = out.clone(); set_hook(Box::new(move |info| { diff --git a/instrumentation/src/utils.rs b/instrumentation/src/utils.rs @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2022 Taler Systems SA + Copyright (C) 2022-2024 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software @@ -22,6 +22,7 @@ use std::{ path::{Path, PathBuf}, process::{Child, Command, Stdio}, str::FromStr, + sync::Arc, thread::sleep, time::{Duration, Instant}, }; @@ -34,7 +35,6 @@ use common::{ url::Url, }; use indicatif::ProgressBar; -use signal_child::{signal::Signal, Signalable}; use tempfile::TempDir; pub fn print_now(disp: impl Display) { @@ -149,6 +149,7 @@ impl Drop for ChildGuard { } } +#[track_caller] pub fn cmd_out(cmd: &str, args: &[&str]) -> String { let output = Command::new(cmd) .args(args) @@ -162,7 +163,12 @@ pub fn cmd_out(cmd: &str, args: &[&str]) -> String { } } -pub fn try_cmd_redirect(cmd: &str, args: &[&str], path: &str) -> std::io::Result<ChildGuard> { +#[track_caller] +pub fn try_cmd_redirect( + cmd: &str, + args: &[&str], + path: impl AsRef<Path>, +) -> std::io::Result<ChildGuard> { let log_file = std::fs::OpenOptions::new() .create(true) .append(true) @@ -177,10 +183,12 @@ pub fn try_cmd_redirect(cmd: &str, args: &[&str], path: &str) -> std::io::Result Ok(ChildGuard(child)) } -pub fn cmd_redirect(cmd: &str, args: &[&str], path: &str) -> ChildGuard { +#[track_caller] +pub fn cmd_redirect(cmd: &str, args: &[&str], path: impl AsRef<Path>) -> ChildGuard { try_cmd_redirect(cmd, args, path).unwrap() } +#[track_caller] pub fn cmd_ok(mut child: ChildGuard, name: &str) { let result = child.0.wait().unwrap(); if !result.success() { @@ -188,10 +196,12 @@ pub fn cmd_ok(mut child: ChildGuard, name: &str) { } } -pub fn cmd_redirect_ok(cmd: &str, args: &[&str], path: &str, name: &str) { +#[track_caller] +pub fn cmd_redirect_ok(cmd: &str, args: &[&str], path: impl AsRef<Path>, name: &str) { cmd_ok(cmd_redirect(cmd, args, path), name) } +#[track_caller] pub fn retry_opt<T>(mut lambda: impl FnMut() -> Option<T>) -> T { let start = Instant::now(); loop { @@ -204,47 +214,60 @@ pub fn retry_opt<T>(mut lambda: impl FnMut() -> Option<T>) -> T { } } +#[track_caller] pub fn retry(mut lambda: impl FnMut() -> bool) { retry_opt(|| lambda().then_some(())) } #[derive(Clone)] pub struct TestCtx { - pub log_dir: String, + pub name: String, + pub log_dir: PathBuf, pub pb: ProgressBar, + pub db: Arc<TestDb>, } impl TestCtx { - pub fn new(name: &str, pb: ProgressBar) -> Self { + pub fn new(name: &str, pb: ProgressBar, db: Arc<TestDb>) -> Self { // Create log dir - let log_dir = format!("log/{name}"); + let log_dir = PathBuf::from_str("log").unwrap().join(name); std::fs::remove_dir_all(&log_dir).ok(); std::fs::create_dir_all(&log_dir).unwrap(); - // Generate password - let pwd: String = (0..30).map(|_| fastrand::alphanumeric()).collect(); - std::env::set_var("PASSWORD", pwd); - Self { log_dir, pb } + Self { + name: name.to_owned(), + log_dir, + pb, + db, + } } - pub fn log(&self, name: &str) -> String { - format!("{}/{name}.log", self.log_dir) + pub fn log(&self, name: &str) -> PathBuf { + self.log_dir.join(format!("{name}.log")) } pub fn step(&self, disp: impl Display) { self.pb.set_message(format!("{disp}")) } + + /* ----- Database ----- */ + + pub fn stop_db(&mut self) { + self.db.stop_db(&self.name); + } + + pub fn resume_db(&mut self) { + self.db.resume_db(&self.name); + } } pub struct TalerCtx { pub dir: TempDir, pub wire_dir: PathBuf, pub wire2_dir: PathBuf, - pub db_dir: PathBuf, pub conf: PathBuf, pub taler_conf: TalerConfig, ctx: TestCtx, - db: ChildGuard, pub wire_bin_path: String, stressed: bool, gateway: Option<ChildGuard>, @@ -263,14 +286,12 @@ impl TalerCtx { // Create common dirs let wire_dir = dir.path().join("wire"); let wire2_dir = dir.path().join("wire2"); - let db_dir = dir.path().join("db"); - for dir in [&wire_dir, &wire2_dir, &db_dir] { + for dir in [&wire_dir, &wire2_dir] { std::fs::create_dir_all(dir).unwrap(); } // Find unused port let gateway_port = unused_port(); - let db_port = unused_port(); // Generate taler config from base let config = PathBuf::from_str("instrumentation/conf") @@ -297,72 +318,25 @@ impl TalerCtx { .set("IPC_PATH", wire_dir.to_string_lossy()) .set( "DB_URL", - format!("postgres://localhost:{db_port}/postgres?user=postgres&password=password"), + format!( + "postgres://localhost:{}/{}?user=postgres&password=password", + ctx.db.port, ctx.name + ), ) .set("PORT", gateway_port.to_string()); config.write_to_file(&conf).unwrap(); let taler_conf = TalerConfig::load(Some(&conf)); - // Setup database - let db = { - // Init databases files - cmd_redirect_ok( - "initdb", - &[db_dir.to_string_lossy().as_ref()], - &ctx.log("postgres"), - "init_db", - ); - // Generate database config - std::fs::write( - db_dir.join("postgresql.conf"), - format!( - "port={db_port}\nunix_socket_directories='{}'\n", - db_dir.to_string_lossy().as_ref() - ), - ) - .unwrap(); - let db = TalerCtx::start_db(&db_dir, ctx); - retry(|| { - let mut psql = ChildGuard( - Command::new("psql") - .args(["-h", "localhost", "-p", &db_port.to_string(), "postgres"]) - .stderr(Stdio::null()) - .stdout( - std::fs::File::options() - .append(true) - .create(true) - .open(ctx.log("postgres")) - .unwrap(), - ) - .stdin(Stdio::piped()) - .spawn() - .unwrap(), - ); - psql.0 - .stdin - .as_mut() - .unwrap() - .write_all( - "CREATE ROLE postgres LOGIN SUPERUSER PASSWORD 'password'".as_bytes(), - ) - .unwrap(); - psql.0.wait().unwrap().success() - }); - - db - }; let wire_name = wire_name.into(); Self { + dir, ctx: ctx.clone(), gateway_url: format!("http://localhost:{}/", taler_conf.port()), - dir, wire_dir, wire2_dir, - db_dir, conf, taler_conf, - db, wire_bin_path: if stressed { format!("log/bin/{wire_name}-fail") } else { @@ -377,41 +351,39 @@ impl TalerCtx { } pub fn init_db(&self) { + self.db.create_db(&self.ctx.name); // Init db - retry(|| { - cmd_redirect( - &self.wire_bin_path, - &["-c", self.conf.to_string_lossy().as_ref(), "initdb"], - &self.log("cmd"), - ) - .0 - .wait() - .unwrap() - .success() - }) + cmd_redirect_ok( + &self.wire_bin_path, + &["-c", self.conf.to_string_lossy().as_ref(), "initdb"], + self.log("cmd"), + "wire initdb", + ); } pub fn run(&mut self) { + // Run gateway + self.gateway = Some(cmd_redirect( + "log/bin/wire-gateway", + &["-c", self.conf.to_string_lossy().as_ref()], + self.log("gateway"), + )); + // Start wires self.wire = Some(cmd_redirect( &self.wire_bin_path, &["-c", self.conf.to_string_lossy().as_ref()], - &self.log("wire"), + self.log("wire"), )); self.wire2 = self.stressed.then(|| { cmd_redirect( &self.wire_bin_path, &["-c", self.conf.to_string_lossy().as_ref()], - &self.log("wire1"), + self.log("wire1"), ) }); - // Run gateway - self.gateway = Some(cmd_redirect( - "log/bin/wire-gateway", - &["-c", self.conf.to_string_lossy().as_ref()], - &self.log("gateway"), - )); + // Wait for gateway to be up retry(|| { TcpStream::connect(SocketAddrV4::new(Ipv4Addr::LOCALHOST, self.gateway_port)).is_ok() }); @@ -435,24 +407,6 @@ impl TalerCtx { .is_none() } - /* ----- Database ----- */ - - fn start_db(db_dir: &Path, ctx: &TestCtx) -> ChildGuard { - cmd_redirect( - "postgres", - &["-D", db_dir.to_string_lossy().as_ref()], - &ctx.log("postgres"), - ) - } - - pub fn resume_db(&mut self) { - self.db = Self::start_db(&self.db_dir, &self.ctx); - } - - pub fn stop_db(&mut self) { - self.db.0.signal(Signal::SIGQUIT).unwrap(); - } - /* ----- Wire Gateway -----*/ pub fn expect_credits(&self, txs: &[([u8; 32], Amount)]) { @@ -497,3 +451,110 @@ pub fn unused_port() -> u16 { .unwrap() .port() } + +pub struct TestDb { + pub dir: TempDir, + pub port: u16, + _db: ChildGuard, +} + +impl TestDb { + pub fn new() -> Self { + let dir = TempDir::new().unwrap(); + let port = unused_port(); + let log = "log/postgres.log"; + + // Init databases files + cmd_redirect_ok( + "initdb", + &[dir.path().to_string_lossy().as_ref()], + log, + "init_db", + ); + // Generate database config + std::fs::write( + dir.path().join("postgresql.conf"), + format!( + " + port={port} + unix_socket_directories='{}' + fsync=off + synchronous_commit=off + full_page_writes=off + ", + dir.path().to_string_lossy().as_ref() + ), + ) + .unwrap(); + let db = cmd_redirect( + "postgres", + &["-D", dir.path().to_string_lossy().as_ref()], + log, + ); + retry(|| { + Self::execute_sql( + port, + "CREATE ROLE postgres LOGIN SUPERUSER PASSWORD 'password'", + ) + }); + + Self { dir, port, _db: db } + } + + fn execute_sql(port: u16, sql: &str) -> bool { + let mut psql = ChildGuard( + Command::new("psql") + .arg(format!("postgres://localhost:{}/postgres", port)) + .stderr(Stdio::null()) + .stdout( + std::fs::File::options() + .append(true) + .create(true) + .open("log/postgres.log") + .unwrap(), + ) + .stdin(Stdio::piped()) + .spawn() + .unwrap(), + ); + psql.0 + .stdin + .as_mut() + .unwrap() + .write_all(sql.as_bytes()) + .unwrap(); + psql.0.wait().unwrap().success() + } + + pub fn create_db(&self, name: &str) { + Self::execute_sql( + self.port, + &format!( + " + DROP DATABASE IF EXISTS {name}; + CREATE DATABASE {name}; + " + ), + ); + } + + pub fn stop_db(&self, name: &str) { + Self::execute_sql( + self.port, + &format!( + " + UPDATE pg_database SET datallowconn=false WHERE datname='{name}'; + SELECT pg_terminate_backend(pid) + FROM pg_stat_activity + WHERE datname='{name}' AND pid <> pg_backend_pid(); + " + ), + ); + } + pub fn resume_db(&self, name: &str) { + Self::execute_sql( + self.port, + &format!("UPDATE pg_database SET datallowconn=true WHERE datname='{name}';"), + ); + } +} diff --git a/makefile b/makefile @@ -9,5 +9,8 @@ segwit_demo: test: RUST_BACKTRACE=full cargo run --profile dev --bin instrumentation -- offline +check: + cargo check + msrv: cargo msrv --min 1.70.0 \ No newline at end of file