Skip to content

Commit

Permalink
fix test pairing to use simpler deviceid, pw, appname system
Browse files Browse the repository at this point in the history
  • Loading branch information
netbonus committed Jul 9, 2024
1 parent 1f50d75 commit a68793d
Show file tree
Hide file tree
Showing 17 changed files with 129 additions and 86 deletions.
5 changes: 3 additions & 2 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
REUSE_KEY=0
APP_NAME="SDK Test"
DEVICE_ID=""
PASSWORD=""

ENC_PW=
ETHERSCAN_KEY=""
name="SDK Test"
baseUrl="https://signing.gridpl.us"
9 changes: 7 additions & 2 deletions src/__test__/e2e/btc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import {
setup_btc_sig_test,
stripDER,
} from '../utils/helpers';
import { initializeClient } from '../utils/initializeClient';
import { testRequest } from '../utils/testRequest';
import { setupClient } from '../utils/setup';
import { Wallet } from 'ethers';

const prng = getPrng();
const TEST_TESTNET = !!getTestnet() || false;
Expand Down Expand Up @@ -104,7 +105,11 @@ async function runTestSet(
}

describe('Bitcoin', () => {
const client = initializeClient();
let client;

test('pair', async () => {
client = await setupClient();
});

describe('wallet seeds', () => {
it('Should get GP_SUCCESS for a known, connected wallet', async () => {
Expand Down
8 changes: 6 additions & 2 deletions src/__test__/e2e/eth.msg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@
import { HARDENED_OFFSET } from '../../constants';
import { randomBytes } from '../../util';
import { buildEthMsgReq, buildRandomMsg } from '../utils/builders';
import { initializeClient } from '../utils/initializeClient';
import { runEthMsg } from '../utils/runners';
import { setupClient } from '../utils/setup';

describe('ETH Messages', () => {
const client = initializeClient();
let client;

test('pair', async () => {
client = await setupClient();
});

describe('Test ETH personalSign', function () {
it('Should throw error when message contains non-ASCII characters', async () => {
Expand Down
11 changes: 8 additions & 3 deletions src/__test__/e2e/general.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
import { TransactionFactory as EthTxFactory } from '@ethereumjs/tx';
import { question } from 'readline-sync';
import { HARDENED_OFFSET, LatticeResponseCode } from '../../constants';
import { HARDENED_OFFSET } from '../../constants';
import { LatticeResponseCode, ProtocolConstants } from '../../protocol';
import { randomBytes } from '../../util';
import { buildEthSignRequest } from '../utils/builders';
Expand All @@ -32,12 +32,17 @@ import {
ETH_COIN,
setupTestClient,
} from '../utils/helpers';
import { initializeClient } from '../utils/initializeClient';

import { setupClient } from '../utils/setup';

const id = getDeviceId();

describe('General', () => {
const client = initializeClient();
let client;

test('pair', async () => {
client = await setupClient();
});

it('Should test SDK dehydration/rehydration', async () => {
const addrData = {
Expand Down
9 changes: 7 additions & 2 deletions src/__test__/e2e/kv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { question } from 'readline-sync';
import { HARDENED_OFFSET } from '../../constants';
import { LatticeResponseCode, ProtocolConstants } from '../../protocol';
import { BTC_PURPOSE_P2PKH, ETH_COIN } from '../utils/helpers';
import { initializeClient } from '../utils/initializeClient';

import { setupClient } from '../utils/setup';

// Random address to test the screen with.
// IMPORTANT NOTE: For Ethereum addresses you should always add the lower case variety since
Expand All @@ -34,7 +35,11 @@ const ETH_REQ = {
};

describe('key-value', () => {
const client = initializeClient();
let client;

test('pair', async () => {
client = await setupClient();
});

it('Should ask if the user wants to reset state', async () => {
const answer = question(
Expand Down
9 changes: 7 additions & 2 deletions src/__test__/e2e/non-exportable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ import { ecdsaRecover } from 'secp256k1';
import { Constants } from '../..';
import { DEFAULT_SIGNER } from '../utils/builders';
import { getSigStr } from '../utils/helpers';
import { initializeClient } from '../utils/initializeClient';

import { setupClient } from '../utils/setup';

let runTests = true;

describe('Non-Exportable Seed', () => {
const client = initializeClient();
let client;

test('pair', async () => {
client = await setupClient();
});

describe('Setup', () => {
it('Should ask if the user wants to test a card with a non-exportable seed', async () => {
Expand Down
14 changes: 10 additions & 4 deletions src/__test__/e2e/signing/bls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import { mnemonicToSeedSync } from 'bip39';
import { deriveSeedTree } from 'bls12-381-keygen';
import { question } from 'readline-sync';

import { Constants } from '../../../index';
import { getPathStr } from '../../../shared/utilities';
import { getEncPw } from '../../utils/getters';
import { initializeClient, initializeSeed } from '../../utils/initializeClient';
import {
buildPath,
copyBuffer,
Expand All @@ -31,9 +32,9 @@ import {
parseWalletJobResp,
serializeJobData,
} from '../../utils/helpers';
import { initializeSeed } from '../../utils/initializeClient';
import { setupClient } from '../../utils/setup';
import { testRequest } from '../../utils/testRequest';
import { Constants } from '../../../index';
import { getPathStr } from '../../../shared/utilities';

const globalVectors = getTestVectors();

Expand All @@ -46,7 +47,12 @@ const KNOWN_MNEMONIC = globalVectors.ethDeposit.mnemonic;
const KNOWN_SEED = mnemonicToSeedSync(KNOWN_MNEMONIC);

describe('[BLS keys]', () => {
client = initializeClient();
let client;

test('pair', async () => {
client = await setupClient();
});

it('Should get the device encryption password', async () => {
encPw = getEncPw();
if (!encPw) {
Expand Down
21 changes: 13 additions & 8 deletions src/__test__/e2e/signing/determinism.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ import {
gpErrors,
jobTypes,
} from '../../utils/helpers';
import { initializeClient, initializeSeed } from '../../utils/initializeClient';
import { initializeSeed } from '../../utils/initializeClient';
import { runTestCase } from '../../utils/runners';
import { setupClient } from '../../utils/setup';
let seed: Buffer;

describe('[Determinism]', () => {
const client = initializeClient();
let client;

test('pair', async () => {
client = await setupClient();
});

describe('Setup and validate seed', () => {
it('Should re-connect to the Lattice and update the walletUID.', async () => {
Expand Down Expand Up @@ -152,42 +157,42 @@ describe('[Determinism]', () => {
});

describe('Test uniformity of Ethereum transaction sigs', () => {
it('Should validate uniformity sigs on m/44\'/60\'/0\'/0/0', async () => {
it("Should validate uniformity sigs on m/44'/60'/0'/0/0", async () => {

Check failure on line 160 in src/__test__/e2e/signing/determinism.test.ts

View workflow job for this annotation

GitHub Actions / Build

Strings must use singlequote
const tx = buildTx();
const txReq = buildTxReq(tx);
txReq.data.signerPath[2] = HARDENED_OFFSET;
await testUniformSigs(txReq, tx, client);
});

it('Should validate uniformity sigs on m/44\'/60\'/1\'/0/0', async () => {
it("Should validate uniformity sigs on m/44'/60'/1'/0/0", async () => {

Check failure on line 167 in src/__test__/e2e/signing/determinism.test.ts

View workflow job for this annotation

GitHub Actions / Build

Strings must use singlequote
const tx = buildTx();
const txReq = buildTxReq(tx);
txReq.data.signerPath[2] = HARDENED_OFFSET + 1;
await testUniformSigs(txReq, tx, client);
});

it('Should validate uniformity sigs on m/44\'/60\'/8\'/0/0', async () => {
it("Should validate uniformity sigs on m/44'/60'/8'/0/0", async () => {

Check failure on line 174 in src/__test__/e2e/signing/determinism.test.ts

View workflow job for this annotation

GitHub Actions / Build

Strings must use singlequote
const tx = buildTx();
const txReq = buildTxReq(tx);
txReq.data.signerPath[2] = HARDENED_OFFSET + 8;
await testUniformSigs(txReq, tx, client);
});

it('Should validate uniformity sigs on m/44\'/60\'/0\'/0/0', async () => {
it("Should validate uniformity sigs on m/44'/60'/0'/0/0", async () => {

Check failure on line 181 in src/__test__/e2e/signing/determinism.test.ts

View workflow job for this annotation

GitHub Actions / Build

Strings must use singlequote
const tx = buildTx(`0x${randomBytes(4000).toString('hex')}`);
const txReq = buildTxReq(tx);
txReq.data.signerPath[2] = HARDENED_OFFSET;
await testUniformSigs(txReq, tx, client);
});

it('Should validate uniformity sigs on m/44\'/60\'/1\'/0/0', async () => {
it("Should validate uniformity sigs on m/44'/60'/1'/0/0", async () => {

Check failure on line 188 in src/__test__/e2e/signing/determinism.test.ts

View workflow job for this annotation

GitHub Actions / Build

Strings must use singlequote
const tx = buildTx(`0x${randomBytes(4000).toString('hex')}`);
const txReq = buildTxReq(tx);
txReq.data.signerPath[2] = HARDENED_OFFSET + 1;
await testUniformSigs(txReq, tx, client);
});

it('Should validate uniformity sigs on m/44\'/60\'/8\'/0/0', async () => {
it("Should validate uniformity sigs on m/44'/60'/8'/0/0", async () => {

Check failure on line 195 in src/__test__/e2e/signing/determinism.test.ts

View workflow job for this annotation

GitHub Actions / Build

Strings must use singlequote
const tx = buildTx(`0x${randomBytes(4000).toString('hex')}`);
const txReq = buildTxReq(tx);
txReq.data.signerPath[2] = HARDENED_OFFSET + 8;
Expand Down
9 changes: 7 additions & 2 deletions src/__test__/e2e/signing/evm-abi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
} from '../../utils/builders';
import { getEtherscanKey } from '../../utils/getters';
import { runEvm } from '../../utils/runners';
import { initializeClient, initializeSeed } from '../../utils/initializeClient';
import { initializeSeed } from '../../utils/initializeClient';
import { setupClient } from '../../utils/setup';

const globalVectors = getTestVectors();
const vectors = globalVectors.evm.calldata;
Expand All @@ -31,7 +32,11 @@ const { encDefs, encDefsCalldata } = buildEncDefs(vectors);
// TESTS
//---------------------------------------
describe('[EVM ABI]', () => {
const client = initializeClient();
let client;

test('pair', async () => {
client = await setupClient();
});
const runEvmTestForReq = (
req?: any,
bypassSetPayload?: boolean,
Expand Down
10 changes: 8 additions & 2 deletions src/__test__/e2e/signing/evm-tx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { encode as rlpEncode } from 'rlp';
import { randomBytes } from '../../../util';
import { DEFAULT_SIGNER, buildEvmReq, getNumIter } from '../../utils/builders';
import { runEvm } from '../../utils/runners';
import { initializeClient, initializeSeed } from '../../utils/initializeClient';
import { initializeSeed } from '../../utils/initializeClient';
import { setupClient } from '../../utils/setup';
//---------------------------------------
// STATE DATA
//---------------------------------------
Expand All @@ -20,7 +21,12 @@ let CURRENT_SEED = null;
// TESTS
//---------------------------------------
describe('[EVM TX]', () => {
const client = initializeClient();
let client;

test('pair', async () => {
client = await setupClient();
});

const runEvmTestForReq = (
req?: any,
bypassSetPayload?: boolean,
Expand Down
8 changes: 6 additions & 2 deletions src/__test__/e2e/signing/solana/solana.programs.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { Constants } from '../../../..';
import { initializeClient } from '../../../utils/initializeClient';
import { setupClient } from '../../../utils/setup';
import { dexlabProgram, raydiumProgram } from './__mocks__/programs';

describe('Solana Programs', () => {
const client = initializeClient();
let client;

test('pair', async () => {
client = await setupClient();
});

it('should sign Dexlab program', async () => {
const payload = dexlabProgram;
Expand Down
13 changes: 8 additions & 5 deletions src/__test__/e2e/signing/solana/solana.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ import { Constants } from '../../../..';
import { HARDENED_OFFSET } from '../../../../constants';
import { getPrng } from '../../../utils/getters';
import { deriveED25519Key, prandomBuf } from '../../../utils/helpers';
import {
initializeClient,
initializeSeed,
} from '../../../utils/initializeClient';
import { initializeSeed } from '../../../utils/initializeClient';
import { runGeneric } from '../../../utils/runners';
import { setupClient } from '../../../utils/setup';

//---------------------------------------
// STATE DATA
Expand All @@ -26,7 +24,12 @@ const DEFAULT_SOLANA_SIGNER = [
const prng = getPrng();

describe('[Solana]', () => {
const client = initializeClient();
let client;

test('pair', async () => {
client = await setupClient();
});

const getReq = (overrides: any) => ({
data: {
curveType: Constants.SIGNING.CURVES.ED25519,
Expand Down
9 changes: 7 additions & 2 deletions src/__test__/e2e/signing/unformatted.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ethPersonalSignMsg, prandomBuf } from '../../utils/helpers';
import { runGeneric } from '../../utils/runners';
import { HARDENED_OFFSET } from '../../../constants';
import { getPrng } from '../../utils/getters';
import { initializeClient } from '../../utils/initializeClient';
import { setupClient } from '../../utils/setup';

const prng = getPrng();
const numIter = getNumIter();
Expand All @@ -17,7 +17,12 @@ const DEFAULT_SIGNER = [
];

describe('[Unformatted]', () => {
const client = initializeClient();
let client;

test('pair', async () => {
client = await setupClient();
});

const getReq = (overrides: any) => ({
data: {
signerPath: DEFAULT_SIGNER,
Expand Down
Loading

0 comments on commit a68793d

Please sign in to comment.