Skip to content

Commit

Permalink
fix: Update deps fix (#65)
Browse files Browse the repository at this point in the history
* Update @lqdgerhq/hw-transport-node-hid

* fix imports

* Work around weird ts-lint false positive

* update all ledger deps

* update ethereumjs-util

* Create a new ganache provider in a describe

* Use isomorphic-fetch 3.0.0

* Update yargs, top level ganache

* Fix integration issues

* update equality tests with new ganache error format

* linter

* rename typescript typings for Ledger Transport

* CHANGELOG

* update moment for monorepo-scripts

* Update CHANGELOGs to a few major versions
  • Loading branch information
dekz authored Aug 8, 2022
1 parent 14e5370 commit e003034
Show file tree
Hide file tree
Showing 26 changed files with 487 additions and 288 deletions.
2 changes: 1 addition & 1 deletion abi-gen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"tmp": "^0.0.33",
"to-snake-case": "^1.0.0",
"toposort": "^2.0.2",
"yargs": "^10.0.3"
"yargs": "^17.5.1"
},
"devDependencies": {
"@0x/assert": "^3.0.34",
Expand Down
18 changes: 13 additions & 5 deletions abi-gen/test-cli/test_typescript/test/abi_gen_dummy_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ const txDefaults = {
gas: devConstants.GAS_LIMIT,
};

const provider: Web3ProviderEngine = web3Factory.getRpcProvider({ shouldUseInProcessGanache: true });
const web3Wrapper = new Web3Wrapper(provider);

chai.config.includeStack = true;
chai.use(ChaiBigNumber());
chai.use(dirtyChai);
chai.use(chaiAsPromised);
const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);

