Skip to content

Commit

Permalink
typecheck tests, refactor tests, add quantity to orders
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderatallah committed Aug 19, 2019
1 parent 8c69fad commit d89d703
Show file tree
Hide file tree
Showing 13 changed files with 310 additions and 238 deletions.
2 changes: 1 addition & 1 deletion lib/seaport.d.ts
Expand Up @@ -191,7 +191,7 @@ export declare class OpenSeaPort {
}): Promise<Order>;
/**
* Create a sell order to auction an asset.
* Will throw a 'You do not own this asset' error if the maker doesn't have the asset.
* Will throw a 'You do not own enough of this asset' error if the maker doesn't have the asset or not enough of it to sell the specific `quantity`.
* If the user hasn't approved access to the token yet, this will emit `ApproveAllAssets` (or `ApproveAsset` if the contract doesn't support approve-all) before asking for approval.
* @param param0 __namedParameters Object
* @param tokenId DEPRECATED: Token ID. Use `asset` instead.
Expand Down
17 changes: 12 additions & 5 deletions lib/seaport.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/seaport.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/types.d.ts
Expand Up @@ -176,6 +176,7 @@ export interface Asset {
tokenAddress: string;
version?: TokenStandardVersion;
name?: string;
decimals?: number;
}
/**
* Annotated asset contract with OpenSea metadata
Expand Down Expand Up @@ -288,6 +289,7 @@ export interface UnhashedOrder extends WyvernOrder {
side: OrderSide;
saleKind: SaleKind;
howToCall: HowToCall;
quantity: BigNumber;
makerReferrerFee: BigNumber;
waitingForBestCounterOrder: boolean;
metadata: {
Expand Down
1 change: 1 addition & 0 deletions lib/utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/utils.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -8,7 +8,7 @@
],
"main": "lib/index.js",
"scripts": {
"test": "./node_modules/.bin/mocha test/*.ts --require ts-node/register --timeout 15000",
"test": "./node_modules/.bin/mocha test/**/*.ts --require ts-node/register --timeout 15000",
"lint": "tslint --project . 'src/**/*.ts' --fix",
"build": "npm run lint && tsc",
"docs": "npm run docsHtml",
Expand Down
11 changes: 9 additions & 2 deletions src/seaport.ts
Expand Up @@ -1832,7 +1832,8 @@ export class OpenSeaPort {

accountAddress = validateAndFormatWalletAddress(this.web3, accountAddress)
const schema = this._getSchema(schemaName)
const wyAsset = getWyvernAsset(schema, asset, new BigNumber(quantity))
const quantityBN = WyvernProtocol.toBaseUnitAmount(makeBigNumber(quantity), asset.decimals || 0)
const wyAsset = getWyvernAsset(schema, asset, quantityBN)

let makerRelayerFee
let takerRelayerFee
Expand Down Expand Up @@ -1867,6 +1868,7 @@ export class OpenSeaPort {
exchange: WyvernProtocol.getExchangeContractAddress(this._networkName),
maker: accountAddress,
taker,
quantity: quantityBN,
makerRelayerFee,
takerRelayerFee,
makerProtocolFee: makeBigNumber(0),
Expand Down Expand Up @@ -1913,6 +1915,7 @@ export class OpenSeaPort {

accountAddress = validateAndFormatWalletAddress(this.web3, accountAddress)
const schema = this._getSchema(schemaName)
const quantityBN = WyvernProtocol.toBaseUnitAmount(makeBigNumber(quantity), asset.decimals || 0)
const wyAsset = getWyvernAsset(schema, asset, new BigNumber(quantity))
const isPrivate = buyerAddress != NULL_ADDRESS
const { totalSellerFeeBPS,
Expand All @@ -1925,7 +1928,7 @@ export class OpenSeaPort {
? SaleKind.DutchAuction
: SaleKind.FixedPrice

const { basePrice, extra } = await this._getPriceParameters(paymentTokenAddress, expirationTime, startAmount, endAmount, waitForHighestBid)
const { basePrice, extra, } = await this._getPriceParameters(paymentTokenAddress, expirationTime, startAmount, endAmount, waitForHighestBid)
const times = this._getTimeParameters(expirationTime, waitForHighestBid)
// Use buyer as the maker when it's an English auction, so Wyvern sets prices correctly
const feeRecipient = waitForHighestBid
Expand All @@ -1945,6 +1948,7 @@ export class OpenSeaPort {
exchange: WyvernProtocol.getExchangeContractAddress(this._networkName),
maker: accountAddress,
taker: buyerAddress,
quantity: quantityBN,
makerRelayerFee,
takerRelayerFee,
makerProtocolFee: makeBigNumber(0),
Expand Down Expand Up @@ -2022,6 +2026,7 @@ export class OpenSeaPort {
exchange: WyvernProtocol.getExchangeContractAddress(this._networkName),
maker: accountAddress,
taker: NULL_ADDRESS,
quantity: makeBigNumber(1),
makerRelayerFee,
takerRelayerFee,
makerProtocolFee: makeBigNumber(0),
Expand Down Expand Up @@ -2102,6 +2107,7 @@ export class OpenSeaPort {
exchange: WyvernProtocol.getExchangeContractAddress(this._networkName),
maker: accountAddress,
taker: buyerAddress,
quantity: makeBigNumber(1),
makerRelayerFee: makeBigNumber(totalSellerFeeBPS),
takerRelayerFee: makeBigNumber(totalBuyerFeeBPS),
makerProtocolFee: makeBigNumber(0),
Expand Down Expand Up @@ -2176,6 +2182,7 @@ export class OpenSeaPort {
exchange: order.exchange,
maker: accountAddress,
taker: order.maker,
quantity: order.quantity,
makerRelayerFee: order.makerRelayerFee,
takerRelayerFee: order.takerRelayerFee,
makerProtocolFee: order.makerProtocolFee,
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Expand Up @@ -229,6 +229,8 @@ export interface Asset {
version?: TokenStandardVersion,
// Optional for ENS names
name?: string,
// Optional for fungible items
decimals?: number
}

/**
Expand Down
14 changes: 7 additions & 7 deletions test/api.ts
Expand Up @@ -11,8 +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, MAINNET_API_KEY, CK_ADDRESS } from './constants'
import { getOrderHash } from '../src/utils';
import { mainApi, rinkebyApi, apiToTest, ALEX_ADDRESS, CK_RINKEBY_TOKEN_ID, CK_RINKEBY_ADDRESS, CK_RINKEBY_SELLER_FEE, RINKEBY_API_KEY, CK_ADDRESS } from './constants'
import { getOrderHash } from '../src/utils'

suite('api', () => {

Expand All @@ -35,20 +35,20 @@ suite('api', () => {
})

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

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

await logPromise
Expand Down

0 comments on commit d89d703

Please sign in to comment.