Skip to content

Commit

Permalink
all tests not passing yet
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyapotti committed Sep 14, 2023
1 parent 246c0a0 commit 1e9676d
Show file tree
Hide file tree
Showing 15 changed files with 1,211 additions and 722 deletions.
1,748 changes: 1,134 additions & 614 deletions package-lock.json

Large diffs are not rendered by default.

87 changes: 43 additions & 44 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,37 @@
"test:e2e:mobile": "env MOBILE_ENV=true mocha --timeout=60000 ./test/e2e"
},
"dependencies": {
"@ethereumjs/common": "^3.2.0",
"@ethereumjs/tx": "^4.2.0",
"@ethereumjs/util": "^8.1.0",
"@ethereumjs/common": "^4.0.0",
"@ethereumjs/tx": "^5.0.0",
"@ethereumjs/util": "^9.0.0",
"@gtm-support/vue2-gtm": "^2.0.0",
"@metamask/contract-metadata": "^2.3.1",
"@metamask/contract-metadata": "^2.4.0",
"@metamask/eth-json-rpc-infura": "^8.1.1",
"@metamask/eth-json-rpc-middleware": "^11.0.1",
"@metamask/eth-json-rpc-provider": "^1.0.1",
"@metamask/eth-sig-util": "^6.0.0",
"@sentry/browser": "^7.64.0",
"@sentry/tracing": "^7.64.0",
"@sentry/vue": "^7.64.0",
"@toruslabs/broadcast-channel": "^7.0.0",
"@toruslabs/eccrypto": "^3.0.0",
"@toruslabs/http-helpers": "^4.0.0",
"@toruslabs/loglevel-sentry": "^5.0.0",
"@toruslabs/metadata-helpers": "^4.0.0",
"@toruslabs/openlogin": "^4.7.2",
"@toruslabs/openlogin-jrpc": "^4.7.2",
"@toruslabs/openlogin-session-manager": "^1.1.0",
"@toruslabs/openlogin-subkey": "^4.7.2",
"@toruslabs/openlogin-utils": "^4.7.0",
"@uniswap/default-token-list": "^11.5.0",
"@walletconnect/sign-client": "^2.10.0",
"@walletconnect/utils": "^2.10.0",
"@metamask/eth-json-rpc-middleware": "^11.0.2",
"@metamask/eth-json-rpc-provider": "^2.1.0",
"@metamask/eth-sig-util": "^7.0.0",
"@sentry/browser": "^7.68.0",
"@sentry/tracing": "^7.68.0",
"@sentry/vue": "^7.68.0",
"@toruslabs/broadcast-channel": "^8.0.0",
"@toruslabs/eccrypto": "^4.0.0",
"@toruslabs/http-helpers": "^5.0.0",
"@toruslabs/loglevel-sentry": "^6.0.1",
"@toruslabs/metadata-helpers": "^5.0.0",
"@toruslabs/openlogin": "^5.0.3",
"@toruslabs/openlogin-jrpc": "^5.0.2",
"@toruslabs/openlogin-session-manager": "^3.0.0",
"@toruslabs/openlogin-subkey": "^5.0.0",
"@toruslabs/openlogin-utils": "^5.0.2",
"@uniswap/default-token-list": "^11.6.0",
"@walletconnect/sign-client": "^2.10.1",
"@walletconnect/utils": "^2.10.1",
"await-semaphore": "^0.1.3",
"bignumber.js": "^9.1.1",
"bignumber.js": "^9.1.2",
"bn.js": "^5.2.1",
"bowser": "^2.11.0",
"copy-to-clipboard": "^3.3.3",
"core-js": "^3.32.0",
"core-js": "^3.32.2",
"das-sdk": "^1.9.3",
"deepmerge": "^4.3.1",
"eth-block-tracker": "^7.1.0",
Expand Down Expand Up @@ -97,64 +97,63 @@
"workbox-strategies": "^7.0.0"
},
"devDependencies": {
"@babel/core": "^7.22.10",
"@babel/eslint-parser": "^7.22.10",
"@babel/core": "^7.22.17",
"@babel/eslint-parser": "^7.22.15",
"@babel/eslint-plugin": "^7.22.10",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-numeric-separator": "^7.18.6",
"@babel/preset-env": "^7.22.10",
"@babel/register": "^7.22.5",
"@sentry/cli": "^2.20.5",
"@babel/preset-env": "^7.22.15",
"@babel/register": "^7.22.15",
"@sentry/cli": "^2.20.7",
"@vue/cli-plugin-babel": "^5.0.8",
"@vue/cli-plugin-eslint": "^5.0.8",
"@vue/cli-plugin-pwa": "^5.0.8",
"@vue/cli-service": "^5.0.8",
"@vue/eslint-config-standard": "^8.0.1",
"assert": "^2.0.0",
"assert": "^2.1.0",
"codecov": "^3.8.3",
"cross-env": "^7.0.3",
"dotenv": "^16.3.1",
"empty-module": "0.0.2",
"eslint": "^8.47.0",
"eslint": "^8.49.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^9.0.0",
"eslint-config-problems": "^8.0.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-n": "^16.0.1",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-n": "^16.1.0",
"eslint-plugin-only-error": "^1.0.2",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-switch-case": "^1.1.2",
"eslint-plugin-unicorn": "^47.0.0",
"eslint-plugin-unicorn": "^48.0.1",
"eslint-plugin-vue": "^9.17.0",
"eslint-plugin-vue-scoped-css": "^2.5.0",
"express": "^4.18.2",
"fibers": "^5.0.3",
"ganache": "^7.9.0",
"ganache": "^7.9.1",
"husky": "^8.0.3",
"jsdom": "^22.1.0",
"jsdom-global": "^3.0.2",
"lint-staged": "^14.0.0",
"lint-staged": "^14.0.1",
"lodash-es": "^4.17.21",
"luxon": "^3.4.0",
"luxon": "^3.4.3",
"mocha": "^10.2.0",
"nock": "13.3.2",
"node-fetch": "^3.3.2",
"nock": "13.3.3",
"nyc": "^15.1.0",
"prettier": "^3.0.2",
"prettier": "^3.0.3",
"process": "^0.11.10",
"puppeteer": "^21.0.3",
"puppeteer": "^21.2.0",
"sass": "~1.32.13",
"sass-loader": "^13.3.2",
"sinon": "^15.2.0",
"stylus": "^0.59.0",
"stylus": "^0.60.0",
"stylus-loader": "^7.1.3",
"terser-webpack-plugin": "^5.3.9",
"through2": "^4.0.2",
"uglifyify": "^5.0.2",
"url": "^0.11.1",
"url": "^0.11.2",
"vue-cli-plugin-vuetify": "^2.5.8",
"vue-cli-plugin-webpack-bundle-analyzer": "~4.0.0",
"vue-template-compiler": "^2.7.14",
Expand Down
3 changes: 1 addition & 2 deletions scripts/importLocales.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable unicorn/prefer-top-level-await */
/* eslint-disable import/no-extraneous-dependencies */

import fs from 'fs'
import fetch from 'node-fetch'
import path from 'path'

const args = process.argv.slice(2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
</template>

<script>
import { addHexPrefix, isValidPrivate, stripHexPrefix, toBuffer } from '@ethereumjs/util'
import { addHexPrefix, isValidPrivate, stripHexPrefix } from '@ethereumjs/util'
import BN from 'bn.js'
import log from 'loglevel'
Expand Down Expand Up @@ -129,7 +129,7 @@ export default {
return this.t('walletSettings.customKey.privateKeyCannotBeZero') // 'Private key cannot be 0'
}
const prefixed = addHexPrefix(v)
const buffer = toBuffer(prefixed)
const buffer = Buffer.from(prefixed.slice(2), 'hex')
if (!isValidPrivate(buffer)) {
return this.t('walletSettings.customKey.invalidPrivateKey') // 'Invalid private key'
}
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/DecryptMessageManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addHexPrefix, bufferToHex, stripHexPrefix } from '@ethereumjs/util'
import { addHexPrefix, bytesToHex, stripHexPrefix } from '@ethereumjs/util'
import { ethErrors } from 'eth-rpc-errors'
import EventEmitter from 'events'
import log from 'loglevel'
Expand Down Expand Up @@ -309,6 +309,6 @@ export default class DecryptMessageManager extends EventEmitter {
log.debug('Message was not hex encoded, interpreting as utf8.')
}

return bufferToHex(Buffer.from(data, 'utf8'))
return bytesToHex(Buffer.from(data, 'utf8'))
}
}
4 changes: 2 additions & 2 deletions src/controllers/MessageManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bufferToHex } from '@ethereumjs/util'
import { bytesToHex } from '@ethereumjs/util'
import { keccak256 } from '@toruslabs/metadata-helpers'
import { ethErrors } from 'eth-rpc-errors'
import EventEmitter from 'events'
Expand Down Expand Up @@ -290,5 +290,5 @@ function normalizeMessageData(data) {
return data
}
// data is unicode, convert to hex
return bufferToHex(Buffer.from(data, 'utf8'))
return bytesToHex(Buffer.from(data, 'utf8'))
}
4 changes: 2 additions & 2 deletions src/controllers/PersonalMessageManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addHexPrefix, bufferToHex, stripHexPrefix } from '@ethereumjs/util'
import { addHexPrefix, bytesToHex, stripHexPrefix } from '@ethereumjs/util'
import { ethErrors } from 'eth-rpc-errors'
import EventEmitter from 'events'
import log from 'loglevel'
Expand Down Expand Up @@ -290,6 +290,6 @@ export default class PersonalMessageManager extends EventEmitter {
log.debug('Message was not hex encoded, interpreting as utf8.', error)
}

