chore: integration test for ws-rpc-client lib

This commit is contained in:
Matthew Little
2020-08-06 08:33:11 -06:00
parent 0a67a11043
commit d284524c61
5 changed files with 4863 additions and 0 deletions

View File

@@ -7,3 +7,4 @@ scripts/
stacks-blockchain/
src/schemas/*
docs/
ws-rpc-client/

4772
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -108,6 +108,7 @@
"@actions/io": "^1.0.2",
"@blockstack/eslint-config": "^1.0.5",
"@blockstack/prettier-config": "0.0.6",
"@blockstack/ws-rpc-client": "file:ws-rpc-client",
"@commitlint/cli": "^9.1.2",
"@commitlint/config-conventional": "^9.1.1",
"@types/ajv": "^1.0.0",

View File

@@ -26,6 +26,7 @@ import {
RpcAddressBalanceNotificationParams,
TransactionStatus,
} from '@blockstack/stacks-blockchain-api-types';
import { connect as connectWebSocketClient } from '@blockstack/ws-rpc-client';
describe('websocket notifications', () => {
let apiServer: ApiServer;
@@ -395,6 +396,93 @@ describe('websocket notifications', () => {
}
});
test('websocket rpc client lib', async () => {
// build the db block, tx, and event
const block: DbBlock = {
block_hash: '0x1234',
index_block_hash: '0xdeadbeef',
parent_index_block_hash: '0x00',
parent_block_hash: '0xff0011',
parent_microblock: '0x9876',
block_height: 1,
burn_block_time: 94869286,
canonical: true,
};
const tx: DbTx = {
tx_id: '0x8912000000000000000000000000000000000000000000000000000000000000',
tx_index: 4,
raw_tx: Buffer.from('raw-tx-test'),
index_block_hash: '0x5432',
block_hash: '0x9876',
block_height: 68456,
burn_block_time: 2837565,
type_id: DbTxTypeId.TokenTransfer,
status: DbTxStatus.Success,
raw_result: '0x0100000000000000000000000000000001', // u1
canonical: true,
post_conditions: Buffer.from([0x01, 0xf5]),
fee_rate: BigInt(1234),
sponsored: false,
sender_address: 'ST3GQB6WGCWKDNFNPSQRV8DY93JN06XPZ2ZE9EVMA',
origin_hash_mode: 1,
token_transfer_recipient_address: 'STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6',
token_transfer_amount: BigInt(100),
token_transfer_memo: new Buffer('memo'),
};
const stxEvent: DbStxEvent = {
canonical: tx.canonical,
event_type: DbEventTypeId.StxAsset,
asset_event_type_id: DbAssetEventTypeId.Transfer,
event_index: 0,
tx_id: tx.tx_id,
tx_index: tx.tx_index,
block_height: tx.block_height,
amount: tx.token_transfer_amount as bigint,
recipient: tx.token_transfer_recipient_address,
sender: tx.sender_address,
};
const dbUpdate: DataStoreUpdateData = {
block,
txs: [
{
tx,
stxEvents: [stxEvent],
ftEvents: [],
nftEvents: [],
contractLogEvents: [],
smartContracts: [],
},
],
};
const addr = apiServer.address;
const wsAddress = `ws://${addr}/extended/v1/ws`;
const client = await connectWebSocketClient(wsAddress);
try {
await client.subscribeAddressTransactions(tx.sender_address);
const addrTxUpdates: Waiter<RpcAddressTxNotificationParams> = waiter();
client.on('addressTxUpdate', event => addrTxUpdates.finish(event));
await db.update(dbUpdate);
// check for tx update notification
const txUpdate1 = await addrTxUpdates;
expect(txUpdate1).toEqual({
address: 'ST3GQB6WGCWKDNFNPSQRV8DY93JN06XPZ2ZE9EVMA',
tx_id: '0x8912000000000000000000000000000000000000000000000000000000000000',
tx_status: 'success',
tx_type: 'token_transfer',
});
await client.unsubscribeAddressTransactions(tx.sender_address);
} finally {
client.webSocket.close();
}
});
test.skip('websocket connect endpoint', async () => {
// build the db block, tx, and event
const block: DbBlock = {

View File

@@ -11,6 +11,7 @@
"allowSyntheticDefaultImports": false,
"resolveJsonModule": true,
"baseUrl": ".",
"skipLibCheck": true,
"paths": {
"*": ["src/@types/*"]
}