Skip to content

Commit

Permalink
Merge pull request #406 from EdgeApp/matthew/getTokenId
Browse files Browse the repository at this point in the history
Fix tests
  • Loading branch information
thehobbit85 authored May 12, 2022
2 parents ca85de6 + b0e7567 commit 70c1d84
Show file tree
Hide file tree
Showing 13 changed files with 524 additions and 341 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"uuid": "3.3.3"
},
"dependencies": {
"@binance-chain/javascript-sdk": "^2.14.4",
"@binance-chain/javascript-sdk": "^4.2.0",
"@ethereumjs/common": "^2.4.0",
"@ethereumjs/tx": "^3.3.0",
"@fioprotocol/fiosdk": "^1.5.0",
Expand Down
4 changes: 2 additions & 2 deletions src/binance/bnbEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
// @flow

import BnbApiClient from '@binance-chain/javascript-sdk'
import { BncClient } from '@binance-chain/javascript-sdk'
import { bns } from 'biggystring'
import {
type EdgeSpendInfo,
Expand Down Expand Up @@ -517,7 +517,7 @@ export class BinanceEngine extends CurrencyEngine {
async signTx(edgeTransaction: EdgeTransaction): Promise<EdgeTransaction> {
const otherParams = getOtherParams(edgeTransaction)

const bnbClient = new BnbApiClient(
const bnbClient = new BncClient(
currencyInfo.defaultSettings.otherSettings.binanceApiServers[0]
)
bnbClient.chooseNetwork('mainnet')
Expand Down
25 changes: 14 additions & 11 deletions src/binance/bnbPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
// @flow

import BnbApiClient from '@binance-chain/javascript-sdk'
import { crypto } from '@binance-chain/javascript-sdk'
import { bns } from 'biggystring'
import { entropyToMnemonic } from 'bip39'
import { Buffer } from 'buffer'
Expand All @@ -24,7 +24,12 @@ import { getDenomInfo } from '../common/utils.js'
import { BinanceEngine } from './bnbEngine.js'
import { currencyInfo } from './bnbInfo.js'

const bnbCrypto = BnbApiClient.crypto
const {
checkAddress,
getAddressFromPrivateKey,
getPrivateKeyFromMnemonic,
validateMnemonic
} = crypto

export class BinancePlugin extends CurrencyPlugin {
constructor(io: EdgeIo) {
Expand All @@ -33,9 +38,9 @@ export class BinancePlugin extends CurrencyPlugin {

// will actually use MNEMONIC version of private key
async importPrivateKey(mnemonic: string): Promise<Object> {
const isValid = bnbCrypto.validateMnemonic(mnemonic)
const isValid = validateMnemonic(mnemonic)
if (!isValid) throw new Error('Invalid BNB mnemonic')
const binanceKey = bnbCrypto.getPrivateKeyFromMnemonic(mnemonic)
const binanceKey = getPrivateKeyFromMnemonic(mnemonic)

return { binanceMnemonic: mnemonic, binanceKey }
}
Expand All @@ -46,7 +51,7 @@ export class BinancePlugin extends CurrencyPlugin {
if (type === 'binance') {
const entropy = Buffer.from(this.io.random(32)).toString('hex')
const binanceMnemonic = entropyToMnemonic(entropy)
const binanceKey = bnbCrypto.getPrivateKeyFromMnemonic(binanceMnemonic)
const binanceKey = getPrivateKeyFromMnemonic(binanceMnemonic)

return { binanceMnemonic, binanceKey }
} else {
Expand All @@ -60,11 +65,9 @@ export class BinancePlugin extends CurrencyPlugin {
let publicKey = ''
let privateKey = walletInfo.keys.binanceKey
if (typeof privateKey !== 'string') {
privateKey = bnbCrypto.getPrivateKeyFromMnemonic(
walletInfo.keys.binanceMnemonic
)
privateKey = getPrivateKeyFromMnemonic(walletInfo.keys.binanceMnemonic)
}
publicKey = bnbCrypto.getAddressFromPrivateKey(privateKey, 'bnb')
publicKey = getAddressFromPrivateKey(privateKey, 'bnb')
return { publicKey }
} else {
throw new Error('InvalidWalletType')
Expand All @@ -90,7 +93,7 @@ export class BinancePlugin extends CurrencyPlugin {
address = edgeParsedUri.publicAddress
}

const valid = bnbCrypto.checkAddress(address || '', 'bnb')
const valid = checkAddress(address || '', 'bnb')
if (!valid) {
throw new Error('InvalidPublicAddressError')
}
Expand All @@ -104,7 +107,7 @@ export class BinancePlugin extends CurrencyPlugin {
customTokens?: EdgeMetaToken[]
): Promise<string> {
const { publicAddress, nativeAmount, currencyCode } = obj
const valid = bnbCrypto.checkAddress(publicAddress, 'bnb')
const valid = checkAddress(publicAddress, 'bnb')
if (!valid) {
throw new Error('InvalidPublicAddressError')
}
Expand Down
2 changes: 1 addition & 1 deletion src/fio/fioEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ export class FioEngine extends CurrencyEngine {
this.fioSdkPreparedTrx = new FIOSDK(
this.walletInfo.keys.fioKey,
this.walletInfo.keys.publicKey,
'',
baseUrl,
this.fetchCors,
undefined,
this.tpid,
Expand Down
9 changes: 5 additions & 4 deletions src/fio/fioInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ const defaultSettings: any = {
apiUrls: [
'https://fio.eu.eosamsterdam.net/v1/',
'https://fio.eosdac.io/v1/',
'https://fio.eosphere.io/v1/',
'https://fio.eosrio.io/v1/',
'https://fio.acherontrading.com/v1/',
'https://fio.eos.barcelona/v1/',
'https://api.fio.eosdetroit.io/v1/',
'https://api.fio.alohaeos.com/v1/',
'https://fio.greymass.com/v1/',
'https://fio.eosargentina.io/v1/',
'https://fio.cryptolions.io/v1/',
'https://api.fio.currencyhub.io/v1/',
'https://fio.eoscannon.io/v1/',
'https://fio.eosdublin.io/v1/',
'https://api.fiosweden.org/v1/'
'https://fio-za.eostribe.io/v1/',
'https://fioapi.ledgerwise.io/v1/',
'https://api.fio.greeneosio.com/v1/',
'https://api.fio.services/v1/',
'https://fio.eosusa.news/v1/'
],
historyNodeUrls: [
'https://fio.greymass.com/v1/',
Expand Down
4 changes: 3 additions & 1 deletion src/fio/fioPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { CurrencyPlugin } from '../common/plugin.js'
import {
asyncWaterfall,
getDenomInfo,
pickRandom,
safeErrorMessage,
shuffleArray
} from '../common/utils'
Expand Down Expand Up @@ -144,7 +145,8 @@ export function makeFioPlugin(opts: EdgeCorePluginOptions): EdgeCurrencyPlugin {
const { fetchCors = io.fetch } = io
const { tpid = 'finance@edge', fioRegApiToken = FIO_REG_SITE_API_KEY } =
initOptions
const connection = new FIOSDK('', '', '', fetchCors, undefined, tpid)
const baseUrl = pickRandom(currencyInfo.defaultSettings.apiUrls, 1)[0]
const connection = new FIOSDK('', '', baseUrl, fetchCors, undefined, tpid)

let toolsPromise: Promise<FioPlugin>
function makeCurrencyTools(): Promise<FioPlugin> {
Expand Down
2 changes: 1 addition & 1 deletion src/xrp/xrpEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export class XrpEngine extends CurrencyEngine {

async killEngine() {
await super.killEngine()
await this.xrpPlugin.disconnectApi(this.walletId)
await this.multicastServers('disconnect')
}

async resyncBlockchain(): Promise<void> {
Expand Down
34 changes: 19 additions & 15 deletions test/engine/engine.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@ import fetch from 'node-fetch'
import { CurrencyEngine } from '../../src/common/engine.js'
import { CurrencyPlugin } from '../../src/common/plugin.js'
import { WalletLocalData } from '../../src/common/types.js'
import { currencyInfo } from '../../src/ethereum/info/ethInfo.js'
import edgeCorePlugins from '../../src/index.js'
import { fakeLog } from '../fakeLog.js'
import { engineTestTxs } from './engine.txs.js'
import fixtures from './fixtures.js'

const fakeIo = makeFakeIo()
const opts: EdgeCorePluginOptions = {
initOptions: {},
io: { ...fakeIo, fetch },
log: fakeLog,
nativeIo: {},
pluginDisklet: fakeIo.disklet
}

for (const fixture of fixtures) {
let tools: EdgeCurrencyTools
let engine: EdgeCurrencyEngine
Expand All @@ -33,14 +41,8 @@ for (const fixture of fixtures) {
const WALLET_TYPE = fixture.WALLET_TYPE
// const TX_AMOUNT = fixture['TX_AMOUNT']

const fakeIo = makeFakeIo()
const opts: EdgeCorePluginOptions = {
initOptions: {},
io: { ...fakeIo, fetch, random: size => fixture.key },
log: fakeLog,
nativeIo: {},
pluginDisklet: fakeIo.disklet
}
opts.io = { ...opts.io, random: size => fixture.key }

const factory = edgeCorePlugins[fixture.pluginId]
const plugin: EdgeCurrencyPlugin = factory(opts)

Expand Down Expand Up @@ -151,6 +153,10 @@ for (const fixture of fixtures) {

describe('Start engine', function () {
it('Get BlockHeight', function (done) {
if (!engine) throw new Error('ErrorNoEngine')
engine.startEngine().catch(e => {
console.log('startEngine error', e, e.message)
})
this.timeout(100000)
emitter.once('onBlockHeightChange', height => {
const thirdPartyHeight = 1578127
Expand All @@ -167,10 +173,6 @@ for (const fixture of fixtures) {
assert(getHeight > 0)
done() // Can be "done" since the promise resolves before the event fires but just be on the safe side
})
if (!engine) throw new Error('ErrorNoEngine')
engine.startEngine().catch(e => {
console.log('startEngine error', e, e.message)
})
})
})

Expand Down Expand Up @@ -206,8 +208,10 @@ for (const fixture of fixtures) {
})
}

const fakeIo = makeFakeIo()
const plugin = new CurrencyPlugin(fakeIo, 'fakePlugin', currencyInfo)
// Get the currency info
const factory = edgeCorePlugins.ethereum
const ethPlugin = factory(opts)
const plugin = new CurrencyPlugin(fakeIo, 'fakePlugin', ethPlugin.currencyInfo)
const emitter = new EventEmitter()
const callbacks: EdgeCurrencyEngineCallbacks = {
onAddressesChecked(progressRatio) {
Expand Down
35 changes: 21 additions & 14 deletions test/engine/feeProvider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from '../../src/ethereum/fees/feeProviders'
import { currencyInfo as ethCurrencyInfo } from '../../src/ethereum/info/ethInfo.js'
import { currencyInfo as ftmCurrencyInfo } from '../../src/ethereum/info/ftmInfo.js'
import { fakeLog } from '../fakeLog.js'

// TODO: Loop for all plugins
describe(`FTM Network Fees`, function () {
Expand All @@ -25,25 +26,31 @@ describe(`FTM Network Fees`, function () {

it('EvmGasStation Fees', async function () {
// $FlowFixMe
const fees = await fetchFeesFromEvmGasStation(fetch, ethCurrencyInfo, {
gasStationApiKey: [
'EG16P5AF5FNJ3XR8ICP3UAYHT68G53TAKU',
'63YA67UBCWPG6SEREC9GNRRR31SDPGSQY9',
'D925MHYVPJH3ZBSJKES5EFC876FFMW3ZHX'
]
})
const fees = await fetchFeesFromEvmGasStation(
fetch,
ethCurrencyInfo,
{
gasStationApiKey: 'D925MHYVPJH3ZBSJKES5EFC876FFMW3ZHX'
},
fakeLog
)
validateGasPrices(fees)
})

it('EvmScan Fees', async function () {
// $FlowFixMe
const fees = await fetchFeesFromEvmScan(fetch, ftmCurrencyInfo, {
evmScanApiKey: [
'EG16P5AF5FNJ3XR8ICP3UAYHT68G53TAKU',
'63YA67UBCWPG6SEREC9GNRRR31SDPGSQY9',
'D925MHYVPJH3ZBSJKES5EFC876FFMW3ZHX'
]
})
const fees = await fetchFeesFromEvmScan(
fetch,
ftmCurrencyInfo,
{
evmScanApiKey: [
'EG16P5AF5FNJ3XR8ICP3UAYHT68G53TAKU',
'63YA67UBCWPG6SEREC9GNRRR31SDPGSQY9',
'D925MHYVPJH3ZBSJKES5EFC876FFMW3ZHX'
]
},
fakeLog
)
validateGasPrices(fees)
})
})
Expand Down
1 change: 1 addition & 0 deletions test/eos/activation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ describe(`EOS activation`, function () {
})

it.skip('getSupportedCurrencies', async function () {
this.timeout(5000)
if (plugin.otherMethods) {
const result =
await plugin.otherMethods.getActivationSupportedCurrencies()
Expand Down
2 changes: 0 additions & 2 deletions test/plugin/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -923,5 +923,3 @@ export default [
}
}
]
// 302e020100300506032b657004220420ffd3dadf65d2fb2889f3a22de0aab48691ee8a3d3e0ea8a70c2b48482a08bb68
// 302e020100300506032b657004220420906327db5cbe7ece6bf2478b907d668b99f7241c750413e4712237ee6fc68523
3 changes: 2 additions & 1 deletion test/plugin/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
makeFakeIo
} from 'edge-core-js'
import { before, describe, it } from 'mocha'
import fetch from 'node-fetch'

import edgeCorePlugins from '../../src/index.js'
import { expectRejection } from '../expectRejection.js'
Expand All @@ -28,7 +29,7 @@ for (const fixture of fixtures) {
const fakeIo = makeFakeIo()
const opts: EdgeCorePluginOptions = {
initOptions: {},
io: { ...fakeIo, random: size => fixture.key },
io: { ...fakeIo, fetch, random: size => fixture.key },
log: fakeLog,
nativeIo: {},
pluginDisklet: fakeIo.disklet
Expand Down
Loading

0 comments on commit 70c1d84

Please sign in to comment.