Skip to content

Commit

Permalink
test(cucumber): enable indexer feature (#1142)
Browse files Browse the repository at this point in the history
Co-authored-by: Stan Bondi <[email protected]>
  • Loading branch information
therealdannzor and sdbondi authored Sep 17, 2024
1 parent 695d703 commit 62b6cde
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -529,12 +529,14 @@ impl SubstateStoreReadTransaction for SqliteSubstateStoreReadTransaction<'_> {
}

fn get_all_events(&mut self, substate_id: &SubstateId) -> Result<Vec<EventData>, StorageError> {
let res = sql_query("SELECT substate_id, tx_hash, topic, payload FROM events WHERE substate_id = ?")
.bind::<Text, _>(substate_id.to_string())
.get_results::<EventData>(self.connection())
.map_err(|e| StorageError::QueryError {
reason: format!("get_events_by_version: {}", e),
})?;
let res = sql_query(
"SELECT substate_id, template_address, tx_hash, topic, payload, version FROM events WHERE substate_id = ?",
)
.bind::<Text, _>(substate_id.to_string())
.get_results::<EventData>(self.connection())
.map_err(|e| StorageError::QueryError {
reason: format!("get_all_events: {}", e),
})?;
Ok(res)
}

Expand Down
14 changes: 9 additions & 5 deletions integration_tests/src/wallet_daemon_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,11 @@ pub async fn submit_manifest_with_signing_keys(
transaction: None,
signing_key_index: Some(account.key_index),
instructions: instructions.instructions,
fee_instructions: vec![],
fee_instructions: vec![Instruction::CallMethod {
component_address: account.address.as_component_address().unwrap(),
method: "pay_fee".to_string(),
args: args![Amount(2000)],
}],
override_inputs: false,
is_dry_run: false,
proof_ids: vec![],
Expand Down Expand Up @@ -654,7 +658,7 @@ pub async fn create_component(
fee_instructions: vec![Instruction::CallMethod {
component_address: account.address.as_component_address().unwrap(),
method: "pay_fee".to_string(),
args: args![Amount(100)],
args: args![Amount(2000)],
}],
override_inputs: false,
is_dry_run: false,
Expand All @@ -672,8 +676,8 @@ pub async fn create_component(
};
let wait_resp = client.wait_transaction_result(wait_req).await.unwrap();

if let Some(reason) = wait_resp.result.clone().and_then(|finalize| finalize.reject().cloned()) {
panic!("Transaction failed: {}", reason);
if let Some(reason) = wait_resp.result.as_ref().and_then(|finalize| finalize.full_reject()) {
panic!("Create component tx failed: {}", reason);
}
add_substate_ids(
world,
Expand Down Expand Up @@ -706,7 +710,7 @@ pub async fn call_component(
.expect("Failed to get account component address");

let tx = Transaction::builder()
.fee_transaction_pay_from_component(account_component_address, Amount(1))
.fee_transaction_pay_from_component(account_component_address, Amount(1000))
.call_method(source_component_address, &function_call, vec![])
.build_unsigned_transaction();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
# Copyright 2022 The Tari Project
# Copyright 2024 The Tari Project
# SPDX-License-Identifier: BSD-3-Clause

# TODO: Ignored, no inputs - replace with wallet daemon calls
@indexer
Feature: Indexer node

@serial
Scenario: Indexer is able to connect to validator nodes
Given fees are disabled
Scenario: Wallet daemon is able to connect to indexer

##### Setup
# Initialize a base node, wallet, miner and VN
Given a base node BASE
Given a wallet WALLET connected to base node BASE
Given a miner MINER connected to base node BASE and wallet WALLET

# Initialize a VN
# Initialize a validator node
Given a validator node VN connected to base node BASE and wallet daemon WALLET_D

# The wallet must have some funds before the VN sends transactions
When miner MINER mines 6 new blocks
When wallet WALLET has at least 2000000000 uT

# VN registration
# Fund wallet to send VN registration tx
When miner MINER mines 10 new blocks
When wallet WALLET has at least 2000 T
When validator node VN sends a registration transaction to base wallet WALLET
When miner MINER mines 16 new blocks
Then the validator node VN is listed as registered

# Initialize indexer and connect wallet daemon
Given an indexer IDX connected to base node BASE
Given a wallet daemon WALLET_D connected to indexer IDX

# Register some templates
When base wallet WALLET registers the template "counter"
When base wallet WALLET registers the template "basic_nft"
When miner MINER mines 10 new blocks
Then VN has scanned to height 13
Then the validator node VN is listed as registered
When miner MINER mines 20 new blocks
Then VN has scanned to height 43
Then the template "counter" is listed as registered by the validator node VN
Then the template "basic_nft" is listed as registered by the validator node VN

# A file-base CLI account must be created to sign future calls
When I use an account key named K1
# Create the sender account
When I create an account ACC via the wallet daemon WALLET_D with 10000 free coins

# Create a new Counter component and increase it to have a version 1
When I create a component COUNTER_1 of template "counter" on VN using "new"
When I invoke on VN on component COUNTER_1/components/Counter the method call "increase" named "TX1"

# Create an account to deposit minted nfts
When I create an account ACC1 on VN
##### Scenario
# Create a new Counter component and increase it to have version 1
When I call function "new" on template "counter" using account ACC to pay fees via wallet daemon WALLET_D named "COUNTER"
When I invoke on wallet daemon WALLET_D on account ACC on component COUNTER/components/Counter the method call "increase"

# Create a new SparkleNft component and mint an NFT
When I call function "new" on template "basic_nft" on VN named "NFT"
When I submit a transaction manifest on VN with inputs "NFT, ACC1" named "TX2" signed with key ACC1
When I call function "new" on template "basic_nft" using account ACC to pay fees via wallet daemon WALLET_D named "NFT"
When I submit a transaction manifest via wallet daemon WALLET_D signed by the key of ACC with inputs "NFT, ACC" named "TX1"
```
// $mint NFT/resources/0 6
// $nft_index NFT/resources/0 0
Expand All @@ -54,7 +55,7 @@ Feature: Indexer node
// $nft_index NFT/resources/0 4
// $nft_index NFT/resources/0 5
let sparkle_nft = global!["NFT/components/SparkleNft"];
let mut acc1 = global!["ACC1/components/Account"];
let mut acc1 = global!["ACC/components/Account"];

// mint a couple of nfts with random ids
let nft_bucket_1 = sparkle_nft.mint("Astronaut (Image by Freepik.com)", "https://img.freepik.com/free-vector/hand-drawn-nft-style-ape-illustration_23-2149622024.jpg");
Expand All @@ -71,28 +72,21 @@ Feature: Indexer node
acc1.deposit(nft_bucket_6);
```

# Initialize an indexer
Given an indexer IDX connected to base node BASE
Then indexer IDX has scanned to height 13

# Get substate of a component (the counter has been increased, so the version is 1)
Then the indexer IDX returns version 1 for substate COUNTER_1/components/Counter
Then the indexer IDX returns version 1 for substate COUNTER/components/Counter

# Get substate of a resource (the nft resource has been mutated by the minting, so the version is 1)
Then the indexer IDX returns version 1 for substate NFT/resources/0

# Get substate of an nft (newly minted and not mutated, so version is 0)
Then the indexer IDX returns version 0 for substate TX2/nfts/0
Then the indexer IDX returns version 0 for substate TX1/nfts/0

# List the nfts of a resource
Then the indexer IDX returns 6 non fungibles for resource NFT/resources/0

# Scan the network for the event emitted on ACC_1 creation
When indexer IDX scans the network events for account ACC1 with topics component-created,deposit,deposit,deposit,deposit,deposit,deposit

# When I print the cucumber world
# When I wait 5000 seconds
# FIXME: indexer relies on NFT index which is no longer created
# Then the indexer IDX returns 6 non fungibles for resource NFT/resources/0

# Scan the network for the event emitted on ACC creation
When indexer IDX scans the network events for account ACC with topics component-created,pay_fee,pay_fee,pay_fee,pay_fee,pay_fee,deposit,component-created,pay_fee,pay_fee,deposit,deposit,deposit,deposit,deposit,deposit

@serial
Scenario: Indexer GraphQL requests work
Expand All @@ -107,88 +101,75 @@ Feature: Indexer node

@serial
Scenario: Indexer GraphQL requests events over network substate indexing
Given fees are disabled

##### Setup
# Initialize a base node, wallet, miner and VN
Given a base node BASE
Given a wallet WALLET connected to base node BASE
Given a miner MINER connected to base node BASE and wallet WALLET

# Initialize a VN
# Initialize a validator node
Given a validator node VN connected to base node BASE and wallet daemon WALLET_D

# Initialize an indexer
Given an indexer IDX connected to base node BASE

# The wallet must have some funds before the VN sends transactions
When miner MINER mines 6 new blocks
When wallet WALLET has at least 2000000000 uT

# VN registration
# Fund wallet to send VN registration tx
When miner MINER mines 10 new blocks
When wallet WALLET has at least 2000 T
When validator node VN sends a registration transaction to base wallet WALLET

When miner MINER mines 16 new blocks
Then VN has scanned to height 19
Then indexer IDX has scanned to height 19
Then the validator node VN is listed as registered

# A file-base CLI account must be created to sign future calls
When I use an account key named K1
# Initialize indexer and connect wallet daemon
Given an indexer IDX connected to base node BASE
Given a wallet daemon WALLET_D connected to indexer IDX

# Creates a new account
When I create an account ACC_1 on VN
When I create an account ACC_2 on VN
When I create an account ACC_1 via the wallet daemon WALLET_D with 10000 free coins
When I create an account ACC_2 via the wallet daemon WALLET_D with 10000 free coins

##### Scenario
# Scan the network for the event emitted on ACC_1 creation
When indexer IDX scans the network events for account ACC_1 with topics component-created
When indexer IDX scans the network events for account ACC_1 with topics component-created,pay_fee,component-created,pay_fee

# Scan the network for the event emitted on ACC_2 creation
When indexer IDX scans the network events for account ACC_2 with topics component-created
When indexer IDX scans the network events for account ACC_2 with topics component-created,pay_fee,component-created,pay_fee

@serial
Scenario: Indexer GraphQL filtering and pagination of events
Given fees are disabled

##### Setup
# Initialize a base node, wallet, miner and VN
Given a base node BASE
Given a wallet WALLET connected to base node BASE
Given a miner MINER connected to base node BASE and wallet WALLET

# Initialize a VN
# Initialize a validator node
Given a validator node VN connected to base node BASE and wallet daemon WALLET_D

# Initialize an indexer
Given an indexer IDX connected to base node BASE

# The wallet must have some funds before the VN sends transactions
When miner MINER mines 6 new blocks
When wallet WALLET has at least 2000000000 uT

# VN registration
# Fund wallet to send VN registration tx
When miner MINER mines 10 new blocks
When wallet WALLET has at least 2000 T
When validator node VN sends a registration transaction to base wallet WALLET

# Register the "faucet" template
When base wallet WALLET registers the template "faucet"

# Mine a few block for the VN and template registration
When miner MINER mines 16 new blocks
Then VN has scanned to height 19
Then indexer IDX has scanned to height 19
Then the validator node VN is listed as registered

# Initialize the wallet daemon
# Initialize indexer and connect wallet daemon
Given an indexer IDX connected to base node BASE
Given a wallet daemon WALLET_D connected to indexer IDX

# A file-base CLI account must be created to sign future calls
When I use an account key named K1
# Register template
When base wallet WALLET registers the template "faucet"
When miner MINER mines 20 new blocks
Then VN has scanned to height 43
Then the template "faucet" is listed as registered by the validator node VN

# Creates a new account
When I create an account ACC_1 on VN
When I create an account ACC_2 on VN
When I create an account ACC_1 via the wallet daemon WALLET_D with 10000 free coins
When I create an account ACC_2 via the wallet daemon WALLET_D with 10000 free coins

##### Scenario
# Create a new faucet component
When I call function "mint" on template "faucet" using account ACC_1 to pay fees via wallet daemon WALLET_D with args "10000" named "FAUCET"

# Generate some events by doing vault operations with the faucet and the acounts
When I submit a transaction manifest via wallet daemon WALLET_D with inputs "FAUCET, ACC_1, ACC_2" named "TX1"
When I submit a transaction manifest via wallet daemon WALLET_D signed by the key of ACC_1 with inputs "FAUCET, ACC_1, ACC_2" named "TX1"
```
let faucet = global!["FAUCET/components/TestFaucet"];
let faucet_resource = global!["FAUCET/resources/0"];
Expand All @@ -213,4 +194,3 @@ Feature: Indexer node

# Query the events from the network
When indexer IDX scans the network for events of resource FAUCET/resources/0

4 changes: 3 additions & 1 deletion integration_tests/tests/steps/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ async fn indexer_scans_network_events(
account_name: String,
topics_str: String,
) {
let indexer: &mut IndexerProcess = world.indexers.get_mut(&indexer_name).unwrap();
let indexer: &mut IndexerProcess = world.indexers.get_mut(&indexer_name).unwrap_or_else(|| {
panic!("Indexer {} not found", indexer_name);
});
let accounts_component_addresses = world.outputs.get(&account_name).expect("Account name not found");
let component_address = accounts_component_addresses
.into_iter()
Expand Down

0 comments on commit 62b6cde

Please sign in to comment.