Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3288 from trufflesuite/develop
Browse files Browse the repository at this point in the history
Release v7.3.2
  • Loading branch information
davidmurdoch authored Jun 24, 2022
2 parents 6eeaf3a + 75a5a26 commit 2ea79dd
Show file tree
Hide file tree
Showing 29 changed files with 318 additions and 193 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,23 @@ jobs:
env:
FORCE_COLOR: 1
INFURA_KEY: ${{ secrets.TEST_INFURA_KEY }}

- name: Check bundle size
# this should match the os and version used in the release.yml
if: startsWith(matrix.os, 'ubuntu-20.04') && startsWith(matrix.node, '14.')
# 1. build ganache
# 2. pack it into a tarball
# 3. measure the _unpacked_ tarball's size
# 4. test to make sure the tarball is less than 99MB because jsDelivr
# CDN doesn't allow bundles greater than 100MB.
# 5. exit with non-zero exit code if the test fails.
run: |
npm run build &&
cd ./src/packages/ganache &&
npm pack &&
size="$(zcat ganache-*.tgz | wc -c)" &&
echo "Bundle size: $size" &&
echo "Bundle size is $([[ "$size" -lt 99000000 ]] && echo "ok" || echo "not ok")" &&
test "$size" -lt 99000000
env:
INFURA_KEY: ${{ secrets.INFURA_KEY }}
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ on:

jobs:
release:
# this should match the os version used by the "check bundle size" step in
# pr.yml
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
Expand All @@ -16,6 +18,8 @@ jobs:
- uses: actions/setup-node@v1
with:
# use node 14 until we can evaluate using npm 7+ and lock file version 2
# this should match the node version used by the "check bundle size"
# step in pr.yml
node-version: 14

- name: Import Robot GPG key
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/js/ganache/ganache.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/assets/js/ganache/ganache.min.js.map

Large diffs are not rendered by default.

