Skip to content

Commit

Permalink
refactor: refactor wallet ffi cucumber tests (#3259)
Browse files Browse the repository at this point in the history
Description
Refactored WalletFFI.feature into a working state, tested locally.

Further refactoring and dead code removal would be beneficial.

Motivation and Context
Necessary to get WalletFFI.feature working.

How Has This Been Tested?
Tested locally, each scenario tested with:
`./node_modules/.bin/cucumber-js --name "${scenario_name}"`
  • Loading branch information
StriderDM authored Aug 30, 2021
1 parent 60f286b commit 8d82fd0
Show file tree
Hide file tree
Showing 24 changed files with 3,121 additions and 751 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ commands:
when: always
- run:
name: Run ffi cucumber scenarios
command: cd integration_tests && mkdir -p cucumber_output && node_modules/.bin/cucumber-js --tags "not @long-running and not @broken and not @flaky and @wallet-ffi" --format json:cucumber_output/tests-ffi.cucumber --exit
command: cd integration_tests && mkdir -p cucumber_output && node_modules/.bin/cucumber-js --tags "not @long-running and not @broken and not @flaky and @wallet-ffi" --format json:cucumber_output/tests_ffi.cucumber --exit
- run:
name: Generate report (ffi)
command: cd integration_tests && touch cucumber_output/tests-ffi.cucumber && node ./generate_report.js cucumber_output/tests-ffi.cucumber temp/reports/cucumber_ffi_report.html
command: cd integration_tests && node ./generate_report.js "cucumber_output/tests_ffi.cucumber" "temp/reports/cucumber_ffi_report.html"
when: always
# - run:
# name: Run flaky/broken cucumber scenarios (Always pass)
Expand Down
2 changes: 2 additions & 0 deletions applications/ffi_client/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// this is nasty
// ¯\_(ツ)_/¯

// TODO: Use implementation in cucumber tests instead (see helpers/ffi).

const lib = require("./lib");
const ref = require("ref-napi");
const ffi = require("ffi-napi");
Expand Down
12 changes: 6 additions & 6 deletions base_layer/wallet_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -917,14 +917,14 @@ pub unsafe extern "C" fn seed_words_push_word(

(*seed_words).0.push(word_string);
if (*seed_words).0.len() >= 24 {
if let Err(e) = TariPrivateKey::from_mnemonic(&(*seed_words).0) {
return if let Err(e) = TariPrivateKey::from_mnemonic(&(*seed_words).0) {
log::error!(target: LOG_TARGET, "Problem building private key from seed phrase");
error = LibWalletError::from(e).code;
ptr::swap(error_out, &mut error as *mut c_int);
return SeedWordPushResult::InvalidSeedPhrase as u8;
SeedWordPushResult::InvalidSeedPhrase as u8
} else {
return SeedWordPushResult::SeedPhraseComplete as u8;
}
SeedWordPushResult::SeedPhraseComplete as u8
};
}

SeedWordPushResult::SuccessfulPush as u8
Expand Down Expand Up @@ -2858,7 +2858,7 @@ pub unsafe extern "C" fn wallet_create(
match TariPrivateKey::from_mnemonic(&(*seed_words).0) {
Ok(private_key) => Some(private_key),
Err(e) => {
error!(target: LOG_TARGET, "Mnemonic Error for given seed words: {}", e);
error!(target: LOG_TARGET, "Mnemonic Error for given seed words: {:?}", e);
error = LibWalletError::from(e).code;
ptr::swap(error_out, &mut error as *mut c_int);
return ptr::null_mut();
Expand Down Expand Up @@ -2947,7 +2947,7 @@ pub unsafe extern "C" fn wallet_create(
// lets ensure the wallet tor_id is saved, this could have been changed during wallet startup
if let Some(hs) = w.comms.hidden_service() {
if let Err(e) = runtime.block_on(w.db.set_tor_identity(hs.tor_identity().clone())) {
warn!(target: LOG_TARGET, "Could not save tor identity to db: {}", e);
warn!(target: LOG_TARGET, "Could not save tor identity to db: {:?}", e);
}
}
// Start Callback Handler
Expand Down
165 changes: 86 additions & 79 deletions integration_tests/features/WalletFFI.feature
Original file line number Diff line number Diff line change
@@ -1,129 +1,136 @@
@wallet-ffi
Feature: Wallet FFI
# Increase heap memory available to nodejs if frequent crashing occurs with
# error being be similar to this: `0x1a32cd5 V8_Fatal(char const*, ...)`

Scenario: As a client I want to send Tari to a Public Key
# It's a subtest of "As a client I want to retrieve a list of transactions I have made and received"

Scenario: As a client I want to specify a custom fee when I send tari
# It's a subtest of "As a client I want to retrieve a list of transactions I have made and received"

Scenario: As a client I want to receive Tari via my Public Key while I am online
# It's a subtest of "As a client I want to retrieve a list of transactions I have made and received"
# It's just calling the encrypt function, we don't test if it's actually encrypted
Scenario: As a client I want to be able to protect my wallet with a passphrase
Given I have a base node BASE
And I have a ffi wallet FFI_WALLET connected to base node BASE
And I set passphrase PASSPHRASE of ffi wallet FFI_WALLET
And I stop ffi wallet FFI_WALLET

@long-running @broken
Scenario: As a client I want to receive Tari via my Public Key sent while I am offline when I come back online
Scenario: As a client I want to see my whoami info
Given I have a base node BASE
And I have wallet SENDER connected to base node BASE
And I have mining node MINER connected to base node BASE and wallet SENDER
And mining node MINER mines 4 blocks
Then I wait for wallet SENDER to have at least 1000000 uT
And I have a ffi wallet FFI_WALLET connected to base node BASE
And I stop wallet FFI_WALLET
Then I want to get public key of ffi wallet FFI_WALLET
And I want to get emoji id of ffi wallet FFI_WALLET
And I stop ffi wallet FFI_WALLET

Scenario: As a client I want to be able to restore my ffi wallet from seed words
Given I have a base node BASE
And I have wallet SPECTATOR connected to base node BASE
And I have mining node MINER connected to base node BASE and wallet SPECTATOR
And mining node MINER mines 10 blocks
Then I wait for wallet SPECTATOR to have at least 1000000 uT
Then I recover wallet SPECTATOR into ffi wallet FFI_WALLET from seed words on node BASE
And I wait for ffi wallet FFI_WALLET to have at least 1000000 uT
And I stop ffi wallet FFI_WALLET

Scenario: As a client I want to set the base node
Given I have a base node BASE1
Given I have a base node BASE2
And I have a ffi wallet FFI_WALLET connected to base node BASE1
And I set base node BASE2 for ffi wallet FFI_WALLET
And I stop ffi wallet FFI_WALLET
And I stop node BASE1
And I wait 5 seconds
And I send 2000000 uT from wallet SENDER to wallet FFI_WALLET at fee 100
And I restart ffi wallet FFI_WALLET
# Possibly check SAF messages, no way to get current connected base node peer from the library itself afaik
# Good idea just to add a fn to do this to the library.
# Then I wait for ffi wallet FFI_WALLET to receive 1 SAF message
And I wait 5 seconds
And I start wallet FFI_WALLET
And wallet SENDER detects all transactions are at least Broadcast
And mining node MINER mines 10 blocks
Then I wait for ffi wallet FFI_WALLET to have at least 1000000 uT
And I stop ffi wallet FFI_WALLET

@long-running
Scenario: As a client I want to retrieve a list of transactions I have made and received
Scenario: As a client I want to cancel a transaction
Given I have a base node BASE
And I have wallet SENDER connected to base node BASE
And I have mining node MINER connected to base node BASE and wallet SENDER
And mining node MINER mines 4 blocks
And mining node MINER mines 10 blocks
Then I wait for wallet SENDER to have at least 1000000 uT
And I have a ffi wallet FFI_WALLET connected to base node BASE
And I send 2000000 uT from wallet SENDER to wallet FFI_WALLET at fee 100
And wallet SENDER detects all transactions are at least Broadcast
And mining node MINER mines 10 blocks
Then I wait for ffi wallet FFI_WALLET to have at least 1000000 uT
And Check callbacks for finished inbound tx on ffi wallet FFI_WALLET
And I have wallet RECEIVER connected to base node BASE
And I stop wallet RECEIVER
And I send 1000000 uT from ffi wallet FFI_WALLET to wallet RECEIVER at fee 100
And ffi wallet FFI_WALLET has 1 broadcast transaction
And mining node MINER mines 4 blocks
Then I wait for wallet RECEIVER to have at least 1000000 uT
And Check callbacks for finished outbound tx on ffi wallet FFI_WALLET
And I have 1 received and 1 send transaction in ffi wallet FFI_WALLET
And I start STXO validation on wallet FFI_WALLET
And I start UTXO validation on wallet FFI_WALLET

# It's just calling the encrypt function, we don't test if it's actually encrypted
Scenario: As a client I want to be able to protect my wallet with a passphrase
Given I have a base node BASE
And I have a ffi wallet FFI_WALLET connected to base node BASE
And I set passphrase PASSPHRASE of ffi wallet FFI_WALLET
Then I wait for ffi wallet FFI_WALLET to have 1 pending outbound transaction
Then I cancel all outbound transactions on ffi wallet FFI_WALLET and it will cancel 1 transaction
And I stop ffi wallet FFI_WALLET

Scenario: As a client I want to manage contacts
Given I have a base node BASE
And I have a ffi wallet FFI_WALLET connected to base node BASE
And I have wallet WALLET connected to base node BASE
And I wait 5 seconds
And I add contact with alias ALIAS and pubkey WALLET to ffi wallet FFI_WALLET
Then I have contact with alias ALIAS and pubkey WALLET in ffi wallet FFI_WALLET
When I remove contact with alias ALIAS from ffi wallet FFI_WALLET
Then I don't have contact with alias ALIAS in ffi wallet FFI_WALLET
And I stop ffi wallet FFI_WALLET

Scenario: As a client I want to set the base node (should be persisted)
Given I have a base node BASE1
Given I have a base node BASE2
And I have a ffi wallet FFI_WALLET connected to base node BASE1
And I set base node BASE2 for ffi wallet FFI_WALLET
Then BASE2 is connected to FFI_WALLET
And I stop wallet FFI_WALLET
And I wait 5 seconds
And I start wallet FFI_WALLET
Then BASE2 is connected to FFI_WALLET

Scenario: As a client I want to see my public_key, emoji ID, address (whoami)
Given I have a base node BASE
And I have a ffi wallet FFI_WALLET connected to base node BASE
Then I want to get public key of ffi wallet FFI_WALLET
And I want to get emoji id of ffi wallet FFI_WALLET

Scenario: As a client I want to get my balance
# It's a subtest of "As a client I want to retrieve a list of transactions I have made and received"

@long-running
Scenario: As a client I want to cancel a transaction
Scenario: As a client I want to retrieve a list of transactions I have made and received
Given I have a base node BASE
And I have wallet SENDER connected to base node BASE
And I have mining node MINER connected to base node BASE and wallet SENDER
And mining node MINER mines 4 blocks
And mining node MINER mines 10 blocks
Then I wait for wallet SENDER to have at least 1000000 uT
And I have a ffi wallet FFI_WALLET connected to base node BASE
And I send 2000000 uT from wallet SENDER to wallet FFI_WALLET at fee 100
And wallet SENDER detects all transactions are at least Broadcast
And mining node MINER mines 10 blocks
Then I wait for ffi wallet FFI_WALLET to have at least 1000000 uT
And I have wallet RECEIVER connected to base node BASE
And I stop wallet RECEIVER
And I send 1000000 uT from ffi wallet FFI_WALLET to wallet RECEIVER at fee 100
Then I wait for ffi wallet FFI_WALLET to have 1 pending outbound transaction
Then I cancel all transactions on ffi wallet FFI_WALLET and it will cancel 1 transaction
And mining node MINER mines 10 blocks
Then I wait for wallet RECEIVER to have at least 1000000 uT
And I have 1 received and 1 send transaction in ffi wallet FFI_WALLET
And I start STXO validation on ffi wallet FFI_WALLET
And I start UTXO validation on ffi wallet FFI_WALLET
And I stop ffi wallet FFI_WALLET

@long-running
Scenario: As a client I want to be able to restore my wallet from seed words
Scenario: As a client I want to receive Tari via my Public Key sent while I am offline when I come back online
Given I have a base node BASE
And I have wallet WALLET connected to base node BASE
And I have mining node MINER connected to base node BASE and wallet WALLET
And mining node MINER mines 4 blocks
Then I wait for wallet WALLET to have at least 1000000 uT
Then I recover wallet WALLET into ffi wallet FFI_WALLET from seed words on node BASE
And I wait for recovery of wallet FFI_WALLET to finish
And I wait for ffi wallet FFI_WALLET to have at least 1000000 uT
And I have wallet SENDER connected to base node BASE
And I have mining node MINER connected to base node BASE and wallet SENDER
And mining node MINER mines 10 blocks
Then I wait for wallet SENDER to have at least 1000000 uT
And I have a ffi wallet FFI_WALLET connected to base node BASE
And I stop ffi wallet FFI_WALLET
And I wait 10 seconds
And I send 2000000 uT from wallet SENDER to wallet FFI_WALLET at fee 100
And I wait 5 seconds
And I restart ffi wallet FFI_WALLET
Then I wait for ffi wallet FFI_WALLET to receive 1 transaction
Then I wait for ffi wallet FFI_WALLET to receive 1 finalization
# Assume tx will be mined to reduce time taken for test, balance is tested in later scenarios.
# And mining node MINER mines 10 blocks
# Then I wait for ffi wallet FFI_WALLET to have at least 1000000 uT
And I stop ffi wallet FFI_WALLET

# Scenario: As a client I want to get my balance
# It's a subtest of "As a client I want to retrieve a list of transactions I have made and received"

#Scenario: As a client I want to send Tari to a Public Key
# It's a subtest of "As a client I want to retrieve a list of transactions I have made and received"

Scenario: As a client I want to be able to initiate TXO and TX validation with the specifed base node.
#Scenario: As a client I want to specify a custom fee when I send tari
# It's a subtest of "As a client I want to retrieve a list of transactions I have made and received"

Scenario: As a client I want async feedback about the progress of sending and receiving a transaction
#Scenario: As a client I want to receive Tari via my Public Key while I am online
# It's a subtest of "As a client I want to retrieve a list of transactions I have made and received"

Scenario: As a client I want async feedback about my connection status to the specifed Base Node
# Scenario: As a client I want to be able to initiate TXO and TX validation with the specifed base node.
# It's a subtest of "As a client I want to retrieve a list of transactions I have made and received"

# Scenario: As a client I want feedback about the progress of sending and receiving a transaction
# It's a subtest of "As a client I want to retrieve a list of transactions I have made and received"

Scenario: As a client I want async feedback about the wallet restoration process
# Scenario: As a client I want feedback about my connection status to the specifed Base Node

# Scenario: As a client I want feedback about the wallet restoration process
# As a client I want to be able to restore my wallet from seed words

Scenario: As a client I want async feedback about TXO and TX validation processes
# It's a subtest of "As a client I want to retrieve a list of transactions I have made and received"
# Scenario: As a client I want feedback about TXO and TX validation processes
# It's a subtest of "As a client I want to retrieve a list of transactions I have made and received"
Loading

0 comments on commit 8d82fd0

Please sign in to comment.