Skip to content

Commit

Permalink
Fix tests + update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
arch1995 committed Oct 27, 2023
1 parent ecb8030 commit 7ad7e8a
Show file tree
Hide file tree
Showing 14 changed files with 1,075 additions and 1,945 deletions.
2,394 changes: 761 additions & 1,633 deletions package-lock.json

Large diffs are not rendered by default.

68 changes: 35 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,43 +35,44 @@
"@ethereumjs/util": "^9.0.0",
"@gtm-support/vue2-gtm": "^2.0.0",
"@metamask/contract-metadata": "^2.4.0",
"@metamask/eth-json-rpc-infura": "^8.1.1",
"@metamask/eth-json-rpc-middleware": "^11.0.2",
"@metamask/eth-json-rpc-provider": "^2.1.0",
"@metamask/eth-json-rpc-infura": "^9.0.0",
"@metamask/eth-json-rpc-middleware": "^12.0.0",
"@metamask/eth-json-rpc-provider": "^2.2.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",
"@sentry/browser": "^7.75.1",
"@sentry/tracing": "^7.75.1",
"@sentry/vue": "^7.75.1",
"@toruslabs/broadcast-channel": "^9.0.1",
"@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": "^5.3.0",
"@toruslabs/openlogin-jrpc": "^5.3.0",
"@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",
"@toruslabs/openlogin-utils": "^5.3.0",
"@uniswap/default-token-list": "^11.9.0",
"@walletconnect/sign-client": "^2.10.4",
"@walletconnect/utils": "^2.10.4",
"await-semaphore": "^0.1.3",
"bignumber.js": "^9.1.2",
"bn.js": "^5.2.1",
"bowser": "^2.11.0",
"clone": "^2.1.2",
"copy-to-clipboard": "^3.3.3",
"core-js": "^3.32.2",
"core-js": "^3.33.1",
"das-sdk": "^1.9.3",
"deepmerge": "^4.3.1",
"eth-block-tracker": "^7.1.0",
"eth-json-rpc-filters": "^6.0.0",
"eth-block-tracker": "^8.1.0",
"eth-json-rpc-filters": "^6.0.1",
"eth-query": "^2.1.2",
"eth-rpc-errors": "^4.0.3",
"ethers": "^6.7.1",
"ethers": "^6.8.0",
"ethjs-query": "^0.3.8",
"fast-json-patch": "^3.1.1",
"jsonschema": "^1.4.1",
"jwt-decode": "^3.1.2",
"jwt-decode": "^4.0.0",
"lodash": "^4.17.21",
"loglevel": "^1.8.1",
"pify": "^5.0.0",
Expand All @@ -97,14 +98,14 @@
"workbox-strategies": "^7.0.0"
},
"devDependencies": {
"@babel/core": "^7.22.17",
"@babel/core": "^7.23.2",
"@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.15",
"@babel/preset-env": "^7.23.2",
"@babel/register": "^7.22.15",
"@sentry/cli": "^2.20.7",
"@sentry/cli": "^2.21.2",
"@vue/cli-plugin-babel": "^5.0.8",
"@vue/cli-plugin-eslint": "^5.0.8",
"@vue/cli-plugin-pwa": "^5.0.8",
Expand All @@ -115,48 +116,49 @@
"cross-env": "^7.0.3",
"dotenv": "^16.3.1",
"empty-module": "0.0.2",
"eslint": "^8.49.0",
"eslint": "^8.52.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.1",
"eslint-plugin-n": "^16.1.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-n": "^16.2.0",
"eslint-plugin-only-error": "^1.0.2",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-switch-case": "^1.1.2",
"eslint-plugin-unicorn": "^48.0.1",
"eslint-plugin-vue": "^9.17.0",
"eslint-plugin-vue-scoped-css": "^2.5.0",
"eslint-plugin-vue": "^9.18.1",
"eslint-plugin-vue-scoped-css": "^2.5.1",
"express": "^4.18.2",
"fibers": "^5.0.3",
"ganache": "^7.9.1",
"husky": "^8.0.3",
"jsdom": "^22.1.0",
"jsdom-global": "^3.0.2",
"lint-staged": "^14.0.1",
"lint-staged": "^15.0.2",
"lodash-es": "^4.17.21",
"luxon": "^3.4.3",
"mocha": "^10.2.0",
"nock": "13.3.3",
"nock": "13.3.6",
"nyc": "^15.1.0",
"prettier": "^3.0.3",
"process": "^0.11.10",
"puppeteer": "^21.2.0",
"sass": "~1.32.13",
"puppeteer": "^21.4.1",
"sass": "~1.69.5",
"sass-loader": "^13.3.2",
"sinon": "^15.2.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.2",
"undici": "^5.27.0",
"url": "^0.11.3",
"vue-cli-plugin-vuetify": "^2.5.8",
"vue-cli-plugin-webpack-bundle-analyzer": "~4.0.0",
"vue-template-compiler": "^2.7.14",
"vue-template-compiler": "^2.7.15",
"vuetify-loader": "^1.9.2",
"worker-loader": "^3.0.8"
},
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/TorusKeyring.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ecsign, stripHexPrefix } from '@ethereumjs/util'
import { bigIntToBytes, 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 @@ -85,7 +85,7 @@ export default class TorusKeyring extends EventEmitter {
const privKey = this.getBufferPrivateKey(wallet.privateKey)

const messageSig = ecsign(Buffer.from(message, 'hex'), privKey)
const rawMessageSig = concatSig(messageSig.v, messageSig.r, messageSig.s)
const rawMessageSig = concatSig(Buffer.from(bigIntToBytes(messageSig.v)), Buffer.from(messageSig.r), Buffer.from(messageSig.s))
return rawMessageSig
}

Expand Down
2 changes: 1 addition & 1 deletion src/controllers/gas/GasFeeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ class GasFeeController {

try {
if (isEIP1559Compatible) {
// TODO: kovan is not working due to a bug in metamask api
const estimates = await this.fetchGasEstimates(this.EIP1559APIEndpoint.replace('<chain_id>', `${chainId}`))
const { suggestedMaxPriorityFeePerGas, suggestedMaxFeePerGas } = estimates.medium
const estimatedGasFeeTimeBounds = this.getTimeEstimate(suggestedMaxPriorityFeePerGas, suggestedMaxFeePerGas)
Expand All @@ -160,6 +159,7 @@ class GasFeeController {
}
} catch {
try {
log.log('fetching gas fee estimates from dqwd API')
const estimates = await this.fetchEthGasPriceEstimate(this.ethQuery)
newState = {
gasFeeEstimates: estimates,
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/transactions/TransactionController.js
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ class TransactionController extends SafeEventEmitter {

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

Expand Down
118 changes: 62 additions & 56 deletions test/unit/controllers/assets-controller-test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* eslint-disable */
import { toChecksumAddress } from '@ethereumjs/util'
import assert from 'assert'
import nock from 'nock'
import log from 'loglevel'
import { createSandbox } from 'sinon'
import { MockAgent, setGlobalDispatcher } from 'undici'

import config from '../../../src/config'
import * as utils from '../../../src/utils/utils'
import AssetsContractController from '../../../src/controllers/AssetsContractController'
import AssetsController from '../../../src/controllers/AssetsController'
import NetworkController from '../../../src/controllers/network/NetworkController'
import PreferencesController from '../../../src/controllers/PreferencesController'
import { toChecksumAddress } from '@ethereumjs/util'
import * as utils from '../../../src/utils/utils'

const noop = () => {}
const KUDOSADDRESS = '0x2aea4add166ebf38b63d09a75de1a7b94aa24163'
Expand Down Expand Up @@ -70,8 +70,13 @@ describe('AssetsController', () => {
validateImageUrlStub = sandbox.stub(utils, 'validateImageUrl').returns(true)
}

nock(COVALENT_API)
.get(`/covalent?url=${encodeURIComponent('https://api.covalenthq.com/v1/1/tokens/foo/nft_metadata/1/')}`)
const mockAgent = new MockAgent()
setGlobalDispatcher(mockAgent)
const mockPool = mockAgent.get(COVALENT_API)

mockPool
.intercept({ path: `/covalent?url=${encodeURIComponent('https://api.covalenthq.com/v1/1/tokens/foo/nft_metadata/1/')}`, method: 'get' })
.defaultReplyHeaders({ 'content-type': 'application/json' })
.reply(200, {
data: {
data: {
Expand Down Expand Up @@ -115,8 +120,9 @@ describe('AssetsController', () => {
})
.persist(true)

nock(COVALENT_API)
.get(`/covalent?url=${encodeURIComponent('https://api.covalenthq.com/v1/1/tokens/foo/nft_metadata/2/')}`)
mockPool
.intercept({ path: `/covalent?url=${encodeURIComponent('https://api.covalenthq.com/v1/1/tokens/foo/nft_metadata/2/')}`, method: 'get' })
.defaultReplyHeaders({ 'content-type': 'application/json' })
.reply(200, {
data: {
data: {
Expand Down Expand Up @@ -160,8 +166,9 @@ describe('AssetsController', () => {
})
.persist(true)

nock(COVALENT_API)
.get(`/covalent?url=${encodeURIComponent('https://api.covalenthq.com/v1/1/tokens/fou/nft_metadata/1/')}`)
mockPool
.intercept({ path: `/covalent?url=${encodeURIComponent('https://api.covalenthq.com/v1/1/tokens/fou/nft_metadata/1/')}`, method: 'get' })
.defaultReplyHeaders({ 'content-type': 'application/json' })
.reply(200, {
data: {
data: {
Expand Down Expand Up @@ -205,8 +212,12 @@ describe('AssetsController', () => {
})
.persist(true)

nock(COVALENT_API)
.get(`/covalent?url=${encodeURIComponent(`https://api.covalenthq.com/v1/1/tokens/${KUDOSADDRESS}/nft_metadata/1203/`)}`)
mockPool
.intercept({
path: `/covalent?url=${encodeURIComponent(`https://api.covalenthq.com/v1/1/tokens/${KUDOSADDRESS}/nft_metadata/1203/`)}`,
method: 'get',
})
.defaultReplyHeaders({ 'content-type': 'application/json' })
.reply(200, {
data: {
data: {
Expand Down Expand Up @@ -248,9 +259,14 @@ describe('AssetsController', () => {
error_code: null,
},
})
.persist(true)
nock(COVALENT_API)
.get(`/covalent?url=${encodeURIComponent(`https://api.covalenthq.com/v1/1/tokens/${KUDOSADDRESS}/nft_metadata/1/`)}`)
.persist()

mockPool
.intercept({
path: `/covalent?url=${encodeURIComponent(`https://api.covalenthq.com/v1/1/tokens/${KUDOSADDRESS}/nft_metadata/1/`)}`,
method: 'get',
})
.defaultReplyHeaders({ 'content-type': 'application/json' })
.reply(200, {
data: {
data: {
Expand Down Expand Up @@ -292,30 +308,45 @@ describe('AssetsController', () => {
error_code: null,
},
})
.persist(true)
nock('https://ipfs.gitcoin.co:443')
.get('/api/v0/cat/QmPmt6EAaioN78ECnW5oCL8v2YvVSpoBjLCjrXhhsAvoov')
.persist()

const ipfsMockPool = mockAgent.get('https://ipfs.gitcoin.co:443')

ipfsMockPool
.intercept({ path: '/api/v0/cat/QmPmt6EAaioN78ECnW5oCL8v2YvVSpoBjLCjrXhhsAvoov', method: 'get' })
.defaultReplyHeaders({ 'content-type': 'application/json' })
.reply(200, {
image: 'Kudos Image',
name: 'Kudos Name',
})
.persist(true)
nock(COVALENT_API)
.get(
`/covalent?url=${encodeURIComponent(
.persist()

mockPool
.intercept({
path: `/covalent?url=${encodeURIComponent(
'https://api.covalenthq.com/v1/1/tokens/0x6EbeAf8e8E946F0716E6533A6f2cefc83f60e8Ab/nft_metadata/798958393/'
)}`
)
)}`,
method: 'get',
})
.replyWithError(new TypeError('failed to fetch'))
.persist(true)

nock(COVALENT_API)
.get(`/covalent?url=${encodeURIComponent('https://api.covalenthq.com/v1/1/tokens/0x6EbeAf8e8E946F0716E6533A6f2cefc83f60e8Ab/nft_metadata/1/')}`)
mockPool
.intercept({
path: `/covalent?url=${encodeURIComponent(
'https://api.covalenthq.com/v1/1/tokens/0x6EbeAf8e8E946F0716E6533A6f2cefc83f60e8Ab/nft_metadata/1/'
)}`,
method: 'get',
})
.replyWithError(new TypeError('failed to fetch'))
.persist(true)

nock(COVALENT_API)
.get(`/covalent?url=${encodeURIComponent('https://api.covalenthq.com/v1/1/tokens/${KUDOSADDRESS}/nft_metadata/1/')}`)
mockPool
.intercept({
path: `/covalent?url=${encodeURIComponent(`https://api.covalenthq.com/v1/1/tokens/${KUDOSADDRESS}/nft_metadata/1/`)}`,
method: 'get',
})
.defaultReplyHeaders({ 'content-type': 'application/json' })
.reply(200, {
data: {
data: {
Expand Down Expand Up @@ -357,12 +388,11 @@ describe('AssetsController', () => {
error_code: null,
},
})
.persist(true)
.persist()
})

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

it('should set default state', () => {
Expand Down Expand Up @@ -502,30 +532,6 @@ describe('AssetsController', () => {
})
})

// it('should add collectible and get collectible contract information from contract', async () => {
// sandbox.stub(assetsController, 'getCollectibleContractInformationFromApi').returns(undefined)
// sandbox.stub(assetsController, 'getCollectibleInformationFromApi').returns(undefined)
// nock.enableNetConnect()
// await assetsController.addCollectible(KUDOSADDRESS, 1203)
// assert.deepStrictEqual(assetsController.state.collectibles[0], {
// address: '0x2aea4add166ebf38b63d09a75de1a7b94aa24163',
// description: undefined,
// image: 'Kudos Image',
// name: 'Kudos Name',
// tokenId: 1203
// })
// assert.deepStrictEqual(assetsController.state.collectibleContracts[0], {
// address: '0x2aea4add166ebf38b63d09a75de1a7b94aa24163',
// description: undefined,
// logo: undefined,
// name: 'KudosToken',
// symbol: 'KDO',
// totalSupply: undefined
// })
// nock.disableNetConnect()
// nock.enableNetConnect(host => host.includes('localhost') || host.includes('mainnet.infura.io:443'))
// })

it('should add collectible by selected address', async () => {
const firstAddress = TEST_ADDRESS_2
const secondAddress = TEST_ADDRESS_3
Expand Down Expand Up @@ -594,7 +600,7 @@ describe('AssetsController', () => {
tokenId: '1203',
standard: 'erc721',
tokenBalance: 1,
collectibleIndex: checkSummedAddress + '_1203',
collectibleIndex: `${checkSummedAddress}_1203`,
video: undefined,
},
])
Expand Down Expand Up @@ -654,7 +660,7 @@ describe('AssetsController', () => {
it('should add replace contract logo and asset image url with placeholder url if fallback url is not given', async () => {
validateImageUrlStub.restore()
sandbox.stub(utils, 'validateImageUrl').throws()
const stubbedCollectibleInfo = sandbox.stub(assetsController, 'getCollectibleInfo').returns({})
sandbox.stub(assetsController, 'getCollectibleInfo').returns({})
await assetsController.addCollectibles([
{
contractAddress: 'foo',
Expand Down
Loading

0 comments on commit 7ad7e8a

Please sign in to comment.