Skip to content

Commit

Permalink
fix: remove purpose from BaseWallet
Browse files Browse the repository at this point in the history
  • Loading branch information
greatertomi committed Jun 3, 2024
1 parent 3848952 commit 3ae0b1b
Show file tree
Hide file tree
Showing 42 changed files with 63 additions and 114 deletions.
11 changes: 4 additions & 7 deletions packages/e2e/src/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
CommunicationType,
InMemoryKeyAgent,
KeyAgentDependencies,
KeyPurpose,
Witnesser,
util
} from '@cardano-sdk/key-management';
Expand Down Expand Up @@ -281,7 +280,6 @@ export type GetWalletProps = {
env: any;
idx?: number;
logger: Logger;
purpose: KeyPurpose;
name: string;
polling?: PollingConfig;
handlePolicyIds?: Cardano.PolicyId[];
Expand All @@ -295,7 +293,6 @@ export type GetSharedWalletProps = {
env: any;
logger: Logger;
name: string;
purpose: KeyPurpose;
polling?: PollingConfig;
handlePolicyIds?: Cardano.PolicyId[];
stores?: storage.WalletStores;
Expand Down Expand Up @@ -327,7 +324,7 @@ const patchInitializeTxToRespectEpochBoundary = <T extends ObservableWallet>(
* @returns an object containing the wallet and providers passed to it
*/
export const getWallet = async (props: GetWalletProps) => {
const { env, idx, logger, name, stores, customKeyParams, keyAgent, witnesser, purpose } = props;
const { env, idx, logger, name, stores, customKeyParams, keyAgent, witnesser } = props;
let polling = props.polling;
const providers = {
addressDiscovery: await addressDiscoveryFactory.create(
Expand Down Expand Up @@ -384,7 +381,7 @@ export const getWallet = async (props: GetWalletProps) => {
}

const wallet = createPersonalWallet(
{ name, polling, purpose },
{ name, polling },
{
...providers,
bip32Account,
Expand All @@ -411,7 +408,7 @@ export const getWallet = async (props: GetWalletProps) => {
* @returns an object containing the wallet and providers passed to it
*/
export const getSharedWallet = async (props: GetSharedWalletProps) => {
const { env, logger, name, polling, stores, paymentScript, stakingScript, witnesser, purpose } = props;
const { env, logger, name, polling, stores, paymentScript, stakingScript, witnesser } = props;
const providers = {
assetProvider: await assetProviderFactory.create(env.ASSET_PROVIDER, env.ASSET_PROVIDER_PARAMS, logger),
chainHistoryProvider: await chainHistoryProviderFactory.create(
Expand Down Expand Up @@ -439,7 +436,7 @@ export const getSharedWallet = async (props: GetSharedWalletProps) => {
utxoProvider: await utxoProviderFactory.create(env.UTXO_PROVIDER, env.UTXO_PROVIDER_PARAMS, logger)
};
const wallet = createSharedWallet(
{ name, polling, purpose },
{ name, polling },
{
...providers,
logger,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console, max-statements, max-params, @typescript-eslint/no-floating-promises */
import { Cardano } from '@cardano-sdk/core';
import { KeyPurpose, util } from '@cardano-sdk/key-management';
import { logger } from '@cardano-sdk/util-dev';
import { util } from '@cardano-sdk/key-management';

import { BaseWallet } from '@cardano-sdk/wallet';
import { Files, Paths } from './files';
Expand Down Expand Up @@ -102,8 +102,7 @@ export const waitForFundingWallet = async (monitor: TerminalProgressMonitor): Pr
idx: 0,
logger,
name: 'Funding wallet',
polling: { interval: 500 },
purpose: KeyPurpose.STANDARD
polling: { interval: 500 }
})
).wallet;

Expand Down Expand Up @@ -140,8 +139,7 @@ export const createDelegationWallet = async (monitor: TerminalProgressMonitor) =
idx: 0,
logger,
name: 'Delegation Wallet',
polling: { interval: 500 },
purpose: KeyPurpose.STANDARD
polling: { interval: 500 }
})
).wallet;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ export const walletRestoration: FunctionHook<WalletVars> = async ({ vars, _uid }
keyAgent,
logger,
name: `Test Wallet of VU with id: ${_uid}`,
polling: { interval: 50 },
purpose: KeyPurpose.STANDARD
polling: { interval: 50 }
});

vars.currentWallet = wallet;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable import/imports-first */
import * as dotenv from 'dotenv';
import { BaseWallet, createPersonalWallet } from '@cardano-sdk/wallet';
import { Bip32Account, KeyPurpose, util } from '@cardano-sdk/key-management';
import { Bip32Account, util } from '@cardano-sdk/key-management';
import { Logger } from 'ts-log';
import {
MeasurementUtil,
Expand Down Expand Up @@ -83,7 +83,7 @@ const createWallet = async (accountIndex: number): Promise<BaseWallet> => {

measurementUtil.addStartMarker(MeasureTarget.wallet, accountIndex);
return createPersonalWallet(
{ name: `Wallet ${accountIndex}`, purpose: KeyPurpose.STANDARD },
{ name: `Wallet ${accountIndex}` },
{
...providers,
bip32Account: await Bip32Account.fromAsyncKeyAgent(keyAgent),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import path from 'path';
dotenv.config({ path: path.join(__dirname, '../../../.env') });
import { BaseWallet } from '@cardano-sdk/wallet';
import { Cardano } from '@cardano-sdk/core';
import { GroupedAddress, KeyPurpose, util } from '@cardano-sdk/key-management';
import { GroupedAddress, util } from '@cardano-sdk/key-management';
import { Logger } from 'ts-log';
import { MINUTE, createMockKeyAgent, getEnv, getWallet, waitForWalletStateSettle, walletVariables } from '../../../src';
import { logger } from '@cardano-sdk/util-dev';
Expand Down Expand Up @@ -48,8 +48,7 @@ const initWallets = async (walletsNum: number, addresses: GroupedAddress[]): Pro
keyAgent,
logger,
name: 'Test Wallet',
polling: { interval: 50 },
purpose: KeyPurpose.STANDARD
polling: { interval: 50 }
});
wallets.push(wallet);
}
Expand Down
8 changes: 3 additions & 5 deletions packages/e2e/test/local-network/register-pool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { firstValueFrom } from 'rxjs';
import { logger } from '@cardano-sdk/util-dev';

import * as Crypto from '@cardano-sdk/crypto';
import { AddressType, KeyPurpose, KeyRole } from '@cardano-sdk/key-management';
import { AddressType, KeyRole } from '@cardano-sdk/key-management';

const env = getEnv(walletVariables);

Expand Down Expand Up @@ -54,17 +54,15 @@ describe('local-network/register-pool', () => {
idx: 0,
logger,
name: 'Pool Wallet 1',
polling: { interval: 500 },
purpose: KeyPurpose.STANDARD
polling: { interval: 500 }
});
wallet2 = await getWallet({
customKeyParams: wallet2Params,
env,
idx: 0,
logger,
name: 'Pool Wallet 2',
polling: { interval: 500 },
purpose: KeyPurpose.STANDARD
polling: { interval: 500 }
});

await waitForWalletStateSettle(wallet1.wallet);
Expand Down
5 changes: 2 additions & 3 deletions packages/e2e/test/long-running/cache-invalidation.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Crypto from '@cardano-sdk/crypto';
import { AddressType, KeyPurpose, KeyRole } from '@cardano-sdk/key-management';
import { AddressType, KeyRole } from '@cardano-sdk/key-management';
import { Cardano } from '@cardano-sdk/core';
import {
KeyAgentFactoryProps,
Expand Down Expand Up @@ -89,8 +89,7 @@ describe('cache invalidation', () => {
idx: 0,
logger,
name: 'Pool Wallet 1',
polling: { interval: 500 },
purpose: KeyPurpose.STANDARD
polling: { interval: 500 }
});

await waitForWalletStateSettle(wallet1.wallet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ describe('multi signature wallet', () => {
env,
logger,
name: 'Faucet Wallet',
polling: { interval: 50 },
purpose: KeyPurpose.MULTI_SIG
polling: { interval: 50 }
}));

await walletReady(faucetWallet);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { BaseWallet } from '@cardano-sdk/wallet';
import { Cardano, StakePoolProvider } from '@cardano-sdk/core';
import { KeyPurpose } from '@cardano-sdk/key-management';
import { buildSharedWallets } from '../wallet_epoch_0/SharedWallet/utils';
import { filter, firstValueFrom, map, take } from 'rxjs';
import {
Expand Down Expand Up @@ -102,7 +101,7 @@ describe('shared wallet delegation rewards', () => {
({
wallet: faucetWallet,
providers: { stakePoolProvider }
} = await getWallet({ env, logger, name: 'Sending Wallet', purpose: KeyPurpose.MULTI_SIG }));
} = await getWallet({ env, logger, name: 'Sending Wallet' }));

// Make sure the wallet has sufficient funds to run this test
await walletReady(faucetWallet, initialFunds);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { BaseWallet } from '@cardano-sdk/wallet';
import { Cardano, StakePoolProvider } from '@cardano-sdk/core';
import { KeyPurpose } from '@cardano-sdk/key-management';
import {
TestWallet,
getEnv,
Expand Down Expand Up @@ -86,10 +85,9 @@ describe('simple delegation rewards', () => {
env,
logger,
name: 'Sending Wallet',
polling: { interval: 50 },
purpose: KeyPurpose.STANDARD
polling: { interval: 50 }
}));
({ wallet: wallet2 } = await getWallet({ env, logger, name: 'Receiving Wallet', purpose: KeyPurpose.STANDARD }));
({ wallet: wallet2 } = await getWallet({ env, logger, name: 'Receiving Wallet' }));

await waitForWalletStateSettle(wallet1);
await waitForWalletStateSettle(wallet2);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable sonarjs/no-duplicate-string */
import { BaseWallet } from '@cardano-sdk/wallet';
import { Cardano } from '@cardano-sdk/core';
import { KeyPurpose } from '@cardano-sdk/key-management';
import { createLogger } from '@cardano-sdk/util-dev';
import { filter, firstValueFrom, map, take } from 'rxjs';
import { getEnv, walletVariables } from '../../../src/environment';
Expand All @@ -15,7 +14,7 @@ describe('PersonalWallet/byron', () => {
let wallet: BaseWallet;

beforeAll(async () => {
wallet = (await getWallet({ env, idx: 0, logger, name: 'Wallet', purpose: KeyPurpose.STANDARD })).wallet;
wallet = (await getWallet({ env, idx: 0, logger, name: 'Wallet' })).wallet;
});

afterAll(() => {
Expand Down
12 changes: 4 additions & 8 deletions packages/e2e/test/wallet_epoch_0/PersonalWallet/handle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ describe('Ada handle', () => {
const coins = coinsRequiredByHandleMint + 10_000_000n; // maximum number of coins to use in each transaction

const initPolicyId = async () => {
wallet = (await getWallet({ env, idx: 0, logger, name: 'Handle Init Wallet', purpose: KeyPurpose.STANDARD }))
.wallet;
wallet = (await getWallet({ env, idx: 0, logger, name: 'Handle Init Wallet' })).wallet;
await walletReady(wallet, coins);

keyAgent = await createStandaloneKeyAgent(
Expand All @@ -71,8 +70,7 @@ describe('Ada handle', () => {
idx: 0,
logger,
name: 'Minting Wallet',
polling: { interval: 50 },
purpose: KeyPurpose.STANDARD
polling: { interval: 50 }
})
).wallet;
await walletReady(wallet, coins);
Expand All @@ -87,8 +85,7 @@ describe('Ada handle', () => {
idx: 0,
logger,
name: 'Minting Wallet',
polling: { interval: 50 },
purpose: KeyPurpose.STANDARD
polling: { interval: 50 }
})
).wallet;
receivingWallet = (
Expand All @@ -98,8 +95,7 @@ describe('Ada handle', () => {
idx: 1,
logger,
name: 'Receiving Wallet',
polling: { interval: 50 },
purpose: KeyPurpose.STANDARD
polling: { interval: 50 }
})
).wallet;
await Promise.all([walletReady(wallet, coins), walletReady(receivingWallet, 0n)]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { BaseWallet, createWalletUtil } from '@cardano-sdk/wallet';
import { Cardano } from '@cardano-sdk/core';
import { KeyPurpose } from '@cardano-sdk/key-management';
import { filter, firstValueFrom, map } from 'rxjs';
import { getEnv, getWallet, walletReady, walletVariables } from '../../../src';
import { isNotNil } from '@cardano-sdk/util';
Expand All @@ -13,7 +12,7 @@ describe('PersonalWallet/metadata', () => {
let ownAddress: Cardano.PaymentAddress;

beforeAll(async () => {
wallet = (await getWallet({ env, logger, name: 'Test Wallet', purpose: KeyPurpose.STANDARD })).wallet;
wallet = (await getWallet({ env, logger, name: 'Test Wallet' })).wallet;
ownAddress = (await firstValueFrom(wallet.addresses$))[0].address;

await walletReady(wallet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('PersonalWallet/mint', () => {
});

it('can mint a token with no asset name', async () => {
wallet = (await getWallet({ env, logger, name: 'Minting Wallet', purpose: KeyPurpose.STANDARD })).wallet;
wallet = (await getWallet({ env, logger, name: 'Minting Wallet' })).wallet;

const coins = 3_000_000n;
await walletReady(wallet, coins);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('PersonalWallet/multiAddress', () => {
let wallet: BaseWallet;

beforeAll(async () => {
wallet = (await getWallet({ env, idx: 0, logger, name: 'Wallet', purpose: KeyPurpose.STANDARD })).wallet;
wallet = (await getWallet({ env, idx: 0, logger, name: 'Wallet' })).wallet;
});

afterAll(() => {
Expand Down Expand Up @@ -108,8 +108,7 @@ describe('PersonalWallet/multiAddress', () => {
idx: 0,
logger,
name: 'New Multi Address Wallet',
polling: { interval: 500 },
purpose: KeyPurpose.STANDARD
polling: { interval: 500 }
});

await walletReady(newWallet.wallet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('PersonalWallet/multisignature', () => {
});

it('can create a transaction with multiple signatures to mint an asset', async () => {
wallet = (await getWallet({ env, logger, name: 'Minting Wallet', purpose: KeyPurpose.MULTI_SIG })).wallet;
wallet = (await getWallet({ env, logger, name: 'Minting Wallet' })).wallet;

const coins = 3_000_000n;
await walletReady(wallet, coins);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('PersonalWallet.assets/nft', () => {
const coins = 10_000_000n; // number of coins to use in each transaction

beforeAll(async () => {
wallet = (await getWallet({ env, logger, name: 'Minting Wallet', purpose: KeyPurpose.STANDARD })).wallet;
wallet = (await getWallet({ env, logger, name: 'Minting Wallet' })).wallet;

await walletReady(wallet, coins);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { BaseWallet, FinalizeTxProps, TransactionFailure } from '@cardano-sdk/wa
import { Cardano, Serialization } from '@cardano-sdk/core';
import { HexBlob, isNotNil } from '@cardano-sdk/util';
import { InitializeTxProps, computeScriptDataHash } from '@cardano-sdk/tx-construction';
import { KeyPurpose } from '@cardano-sdk/key-management';
import { createLogger } from '@cardano-sdk/util-dev';
import { filter, firstValueFrom, map, take } from 'rxjs';
import { firstValueFromTimed, getEnv, getWallet, walletReady, walletVariables } from '../../../src';
Expand Down Expand Up @@ -72,9 +71,7 @@ describe('PersonalWallet/phase2validation', () => {
});

it('can detect a phase2 validation failure and emit the transaction as failed', async () => {
wallet = (
await getWallet({ env, logger, name: 'Minting Wallet', polling: { interval: 50 }, purpose: KeyPurpose.STANDARD })
).wallet;
wallet = (await getWallet({ env, logger, name: 'Minting Wallet', polling: { interval: 50 } })).wallet;

// Plutus script that always returns false.
const alwaysFailScript: Cardano.PlutusScript = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { BaseWallet } from '@cardano-sdk/wallet';
import { Cardano, Serialization, UtxoProvider } from '@cardano-sdk/core';
import { HexBlob, isNotNil } from '@cardano-sdk/util';
import { KeyPurpose } from '@cardano-sdk/key-management';
import { Observable, filter, firstValueFrom, interval, map, switchMap, take } from 'rxjs';
import { createLogger } from '@cardano-sdk/util-dev';
import { getEnv, getWallet, utxoProviderFactory, walletReady, walletVariables } from '../../../src';
Expand Down Expand Up @@ -192,9 +191,7 @@ describe('PersonalWallet/plutus', () => {
});

it('can spend balance from a plutus script', async () => {
wallet = (
await getWallet({ env, logger, name: 'Spending Wallet', polling: { interval: 50 }, purpose: KeyPurpose.STANDARD })
).wallet;
wallet = (await getWallet({ env, logger, name: 'Spending Wallet', polling: { interval: 50 } })).wallet;
// UTXO provider can be use to fetch the UTXO set from the script address.
const utxoProvider = await utxoProviderFactory.create(env.UTXO_PROVIDER, env.UTXO_PROVIDER_PARAMS, logger);

Expand Down Expand Up @@ -268,9 +265,7 @@ describe('PersonalWallet/plutus', () => {
});

it('can spend balance from a plutus script using a reference script', async () => {
wallet = (
await getWallet({ env, logger, name: 'Spending Wallet', polling: { interval: 50 }, purpose: KeyPurpose.STANDARD })
).wallet;
wallet = (await getWallet({ env, logger, name: 'Spending Wallet', polling: { interval: 50 } })).wallet;
// UTXO provider can be use to fetch the UTXO set from the script address.
const utxoProvider = await utxoProviderFactory.create(env.UTXO_PROVIDER, env.UTXO_PROVIDER_PARAMS, logger);

Expand Down
Loading

0 comments on commit 3ae0b1b

Please sign in to comment.