Skip to content

Commit

Permalink
split up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderatallah committed Aug 19, 2019
1 parent 0071d8b commit 8c69fad
Show file tree
Hide file tree
Showing 4 changed files with 386 additions and 309 deletions.
37 changes: 36 additions & 1 deletion test/api.ts
Expand Up @@ -11,7 +11,8 @@ import {
import { ORDERBOOK_VERSION } from '../src/api'
import { Order, OrderSide, OrderJSON } from '../src/types'
import { orderToJSON } from '../src'
import { mainApi, rinkebyApi, apiToTest, ALEX_ADDRESS, CK_RINKEBY_TOKEN_ID, CK_RINKEBY_ADDRESS, CK_RINKEBY_SELLER_FEE } from './constants'
import { mainApi, rinkebyApi, apiToTest, ALEX_ADDRESS, CK_RINKEBY_TOKEN_ID, CK_RINKEBY_ADDRESS, CK_RINKEBY_SELLER_FEE, MAINNET_API_KEY, CK_ADDRESS } from './constants'
import { getOrderHash } from '../src/utils';

suite('api', () => {

Expand All @@ -33,6 +34,40 @@ suite('api', () => {
assert.isNotEmpty(bundle.sellOrders)
})

test('Includes API key in token request', async () => {
const oldLogger = apiToTest.logger

const logPromise = new Promise((resolve, reject) => {
apiToTest.logger = log => {
try {
assert.include(log, `"X-API-KEY":"${MAINNET_API_KEY}"`)
resolve()
} catch (e) {
reject(e)
} finally {
apiToTest.logger = oldLogger
}
}
apiToTest.getPaymentTokens({ symbol: "MANA" })
})

await logPromise
})

test('An API asset\'s order has correct hash', async () => {
const asset = await mainApi.getAsset(CK_ADDRESS, 1)
assert.isNotNull(asset.orders)
if (!asset.orders) {
return
}
const order = asset.orders[0]
assert.isNotNull(order)
if (!order) {
return
}
assert.equal(order.hash, getOrderHash(order))
})

// Skip these tests, since many are redundant with other tests
skip(() => {

Expand Down
69 changes: 69 additions & 0 deletions test/seaport/misc.ts
@@ -0,0 +1,69 @@
import {
assert,
} from 'chai'

import { before } from 'mocha'

import {
suite,
test,
skip,
} from 'mocha-typescript'

import { OpenSeaPort } from '../../src/index'
import * as Web3 from 'web3'
import { Network } from '../../src/types'
import { MAX_UINT_256, getCurrentGasPrice } from '../../src/utils'
import { ALEX_ADDRESS, MAINNET_API_KEY} from '../constants'

const provider = new Web3.providers.HttpProvider('https://mainnet.infura.io')

const client = new OpenSeaPort(provider, {
networkName: Network.Main,
apiKey: MAINNET_API_KEY
}, line => console.info(`MAINNET: ${line}`))

suite('seaport: misc', () => {

test('Instance has public methods', () => {
assert.equal(typeof client.getCurrentPrice, 'function')
assert.equal(typeof client.wrapEth, 'function')
})

test('Instance exposes API methods', () => {
assert.equal(typeof client.api.getOrder, 'function')
assert.equal(typeof client.api.getOrders, 'function')
assert.equal(typeof client.api.postOrder, 'function')
})

test('Instance exposes some underscored methods', () => {
assert.equal(typeof client._initializeProxy, 'function')
assert.equal(typeof client._getProxy, 'function')
})

test('Uses a gas price above the mean', async () => {
const gasPrice = await client._computeGasPrice()
const meanGasPrice = await getCurrentGasPrice(client.web3)
assert.isAbove(meanGasPrice.toNumber(), 0)
assert.isAbove(gasPrice.toNumber(), meanGasPrice.toNumber())
})

test('Fetches proxy for an account', async () => {
const accountAddress = ALEX_ADDRESS
const proxy = await client._getProxy(accountAddress)
assert.isNotNull(proxy)
})

test('Fetches positive token balance for an account', async () => {
const accountAddress = ALEX_ADDRESS
const balance = await client.getTokenBalance({ accountAddress })
assert.isAbove(balance.toNumber(), 0)
})

test('Accounts have maximum token balance approved', async () => {
const accountAddress = ALEX_ADDRESS
const approved = await client._getApprovedTokenCount({ accountAddress })
assert.equal(approved.toString(), MAX_UINT_256.toString())
})

})

0 comments on commit 8c69fad

Please sign in to comment.