194 changes: 97 additions & 97 deletions docs/typedoc/classes/default.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/chains/ethereum/ethereum/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/chains/ethereum/ethereum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"ws": "8.2.3"
},
"devDependencies": {
"@trufflesuite/uws-js-unofficial": "20.10.0-unofficial.0",
"@trufflesuite/uws-js-unofficial": "20.10.0-unofficial.1",
"@types/abstract-leveldown": "7.2.0",
"@types/encoding-down": "5.0.0",
"@types/fs-extra": "9.0.2",
Expand Down
2 changes: 1 addition & 1 deletion src/chains/ethereum/ethereum/src/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ export default class Blockchain extends Emittery<BlockchainTypedEvents> {
await this.#blockBeingSavedPromise;
return {
transactions,
blockNumber: nextBlock.header.number.toBuffer()
blockNumber: nextBlock.header.number.toArrayLike(Buffer)
};
};

Expand Down
62 changes: 33 additions & 29 deletions src/chains/ethereum/ethereum/src/forking/handlers/http-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ export class HttpHandler extends BaseHandler implements Handler {
});
}
}
private handleLengthedResponse(res: http.IncomingMessage, length: number) {
let buffer = Buffer.allocUnsafe(length);
let offset = 0;
return new Promise<Buffer>((resolve, reject) => {
private async handleLengthedResponse(
res: http.IncomingMessage,
length: number
) {
return await new Promise<Buffer>((resolve, reject) => {
const buffer = Buffer.allocUnsafe(length);
let offset = 0;
function data(message: Buffer) {
const messageLength = message.length;
// note: Node will NOT send us more data than the content-length header
Expand All @@ -54,9 +57,9 @@ export class HttpHandler extends BaseHandler implements Handler {
offset += messageLength;
}
function end() {
// note: Node doesn't check if the content-length matches, so we do that
// here
if (offset !== buffer.length) {
// note: Node doesn't check if the content-length matches (we might
// receive less data than expected), so we do that here
if (offset !== length) {
// if we didn't receive enough data, throw
reject(new Error("content-length mismatch"));
} else {
Expand All @@ -65,24 +68,18 @@ export class HttpHandler extends BaseHandler implements Handler {
}
res.on("data", data);
res.on("end", end);
res.on("error", reject);
});
}
private handleChunkedResponse(res: http.IncomingMessage) {
let buffer: Buffer;
return new Promise<Buffer>(resolve => {
res.on("data", (message: Buffer) => {
const chunk = message;
if (buffer) {
buffer = Buffer.concat([buffer, chunk], buffer.length + chunk.length);
} else {
buffer = Buffer.concat([chunk], chunk.length);
}
});

res.on("end", () => {
resolve(buffer);
});
});
private async handleChunkedResponse(res: http.IncomingMessage) {
const chunks = [];
let totalLength = 0;
for await (let chunk of res) {
chunks.push(chunk);
totalLength += chunk.length;
}
return chunks.length === 1 ? chunks[0] : Buffer.concat(chunks, totalLength);
}

public async request<T>(
Expand Down Expand Up @@ -119,17 +116,24 @@ export class HttpHandler extends BaseHandler implements Handler {
const { headers } = res;

let buffer: Promise<Buffer>;
// if we have a transfer-encoding we don't care about "content-length"
// (per HTTP spec). We also don't care about invalid lengths
if ("transfer-encoding" in headers) {
// in the browser we can't detect if the response is compressed (gzip),
// but it doesn't matter since the browser has decompressed already
// anyway
if (process.env.IS_BROWSER) {
buffer = this.handleChunkedResponse(res);
} else {
const length = (headers["content-length"] as any) / 1;
if (isNaN(length) || length <= 0) {
// if we have a transfer-encoding we don't care about "content-length"
// (per HTTP spec). We also don't care about invalid lengths
if ("transfer-encoding" in headers) {
buffer = this.handleChunkedResponse(res);
} else {
// we have a content-length; use it to pre-allocate the required memory
buffer = this.handleLengthedResponse(res, length);
const length = (headers["content-length"] as any) / 1;
if (isNaN(length) || length <= 0) {
buffer = this.handleChunkedResponse(res);
} else {
// we have a content-length; use it to pre-allocate the required memory
buffer = this.handleLengthedResponse(res, length);
}
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/chains/ethereum/options/src/miner-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,18 @@ const toBigIntOrString = (str: string) => {
return BigInt(str);
}
};
/**
* Handles defaultTransactionGasLimit special case of 'estimate' for tx value.
*
* @param str - the string literal 'estimate' or string that that represents a bigint, number, or hexadecimal value.
*/
const estimateOrToBigIntOrString = (str: string) => {
if (str === "estimate") {
return str;
} else {
return toBigIntOrString(str);
}
};

/**
* Attempts to convert strings that don't start with `0x` to a number
Expand Down Expand Up @@ -259,7 +271,7 @@ export const MinerOptions: Definitions<MinerConfig> = {
'Sets the default transaction gas limit in WEI. Set to "estimate" to use an estimate (slows down transaction execution by 40%+).',
default: () => Quantity.from(90_000),
cliType: "string",
cliCoerce: toBigIntOrString
cliCoerce: estimateOrToBigIntOrString
},
difficulty: {
normalize: Quantity.from,
Expand Down
4 changes: 2 additions & 2 deletions src/chains/ethereum/utils/src/errors/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ export const INTRINSIC_GAS_TOO_LOW = "intrinsic gas too low";
export const GAS_LIMIT = "exceeds block gas limit";

/**
* Prefix for a single VM Exception occuring when running a transaction or block
* Prefix for a single VM Exception occurring when running a transaction or block
*/
export const VM_EXCEPTION = "VM Exception while processing transaction: ";

/**
* Prefix for multiple VM Exceptions occuring when running transactions or a block
* Prefix for multiple VM Exceptions occurring when running transactions or a block
*/
export const VM_EXCEPTIONS =
"Multiple VM Exceptions while processing transactions: : \n\n";
Expand Down
6 changes: 3 additions & 3 deletions src/chains/filecoin/filecoin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/chains/filecoin/filecoin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@filecoin-shipyard/lotus-client-schema": "2.0.0",
"@ganache/filecoin-options": "0.4.1",
"@ganache/utils": "0.4.1",
"@trufflesuite/uws-js-unofficial": "20.10.0-unofficial.0",
"@trufflesuite/uws-js-unofficial": "20.10.0-unofficial.1",
"@types/abstract-leveldown": "7.2.0",
"@types/bn.js": "5.1.0",
"@types/deep-equal": "1.0.1",
Expand Down
6 changes: 3 additions & 3 deletions src/chains/tezos/tezos/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/chains/tezos/tezos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"emittery": "0.10.0"
},
"devDependencies": {
"@trufflesuite/uws-js-unofficial": "20.10.0-unofficial.0",
"@trufflesuite/uws-js-unofficial": "20.10.0-unofficial.1",
"@types/mocha": "9.0.0",
"cheerio": "1.0.0-rc.3",
"cross-env": "7.0.3",
Expand Down
6 changes: 3 additions & 3 deletions src/packages/core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@ganache/options": "0.4.1",
"@ganache/tezos": "0.4.1",
"@ganache/utils": "0.4.1",
"@trufflesuite/uws-js-unofficial": "20.10.0-unofficial.0",
"@trufflesuite/uws-js-unofficial": "20.10.0-unofficial.1",
"aggregate-error": "3.1.0",
"emittery": "0.10.0",
"promise.allsettled": "1.0.4"
Expand Down
1 change: 0 additions & 1 deletion src/packages/flavors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export function GetConnector<Flavor extends FlavorName>(
const f = eval("require")(flavor);
const Connector: FilecoinConnector =
typeof f.default != "undefined" ? f.default.Connector : f.Connector;
console.log(Connector, f);
// @ts-ignore
return new Connector(providerOptions, executor);
}
Expand Down
2 changes: 0 additions & 2 deletions src/packages/ganache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,6 @@ const options = {};
const provider = Ganache.provider(options);
```

NOTE: currently forking does not work in the browser, but we plan to add support in the future.

## Documentation

New interactive RPC documentation coming soon!
Expand Down
5 changes: 5 additions & 0 deletions src/packages/ganache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export type {
export { EthereumProvider } from "@ganache/core";
import type { ConnectorsByName } from "@ganache/flavors";
export type FilecoinProvider = ConnectorsByName["filecoin"];

// polyfill "setImmediate" for the browser
// this is removed by webpack for our Node.js build
require("setimmediate");

export {
server,
provider,
Expand Down
Loading

0 comments on commit 2ea79dd

Please sign in to comment.