diff options
Diffstat (limited to 'packages/contract-wrappers')
-rw-r--r-- | packages/contract-wrappers/CHANGELOG.json | 9 | ||||
-rw-r--r-- | packages/contract-wrappers/CHANGELOG.md | 4 | ||||
-rw-r--r-- | packages/contract-wrappers/package.json | 32 | ||||
-rw-r--r-- | packages/contract-wrappers/test/revert_validation_test.ts | 122 | ||||
-rw-r--r-- | packages/contract-wrappers/test/transaction_encoder_test.ts | 2 |
5 files changed, 152 insertions, 17 deletions
diff --git a/packages/contract-wrappers/CHANGELOG.json b/packages/contract-wrappers/CHANGELOG.json index 8863f61f4..6a9a1d110 100644 --- a/packages/contract-wrappers/CHANGELOG.json +++ b/packages/contract-wrappers/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "timestamp": 1538157789, + "version": "2.0.1", + "changes": [ + { + "note": "Dependencies updated" + } + ] + }, + { "version": "2.0.0", "changes": [ { diff --git a/packages/contract-wrappers/CHANGELOG.md b/packages/contract-wrappers/CHANGELOG.md index 41e5645a3..8a9612be5 100644 --- a/packages/contract-wrappers/CHANGELOG.md +++ b/packages/contract-wrappers/CHANGELOG.md @@ -5,6 +5,10 @@ Edit the package's CHANGELOG.json file only. CHANGELOG +## v2.0.1 - _September 28, 2018_ + + * Dependencies updated + ## v2.0.0 - _September 25, 2018_ * Fixes dropped events in subscriptions by fetching logs by blockHash instead of blockNumber. Support for fetching by blockHash was added in Geth > v1.8.13 and Parity > v2.1.0. Infura works too. (#1080) diff --git a/packages/contract-wrappers/package.json b/packages/contract-wrappers/package.json index c2b1ecdc9..b561fff75 100644 --- a/packages/contract-wrappers/package.json +++ b/packages/contract-wrappers/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/contract-wrappers", - "version": "2.0.0", + "version": "2.0.1", "description": "Smart TS wrappers for 0x smart contracts", "keywords": [ "0xproject", @@ -41,10 +41,10 @@ "node": ">=6.0.0" }, "devDependencies": { - "@0xproject/abi-gen": "^1.0.11", - "@0xproject/dev-utils": "^1.0.10", - "@0xproject/migrations": "^1.0.12", - "@0xproject/subproviders": "^2.0.5", + "@0xproject/abi-gen": "^1.0.12", + "@0xproject/dev-utils": "^1.0.11", + "@0xproject/migrations": "^1.0.13", + "@0xproject/subproviders": "^2.0.6", "@0xproject/tslint-config": "^1.0.7", "@types/lodash": "4.14.104", "@types/mocha": "^2.2.42", @@ -72,19 +72,19 @@ "web3-provider-engine": "14.0.6" }, "dependencies": { - "@0xproject/assert": "^1.0.11", - "@0xproject/base-contract": "^2.0.5", - "@0xproject/fill-scenarios": "^1.0.5", - "@0xproject/json-schemas": "^1.0.4", - "@0xproject/order-utils": "^1.0.5", - "@0xproject/types": "^1.1.1", - "@0xproject/typescript-typings": "^2.0.2", - "@0xproject/utils": "^1.0.11", - "@0xproject/web3-wrapper": "^3.0.1", - "ethereum-types": "^1.0.8", + "@0xproject/assert": "^1.0.12", + "@0xproject/base-contract": "^3.0.0", + "@0xproject/fill-scenarios": "^1.0.6", + "@0xproject/json-schemas": "^1.0.5", + "@0xproject/order-utils": "^1.0.6", + "@0xproject/types": "^1.1.2", + "@0xproject/typescript-typings": "^3.0.0", + "@0xproject/utils": "^2.0.0", + "@0xproject/web3-wrapper": "^3.0.2", + "ethereum-types": "^1.0.9", "ethereumjs-blockstream": "6.0.0", "ethereumjs-util": "^5.1.1", - "ethers": "3.0.22", + "ethers": "4.0.0-beta.14", "js-sha3": "^0.7.0", "lodash": "^4.17.5", "uuid": "^3.1.0" diff --git a/packages/contract-wrappers/test/revert_validation_test.ts b/packages/contract-wrappers/test/revert_validation_test.ts new file mode 100644 index 000000000..da011c1d7 --- /dev/null +++ b/packages/contract-wrappers/test/revert_validation_test.ts @@ -0,0 +1,122 @@ +import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; +import { FillScenarios } from '@0xproject/fill-scenarios'; +import { runV2MigrationsAsync } from '@0xproject/migrations'; +import { assetDataUtils } from '@0xproject/order-utils'; +import { SignedOrder } from '@0xproject/types'; +import { BigNumber } from '@0xproject/utils'; +import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import * as chai from 'chai'; +import 'mocha'; + +import { ContractWrappers } from '../src'; + +import { chaiSetup } from './utils/chai_setup'; +import { constants } from './utils/constants'; +import { tokenUtils } from './utils/token_utils'; + +chaiSetup.configure(); +const expect = chai.expect; + +describe('Revert Validation ExchangeWrapper', () => { + let contractWrappers: ContractWrappers; + let userAddresses: string[]; + let zrxTokenAddress: string; + let fillScenarios: FillScenarios; + let exchangeContractAddress: string; + let makerTokenAddress: string; + let takerTokenAddress: string; + let coinbase: string; + let makerAddress: string; + let anotherMakerAddress: string; + let takerAddress: string; + let makerAssetData: string; + let takerAssetData: string; + let feeRecipient: string; + let txHash: string; + let blockchainLifecycle: BlockchainLifecycle; + let web3Wrapper: Web3Wrapper; + const fillableAmount = new BigNumber(5); + const takerTokenFillAmount = new BigNumber(5); + let signedOrder: SignedOrder; + const config = { + networkId: constants.TESTRPC_NETWORK_ID, + blockPollingIntervalMs: 0, + }; + before(async () => { + // vmErrorsOnRPCResponse is useful for quick feedback and testing during development + // but is not the default behaviour in production. Here we ensure our failure cases + // are handled in an environment which behaves similar to production + const provider = web3Factory.getRpcProvider({ + shouldUseInProcessGanache: true, + shouldThrowErrorsOnGanacheRPCResponse: false, + }); + web3Wrapper = new Web3Wrapper(provider); + blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); + const txDefaults = { + gas: devConstants.GAS_LIMIT, + from: devConstants.TESTRPC_FIRST_ADDRESS, + }; + const artifactsDir = `src/artifacts`; + // Re-deploy the artifacts in this provider, rather than in the default provider exposed in + // the beforeAll hook. This is due to the fact that the default provider enabled vmErrorsOnRPCResponse + // and we are explicity testing with vmErrorsOnRPCResponse disabled. + await runV2MigrationsAsync(provider, artifactsDir, txDefaults); + await blockchainLifecycle.startAsync(); + contractWrappers = new ContractWrappers(provider, config); + exchangeContractAddress = contractWrappers.exchange.getContractAddress(); + userAddresses = await web3Wrapper.getAvailableAddressesAsync(); + zrxTokenAddress = tokenUtils.getProtocolTokenAddress(); + fillScenarios = new FillScenarios( + provider, + userAddresses, + zrxTokenAddress, + exchangeContractAddress, + contractWrappers.erc20Proxy.getContractAddress(), + contractWrappers.erc721Proxy.getContractAddress(), + ); + [coinbase, makerAddress, takerAddress, feeRecipient, anotherMakerAddress] = userAddresses; + [makerTokenAddress, takerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses(); + [makerAssetData, takerAssetData] = [ + assetDataUtils.encodeERC20AssetData(makerTokenAddress), + assetDataUtils.encodeERC20AssetData(takerTokenAddress), + ]; + signedOrder = await fillScenarios.createFillableSignedOrderAsync( + makerAssetData, + takerAssetData, + makerAddress, + takerAddress, + fillableAmount, + ); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); + beforeEach(async () => { + await blockchainLifecycle.startAsync(); + }); + afterEach(async () => { + await blockchainLifecycle.revertAsync(); + }); + describe('#fillOrderAsync', () => { + it('should throw the revert reason when shouldValidate is true and a fill would revert', async () => { + // Create a scenario where the fill will revert + const makerTokenBalance = await contractWrappers.erc20Token.getBalanceAsync( + makerTokenAddress, + makerAddress, + ); + // Transfer all of the tokens from maker to create a failure scenario + txHash = await contractWrappers.erc20Token.transferAsync( + makerTokenAddress, + makerAddress, + takerAddress, + makerTokenBalance, + ); + await web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); + expect( + contractWrappers.exchange.fillOrderAsync(signedOrder, takerTokenFillAmount, takerAddress, { + shouldValidate: true, + }), + ).to.be.rejectedWith('TRANSFER_FAILED'); + }); + }); +}); diff --git a/packages/contract-wrappers/test/transaction_encoder_test.ts b/packages/contract-wrappers/test/transaction_encoder_test.ts index e76c5b12d..a397e43a8 100644 --- a/packages/contract-wrappers/test/transaction_encoder_test.ts +++ b/packages/contract-wrappers/test/transaction_encoder_test.ts @@ -1,6 +1,6 @@ import { BlockchainLifecycle } from '@0xproject/dev-utils'; import { FillScenarios } from '@0xproject/fill-scenarios'; -import { assetDataUtils, signatureUtils, generatePseudoRandomSalt, orderHashUtils } from '@0xproject/order-utils'; +import { assetDataUtils, generatePseudoRandomSalt, orderHashUtils, signatureUtils } from '@0xproject/order-utils'; import { SignedOrder, SignerType } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import 'mocha'; |