Skip to content

Commit

Permalink
feat(e2e): added faucet factory
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelCastilloB committed Jun 21, 2022
1 parent ea28890 commit a171968
Show file tree
Hide file tree
Showing 11 changed files with 274 additions and 54 deletions.
21 changes: 2 additions & 19 deletions packages/e2e/.env.example
@@ -1,20 +1,3 @@
TX_SUBMIT_PROVIDER=blockfrost
TX_SUBMIT_HTTP_URL=http://localhost:3000
WALLET_PROVIDER=blockfrost
REWARDS_PROVIDER=blockfrost
ASSET_PROVIDER=blockfrost
STAKE_POOL_PROVIDER=stub
NETWORK_INFO_PROVIDER=blockfrost
CHAIN_HISTORY_PROVIDER=blockfrost
BLOCKFROST_API_KEY=testnetNElagmhpQDubE6Ic4XBUVJjV5DROyijO # A valid api key can be obtained at https://blockfrost.io/
NETWORK_ID=0
MNEMONIC_WORDS="actor scout worth mansion thumb device mass pave gospel secret height document merge text broom kind lesson invest across estate erase interest end century"
WALLET_PASSWORD=some_password
POOL_ID_1=pool1euf2nh92ehqfw7rpd4s9qgq34z8dg4pvfqhjmhggmzk95gcd402
POOL_ID_2=pool1fghrkl620rl3g54ezv56weeuwlyce2tdannm2hphs62syf3vyyh
OGMIOS_URL=ws://localhost:1337
LOGGER_MIN_SEVERITY=debug
KEY_AGENT=InMemory
UTXO_PROVIDER=blockfrost
CARDANO_WALLET_URL=http://localhost:8090/v2
FAUCET_SEED_WORDS="fire method repair aware foot tray accuse brother popular olive find account sick rocket next"
FAUCET_PROVIDER="CardanoWalletFaucetProvider"
FAUCET_PROVIDER_PARAMS='{"url":"http://localhost:8090/v2","mnomonics":"fire method repair aware foot tray accuse brother popular olive find account sick rocket next"}'
1 change: 1 addition & 0 deletions packages/e2e/jest.config.js
@@ -1,6 +1,7 @@
module.exports = {
coveragePathIgnorePatterns: ['.config.js'],
preset: 'ts-jest',
setupFiles: ['dotenv/config'],
testTimeout: process.env.CI ? 120000 : 12000,
transform: {
'^.+\\.test.ts?$': 'ts-jest'
Expand Down
126 changes: 126 additions & 0 deletions packages/e2e/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions packages/e2e/package.json
Expand Up @@ -15,10 +15,15 @@
"author": "Angel Castillo",
"license": "Apache-2.0",
"dependencies": {
"bunyan": "^1.8.15",
"cardano-wallet-js": "^1.4.0",
"dotenv": "^16.0.1",
"envalid": "^7.3.1",
"ts-log": "^2.2.4",
"ts-stopwatch": "0.0.4"
},
"devDependencies": {
"@types/bunyan": "^1.8.8",
"@types/jest": "^28.1.2",
"jest": "^28.1.1",
"ts-jest": "^28.0.5",
Expand Down
39 changes: 39 additions & 0 deletions packages/e2e/src/FaucetProvider/faucetFactory.ts
@@ -0,0 +1,39 @@
import { CardanoWalletFaucetProvider } from "./providers/cardanoWalletFaucetProvider"
import { FaucetProvider } from "./types"

// Constants
const PARAM_NAME_URL: string = 'url';
const PARAM_NAME_MNEMONICS: string = 'mnomonics';

/**
* Faucet provider factories.
*/
export class FaucetFactory {

/**
* Creates a new faucet factory.
*
* @param name The name of the concrete facet provider implementation.
* @param params The parameters to be passed to the concrete implementation constructor.
*
* @returns The new Faucet provider.
*
* @throws if The give provider name is not registered, or the constructor parameters of the providers are either missing or invalid.
*/
static create(name: string, params: any): FaucetProvider {

if (name === CardanoWalletFaucetProvider.name) {

if (!params.hasOwnProperty(PARAM_NAME_URL))
throw new Error(`${CardanoWalletFaucetProvider.name} missing argument: ${PARAM_NAME_URL}`);

if (!params.hasOwnProperty(PARAM_NAME_MNEMONICS))
throw new Error(`${CardanoWalletFaucetProvider.name} missing argument: ${PARAM_NAME_MNEMONICS}`);

return new CardanoWalletFaucetProvider(params[PARAM_NAME_URL], params[PARAM_NAME_MNEMONICS]);

} else {
throw new Error(`Faucet provider unsupported: ${name}`);
}
}
}
1 change: 1 addition & 0 deletions packages/e2e/src/FaucetProvider/index.ts
@@ -1,2 +1,3 @@
export * from './types';
export * from './providers/cardanoWalletFaucetProvider';
export * from './faucetFactory';
Expand Up @@ -17,7 +17,7 @@ const DEFAULT_CONFIRMATIONS: number = 0;
* Cardano Wallet implementation of the faucet provider. This provider utlizes the Cardano Wallet HTTP service
* to construct, sign, submit and track the transaction generated by the faucet.
*/
export class CardanoWalletFaucetService implements FaucetProvider {
export class CardanoWalletFaucetProvider implements FaucetProvider {

_serviceUrl: string = "";
_seedPhrases: string = "";
Expand All @@ -36,6 +36,19 @@ export class CardanoWalletFaucetService implements FaucetProvider {
this._seedPhrases = seedPhrases;
}

/**
* Request tAda to be transferred to a single given address.
*
* @param address The address where the tAda must be deposited.
* @param amount The amount of tAda to be deposited at the given address address (in lovelace).
* @param timeout The time we are willing to wait (in milliseconds) for the faucet request transaction to be confirmed.
* @param confirmations The number of blocks that has passed since our transaction was added to the blockchain.
*/
public async request(address: string, amount: number, confirmations: number = DEFAULT_CONFIRMATIONS, timeout: number = DEFAULT_TIMEOUT): Promise<FaucetRequestResult> {

return this.multiRequest([address], [amount], confirmations, timeout);
}

/**
* Request tAda to be transferred to the given address.
*
Expand All @@ -44,7 +57,7 @@ export class CardanoWalletFaucetService implements FaucetProvider {
* @param timeout The time we are willing to wait (in milliseconds) for the faucet request transaction to be confirmed.
* @param confirmations The number of blocks that has passed since our transaction was added to the blockchain.
*/
public async request(addresses: string[], amounts: number[], confirmations: number = DEFAULT_CONFIRMATIONS, timeout: number = DEFAULT_TIMEOUT): Promise<FaucetRequestResult> {
public async multiRequest(addresses: string[], amounts: number[], confirmations: number = DEFAULT_CONFIRMATIONS, timeout: number = DEFAULT_TIMEOUT): Promise<FaucetRequestResult> {

let faucetWallet = await this._walletServer.getShelleyWallet(this._faucetWalletId);

Expand Down Expand Up @@ -91,7 +104,7 @@ export class CardanoWalletFaucetService implements FaucetProvider {

if (e.response === undefined)
throw e;

// This seed phrases already exists on the cardano wallet service.
if (e.response.status === HTTP_ERROR_CODE_IN_CONFLICT)
{
Expand Down
24 changes: 22 additions & 2 deletions packages/e2e/src/FaucetProvider/types.ts
@@ -1,6 +1,6 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { Provider, Address } from '../../../core';
import { Provider, Address, HealthCheckResponse } from '../../../core';

/**
* Faucet request transaction status.
Expand Down Expand Up @@ -46,6 +46,16 @@ export class FaucetRequestResult {
*/
export interface FaucetProvider extends Provider {

/**
* Request tAda to be transferred to a single given address.
*
* @param address The address where the tAda must be deposited.
* @param amount The amount of tAda to be deposited at the given address address (in lovelace).
* @param timeout The time we are willing to wait (in milliseconds) for the faucet request transaction to be confirmed.
* @param confirmations The number of blocks that has passed since our transaction was added to the blockchain.
*/
request(address: string, amount: number, confirmations?: number, timeout?: number): Promise<FaucetRequestResult>;

/**
* Request tAda to be transferred to several given addresses.
*
Expand All @@ -54,5 +64,15 @@ export interface FaucetProvider extends Provider {
* @param timeout The time we are willing to wait (in milliseconds) for the faucet request transaction to be confirmed.
* @param confirmations The number of blocks that has passed since our transaction was added to the blockchain.
*/
request(addresses: string[], amounts: number[], confirmations: number, timeout: number): Promise<FaucetRequestResult>;
multiRequest(addresses: string[], amounts: number[], confirmations?: number, timeout?: number): Promise<FaucetRequestResult>;

start?(): Promise<void>;
/**
* @throws ProviderError
*/
close?(): Promise<void>;
/**
* @throws ProviderError
*/
healthCheck(): Promise<HealthCheckResponse>;
}

0 comments on commit a171968

Please sign in to comment.