return bufferToHex(Buffer.from(data, 'utf8'))
return bytesToHex(Buffer.from(data, 'utf8'))
}
}
2 changes: 1 addition & 1 deletion src/controllers/PreferencesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class PreferencesController extends SafeEventEmitter {
const messageToSign = await this.getMessageForSigning(address)
if (!messageToSign.startsWith('Torus Signin')) throw new Error('Cannot sign on invalid message')
const bufferedMessage = Buffer.from(messageToSign, 'utf8')
const hashedMessage = hashPersonalMessage(bufferedMessage).toString('hex')
const hashedMessage = Buffer.from(hashPersonalMessage(bufferedMessage)).toString('hex')
const signedMessage = await this.signMessage(address, hashedMessage)
response = await this.api.post(
`${config.api}/auth/verify`,
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/TorusKeyring.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bufferToHex, ecsign, stripHexPrefix } from '@ethereumjs/util'
import { ecsign, stripHexPrefix } from '@ethereumjs/util'
import { concatSig, decrypt, getEncryptionPublicKey, personalSign, signTypedData } from '@metamask/eth-sig-util'
import { Wallet } from 'ethers'
import { EventEmitter } from 'events'
Expand Down Expand Up @@ -57,13 +57,13 @@ export default class TorusKeyring extends EventEmitter {
newWallets.push(Wallet.createRandom())
}
this.wallets = [...this.wallets, ...newWallets]
const hexWallets = newWallets.map((w) => bufferToHex(w.address))
const hexWallets = newWallets.map((w) => w.address)
return hexWallets
}

