From 94142335aee12eda7cab1357f318e8e890a47a7e Mon Sep 17 00:00:00 2001 From: Justin Chen Date: Tue, 24 Jul 2018 00:35:40 -0700 Subject: [PATCH 1/2] Fix linting and fix return value of signMessage --- .../core/extensions/coreIssuanceOrder.spec.ts | 8 +- .../coreIssuanceOrderScenarios.spec.ts | 150 +++++++++--------- .../extensions/coreIssuanceOrderScenarios.ts | 56 +++---- test/contracts/core/lib/orderLibrary.spec.ts | 8 +- test/contracts/lib/authorizable.spec.ts | 4 - types/common.ts | 6 + utils/orderWrapper.ts | 47 +++--- 7 files changed, 137 insertions(+), 142 deletions(-) diff --git a/test/contracts/core/extensions/coreIssuanceOrder.spec.ts b/test/contracts/core/extensions/coreIssuanceOrder.spec.ts index eb9d48eb8..9fe155942 100644 --- a/test/contracts/core/extensions/coreIssuanceOrder.spec.ts +++ b/test/contracts/core/extensions/coreIssuanceOrder.spec.ts @@ -167,7 +167,7 @@ contract('CoreIssuanceOrder', accounts => { makerToken = deployedTokens[2]; relayerToken = deployedTokens[3]; - issuanceOrderParams = await generateFillOrderParameters( + issuanceOrderParams = generateFillOrderParameters( setAddress || setToken.address, signerAccount, makerAddress || signerAccount, @@ -530,7 +530,7 @@ contract('CoreIssuanceOrder', accounts => { }); }); - describe("when rounding error is too large", async () => { + describe('when rounding error is too large', async () => { before(async () => { orderQuantity = ether(6); makerTokenAmount = new BigNumber(10); @@ -545,7 +545,7 @@ contract('CoreIssuanceOrder', accounts => { makerTokenAmount = undefined; }); - it("should revert", async () => { + it('should revert', async () => { await expectRevertError(subject()); }); }); @@ -594,7 +594,7 @@ contract('CoreIssuanceOrder', accounts => { subjectCaller = signerAccount; subjectQuantityToCancel = ether(2); - issuanceOrderParams = await generateFillOrderParameters( + issuanceOrderParams = generateFillOrderParameters( setToken.address, signerAccount, signerAccount, diff --git a/test/contracts/core/extensions/coreIssuanceOrderScenarios.spec.ts b/test/contracts/core/extensions/coreIssuanceOrderScenarios.spec.ts index 1f50bc9bc..3cb894c07 100644 --- a/test/contracts/core/extensions/coreIssuanceOrderScenarios.spec.ts +++ b/test/contracts/core/extensions/coreIssuanceOrderScenarios.spec.ts @@ -1,83 +1,70 @@ -import * as chai from "chai"; -import * as _ from "lodash"; +import * as chai from 'chai'; +import * as _ from 'lodash'; -import * as ABIDecoder from "abi-decoder"; -import { BigNumber } from "bignumber.js"; -import { ether } from "../../../../utils/units"; +import * as ABIDecoder from 'abi-decoder'; +import { BigNumber } from 'bignumber.js'; +import { ether } from '../../../../utils/units'; // Types -import { Address, Bytes32, IssuanceOrder } from "../../../../types/common.js"; +import { Address, Bytes32 } from '../../../../types/common.js'; // Contract types -import { CoreContract } from "../../../../types/generated/core"; -import { SetTokenContract } from "../../../../types/generated/set_token"; -import { SetTokenFactoryContract } from "../../../../types/generated/set_token_factory"; -import { StandardTokenMockContract } from "../../../../types/generated/standard_token_mock"; -import { TakerWalletWrapperContract } from "../../../../types/generated/taker_wallet_wrapper"; -import { TransferProxyContract } from "../../../../types/generated/transfer_proxy"; -import { VaultContract } from "../../../../types/generated/vault"; +import { CoreContract } from '../../../../types/generated/core'; +import { SetTokenContract } from '../../../../types/generated/set_token'; +import { SetTokenFactoryContract } from '../../../../types/generated/set_token_factory'; +import { StandardTokenMockContract } from '../../../../types/generated/standard_token_mock'; +import { TakerWalletWrapperContract } from '../../../../types/generated/taker_wallet_wrapper'; +import { TransferProxyContract } from '../../../../types/generated/transfer_proxy'; +import { VaultContract } from '../../../../types/generated/vault'; // Artifacts -const Core = artifacts.require("Core"); +const Core = artifacts.require('Core'); // Core wrapper -import { CoreWrapper } from "../../../../utils/coreWrapper"; -import { ERC20Wrapper } from "../../../../utils/erc20Wrapper"; -import { ExchangeWrapper } from "../../../../utils/exchangeWrapper"; +import { CoreWrapper } from '../../../../utils/coreWrapper'; +import { ERC20Wrapper } from '../../../../utils/erc20Wrapper'; +import { ExchangeWrapper } from '../../../../utils/exchangeWrapper'; import { generateFillOrderParameters, - generateOrdersDataForOrderCount, - generateOrdersDataWithIncorrectExchange, generateOrdersDataWithTakerOrders, -} from "../../../../utils/orderWrapper"; +} from '../../../../utils/orderWrapper'; // Log Testing Tools import { assertLogEquivalence, getFormattedLogsFromTxHash -} from "../../../../utils/logs"; +} from '../../../../utils/logs'; import { getExpectedFillLog, - getExpectedCancelLog, -} from "../../../../utils/contract_logs/coreIssuanceOrder"; +} from '../../../../utils/contract_logs/coreIssuanceOrder'; // Testing Set up -import { BigNumberSetup } from "../../../../utils/bigNumberSetup"; -import ChaiSetup from "../../../../utils/chaiSetup"; +import { BigNumberSetup } from '../../../../utils/bigNumberSetup'; +import ChaiSetup from '../../../../utils/chaiSetup'; BigNumberSetup.configure(); ChaiSetup.configure(); -const { expect, assert } = chai; +const { expect } = chai; -import { - IssuanceComponentDeposited, -} from "../../../../utils/contract_logs/core"; import { assertTokenBalance, - expectRevertError, -} from "../../../../utils/tokenAssertions"; +} from '../../../../utils/tokenAssertions'; import { DEPLOYED_TOKEN_QUANTITY, - ZERO, - NULL_ADDRESS, - DEFAULT_GAS, EXCHANGES, -} from "../../../../utils/constants"; +} from '../../../../utils/constants'; -import { SCENARIOS } from "./coreIssuanceOrderScenarios"; +import { SCENARIOS } from './coreIssuanceOrderScenarios'; -contract("CoreIssuanceOrder::Scenarios", (accounts) => { +contract('CoreIssuanceOrder::Scenarios', accounts => { const [ ownerAccount, takerAccount, - makerAccount, signerAccount, relayerAccount, - mockSetTokenAccount, - mockTokenAccount ] = accounts; let core: CoreContract; @@ -112,29 +99,32 @@ contract("CoreIssuanceOrder::Scenarios", (accounts) => { await coreWrapper.setDefaultStateAndAuthorizationsAsync(core, vault, transferProxy, setTokenFactory); }); - describe("#fillOrder", async () => { - SCENARIOS.forEach(async (scenario) => { + describe('#fillOrder', async () => { + SCENARIOS.forEach(async scenario => { describe(scenario.title, async () => { - let subjectCaller: Address = takerAccount; - let subjectQuantityToIssue: BigNumber = scenario.exchangeOrders.subjectQuantityToIssue; + const subjectCaller: Address = takerAccount; + const subjectQuantityToIssue: BigNumber = scenario.exchangeOrders.subjectQuantityToIssue; let subjectExchangeOrdersData: Bytes32; - let makerAddress: Address = signerAccount; - let relayerAddress: Address = relayerAccount; + const makerAddress: Address = signerAccount; + const relayerAddress: Address = relayerAccount; let setToken: SetTokenContract; let makerToken: StandardTokenMockContract; let relayerToken: StandardTokenMockContract; - let makerTokenAmount: BigNumber = scenario.issuanceOrderParams.makerTokenAmount; - let relayerTokenAmount: BigNumber = ether(1); - let orderQuantity: BigNumber = scenario.issuanceOrderParams.orderQuantity; - let fillPercentage: BigNumber = subjectQuantityToIssue.div(orderQuantity); + const makerTokenAmount: BigNumber = scenario.issuanceOrderParams.makerTokenAmount; + const relayerTokenAmount: BigNumber = ether(1); + const orderQuantity: BigNumber = scenario.issuanceOrderParams.orderQuantity; + const fillPercentage: BigNumber = subjectQuantityToIssue.div(orderQuantity); let issuanceOrderParams: any; beforeEach(async () => { - const deployedTokens = await erc20Wrapper.deployTokensAsync(scenario.tokenState.numberOfComponents + 2, ownerAccount); + const deployedTokens = await erc20Wrapper.deployTokensAsync( + scenario.tokenState.numberOfComponents + 2, + ownerAccount + ); await erc20Wrapper.approveTransfersAsync(deployedTokens, transferProxy.address, ownerAccount); await erc20Wrapper.approveTransfersAsync(deployedTokens, transferProxy.address, signerAccount); await erc20Wrapper.approveTransfersAsync(deployedTokens, transferProxy.address, takerAccount); @@ -157,16 +147,26 @@ contract("CoreIssuanceOrder::Scenarios", (accounts) => { amount, { from: signerAccount }, ); - }; + } }); // Give maker and taker their maker and relayer tokens - await erc20Wrapper.transferTokensAsync(deployedTokens.slice(-2), signerAccount, DEPLOYED_TOKEN_QUANTITY.div(2), ownerAccount); - await erc20Wrapper.transferTokensAsync(deployedTokens.slice(-2), takerAccount, DEPLOYED_TOKEN_QUANTITY.div(2), ownerAccount); + await erc20Wrapper.transferTokensAsync( + deployedTokens.slice(-2), + signerAccount, + DEPLOYED_TOKEN_QUANTITY.div(2), + ownerAccount + ); + await erc20Wrapper.transferTokensAsync( + deployedTokens.slice(-2), + takerAccount, + DEPLOYED_TOKEN_QUANTITY.div(2), + ownerAccount + ); // Set up and create SetToken const componentTokens = deployedTokens.slice(0, scenario.tokenState.numberOfComponents); - const componentAddresses = _.map(componentTokens, (token) => token.address); + const componentAddresses = _.map(componentTokens, token => token.address); const componentUnits = _.map(componentTokens, () => scenario.componentUnit); // Multiple of naturalUnit setToken = await coreWrapper.createSetTokenAsync( core, @@ -181,8 +181,8 @@ contract("CoreIssuanceOrder::Scenarios", (accounts) => { relayerToken = deployedTokens.slice(-1)[0]; // Define rest of params for issuanceOrder and create issuanceOrder object - let requiredComponentAmounts: BigNumber[] = []; - let requiredComponents: Address[] = []; + const requiredComponentAmounts: BigNumber[] = []; + const requiredComponents: Address[] = []; scenario.issuanceOrderParams.requiredComponentWeighting.forEach((weight, idx) => { if (weight != 0) { requiredComponents.push(componentAddresses[idx]); @@ -192,7 +192,7 @@ contract("CoreIssuanceOrder::Scenarios", (accounts) => { }); const timeToExpiration = 10; - issuanceOrderParams = await generateFillOrderParameters( + issuanceOrderParams = generateFillOrderParameters( setToken.address, signerAccount, makerAddress, @@ -210,8 +210,8 @@ contract("CoreIssuanceOrder::Scenarios", (accounts) => { await coreWrapper.registerExchange(core, EXCHANGES.TAKER_WALLET, takerWalletWrapper.address); // Create parameters for exchange orders and generate exchange order data - let takerAmountsToTransfer: BigNumber[] = []; - let takerComponents: Address[] = []; + const takerAmountsToTransfer: BigNumber[] = []; + const takerComponents: Address[] = []; scenario.exchangeOrders.takerWeightsToTransfer.forEach((weight, idx) => { if (weight != 0) { takerComponents.push(componentAddresses[idx]); @@ -241,7 +241,7 @@ contract("CoreIssuanceOrder::Scenarios", (accounts) => { ); } - it("transfers the full maker token amount from the maker", async () => { + it('transfers the full maker token amount from the maker', async () => { console.log(scenario.description); // Get pre-run balances const makerMakerTokenPreBalance = await makerToken.balanceOf.callAsync(signerAccount); @@ -253,28 +253,34 @@ contract("CoreIssuanceOrder::Scenarios", (accounts) => { await subject(); // Expected token balances - const makerMakerTokenExpectedBalance = makerMakerTokenPreBalance.sub((makerTokenAmount.mul(fillPercentage)).round(0,3)); - const takerMakerTokenExpectedBalance = takerMakerTokenPreBalance.add((makerTokenAmount.mul(fillPercentage)).round(0,3)); - const relayerRelayerTokenExpectedBalance = relayerRelayerTokenPreBalance.add((relayerTokenAmount.mul(fillPercentage)).round(0,3).mul(2)); + const makerMakerTokenExpectedBalance = makerMakerTokenPreBalance.sub( + (makerTokenAmount.mul(fillPercentage)).round(0, 3) + ); + const takerMakerTokenExpectedBalance = takerMakerTokenPreBalance.add( + (makerTokenAmount.mul(fillPercentage)).round(0, 3) + ); + const relayerRelayerTokenExpectedBalance = relayerRelayerTokenPreBalance.add( + (relayerTokenAmount.mul(fillPercentage)).round(0, 3).mul(2) + ); const makerSetTokenExpectedBalance = makerSetTokenPreBalance.add(subjectQuantityToIssue); const expectedFillOrderBalance = preFillOrderBalance.add(subjectQuantityToIssue); // Assert token balance equal what we expect - console.log("Expected maker token amount taken from maker."); + console.log('Expected maker token amount taken from maker.'); await assertTokenBalance(makerToken, makerMakerTokenExpectedBalance, signerAccount); - console.log("Expected maker token amount given to taker."); + console.log('Expected maker token amount given to taker.'); await assertTokenBalance(makerToken, takerMakerTokenExpectedBalance, subjectCaller); - console.log("Expected relayer token amount given to relayer."); + console.log('Expected relayer token amount given to relayer.'); await assertTokenBalance(relayerToken, relayerRelayerTokenExpectedBalance, relayerAddress); - console.log("Expected set token amount minted for maker."); + console.log('Expected set token amount minted for maker.'); await assertTokenBalance(setToken, makerSetTokenExpectedBalance, signerAccount); const postFillOrderBalance = await core.orderFills.callAsync(issuanceOrderParams.orderHash); - console.log("Expected fill amount marked in mapping.") + console.log('Expected fill amount marked in mapping.'); expect(expectedFillOrderBalance).to.be.bignumber.equal(postFillOrderBalance); }); - it("emits correct LogFill event", async () => { + it('emits correct LogFill event', async () => { const txHash = await subject(); const formattedLogs = await getFormattedLogsFromTxHash(txHash); @@ -286,8 +292,8 @@ contract("CoreIssuanceOrder::Scenarios", (accounts) => { relayerAddress, relayerToken.address, subjectQuantityToIssue, - (makerTokenAmount.mul(fillPercentage)).round(0,3), - (relayerTokenAmount.mul(fillPercentage)).round(0,3).mul(2), + (makerTokenAmount.mul(fillPercentage)).round(0, 3), + (relayerTokenAmount.mul(fillPercentage)).round(0, 3).mul(2), issuanceOrderParams.orderHash, core.address ); diff --git a/test/contracts/core/extensions/coreIssuanceOrderScenarios.ts b/test/contracts/core/extensions/coreIssuanceOrderScenarios.ts index 6974c58bf..66acca4fd 100644 --- a/test/contracts/core/extensions/coreIssuanceOrderScenarios.ts +++ b/test/contracts/core/extensions/coreIssuanceOrderScenarios.ts @@ -1,19 +1,17 @@ import { DEPLOYED_TOKEN_QUANTITY, ZERO, - NULL_ADDRESS, - EXCHANGES, -} from "../../../../utils/constants"; +} from '../../../../utils/constants'; import { ether, -} from "../../../../utils/units"; +} from '../../../../utils/units'; export const SCENARIOS = [ { - title: "Base Case", - description: "Maker pays for all components in the Set and receives Set in return.\ - Taker receives maker tokens and gives up component units.", + title: 'Base Case', + description: 'Maker pays for all components in the Set and receives Set in return.\ + Taker receives maker tokens and gives up component units.', naturalUnit: ether(2), componentUnit: ether(4), tokenState: { @@ -33,9 +31,9 @@ export const SCENARIOS = [ }, }, { - title: "Three Set Components Case", - description: "Maker pays for all components in the Set and receives Set in return.\ - Taker receives maker tokens and gives up component units.", + title: 'Three Set Components Case', + description: 'Maker pays for all components in the Set and receives Set in return.\ + Taker receives maker tokens and gives up component units.', naturalUnit: ether(2), componentUnit: ether(4), tokenState: { @@ -55,9 +53,9 @@ export const SCENARIOS = [ }, }, { - title: "Maker Has One Component in Wallet", - description: "Maker pays for two components in the Set and uses one of their own tokens to mint Set.\ - Taker receives maker tokens and gives up two component units.", + title: 'Maker Has One Component in Wallet', + description: 'Maker pays for two components in the Set and uses one of their own tokens to mint Set.\ + Taker receives maker tokens and gives up two component units.', naturalUnit: ether(2), componentUnit: ether(4), tokenState: { @@ -77,9 +75,9 @@ export const SCENARIOS = [ }, }, { - title: "Maker Has Two Components in Wallet", - description: "Maker pays for one component in the Set and uses two of their own tokens to mint Set.\ - Taker receives maker tokens and gives up one component unit.", + title: 'Maker Has Two Components in Wallet', + description: 'Maker pays for one component in the Set and uses two of their own tokens to mint Set.\ + Taker receives maker tokens and gives up one component unit.', naturalUnit: ether(2), componentUnit: ether(4), tokenState: { @@ -99,16 +97,17 @@ export const SCENARIOS = [ }, }, { - title: "Maker Has One Component in Wallet, One in Vault", - description: "Maker pays for one component in the Set and uses two of their own tokens to mint Set\ - (one in wallet and one in Vault). Taker receives maker tokens and gives up one component unit.", + title: 'Maker Has One Component in Wallet, One in Vault', + description: 'Maker pays for one component in the Set and uses two of their own tokens to mint Set\ + (one in wallet and one in Vault). Taker receives maker tokens and gives up one component unit.', naturalUnit: ether(2), componentUnit: ether(4), tokenState: { numberOfComponents: 3, takerAmounts: [DEPLOYED_TOKEN_QUANTITY.div(2), DEPLOYED_TOKEN_QUANTITY.div(2), DEPLOYED_TOKEN_QUANTITY], makerAmounts: [DEPLOYED_TOKEN_QUANTITY.div(2), DEPLOYED_TOKEN_QUANTITY.div(2), ZERO], - vault: [ZERO, DEPLOYED_TOKEN_QUANTITY.div(2), ZERO], // Must havevault amount declared in makerAmounts as well to make xfer go through + // Must have Vault amount declared in makerAmounts as well to make transfer go through + vault: [ZERO, DEPLOYED_TOKEN_QUANTITY.div(2), ZERO], }, exchangeOrders: { takerWeightsToTransfer: [0, 0, 1], @@ -121,17 +120,18 @@ export const SCENARIOS = [ }, }, { - title: "Maker Has One Component in Wallet, One in Vault, Taker takes half", - description: "Maker pays for one component in the Set and uses two of their own tokens to mint Set\ + title: 'Maker Has One Component in Wallet, One in Vault, Taker takes half', + description: 'Maker pays for one component in the Set and uses two of their own tokens to mint Set\ (one in wallet and one in Vault). Taker receives maker tokens and gives up one component unit. Only\ - half of order is filled.", + half of order is filled.', naturalUnit: ether(2), componentUnit: ether(4), tokenState: { numberOfComponents: 3, takerAmounts: [DEPLOYED_TOKEN_QUANTITY.div(2), DEPLOYED_TOKEN_QUANTITY.div(2), DEPLOYED_TOKEN_QUANTITY], makerAmounts: [DEPLOYED_TOKEN_QUANTITY.div(2), DEPLOYED_TOKEN_QUANTITY.div(2), ZERO], - vault: [ZERO, DEPLOYED_TOKEN_QUANTITY.div(2), ZERO], // Must havevault amount declared in makerAmounts as well to make xfer go through + // Must have Vault amount declared in makerAmounts as well to make transfer go through + vault: [ZERO, DEPLOYED_TOKEN_QUANTITY.div(2), ZERO], }, exchangeOrders: { takerWeightsToTransfer: [0, 0, .5], @@ -144,10 +144,10 @@ export const SCENARIOS = [ }, }, { - title: "Base Case with rounding errors", - description: "Maker pays for all components in the Set and receives Set in return.\ + title: 'Base Case with rounding errors', + description: 'Maker pays for all components in the Set and receives Set in return.\ Taker receives maker tokens and gives up component units. Due to rounding errors amounts\ - received are not exact.", + received are not exact.', naturalUnit: ether(2), componentUnit: ether(4), tokenState: { @@ -166,4 +166,4 @@ export const SCENARIOS = [ makerTokenAmount: ether(10), }, }, -] +]; diff --git a/test/contracts/core/lib/orderLibrary.spec.ts b/test/contracts/core/lib/orderLibrary.spec.ts index 74fcc3cfa..e470915da 100644 --- a/test/contracts/core/lib/orderLibrary.spec.ts +++ b/test/contracts/core/lib/orderLibrary.spec.ts @@ -22,10 +22,6 @@ BigNumberSetup.configure(); ChaiSetup.configure(); const { expect } = chai; -import { - ZERO, - NULL_ADDRESS, -} from '../../../../utils/constants'; contract('OrderLibrary', accounts => { const [ @@ -71,7 +67,7 @@ contract('OrderLibrary', accounts => { requiredComponents = [mockTokenAccount, mockTokenAccount2]; requiredComponentAmounts = [ether(2), ether(2)]; - issuanceOrderParams = await generateFillOrderParameters( + issuanceOrderParams = generateFillOrderParameters( mockSetTokenAccount, signerAddress, signerAddress, @@ -137,7 +133,7 @@ contract('OrderLibrary', accounts => { requiredComponents = [mockTokenAccount, mockTokenAccount2]; requiredComponentAmounts = [ether(2), ether(2)]; - issuanceOrderParams = await generateFillOrderParameters( + issuanceOrderParams = generateFillOrderParameters( mockSetTokenAccount, signerAddress, signerAddress, diff --git a/test/contracts/lib/authorizable.spec.ts b/test/contracts/lib/authorizable.spec.ts index 5c2038075..a9b90b66a 100644 --- a/test/contracts/lib/authorizable.spec.ts +++ b/test/contracts/lib/authorizable.spec.ts @@ -35,10 +35,6 @@ import { import { expectRevertError, } from '../../../utils/tokenAssertions'; -import { - DEPLOYED_TOKEN_QUANTITY, - UNLIMITED_ALLOWANCE_IN_BASE_UNITS, -} from '../../../utils/constants'; contract('Authorizable', accounts => { const [ diff --git a/types/common.ts b/types/common.ts index 166eef56e..e59bcc80f 100644 --- a/types/common.ts +++ b/types/common.ts @@ -44,6 +44,12 @@ export interface IssuanceOrder { requiredComponentAmounts: BigNumber[], } +export interface ECSig { + v: string; + r: string; + s: string; +} + export interface Log { event: string; address: Address; diff --git a/utils/orderWrapper.ts b/utils/orderWrapper.ts index 8f4611c33..abe38dc56 100644 --- a/utils/orderWrapper.ts +++ b/utils/orderWrapper.ts @@ -1,34 +1,27 @@ -import * as _ from "lodash"; -import * as ethUtil from "ethereumjs-util"; -import * as ethABI from 'ethereumjs-abi'; +import * as _ from 'lodash'; +import * as ethUtil from 'ethereumjs-util'; import { soliditySHA3 } from './ethereum-abi-arrays'; -import { BigNumber } from "bignumber.js"; -import BN = require('bn.js'); +import { BigNumber } from 'bignumber.js'; -import { Address, Bytes32, UInt, IssuanceOrder, SolidityTypes } from "../types/common.js"; +import { Address, Bytes32, IssuanceOrder, SolidityTypes, ECSig } from '../types/common.js'; import { EXCHANGES, MAX_DIGITS_IN_UNSIGNED_256_INT, -} from "./constants"; +} from './constants'; -import { ether } from "./units"; -import { bufferAndLPad32BigNumber } from "./encoding" - - -function bigNumberToBN(value: BigNumber) { - return new BN(value.toString(), 10); -} +import { ether } from './units'; +import { bufferAndLPad32BigNumber } from './encoding'; function parseSigHexAsRSV(sigHex: string): any { - const { v,r,s } = ethUtil.fromRpcSig(sigHex); + const { v, r, s } = ethUtil.fromRpcSig(sigHex); const ecSig = { v, r: ethUtil.bufferToHex(r), s: ethUtil.bufferToHex(s), }; - return ecSig + return ecSig; } export function generateOrdersDataForOrderCount( @@ -37,7 +30,7 @@ export function generateOrdersDataForOrderCount( makerTokenAmounts: number[], ): Bytes32 { const exchangeOrderDatum: Buffer[] = []; - _.times(orderCount, (index) => { + _.times(orderCount, index => { const exchange = _.sample(EXCHANGES); exchangeOrderDatum.push(paddedBufferForData(exchange)); exchangeOrderDatum.push(paddedBufferForData(makerTokenAddress)); @@ -118,7 +111,7 @@ function randomBufferOfLength( export function generateSalt(): BigNumber { const randomNumber = BigNumber.random(MAX_DIGITS_IN_UNSIGNED_256_INT); - const factor = new BigNumber(10).pow(MAX_DIGITS_IN_UNSIGNED_256_INT-1); + const factor = new BigNumber(10).pow(MAX_DIGITS_IN_UNSIGNED_256_INT - 1); const salt = randomNumber.times(factor).round(); return salt; } @@ -127,7 +120,7 @@ export function generateTimeStamp( min: number, ): BigNumber { const timeToExpiration = min * 60 * 1000; - const expiration = new BigNumber(Math.floor((Date.now() + timeToExpiration)/1000)); + const expiration = new BigNumber(Math.floor((Date.now() + timeToExpiration) / 1000)); return expiration; } @@ -147,7 +140,7 @@ export function hashOrderHex( {value: order.salt, type: SolidityTypes.Uint256}, {value: order.requiredComponents, type: SolidityTypes.AddressArray}, {value: order.requiredComponentAmounts, type: SolidityTypes.UintArray}, - ] + ]; const types = _.map(orderParts, o => o.type); const values = _.map(orderParts, o => o.value); @@ -159,15 +152,13 @@ export function hashOrderHex( export async function signMessage( msg: string, address: Address -): Promise { - const normalSigner = String(address).toLowerCase(); - - const sig = web3.eth.sign(address, msg); +): Promise { + const sig = await web3.eth.sign(address, msg); const ecSig = parseSigHexAsRSV(sig); return ecSig; } -export async function generateFillOrderParameters( +export function generateFillOrderParameters( setAddress: Address, signerAddress: Address, makerAddress: Address, @@ -180,7 +171,7 @@ export async function generateFillOrderParameters( makerTokenAmount: BigNumber, timeToExpiration: number, -): Promise { +): any { const order = { setAddress, makerAddress, @@ -200,13 +191,13 @@ export async function generateFillOrderParameters( const values = [order.quantity, order.makerTokenAmount, order.expiration, order.relayerTokenAmount, order.salt]; const orderHash = hashOrderHex(order); - const signature = await signMessage(orderHash, signerAddress); + const signature = signMessage(orderHash, signerAddress); return { addresses, values, orderHash, signature, requiredComponents, - requiredComponentAmounts + requiredComponentAmounts, }; } From 7d70bb15bf50f55d93de04b48e407d8e0ab2208b Mon Sep 17 00:00:00 2001 From: Justin Chen Date: Tue, 24 Jul 2018 08:13:58 -0700 Subject: [PATCH 2/2] Add await in front of returned Promises --- test/contracts/core/extensions/coreIssuanceOrder.spec.ts | 4 ++-- .../core/extensions/coreIssuanceOrderScenarios.spec.ts | 2 +- test/contracts/core/lib/orderLibrary.spec.ts | 4 ++-- utils/orderWrapper.ts | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/contracts/core/extensions/coreIssuanceOrder.spec.ts b/test/contracts/core/extensions/coreIssuanceOrder.spec.ts index 9fe155942..e9b9ad069 100644 --- a/test/contracts/core/extensions/coreIssuanceOrder.spec.ts +++ b/test/contracts/core/extensions/coreIssuanceOrder.spec.ts @@ -167,7 +167,7 @@ contract('CoreIssuanceOrder', accounts => { makerToken = deployedTokens[2]; relayerToken = deployedTokens[3]; - issuanceOrderParams = generateFillOrderParameters( + issuanceOrderParams = await generateFillOrderParameters( setAddress || setToken.address, signerAccount, makerAddress || signerAccount, @@ -594,7 +594,7 @@ contract('CoreIssuanceOrder', accounts => { subjectCaller = signerAccount; subjectQuantityToCancel = ether(2); - issuanceOrderParams = generateFillOrderParameters( + issuanceOrderParams = await generateFillOrderParameters( setToken.address, signerAccount, signerAccount, diff --git a/test/contracts/core/extensions/coreIssuanceOrderScenarios.spec.ts b/test/contracts/core/extensions/coreIssuanceOrderScenarios.spec.ts index 3cb894c07..86dcb4b36 100644 --- a/test/contracts/core/extensions/coreIssuanceOrderScenarios.spec.ts +++ b/test/contracts/core/extensions/coreIssuanceOrderScenarios.spec.ts @@ -192,7 +192,7 @@ contract('CoreIssuanceOrder::Scenarios', accounts => { }); const timeToExpiration = 10; - issuanceOrderParams = generateFillOrderParameters( + issuanceOrderParams = await generateFillOrderParameters( setToken.address, signerAccount, makerAddress, diff --git a/test/contracts/core/lib/orderLibrary.spec.ts b/test/contracts/core/lib/orderLibrary.spec.ts index e470915da..7db44fa85 100644 --- a/test/contracts/core/lib/orderLibrary.spec.ts +++ b/test/contracts/core/lib/orderLibrary.spec.ts @@ -67,7 +67,7 @@ contract('OrderLibrary', accounts => { requiredComponents = [mockTokenAccount, mockTokenAccount2]; requiredComponentAmounts = [ether(2), ether(2)]; - issuanceOrderParams = generateFillOrderParameters( + issuanceOrderParams = await generateFillOrderParameters( mockSetTokenAccount, signerAddress, signerAddress, @@ -133,7 +133,7 @@ contract('OrderLibrary', accounts => { requiredComponents = [mockTokenAccount, mockTokenAccount2]; requiredComponentAmounts = [ether(2), ether(2)]; - issuanceOrderParams = generateFillOrderParameters( + issuanceOrderParams = await generateFillOrderParameters( mockSetTokenAccount, signerAddress, signerAddress, diff --git a/utils/orderWrapper.ts b/utils/orderWrapper.ts index abe38dc56..b8e855a8f 100644 --- a/utils/orderWrapper.ts +++ b/utils/orderWrapper.ts @@ -158,7 +158,7 @@ export async function signMessage( return ecSig; } -export function generateFillOrderParameters( +export async function generateFillOrderParameters( setAddress: Address, signerAddress: Address, makerAddress: Address, @@ -171,7 +171,7 @@ export function generateFillOrderParameters( makerTokenAmount: BigNumber, timeToExpiration: number, -): any { +): Promise { const order = { setAddress, makerAddress, @@ -191,7 +191,7 @@ export function generateFillOrderParameters( const values = [order.quantity, order.makerTokenAmount, order.expiration, order.relayerTokenAmount, order.salt]; const orderHash = hashOrderHex(order); - const signature = signMessage(orderHash, signerAddress); + const signature = await signMessage(orderHash, signerAddress); return { addresses, values,