Skip to content

Commit

Permalink
test: replaced bip32Ed25519 default strategy (CML for Sodium)
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelCastilloB committed Jul 18, 2023
1 parent e2b1808 commit 0d51847
Show file tree
Hide file tree
Showing 19 changed files with 38 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
yarn workspace @cardano-sdk/e2e test:pg-boss
env:
KEY_MANAGEMENT_PROVIDER: 'inMemory'
KEY_MANAGEMENT_PARAMS: '{"bip32Ed25519": "CML", "accountIndex": 0, "chainId":{"networkId": 0, "networkMagic": 888}, "passphrase":"some_passphrase","mnemonic":"vacant violin soft weird deliver render brief always monitor general maid smart jelly core drastic erode echo there clump dizzy card filter option defense"}'
KEY_MANAGEMENT_PARAMS: '{"bip32Ed25519": "Sodium", "accountIndex": 0, "chainId":{"networkId": 0, "networkMagic": 888}, "passphrase":"some_passphrase","mnemonic":"vacant violin soft weird deliver render brief always monitor general maid smart jelly core drastic erode echo there clump dizzy card filter option defense"}'
ASSET_PROVIDER: 'http'
ASSET_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:4000/asset"}'
CHAIN_HISTORY_PROVIDER: 'http'
Expand Down
12 changes: 5 additions & 7 deletions packages/e2e/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ LOGGER_MIN_SEVERITY=info

# Key management setup - required by getWallet
KEY_MANAGEMENT_PROVIDER=inMemory
KEY_MANAGEMENT_PARAMS='{"bip32Ed25519": "CML", "accountIndex": 0, "chainId":{"networkId": 0, "networkMagic": 888}, "passphrase":"some_passphrase","mnemonic":"vacant violin soft weird deliver render brief always monitor general maid smart jelly core drastic erode echo there clump dizzy card filter option defense"}'
#KEY_MANAGEMENT_PARAMS='{"bip32Ed25519": "CML", "accountIndex": 0, "chainId":{"networkId": 0, "networkMagic": 888}, "passphrase":"some_passphrase","mnemonic":"slab gorilla reflect display cage aim silver add own arrange crew start female bitter menu inner combine exit swallow bamboo midnight wealth culture picnic"}'
#KEY_MANAGEMENT_PARAMS='{"bip32Ed25519": "CML", "accountIndex": 0, "chainId":{"networkId": 0, "networkMagic": 888}, "passphrase":"some_passphrase","mnemonic":"decorate survey empower stairs pledge humble social leisure baby wrap grief exact monster rug dash kiss perfect select science light frame play swallow day"}'
#KEY_MANAGEMENT_PARAMS='{"bip32Ed25519": "CML", "accountIndex": 0, "chainId":{"networkId": 0, "networkMagic": 888}, "passphrase":"some_passphrase","mnemonic":"phrase raw learn suspect inmate powder combine apology regular hero gain chronic fruit ritual short screen goddess odor keen creek brand today kit machine"}'
#KEY_MANAGEMENT_PARAMS='{"bip32Ed25519": "CML", "accountIndex": 0, "chainId":{"networkId": 0, "networkMagic": 888}, "passphrase":"some_passphrase","mnemonic":"salon zoo engage submit smile frost later decide wing sight chaos renew lizard rely canal coral scene hobby scare step bus leaf tobacco slice"}'
KEY_MANAGEMENT_PARAMS='{"bip32Ed25519": "Sodium", "accountIndex": 0, "chainId":{"networkId": 0, "networkMagic": 888}, "passphrase":"some_passphrase","mnemonic":"vacant violin soft weird deliver render brief always monitor general maid smart jelly core drastic erode echo there clump dizzy card filter option defense"}'
#KEY_MANAGEMENT_PARAMS='{"bip32Ed25519": "Sodium", "accountIndex": 0, "chainId":{"networkId": 0, "networkMagic": 888}, "passphrase":"some_passphrase","mnemonic":"slab gorilla reflect display cage aim silver add own arrange crew start female bitter menu inner combine exit swallow bamboo midnight wealth culture picnic"}'
#KEY_MANAGEMENT_PARAMS='{"bip32Ed25519": "Sodium", "accountIndex": 0, "chainId":{"networkId": 0, "networkMagic": 888}, "passphrase":"some_passphrase","mnemonic":"decorate survey empower stairs pledge humble social leisure baby wrap grief exact monster rug dash kiss perfect select science light frame play swallow day"}'
#KEY_MANAGEMENT_PARAMS='{"bip32Ed25519": "Sodium", "accountIndex": 0, "chainId":{"networkId": 0, "networkMagic": 888}, "passphrase":"some_passphrase","mnemonic":"phrase raw learn suspect inmate powder combine apology regular hero gain chronic fruit ritual short screen goddess odor keen creek brand today kit machine"}'
#KEY_MANAGEMENT_PARAMS='{"bip32Ed25519": "Sodium", "accountIndex": 0, "chainId":{"networkId": 0, "networkMagic": 888}, "passphrase":"some_passphrase","mnemonic":"salon zoo engage submit smile frost later decide wing sight chaos renew lizard rely canal coral scene hobby scare step bus leaf tobacco slice"}'

