fix: remove buggy node polyfill plugin (#18531)
* fix: remove buggy node polyfill plugin * fix websocket test * remove assert dependency
This commit is contained in:
parent
f6371cce17
commit
2ef2b6daa0
|
@ -17562,6 +17562,7 @@
|
||||||
"version": "3.0.2",
|
"version": "3.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/rollup-plugin-inject/-/rollup-plugin-inject-3.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/rollup-plugin-inject/-/rollup-plugin-inject-3.0.2.tgz",
|
||||||
"integrity": "sha512-ptg9PQwzs3orn4jkgXJ74bfs5vYz1NCZlSQMBUA0wKcGp5i5pA1AO3fOUEte8enhGUC+iapTCzEWw2jEFFUO/w==",
|
"integrity": "sha512-ptg9PQwzs3orn4jkgXJ74bfs5vYz1NCZlSQMBUA0wKcGp5i5pA1AO3fOUEte8enhGUC+iapTCzEWw2jEFFUO/w==",
|
||||||
|
"deprecated": "This package has been deprecated and is no longer maintained. Please use @rollup/plugin-inject.",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"estree-walker": "^0.6.1",
|
"estree-walker": "^0.6.1",
|
||||||
|
|
|
@ -2,7 +2,6 @@ import babel from '@rollup/plugin-babel';
|
||||||
import commonjs from '@rollup/plugin-commonjs';
|
import commonjs from '@rollup/plugin-commonjs';
|
||||||
import json from '@rollup/plugin-json';
|
import json from '@rollup/plugin-json';
|
||||||
import nodeResolve from '@rollup/plugin-node-resolve';
|
import nodeResolve from '@rollup/plugin-node-resolve';
|
||||||
import nodePolyfills from 'rollup-plugin-node-polyfills';
|
|
||||||
import replace from '@rollup/plugin-replace';
|
import replace from '@rollup/plugin-replace';
|
||||||
import {terser} from 'rollup-plugin-terser';
|
import {terser} from 'rollup-plugin-terser';
|
||||||
|
|
||||||
|
@ -90,7 +89,7 @@ function generateConfig(configType, format) {
|
||||||
'crypto-hash',
|
'crypto-hash',
|
||||||
'jayson/lib/client/browser',
|
'jayson/lib/client/browser',
|
||||||
'js-sha3',
|
'js-sha3',
|
||||||
'node-fetch',
|
// 'node-fetch', will resolve to whatwg-fetch
|
||||||
'rpc-websockets',
|
'rpc-websockets',
|
||||||
'secp256k1',
|
'secp256k1',
|
||||||
'superstruct',
|
'superstruct',
|
||||||
|
@ -125,7 +124,6 @@ function generateConfig(configType, format) {
|
||||||
// TODO: Find a workaround to avoid resolving the following JSON file:
|
// TODO: Find a workaround to avoid resolving the following JSON file:
|
||||||
// `node_modules/secp256k1/node_modules/elliptic/package.json`
|
// `node_modules/secp256k1/node_modules/elliptic/package.json`
|
||||||
config.plugins.push(json());
|
config.plugins.push(json());
|
||||||
config.plugins.push(nodePolyfills());
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'node':
|
case 'node':
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
import assert from 'assert';
|
|
||||||
import bs58 from 'bs58';
|
import bs58 from 'bs58';
|
||||||
import {Buffer} from 'buffer';
|
import {Buffer} from 'buffer';
|
||||||
import {parse as urlParse} from 'url';
|
|
||||||
import fetch, {Response} from 'node-fetch';
|
import fetch, {Response} from 'node-fetch';
|
||||||
import {
|
import {
|
||||||
type as pick,
|
type as pick,
|
||||||
|
@ -34,6 +32,7 @@ import {Signer} from './keypair';
|
||||||
import {MS_PER_SLOT} from './timing';
|
import {MS_PER_SLOT} from './timing';
|
||||||
import {Transaction} from './transaction';
|
import {Transaction} from './transaction';
|
||||||
import {Message} from './message';
|
import {Message} from './message';
|
||||||
|
import assert from './util/assert';
|
||||||
import {sleep} from './util/sleep';
|
import {sleep} from './util/sleep';
|
||||||
import {promiseTimeout} from './util/promise-timeout';
|
import {promiseTimeout} from './util/promise-timeout';
|
||||||
import {toBuffer} from './util/to-buffer';
|
import {toBuffer} from './util/to-buffer';
|
||||||
|
@ -2025,7 +2024,7 @@ export class Connection {
|
||||||
endpoint: string,
|
endpoint: string,
|
||||||
commitmentOrConfig?: Commitment | ConnectionConfig,
|
commitmentOrConfig?: Commitment | ConnectionConfig,
|
||||||
) {
|
) {
|
||||||
let url = urlParse(endpoint);
|
let url = new URL(endpoint);
|
||||||
const useHttps = url.protocol === 'https:';
|
const useHttps = url.protocol === 'https:';
|
||||||
|
|
||||||
let wsEndpoint;
|
let wsEndpoint;
|
||||||
|
@ -2046,7 +2045,7 @@ export class Connection {
|
||||||
this._rpcWsEndpoint = wsEndpoint || makeWebsocketUrl(endpoint);
|
this._rpcWsEndpoint = wsEndpoint || makeWebsocketUrl(endpoint);
|
||||||
|
|
||||||
this._rpcClient = createRpcClient(
|
this._rpcClient = createRpcClient(
|
||||||
url.href,
|
url.toString(),
|
||||||
useHttps,
|
useHttps,
|
||||||
httpHeaders,
|
httpHeaders,
|
||||||
fetchMiddleware,
|
fetchMiddleware,
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import {Buffer} from 'buffer';
|
import {Buffer} from 'buffer';
|
||||||
import * as BufferLayout from '@solana/buffer-layout';
|
import * as BufferLayout from '@solana/buffer-layout';
|
||||||
import secp256k1 from 'secp256k1';
|
import secp256k1 from 'secp256k1';
|
||||||
import assert from 'assert';
|
|
||||||
import {keccak_256} from 'js-sha3';
|
import {keccak_256} from 'js-sha3';
|
||||||
|
|
||||||
import {PublicKey} from './publickey';
|
import {PublicKey} from './publickey';
|
||||||
import {TransactionInstruction} from './transaction';
|
import {TransactionInstruction} from './transaction';
|
||||||
|
import assert from './util/assert';
|
||||||
import {toBuffer} from './util/to-buffer';
|
import {toBuffer} from './util/to-buffer';
|
||||||
|
|
||||||
const {publicKeyCreate, ecdsaSign} = secp256k1;
|
const {publicKeyCreate, ecdsaSign} = secp256k1;
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import invariant from 'assert';
|
|
||||||
import nacl from 'tweetnacl';
|
import nacl from 'tweetnacl';
|
||||||
import bs58 from 'bs58';
|
import bs58 from 'bs58';
|
||||||
import {Buffer} from 'buffer';
|
import {Buffer} from 'buffer';
|
||||||
|
@ -7,6 +6,7 @@ import {Message} from './message';
|
||||||
import {PublicKey} from './publickey';
|
import {PublicKey} from './publickey';
|
||||||
import * as shortvec from './util/shortvec-encoding';
|
import * as shortvec from './util/shortvec-encoding';
|
||||||
import {toBuffer} from './util/to-buffer';
|
import {toBuffer} from './util/to-buffer';
|
||||||
|
import invariant from './util/assert';
|
||||||
import type {Signer} from './keypair';
|
import type {Signer} from './keypair';
|
||||||
import type {Blockhash} from './blockhash';
|
import type {Blockhash} from './blockhash';
|
||||||
import type {CompiledInstruction} from './message';
|
import type {CompiledInstruction} from './message';
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
export default function (
|
||||||
|
condition: unknown,
|
||||||
|
message?: string,
|
||||||
|
): asserts condition {
|
||||||
|
if (!condition) {
|
||||||
|
throw new Error(message || 'Assertion failed');
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,5 @@
|
||||||
import {format as urlFormat, parse as urlParse} from 'url';
|
|
||||||
|
|
||||||
export function makeWebsocketUrl(endpoint: string) {
|
export function makeWebsocketUrl(endpoint: string) {
|
||||||
let url = urlParse(endpoint);
|
let url = new URL(endpoint);
|
||||||
const useHttps = url.protocol === 'https:';
|
const useHttps = url.protocol === 'https:';
|
||||||
|
|
||||||
url.protocol = useHttps ? 'wss:' : 'ws:';
|
url.protocol = useHttps ? 'wss:' : 'ws:';
|
||||||
|
@ -13,8 +11,8 @@ export function makeWebsocketUrl(endpoint: string) {
|
||||||
// When the endpoint omits the port, we're connecting to the protocol
|
// When the endpoint omits the port, we're connecting to the protocol
|
||||||
// default ports: http(80) or https(443) and it's assumed we're behind a reverse
|
// default ports: http(80) or https(443) and it's assumed we're behind a reverse
|
||||||
// proxy which manages WebSocket upgrade and backend port redirection.
|
// proxy which manages WebSocket upgrade and backend port redirection.
|
||||||
if (url.port !== null) {
|
if (url.port !== '') {
|
||||||
url.port = String(Number(url.port) + 1);
|
url.port = String(Number(url.port) + 1);
|
||||||
}
|
}
|
||||||
return urlFormat(url);
|
return url.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import bs58 from 'bs58';
|
import bs58 from 'bs58';
|
||||||
import invariant from 'assert';
|
|
||||||
import {Buffer} from 'buffer';
|
import {Buffer} from 'buffer';
|
||||||
import {Token, u64} from '@solana/spl-token';
|
import {Token, u64} from '@solana/spl-token';
|
||||||
import {expect, use} from 'chai';
|
import {expect, use} from 'chai';
|
||||||
|
@ -19,6 +18,7 @@ import {
|
||||||
sendAndConfirmTransaction,
|
sendAndConfirmTransaction,
|
||||||
Keypair,
|
Keypair,
|
||||||
} from '../src';
|
} from '../src';
|
||||||
|
import invariant from '../src/util/assert';
|
||||||
import {DEFAULT_TICKS_PER_SLOT, NUM_TICKS_PER_SECOND} from '../src/timing';
|
import {DEFAULT_TICKS_PER_SLOT, NUM_TICKS_PER_SECOND} from '../src/timing';
|
||||||
import {MOCK_PORT, url} from './url';
|
import {MOCK_PORT, url} from './url';
|
||||||
import {
|
import {
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import bs58 from 'bs58';
|
import bs58 from 'bs58';
|
||||||
import BN from 'bn.js';
|
import BN from 'bn.js';
|
||||||
import invariant from 'assert';
|
|
||||||
import * as mockttp from 'mockttp';
|
import * as mockttp from 'mockttp';
|
||||||
|
|
||||||
import {mockRpcMessage} from './rpc-websockets';
|
import {mockRpcMessage} from './rpc-websockets';
|
||||||
import {Connection, PublicKey, Transaction, Signer} from '../../src';
|
import {Connection, PublicKey, Transaction, Signer} from '../../src';
|
||||||
|
import invariant from '../../src/util/assert';
|
||||||
import type {Commitment, HttpHeaders, RpcParams} from '../../src/connection';
|
import type {Commitment, HttpHeaders, RpcParams} from '../../src/connection';
|
||||||
|
|
||||||
export const mockServer: mockttp.Mockttp | undefined =
|
export const mockServer: mockttp.Mockttp | undefined =
|
||||||
|
@ -150,7 +150,7 @@ const processTransaction = async ({
|
||||||
transaction.sign(...signers);
|
transaction.sign(...signers);
|
||||||
|
|
||||||
const encoded = transaction.serialize().toString('base64');
|
const encoded = transaction.serialize().toString('base64');
|
||||||
invariant(transaction.signature !== null);
|
invariant(transaction.signature);
|
||||||
const signature = bs58.encode(transaction.signature);
|
const signature = bs58.encode(transaction.signature);
|
||||||
await mockRpcResponse({
|
await mockRpcResponse({
|
||||||
method: 'sendTransaction',
|
method: 'sendTransaction',
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import base58 from 'bs58';
|
import base58 from 'bs58';
|
||||||
import invariant from 'assert';
|
|
||||||
import {expect} from 'chai';
|
import {expect} from 'chai';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -9,6 +8,7 @@ import {
|
||||||
SystemProgram,
|
SystemProgram,
|
||||||
LAMPORTS_PER_SOL,
|
LAMPORTS_PER_SOL,
|
||||||
} from '../src';
|
} from '../src';
|
||||||
|
import invariant from '../src/util/assert';
|
||||||
import {MOCK_PORT, url} from './url';
|
import {MOCK_PORT, url} from './url';
|
||||||
import {helpers, mockRpcResponse, mockServer} from './mocks/rpc-http';
|
import {helpers, mockRpcResponse, mockServer} from './mocks/rpc-http';
|
||||||
import {stubRpcWebSocket, restoreRpcWebSocket} from './mocks/rpc-websockets';
|
import {stubRpcWebSocket, restoreRpcWebSocket} from './mocks/rpc-websockets';
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import bs58 from 'bs58';
|
import bs58 from 'bs58';
|
||||||
import invariant from 'assert';
|
|
||||||
import {Buffer} from 'buffer';
|
import {Buffer} from 'buffer';
|
||||||
import nacl from 'tweetnacl';
|
import nacl from 'tweetnacl';
|
||||||
import {expect} from 'chai';
|
import {expect} from 'chai';
|
||||||
|
@ -10,6 +9,7 @@ import {Transaction} from '../src/transaction';
|
||||||
import {StakeProgram} from '../src/stake-program';
|
import {StakeProgram} from '../src/stake-program';
|
||||||
import {SystemProgram} from '../src/system-program';
|
import {SystemProgram} from '../src/system-program';
|
||||||
import {Message} from '../src/message';
|
import {Message} from '../src/message';
|
||||||
|
import invariant from '../src/util/assert';
|
||||||
import {toBuffer} from '../src/util/to-buffer';
|
import {toBuffer} from '../src/util/to-buffer';
|
||||||
|
|
||||||
describe('Transaction', () => {
|
describe('Transaction', () => {
|
||||||
|
|
|
@ -65,7 +65,7 @@ if (process.env.TEST_LIVE) {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('connect by websocket endpoint from options', async () => {
|
it('connect by websocket endpoint from options', async () => {
|
||||||
let connection = new Connection('', {
|
let connection = new Connection('http://localhost', {
|
||||||
wsEndpoint: wsUrl,
|
wsEndpoint: wsUrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue