Skip to content

Commit

Permalink
Merge branch 'feature/migrate-to-etherscan' of github.com:MetaMask/ga…
Browse files Browse the repository at this point in the history
…ba into feature/migrate-to-etherscan

* 'feature/migrate-to-etherscan' of github.com:MetaMask/gaba:
  Update `sinon` and `@types/sinon` to latest versions (#352)
  Fix `tsconfig.json` indentation (#355)
  Replace `fetch-mock` with `nock` (#340)
  Update `ethereumjs-wallet` from v0.6.5 to v1.0.1 (#347)
  Add `babel-runtime` dependency required by `ethjs-query` (#341)
  Update `@metamask/eslint-config` from v3 to v4.1.0 (#344)
  Add `docs` to list of ignored eslint patterns (#345)
  Update `uuid` from `v3.3.3` to `v8.3.2` (#346)
  Update approval controller test import (#339)
  Add Dependabot config (#343)
  Update `typedoc` (#342)
  Remove unused test module (#338)
  Replace `await-semaphore` with `async-mutex` (#334)
  Update `eth-json-rpc-filters` in lockfile (#336)
  • Loading branch information
rickycodes committed Feb 18, 2021
2 parents d612c46 + 2455801 commit 01b4d01
Show file tree
Hide file tree
Showing 23 changed files with 706 additions and 851 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
'!jest.config.js',
'node_modules',
'dist',
'docs',
'coverage',
'*.d.ts',
],
Expand Down Expand Up @@ -53,6 +54,7 @@ module.exports = {
},
],

'accessor-pairs': 'off',
'camelcase': 'off',
'consistent-return': 'off',
'default-case': 'off',
Expand All @@ -74,6 +76,8 @@ module.exports = {
'radix': 'off',
'require-atomic-updates': 'off',

'node/no-extraneous-require': 'off',

'jest/expect-expect': 'off',
'jest/no-test-return-statement': 'off',
'jest/no-truthy-falsy': 'off',
Expand Down
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "daily"
allow:
- dependency-name: "@metamask/*"
versioning-strategy: "increase"
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
},
"dependencies": {
"@metamask/contract-metadata": "^1.22.0",
"await-semaphore": "^0.1.3",
"async-mutex": "^0.2.6",
"babel-runtime": "^6.26.0",
"eth-ens-namehash": "^2.0.8",
"eth-json-rpc-infura": "^5.1.0",
"eth-keyring-controller": "^6.1.0",
Expand All @@ -46,38 +47,38 @@
"eth-rpc-errors": "^4.0.0",
"eth-sig-util": "^3.0.0",
"ethereumjs-util": "^6.1.0",
"ethereumjs-wallet": "^0.6.4",
"ethereumjs-wallet": "^1.0.1",
"human-standard-collectible-abi": "^1.0.2",
"human-standard-token-abi": "^2.0.0",
"isomorphic-fetch": "^3.0.0",
"jsonschema": "^1.2.4",
"nanoid": "^3.1.12",
"single-call-balance-checker-abi": "^1.0.0",
"uuid": "^3.3.2",
"uuid": "^8.3.2",
"web3": "^0.20.7",
"web3-provider-engine": "^16.0.1"
},
"devDependencies": {
"@metamask/eslint-config": "^3.0.0",
"@types/fetch-mock": "^7.3.1",
"@metamask/eslint-config": "^4.1.0",
"@types/jest": "^22.2.3",
"@types/node": "^10.1.4",
"@types/sinon": "^4.3.3",
"@types/sinon": "^9.0.10",
"@types/web3": "^1.0.6",
"@typescript-eslint/eslint-plugin": "^4.1.0",
"@typescript-eslint/parser": "^4.1.0",
"eslint": "^6.8.0",
"eslint": "^7.19.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-jest": "^23.6.0",
"eslint-plugin-node": "^11.1.0",
"ethjs-provider-http": "^0.1.6",
"fetch-mock": "^9.10.7",
"jest": "^26.4.2",
"jest-environment-jsdom": "^25.0.0",
"lint-staged": "^6.1.0",
"nock": "^13.0.7",
"prettier": "^2.1.1",
"sinon": "^7.4.1",
"sinon": "^9.2.4",
"ts-jest": "^26.3.0",
"typedoc": "^0.20.20",
"typedoc": "^0.20.24",
"typescript": "^4.0.3"
},
"jest": {
Expand All @@ -96,7 +97,6 @@
],
"coveragePathIgnorePatterns": [
"/node_modules/",
"dist/BaseController*",
"tests/"
],
"coverageThreshold": {
Expand Down
2 changes: 1 addition & 1 deletion src/assets/AccountTrackerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PreferencesController from '../user/PreferencesController';
import { BNToHex, query, safelyExecuteWithTimeout } from '../util';

const EthQuery = require('eth-query');
const { Mutex } = require('await-semaphore');
const { Mutex } = require('async-mutex');

/**
* @type AccountInformation
Expand Down
4 changes: 2 additions & 2 deletions src/assets/AssetsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { Token } from './TokenRatesController';
import { AssetsContractController } from './AssetsContractController';
import { ApiCollectibleResponse } from './AssetsDetectionController';

const { Mutex } = require('await-semaphore');
const random = require('uuid/v1');
const { Mutex } = require('async-mutex');
const random = require('uuid').v1;

/**
* @type Collectible
Expand Down
2 changes: 1 addition & 1 deletion src/assets/CurrencyRateController.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BaseController, { BaseConfig, BaseState } from '../BaseController';
import { safelyExecute, handleFetch } from '../util';

const { Mutex } = require('await-semaphore');
const { Mutex } = require('async-mutex');

/**
* @type CurrencyRateConfig
Expand Down
7 changes: 3 additions & 4 deletions src/keyring/KeyringController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ import {
signTypedData_v4,
signTypedDataLegacy,
} from 'eth-sig-util';
import Wallet, { thirdparty as importers } from 'ethereumjs-wallet';
import BaseController, { BaseConfig, BaseState, Listener } from '../BaseController';
import PreferencesController from '../user/PreferencesController';
import { Transaction } from '../transaction/TransactionController';
import { PersonalMessageParams } from '../message-manager/PersonalMessageManager';
import { TypedMessageParams } from '../message-manager/TypedMessageManager';

const Keyring = require('eth-keyring-controller');
const { Mutex } = require('await-semaphore');
const Wallet = require('ethereumjs-wallet');
const { Mutex } = require('async-mutex');
const ethUtil = require('ethereumjs-util');
const importers = require('ethereumjs-wallet/thirdparty');

const privates = new WeakMap();

Expand Down Expand Up @@ -288,7 +287,7 @@ export class KeyringController extends BaseController<KeyringConfig, KeyringStat
try {
wallet = importers.fromEtherWallet(input, password);
} catch (e) {
wallet = wallet || Wallet.fromV3(input, password, true);
wallet = wallet || await Wallet.fromV3(input, password, true);
}
privateKey = ethUtil.bufferToHex(wallet.getPrivateKey());
break;
Expand Down
2 changes: 1 addition & 1 deletion src/message-manager/MessageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import AbstractMessageManager, {
OriginalRequest,
} from './AbstractMessageManager';

const random = require('uuid/v1');
const random = require('uuid').v1;

/**
* @type Message
Expand Down
2 changes: 1 addition & 1 deletion src/message-manager/PersonalMessageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import AbstractMessageManager, {
OriginalRequest,
} from './AbstractMessageManager';

const random = require('uuid/v1');
const random = require('uuid').v1;

/**
* @type Message
Expand Down
2 changes: 1 addition & 1 deletion src/message-manager/TypedMessageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import AbstractMessageManager, {
OriginalRequest,
} from './AbstractMessageManager';

const random = require('uuid/v1');
const random = require('uuid').v1;

/**
* @type TypedMessage
Expand Down
2 changes: 1 addition & 1 deletion src/network/NetworkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const EthQuery = require('eth-query');
const Subprovider = require('web3-provider-engine/subproviders/provider.js');
const createInfuraProvider = require('eth-json-rpc-infura/src/createProvider');
const createMetamaskProvider = require('web3-provider-engine//zero.js');
const { Mutex } = require('await-semaphore');
const { Mutex } = require('async-mutex');

/**
* Human-readable network name
Expand Down
4 changes: 2 additions & 2 deletions src/transaction/TransactionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import {
const MethodRegistry = require('eth-method-registry');
const EthQuery = require('eth-query');
const Transaction = require('ethereumjs-tx');
const random = require('uuid/v1');
const random = require('uuid').v1;
const { BN } = require('ethereumjs-util');
const { Mutex } = require('await-semaphore');
const { Mutex } = require('async-mutex');

/**
* @type Result
Expand Down
2 changes: 1 addition & 1 deletion tests/ApprovalController.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { errorCodes } = require('eth-rpc-errors');
const ApprovalController = require('../dist/approval/ApprovalController').default;
const ApprovalController = require('../src/approval/ApprovalController').default;

const defaultConfig = {
showApprovalRequest: () => undefined,
Expand Down
2 changes: 1 addition & 1 deletion tests/ApprovalController.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { errorCodes } from 'eth-rpc-errors';
import ApprovalController from '../dist/approval/ApprovalController';
import ApprovalController from '../src/approval/ApprovalController';

const sinon = require('sinon');

Expand Down
137 changes: 50 additions & 87 deletions tests/AssetsController.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createSandbox } from 'sinon';
import { getOnce } from 'fetch-mock';
import * as nock from 'nock';
import AssetsController from '../src/assets/AssetsController';
import ComposableController from '../src/ComposableController';
import PreferencesController from '../src/user/PreferencesController';
Expand All @@ -10,7 +10,8 @@ const HttpProvider = require('ethjs-provider-http');

const KUDOSADDRESS = '0x2aea4add166ebf38b63d09a75de1a7b94aa24163';
const MAINNET_PROVIDER = new HttpProvider('https://mainnet.infura.io/v3/341eacb578dd44a1a049cbc5f6fd4035');
const OPEN_SEA_API = 'https://api.opensea.io/api/v1/';
const OPEN_SEA_HOST = 'https://api.opensea.io';
const OPEN_SEA_PATH = '/api/v1';

describe('AssetsController', () => {
let assetsController: AssetsController;
Expand All @@ -27,94 +28,56 @@ describe('AssetsController', () => {

new ComposableController([assetsController, assetsContract, network, preferences]);

getOnce(
`${OPEN_SEA_API}asset_contract/0xfoO`,
() => ({
body: JSON.stringify({
description: 'Description',
image_url: 'url',
name: 'Name',
symbol: 'FOO',
total_supply: 0,
}),
}),
{ overwriteRoutes: true, method: 'GET' },
);
getOnce(
`${OPEN_SEA_API}asset_contract/0xFOu`,
() => ({
body: JSON.stringify({
description: 'Description',
image_url: 'url',
name: 'Name',
symbol: 'FOU',
total_supply: 10,
}),
}),
{ overwriteRoutes: true, method: 'GET' },
);
getOnce(
`${OPEN_SEA_API}asset/0xfoO/1`,
() => ({
body: JSON.stringify({
description: 'Description',
image_original_url: 'url',
name: 'Name',
}),
}),
{ overwriteRoutes: true, method: 'GET' },
);
getOnce(
`${OPEN_SEA_API}asset/0x2aEa4Add166EBf38b63d09a75dE1a7b94Aa24163/1203`,
() => ({
body: JSON.stringify({
description: 'Kudos Description',
image_original_url: 'Kudos url',
name: 'Kudos Name',
}),
}),
{ overwriteRoutes: true, method: 'GET' },
);
getOnce(
'https://ipfs.gitcoin.co:443/api/v0/cat/QmPmt6EAaioN78ECnW5oCL8v2YvVSpoBjLCjrXhhsAvoov',
() => ({
body: JSON.stringify({
image: 'Kudos Image',
name: 'Kudos Name',
}),
}),
{ overwriteRoutes: true, method: 'GET' },
);
getOnce(
`${OPEN_SEA_API}asset/0x6EbeAf8e8E946F0716E6533A6f2cefc83f60e8Ab/798958393`,
() => ({
throws: new TypeError('Failed to fetch'),
}),
{ overwriteRoutes: true, method: 'GET' },
);
getOnce(
`${OPEN_SEA_API}asset_contract/0x6EbeAf8e8E946F0716E6533A6f2cefc83f60e8Ab`,
() => ({
throws: new TypeError('Failed to fetch'),
}),
{ overwriteRoutes: true, method: 'GET' },
);
getOnce(
`${OPEN_SEA_API}asset_contract/0x2aEa4Add166EBf38b63d09a75dE1a7b94Aa24163`,
() => ({
body: JSON.stringify({
description: 'Kudos Description',
image_url: 'Kudos url',
name: 'Kudos',
symbol: 'KDO',
total_supply: 10,
}),
}),
{ overwriteRoutes: true, method: 'GET' },
);
nock(OPEN_SEA_HOST)
.get(`${OPEN_SEA_PATH}/asset_contract/0xfoO`)
.reply(200, {
description: 'Description',
image_url: 'url',
name: 'Name',
symbol: 'FOO',
total_supply: 0,
})
.get(`${OPEN_SEA_PATH}/asset_contract/0xFOu`)
.reply(200, {
description: 'Description',
image_url: 'url',
name: 'Name',
symbol: 'FOU',
total_supply: 10,
})
.get(`${OPEN_SEA_PATH}/asset/0xfoO/1`)
.reply(200, {
description: 'Description',
image_original_url: 'url',
name: 'Name',
})
.get(`${OPEN_SEA_PATH}/asset/0x2aEa4Add166EBf38b63d09a75dE1a7b94Aa24163/1203`)
.reply(200, {
description: 'Kudos Description',
image_original_url: 'Kudos url',
name: 'Kudos Name',
})
.get(`${OPEN_SEA_PATH}/asset/0x6EbeAf8e8E946F0716E6533A6f2cefc83f60e8Ab/798958393`)
.replyWithError(new TypeError('Failed to fetch'))
.get(`${OPEN_SEA_PATH}/asset_contract/0x6EbeAf8e8E946F0716E6533A6f2cefc83f60e8Ab`)
.replyWithError(new TypeError('Failed to fetch'))
.get(`${OPEN_SEA_PATH}/asset_contract/0x2aEa4Add166EBf38b63d09a75dE1a7b94Aa24163`)
.reply(200, {
description: 'Kudos Description',
image_url: 'Kudos url',
name: 'Kudos',
symbol: 'KDO',
total_supply: 10,
});

nock('https://ipfs.gitcoin.co:443').get('/api/v0/cat/QmPmt6EAaioN78ECnW5oCL8v2YvVSpoBjLCjrXhhsAvoov').reply(200, {
image: 'Kudos Image',
name: 'Kudos Name',
});
});

afterEach(() => {
nock.cleanAll();
sandbox.reset();
});

Expand Down
Loading

0 comments on commit 01b4d01

Please sign in to comment.