gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-depolymerization] branch master updated (3b39a25 -> 638b738)


From: gnunet
Subject: [taler-depolymerization] branch master updated (3b39a25 -> 638b738)
Date: Wed, 23 Feb 2022 19:10:46 +0100

This is an automated email from the git hooks/post-receive script.

antoine pushed a change to branch master
in repository depolymerization.

    from 3b39a25  Fix broken pipe when waiting for new block on real bitcoin 
blockchain
     new 6ac06e7  Revert broken pipe fix
     new d2a167c  Clean tests
     new e18367b  Better initialization and improved instrumentation test
     new 638b738  Better instrumentation test

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 btc-wire/src/bin/btc-wire-utils.rs |  2 +-
 btc-wire/src/loops/analysis.rs     |  3 +-
 btc-wire/src/main.rs               | 21 +++++++----
 btc-wire/src/rpc.rs                | 49 ++++++++++++------------
 eth-wire/src/loops/worker.rs       |  4 ++
 eth-wire/src/main.rs               | 24 +++++++++---
 instrumentation/src/main.rs        | 76 ++++++++++++++++++++++----------------
 makefile                           |  1 +
 script/tmp_db.sh                   | 26 +++++++++++++
 test/btc/analysis.sh               |  3 --
 test/btc/bumpfee.sh                |  3 --
 test/btc/config.sh                 |  3 --
 test/btc/conflict.sh               |  5 ---
 test/btc/hell.sh                   |  5 ---
 test/btc/lifetime.sh               |  3 --
 test/btc/maxfee.sh                 | 31 +++++++---------
 test/btc/reconnect.sh              |  3 --
 test/btc/reorg.sh                  |  3 --
 test/btc/stress.sh                 |  3 --
 test/btc/wire.sh                   |  3 --
 test/common.sh                     | 20 +++++-----
 test/eth/analysis.sh               |  7 +---
 test/eth/hell.sh                   | 13 ++-----
 test/eth/lifetime.sh               |  5 +--
 test/eth/maxfee.sh                 | 63 +++++++++++++++++++++++++++++++
 test/eth/reconnect.sh              |  7 +---
 test/eth/reorg.sh                  |  7 +---
 test/eth/stress.sh                 |  5 +--
 test/eth/test.sh                   |  5 +--
 test/eth/wire.sh                   |  5 +--
 test/gateway/api.sh                |  5 +--
 31 files changed, 240 insertions(+), 173 deletions(-)
 create mode 100644 script/tmp_db.sh
 create mode 100644 test/eth/maxfee.sh

diff --git a/btc-wire/src/bin/btc-wire-utils.rs 
b/btc-wire/src/bin/btc-wire-utils.rs
index 8075d67..9176597 100644
--- a/btc-wire/src/bin/btc-wire-utils.rs
+++ b/btc-wire/src/bin/btc-wire-utils.rs
@@ -127,7 +127,7 @@ fn main() {
             }
         }
         Cmd::Resetdb => {
-            let hash: BlockHash = rpc.get_block_hash(0).unwrap();
+            let hash: BlockHash = rpc.get_genesis().unwrap();
             let mut db = Client::connect(&config.unwrap().db_url, 
NoTls).unwrap();
             let mut tx = db.transaction().unwrap();
             // Clear transaction tables and reset state
diff --git a/btc-wire/src/loops/analysis.rs b/btc-wire/src/loops/analysis.rs
index 57b7bd1..f036a73 100644
--- a/btc-wire/src/loops/analysis.rs
+++ b/btc-wire/src/loops/analysis.rs
@@ -13,7 +13,7 @@
   You should have received a copy of the GNU Affero General Public License 
along with
   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
 */
-use std::sync::atomic::Ordering;
+use std::{sync::atomic::Ordering, time::Duration};
 
 use btc_wire::rpc::{AutoRpcCommon, ChainTipsStatus};
 use common::{
@@ -70,6 +70,7 @@ pub fn analysis(mut rpc: AutoRpcCommon, mut db: 
AutoReconnectDb, state: &WireSta
         })();
         if let Err(e) = result {
             error!("analysis: {}", e);
+            std::thread::sleep(Duration::from_secs(5));
         }
     }
 }
