From 000d939a2c8fcb1d0fa229acb2ca3c21dfa037e3 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Wed, 3 Aug 2022 12:36:25 +0100 Subject: [PATCH 01/15] clear pending coinbase transactions now rely on utxo hashes --- base_layer/core/src/transactions/coinbase_builder.rs | 2 +- .../wallet/src/output_manager_service/service.rs | 4 ++-- .../output_manager_service/storage/database/backend.rs | 4 ++-- .../src/output_manager_service/storage/database/mod.rs | 6 +++--- .../output_manager_service/storage/sqlite_db/mod.rs | 8 ++++---- .../storage/sqlite_db/output_sql.rs | 10 ++++++++++ 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/base_layer/core/src/transactions/coinbase_builder.rs b/base_layer/core/src/transactions/coinbase_builder.rs index 6363831374..ecdce58e26 100644 --- a/base_layer/core/src/transactions/coinbase_builder.rs +++ b/base_layer/core/src/transactions/coinbase_builder.rs @@ -203,7 +203,7 @@ impl CoinbaseBuilder { let sig = Signature::sign(spending_key.clone(), nonce, &challenge) .map_err(|_| CoinbaseBuildError::BuildError("Challenge could not be represented as a scalar".into()))?; - let sender_offset_private_key = PrivateKey::random(&mut OsRng); + let sender_offset_private_key = PrivateKey::from_bytes(Blake256::digest(spending_key)); // H(spending_key) <- Blake256 let sender_offset_public_key = PublicKey::from_secret_key(&sender_offset_private_key); let covenant = self.covenant; diff --git a/base_layer/wallet/src/output_manager_service/service.rs b/base_layer/wallet/src/output_manager_service/service.rs index cc16d39468..c50c7da0aa 100644 --- a/base_layer/wallet/src/output_manager_service/service.rs +++ b/base_layer/wallet/src/output_manager_service/service.rs @@ -1012,12 +1012,12 @@ where match self .resources .db - .clear_pending_coinbase_transaction_at_block_height(block_height) + .clear_pending_coinbase_transaction_with_hash(output.hash.as_slice()) { Ok(_) => { debug!( target: LOG_TARGET, - "An existing pending coinbase was cleared for block height {}", block_height + "An existing pending coinbase was cleared with hash {}", output.hash.to_hex() ) }, Err(e) => match e { diff --git a/base_layer/wallet/src/output_manager_service/storage/database/backend.rs b/base_layer/wallet/src/output_manager_service/storage/database/backend.rs index 4527e1b561..e3a7cad923 100644 --- a/base_layer/wallet/src/output_manager_service/storage/database/backend.rs +++ b/base_layer/wallet/src/output_manager_service/storage/database/backend.rs @@ -97,9 +97,9 @@ pub trait OutputManagerBackend: Send + Sync + Clone { /// Get the output that was most recently spent, ordered descending by mined height fn get_last_spent_output(&self) -> Result, OutputManagerStorageError>; /// Check if there is a pending coinbase transaction at this block height, if there is clear it. - fn clear_pending_coinbase_transaction_at_block_height( + fn clear_pending_coinbase_transaction_with_hash( &self, - block_height: u64, + hash: &[u8], ) -> Result<(), OutputManagerStorageError>; /// Set if a coinbase output is abandoned or not fn set_coinbase_abandoned(&self, tx_id: TxId, abandoned: bool) -> Result<(), OutputManagerStorageError>; diff --git a/base_layer/wallet/src/output_manager_service/storage/database/mod.rs b/base_layer/wallet/src/output_manager_service/storage/database/mod.rs index 91c15e1bbb..d5af1bcbae 100644 --- a/base_layer/wallet/src/output_manager_service/storage/database/mod.rs +++ b/base_layer/wallet/src/output_manager_service/storage/database/mod.rs @@ -220,11 +220,11 @@ where T: OutputManagerBackend + 'static } /// Check if there is a pending coinbase transaction at this block height, if there is clear it. - pub fn clear_pending_coinbase_transaction_at_block_height( + pub fn clear_pending_coinbase_transaction_with_hash( &self, - block_height: u64, + hash: &[u8], ) -> Result<(), OutputManagerStorageError> { - self.db.clear_pending_coinbase_transaction_at_block_height(block_height) + self.db.clear_pending_coinbase_transaction_with_hash(hash) } pub fn fetch_all_unspent_outputs(&self) -> Result, OutputManagerStorageError> { diff --git a/base_layer/wallet/src/output_manager_service/storage/sqlite_db/mod.rs b/base_layer/wallet/src/output_manager_service/storage/sqlite_db/mod.rs index 09fdafe15d..f2d0a21e03 100644 --- a/base_layer/wallet/src/output_manager_service/storage/sqlite_db/mod.rs +++ b/base_layer/wallet/src/output_manager_service/storage/sqlite_db/mod.rs @@ -1074,21 +1074,21 @@ impl OutputManagerBackend for OutputManagerSqliteDatabase { Ok(()) } - fn clear_pending_coinbase_transaction_at_block_height( + fn clear_pending_coinbase_transaction_with_hash( &self, - block_height: u64, + hash: &[u8], ) -> Result<(), OutputManagerStorageError> { let start = Instant::now(); let conn = self.database_connection.get_pooled_connection()?; let acquire_lock = start.elapsed(); - let output = OutputSql::find_pending_coinbase_at_block_height(block_height, &conn)?; + let output = OutputSql::find_pending_coinbase_with_hash(hash, &conn)?; output.delete(&conn)?; if start.elapsed().as_millis() > 0 { trace!( target: LOG_TARGET, - "sqlite profile - clear_pending_coinbase_transaction_at_block_height: lock {} + db_op {} = {} ms", + "sqlite profile - clear_pending_coinbase_transaction_with_hash: lock {} + db_op {} = {} ms", acquire_lock.as_millis(), (start.elapsed() - acquire_lock).as_millis(), start.elapsed().as_millis() diff --git a/base_layer/wallet/src/output_manager_service/storage/sqlite_db/output_sql.rs b/base_layer/wallet/src/output_manager_service/storage/sqlite_db/output_sql.rs index 63480ee86c..804681ab59 100644 --- a/base_layer/wallet/src/output_manager_service/storage/sqlite_db/output_sql.rs +++ b/base_layer/wallet/src/output_manager_service/storage/sqlite_db/output_sql.rs @@ -576,6 +576,16 @@ impl OutputSql { .first::(conn)?) } + pub fn find_pending_coinbase_with_hash( + hash: &[u8], + conn: &SqliteConnection, + ) -> Result { + Ok(outputs::table + .filter(outputs::status.ne(OutputStatus::Unspent as i32)) + .filter(outputs::hash.eq(Some(hash))) + .first::(conn)?) + } + /// Find a particular Output, if it exists and is in the specified Spent state pub fn find_pending_coinbase_at_block_height( block_height: u64, From aa225a474a69c0cf0ad02f203c1de853063742b2 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Mon, 8 Aug 2022 12:15:51 +0100 Subject: [PATCH 02/15] sync with dev --- base_layer/core/src/transactions/coinbase_builder.rs | 2 +- .../wallet/src/output_manager_service/service.rs | 4 ++-- .../output_manager_service/storage/database/backend.rs | 4 ++-- .../src/output_manager_service/storage/database/mod.rs | 6 +++--- .../output_manager_service/storage/sqlite_db/mod.rs | 8 ++++---- .../storage/sqlite_db/output_sql.rs | 10 ---------- 6 files changed, 12 insertions(+), 22 deletions(-) diff --git a/base_layer/core/src/transactions/coinbase_builder.rs b/base_layer/core/src/transactions/coinbase_builder.rs index 5b984352cf..0b55b78e6d 100644 --- a/base_layer/core/src/transactions/coinbase_builder.rs +++ b/base_layer/core/src/transactions/coinbase_builder.rs @@ -205,7 +205,7 @@ impl CoinbaseBuilder { let sig = Signature::sign(spending_key.clone(), nonce, &challenge) .map_err(|_| CoinbaseBuildError::BuildError("Challenge could not be represented as a scalar".into()))?; - let sender_offset_private_key = PrivateKey::from_bytes(Blake256::digest(spending_key)); // H(spending_key) <- Blake256 + let sender_offset_private_key = PrivateKey::random(&mut OsRng); let sender_offset_public_key = PublicKey::from_secret_key(&sender_offset_private_key); let covenant = self.covenant; diff --git a/base_layer/wallet/src/output_manager_service/service.rs b/base_layer/wallet/src/output_manager_service/service.rs index 9e8395c57a..97bdfd64a3 100644 --- a/base_layer/wallet/src/output_manager_service/service.rs +++ b/base_layer/wallet/src/output_manager_service/service.rs @@ -1014,12 +1014,12 @@ where match self .resources .db - .clear_pending_coinbase_transaction_with_hash(output.hash.as_slice()) + .clear_pending_coinbase_transaction_at_block_height(block_height) { Ok(_) => { debug!( target: LOG_TARGET, - "An existing pending coinbase was cleared with hash {}", output.hash.to_hex() + "An existing pending coinbase was cleared for block height {}", block_height ) }, Err(e) => match e { diff --git a/base_layer/wallet/src/output_manager_service/storage/database/backend.rs b/base_layer/wallet/src/output_manager_service/storage/database/backend.rs index e3a7cad923..4527e1b561 100644 --- a/base_layer/wallet/src/output_manager_service/storage/database/backend.rs +++ b/base_layer/wallet/src/output_manager_service/storage/database/backend.rs @@ -97,9 +97,9 @@ pub trait OutputManagerBackend: Send + Sync + Clone { /// Get the output that was most recently spent, ordered descending by mined height fn get_last_spent_output(&self) -> Result, OutputManagerStorageError>; /// Check if there is a pending coinbase transaction at this block height, if there is clear it. - fn clear_pending_coinbase_transaction_with_hash( + fn clear_pending_coinbase_transaction_at_block_height( &self, - hash: &[u8], + block_height: u64, ) -> Result<(), OutputManagerStorageError>; /// Set if a coinbase output is abandoned or not fn set_coinbase_abandoned(&self, tx_id: TxId, abandoned: bool) -> Result<(), OutputManagerStorageError>; diff --git a/base_layer/wallet/src/output_manager_service/storage/database/mod.rs b/base_layer/wallet/src/output_manager_service/storage/database/mod.rs index d5af1bcbae..91c15e1bbb 100644 --- a/base_layer/wallet/src/output_manager_service/storage/database/mod.rs +++ b/base_layer/wallet/src/output_manager_service/storage/database/mod.rs @@ -220,11 +220,11 @@ where T: OutputManagerBackend + 'static } /// Check if there is a pending coinbase transaction at this block height, if there is clear it. - pub fn clear_pending_coinbase_transaction_with_hash( + pub fn clear_pending_coinbase_transaction_at_block_height( &self, - hash: &[u8], + block_height: u64, ) -> Result<(), OutputManagerStorageError> { - self.db.clear_pending_coinbase_transaction_with_hash(hash) + self.db.clear_pending_coinbase_transaction_at_block_height(block_height) } pub fn fetch_all_unspent_outputs(&self) -> Result, OutputManagerStorageError> { diff --git a/base_layer/wallet/src/output_manager_service/storage/sqlite_db/mod.rs b/base_layer/wallet/src/output_manager_service/storage/sqlite_db/mod.rs index 9fab53d2d1..73af04cd9c 100644 --- a/base_layer/wallet/src/output_manager_service/storage/sqlite_db/mod.rs +++ b/base_layer/wallet/src/output_manager_service/storage/sqlite_db/mod.rs @@ -1074,21 +1074,21 @@ impl OutputManagerBackend for OutputManagerSqliteDatabase { Ok(()) } - fn clear_pending_coinbase_transaction_with_hash( + fn clear_pending_coinbase_transaction_at_block_height( &self, - hash: &[u8], + block_height: u64, ) -> Result<(), OutputManagerStorageError> { let start = Instant::now(); let conn = self.database_connection.get_pooled_connection()?; let acquire_lock = start.elapsed(); - let output = OutputSql::find_pending_coinbase_with_hash(hash, &conn)?; + let output = OutputSql::find_pending_coinbase_at_block_height(block_height, &conn)?; output.delete(&conn)?; if start.elapsed().as_millis() > 0 { trace!( target: LOG_TARGET, - "sqlite profile - clear_pending_coinbase_transaction_with_hash: lock {} + db_op {} = {} ms", + "sqlite profile - clear_pending_coinbase_transaction_at_block_height: lock {} + db_op {} = {} ms", acquire_lock.as_millis(), (start.elapsed() - acquire_lock).as_millis(), start.elapsed().as_millis() diff --git a/base_layer/wallet/src/output_manager_service/storage/sqlite_db/output_sql.rs b/base_layer/wallet/src/output_manager_service/storage/sqlite_db/output_sql.rs index cfedab1288..8e6cbdd476 100644 --- a/base_layer/wallet/src/output_manager_service/storage/sqlite_db/output_sql.rs +++ b/base_layer/wallet/src/output_manager_service/storage/sqlite_db/output_sql.rs @@ -576,16 +576,6 @@ impl OutputSql { .first::(conn)?) } - pub fn find_pending_coinbase_with_hash( - hash: &[u8], - conn: &SqliteConnection, - ) -> Result { - Ok(outputs::table - .filter(outputs::status.ne(OutputStatus::Unspent as i32)) - .filter(outputs::hash.eq(Some(hash))) - .first::(conn)?) - } - /// Find a particular Output, if it exists and is in the specified Spent state pub fn find_pending_coinbase_at_block_height( block_height: u64, From 766e6b08b21704a088b05e90284e6b6d31b6a469 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Wed, 17 Aug 2022 13:14:49 +0100 Subject: [PATCH 03/15] first commit --- .../tari_console_wallet/src/grpc/wallet_grpc_server.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs b/applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs index 7cb6609c23..27b01929a0 100644 --- a/applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs +++ b/applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs @@ -198,9 +198,9 @@ impl wallet_server::Wallet for WalletGrpcServer { async fn identify(&self, _: Request) -> Result, Status> { let identity = self.wallet.comms.node_identity(); Ok(Response::new(GetIdentityResponse { - public_key: identity.public_key().to_string().into_bytes(), + public_key: identity.public_key().to_vec(), public_address: identity.public_address().to_string(), - node_id: identity.node_id().to_string().into_bytes(), + node_id: identity.node_id().to_vec(), })) } From 79d5701fee7d667c45328a3b22b9a3ffb0f7cd44 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Thu, 18 Aug 2022 13:53:05 +0100 Subject: [PATCH 04/15] refactor cucumber tests --- integration_tests/features/support/ffi_steps.js | 4 ++-- integration_tests/features/support/steps.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/integration_tests/features/support/ffi_steps.js b/integration_tests/features/support/ffi_steps.js index 14ba852583..a3d7190adb 100644 --- a/integration_tests/features/support/ffi_steps.js +++ b/integration_tests/features/support/ffi_steps.js @@ -646,7 +646,7 @@ Then("I want to get public key of ffi wallet {word}", function (name) { let wallet = this.getWallet(name); let public_key = wallet.identify(); expect(public_key.length).to.be.equal( - 64, + 32, `Public key has wrong length : ${public_key}` ); }); @@ -723,7 +723,7 @@ Then( () => { let publicKeys = wallet.listConnectedPublicKeys(); return ( - publicKeys && publicKeys.some((p) => p === nodeIdentity.public_key) + publicKeys && publicKeys.some((p) => p === nodeIdentity.public_key.toString("hex")) ); }, true, diff --git a/integration_tests/features/support/steps.js b/integration_tests/features/support/steps.js index 44ae055d78..c934c8ca5a 100644 --- a/integration_tests/features/support/steps.js +++ b/integration_tests/features/support/steps.js @@ -519,7 +519,7 @@ Then(/(.*) is connected to (.*)/, async function (firstNode, secondNode) { const secondNodeIdentity = await secondNodeClient.identify(); let peers = await firstNodeClient.listConnectedPeers(); expect( - peers.some((p) => secondNodeIdentity.public_key === p.public_key) + peers.some((p) => secondNodeIdentity.public_key.toString("hex") === p.public_key) ).to.be.true; }); From f965c27784e1c7bc4d0c255a1dde0add1293ba74 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Thu, 18 Aug 2022 15:12:51 +0100 Subject: [PATCH 05/15] refactor cucumber tests --- integration_tests/features/support/ffi_steps.js | 2 +- integration_tests/features/support/steps.js | 4 +++- integration_tests/features/support/world.js | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/integration_tests/features/support/ffi_steps.js b/integration_tests/features/support/ffi_steps.js index a3d7190adb..1b7e805902 100644 --- a/integration_tests/features/support/ffi_steps.js +++ b/integration_tests/features/support/ffi_steps.js @@ -723,7 +723,7 @@ Then( () => { let publicKeys = wallet.listConnectedPublicKeys(); return ( - publicKeys && publicKeys.some((p) => p === nodeIdentity.public_key.toString("hex")) + publicKeys && publicKeys.some((p) => p === nodeIdentity.public_key) ); }, true, diff --git a/integration_tests/features/support/steps.js b/integration_tests/features/support/steps.js index c934c8ca5a..33c4cd9662 100644 --- a/integration_tests/features/support/steps.js +++ b/integration_tests/features/support/steps.js @@ -519,7 +519,9 @@ Then(/(.*) is connected to (.*)/, async function (firstNode, secondNode) { const secondNodeIdentity = await secondNodeClient.identify(); let peers = await firstNodeClient.listConnectedPeers(); expect( - peers.some((p) => secondNodeIdentity.public_key.toString("hex") === p.public_key) + peers.some((p) => { + secondNodeIdentity.public_key.toString("hex") === p.public_key; + }) ).to.be.true; }); diff --git a/integration_tests/features/support/world.js b/integration_tests/features/support/world.js index 37db97cfa8..3fae5e1a03 100644 --- a/integration_tests/features/support/world.js +++ b/integration_tests/features/support/world.js @@ -154,7 +154,7 @@ class CustomWorld { const wallet = new WalletFFIClient(name); await wallet.startNew(seed_words, passphrase); this.walletsFFI[name] = wallet; - this.walletPubkeys[name] = wallet.identify(); + this.walletPubkeys[name] = wallet.identify().public_key; return wallet; } From 209926a3851387fa4de5a7f6639ad356cc84ddc6 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Fri, 19 Aug 2022 09:11:14 +0100 Subject: [PATCH 06/15] refactor cucumber tests --- integration_tests/features/support/ffi_steps.js | 2 +- integration_tests/features/support/steps.js | 2 +- integration_tests/features/support/world.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/integration_tests/features/support/ffi_steps.js b/integration_tests/features/support/ffi_steps.js index 1b7e805902..14ba852583 100644 --- a/integration_tests/features/support/ffi_steps.js +++ b/integration_tests/features/support/ffi_steps.js @@ -646,7 +646,7 @@ Then("I want to get public key of ffi wallet {word}", function (name) { let wallet = this.getWallet(name); let public_key = wallet.identify(); expect(public_key.length).to.be.equal( - 32, + 64, `Public key has wrong length : ${public_key}` ); }); diff --git a/integration_tests/features/support/steps.js b/integration_tests/features/support/steps.js index 33c4cd9662..efbafc7a42 100644 --- a/integration_tests/features/support/steps.js +++ b/integration_tests/features/support/steps.js @@ -520,7 +520,7 @@ Then(/(.*) is connected to (.*)/, async function (firstNode, secondNode) { let peers = await firstNodeClient.listConnectedPeers(); expect( peers.some((p) => { - secondNodeIdentity.public_key.toString("hex") === p.public_key; + secondNodeIdentity.public_key === p.public_key; }) ).to.be.true; }); diff --git a/integration_tests/features/support/world.js b/integration_tests/features/support/world.js index 3fae5e1a03..37db97cfa8 100644 --- a/integration_tests/features/support/world.js +++ b/integration_tests/features/support/world.js @@ -154,7 +154,7 @@ class CustomWorld { const wallet = new WalletFFIClient(name); await wallet.startNew(seed_words, passphrase); this.walletsFFI[name] = wallet; - this.walletPubkeys[name] = wallet.identify().public_key; + this.walletPubkeys[name] = wallet.identify(); return wallet; } From 85082c0ebf2ddd080b98258ae5aa69e52023b532 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Fri, 19 Aug 2022 13:51:08 +0100 Subject: [PATCH 07/15] change 32-byte little endian representation of pub key to hex representation --- applications/tari_app_grpc/proto/network.proto | 2 +- applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/applications/tari_app_grpc/proto/network.proto b/applications/tari_app_grpc/proto/network.proto index 63dcdb463e..10415e29ed 100644 --- a/applications/tari_app_grpc/proto/network.proto +++ b/applications/tari_app_grpc/proto/network.proto @@ -95,7 +95,7 @@ message SoftwareUpdate { message GetIdentityRequest { } message GetIdentityResponse { - bytes public_key = 1; + string public_key = 1; string public_address = 2; bytes node_id = 3; } diff --git a/applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs b/applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs index 27b01929a0..692a50ef89 100644 --- a/applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs +++ b/applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs @@ -198,7 +198,7 @@ impl wallet_server::Wallet for WalletGrpcServer { async fn identify(&self, _: Request) -> Result, Status> { let identity = self.wallet.comms.node_identity(); Ok(Response::new(GetIdentityResponse { - public_key: identity.public_key().to_vec(), + public_key: identity.public_key().to_string(), public_address: identity.public_address().to_string(), node_id: identity.node_id().to_vec(), })) From 6bf8ba63f4999f38853373baf17300f601c518a6 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Fri, 19 Aug 2022 15:59:53 +0100 Subject: [PATCH 08/15] formatting --- integration_tests/features/support/steps.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/integration_tests/features/support/steps.js b/integration_tests/features/support/steps.js index efbafc7a42..44ae055d78 100644 --- a/integration_tests/features/support/steps.js +++ b/integration_tests/features/support/steps.js @@ -519,9 +519,7 @@ Then(/(.*) is connected to (.*)/, async function (firstNode, secondNode) { const secondNodeIdentity = await secondNodeClient.identify(); let peers = await firstNodeClient.listConnectedPeers(); expect( - peers.some((p) => { - secondNodeIdentity.public_key === p.public_key; - }) + peers.some((p) => secondNodeIdentity.public_key === p.public_key) ).to.be.true; }); From 9fc96c7915adbada1b9331a8c1a6bfc70948c4d8 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Fri, 19 Aug 2022 18:00:35 +0100 Subject: [PATCH 09/15] add little endian representation of public key --- applications/tari_app_grpc/proto/network.proto | 2 +- applications/tari_app_grpc/proto/wallet.proto | 4 ++-- .../tari_console_wallet/src/grpc/wallet_grpc_server.rs | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/applications/tari_app_grpc/proto/network.proto b/applications/tari_app_grpc/proto/network.proto index 10415e29ed..63dcdb463e 100644 --- a/applications/tari_app_grpc/proto/network.proto +++ b/applications/tari_app_grpc/proto/network.proto @@ -95,7 +95,7 @@ message SoftwareUpdate { message GetIdentityRequest { } message GetIdentityResponse { - string public_key = 1; + bytes public_key = 1; string public_address = 2; bytes node_id = 3; } diff --git a/applications/tari_app_grpc/proto/wallet.proto b/applications/tari_app_grpc/proto/wallet.proto index 2e08212ad5..8ea368948f 100644 --- a/applications/tari_app_grpc/proto/wallet.proto +++ b/applications/tari_app_grpc/proto/wallet.proto @@ -100,7 +100,7 @@ message CreateBurnTransactionRequest{ } message PaymentRecipient { - string address = 1; + bytes address = 1; uint64 amount = 2; uint64 fee_per_gram = 3; string message = 4; @@ -131,7 +131,7 @@ message CreateBurnTransactionResponse{ } message TransferResult { - string address = 1; + bytes address = 1; uint64 transaction_id = 2; bool is_success = 3; string failure_message = 4; diff --git a/applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs b/applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs index 692a50ef89..7c47435f86 100644 --- a/applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs +++ b/applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs @@ -198,7 +198,7 @@ impl wallet_server::Wallet for WalletGrpcServer { async fn identify(&self, _: Request) -> Result, Status> { let identity = self.wallet.comms.node_identity(); Ok(Response::new(GetIdentityResponse { - public_key: identity.public_key().to_string(), + public_key: Vec::from(identity.public_key().as_bytes()), public_address: identity.public_address().to_string(), node_id: identity.node_id().to_vec(), })) @@ -301,7 +301,7 @@ impl wallet_server::Wallet for WalletGrpcServer { .into_inner() .recipient .ok_or_else(|| Status::internal("Request is malformed".to_string()))?; - let address = CommsPublicKey::from_hex(&message.address) + let address = CommsPublicKey::from_hex(&message.address.to_hex()) .map_err(|_| Status::internal("Destination address is malformed".to_string()))?; let mut transaction_service = self.get_transaction_service(); @@ -461,7 +461,7 @@ impl wallet_server::Wallet for WalletGrpcServer { .into_iter() .enumerate() .map(|(idx, dest)| -> Result<_, String> { - let pk = CommsPublicKey::from_hex(&dest.address) + let pk = CommsPublicKey::from_hex(&dest.address.to_hex()) .map_err(|_| format!("Destination address at index {} is malformed", idx))?; Ok(( dest.address, @@ -530,7 +530,7 @@ impl wallet_server::Wallet for WalletGrpcServer { Err(err) => { warn!( target: LOG_TARGET, - "Failed to send transaction for address `{}`: {}", address, err + "Failed to send transaction for address `{}`: {}", address.to_hex(), err ); TransferResult { address, From f5d54365cdcc1c8e2f8d667d2a8161136042d3d1 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Mon, 22 Aug 2022 13:33:55 +0100 Subject: [PATCH 10/15] refactor cucumber tests --- applications/tari_app_grpc/proto/wallet.proto | 4 +- .../src/grpc/wallet_grpc_server.rs | 8 +- .../features/support/ffi_steps.js | 4 +- integration_tests/features/support/steps.js | 6 +- .../features/support/wallet_steps.js | 96 +++++++++---------- integration_tests/features/support/world.js | 8 +- integration_tests/helpers/walletClient.js | 4 +- 7 files changed, 65 insertions(+), 65 deletions(-) diff --git a/applications/tari_app_grpc/proto/wallet.proto b/applications/tari_app_grpc/proto/wallet.proto index 8ea368948f..2e08212ad5 100644 --- a/applications/tari_app_grpc/proto/wallet.proto +++ b/applications/tari_app_grpc/proto/wallet.proto @@ -100,7 +100,7 @@ message CreateBurnTransactionRequest{ } message PaymentRecipient { - bytes address = 1; + string address = 1; uint64 amount = 2; uint64 fee_per_gram = 3; string message = 4; @@ -131,7 +131,7 @@ message CreateBurnTransactionResponse{ } message TransferResult { - bytes address = 1; + string address = 1; uint64 transaction_id = 2; bool is_success = 3; string failure_message = 4; diff --git a/applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs b/applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs index 7c47435f86..27b01929a0 100644 --- a/applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs +++ b/applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs @@ -198,7 +198,7 @@ impl wallet_server::Wallet for WalletGrpcServer { async fn identify(&self, _: Request) -> Result, Status> { let identity = self.wallet.comms.node_identity(); Ok(Response::new(GetIdentityResponse { - public_key: Vec::from(identity.public_key().as_bytes()), + public_key: identity.public_key().to_vec(), public_address: identity.public_address().to_string(), node_id: identity.node_id().to_vec(), })) @@ -301,7 +301,7 @@ impl wallet_server::Wallet for WalletGrpcServer { .into_inner() .recipient .ok_or_else(|| Status::internal("Request is malformed".to_string()))?; - let address = CommsPublicKey::from_hex(&message.address.to_hex()) + let address = CommsPublicKey::from_hex(&message.address) .map_err(|_| Status::internal("Destination address is malformed".to_string()))?; let mut transaction_service = self.get_transaction_service(); @@ -461,7 +461,7 @@ impl wallet_server::Wallet for WalletGrpcServer { .into_iter() .enumerate() .map(|(idx, dest)| -> Result<_, String> { - let pk = CommsPublicKey::from_hex(&dest.address.to_hex()) + let pk = CommsPublicKey::from_hex(&dest.address) .map_err(|_| format!("Destination address at index {} is malformed", idx))?; Ok(( dest.address, @@ -530,7 +530,7 @@ impl wallet_server::Wallet for WalletGrpcServer { Err(err) => { warn!( target: LOG_TARGET, - "Failed to send transaction for address `{}`: {}", address.to_hex(), err + "Failed to send transaction for address `{}`: {}", address, err ); TransferResult { address, diff --git a/integration_tests/features/support/ffi_steps.js b/integration_tests/features/support/ffi_steps.js index 14ba852583..a3d7190adb 100644 --- a/integration_tests/features/support/ffi_steps.js +++ b/integration_tests/features/support/ffi_steps.js @@ -646,7 +646,7 @@ Then("I want to get public key of ffi wallet {word}", function (name) { let wallet = this.getWallet(name); let public_key = wallet.identify(); expect(public_key.length).to.be.equal( - 64, + 32, `Public key has wrong length : ${public_key}` ); }); @@ -723,7 +723,7 @@ Then( () => { let publicKeys = wallet.listConnectedPublicKeys(); return ( - publicKeys && publicKeys.some((p) => p === nodeIdentity.public_key) + publicKeys && publicKeys.some((p) => p === nodeIdentity.public_key.toString("hex")) ); }, true, diff --git a/integration_tests/features/support/steps.js b/integration_tests/features/support/steps.js index 44ae055d78..5b72086d3d 100644 --- a/integration_tests/features/support/steps.js +++ b/integration_tests/features/support/steps.js @@ -436,7 +436,7 @@ Then( const walletInfo = await walletClient.identify(); const miningNode = this.getMiningNode(miner); - const txIds = this.transactionsMap.get(walletInfo.public_key); + const txIds = this.transactionsMap.get(walletInfo); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -508,7 +508,7 @@ When( await waitForPredicate(async () => { let peers = await firstNodeClient.listConnectedPeers(); - return peers.some((p) => secondNodeIdentity.public_key === p.public_key); + return peers.some((p) => secondNodeIdentity.public_key.toString("hex") === p.public_key); }, 50 * 1000); } ); @@ -519,7 +519,7 @@ Then(/(.*) is connected to (.*)/, async function (firstNode, secondNode) { const secondNodeIdentity = await secondNodeClient.identify(); let peers = await firstNodeClient.listConnectedPeers(); expect( - peers.some((p) => secondNodeIdentity.public_key === p.public_key) + peers.some((p) => secondNodeIdentity.public_key.toString("hex") === p.public_key) ).to.be.true; }); diff --git a/integration_tests/features/support/wallet_steps.js b/integration_tests/features/support/wallet_steps.js index 95646c2f59..c596d44550 100644 --- a/integration_tests/features/support/wallet_steps.js +++ b/integration_tests/features/support/wallet_steps.js @@ -95,7 +95,7 @@ Given( this.addWallet(walletName, wallet); let walletClient = await this.getWallet(walletName).connectClient(); let walletInfo = await walletClient.identify(); - this.addWalletPubkey(walletName, walletInfo.public_key); + this.addWalletPubkey(walletName, walletInfo.public_key.toString("hex")); } ); @@ -114,7 +114,7 @@ Given( this.addWallet(name, wallet); let walletClient = await this.getWallet(name).connectClient(); let walletInfo = await walletClient.identify(); - this.addWalletPubkey(name, walletInfo.public_key); + this.addWalletPubkey(name, walletInfo.public_key.toString("hex")); } ); @@ -197,7 +197,7 @@ Given( this.addWallet(name, wallet); let walletClient = await this.getWallet(name).connectClient(); let walletInfo = await walletClient.identify(); - this.addWalletPubkey(name, walletInfo.public_key); + this.addWalletPubkey(name, walletInfo.public_key.toString("hex")); } ); @@ -245,7 +245,7 @@ Given( this.addWallet(walletNameB, walletB); let walletClient = await this.getWallet(walletNameB).connectClient(); let walletInfo = await walletClient.identify(); - this.addWalletPubkey(walletNameB, walletInfo.public_key); + this.addWalletPubkey(walletNameB, walletInfo.public_key.toString("hex")); } ); @@ -280,7 +280,7 @@ Given( recoveredWalletName ).connectClient(); let walletInfo = await walletClient.identify(); - this.addWalletPubkey(recoveredWalletName, walletInfo.public_key); + this.addWalletPubkey(recoveredWalletName, walletInfo.public_key.toString("hex")); } } ); @@ -312,7 +312,7 @@ Given( this.addWallet(i, wallet); let walletClient = await this.getWallet(i.toString()).connectClient(); let walletInfo = await walletClient.identify(); - this.addWalletPubkey(wallet, walletInfo.public_key); + this.addWalletPubkey(wallet, walletInfo.public_key.toString("hex")); } } ); @@ -528,7 +528,7 @@ When( try { this.lastResult = await sourceClient.sendHtlc({ recipient: { - address: destInfo.public_key, + address: destInfo.public_key.toString("hex"), amount: tariAmount, fee_per_gram: feePerGram, message: "msg", @@ -566,10 +566,10 @@ When( } if (success) { this.addTransaction( - sourceInfo.public_key, + sourceInfo.public_key.toString("hex"), this.lastResult.transaction_id ); - this.addTransaction(destInfo.public_key, this.lastResult.transaction_id); + this.addTransaction(destInfo.public_key.toString("hex"), this.lastResult.transaction_id); } expect(success).to.equal(true); //lets now wait for this transaction to be at least broadcast before we continue. @@ -643,7 +643,7 @@ When( if (success) { this.addTransaction( - sourceInfo.public_key, + sourceInfo.public_key.toString("hex"), this.lastResult.results.transaction_id ); } @@ -721,7 +721,7 @@ When( if (success) { this.addTransaction( - sourceInfo.public_key, + sourceInfo.public_key.toString("hex"), this.lastResult.results.transaction_id ); } @@ -754,7 +754,7 @@ When( const sourceClient = await sourceWallet.connectClient(); const sourceInfo = await sourceClient.identify(); - const destPublicKey = this.getWalletPubkey(dest); + const destPublicKey = this.getWalletPubkey(dest).toString("hex"); this.lastResult = await this.send_tari( sourceWallet, @@ -796,7 +796,7 @@ When( this.lastResult = await this.send_tari( this.getWallet(source), destInfo.name, - destInfo.public_key, + destInfo.public_key.toString("hex"), tariAmount, fee ); @@ -848,18 +848,18 @@ When( this.lastResult = await this.send_tari( this.getWallet(source), destInfo.name, - destInfo.public_key, + destInfo.public_key.toString("hex"), tariAmount, fee ); expect(this.lastResult.results[0].is_success).to.equal(true); tx_ids.push(this.lastResult.results[0].transaction_id); this.addTransaction( - sourceInfo.public_key, + sourceInfo.public_key.toString("hex"), this.lastResult.results[0].transaction_id ); this.addTransaction( - destInfo.public_key, + destInfo.public_key.toString("hex"), this.lastResult.results[0].transaction_id ); // console.log(" Transaction '" + this.lastResult.results[0]["transaction_id"] + "' is_success(" + @@ -914,13 +914,13 @@ When( lastResult = await sourceClient.transfer({ recipients: [ { - address: dest1Info.public_key, + address: dest1Info.public_key.toString("hex"), amount: tariAmount, fee_per_gram: feePerGram, message: "msg", }, { - address: dest2Info.public_key, + address: dest2Info.public_key.toString("hex"), amount: tariAmount, fee_per_gram: feePerGram, message: "msg", @@ -960,19 +960,19 @@ When( } if (success) { this.addTransaction( - sourceInfo.public_key, + sourceInfo.public_key.toString("hex"), lastResult.results[0].transaction_id ); this.addTransaction( - sourceInfo.public_key, + sourceInfo.public_key.toString("hex"), lastResult.results[1].transaction_id ); this.addTransaction( - dest1Info.public_key, + dest1Info.public_key.toString("hex"), lastResult.results[0].transaction_id ); this.addTransaction( - dest2Info.public_key, + dest2Info.public_key.toString("hex"), lastResult.results[1].transaction_id ); } @@ -989,14 +989,14 @@ When( this.lastResult = await this.send_tari( this.getWallet(source), sourceInfo.name, - sourceInfo.public_key, + sourceInfo.public_key.toString("hex"), tariAmount, feePerGram ); expect(this.lastResult.results[0].is_success).to.equal(true); this.addTransaction( - sourceInfo.public_key, + sourceInfo.public_key.toString("hex"), this.lastResult.results[0].transaction_id ); console.log( @@ -1040,7 +1040,7 @@ When( async () => { try { const recipients = destWallets.map((w) => ({ - address: w.public_key, + address: w.public_key.toString("hex"), amount: amount, fee_per_gram: feePerGram, message: "msg", @@ -1076,7 +1076,7 @@ When( const lastResult = await this.send_tari( sourceWallet, dest, - destPublicKey, + destPublicKey.toString("hex"), amount, feePerGram, PaymentType.ONE_SIDED @@ -1084,7 +1084,7 @@ When( expect(lastResult.results[0].is_success).to.equal(true); this.addTransaction( - sourceInfo.public_key, + sourceInfo.public_key.toString("hex"), lastResult.results[0].transaction_id ); //lets now wait for this transaction to be at least broadcast before we continue. @@ -1118,7 +1118,7 @@ When( const lastResult = await this.send_tari( sourceWallet, dest, - destPublicKey, + destPublicKey.toString("hex"), amount, feePerGram, PaymentType.ONE_SIDED_TO_STEALTH_ADDRESS @@ -1126,7 +1126,7 @@ When( expect(lastResult.results[0].is_success).to.equal(true); this.addTransaction( - sourceInfo.public_key, + sourceInfo.public_key.toString("hex"), lastResult.results[0].transaction_id ); //lets now wait for this transaction to be at least broadcast before we continue. @@ -1158,7 +1158,7 @@ When( const lastResult = await this.burn_tari(sourceWallet, amount, feePerGram); expect(lastResult.is_success).to.equal(true); - this.addTransaction(sourceInfo.public_key, lastResult.transaction_id); + this.addTransaction(sourceInfo.public_key.toString("hex"), lastResult.transaction_id); //lets now wait for this transaction to be at least broadcast before we continue. await waitFor( async () => @@ -1262,7 +1262,7 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key); + const txIds = this.transactionsMap.get(walletInfo.public_key.toString("hex")); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1312,7 +1312,7 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key); + const txIds = this.transactionsMap.get(walletInfo.public_key.toString("hex")); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1420,7 +1420,7 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key); + const txIds = this.transactionsMap.get(walletInfo.public_key.toString("hex")); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1469,7 +1469,7 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key); + const txIds = this.transactionsMap.get(walletInfo.public_key.toString("hex")); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1518,7 +1518,7 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - let txIds = this.transactionsMap.get(walletInfo.public_key); + let txIds = this.transactionsMap.get(walletInfo.public_key.toString("hex")); console.log(walletName, txIds); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); @@ -1568,7 +1568,7 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key); + const txIds = this.transactionsMap.get(walletInfo.public_key.toString("hex")); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1617,7 +1617,7 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key); + const txIds = this.transactionsMap.get(walletInfo.public_key.toString("hex")); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1665,7 +1665,7 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key); + const txIds = this.transactionsMap.get(walletInfo.public_key.toString("hex")); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1713,7 +1713,7 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key); + const txIds = this.transactionsMap.get(walletInfo.public_key.toString("hex")); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1761,7 +1761,7 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key); + const txIds = this.transactionsMap.get(walletInfo.public_key.toString("hex")); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1809,7 +1809,7 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key); + const txIds = this.transactionsMap.get(walletInfo.public_key.toString("hex")); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1855,7 +1855,7 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); const nodeClient = this.getClient(nodeName); - const txIds = this.transactionsMap.get(walletInfo.public_key); + const txIds = this.transactionsMap.get(walletInfo.public_key.toString("hex")); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); throw new Error("No transactions for " + walletName + "!"); @@ -1916,7 +1916,7 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key); + const txIds = this.transactionsMap.get(walletInfo.public_key.toString("hex")); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -2295,7 +2295,7 @@ When( " completed with TxId: ", result ); - this.addTransaction(walletInfo.public_key, result.tx_id); + this.addTransaction(walletInfo.public_key.toString("hex"), result.tx_id); this.lastResult = result; } } @@ -2318,7 +2318,6 @@ When( const sourceInfo = await sourceWalletClient.identify(); const destWalletClient = await this.getWallet(destWallet).connectClient(); const destInfo = await destWalletClient.identify(); - console.log( "Sending", numTransactions, @@ -2330,11 +2329,12 @@ When( let batch = 1; let tx_ids = []; + for (let i = 0; i < numTransactions; i++) { const result = await this.send_tari( this.getWallet(sourceWallet), destInfo.name, - destInfo.public_key, + destInfo.public_key.toString("hex"), amount, feePerGram, false, @@ -2344,11 +2344,11 @@ When( expect(result.results[0].is_success).to.equal(true); tx_ids.push(result.results[0].transaction_id); this.addTransaction( - sourceInfo.public_key, + sourceInfo.public_key.toString("hex"), result.results[0].transaction_id ); this.addTransaction( - destInfo.public_key, + destInfo.public_key.toString("hex"), result.results[0].transaction_id ); diff --git a/integration_tests/features/support/world.js b/integration_tests/features/support/world.js index 37db97cfa8..dca7f5a100 100644 --- a/integration_tests/features/support/world.js +++ b/integration_tests/features/support/world.js @@ -17,7 +17,7 @@ const TransactionBuilder = require("../../helpers/transactionBuilder"); const glob = require("glob"); const fs = require("fs"); const archiver = require("archiver"); -const { waitFor, sleep, consoleLogBalance } = require("../../helpers/util"); +const { waitFor, sleep, encodeOption, consoleLogBalance } = require("../../helpers/util"); const { PaymentType } = require("../../helpers/types"); const { expect } = require("chai"); const InterfaceFFI = require("../../helpers/ffi/ffiInterface"); @@ -147,14 +147,14 @@ class CustomWorld { this.addWallet(name, wallet); let walletClient = await wallet.connectClient(); let walletInfo = await walletClient.identify(); - this.walletPubkeys[name] = walletInfo.public_key; + this.walletPubkeys[name] = walletInfo.public_key.toString("hex"); } async createAndAddFFIWallet(name, seed_words = null, passphrase = null) { const wallet = new WalletFFIClient(name); await wallet.startNew(seed_words, passphrase); this.walletsFFI[name] = wallet; - this.walletPubkeys[name] = wallet.identify(); + this.walletPubkeys[name] = wallet.identify().public_key.toString("hex"); return wallet; } @@ -608,7 +608,7 @@ class CustomWorld { const sourceClient = await sourceWallet.connectClient(); const sourceInfo = await sourceClient.identify(); - const destPublicKey = this.getWalletPubkey(dest); + const destPublicKey = this.getWalletPubkey(dest).toString("hex"); this.lastResult = await this.send_tari( sourceWallet, diff --git a/integration_tests/helpers/walletClient.js b/integration_tests/helpers/walletClient.js index 962a24114e..55a957a08e 100644 --- a/integration_tests/helpers/walletClient.js +++ b/integration_tests/helpers/walletClient.js @@ -180,9 +180,9 @@ class WalletClient { async identify() { const info = await this.client.identify(); return { - public_key: info.public_key.toString("utf8"), + public_key: info.public_key, public_address: info.public_address, - node_id: info.node_id.toString("utf8"), + node_id: info.node_id, }; } From bba5f95a3f1640c9b21f35dfd251a6e5001d7700 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Mon, 22 Aug 2022 13:56:32 +0100 Subject: [PATCH 11/15] refactor cucumber tests --- .../features/support/ffi_steps.js | 3 +- integration_tests/features/support/steps.js | 8 ++- .../features/support/wallet_steps.js | 63 ++++++++++++++----- integration_tests/features/support/world.js | 2 +- 4 files changed, 57 insertions(+), 19 deletions(-) diff --git a/integration_tests/features/support/ffi_steps.js b/integration_tests/features/support/ffi_steps.js index a3d7190adb..3c2b58a636 100644 --- a/integration_tests/features/support/ffi_steps.js +++ b/integration_tests/features/support/ffi_steps.js @@ -723,7 +723,8 @@ Then( () => { let publicKeys = wallet.listConnectedPublicKeys(); return ( - publicKeys && publicKeys.some((p) => p === nodeIdentity.public_key.toString("hex")) + publicKeys && + publicKeys.some((p) => p === nodeIdentity.public_key.toString("hex")) ); }, true, diff --git a/integration_tests/features/support/steps.js b/integration_tests/features/support/steps.js index 5b72086d3d..7ce4a297c7 100644 --- a/integration_tests/features/support/steps.js +++ b/integration_tests/features/support/steps.js @@ -508,7 +508,9 @@ When( await waitForPredicate(async () => { let peers = await firstNodeClient.listConnectedPeers(); - return peers.some((p) => secondNodeIdentity.public_key.toString("hex") === p.public_key); + return peers.some( + (p) => secondNodeIdentity.public_key.toString("hex") === p.public_key + ); }, 50 * 1000); } ); @@ -519,7 +521,9 @@ Then(/(.*) is connected to (.*)/, async function (firstNode, secondNode) { const secondNodeIdentity = await secondNodeClient.identify(); let peers = await firstNodeClient.listConnectedPeers(); expect( - peers.some((p) => secondNodeIdentity.public_key.toString("hex") === p.public_key) + peers.some( + (p) => secondNodeIdentity.public_key.toString("hex") === p.public_key + ) ).to.be.true; }); diff --git a/integration_tests/features/support/wallet_steps.js b/integration_tests/features/support/wallet_steps.js index c596d44550..b94a60c931 100644 --- a/integration_tests/features/support/wallet_steps.js +++ b/integration_tests/features/support/wallet_steps.js @@ -280,7 +280,10 @@ Given( recoveredWalletName ).connectClient(); let walletInfo = await walletClient.identify(); - this.addWalletPubkey(recoveredWalletName, walletInfo.public_key.toString("hex")); + this.addWalletPubkey( + recoveredWalletName, + walletInfo.public_key.toString("hex") + ); } } ); @@ -569,7 +572,10 @@ When( sourceInfo.public_key.toString("hex"), this.lastResult.transaction_id ); - this.addTransaction(destInfo.public_key.toString("hex"), this.lastResult.transaction_id); + this.addTransaction( + destInfo.public_key.toString("hex"), + this.lastResult.transaction_id + ); } expect(success).to.equal(true); //lets now wait for this transaction to be at least broadcast before we continue. @@ -1158,7 +1164,10 @@ When( const lastResult = await this.burn_tari(sourceWallet, amount, feePerGram); expect(lastResult.is_success).to.equal(true); - this.addTransaction(sourceInfo.public_key.toString("hex"), lastResult.transaction_id); + this.addTransaction( + sourceInfo.public_key.toString("hex"), + lastResult.transaction_id + ); //lets now wait for this transaction to be at least broadcast before we continue. await waitFor( async () => @@ -1262,7 +1271,9 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key.toString("hex")); + const txIds = this.transactionsMap.get( + walletInfo.public_key.toString("hex") + ); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1312,7 +1323,9 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key.toString("hex")); + const txIds = this.transactionsMap.get( + walletInfo.public_key.toString("hex") + ); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1420,7 +1433,9 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key.toString("hex")); + const txIds = this.transactionsMap.get( + walletInfo.public_key.toString("hex") + ); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1469,7 +1484,9 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key.toString("hex")); + const txIds = this.transactionsMap.get( + walletInfo.public_key.toString("hex") + ); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1568,7 +1585,9 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key.toString("hex")); + const txIds = this.transactionsMap.get( + walletInfo.public_key.toString("hex") + ); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1617,7 +1636,9 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key.toString("hex")); + const txIds = this.transactionsMap.get( + walletInfo.public_key.toString("hex") + ); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1665,7 +1686,9 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key.toString("hex")); + const txIds = this.transactionsMap.get( + walletInfo.public_key.toString("hex") + ); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1713,7 +1736,9 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key.toString("hex")); + const txIds = this.transactionsMap.get( + walletInfo.public_key.toString("hex") + ); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1761,7 +1786,9 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key.toString("hex")); + const txIds = this.transactionsMap.get( + walletInfo.public_key.toString("hex") + ); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1809,7 +1836,9 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key.toString("hex")); + const txIds = this.transactionsMap.get( + walletInfo.public_key.toString("hex") + ); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1855,7 +1884,9 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); const nodeClient = this.getClient(nodeName); - const txIds = this.transactionsMap.get(walletInfo.public_key.toString("hex")); + const txIds = this.transactionsMap.get( + walletInfo.public_key.toString("hex") + ); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); throw new Error("No transactions for " + walletName + "!"); @@ -1916,7 +1947,9 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key.toString("hex")); + const txIds = this.transactionsMap.get( + walletInfo.public_key.toString("hex") + ); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); diff --git a/integration_tests/features/support/world.js b/integration_tests/features/support/world.js index dca7f5a100..31419b5424 100644 --- a/integration_tests/features/support/world.js +++ b/integration_tests/features/support/world.js @@ -17,7 +17,7 @@ const TransactionBuilder = require("../../helpers/transactionBuilder"); const glob = require("glob"); const fs = require("fs"); const archiver = require("archiver"); -const { waitFor, sleep, encodeOption, consoleLogBalance } = require("../../helpers/util"); +const { waitFor, sleep, consoleLogBalance } = require("../../helpers/util"); const { PaymentType } = require("../../helpers/types"); const { expect } = require("chai"); const InterfaceFFI = require("../../helpers/ffi/ffiInterface"); From 592886e25a8c52407f30c421bdc5c88e288e71f1 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Mon, 22 Aug 2022 15:30:25 +0100 Subject: [PATCH 12/15] remove undefined behavior --- .../features/support/ffi_steps.js | 3 +- integration_tests/features/support/steps.js | 10 +- .../features/support/wallet_steps.js | 129 +++++++----------- integration_tests/features/support/world.js | 4 +- 4 files changed, 54 insertions(+), 92 deletions(-) diff --git a/integration_tests/features/support/ffi_steps.js b/integration_tests/features/support/ffi_steps.js index 3c2b58a636..a3d7190adb 100644 --- a/integration_tests/features/support/ffi_steps.js +++ b/integration_tests/features/support/ffi_steps.js @@ -723,8 +723,7 @@ Then( () => { let publicKeys = wallet.listConnectedPublicKeys(); return ( - publicKeys && - publicKeys.some((p) => p === nodeIdentity.public_key.toString("hex")) + publicKeys && publicKeys.some((p) => p === nodeIdentity.public_key.toString("hex")) ); }, true, diff --git a/integration_tests/features/support/steps.js b/integration_tests/features/support/steps.js index 7ce4a297c7..c934c8ca5a 100644 --- a/integration_tests/features/support/steps.js +++ b/integration_tests/features/support/steps.js @@ -436,7 +436,7 @@ Then( const walletInfo = await walletClient.identify(); const miningNode = this.getMiningNode(miner); - const txIds = this.transactionsMap.get(walletInfo); + const txIds = this.transactionsMap.get(walletInfo.public_key); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -508,9 +508,7 @@ When( await waitForPredicate(async () => { let peers = await firstNodeClient.listConnectedPeers(); - return peers.some( - (p) => secondNodeIdentity.public_key.toString("hex") === p.public_key - ); + return peers.some((p) => secondNodeIdentity.public_key === p.public_key); }, 50 * 1000); } ); @@ -521,9 +519,7 @@ Then(/(.*) is connected to (.*)/, async function (firstNode, secondNode) { const secondNodeIdentity = await secondNodeClient.identify(); let peers = await firstNodeClient.listConnectedPeers(); expect( - peers.some( - (p) => secondNodeIdentity.public_key.toString("hex") === p.public_key - ) + peers.some((p) => secondNodeIdentity.public_key.toString("hex") === p.public_key) ).to.be.true; }); diff --git a/integration_tests/features/support/wallet_steps.js b/integration_tests/features/support/wallet_steps.js index b94a60c931..95646c2f59 100644 --- a/integration_tests/features/support/wallet_steps.js +++ b/integration_tests/features/support/wallet_steps.js @@ -95,7 +95,7 @@ Given( this.addWallet(walletName, wallet); let walletClient = await this.getWallet(walletName).connectClient(); let walletInfo = await walletClient.identify(); - this.addWalletPubkey(walletName, walletInfo.public_key.toString("hex")); + this.addWalletPubkey(walletName, walletInfo.public_key); } ); @@ -114,7 +114,7 @@ Given( this.addWallet(name, wallet); let walletClient = await this.getWallet(name).connectClient(); let walletInfo = await walletClient.identify(); - this.addWalletPubkey(name, walletInfo.public_key.toString("hex")); + this.addWalletPubkey(name, walletInfo.public_key); } ); @@ -197,7 +197,7 @@ Given( this.addWallet(name, wallet); let walletClient = await this.getWallet(name).connectClient(); let walletInfo = await walletClient.identify(); - this.addWalletPubkey(name, walletInfo.public_key.toString("hex")); + this.addWalletPubkey(name, walletInfo.public_key); } ); @@ -245,7 +245,7 @@ Given( this.addWallet(walletNameB, walletB); let walletClient = await this.getWallet(walletNameB).connectClient(); let walletInfo = await walletClient.identify(); - this.addWalletPubkey(walletNameB, walletInfo.public_key.toString("hex")); + this.addWalletPubkey(walletNameB, walletInfo.public_key); } ); @@ -280,10 +280,7 @@ Given( recoveredWalletName ).connectClient(); let walletInfo = await walletClient.identify(); - this.addWalletPubkey( - recoveredWalletName, - walletInfo.public_key.toString("hex") - ); + this.addWalletPubkey(recoveredWalletName, walletInfo.public_key); } } ); @@ -315,7 +312,7 @@ Given( this.addWallet(i, wallet); let walletClient = await this.getWallet(i.toString()).connectClient(); let walletInfo = await walletClient.identify(); - this.addWalletPubkey(wallet, walletInfo.public_key.toString("hex")); + this.addWalletPubkey(wallet, walletInfo.public_key); } } ); @@ -531,7 +528,7 @@ When( try { this.lastResult = await sourceClient.sendHtlc({ recipient: { - address: destInfo.public_key.toString("hex"), + address: destInfo.public_key, amount: tariAmount, fee_per_gram: feePerGram, message: "msg", @@ -569,13 +566,10 @@ When( } if (success) { this.addTransaction( - sourceInfo.public_key.toString("hex"), - this.lastResult.transaction_id - ); - this.addTransaction( - destInfo.public_key.toString("hex"), + sourceInfo.public_key, this.lastResult.transaction_id ); + this.addTransaction(destInfo.public_key, this.lastResult.transaction_id); } expect(success).to.equal(true); //lets now wait for this transaction to be at least broadcast before we continue. @@ -649,7 +643,7 @@ When( if (success) { this.addTransaction( - sourceInfo.public_key.toString("hex"), + sourceInfo.public_key, this.lastResult.results.transaction_id ); } @@ -727,7 +721,7 @@ When( if (success) { this.addTransaction( - sourceInfo.public_key.toString("hex"), + sourceInfo.public_key, this.lastResult.results.transaction_id ); } @@ -760,7 +754,7 @@ When( const sourceClient = await sourceWallet.connectClient(); const sourceInfo = await sourceClient.identify(); - const destPublicKey = this.getWalletPubkey(dest).toString("hex"); + const destPublicKey = this.getWalletPubkey(dest); this.lastResult = await this.send_tari( sourceWallet, @@ -802,7 +796,7 @@ When( this.lastResult = await this.send_tari( this.getWallet(source), destInfo.name, - destInfo.public_key.toString("hex"), + destInfo.public_key, tariAmount, fee ); @@ -854,18 +848,18 @@ When( this.lastResult = await this.send_tari( this.getWallet(source), destInfo.name, - destInfo.public_key.toString("hex"), + destInfo.public_key, tariAmount, fee ); expect(this.lastResult.results[0].is_success).to.equal(true); tx_ids.push(this.lastResult.results[0].transaction_id); this.addTransaction( - sourceInfo.public_key.toString("hex"), + sourceInfo.public_key, this.lastResult.results[0].transaction_id ); this.addTransaction( - destInfo.public_key.toString("hex"), + destInfo.public_key, this.lastResult.results[0].transaction_id ); // console.log(" Transaction '" + this.lastResult.results[0]["transaction_id"] + "' is_success(" + @@ -920,13 +914,13 @@ When( lastResult = await sourceClient.transfer({ recipients: [ { - address: dest1Info.public_key.toString("hex"), + address: dest1Info.public_key, amount: tariAmount, fee_per_gram: feePerGram, message: "msg", }, { - address: dest2Info.public_key.toString("hex"), + address: dest2Info.public_key, amount: tariAmount, fee_per_gram: feePerGram, message: "msg", @@ -966,19 +960,19 @@ When( } if (success) { this.addTransaction( - sourceInfo.public_key.toString("hex"), + sourceInfo.public_key, lastResult.results[0].transaction_id ); this.addTransaction( - sourceInfo.public_key.toString("hex"), + sourceInfo.public_key, lastResult.results[1].transaction_id ); this.addTransaction( - dest1Info.public_key.toString("hex"), + dest1Info.public_key, lastResult.results[0].transaction_id ); this.addTransaction( - dest2Info.public_key.toString("hex"), + dest2Info.public_key, lastResult.results[1].transaction_id ); } @@ -995,14 +989,14 @@ When( this.lastResult = await this.send_tari( this.getWallet(source), sourceInfo.name, - sourceInfo.public_key.toString("hex"), + sourceInfo.public_key, tariAmount, feePerGram ); expect(this.lastResult.results[0].is_success).to.equal(true); this.addTransaction( - sourceInfo.public_key.toString("hex"), + sourceInfo.public_key, this.lastResult.results[0].transaction_id ); console.log( @@ -1046,7 +1040,7 @@ When( async () => { try { const recipients = destWallets.map((w) => ({ - address: w.public_key.toString("hex"), + address: w.public_key, amount: amount, fee_per_gram: feePerGram, message: "msg", @@ -1082,7 +1076,7 @@ When( const lastResult = await this.send_tari( sourceWallet, dest, - destPublicKey.toString("hex"), + destPublicKey, amount, feePerGram, PaymentType.ONE_SIDED @@ -1090,7 +1084,7 @@ When( expect(lastResult.results[0].is_success).to.equal(true); this.addTransaction( - sourceInfo.public_key.toString("hex"), + sourceInfo.public_key, lastResult.results[0].transaction_id ); //lets now wait for this transaction to be at least broadcast before we continue. @@ -1124,7 +1118,7 @@ When( const lastResult = await this.send_tari( sourceWallet, dest, - destPublicKey.toString("hex"), + destPublicKey, amount, feePerGram, PaymentType.ONE_SIDED_TO_STEALTH_ADDRESS @@ -1132,7 +1126,7 @@ When( expect(lastResult.results[0].is_success).to.equal(true); this.addTransaction( - sourceInfo.public_key.toString("hex"), + sourceInfo.public_key, lastResult.results[0].transaction_id ); //lets now wait for this transaction to be at least broadcast before we continue. @@ -1164,10 +1158,7 @@ When( const lastResult = await this.burn_tari(sourceWallet, amount, feePerGram); expect(lastResult.is_success).to.equal(true); - this.addTransaction( - sourceInfo.public_key.toString("hex"), - lastResult.transaction_id - ); + this.addTransaction(sourceInfo.public_key, lastResult.transaction_id); //lets now wait for this transaction to be at least broadcast before we continue. await waitFor( async () => @@ -1271,9 +1262,7 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get( - walletInfo.public_key.toString("hex") - ); + const txIds = this.transactionsMap.get(walletInfo.public_key); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1323,9 +1312,7 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get( - walletInfo.public_key.toString("hex") - ); + const txIds = this.transactionsMap.get(walletInfo.public_key); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1433,9 +1420,7 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get( - walletInfo.public_key.toString("hex") - ); + const txIds = this.transactionsMap.get(walletInfo.public_key); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1484,9 +1469,7 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get( - walletInfo.public_key.toString("hex") - ); + const txIds = this.transactionsMap.get(walletInfo.public_key); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1535,7 +1518,7 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - let txIds = this.transactionsMap.get(walletInfo.public_key.toString("hex")); + let txIds = this.transactionsMap.get(walletInfo.public_key); console.log(walletName, txIds); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); @@ -1585,9 +1568,7 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get( - walletInfo.public_key.toString("hex") - ); + const txIds = this.transactionsMap.get(walletInfo.public_key); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1636,9 +1617,7 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get( - walletInfo.public_key.toString("hex") - ); + const txIds = this.transactionsMap.get(walletInfo.public_key); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1686,9 +1665,7 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get( - walletInfo.public_key.toString("hex") - ); + const txIds = this.transactionsMap.get(walletInfo.public_key); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1736,9 +1713,7 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get( - walletInfo.public_key.toString("hex") - ); + const txIds = this.transactionsMap.get(walletInfo.public_key); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1786,9 +1761,7 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get( - walletInfo.public_key.toString("hex") - ); + const txIds = this.transactionsMap.get(walletInfo.public_key); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1836,9 +1809,7 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get( - walletInfo.public_key.toString("hex") - ); + const txIds = this.transactionsMap.get(walletInfo.public_key); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1884,9 +1855,7 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); const nodeClient = this.getClient(nodeName); - const txIds = this.transactionsMap.get( - walletInfo.public_key.toString("hex") - ); + const txIds = this.transactionsMap.get(walletInfo.public_key); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); throw new Error("No transactions for " + walletName + "!"); @@ -1947,9 +1916,7 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get( - walletInfo.public_key.toString("hex") - ); + const txIds = this.transactionsMap.get(walletInfo.public_key); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -2328,7 +2295,7 @@ When( " completed with TxId: ", result ); - this.addTransaction(walletInfo.public_key.toString("hex"), result.tx_id); + this.addTransaction(walletInfo.public_key, result.tx_id); this.lastResult = result; } } @@ -2351,6 +2318,7 @@ When( const sourceInfo = await sourceWalletClient.identify(); const destWalletClient = await this.getWallet(destWallet).connectClient(); const destInfo = await destWalletClient.identify(); + console.log( "Sending", numTransactions, @@ -2362,12 +2330,11 @@ When( let batch = 1; let tx_ids = []; - for (let i = 0; i < numTransactions; i++) { const result = await this.send_tari( this.getWallet(sourceWallet), destInfo.name, - destInfo.public_key.toString("hex"), + destInfo.public_key, amount, feePerGram, false, @@ -2377,11 +2344,11 @@ When( expect(result.results[0].is_success).to.equal(true); tx_ids.push(result.results[0].transaction_id); this.addTransaction( - sourceInfo.public_key.toString("hex"), + sourceInfo.public_key, result.results[0].transaction_id ); this.addTransaction( - destInfo.public_key.toString("hex"), + destInfo.public_key, result.results[0].transaction_id ); diff --git a/integration_tests/features/support/world.js b/integration_tests/features/support/world.js index 31419b5424..15f1fd2daa 100644 --- a/integration_tests/features/support/world.js +++ b/integration_tests/features/support/world.js @@ -147,14 +147,14 @@ class CustomWorld { this.addWallet(name, wallet); let walletClient = await wallet.connectClient(); let walletInfo = await walletClient.identify(); - this.walletPubkeys[name] = walletInfo.public_key.toString("hex"); + this.walletPubkeys[name] = walletInfo.public_key; } async createAndAddFFIWallet(name, seed_words = null, passphrase = null) { const wallet = new WalletFFIClient(name); await wallet.startNew(seed_words, passphrase); this.walletsFFI[name] = wallet; - this.walletPubkeys[name] = wallet.identify().public_key.toString("hex"); + this.walletPubkeys[name] = wallet.identify(); return wallet; } From a42a1387917b8f784aff29599ff869cb3ae0029e Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Mon, 22 Aug 2022 16:06:52 +0100 Subject: [PATCH 13/15] add toString("hex") --- .../features/support/ffi_steps.js | 3 +- integration_tests/features/support/steps.js | 10 +- .../features/support/wallet_steps.js | 129 +++++++++++------- integration_tests/features/support/world.js | 2 +- 4 files changed, 92 insertions(+), 52 deletions(-) diff --git a/integration_tests/features/support/ffi_steps.js b/integration_tests/features/support/ffi_steps.js index a3d7190adb..3c2b58a636 100644 --- a/integration_tests/features/support/ffi_steps.js +++ b/integration_tests/features/support/ffi_steps.js @@ -723,7 +723,8 @@ Then( () => { let publicKeys = wallet.listConnectedPublicKeys(); return ( - publicKeys && publicKeys.some((p) => p === nodeIdentity.public_key.toString("hex")) + publicKeys && + publicKeys.some((p) => p === nodeIdentity.public_key.toString("hex")) ); }, true, diff --git a/integration_tests/features/support/steps.js b/integration_tests/features/support/steps.js index c934c8ca5a..3d2867c3a5 100644 --- a/integration_tests/features/support/steps.js +++ b/integration_tests/features/support/steps.js @@ -508,7 +508,9 @@ When( await waitForPredicate(async () => { let peers = await firstNodeClient.listConnectedPeers(); - return peers.some((p) => secondNodeIdentity.public_key === p.public_key); + return peers.some( + (p) => secondNodeIdentity.public_key.toString("hex") === p.public_key + ); }, 50 * 1000); } ); @@ -519,7 +521,11 @@ Then(/(.*) is connected to (.*)/, async function (firstNode, secondNode) { const secondNodeIdentity = await secondNodeClient.identify(); let peers = await firstNodeClient.listConnectedPeers(); expect( - peers.some((p) => secondNodeIdentity.public_key.toString("hex") === p.public_key) + peers.some( + (p) => + secondNodeIdentity.public_key.toString("hex") === + p.public_key.toString("hex") + ) ).to.be.true; }); diff --git a/integration_tests/features/support/wallet_steps.js b/integration_tests/features/support/wallet_steps.js index 95646c2f59..b94a60c931 100644 --- a/integration_tests/features/support/wallet_steps.js +++ b/integration_tests/features/support/wallet_steps.js @@ -95,7 +95,7 @@ Given( this.addWallet(walletName, wallet); let walletClient = await this.getWallet(walletName).connectClient(); let walletInfo = await walletClient.identify(); - this.addWalletPubkey(walletName, walletInfo.public_key); + this.addWalletPubkey(walletName, walletInfo.public_key.toString("hex")); } ); @@ -114,7 +114,7 @@ Given( this.addWallet(name, wallet); let walletClient = await this.getWallet(name).connectClient(); let walletInfo = await walletClient.identify(); - this.addWalletPubkey(name, walletInfo.public_key); + this.addWalletPubkey(name, walletInfo.public_key.toString("hex")); } ); @@ -197,7 +197,7 @@ Given( this.addWallet(name, wallet); let walletClient = await this.getWallet(name).connectClient(); let walletInfo = await walletClient.identify(); - this.addWalletPubkey(name, walletInfo.public_key); + this.addWalletPubkey(name, walletInfo.public_key.toString("hex")); } ); @@ -245,7 +245,7 @@ Given( this.addWallet(walletNameB, walletB); let walletClient = await this.getWallet(walletNameB).connectClient(); let walletInfo = await walletClient.identify(); - this.addWalletPubkey(walletNameB, walletInfo.public_key); + this.addWalletPubkey(walletNameB, walletInfo.public_key.toString("hex")); } ); @@ -280,7 +280,10 @@ Given( recoveredWalletName ).connectClient(); let walletInfo = await walletClient.identify(); - this.addWalletPubkey(recoveredWalletName, walletInfo.public_key); + this.addWalletPubkey( + recoveredWalletName, + walletInfo.public_key.toString("hex") + ); } } ); @@ -312,7 +315,7 @@ Given( this.addWallet(i, wallet); let walletClient = await this.getWallet(i.toString()).connectClient(); let walletInfo = await walletClient.identify(); - this.addWalletPubkey(wallet, walletInfo.public_key); + this.addWalletPubkey(wallet, walletInfo.public_key.toString("hex")); } } ); @@ -528,7 +531,7 @@ When( try { this.lastResult = await sourceClient.sendHtlc({ recipient: { - address: destInfo.public_key, + address: destInfo.public_key.toString("hex"), amount: tariAmount, fee_per_gram: feePerGram, message: "msg", @@ -566,10 +569,13 @@ When( } if (success) { this.addTransaction( - sourceInfo.public_key, + sourceInfo.public_key.toString("hex"), + this.lastResult.transaction_id + ); + this.addTransaction( + destInfo.public_key.toString("hex"), this.lastResult.transaction_id ); - this.addTransaction(destInfo.public_key, this.lastResult.transaction_id); } expect(success).to.equal(true); //lets now wait for this transaction to be at least broadcast before we continue. @@ -643,7 +649,7 @@ When( if (success) { this.addTransaction( - sourceInfo.public_key, + sourceInfo.public_key.toString("hex"), this.lastResult.results.transaction_id ); } @@ -721,7 +727,7 @@ When( if (success) { this.addTransaction( - sourceInfo.public_key, + sourceInfo.public_key.toString("hex"), this.lastResult.results.transaction_id ); } @@ -754,7 +760,7 @@ When( const sourceClient = await sourceWallet.connectClient(); const sourceInfo = await sourceClient.identify(); - const destPublicKey = this.getWalletPubkey(dest); + const destPublicKey = this.getWalletPubkey(dest).toString("hex"); this.lastResult = await this.send_tari( sourceWallet, @@ -796,7 +802,7 @@ When( this.lastResult = await this.send_tari( this.getWallet(source), destInfo.name, - destInfo.public_key, + destInfo.public_key.toString("hex"), tariAmount, fee ); @@ -848,18 +854,18 @@ When( this.lastResult = await this.send_tari( this.getWallet(source), destInfo.name, - destInfo.public_key, + destInfo.public_key.toString("hex"), tariAmount, fee ); expect(this.lastResult.results[0].is_success).to.equal(true); tx_ids.push(this.lastResult.results[0].transaction_id); this.addTransaction( - sourceInfo.public_key, + sourceInfo.public_key.toString("hex"), this.lastResult.results[0].transaction_id ); this.addTransaction( - destInfo.public_key, + destInfo.public_key.toString("hex"), this.lastResult.results[0].transaction_id ); // console.log(" Transaction '" + this.lastResult.results[0]["transaction_id"] + "' is_success(" + @@ -914,13 +920,13 @@ When( lastResult = await sourceClient.transfer({ recipients: [ { - address: dest1Info.public_key, + address: dest1Info.public_key.toString("hex"), amount: tariAmount, fee_per_gram: feePerGram, message: "msg", }, { - address: dest2Info.public_key, + address: dest2Info.public_key.toString("hex"), amount: tariAmount, fee_per_gram: feePerGram, message: "msg", @@ -960,19 +966,19 @@ When( } if (success) { this.addTransaction( - sourceInfo.public_key, + sourceInfo.public_key.toString("hex"), lastResult.results[0].transaction_id ); this.addTransaction( - sourceInfo.public_key, + sourceInfo.public_key.toString("hex"), lastResult.results[1].transaction_id ); this.addTransaction( - dest1Info.public_key, + dest1Info.public_key.toString("hex"), lastResult.results[0].transaction_id ); this.addTransaction( - dest2Info.public_key, + dest2Info.public_key.toString("hex"), lastResult.results[1].transaction_id ); } @@ -989,14 +995,14 @@ When( this.lastResult = await this.send_tari( this.getWallet(source), sourceInfo.name, - sourceInfo.public_key, + sourceInfo.public_key.toString("hex"), tariAmount, feePerGram ); expect(this.lastResult.results[0].is_success).to.equal(true); this.addTransaction( - sourceInfo.public_key, + sourceInfo.public_key.toString("hex"), this.lastResult.results[0].transaction_id ); console.log( @@ -1040,7 +1046,7 @@ When( async () => { try { const recipients = destWallets.map((w) => ({ - address: w.public_key, + address: w.public_key.toString("hex"), amount: amount, fee_per_gram: feePerGram, message: "msg", @@ -1076,7 +1082,7 @@ When( const lastResult = await this.send_tari( sourceWallet, dest, - destPublicKey, + destPublicKey.toString("hex"), amount, feePerGram, PaymentType.ONE_SIDED @@ -1084,7 +1090,7 @@ When( expect(lastResult.results[0].is_success).to.equal(true); this.addTransaction( - sourceInfo.public_key, + sourceInfo.public_key.toString("hex"), lastResult.results[0].transaction_id ); //lets now wait for this transaction to be at least broadcast before we continue. @@ -1118,7 +1124,7 @@ When( const lastResult = await this.send_tari( sourceWallet, dest, - destPublicKey, + destPublicKey.toString("hex"), amount, feePerGram, PaymentType.ONE_SIDED_TO_STEALTH_ADDRESS @@ -1126,7 +1132,7 @@ When( expect(lastResult.results[0].is_success).to.equal(true); this.addTransaction( - sourceInfo.public_key, + sourceInfo.public_key.toString("hex"), lastResult.results[0].transaction_id ); //lets now wait for this transaction to be at least broadcast before we continue. @@ -1158,7 +1164,10 @@ When( const lastResult = await this.burn_tari(sourceWallet, amount, feePerGram); expect(lastResult.is_success).to.equal(true); - this.addTransaction(sourceInfo.public_key, lastResult.transaction_id); + this.addTransaction( + sourceInfo.public_key.toString("hex"), + lastResult.transaction_id + ); //lets now wait for this transaction to be at least broadcast before we continue. await waitFor( async () => @@ -1262,7 +1271,9 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key); + const txIds = this.transactionsMap.get( + walletInfo.public_key.toString("hex") + ); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1312,7 +1323,9 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key); + const txIds = this.transactionsMap.get( + walletInfo.public_key.toString("hex") + ); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1420,7 +1433,9 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key); + const txIds = this.transactionsMap.get( + walletInfo.public_key.toString("hex") + ); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1469,7 +1484,9 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key); + const txIds = this.transactionsMap.get( + walletInfo.public_key.toString("hex") + ); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1518,7 +1535,7 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - let txIds = this.transactionsMap.get(walletInfo.public_key); + let txIds = this.transactionsMap.get(walletInfo.public_key.toString("hex")); console.log(walletName, txIds); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); @@ -1568,7 +1585,9 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key); + const txIds = this.transactionsMap.get( + walletInfo.public_key.toString("hex") + ); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1617,7 +1636,9 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key); + const txIds = this.transactionsMap.get( + walletInfo.public_key.toString("hex") + ); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1665,7 +1686,9 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key); + const txIds = this.transactionsMap.get( + walletInfo.public_key.toString("hex") + ); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1713,7 +1736,9 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key); + const txIds = this.transactionsMap.get( + walletInfo.public_key.toString("hex") + ); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1761,7 +1786,9 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key); + const txIds = this.transactionsMap.get( + walletInfo.public_key.toString("hex") + ); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1809,7 +1836,9 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key); + const txIds = this.transactionsMap.get( + walletInfo.public_key.toString("hex") + ); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -1855,7 +1884,9 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); const nodeClient = this.getClient(nodeName); - const txIds = this.transactionsMap.get(walletInfo.public_key); + const txIds = this.transactionsMap.get( + walletInfo.public_key.toString("hex") + ); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); throw new Error("No transactions for " + walletName + "!"); @@ -1916,7 +1947,9 @@ Then( const walletClient = await wallet.connectClient(); const walletInfo = await walletClient.identify(); - const txIds = this.transactionsMap.get(walletInfo.public_key); + const txIds = this.transactionsMap.get( + walletInfo.public_key.toString("hex") + ); if (txIds === undefined) { console.log("\nNo transactions for " + walletName + "!"); expect(false).to.equal(true); @@ -2295,7 +2328,7 @@ When( " completed with TxId: ", result ); - this.addTransaction(walletInfo.public_key, result.tx_id); + this.addTransaction(walletInfo.public_key.toString("hex"), result.tx_id); this.lastResult = result; } } @@ -2318,7 +2351,6 @@ When( const sourceInfo = await sourceWalletClient.identify(); const destWalletClient = await this.getWallet(destWallet).connectClient(); const destInfo = await destWalletClient.identify(); - console.log( "Sending", numTransactions, @@ -2330,11 +2362,12 @@ When( let batch = 1; let tx_ids = []; + for (let i = 0; i < numTransactions; i++) { const result = await this.send_tari( this.getWallet(sourceWallet), destInfo.name, - destInfo.public_key, + destInfo.public_key.toString("hex"), amount, feePerGram, false, @@ -2344,11 +2377,11 @@ When( expect(result.results[0].is_success).to.equal(true); tx_ids.push(result.results[0].transaction_id); this.addTransaction( - sourceInfo.public_key, + sourceInfo.public_key.toString("hex"), result.results[0].transaction_id ); this.addTransaction( - destInfo.public_key, + destInfo.public_key.toString("hex"), result.results[0].transaction_id ); diff --git a/integration_tests/features/support/world.js b/integration_tests/features/support/world.js index 15f1fd2daa..3ca31fc4ca 100644 --- a/integration_tests/features/support/world.js +++ b/integration_tests/features/support/world.js @@ -147,7 +147,7 @@ class CustomWorld { this.addWallet(name, wallet); let walletClient = await wallet.connectClient(); let walletInfo = await walletClient.identify(); - this.walletPubkeys[name] = walletInfo.public_key; + this.walletPubkeys[name] = walletInfo.public_key.toString("hex"); } async createAndAddFFIWallet(name, seed_words = null, passphrase = null) { From 96086a61405b69a9a5c3d1954addff322273975d Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Mon, 22 Aug 2022 17:13:20 +0100 Subject: [PATCH 14/15] small changes --- integration_tests/features/support/wallet_steps.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_tests/features/support/wallet_steps.js b/integration_tests/features/support/wallet_steps.js index b94a60c931..fa966456ce 100644 --- a/integration_tests/features/support/wallet_steps.js +++ b/integration_tests/features/support/wallet_steps.js @@ -1088,7 +1088,7 @@ When( PaymentType.ONE_SIDED ); expect(lastResult.results[0].is_success).to.equal(true); - + this.addTransaction( sourceInfo.public_key.toString("hex"), lastResult.results[0].transaction_id From 0adbdfdd6f22e2e9a853d5f4b2e15cd3f39e32ac Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Mon, 22 Aug 2022 17:53:40 +0100 Subject: [PATCH 15/15] lint --- integration_tests/features/support/wallet_steps.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_tests/features/support/wallet_steps.js b/integration_tests/features/support/wallet_steps.js index fa966456ce..b94a60c931 100644 --- a/integration_tests/features/support/wallet_steps.js +++ b/integration_tests/features/support/wallet_steps.js @@ -1088,7 +1088,7 @@ When( PaymentType.ONE_SIDED ); expect(lastResult.results[0].is_success).to.equal(true); - + this.addTransaction( sourceInfo.public_key.toString("hex"), lastResult.results[0].transaction_id