mirror of
https://github.com/zhigang1992/wallet.git
synced 2026-04-29 13:15:32 +08:00
chore: remove dead files, old resolution
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
---
|
||||
'@stacks/wallet-web': patch
|
||||
---
|
||||
|
||||
This fixes a small bug where if a serialized clarity value is passed to deserializeCV that is prefixed with `0x` it will error out.
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
'@stacks/wallet-web': patch
|
||||
---
|
||||
|
||||
Display in activity list all STX and fungible token transfers from contract calls.
|
||||
26
.fixpackrc
26
.fixpackrc
@@ -1,26 +0,0 @@
|
||||
{
|
||||
"sortToTop": ["name", "description", "scripts", "version", "author"],
|
||||
"required": ["name", "version"],
|
||||
"warn": [
|
||||
"description",
|
||||
"author",
|
||||
"repository",
|
||||
"keywords",
|
||||
"main",
|
||||
"bugs",
|
||||
"homepage",
|
||||
"license"
|
||||
],
|
||||
"requiredOnPrivate": [],
|
||||
"warnOnPrivate": ["name", "version", "description", "main"],
|
||||
"sortedSubItems": [
|
||||
"dependencies",
|
||||
"devDependencies",
|
||||
"jshintConfig",
|
||||
"scripts",
|
||||
"keywords"
|
||||
],
|
||||
"quiet": false,
|
||||
"files": ["package.json"],
|
||||
"wipe": false
|
||||
}
|
||||
10
.github/workflows/integration-tests.yml
vendored
10
.github/workflows/integration-tests.yml
vendored
@@ -6,14 +6,6 @@ env:
|
||||
CI: true
|
||||
|
||||
jobs:
|
||||
pre_run:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Cancel Previous Runs
|
||||
uses: styfle/cancel-workflow-action@ad6cb1b847ffb509a69b745b6ee2f1d14dfe14b8
|
||||
with:
|
||||
access_token: ${{ github.token }}
|
||||
|
||||
directories:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
@@ -26,7 +18,7 @@ jobs:
|
||||
|
||||
test-integration:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [pre_run, directories]
|
||||
needs: [directories]
|
||||
strategy:
|
||||
matrix:
|
||||
dir: ${{ fromJson(needs.directories.outputs.dir) }}
|
||||
|
||||
@@ -2,6 +2,7 @@ const config = require('./jest.config');
|
||||
|
||||
module.exports = {
|
||||
...config,
|
||||
testTimeout: 60000,
|
||||
globalSetup: '<rootDir>/tests/global-setup.ts',
|
||||
globalTeardown: '<rootDir>/tests/global-teardown.ts',
|
||||
};
|
||||
|
||||
@@ -202,7 +202,7 @@
|
||||
"generate-json-webpack-plugin": "2.0.0",
|
||||
"glob-parent": "6.0.2",
|
||||
"html-webpack-plugin": "5.5.0",
|
||||
"jest": "27.3.1",
|
||||
"jest": "26.6.3",
|
||||
"jest-circus": "27.3.1",
|
||||
"jest-dev-server": "6.0.0",
|
||||
"jest-junit": "13.0.0",
|
||||
@@ -235,8 +235,7 @@
|
||||
"yup": "0.32.9"
|
||||
},
|
||||
"resolutions": {
|
||||
"**/**/dns-packet": "5.2.2",
|
||||
"**/**/prismjs": "1.24.0",
|
||||
"**/**/prismjs": "1.25.0",
|
||||
"**/**/xmldom": "github:xmldom/xmldom#0.7.0",
|
||||
"**/**/@stacks/network": "2.0.2",
|
||||
"@tabler/icons": "1.41.2",
|
||||
|
||||
@@ -45,6 +45,6 @@ describe(createTxDateFormatList.name, () => {
|
||||
const mockTx = createFakeTx({ burn_block_time_iso: date.toISOString() });
|
||||
const result = createTxDateFormatList([mockTx]);
|
||||
expect(result[0].date).toEqual(date.toISOString().split('T')[0]);
|
||||
expect(result[0].displayDate).not.toContain(new Date().getFullYear());
|
||||
expect(result[0].displayDate).not.toContain(new Date().getFullYear().toString());
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,197 +0,0 @@
|
||||
import { generateSignedTransaction } from '@common/transactions/transactions';
|
||||
import {
|
||||
PostConditionMode,
|
||||
makeStandardFungiblePostCondition,
|
||||
FungibleConditionCode,
|
||||
createAssetInfo,
|
||||
} from '@stacks/transactions';
|
||||
import {
|
||||
ContractCallOptions,
|
||||
makeContractCallToken,
|
||||
TransactionPayload,
|
||||
UserData,
|
||||
} from '@stacks/connect';
|
||||
import BN from 'bn.js';
|
||||
import { decodeToken } from 'jsontokens';
|
||||
import { STX_TRANSFER_TX_REQUEST, TEST_WALLET } from '../mocks';
|
||||
import { getAppPrivateKey } from '@stacks/wallet-sdk';
|
||||
import { UNAUTHORIZED_TX_REQUEST, verifyTxRequest } from '@common/transactions/requests';
|
||||
import { StacksTestnet } from '@stacks/network';
|
||||
import { AddressTransactionWithTransfers, Transaction } from '@stacks/stacks-blockchain-api-types';
|
||||
import { createTxDateFormatList } from '@common/transactions/transaction-utils';
|
||||
|
||||
(window as any).fetch = jest.fn(() => ({
|
||||
text: () => Promise.resolve(1),
|
||||
ok: true,
|
||||
}));
|
||||
|
||||
const defaultUserSession: Partial<UserData> = {
|
||||
appPrivateKey: 'e494f188c2d35887531ba474c433b1e41fadd8eb824aca983447fd4bb8b277a801',
|
||||
};
|
||||
|
||||
async function generateContractCallToken({
|
||||
userData,
|
||||
txOptions,
|
||||
}: {
|
||||
userData?: Partial<UserData>;
|
||||
txOptions?: Partial<ContractCallOptions>;
|
||||
} = {}) {
|
||||
const address = 'ST1EXHZSN8MJSJ9DSG994G1V8CNKYXGMK7Z4SA6DH';
|
||||
const assetAddress = 'ST34RKEJKQES7MXQFBT29KSJZD73QK3YNT5N56C6X';
|
||||
const assetContractName = 'test-asset-contract';
|
||||
const assetName = 'test-asset-name';
|
||||
const info = createAssetInfo(assetAddress, assetContractName, assetName);
|
||||
localStorage.setItem(
|
||||
'blockstack-session',
|
||||
JSON.stringify({
|
||||
userData: userData || defaultUserSession,
|
||||
version: '1.0.0',
|
||||
})
|
||||
);
|
||||
const network = new StacksTestnet();
|
||||
const txDataToken = await makeContractCallToken({
|
||||
contractAddress: 'ST1EXHZSN8MJSJ9DSG994G1V8CNKYXGMK7Z4SA6DH',
|
||||
contractName: 'hello-world',
|
||||
functionArgs: [],
|
||||
functionName: 'print',
|
||||
postConditionMode: PostConditionMode.Allow,
|
||||
network,
|
||||
postConditions: [
|
||||
makeStandardFungiblePostCondition(
|
||||
address,
|
||||
FungibleConditionCode.GreaterEqual,
|
||||
new BN(100),
|
||||
info
|
||||
),
|
||||
],
|
||||
...txOptions,
|
||||
});
|
||||
return txDataToken;
|
||||
}
|
||||
|
||||
describe('generated transactions', () => {
|
||||
test('can handle encoded payload', async () => {
|
||||
const txDataToken = await generateContractCallToken();
|
||||
const token = decodeToken(txDataToken);
|
||||
const txData = token.payload as unknown as TransactionPayload;
|
||||
const tx = await generateSignedTransaction({
|
||||
txData,
|
||||
senderKey: '8721c6a5237f5e8d361161a7855aa56885a3e19e2ea6ee268fb14eabc5e2ed9001',
|
||||
nonce: 0,
|
||||
} as any);
|
||||
expect(tx.postConditionMode).toEqual(PostConditionMode.Allow);
|
||||
const postCondition = tx.postConditions.values[0];
|
||||
if ('amount' in postCondition) {
|
||||
expect(postCondition.amount.toNumber()).toEqual(100);
|
||||
} else {
|
||||
throw new Error('Deserialized TX does not have post condition');
|
||||
}
|
||||
}, 5000);
|
||||
});
|
||||
|
||||
describe('verifyTxRequest', () => {
|
||||
test('can validate a known valid tx request', async () => {
|
||||
const result = await verifyTxRequest({
|
||||
requestToken: STX_TRANSFER_TX_REQUEST,
|
||||
wallet: TEST_WALLET,
|
||||
appDomain: 'http://localhost:3000',
|
||||
});
|
||||
expect(result.stxAddress).toEqual('ST35Z3YQCTC1WZ8Z7AKHGE91HK05WKMKPTN1KX7Q7');
|
||||
expect(result).toBeTruthy();
|
||||
});
|
||||
|
||||
test('can validate a generated valid tx request', async () => {
|
||||
const [account] = TEST_WALLET.accounts;
|
||||
const appPrivateKey = getAppPrivateKey({ account, appDomain: 'http://localhost:3000' });
|
||||
const txRequest = await generateContractCallToken({
|
||||
userData: {
|
||||
appPrivateKey: appPrivateKey,
|
||||
},
|
||||
});
|
||||
const result = await verifyTxRequest({
|
||||
requestToken: txRequest,
|
||||
wallet: TEST_WALLET,
|
||||
appDomain: 'http://localhost:3000',
|
||||
});
|
||||
expect(result.stxAddress).toBeFalsy();
|
||||
});
|
||||
|
||||
test('can invalidate a tx request with an invalid signature', async () => {
|
||||
const txRequest = await generateContractCallToken();
|
||||
await expect(
|
||||
verifyTxRequest({
|
||||
requestToken: txRequest,
|
||||
wallet: TEST_WALLET,
|
||||
appDomain: 'http://localhost:3000',
|
||||
})
|
||||
).rejects.toThrow(UNAUTHORIZED_TX_REQUEST);
|
||||
});
|
||||
|
||||
test('can invalidate a tx request with non-matching stx address', async () => {
|
||||
const [account] = TEST_WALLET.accounts;
|
||||
const appPrivateKey = getAppPrivateKey({ account, appDomain: 'http://localhost:3000' });
|
||||
const txRequest = await generateContractCallToken({
|
||||
userData: {
|
||||
appPrivateKey: appPrivateKey,
|
||||
},
|
||||
txOptions: {
|
||||
stxAddress: 'STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6',
|
||||
},
|
||||
});
|
||||
await expect(
|
||||
verifyTxRequest({
|
||||
requestToken: txRequest,
|
||||
wallet: TEST_WALLET,
|
||||
appDomain: 'http://localhost:3000',
|
||||
})
|
||||
).rejects.toThrow(UNAUTHORIZED_TX_REQUEST);
|
||||
});
|
||||
});
|
||||
|
||||
function createFakeTx(tx: Partial<Transaction>) {
|
||||
return {
|
||||
tx: { tx_status: 'success', ...tx } as Transaction,
|
||||
} as AddressTransactionWithTransfers;
|
||||
}
|
||||
|
||||
describe(createTxDateFormatList.name, () => {
|
||||
test('grouping by date', () => {
|
||||
const mockTx = createFakeTx({
|
||||
burn_block_time_iso: '1991-02-08T13:48:04.699Z',
|
||||
});
|
||||
expect(createTxDateFormatList([mockTx])).toEqual([
|
||||
{
|
||||
date: '1991-02-08',
|
||||
displayDate: 'Feb 8th, 1991',
|
||||
txs: [mockTx],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test('relative dates todays date', () => {
|
||||
const today = new Date().toISOString();
|
||||
const mockTx = createFakeTx({ burn_block_time_iso: today });
|
||||
const result = createTxDateFormatList([mockTx]);
|
||||
expect(result[0].date).toEqual(today.split('T')[0]);
|
||||
expect(result[0].displayDate).toEqual('Today');
|
||||
});
|
||||
|
||||
test('relative dates yesterdays date', () => {
|
||||
const yesterday = new Date();
|
||||
yesterday.setDate(yesterday.getDate() - 1);
|
||||
const mockTx = createFakeTx({ burn_block_time_iso: yesterday.toISOString() });
|
||||
const result = createTxDateFormatList([mockTx]);
|
||||
expect(result[0].date).toEqual(yesterday.toISOString().split('T')[0]);
|
||||
expect(result[0].displayDate).toEqual('Yesterday');
|
||||
});
|
||||
|
||||
test('dates from this year omit year', () => {
|
||||
const date = new Date();
|
||||
date.setFullYear(date.getFullYear());
|
||||
date.setMonth(6);
|
||||
const mockTx = createFakeTx({ burn_block_time_iso: date.toISOString() });
|
||||
const result = createTxDateFormatList([mockTx]);
|
||||
expect(result[0].date).toEqual(date.toISOString().split('T')[0]);
|
||||
expect(result[0].displayDate).not.toContain(new Date().getFullYear().toString());
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user