describe('AbiGenDummy Contract', () => {
const provider: Web3ProviderEngine = web3Factory.getRpcProvider({ shouldUseInProcessGanache: true });
const web3Wrapper = new Web3Wrapper(provider);
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);

let abiGenDummy: AbiGenDummyContract;
const runTestAsync = async (
contractMethodName: string,
Expand All @@ -54,7 +54,6 @@ describe('AbiGenDummy Contract', () => {
expect(decodedOutput, 'decoded output').to.be.deep.equal(output);
};
before(async () => {
providerUtils.startProviderEngine(provider);
abiGenDummy = await AbiGenDummyContract.deployFrom0xArtifactAsync(
artifacts.AbiGenDummy,
provider,
Expand Down Expand Up @@ -300,12 +299,19 @@ describe('AbiGenDummy Contract', () => {

describe('Lib dummy contract', () => {
let libDummy: TestLibDummyContract;

const provider: Web3ProviderEngine = web3Factory.getRpcProvider({ shouldUseInProcessGanache: true });
const web3Wrapper = new Web3Wrapper(provider);
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);

before(async () => {
await blockchainLifecycle.startAsync();
});

after(async () => {
await blockchainLifecycle.revertAsync();
});

before(async () => {
libDummy = await TestLibDummyContract.deployFrom0xArtifactAsync(
artifacts.TestLibDummy,
Expand All @@ -314,9 +320,11 @@ describe('Lib dummy contract', () => {
artifacts,
);
});

beforeEach(async () => {
await blockchainLifecycle.startAsync();
});

afterEach(async () => {
await blockchainLifecycle.revertAsync();
});
Expand Down
13 changes: 5 additions & 8 deletions base-contract/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
StringRevertError,
} from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import VM from '@ethereumjs/vm';
import { RunCallOpts } from '@ethereumjs/vm/dist/runCall';
import {
AbiDefinition,
AbiType,
Expand All @@ -26,14 +28,9 @@ import {
TxDataPayable,
} from 'ethereum-types';
import * as util from 'ethereumjs-util';
import VM from '@ethereumjs/vm';

export { linkLibrariesInBytecode, methodAbiToFunctionSignature } from './utils';

import { AwaitTransactionSuccessOpts } from './types';
import { formatABIDataItem } from './utils';
import { RunCallOpts } from '@ethereumjs/vm/dist/runCall';
import Common, { Chain, Hardfork } from '@ethereumjs/common';

export { SubscriptionManager } from './subscription_manager';

Expand All @@ -46,6 +43,8 @@ export {
SubscriptionErrors,
} from './types';

export { linkLibrariesInBytecode, methodAbiToFunctionSignature } from './utils';

export interface AbiEncoderByFunctionSignature {
[key: string]: AbiEncoder.Method;
}
Expand Down Expand Up @@ -190,9 +189,7 @@ export class BaseContract {
const decoded = rawDecoded[i];
if (!abiUtils.isAbiDataEqual(params.names[i], params.types[i], original, decoded)) {
throw new Error(
`Cannot safely encode argument: ${params.names[i]} (${original}) of type ${
params.types[i]
}. (Possible type overflow or other encoding error)`,
`Cannot safely encode argument: ${params.names[i]} (${original}) of type ${params.types[i]}. (Possible type overflow or other encoding error)`,
);
}
}
Expand Down
1 change: 1 addition & 0 deletions base-contract/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export function linkLibrariesInBytecode(
bytecode = [
bytecode.substring(0, ref.start * 2),
libraryAddress.toLowerCase().substr(2),
// tslint:disable-next-line:restrict-plus-operands
bytecode.substring((ref.start + ref.length) * 2),
].join('');
}
Expand Down
9 changes: 9 additions & 0 deletions dev-utils/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
[
{
"version": "5.0.0",
"changes": [
{
"note": "Update Ganache to 7.x",
"pr": 64
}
]
},
{
"timestamp": 1647415391,
"version": "4.2.14",
Expand Down
37 changes: 12 additions & 25 deletions dev-utils/test/chai_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,43 +48,30 @@ describe('Chai tests', () => {
const error = new Error(message);
expect(error).is.equal(revert);
});
it('should equate a ganache transaction revert error with reason to a StringRevertError with an equal message', () => {
const message = 'foo';
const error: any = new Error(`VM Exception while processing transaction: revert ${message}`);
error.hashes = ['0x1'];
error.results = { '0x1': { error: 'revert', program_counter: 1, return: '0x', reason: message } };
const revert = new StringRevertError(message);
expect(error).is.equal(revert);
});
it('should equate a ganache transaction revert error with return data to a StringRevertError with an equal message', () => {
const message = 'foo';
const error: any = new Error(`VM Exception while processing transaction: revert`);
error.hashes = ['0x1'];
// Encoding for `Error(string message='foo')`
const returnData =
// tslint:disable-next-line:custom-no-magic-numbers
error.code = -3200;
error.data =
'0x08c379a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003666f6f0000000000000000000000000000000000000000000000000000000000';
error.results = {
'0x1': { error: 'revert', program_counter: 1, return: returnData, reason: undefined },
};
const revert = new StringRevertError('foo');
const revert = new StringRevertError(message);
expect(error).is.equal(revert);
});
it('should not equate a ganache transaction revert error with reason to a StringRevertError with a different message', () => {
const message = 'foo';
const error: any = new Error(`VM Exception while processing transaction: revert ${message}`);
error.hashes = ['0x1'];
error.results = { '0x1': { error: 'revert', program_counter: 1, return: '0x', reason: message } };
const error: any = new Error(`VM Exception while processing transaction: revert`);
error.data = '0x';
// tslint:disable-next-line:custom-no-magic-numbers
error.code = -3200;
const revert = new StringRevertError('boo');
expect(error).is.not.equal(revert);
});
it('should not equate a ganache transaction revert error with return data to a StringRevertError with a different message', () => {
const error: any = new Error(`VM Exception while processing transaction: revert`);
error.hashes = ['0x1'];
// Encoding for `Error(string message='foo')`
const returnData =
// tslint:disable-next-line:custom-no-magic-numbers
error.code = -3200;
error.data =
'0x08c379a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003666f6f0000000000000000000000000000000000000000000000000000000000';
error.results = {
'0x1': { error: 'revert', program_counter: 1, return: returnData, reason: undefined },
};
const revert = new StringRevertError('boo');
expect(error).is.not.equal(revert);
});
Expand Down
6 changes: 3 additions & 3 deletions monorepo-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@
"chalk": "^2.3.0",
"es6-promisify": "^5.0.0",
"glob": "^7.1.2",
"isomorphic-fetch": "2.2.1",
"isomorphic-fetch": "^3.0.0",
"lodash": "^4.17.21",
"mkdirp": "^0.5.1",
"moment": "2.21.0",
"moment": "^2.29.4",
"promisify-child-process": "^1.0.5",
"prompt": "^1.0.0",
"publish-release": "https://github.com/0xProject/publish-release.git#3f8be1105a356527f4b362ff456d94bf9a82f2ed",
Expand All @@ -66,7 +66,7 @@
"semver-diff": "^2.1.0",
"semver-sort": "0.0.4",
"typedoc": "~0.16.11",
"yargs": "^10.0.3"
"yargs": "^17.5.1"
},
"publishConfig": {
"access": "public"
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"scripts": {
"deps_versions:ci": "node ./monorepo-scripts/lib/deps_versions.js",
"fix": "wsrun fix $PKG --fast-exit --parallel --exclude-missing",
"ganache": "ganache-cli -p 8545 --gasLimit 10000000 --networkId 50 -m \"${npm_package_config_mnemonic}\"",
"ganache": "ganache -p 8545 --gasLimit 10000000 --networkId 50 -m \"${npm_package_config_mnemonic}\"",
"prettier": "prettier --write '**/*.{ts,tsx,json,md}' --config .prettierrc",
"prettier:ci": "prettier --list-different '**/*.{ts,tsx,json,md}' --config .prettierrc",
"report_coverage": "lcov-result-merger './*/coverage/lcov.info' | coveralls",
Expand Down Expand Up @@ -54,7 +54,7 @@
"@0xproject/npm-cli-login": "^0.0.11",
"async-child-process": "^1.1.1",
"coveralls": "^3.0.0",
"ganache-cli": "6.8.0-istanbul.0",
"ganache": "^7.4.0",
"lcov-result-merger": "^3.0.0",
"lerna": "^3.0.0-beta.25",
"npm-run-all": "^4.1.5",
Expand Down
4 changes: 2 additions & 2 deletions sol-compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"chalk": "^2.3.0",
"chokidar": "^3.0.2",
"ethereum-types": "^3.7.0",
"ethereumjs-util": "^7.1.0",
"ethereumjs-util": "^7.1.5",
"lodash": "^4.17.21",
"mkdirp": "^0.5.1",
"pluralize": "^7.0.0",
Expand All @@ -97,7 +97,7 @@
"source-map-support": "^0.5.0",
"strip-comments": "^2.0.1",
"web3-eth-abi": "^1.0.0-beta.24",
"yargs": "^10.0.3"
"yargs": "^17.5.1"
},
"publishConfig": {
"access": "public"
Expand Down
4 changes: 2 additions & 2 deletions sol-doc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
"@0x/utils": "^6.5.3",
"@types/node": "12.12.54",
"ethereum-types": "^3.7.0",
"ethereumjs-util": "^7.1.0",
"ethereumjs-util": "^7.1.5",
"glob": "^7.1.2",
"yargs": "^10.0.3"
"yargs": "^17.5.1"
},
"devDependencies": {
"@0x/dev-utils": "^4.2.14",
Expand Down
2 changes: 1 addition & 1 deletion sol-profiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@0x/utils": "^6.5.3",
"@types/node": "12.12.54",
"ethereum-types": "^3.7.0",
"ethereumjs-util": "^7.1.0",
"ethereumjs-util": "^7.1.5",
"lodash": "^4.17.21",
"web3-provider-engine": "16.0.4"
},
Expand Down
2 changes: 1 addition & 1 deletion sol-trace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@types/node": "12.12.54",
"chalk": "^2.3.0",
"ethereum-types": "^3.7.0",
"ethereumjs-util": "^7.1.0",
"ethereumjs-util": "^7.1.5",
"lodash": "^4.17.21",
"loglevel": "^1.6.1",
"web3-provider-engine": "16.0.4"
Expand Down
2 changes: 1 addition & 1 deletion sol-tracing-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@types/solidity-parser-antlr": "^0.2.3",
"chalk": "^2.3.0",
"ethereum-types": "^3.7.0",
"ethereumjs-util": "^7.1.0",
"ethereumjs-util": "^7.1.5",
"ethers": "~4.0.4",
"glob": "^7.1.2",
"istanbul": "^0.4.5",
Expand Down
4 changes: 4 additions & 0 deletions subproviders/CHANGELOG.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
{
"note": "Update Ganache to 7.x",
"pr": 64
},
{
"note": "Change to Ledger `TransportWebUSB` over `TransportU2F`",
"pr": 64
}
]
},
Expand Down
10 changes: 5 additions & 5 deletions subproviders/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@
"@0x/web3-wrapper": "^7.6.5",
"@ethereumjs/common": "^2.6.3",
"@ethereumjs/tx": "^3.5.1",
"@ledgerhq/hw-app-eth": "^4.3.0",
"@ledgerhq/hw-transport-u2f": "4.24.0",
"@ledgerhq/hw-app-eth": "^5.53.0",
"@ledgerhq/hw-transport-webusb": "^5.53.1",
"@types/hdkey": "^0.7.0",
"@types/node": "12.12.54",
"@types/web3-provider-engine": "^14.0.0",
"bip39": "^2.5.0",
"bn.js": "^4.11.8",
"ethereum-types": "^3.7.0",
"ethereumjs-util": "^7.1.0",
"ganache": "^7.3.2",
"ethereumjs-util": "^7.1.5",
"ganache": "^7.4.0",
"hdkey": "^0.7.1",
"json-rpc-error": "2.0.0",
"lodash": "^4.17.21",
Expand Down Expand Up @@ -88,7 +88,7 @@
"webpack": "^4.20.2"
},
"optionalDependencies": {
"@ledgerhq/hw-transport-node-hid": "^4.3.0"
"@ledgerhq/hw-transport-node-hid": "^5.51.1"
},
"publishConfig": {
"access": "public"
Expand Down
4 changes: 2 additions & 2 deletions subproviders/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Eth from '@ledgerhq/hw-app-eth';
import TransportU2F from '@ledgerhq/hw-transport-u2f';
import TransportWebUSB from '@ledgerhq/hw-transport-webusb';
export import Web3ProviderEngine = require('web3-provider-engine');

import { LedgerEthereumClient } from './types';
Expand All @@ -9,7 +9,7 @@ import { LedgerEthereumClient } from './types';
* @return LedgerEthereumClient A browser client for the LedgerSubprovider
*/
export async function ledgerEthereumBrowserClientFactoryAsync(): Promise<LedgerEthereumClient> {
const ledgerConnection = await TransportU2F.create();
const ledgerConnection = await TransportWebUSB.create();
const ledgerEthClient = new Eth(ledgerConnection);
return ledgerEthClient;
}
Expand Down
15 changes: 10 additions & 5 deletions subproviders/src/subproviders/ganache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Hardfork } from '@ethereumjs/common/dist/types';
import { JSONRPCRequestPayload } from 'ethereum-types';
import { EthereumProvider, provider, ProviderOptions } from 'ganache';

Expand All @@ -16,6 +15,7 @@ export interface GanacheOpts {
port?: number;
network_id?: number;
networkId?: number;
// @deprecated _chainId has been removed in 7.x
_chainId?: number;
chainId?: number;
mnemonic?: string;
Expand Down Expand Up @@ -56,12 +56,17 @@ export class GanacheSubprovider extends Subprovider {
unlocked_accounts: opts.unlocked_accounts,
fork: { url: opts.fork },
hardfork: opts.hardfork as any,
asyncRequestProcessing: false,
};
// HACK: appears to be a collision and fork is no longer a string
// typing seems confused (or I'm confused)
// An undefined value is not possible, the key is required to be missing
// HACK: removed undefined values as this seems to cause an issue
// when the keys are present, especially for `fork` option.
Object.keys(migratedOpts).forEach(k => {
if ((migratedOpts as any)[k] === undefined) {
delete (migratedOpts as any)[k];
}
});
if (!opts.fork) {
delete migratedOpts['fork'];
delete migratedOpts.fork;
}
this._ganacheProvider = provider(migratedOpts) as EthereumProvider;
}
Expand Down
4 changes: 2 additions & 2 deletions typescript-typings/types/@ledgerhq/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ declare module '@ledgerhq/hw-app-eth' {
export default Eth;
}

declare module '@ledgerhq/hw-transport-u2f' {
export default class TransportU2F implements LedgerTransport {
declare module '@ledgerhq/hw-transport-webusb' {
export default class TransportWebUSB implements LedgerTransport {
public static create(): Promise<LedgerTransport>;
public close(): Promise<void>;
}
Expand Down
Loading

0 comments on commit e003034

Please sign in to comment.