Skip to content

Commit

Permalink
Merge pull request #48 from varunpareek690/feat/fetchTestWallet/29
Browse files Browse the repository at this point in the history
Updated setActiveWallet.ts for fetching test wallet address
  • Loading branch information
ITZSHOAIB authored Oct 5, 2024
2 parents e2a19e3 + e259360 commit 1bc6c67
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/hot-experts-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chukti": minor
---

feat: new feature added for fetching test wallet address
18 changes: 18 additions & 0 deletions docs/step-definitions/blockchain.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ When I set the active test wallet address to the index {index}
```
[Read details](#switch-wallet-2)

```gherkin
When I fetch the wallet address at index {index}
```
[Read details](#fetch-wallet-index)

## Detailed Step Definitions

### :rocket: Then I validate the status of the last transaction is "expectedStatus" {#validate-transaction-status}
Expand Down Expand Up @@ -68,6 +73,19 @@ Given I set the active test wallet address to the index 1
```
:::

### :rocket: When I fetch the wallet address at index {index} {#fetch-wallet-index}
- **Purpose**
To fetch the wallet address from the provided index without setting it as the active wallet.

- **Required Values:**
- `index`: The index of the wallet address in the test client list.

::: details **Example**
```gherkin
When I fetch the wallet address at index 2
```
:::

::: tip :bulb: Tip
Wanna learn how to write test using these step definitions? Visit [How To Write Test page](/guide/how-to-write-test).
:::
6 changes: 6 additions & 0 deletions src/cucumber/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { verifyContractPathStep } from "./steps/contract/verifyPath.js";
import { writeContractStep } from "./steps/contract/write.js";
import { resultComparisonStep } from "./steps/generic/dataComparison.js";
import { storeResultStep } from "./steps/generic/storeResult.js";
import { fetchWalletByIndexStep } from "./steps/blockchain/setActiveWallet.js";

/**
* Parameters required for registering Chukti steps with the Cucumber framework.
Expand Down Expand Up @@ -95,6 +96,11 @@ export const registerChuktiSteps = ({
"I validate the status of the last transaction is {string}",
validateTxnStep,
);

When(
"I fetch the wallet address at index {int}",
fetchWalletByIndexStep
);
When(
"I set the active test wallet address to the address {string}",
setActiveWalletByAddressStep,
Expand Down
20 changes: 20 additions & 0 deletions src/cucumber/steps/blockchain/setActiveWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,23 @@ export const setActiveWalletByIndexStep = async (index: number) => {
`Active test wallet address set to address at index ${index}: ${testWallet}`,
);
};

/**
* Fetches the wallet address by the provided index
* @param index- The index of the test wallet address to set as active.
*
* @example
* import { fetchWalletByIndexStep } from "chukti";
* When("I fetch the wallet address at index {int}", fetchWalletByIndexStep);
*/

export const fetchWalletByIndexStep = async (index: number) => {
const testWallet = await getTestWalletAddress({ index });
if(!world.chukti){
world.chukti ={};
}
world.chukti.lastResult = testWallet;

// Log the fetched wallet without setting it as active
world.log(`Fetched wallet address at index ${index}: ${testWallet}`);
};

0 comments on commit 1bc6c67

Please sign in to comment.