// Not using
async getAccounts() {
return this.wallets.map((w) => bufferToHex(w.address))
return this.wallets.map((w) => w.address)
}

// tx is an instance of the ethereumjs-transaction class.
Expand Down
15 changes: 7 additions & 8 deletions src/controllers/transactions/TransactionController.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable require-atomic-updates */
import { Common } from '@ethereumjs/common'
import { Common, Hardfork } from '@ethereumjs/common'
import { TransactionFactory } from '@ethereumjs/tx'
import { addHexPrefix, bufferToHex, isHexString, stripHexPrefix } from '@ethereumjs/util'
import { addHexPrefix, bigIntToHex, isHexString, stripHexPrefix } from '@ethereumjs/util'
import { SafeEventEmitter } from '@toruslabs/openlogin-jrpc'
import { ethErrors } from 'eth-rpc-errors'
import { formatEther, keccak256 } from 'ethers'
Expand All @@ -20,7 +20,6 @@ import {
CONTRACT_TYPE_ERC1155,
CONTRACT_TYPE_ETH,
GAS_ESTIMATE_TYPES,
HARDFORKS,
INFURA_PROVIDER_TYPES,
OLD_ERC721_LIST,
RPC,
Expand Down Expand Up @@ -182,7 +181,7 @@ class TransactionController extends SafeEventEmitter {
// This logic below will have to be updated each time a hardfork happens
// that carries with it a new Transaction type. It is inconsequential for
// hardforks that do not include new types.
const hardfork = supportsEIP1559 ? HARDFORKS.LONDON : HARDFORKS.BERLIN
const hardfork = supportsEIP1559 ? Hardfork.Paris : Hardfork.Berlin

// type will be one of our default network names or 'rpc'. the default
// network names are sufficient configuration, simply pass the name as the
Expand Down Expand Up @@ -741,15 +740,15 @@ class TransactionController extends SafeEventEmitter {

// add r,s,v values for provider request purposes see createMetamaskMiddleware
// and JSON rpc standard for further explanation
txMeta.r = bufferToHex(signedEthTx.r)
txMeta.s = bufferToHex(signedEthTx.s)
txMeta.v = bufferToHex(signedEthTx.v)
txMeta.r = bigIntToHex(signedEthTx.r)
txMeta.s = bigIntToHex(signedEthTx.s)
txMeta.v = bigIntToHex(signedEthTx.v)

this.txStateManager.updateTransaction(txMeta, 'transactions#signTransaction: add r, s, v values')

// set state to signed
this.txStateManager.setTxStatusSigned(txMeta.id)
const rawTx = bufferToHex(signedEthTx.serialize())
const rawTx = Buffer.from(signedEthTx.serialize(), 'hex')
return rawTx
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/accountImporter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addHexPrefix, isValidPrivate, stripHexPrefix, toBuffer } from '@ethereumjs/util'
import { addHexPrefix, hexToBytes, isValidPrivate, stripHexPrefix } from '@ethereumjs/util'
import { Wallet } from 'ethers'

const accountImporter = {
Expand All @@ -15,7 +15,7 @@ const accountImporter = {
}

const prefixed = addHexPrefix(privateKey)
const buffer = toBuffer(prefixed)
const buffer = hexToBytes(prefixed)

if (!isValidPrivate(buffer)) {
throw new Error('Cannot import invalid private key.')
Expand Down
21 changes: 0 additions & 21 deletions src/utils/enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -805,27 +805,6 @@ export const TRANSACTION_ENVELOPE_TYPES = {
FEE_MARKET: '0x2',
}

/**
* Hardforks are points in the chain where logic is changed significantly
* enough where there is a fork and the new fork becomes the active chain.
* These constants are presented in chronological order starting with BERLIN
* because when we first needed to track the hardfork we had launched support
* for EIP-2718 (where transactions can have types and different shapes) and
* EIP-2930 (optional access lists), which were included in BERLIN.
*
* BERLIN - forked at block number 12,244,000, included typed transactions and
* optional access lists
* LONDON - future, upcoming fork that introduces the baseFeePerGas, an amount
* of the ETH transaction fees that will be burned instead of given to the
* miner. This change necessitated the third type of transaction envelope to
* specify maxFeePerGas and maxPriorityFeePerGas moving the fee bidding system
* to a second price auction model.
*/
export const HARDFORKS = {
BERLIN: 'berlin',
LONDON: 'london',
}

export const GAS_ESTIMATE_TYPES = {
FEE_MARKET: 'fee-market',
LEGACY: 'legacy',
Expand Down
7 changes: 0 additions & 7 deletions test/helper.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Ganache from 'ganache'
import JSDOM from 'jsdom-global'
import log from 'loglevel'
import nock from 'nock'
import fetch, { Headers, Request, Response } from 'node-fetch'

console.log('requiring helpers for tests in mocha')
const allowedHosts = ['localhost', 'mainnet.infura.io:443', 'bsc-dataseed.binance.org:443', 'polygon-mumbai.infura.io:443']
Expand Down Expand Up @@ -51,12 +50,6 @@ globalThis.log = log
// polyfills
//

// fetch
globalThis.fetch = fetch
globalThis.Response = Response
globalThis.Headers = Headers
globalThis.Request = Request

// dom
JSDOM('', {
url: 'http://localhost',
Expand Down
Loading

0 comments on commit 1e9676d

Please sign in to comment.