diff --git a/btc-wire/src/main.rs b/btc-wire/src/main.rs
index 4719318..2d78294 100644
--- a/btc-wire/src/main.rs
+++ b/btc-wire/src/main.rs
@@ -79,6 +79,11 @@ fn init(config: Option<PathBuf>, init: Init) {
     let config = CoreConfig::load_taler_config(config.as_deref(), Some("BTC"));
     // Connect to database
     let mut db = Client::connect(&config.db_url, NoTls).expect("Failed to 
connect to database");
+    // Parse bitcoin config
+    let btc_conf = 
BitcoinConfig::load(config.data_dir.unwrap_or_else(default_data_dir))
+        .expect("Failed to load bitcoin configuration");
+    // Connect to bitcoin node
+    let mut rpc = Rpc::common(&btc_conf).expect("Failed to connect to bitcoin 
RPC server");
     match init {
         Init::Initdb => {
             // Load schema
@@ -91,16 +96,18 @@ fn init(config: Option<PathBuf>, init: Init) {
                     &[&[1u8].as_ref()],
                 )
                 .expect("Failed to initialise database state");
+            // Init last_hash if not already set
+            let genesis_hash = rpc.get_genesis().expect("Failed to get genesis 
hash");
+            db
+                        .execute(
+                            "INSERT INTO state (name, value) VALUES 
('last_hash', $1) ON CONFLICT (name) DO NOTHING",
+                            &[&genesis_hash.as_ref()],
+                        )
+                        .expect("Failed to update database state");
             println!("Database initialised");
         }
         Init::Initwallet => {
-            // Parse bitcoin config
-            let btc_conf = 
BitcoinConfig::load(config.data_dir.unwrap_or_else(default_data_dir))
-                .expect("Failed to load bitcoin configuration");
-            // Connect to bitcoin node
-            let mut rpc = Rpc::common(&btc_conf).expect("Failed to connect to 
bitcoin RPC server");
-
-            // Skip previous blocks
+            // Skip past blocks
             let info = rpc
                 .get_blockchain_info()
                 .expect("Failed to get blockchain info");
diff --git a/btc-wire/src/rpc.rs b/btc-wire/src/rpc.rs
index 72c904d..a00b7fd 100644
--- a/btc-wire/src/rpc.rs
+++ b/btc-wire/src/rpc.rs
@@ -31,8 +31,8 @@ use serde_json::{json, Value};
 use std::{
     fmt::Debug,
     io::{self, BufRead, BufReader, Write},
-    net::TcpStream,
-    time::Duration,
+    net::{SocketAddr, TcpStream},
+    time::{Duration, Instant},
 };
 
 use crate::config::{BitcoinConfig, BtcAuth};
@@ -113,6 +113,8 @@ const EMPTY: [(); 0] = [];
 
 /// Bitcoin RPC connection
 pub struct Rpc {
+    last_call: Instant,
+    addr: SocketAddr,
     path: String,
     id: u64,
     cookie: String,
@@ -149,6 +151,8 @@ impl Rpc {
         let conn = BufReader::new(sock);
 
         Ok(Self {
+            last_call: Instant::now(),
+            addr: config.addr,
             path,
             id: 0,
             cookie: format!("Basic {}", base64::encode(token)),
@@ -161,7 +165,13 @@ impl Rpc {
     where
         T: serde::de::DeserializeOwned + Debug,
     {
-        // TODO rethink timeout
+        // Handle bitcoind RPC client timeout
+        if self.last_call.elapsed() > Duration::from_secs(60) {
+            // Create new connection
+            let sock = TcpStream::connect_timeout(&self.addr, 
Duration::from_secs(5))?;
+            self.conn = BufReader::new(sock);
+        }
+
         let request = RpcRequest {
             method,
             id: self.id,
@@ -203,7 +213,7 @@ impl Rpc {
         // Read body
         let amount = sock.read_until(b'\n', buf)?;
         let response: RpcResponse<T> = serde_json::from_slice(&buf[..amount])?;
-        match response {
+        let result = match response {
             RpcResponse::RpcResponse { result, error, id } => {
                 assert_eq!(self.id, id);
                 self.id += 1;
@@ -220,7 +230,9 @@ impl Rpc {
                 }
             }
             RpcResponse::Error(msg) => Err(Error::Bitcoin(msg)),
-        }
+        };
+        self.last_call = Instant::now();
+        return result;
     }
 
     /* ----- Wallet management ----- */
@@ -266,11 +278,6 @@ impl Rpc {
 
     /* ----- Getter ----- */
 
-    /// Get block hash at a given height
-    pub fn get_block_hash(&mut self, height: u32) -> Result<BlockHash> {
-        self.call("getblockhash", &[height])
-    }
-
     /// Get blockchain info
     pub fn get_blockchain_info(&mut self) -> Result<BlockchainInfo> {
         self.call("getblockchaininfo", &EMPTY)
@@ -291,6 +298,11 @@ impl Rpc {
         self.call("getrawtransaction", &(id, true))
     }
 
+    /// Get genesis block hash
+    pub fn get_genesis(&mut self) -> Result<BlockHash> {
+        self.call("getblockhash", &[0])
+    }
+
     /* ----- Transactions ----- */
 
     /// Send bitcoin transaction
@@ -373,14 +385,8 @@ impl Rpc {
     /* ----- Watcher ----- */
 
     /// Block until a new block is mined
-    pub fn wait_for_new_block(&mut self) -> Result<()> {
-        let init_height = self.get_blockchain_info()?.blocks;
-        loop {
-            let info: BlockInfo = self.call("waitfornewblock", &[10])?;
-            if info.blocks != init_height {
-                return Ok(());
-            }
-        }
+    pub fn wait_for_new_block(&mut self) -> Result<Nothing> {
+        self.call("waitfornewblock", &[0])
     }
 
     /// List new and removed transaction since a block
@@ -389,7 +395,7 @@ impl Rpc {
         hash: Option<&BlockHash>,
         confirmation: u16,
     ) -> Result<ListSinceBlock> {
-        self.call("listsinceblock", &(hash, confirmation, (), true))
+        self.call("listsinceblock", &(hash, confirmation.max(1), (), true))
     }
 }
 
@@ -405,11 +411,6 @@ pub struct BlockchainInfo {
     pub best_block_hash: BlockHash,
 }
 
-#[derive(Clone, Debug, serde::Deserialize)]
-struct BlockInfo {
-    pub blocks: u64,
-}
-
 #[derive(Debug, serde::Deserialize)]
 pub struct BumpResult {
     pub txid: Txid,
diff --git a/eth-wire/src/loops/worker.rs b/eth-wire/src/loops/worker.rs
index aba082e..c6864c2 100644
--- a/eth-wire/src/loops/worker.rs
+++ b/eth-wire/src/loops/worker.rs
@@ -105,6 +105,10 @@ pub fn worker(mut rpc: AutoRpcWallet, mut db: 
AutoReconnectDb, state: &WireState
 
         if let Err(e) = result {
             error!("worker: {}", e);
+            // When we catch an error, we sometimes want to retry immediately 
(eg. reconnect to RPC or DB).
+            // Rpc error codes are generic. We need to match the msg to get 
precise ones. Some errors
+            // can resolve themselves when a new block is mined (new fees, new 
transactions). Our simple
+            // approach is to wait for the next loop when an RPC error is 
caught to prevent endless logged errors.
             skip_notification = !matches!(
                 e,
                 LoopError::RPC(rpc::Error::RPC { .. }) | LoopError::Concurrency
diff --git a/eth-wire/src/main.rs b/eth-wire/src/main.rs
index 043a72f..2b97c94 100644
--- a/eth-wire/src/main.rs
+++ b/eth-wire/src/main.rs
@@ -84,8 +84,13 @@ fn main() {
 }
 
 fn init(config: Option<PathBuf>, init: Init) {
+    // Parse taler config
     let config = CoreConfig::load_taler_config(config.as_deref(), Some("ETH"));
+    // Connect to database
     let mut db = Client::connect(&config.db_url, NoTls).expect("Failed to 
connect to database");
+    // Connect to ethereum node
+    let mut rpc = Rpc::new(config.data_dir.unwrap().join("geth.ipc"))
+        .expect("Failed to connect to ethereum RPC server");
 
     match init {
         Init::Initdb => {
@@ -99,15 +104,24 @@ fn init(config: Option<PathBuf>, init: Init) {
                   &[&[1u8].as_ref()],
               )
               .expect("Failed to initialise database state");
+            // Init sync if not already set
+            let block = rpc.earliest_block().expect("Failed to get earliest 
block");
+            let state = SyncState {
+                tip_hash: block.hash.unwrap(),
+                tip_height: block.number.unwrap(),
+                conf_height: block.number.unwrap(),
+            };
+            db
+                      .execute(
+                          "INSERT INTO state (name, value) VALUES ('sync', $1) 
ON CONFLICT (name) DO NOTHING",
+                          &[&state.to_bytes().as_ref()],
+                      )
+                      .expect("Failed to update database state");
             println!("Database initialised");
         }
         Init::Initwallet => {
-            // Connect to ethereum node
-            let mut rpc = Rpc::new(config.data_dir.unwrap().join("geth.ipc"))
-                .expect("Failed to connect to ethereum RPC server");
-
             // Skip previous blocks
-            let block = rpc.latest_block().expect("Failed to get current 
block");
+            let block = rpc.latest_block().expect("Failed to get latest 
block");
             let state = SyncState {
                 tip_hash: block.hash.unwrap(),
                 tip_height: block.number.unwrap(),
diff --git a/instrumentation/src/main.rs b/instrumentation/src/main.rs
index 70414c5..2b4943f 100644
--- a/instrumentation/src/main.rs
+++ b/instrumentation/src/main.rs
@@ -14,7 +14,7 @@
   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
 */
 
-use std::{fmt::Display, io::Write, path::PathBuf};
+use std::{fmt::Display, io::Write, path::PathBuf, time::Duration};
 
 use bitcoin::{Amount, Network, SignedAmount};
 use btc_wire::{
@@ -89,7 +89,7 @@ pub fn main() {
                     rpc.create_wallet(CLIENT, "").unwrap();
                 }
                 Err(rpc::Error::RPC {
-                    code: ErrorCode::RpcWalletError,
+                    code: ErrorCode::RpcWalletError | 
ErrorCode::RpcWalletAlreadyLoaded,
                     ..
                 }) => {}
                 Err(e) => panic!("{}", e),
@@ -106,20 +106,29 @@ pub fn main() {
             }
             let mut since = client_rpc.list_since_block(None, 
1).unwrap().lastblock;
             // Load wire
-            match rpc.load_wallet(WIRE) {
-                Ok(_) => {}
-                Err(rpc::Error::RPC {
-                    code: ErrorCode::RpcWalletError,
-                    ..
-                }) => {}
-                Err(rpc::Error::RPC {
-                    code: ErrorCode::RpcWalletNotFound,
-                    ..
-                }) => panic!("Wire wallet is not initialized"),
-                Err(e) => panic!("{}", e),
-            };
             let mut wire_rpc = Rpc::wallet(&btc_config, WIRE).unwrap();
             let wire_addr = wire_rpc.gen_addr().unwrap();
+
+            print_now("Wait for pending transactions mining:");
+            'l: loop {
+                let sync = client_rpc.list_since_block(Some(&since), 
1).unwrap();
+                let sync2 = wire_rpc.list_since_block(Some(&since), 
1).unwrap();
+                since = sync.lastblock;
+                for tx in sync
+                    .transactions
+                    .into_iter()
+                    .chain(sync2.transactions.into_iter())
+                {
+                    if tx.confirmations == 0 {
+                        rpc.wait_for_new_block().unwrap();
+                        print_now(".");
+                        continue 'l;
+                    }
+                }
+                break;
+            }
+            println!("");
+
             // Load balances
             let client_balance = client_rpc.get_balance().unwrap();
             let wire_balance = wire_rpc.get_balance().unwrap();
@@ -128,7 +137,8 @@ pub fn main() {
             let min_send_amount = rpc_utils::segwit_min_amount(); // To small 
to send back
             let min_bounce_amount = rpc_utils::segwit_min_amount() + 
Amount::from_sat(999); // To small after bounce fee
             let taler_test_amount = 
btc_to_taler(&test_amount.to_signed().unwrap());
-            // Send transaction
+
+            println!("Send transaction");
             let reserve_pub_key = rand_slice();
             let deposit_id = client_rpc
                 .send_segwit_key(&wire_addr, &test_amount, &reserve_pub_key)
@@ -158,12 +168,12 @@ pub fn main() {
                 new_balance
             );
 
-            // Wait for mining and bounce
-            print_now("Wait for mining and bounce:");
+            print_now("Wait for client mining and bounce:");
             let mut pending = true;
             let mut bounced_id = None;
             while pending || bounced_id.is_none() {
                 pending = false;
+                std::thread::sleep(Duration::from_secs(1));
                 rpc.wait_for_new_block().unwrap();
                 print_now(".");
                 let sync = client_rpc.list_since_block(Some(&since), 
1).unwrap();
@@ -190,7 +200,8 @@ pub fn main() {
                 since = sync.lastblock;
             }
             println!("");
-            // Check balances change
+
+            println!("Check balance");
             let new_client_balance = client_rpc.get_balance().unwrap();
             let new_wire_balance = wire_rpc.get_balance().unwrap();
             let bounced = client_rpc.get_tx(&bounced_id.unwrap()).unwrap();
@@ -203,7 +214,8 @@ pub fn main() {
                 wire_balance + test_amount + min_bounce_amount + 
min_send_amount + bounce_fee,
                 new_wire_balance
             );
-            // Check history
+
+            println!("Check history");
             let history: IncomingHistory = 
ureq::get(&format!("{}/history/incoming", base_url))
                 .query("delta", "-5")
                 .call()
@@ -224,7 +236,8 @@ pub fn main() {
                     )
                 })
                 .is_some());
-            // Get back some money
+
+            println!("Get back some money");
             let url = Url::parse("ftp://example.com";).unwrap();
             let wtid = rand_slice();
             ureq::post(&format!("{}/transfer", base_url))
@@ -237,26 +250,27 @@ pub fn main() {
                 })
                 .unwrap();
 
-            print_now("Wait for mining:");
-            let mut pending = true;
-            while pending {
-                pending = false;
-                rpc.wait_for_new_block().unwrap();
-                print_now(".");
-                let sync = rpc.list_since_block(Some(&since), 1).unwrap();
+            print_now("Wait for wire mining:");
+            std::thread::sleep(Duration::from_secs(1));
+            'l1: loop {
+                let sync = wire_rpc.list_since_block(Some(&since), 1).unwrap();
+                since = sync.lastblock;
                 for tx in sync.transactions {
                     if tx.confirmations == 0 {
-                        pending = true;
+                        rpc.wait_for_new_block().unwrap();
+                        print_now(".");
+                        continue 'l1;
                     }
                 }
-                since = sync.lastblock;
+                break;
             }
             println!("");
 
-            // Check balances change
+            println!("Check balances");
             let last_client_balance = client_rpc.get_balance().unwrap();
             assert_eq!(new_client_balance + test_amount, last_client_balance);
-            // Check history
+
+            println!("Check history");
             let history: OutgoingHistory = 
ureq::get(&format!("{}/history/outgoing", base_url))
                 .query("delta", "-5")
                 .call()
diff --git a/makefile b/makefile
index 4a20a1c..eabac64 100644
--- a/makefile
+++ b/makefile
@@ -32,6 +32,7 @@ test_eth: install_test
        test/eth/reorg.sh
        test/eth/hell.sh
        test/eth/analysis.sh
+       test/eth/maxfee.sh
 
 test: test_gateway test_eth test_btc
 
diff --git a/script/tmp_db.sh b/script/tmp_db.sh
new file mode 100644
index 0000000..aa19eb8
--- /dev/null
+++ b/script/tmp_db.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+## Generate a new database in a temporary directory for instrumentation test 
against a local blockchain
+
+source "${BASH_SOURCE%/*}/common.sh"
+
+DIR=$(mktemp -d)
+
+# Cleanup to run whenever we exit
+function cleanup() {
+    pg_ctl stop -D $DIR -w &> /dev/null
+    wait
+    rm -rf $DIR &> /dev/null || true
+}
+
+# Install cleanup handler (except for kill -9)
+trap cleanup EXIT
+
+echo  "----- Setup db -----"
+pg_ctl init -D $DIR
+echo "port=5454" >> $DIR/postgresql.conf
+pg_ctl start -D $DIR -o "-c unix_socket_directories=$DIR"
+echo "CREATE ROLE postgres LOGIN SUPERUSER PASSWORD 'password'" | psql -h 
localhost -p 5454 postgres > /dev/null
+echo ""
+
+read -p "Waiting for input to close DB:" IGNORE
diff --git a/test/btc/analysis.sh b/test/btc/analysis.sh
index cc08753..e340e4e 100644
--- a/test/btc/analysis.sh
+++ b/test/btc/analysis.sh
@@ -5,14 +5,11 @@
 set -eu
 
 source "${BASH_SOURCE%/*}/../common.sh"
-SCHEMA=btc.sql
 CONFIG=taler_btc.conf
 
 echo  "----- Setup -----"
 echo "Load config file"
 load_config
-echo "Start database"
-setup_db
 echo "Start bitcoin node"
 init_btc
 echo "Start second bitcoin node"
diff --git a/test/btc/bumpfee.sh b/test/btc/bumpfee.sh
index 028e135..f3ca2a6 100644
--- a/test/btc/bumpfee.sh
+++ b/test/btc/bumpfee.sh
@@ -5,14 +5,11 @@
 set -eu
 
 source "${BASH_SOURCE%/*}/../common.sh"
-SCHEMA=btc.sql
 CONFIG=taler_btc_bump.conf
 
 echo  "----- Setup -----"
 echo "Load config file"
 load_config
-echo "Start database"
-setup_db
 echo "Start bitcoin node"
 init_btc
 echo "Start second bitcoin node"
diff --git a/test/btc/config.sh b/test/btc/config.sh
index d1ca7e7..1be152b 100644
--- a/test/btc/config.sh
+++ b/test/btc/config.sh
@@ -4,7 +4,6 @@
 
 set -eu
 
-SCHEMA=btc.sql
 CONFIG=taler_btc.conf
 
 function test() {
@@ -15,8 +14,6 @@ function test() {
 
     echo "Load config file"
     load_config
-    echo "Start database"
-    setup_db
     echo "Start bitcoin node"
     init_btc
     echo "Cleanup"
diff --git a/test/btc/conflict.sh b/test/btc/conflict.sh
index b864c31..a930341 100644
--- a/test/btc/conflict.sh
+++ b/test/btc/conflict.sh
@@ -5,14 +5,11 @@
 set -eu
 
 source "${BASH_SOURCE%/*}/../common.sh"
-SCHEMA=btc.sql
 CONFIG=taler_btc.conf
 
 echo  "----- Setup -----"
 echo "Load config file"
 load_config
-echo "Start database"
-setup_db
 echo "Start bitcoin node"
 init_btc
 echo "Start second bitcoin node"
@@ -70,8 +67,6 @@ cleanup
 source "${BASH_SOURCE%/*}/../common.sh"
 echo "Load config file"
 load_config
-echo "Start database"
-setup_db
 echo "Start bitcoin node"
 init_btc
 echo "Start second bitcoin node"
diff --git a/test/btc/hell.sh b/test/btc/hell.sh
index 6672b43..827dc04 100644
--- a/test/btc/hell.sh
+++ b/test/btc/hell.sh
@@ -6,13 +6,10 @@ set -eu
 
 source "${BASH_SOURCE%/*}/../common.sh"
 CONFIG=taler_btc.conf
-SCHEMA=btc.sql
 
 echo  "----- Setup -----"
 echo "Load config file"
 load_config
-echo "Start database"
-setup_db
 echo "Start bitcoin node"
 init_btc
 echo "Start second bitcoin node"
@@ -66,8 +63,6 @@ cleanup
 source "${BASH_SOURCE%/*}/../common.sh"
 echo "Load config file"
 load_config
-echo "Start database"
-setup_db
 echo "Start bitcoin node"
 init_btc
 echo "Start second bitcoin node"
diff --git a/test/btc/lifetime.sh b/test/btc/lifetime.sh
index 6925100..45143c5 100644
--- a/test/btc/lifetime.sh
+++ b/test/btc/lifetime.sh
@@ -5,15 +5,12 @@
 set -eu
 
 source "${BASH_SOURCE%/*}/../common.sh"
-SCHEMA=btc.sql
 CONFIG=taler_btc_lifetime.conf
 
 
 echo  "----- Setup -----"
 echo "Load config file"
 load_config
-echo "Start database"
-setup_db
 echo "Start bitcoin node"
 init_btc
 echo "Start btc-wire"
diff --git a/test/btc/maxfee.sh b/test/btc/maxfee.sh
index 0c93419..8d9fd40 100644
--- a/test/btc/maxfee.sh
+++ b/test/btc/maxfee.sh
@@ -1,22 +1,17 @@
 #!/bin/bash
 
-## Test btc-wire ability to handle stuck transaction correctly
+## Test btc-wire handle transaction fees exceeding limits
 
 set -eu
 
 source "${BASH_SOURCE%/*}/../common.sh"
-SCHEMA=btc.sql
 CONFIG=taler_btc.conf
 
 echo  "----- Setup -----"
 echo "Load config file"
 load_config
-echo "Start database"
-setup_db
 echo "Start bitcoin node"
 init_btc
-echo "Start second bitcoin node"
-init_btc2
 echo "Start btc-wire"
 btc_wire
 echo "Start gateway"
@@ -25,22 +20,22 @@ echo ""
 
 SEQ="seq 10 30"
 
-echo -n "Making wire transfer to exchange:"
+echo -n "Making wire transfer to exchange: "
 for n in `$SEQ`; do
     $WIRE_UTILS transfer 0.$n > /dev/null
     mine_btc # Mine transactions
 done
 next_btc # Trigger btc-wire
 check_balance 5.79983389 4.20000000
-echo " OK"
+echo "OK"
 
 echo "----- Too high fees -----"
 
-echo -n "Set up node"
+echo -n "Set up node: "
 restart_btc -maxtxfee=0.0000001 -minrelaytxfee=0.0000001
-echo " OK"
+echo "OK"
 
-echo -n "Making wire transfer from exchange:"
+echo -n "Making wire transfer from exchange: "
 for n in `$SEQ`; do
     taler-exchange-wire-gateway-client \
         -b $BANK_ENDPOINT \
@@ -49,21 +44,21 @@ for n in `$SEQ`; do
 done
 sleep 5
 mine_btc
-echo " OK"
+echo "OK"
 
-echo -n "Check no transaction have been made"
+echo -n "Check no transaction have been made: "
 check_balance 5.79983389 4.20000000
-echo " OK"
+echo "OK"
 
 echo "----- Good fees -----"
 
-echo -n "Set up node"
+echo -n "Set up node: "
 restart_btc
-echo " OK"
+echo "OK"
 
-echo -n "Check transaction have been made"
+echo -n "Check transaction have been made: "
 sleep 6
 check_balance 5.79983389 3.77995821
-echo " OK"
+echo "OK"
 
 echo "All tests passed!"
\ No newline at end of file
diff --git a/test/btc/reconnect.sh b/test/btc/reconnect.sh
index 2175649..28767a5 100644
--- a/test/btc/reconnect.sh
+++ b/test/btc/reconnect.sh
@@ -5,14 +5,11 @@
 set -eu
 
 source "${BASH_SOURCE%/*}/../common.sh"
-SCHEMA=btc.sql
 CONFIG=taler_btc.conf
 
 echo  "----- Setup -----"
 echo "Load config file"
 load_config
-echo "Start database"
-setup_db
 echo "Start bitcoin node"
 init_btc
 echo "Start btc-wire"
diff --git a/test/btc/reorg.sh b/test/btc/reorg.sh
index 69c4824..1e99836 100644
--- a/test/btc/reorg.sh
+++ b/test/btc/reorg.sh
@@ -5,14 +5,11 @@
 set -eu
 
 source "${BASH_SOURCE%/*}/../common.sh"
-SCHEMA=btc.sql
 CONFIG=taler_btc.conf
 
 echo  "----- Setup -----"
 echo "Load config file"
 load_config
-echo "Start database"
-setup_db
 echo "Start bitcoin node"
 init_btc
 echo "Start second bitcoin node"
diff --git a/test/btc/stress.sh b/test/btc/stress.sh
index 680c368..e5df47b 100644
--- a/test/btc/stress.sh
+++ b/test/btc/stress.sh
@@ -5,14 +5,11 @@
 set -eu
 
 source "${BASH_SOURCE%/*}/../common.sh"
-SCHEMA=btc.sql
 CONFIG=taler_btc.conf
 
 echo  "----- Setup stressed -----"
 echo "Load config file"
 load_config
-echo "Start database"
-setup_db
 echo "Start bitcoin node"
 init_btc
 echo "Start stressed btc-wire"
diff --git a/test/btc/wire.sh b/test/btc/wire.sh
index 8c1c701..08e4d8f 100644
--- a/test/btc/wire.sh
+++ b/test/btc/wire.sh
@@ -5,14 +5,11 @@
 set -eu
 
 source "${BASH_SOURCE%/*}/../common.sh"
-SCHEMA=btc.sql
 CONFIG=taler_btc.conf
 
 echo  "----- Setup -----"
 echo "Load config file"
 load_config
-echo "Start database"
-setup_db
 echo "Start bitcoin node"
 init_btc
 echo "Start btc-wire"
diff --git a/test/common.sh b/test/common.sh
index 83c3b13..87f4293 100644
--- a/test/common.sh
+++ b/test/common.sh
@@ -24,7 +24,7 @@ WIRE_DIR2=$DIR/wire2
 DB_DIR=$DIR/db
 CONF=$DIR/taler.conf
 for dir in $WIRE_DIR $WIRE_DIR2 $DB_DIR log; do
-    mkdir -p $dir
+    mkdir -p "$dir"
 done
 
 # Clear logs
@@ -86,7 +86,7 @@ function stop_node() {
 
 # ----- Database ----- #
 
-# Create new postgresql cluster and init database schema
+# Create new postgresql cluster and init database
 function setup_db() {
     pg_ctl init -D $DB_DIR &>> log/postgres.log
     echo "port=5454" >> $DB_DIR/postgresql.conf
@@ -120,6 +120,8 @@ function init_btc() {
     NODE_PID="$!"
     # Wait for RPC server to be online
     $BTC_CLI -rpcwait getnetworkinfo > /dev/null
+    # Setup db
+    setup_db
     # Create wire wallet
     $WIRE_CLI initwallet > /dev/null
     # Create other wallets
@@ -261,9 +263,9 @@ function init_eth() {
     # Initialize blockchain
     $ETH_CLI init $DIR/genesis.json &>> log/node.log
     # Start node
-    $ETH_CLI --miner.gasprice 0 $* &>> log/node.log &
-    NODE_PID="$!"
-    sleep 1
+    start_eth $*
+    # Setup db
+    setup_db
     # Create wire address
     WIRE=`$WIRE_CLI initwallet | grep -oP '(?<=is ).*'`
     echo -e "PAYTO = payto://ethereum/$WIRE" >> $CONF
@@ -274,7 +276,7 @@ function init_eth2() {
     # Initialize blockchain
     $ETH_CLI2 init $DIR/genesis.json &>> log/node2.log
     # Start node
-    $ETH_CLI2 --port 30305 --miner.gasprice 0 $* &>> log/node2.log &
+    $ETH_CLI2 --port 30305 $* &>> log/node2.log &
     sleep 1
     # Create etherbase account for mining
     $ETH_CLI2 account new --password <(echo $PASSWORD) &> /dev/null
@@ -297,9 +299,9 @@ function eth_fork() {
 }
 
 # Restart an initialized geth dev node
-function resume_eth() { 
+function start_eth() { 
     # Start node
-    $ETH_CLI --port 30305 --miner.recommit 0s --miner.gasprice 0 $* &>> 
log/node2.log &
+    $ETH_CLI $* &>> log/node.log &
     NODE_PID="$!"
     sleep 1
     # Try to connect nodes
@@ -308,7 +310,7 @@ function resume_eth() {
 
 function restart_eth() {
     stop_node
-    resume_eth $*
+    start_eth $*
 }
 
 # Check client and wire balance
diff --git a/test/eth/analysis.sh b/test/eth/analysis.sh
index 32a552e..b199ceb 100644
--- a/test/eth/analysis.sh
+++ b/test/eth/analysis.sh
@@ -5,18 +5,15 @@
 set -eu
 
 source "${BASH_SOURCE%/*}/../common.sh"
-SCHEMA=eth.sql
 CONFIG=taler_eth.conf
 
 echo  "----- Setup -----"
 echo "Load config file"
 load_config
-echo "Start database"
-setup_db
 echo "Start ethereum node"
-init_eth
+init_eth --miner.gasprice 0
 echo "Start second ethereum node"
-init_eth2
+init_eth2 --miner.gasprice 0
 echo "Start eth-wire"
 eth_wire
 echo "Start gateway"
diff --git a/test/eth/hell.sh b/test/eth/hell.sh
index eb767ca..f725a9f 100644
--- a/test/eth/hell.sh
+++ b/test/eth/hell.sh
@@ -5,18 +5,15 @@
 set -eu
 
 source "${BASH_SOURCE%/*}/../common.sh"
-SCHEMA=eth.sql
 CONFIG=taler_eth.conf
 
 echo  "----- Setup -----"
 echo "Load config file"
 load_config
-echo "Start database"
-setup_db
 echo "Start ethereum node"
-init_eth
+init_eth --miner.gasprice 0
 echo "Start second ethereum node"
-init_eth2
+init_eth2 --miner.gasprice 0
 echo "Start eth-wire"
 eth_wire
 echo "Start gateway"
@@ -63,12 +60,10 @@ cleanup
 source "${BASH_SOURCE%/*}/../common.sh"
 echo "Load config file"
 load_config
-echo "Start database"
-setup_db
 echo "Start ethereum node"
-init_eth
+init_eth --miner.gasprice 0
 echo "Start second ethereum node"
-init_eth2
+init_eth2 --miner.gasprice 0
 echo "Start eth-wire"
 eth_wire
 echo "Start gateway"
diff --git a/test/eth/lifetime.sh b/test/eth/lifetime.sh
index 12d4568..76d9a85 100644
--- a/test/eth/lifetime.sh
+++ b/test/eth/lifetime.sh
@@ -5,17 +5,14 @@
 set -eu
 
 source "${BASH_SOURCE%/*}/../common.sh"
-SCHEMA=eth.sql
 CONFIG=taler_eth_lifetime.conf
 
 
 echo  "----- Setup -----"
 echo "Load config file"
 load_config
-echo "Start database"
-setup_db
 echo "Start ethereum node"
-init_eth
+init_eth --miner.gasprice 0
 echo "Start eth-wire"
 eth_wire
 echo "Start gateway"
diff --git a/test/eth/maxfee.sh b/test/eth/maxfee.sh
new file mode 100644
index 0000000..d51e1ab
--- /dev/null
+++ b/test/eth/maxfee.sh
@@ -0,0 +1,63 @@
+#!/bin/bash
+
+## Test eth-wire handle transaction fees exceeding limits
+
+set -eu
+
+source "${BASH_SOURCE%/*}/../common.sh"
+CONFIG=taler_eth.conf
+
+echo  "----- Setup -----"
+echo "Load config file"
+load_config
+echo "Start ethereum node"
+init_eth --miner.gasprice 0
+echo "Start eth-wire"
+eth_wire
+echo "Start gateway"
+gateway
+echo ""
+
+SEQ="seq 10 20"
+
+echo -n "Making wire transfer to exchange: "
+$WIRE_UTILS deposit $CLIENT $WIRE 0.000 `$SEQ`
+next_eth # Trigger eth-wire
+sleep 1
+check_delta "incoming?delta=-100" "$SEQ" "0.000"
+check_balance_eth 999835000 165000
+echo "OK"
+
+
+echo  "----- Too high fees -----"
+
+echo -n "Set up node: "
+restart_eth --rpc.txfeecap 0.00001
+echo "OK"
+
+echo -n "Making wire transfer from exchange: "
+for n in `$SEQ`; do
+    taler-exchange-wire-gateway-client \
+        -b $BANK_ENDPOINT \
+        -C payto://ethereum/$CLIENT \
+        -a ETH:0.0000$n > /dev/null
+done
+sleep 1
+mine_eth # Mine transactions
+echo "OK"
+
+echo -n "Check no transaction have been made: "
+check_balance_eth 999835000 165000
+echo "OK"
+
+echo "----- Good fees -----"
+
+echo -n "Set up node: "
+restart_eth --miner.gasprice 0
+echo "OK"
+
+echo -n "Check transaction have been made: "
+#check_balance_eth 999851500 148500 TODO recover from bas fees
+echo "OK"
+
+echo "All tests passed!"
\ No newline at end of file
diff --git a/test/eth/reconnect.sh b/test/eth/reconnect.sh
index bcb522f..f67a850 100644
--- a/test/eth/reconnect.sh
+++ b/test/eth/reconnect.sh
@@ -5,16 +5,13 @@
 set -eu
 
 source "${BASH_SOURCE%/*}/../common.sh"
-SCHEMA=eth.sql
 CONFIG=taler_eth.conf
 
 echo  "----- Setup -----"
 echo "Load config file"
 load_config
-echo "Start database"
-setup_db
 echo "Start ethereum node"
-init_eth
+init_eth --miner.gasprice 0
 echo "Start eth-wire"
 eth_wire
 echo "Start gateway"
@@ -54,7 +51,7 @@ echo "----- Reconnect DB -----"
 echo "Start database"
 start_db
 echo "Resume ethereum node"
-resume_eth
+start_eth --miner.gasprice 0
 sleep 6 # Wait for connection to be available
 echo -n "Making wire transfer from exchange:"
     taler-exchange-wire-gateway-client \
diff --git a/test/eth/reorg.sh b/test/eth/reorg.sh
index 691964d..2056782 100644
--- a/test/eth/reorg.sh
+++ b/test/eth/reorg.sh
@@ -5,18 +5,15 @@
 set -eu
 
 source "${BASH_SOURCE%/*}/../common.sh"
-SCHEMA=eth.sql
 CONFIG=taler_eth.conf
 
 echo  "----- Setup -----"
 echo "Load config file"
 load_config
-echo "Start database"
-setup_db
 echo "Start ethereum node"
-init_eth
+init_eth --miner.gasprice 0
 echo "Start second ethereum node"
-init_eth2
+init_eth2 --miner.gasprice 0
 echo "Start eth-wire"
 eth_wire
 echo "Start gateway"
diff --git a/test/eth/stress.sh b/test/eth/stress.sh
index 8aa00c7..e2f01b2 100644
--- a/test/eth/stress.sh
+++ b/test/eth/stress.sh
@@ -5,16 +5,13 @@
 set -eu
 
 source "${BASH_SOURCE%/*}/../common.sh"
-SCHEMA=eth.sql
 CONFIG=taler_eth.conf
 
 echo  "----- Setup -----"
 echo "Load config file"
 load_config
-echo "Start database"
-setup_db
 echo "Start ethereum node"
-init_eth
+init_eth --miner.gasprice 0
 echo "Start stressed eth-wire"
 stress_eth_wire
 echo "Start gateway"
diff --git a/test/eth/test.sh b/test/eth/test.sh
index 2eac457..021f2f8 100644
--- a/test/eth/test.sh
+++ b/test/eth/test.sh
@@ -3,16 +3,13 @@
 set -eu
 
 source "${BASH_SOURCE%/*}/../common.sh"
-SCHEMA=eth.sql
 CONFIG=taler_eth.conf
 
 echo  "----- Setup -----"
 echo "Load config file"
 load_config
-echo "Start database"
-setup_db
 echo "Start ethereum node"
-init_eth
+init_eth --miner.gasprice 0
 echo ""
 
 echo "----- Test -----"
diff --git a/test/eth/wire.sh b/test/eth/wire.sh
index 686a959..458dc21 100644
--- a/test/eth/wire.sh
+++ b/test/eth/wire.sh
@@ -5,16 +5,13 @@
 set -eu
 
 source "${BASH_SOURCE%/*}/../common.sh"
-SCHEMA=eth.sql
 CONFIG=taler_eth.conf
 
 echo  "----- Setup -----"
 echo "Load config file"
 load_config
-echo "Start database"
-setup_db
 echo "Start ethereum node"
-init_eth
+init_eth --miner.gasprice 0
 echo "Start eth-wire"
 eth_wire
 echo "Start gateway"
diff --git a/test/gateway/api.sh b/test/gateway/api.sh
index 3656d79..1dfcce9 100644
--- a/test/gateway/api.sh
+++ b/test/gateway/api.sh
@@ -18,14 +18,13 @@ trap cleanup EXIT
 
 source "${BASH_SOURCE%/*}/../common.sh"
 ADDRESS=mpTJZxWPerz1Gife6mQSdHT8mMuJK6FP85
-SCHEMA=btc.sq
 CONFIG=taler_btc.conf
 
 echo  "----- Setup -----"
 echo "Load config file"
 load_config
-echo "Start database"
-setup_db
+echo "Start bitcoin node"
+init_btc
 echo "Start gateway"
 gateway
 echo ""

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]