# Providers setup - required by getWallet
ASSET_PROVIDER=http
Expand All @@ -27,8 +27,6 @@ UTXO_PROVIDER_PARAMS='{"baseUrl":"http://localhost:4000/utxo"}'
STAKE_POOL_PROVIDER=http
STAKE_POOL_PROVIDER_PARAMS='{"baseUrl":"http://localhost:4000/stake-pool"}'



# Required by test:ogmios, test:blockfrost
DB_SYNC_CONNECTION_STRING='postgresql://postgres:doNoUseThisSecret!@localhost:5435/cexplorer'
STAKE_POOL_CONNECTION_STRING='postgresql://postgres:doNoUseThisSecret!@localhost:5435/stake_pool'
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@
"buffer": "^6.0.3",
"chromedriver": "114.0.1",
"copy-webpack-plugin": "^10.2.4",
"dockerode": "^3.3.1",
"dockerode-utils": "^0.0.7",
"crypto-browserify": "^3.12.0",
"delay": "^5.0.0",
"dockerode": "^3.3.1",
"dockerode-utils": "^0.0.7",
"eslint": "^7.32.0",
"events": "^3.3.0",
"expect-webdriverio": "^3.2.1",
Expand Down
1 change: 1 addition & 0 deletions packages/e2e/src/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ addressDiscoveryFactory.register(
// bip32Ed25519

bip32Ed25519Factory.register('CML', async () => new Crypto.CmlBip32Ed25519(CML));
bip32Ed25519Factory.register('Sodium', async () => new Crypto.SodiumBip32Ed25519());

// Asset providers

Expand Down
5 changes: 2 additions & 3 deletions packages/e2e/src/scripts/mnemonic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
/* eslint-disable @typescript-eslint/no-floating-promises */
import * as Crypto from '@cardano-sdk/crypto';
import { AddressType, InMemoryKeyAgent, util } from '@cardano-sdk/key-management';
import { CML } from '@cardano-sdk/core';
import { localNetworkChainId } from '../util/localNetworkChainId';
import { localNetworkChainId } from '../util';

/**
* Generates a new set of Mnemonic words and prints them to the console.
Expand All @@ -20,7 +19,7 @@ import { localNetworkChainId } from '../util/localNetworkChainId';
mnemonicWords: mnemonicArray
},
{
bip32Ed25519: new Crypto.CmlBip32Ed25519(CML),
bip32Ed25519: new Crypto.SodiumBip32Ed25519(),
inputResolver: { resolveInput: async () => null },
logger: console
}
Expand Down
4 changes: 2 additions & 2 deletions packages/governance/test/cip36.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Crypto from '@cardano-sdk/crypto';
import { CML, Cardano, coreToCml } from '@cardano-sdk/core';
import { Cardano, coreToCml } from '@cardano-sdk/core';
import { cip36 } from '../src';
import { usingAutoFree } from '@cardano-sdk/util';

Expand Down Expand Up @@ -57,7 +57,7 @@ describe('cip36', () => {
);
const signedCip36Metadata = await cip36.metadataBuilder.signVotingRegistration(votingRegistrationMetadata, {
signBlob: async (blob) => {
const bip32Ed25519 = new Crypto.CmlBip32Ed25519(CML);
const bip32Ed25519 = new Crypto.SodiumBip32Ed25519();
const privateStakeKey = Crypto.Ed25519PrivateNormalKeyHex(
'852fa5d17df3efdfdcd6dac53ec9fe5593f3c0bd7cadb3c2af76c7e15dfa8a5c'
);
Expand Down
4 changes: 2 additions & 2 deletions packages/key-management/test/InMemoryKeyAgent.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Crypto from '@cardano-sdk/crypto';
import { AddressType, InMemoryKeyAgent, KeyRole, SerializableInMemoryKeyAgentData, util } from '../src';
import { CML, Cardano } from '@cardano-sdk/core';
import { Cardano } from '@cardano-sdk/core';
import { HexBlob } from '@cardano-sdk/util';
import { dummyLogger } from 'ts-log';

Expand All @@ -12,7 +12,7 @@ describe('InMemoryKeyAgent', () => {
let getPassphrase: jest.Mock;
let inputResolver: jest.Mocked<Cardano.InputResolver>;
let mnemonicWords: string[];
const bip32Ed25519 = new Crypto.CmlBip32Ed25519(CML);
const bip32Ed25519 = new Crypto.SodiumBip32Ed25519();

beforeEach(async () => {
mnemonicWords = util.generateMnemonicWords();
Expand Down
4 changes: 2 additions & 2 deletions packages/key-management/test/KeyAgentBase.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import {
KeyRole,
SerializableInMemoryKeyAgentData
} from '../src';
import { CML, Cardano } from '@cardano-sdk/core';
import { Cardano } from '@cardano-sdk/core';
import { dummyLogger } from 'ts-log';

const ACCOUNT_INDEX = 1;
const bip32Ed25519 = new Crypto.CmlBip32Ed25519(CML);
const bip32Ed25519 = new Crypto.SodiumBip32Ed25519();

class MockKeyAgent extends KeyAgentBase {
constructor(data: SerializableInMemoryKeyAgentData) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { CML } from '@cardano-sdk/core';
import { CmlBip32Ed25519 } from '@cardano-sdk/crypto';
import { KeyAgentDependencies } from '../../src/';
import { SodiumBip32Ed25519 } from '@cardano-sdk/crypto';
import { dummyLogger } from 'ts-log';

export const mockKeyAgentDependencies = (): jest.Mocked<KeyAgentDependencies> => ({
bip32Ed25519: new CmlBip32Ed25519(CML),
bip32Ed25519: new SodiumBip32Ed25519(),
inputResolver: {
resolveInput: jest.fn().mockResolvedValue(null)
},
Expand Down
4 changes: 2 additions & 2 deletions packages/key-management/test/util/createAsyncKeyAgent.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Crypto from '@cardano-sdk/crypto';
import { AsyncKeyAgent, InMemoryKeyAgent, KeyAgent, util } from '../../src';
import { CML, Cardano } from '@cardano-sdk/core';
import { Cardano } from '@cardano-sdk/core';
import { HexBlob } from '@cardano-sdk/util';
import { dummyLogger } from 'ts-log';
import { firstValueFrom } from 'rxjs';
Expand All @@ -21,7 +21,7 @@ describe('createAsyncKeyAgent maps KeyAgent to AsyncKeyAgent', () => {
getPassphrase,
mnemonicWords
},
{ bip32Ed25519: new Crypto.CmlBip32Ed25519(CML), inputResolver, logger: dummyLogger }
{ bip32Ed25519: new Crypto.SodiumBip32Ed25519(), inputResolver, logger: dummyLogger }
);
asyncKeyAgent = util.createAsyncKeyAgent(keyAgent);
});
Expand Down
3 changes: 1 addition & 2 deletions packages/wallet/test/PersonalWallet/load.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
somePartialStakePools
} from '@cardano-sdk/util-dev';
import {
CML,
Cardano,
ChainHistoryProvider,
NetworkInfoProvider,
Expand Down Expand Up @@ -88,7 +87,7 @@ type CreateWalletProps = {

const createWallet = async (props: CreateWalletProps) => {
const { wallet } = await setupWallet({
bip32Ed25519: new Crypto.CmlBip32Ed25519(CML),
bip32Ed25519: new Crypto.SodiumBip32Ed25519(),
createKeyAgent: async (dependencies) => {
const groupedAddress: GroupedAddress = {
accountIndex: 0,
Expand Down
3 changes: 1 addition & 2 deletions packages/wallet/test/PersonalWallet/rollback.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as Crypto from '@cardano-sdk/crypto';
import { AddressType, GroupedAddress } from '@cardano-sdk/key-management';
import {
CML,
Cardano,
ChainHistoryProvider,
NetworkInfoProvider,
Expand Down Expand Up @@ -32,7 +31,7 @@ interface Providers {

const createWallet = async (stores: WalletStores, providers: Providers, pollingConfig?: PollingConfig) => {
const { wallet } = await setupWallet({
bip32Ed25519: new Crypto.CmlBip32Ed25519(CML),
bip32Ed25519: new Crypto.SodiumBip32Ed25519(),
createKeyAgent: async (dependencies) => {
const groupedAddress: GroupedAddress = {
accountIndex: 0,
Expand Down
3 changes: 1 addition & 2 deletions packages/wallet/test/PersonalWallet/shutdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
somePartialStakePools
} from '@cardano-sdk/util-dev';
import {
CML,
Cardano,
ChainHistoryProvider,
NetworkInfoProvider,
Expand Down Expand Up @@ -50,7 +49,7 @@ const createWallet = async (
pollingConfig?: PollingConfig
) => {
const { wallet } = await setupWallet({
bip32Ed25519: new Crypto.CmlBip32Ed25519(CML),
bip32Ed25519: new Crypto.SodiumBip32Ed25519(),
createKeyAgent: async (dependencies) => {
const groupedAddress: GroupedAddress = {
accountIndex: 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Crypto from '@cardano-sdk/crypto';
import { CML, Cardano } from '@cardano-sdk/core';

import { Cardano } from '@cardano-sdk/core';
import { CommunicationType, KeyAgent, util } from '@cardano-sdk/key-management';
import { LedgerKeyAgent } from '@cardano-sdk/hardware-ledger';
import { ObservableWallet, PersonalWallet, restoreKeyAgent, setupWallet } from '../../../src';
Expand Down Expand Up @@ -46,7 +47,7 @@ const getAddress = async (wallet: ObservableWallet) => (await firstValueFrom(wal
describe('LedgerKeyAgent+PersonalWallet', () => {
test('creating and restoring LedgerKeyAgent wallet', async () => {
const { wallet: freshWallet, keyAgent: freshKeyAgent } = await setupWallet({
bip32Ed25519: new Crypto.CmlBip32Ed25519(CML),
bip32Ed25519: new Crypto.SodiumBip32Ed25519(),
createKeyAgent: (dependencies) =>
LedgerKeyAgent.createWithDevice(
{
Expand All @@ -59,7 +60,7 @@ describe('LedgerKeyAgent+PersonalWallet', () => {
logger
});
const { wallet: restoredWallet } = await setupWallet({
bip32Ed25519: new Crypto.CmlBip32Ed25519(CML),
bip32Ed25519: new Crypto.SodiumBip32Ed25519(),
createKeyAgent: (dependencies) => restoreKeyAgent(freshKeyAgent.serializableData, dependencies),
createWallet,
logger
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Crypto from '@cardano-sdk/crypto';
import { CML, Cardano } from '@cardano-sdk/core';
import { Cardano } from '@cardano-sdk/core';
import { CommunicationType, KeyAgent, TrezorKeyAgent, util } from '@cardano-sdk/key-management';
import { ObservableWallet, PersonalWallet, restoreKeyAgent, setupWallet } from '../../../src';
import { createStubStakePoolProvider, mockProviders } from '@cardano-sdk/util-dev';
Expand Down Expand Up @@ -45,7 +45,7 @@ const getAddress = async (wallet: ObservableWallet) => (await firstValueFrom(wal
describe('TrezorKeyAgent+PersonalWallet', () => {
test('creating and restoring TrezorKeyAgent wallet', async () => {
const { wallet: freshWallet, keyAgent: freshKeyAgent } = await setupWallet({
bip32Ed25519: new Crypto.CmlBip32Ed25519(CML),
bip32Ed25519: new Crypto.SodiumBip32Ed25519(),
createKeyAgent: (dependencies) =>
TrezorKeyAgent.createWithDevice(
{
Expand All @@ -64,7 +64,7 @@ describe('TrezorKeyAgent+PersonalWallet', () => {
logger
});
const { wallet: restoredWallet } = await setupWallet({
bip32Ed25519: new Crypto.CmlBip32Ed25519(CML),
bip32Ed25519: new Crypto.SodiumBip32Ed25519(),
createKeyAgent: (dependencies) => restoreKeyAgent(freshKeyAgent.serializableData, dependencies),
createWallet,
logger
Expand Down
4 changes: 2 additions & 2 deletions packages/wallet/test/hardware/trezor/TrezorKeyAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
util
} from '@cardano-sdk/key-management';
import { AssetId, createStubStakePoolProvider, mockProviders as mocks } from '@cardano-sdk/util-dev';
import { CML, Cardano } from '@cardano-sdk/core';
import { Cardano } from '@cardano-sdk/core';
import { PersonalWallet, setupWallet } from '../../../src';
import { dummyLogger as logger } from 'ts-log';
import { mockKeyAgentDependencies, stakeKeyDerivationPath } from '../../../../key-management/test/mocks';
Expand All @@ -28,7 +28,7 @@ describe('TrezorKeyAgent', () => {
beforeAll(async () => {
txSubmitProvider = mocks.mockTxSubmitProvider();
({ keyAgent, wallet } = await setupWallet({
bip32Ed25519: new Crypto.CmlBip32Ed25519(CML),
bip32Ed25519: new Crypto.SodiumBip32Ed25519(),

createKeyAgent: async (dependencies) => {
const trezorKeyAgent = await TrezorKeyAgent.createWithDevice(
Expand Down
3 changes: 1 addition & 2 deletions packages/wallet/test/integration/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as Crypto from '@cardano-sdk/crypto';
import { CML } from '@cardano-sdk/core';
import { PersonalWallet, setupWallet } from '../../src';
import { WalletStores } from '../../src/persistence';
import { createStubStakePoolProvider, mockProviders } from '@cardano-sdk/util-dev';
Expand Down Expand Up @@ -32,7 +31,7 @@ export type Providers = {

export const createWallet = async (stores?: WalletStores, providers: Providers = {}) =>
await setupWallet({
bip32Ed25519: new Crypto.CmlBip32Ed25519(CML),
bip32Ed25519: new Crypto.SodiumBip32Ed25519(),
createKeyAgent: (dependencies) => testAsyncKeyAgent(undefined, dependencies),
createWallet: async (keyAgent) =>
new PersonalWallet(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import {
errors,
util
} from '@cardano-sdk/key-management';
import { CML, Cardano } from '@cardano-sdk/core';
import { Cardano } from '@cardano-sdk/core';

import { dummyLogger } from 'ts-log';
import { restoreKeyAgent } from '../../../src';

describe('KeyManagement/restoreKeyAgent', () => {
const dependencies: KeyAgentDependencies = {
bip32Ed25519: new Crypto.CmlBip32Ed25519(CML),
bip32Ed25519: new Crypto.SodiumBip32Ed25519(),
inputResolver: { resolveInput: jest.fn() },
logger: dummyLogger
};
Expand Down
3 changes: 1 addition & 2 deletions packages/wallet/test/setupWallet.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import * as Crypto from '@cardano-sdk/crypto';
import { CML } from '@cardano-sdk/core';
import { logger } from '@cardano-sdk/util-dev';
import { setupWallet } from '../src';

jest.mock('../src/services/WalletUtil');
const { createLazyWalletUtil } = jest.requireMock('../src/services/WalletUtil');

describe('setupWallet', () => {
const bip32Ed25519 = new Crypto.CmlBip32Ed25519(CML);
const bip32Ed25519 = new Crypto.SodiumBip32Ed25519();

it('initializes WalletUtil with the wallet that is then used as InputResolver for KeyAgent', async () => {
const initialize = jest.fn();
Expand Down

0 comments on commit 0d51847

Please sign in to comment.