Compare commits

..

157 Commits

Author SHA1 Message Date
Fabio Berger
602abc53dd Fix version in CHANGELOG 2018-02-09 16:18:47 -08:00
Fabio Berger
fdbaa9768a Update changelog version 2018-02-09 16:09:53 -08:00
Fabio Berger
293d7261e0 Fix changelog version 2018-02-09 16:08:26 -08:00
Fabio Berger
efb6eb28ce Merge pull request #389 from 0xProject/fix/npmInclusionIssues
Fix NPM Inclusion Issues
2018-02-09 14:39:05 -08:00
Fabio Berger
ac5531ce85 Fix changelogs 2018-02-09 14:26:48 -08:00
Fabio Berger
bc2415c70e Add yarn-error.log to all .npmignore 2018-02-09 14:03:08 -08:00
Fabio Berger
0fd411f83f Add PR number to CHANGELOGs 2018-02-09 13:31:01 -08:00
Fabio Berger
b74ad0ad12 ignore all files starting with dots in all sub-packages 2018-02-09 13:28:32 -08:00
Fabio Berger
4c58836735 Remove top level .npmignore 2018-02-09 13:19:30 -08:00
Fabio Berger
3206b80dbd Add npmignore to web3-wrapper and update CHANGELOG 2018-02-09 13:18:49 -08:00
Fabio Berger
4910f7a61e Add npmignore and remove .gitignore 2018-02-09 13:16:16 -08:00
Fabio Berger
6e9109eaec Add npmignore to utils and update CHANGELOG 2018-02-09 13:14:31 -08:00
Fabio Berger
a04ec14cf0 Add npmignore to types and update CHANGELOG 2018-02-09 13:12:33 -08:00
Fabio Berger
7d3df3c117 cleanup npmignorex 2018-02-09 13:09:57 -08:00
Fabio Berger
b3a03f8e3e Add npmignore to subproviders and update CHANGELOG 2018-02-09 13:09:00 -08:00
Fabio Berger
e5668c1e5c Add npmignore to json-schemas and update CHANGELOG 2018-02-09 13:05:21 -08:00
Fabio Berger
92e74bc4fa Add npmignore to dev-utils and update CHANGELOG 2018-02-09 12:56:48 -08:00
Fabio Berger
7e12269baf Add npmignore to deployer along with a changelog 2018-02-09 12:52:12 -08:00
Fabio Berger
f3f264f5fd Add tslint.json to deployer package and fix all tslint issues 2018-02-09 12:50:37 -08:00
Brandon Millman
2e3c9b87df Merge pull request #388 from 0xProject/fix/testnet-faucet/base-unit-orders
Convert to baseUnits in signed order
2018-02-09 12:39:43 -08:00
Fabio Berger
0a113e1cf7 Add npmignore to subpackage and update CHANGELOG 2018-02-09 12:37:28 -08:00
Fabio Berger
fd772c48cf Add npmignore to typings packages 2018-02-09 12:37:18 -08:00
Fabio Berger
1c7dce6054 Add npmignore to subpackage and update CHANGELOG 2018-02-09 12:30:06 -08:00
Jacob Evans
0a2947b860 address is not optional in this context 2018-02-09 12:27:28 -08:00
Fabio Berger
c80877af43 Add npmignore to abi-gen and update CHANGELOG 2018-02-09 12:23:03 -08:00
Jacob Evans
e68b9c7e81 Convert to baseUnits in signed order 2018-02-09 12:20:25 -08:00
Fabio Berger
19198737a5 Add correct npmignore to 0x.js and update CHANGELOG 2018-02-09 12:18:23 -08:00
Brandon Millman
fea4b6aecd Merge pull request #387 from 0xProject/fix/testnet-faucet/ecsignature
Testnet Faucet Order conforming to JSON Schema
2018-02-09 12:01:59 -08:00
Fabio Berger
20e2673b82 Fix issue where custom TSLint rules were not being published to NPM 2018-02-09 11:53:38 -08:00
Jacob Evans
ef1375b9dd signature -> ecSignature 2018-02-09 10:50:38 -08:00
Brandon Millman
58f1939ec1 Merge pull request #382 from 0xProject/feature/clean-post-publish-scripts
Simplify standard postpublish script and remove them from some privat…
2018-02-09 10:19:33 -08:00
Leonid
936f6ac10f Merge pull request #379 from 0xProject/portal_json
Make portal order JSON compatible with 0x.js
2018-02-09 09:27:08 +01:00
Fabio Berger
7e04c4f24b Merge pull request #383 from 0xProject/fix/website/addMoreRelayersLanding
Add relayers section to landing page
2018-02-08 18:41:16 -08:00
Fabio Berger
9495c8f46c Fix links 2018-02-08 18:40:06 -08:00
Fabio Berger
b3f91600d3 Center header above relayers 2018-02-08 17:53:31 -08:00
Fabio Berger
ddf4437fb6 Add blog to topBar and as a consequence support external links in topBar menu items 2018-02-08 17:36:17 -08:00
Fabio Berger
4153d57849 Add title above "benefits" section 2018-02-08 16:27:47 -08:00
Fabio Berger
0652790703 Add Relayer section to landing 2018-02-08 16:27:37 -08:00
Brandon Millman
9c934d903d Add new entries to the PR template checklist 2018-02-08 16:20:02 -08:00
Brandon Millman
d7a7e28925 Fix missing references to 'this' 2018-02-08 12:02:13 -08:00
Brandon Millman
6dec29e214 Simplify standard postpublish script and remove them from some private packages 2018-02-08 11:46:33 -08:00
Leonid Logvinov
43cf8d30bd Implement blockchain.portalOrderToZeroExOrder 2018-02-08 18:28:54 +01:00
Leonid
254d3f53e2 Merge pull request #377 from 0xProject/feature/signed_unsigned_order_contracts
Use SignedOrder and Order types from 0x.js
2018-02-08 18:15:10 +01:00
Leonid Logvinov
ec198343b5 Make naming of schemas consistent 2018-02-08 18:14:52 +01:00
Leonid Logvinov
876517d458 Fix namings 2018-02-08 18:03:55 +01:00
Leonid Logvinov
1233c33116 Address feedback 2018-02-08 16:23:20 +01:00
Fabio Berger
eebf205817 Fix flash message when receiving test ether 2018-02-07 16:58:05 -08:00
Brandon Millman
e666bb44c6 Fix incorrect network ids 2018-02-07 16:05:14 -08:00
Brandon Millman
39cb0b5122 Update @0xproject/utils version in top level package.json 2018-02-07 13:36:48 -08:00
Brandon Millman
58003a2811 Publish
- 0x.js@0.32.1
 - @0xproject/abi-gen@0.2.0
 - @0xproject/assert@0.0.17
 - @0xproject/connect@0.5.6
 - contracts@2.1.10
 - @0xproject/deployer@0.0.7
 - @0xproject/dev-utils@0.0.11
 - @0xproject/json-schemas@0.7.9
 - @0xproject/subproviders@0.4.0
 - @0xproject/testnet-faucets@1.0.11
 - @0xproject/types@0.2.0
 - @0xproject/utils@0.3.1
 - @0xproject/web3-wrapper@0.1.11
 - @0xproject/website@0.0.13
2018-02-07 13:25:39 -08:00
Brandon Millman
7f2a7cfa77 Update CHANGELOGs 2018-02-07 13:19:13 -08:00
Leonid Logvinov
8fba0477a6 Remove hash from signatureData 2018-02-07 20:58:19 +01:00
Fabio Berger
7ca1ba7e1e Fix wiki styling 2018-02-07 11:45:50 -08:00
Leonid Logvinov
e6f2c7a382 Remove networkId from orderJSON 2018-02-07 20:38:30 +01:00
Leonid Logvinov
69f5f5e946 Split Order into signedOrder and metadata 2018-02-07 20:26:13 +01:00
Fabio Berger
68a8acbe7b Merge pull request #374 from 0xProject/feature/website/addOtherTestnetFaucets
Feature/website/add other testnet faucets
2018-02-07 11:21:14 -08:00
Brandon Millman
852811b314 Merge pull request #375 from 0xProject/feature/testnet-faucets/queue-by-network
Organize async task queues by network
2018-02-07 11:16:24 -08:00
Brandon Millman
2404ff0304 Prettier 2018-02-07 11:01:21 -08:00
Brandon Millman
9ff4cacf0f Addressed review comments 2018-02-07 11:00:42 -08:00
Jacob Evans
e443cb2a3b Update Subprovider README 2018-02-07 10:37:34 -08:00
Brandon Millman
f3c6cce455 Merge branch 'development' into feature/testnet-faucets/queue-by-network
* development: (24 commits)
  Fix Remco's github name in CODEOWNERS
  Fix ABI error message
  Stop using definite assignment assertion cause prettier doesn't handle that
  Special-case ZRXToken snake case conversion
  Fix linter errors
  Generate contract wrappers on pre-build
  Add missing async
  Remove noImplicitThis
  Tslint disable no-consecutive-blank-lines in generated files
  Change compiled sources in contracts
  Change utils
  Change tests
  Add base_contract.ts
  Remove generated files
  .gitignore gemerated files
  Change the list of generated wrappers
  Change contract templates
  Add indices for index parameters so that their names don't collide
  Use abi-gen for events in 0x.js
  Fix artifacts path
  ...
2018-02-07 10:27:22 -08:00
Leonid Logvinov
ae14b0a71d Reuse ECSignature 2018-02-07 16:13:09 +01:00
Leonid Logvinov
3c7ebe2697 Remove unused types and take their names 2018-02-07 16:11:51 +01:00
Leonid Logvinov
10fb6061cc Introduce makerToken and takerToken fields for unsigned token metadata 2018-02-07 15:26:53 +01:00
Leonid Logvinov
223df8006a Move .taker.amount to .takerTokenAmount and .maker.amount to .makerTokenAmount 2018-02-07 15:09:06 +01:00
Leonid Logvinov
1c9428cbba Move .taker.feeAmount to .takerFee and .maker.feeAmount to .makerFee 2018-02-07 15:02:41 +01:00
Leonid Logvinov
18dc5d17b5 Rename signature to ecSignature 2018-02-07 14:54:37 +01:00
Leonid Logvinov
4d50933189 Rename exchangeContract to exchangeContractAddress 2018-02-07 14:48:59 +01:00
Leonid Logvinov
9b3680780f Rename expiration to expirationUnixTimestampSec 2018-02-07 14:41:40 +01:00
Leonid
a26e77074f Fix Remco's github name in CODEOWNERS 2018-02-07 13:46:14 +01:00
Leonid Logvinov
568e4d33f2 Use Order and SignedOrder type from 0x.js 2018-02-07 13:41:30 +01:00
Leonid Logvinov
fd004032cb Introduce SignedOrder class and remove type assertions 2018-02-07 12:22:22 +01:00
Leonid Logvinov
4b6324050d Make orderHashHex a getter instead of a property 2018-02-07 11:59:40 +01:00
Leonid
12d62e1157 Merge pull request #368 from 0xProject/feature/abigen/addNetworkId
Add CLI option for networkId, add abi-gen to contracts package
2018-02-07 11:40:06 +01:00
Fabio Berger
063c6b66b6 Only show faucet error if not on a testnet 2018-02-06 17:55:15 -08:00
Brandon Millman
d9b1d31e73 Organize async task queues by network 2018-02-06 17:39:49 -08:00
Leonid Logvinov
0bad911a16 Fix ABI error message 2018-02-06 17:34:45 -08:00
Fabio Berger
518efa8ad2 Move isTestNetwork into utils and also check it from showing ZRX request button 2018-02-06 17:29:10 -08:00
Leonid Logvinov
6e87c9e713 Stop using definite assignment assertion cause prettier doesn't handle that 2018-02-06 17:28:55 -08:00
Leonid Logvinov
b61852b1f5 Special-case ZRXToken snake case conversion 2018-02-06 17:27:47 -08:00
Leonid Logvinov
fcbe24a126 Fix linter errors 2018-02-06 17:27:47 -08:00
Leonid Logvinov
55312d00ef Generate contract wrappers on pre-build 2018-02-06 17:27:47 -08:00
Leonid Logvinov
a96e3f3222 Add missing async 2018-02-06 17:27:47 -08:00
Leonid Logvinov
e35519b50f Remove noImplicitThis 2018-02-06 17:27:47 -08:00
Leonid Logvinov
ae775f9664 Tslint disable no-consecutive-blank-lines in generated files 2018-02-06 17:27:47 -08:00
Leonid Logvinov
071b1c47d1 Change compiled sources in contracts 2018-02-06 17:27:47 -08:00
Leonid Logvinov
4cc5bbaf19 Change utils 2018-02-06 17:27:47 -08:00
Leonid Logvinov
a264c36a48 Change tests 2018-02-06 17:27:47 -08:00
Leonid Logvinov
0c2ab22656 Add base_contract.ts 2018-02-06 17:27:47 -08:00
Leonid Logvinov
47adad5122 Remove generated files 2018-02-06 17:27:47 -08:00
Leonid Logvinov
745f209f7e .gitignore gemerated files 2018-02-06 17:27:47 -08:00
Leonid Logvinov
2287597712 Change the list of generated wrappers 2018-02-06 17:27:47 -08:00
Leonid Logvinov
eea8b15180 Change contract templates 2018-02-06 17:27:47 -08:00
Leonid Logvinov
600a2b40af Add indices for index parameters so that their names don't collide 2018-02-06 17:27:47 -08:00
Leonid Logvinov
a7c51593e4 Use abi-gen for events in 0x.js 2018-02-06 17:27:47 -08:00
Amir Bandeali
218876ac19 Fix artifacts path 2018-02-06 17:26:13 -08:00
Amir Bandeali
6cda67df10 Update compile command and run prettier 2018-02-06 17:26:13 -08:00
Amir Bandeali
897515c002 Add CLI option for networkId, add abi-gen to contracts package 2018-02-06 17:26:12 -08:00
Fabio Berger
9deaf612f1 Remove stray log 2018-02-06 17:25:19 -08:00
Fabio Berger
b7676d8c46 Use isTestNetwork instead of isKovanTestNetwork on balances page except for Dharma integration 2018-02-06 17:23:27 -08:00
Fabio Berger
05aa2fa421 Properly detect Rinkeby and Ropsten TokenRegistry tokens as mintable 2018-02-06 17:23:01 -08:00
Fabio Berger
03f5c9b950 Add networkId to faucet requests so that we can request tokens on Kovan, Rinkeby and Ropsten 2018-02-06 17:22:20 -08:00
Fabio Berger
4c9c4c487a Merge branch 'development' of github.com:0xProject/0x.js into development
* 'development' of github.com:0xProject/0x.js:
  Bump subproviders version
  Update yarn.lock
  Change rpcUrls keys back into string literals
  Add types-bn package to 0x.js and testnet-faucets
  Prettier
  Addressed comments and update 0xProject/types-ethereumjs-util deps
  Prettier
  Update testnet-faucets README
  Fix lint errors
  Add order signing and dispensing ability to faucet
2018-02-06 16:26:35 -08:00
Fabio Berger
c172b9e080 Add networkId to event label 2018-02-06 16:25:50 -08:00
Fabio Berger
5533a84dcd Update yarn.lock 2018-02-06 16:25:29 -08:00
Brandon Millman
562bcb8571 Merge pull request #352 from 0xProject/feature/testnet-faucets/order-dispenser
Add order signing and dispensing ability to faucet
2018-02-06 16:15:25 -08:00
Tom Schmidt
00c07b38a4 Merge pull request #370 from 0xProject/feature/ga-portal-logging
Add GA Logging to Portal
2018-02-06 16:01:36 -08:00
Brandon Millman
f44bfa9682 Bump subproviders version 2018-02-06 15:56:40 -08:00
Brandon Millman
7357a0a324 Update yarn.lock 2018-02-06 15:38:23 -08:00
Brandon Millman
36a49966eb Merge branch 'development' into feature/testnet-faucets/order-dispenser
* development:
  Attribute the origins of NonceTracker
  Move BlockParamLiteral to shared types package
  Fixes
  Move BlockParam and BlockParamLiteral to shared types
  Rename called to something more readable
  Newline prettier/lint
  Yarn.lock
  Refactor tests for reuse of the fixture subprovider
  Remove re-fetch of transaction count on error
  Disable linter for multiple class declarations
  Remove double declaration
  Enable CIRCLECI and declare web3
  Test faucets to use new NonceTracker
  Update changelog
  Readability and prettier
  Prettify
  Nonce tracker subprovider Caches the nonce when a request to getTransactionCount is made and increments the pending nonce after successful transactions
2018-02-06 15:36:00 -08:00
Brandon Millman
f818d06b43 Change rpcUrls keys back into string literals 2018-02-06 15:31:12 -08:00
Jacob Evans
548246c05f Merge pull request #355 from 0xProject/feature/subproviders/nonce-tracker
Nonce tracker subprovider
2018-02-06 15:29:19 -08:00
Brandon Millman
2bf1aa975a Add types-bn package to 0x.js and testnet-faucets 2018-02-06 15:24:11 -08:00
Jacob Evans
4be8eca3fe Attribute the origins of NonceTracker
NonceTrackerSubprovider is inspired from Web3ProviderEngine NonceTracker
2018-02-06 15:16:28 -08:00
Jacob Evans
e17ace397c Move BlockParamLiteral to shared types package
Also BlockParam
2018-02-06 13:17:14 -08:00
Brandon Millman
6bdabe72b9 Prettier 2018-02-06 11:48:56 -08:00
Thomas Schmidt
00bfc7f889 Added logging for order filling and order cancelling 2018-02-06 11:47:24 -08:00
Brandon Millman
5fcb77e591 Merge branch 'development' into feature/testnet-faucets/order-dispenser
* development:
  Update utils in top level package to 0.3.0
  Add 0.2.0 back to yarn lock
  Reword comment on any
  Link to the wiki article in the README
  Justify the any usage
  Publish
  Revert "Temp"
  Changelog
  Change the InjectedWeb3Subprovider to accept Web3.Provider
2018-02-06 11:45:55 -08:00
Jacob Evans
df8de7ff51 Fixes
Rename to isFirstGetTransactionCount
assign nextPrefixedHexNonce as a const
2018-02-06 11:34:22 -08:00
Jacob Evans
67d7540907 Move BlockParam and BlockParamLiteral to shared types 2018-02-06 11:27:11 -08:00
Brandon Millman
83d0bad3a1 Addressed comments and update 0xProject/types-ethereumjs-util deps 2018-02-05 18:11:26 -08:00
Thomas Schmidt
9d80a62bb1 Moved to async await 2018-02-05 18:02:05 -08:00
Jacob Evans
629653425d Update utils in top level package to 0.3.0 2018-02-05 17:58:30 -08:00
Jacob Evans
03ce1d8641 Add 0.2.0 back to yarn lock 2018-02-05 17:47:10 -08:00
Jacob Evans
225baeb5cb Merge branch 'development' into feature/subproviders/nonce-tracker 2018-02-05 17:22:45 -08:00
Jacob Evans
cf171d28c7 Reword comment on any 2018-02-05 17:20:45 -08:00
Jacob Evans
61434a9121 Merge pull request #363 from 0xProject/refactor/subproviders/injected-provider-constructor
Change the InjectedWeb3Subprovider to accept Web3.Provider
2018-02-05 17:16:34 -08:00
Jacob Evans
20590b7d35 Rename called to something more readable 2018-02-05 17:11:45 -08:00
Jacob Evans
fce7081215 Newline prettier/lint 2018-02-05 16:57:27 -08:00
Thomas Schmidt
83c7c8110d Formatting and removed old GA code 2018-02-05 16:56:53 -08:00
Jacob Evans
c4680a97a8 Yarn.lock 2018-02-05 16:47:31 -08:00
Thomas Schmidt
91a5bcf380 Converted BigNumber to number for GA logging 2018-02-05 16:43:50 -08:00
Jacob Evans
7e9ae458e2 Merge branch 'development' into feature/subproviders/nonce-tracker 2018-02-05 16:36:46 -08:00
Jacob Evans
4e284f5e6c Refactor tests for reuse of the fixture subprovider 2018-02-05 16:32:43 -08:00
Thomas Schmidt
75ded89790 GA logging for order creation 2018-02-05 16:20:53 -08:00
Thomas Schmidt
598ce0d401 Switch GA to React GA and add logging for Portal 2018-02-05 15:57:29 -08:00
Jacob Evans
fc3058c1e2 Remove re-fetch of transaction count on error 2018-02-05 14:27:58 -08:00
Jacob Evans
d14ae70776 Link to the wiki article in the README 2018-02-05 13:55:01 -08:00
Jacob Evans
882816d609 Justify the any usage 2018-02-05 13:46:59 -08:00
Leonid Logvinov
2205e2b9a0 Publish
- 0x.js@0.32.0
 - @0xproject/abi-gen@0.1.7
 - @0xproject/assert@0.0.16
 - @0xproject/connect@0.5.5
 - contracts@2.1.9
 - @0xproject/deployer@0.0.6
 - @0xproject/dev-utils@0.0.10
 - @0xproject/json-schemas@0.7.8
 - @0xproject/monorepo-scripts@0.1.9
 - @0xproject/subproviders@0.3.6
 - @0xproject/testnet-faucets@1.0.10
 - @0xproject/tslint-config@0.4.7
 - @0xproject/types@0.1.9
 - @0xproject/utils@0.3.0
 - web3-typescript-typings@0.9.9
 - @0xproject/web3-wrapper@0.1.10
 - @0xproject/website@0.0.12
2018-02-05 22:29:42 +01:00
Leonid Logvinov
855fdd7921 Revert "Temp"
This reverts commit 881d32e733.
2018-02-05 22:26:50 +01:00
Brandon Millman
99b1f81e89 Merge branch 'development' into feature/testnet-faucets/order-dispenser
* development: (37 commits)
  Add dates to CHANGELOGs
  Change CHANGELOGs
  Add .editorconfig
  Fix a typo
  Temp
  Use forEach instead of map
  Add PR number
  Fix an exception when a signature collision happens
  Fix prettier
  Add regression tests
  Improve the comment and fix an exception
  Add missing comas
  Lerna-ignore tslint and tsconfig
  Update contract versions, fix tests
  Rename directories
  Rename previous contracts, fix imports, add nested file structure
  Move all contracts into a single directory
  Update import
  Fix import
  Get rid of suffixed contract versioning and replace it with a poor-mans package manager. Versions are stored locally, and are generated in a copy-on-write basis as required
  ...
2018-02-05 13:16:46 -08:00
Jacob Evans
dae6f28f8a Disable linter for multiple class declarations 2018-02-02 15:07:10 -08:00
Jacob Evans
5aca3a2d7d Changelog 2018-02-02 14:53:44 -08:00
Jacob Evans
7f257e258f Change the InjectedWeb3Subprovider to accept Web3.Provider 2018-02-02 14:44:29 -08:00
Jacob Evans
48aa1ad57d Remove double declaration 2018-02-01 18:43:32 -08:00
Jacob Evans
2eccb28dee Enable CIRCLECI and declare web3 2018-02-01 17:08:19 -08:00
Jacob Evans
76eb1e9e7f Test faucets to use new NonceTracker 2018-02-02 11:26:49 +11:00
Jacob Evans
b7af597668 Update changelog 2018-02-02 11:06:56 +11:00
Jacob Evans
d635559a30 Readability and prettier 2018-02-02 11:06:23 +11:00
Jacob Evans
58dd90b7b7 Prettify 2018-02-02 11:06:22 +11:00
Jacob Evans
ead990a734 Nonce tracker subprovider
Caches the nonce when a request to getTransactionCount is made
and increments the pending nonce after successful transactions
2018-02-02 11:06:22 +11:00
Brandon Millman
6577d60733 Prettier 2018-01-31 15:52:05 -08:00
Brandon Millman
c7db837214 Update testnet-faucets README 2018-01-31 15:40:13 -08:00
Brandon Millman
03cb7233dc Merge branch 'development' into feature/testnet-faucets/order-dispenser
* development: (49 commits)
  Prettier
  Updated contract generation in 0x to new abi-gen CLI
  Add PR number to changelog
  Fix lint errors
  Removed deprecated CLI options
  Add protected keyword to underscore lint rule
  Remove unused prop
  Fix prettier
  Uppercase Networks enum values
  Make default gasPrice more readable
  Fix prettier mess
  Fix linter errors
  Shrink img
  Fix all setState calls after unmounted errors. Decided to create our own flag rather then using a cancellablePromise since there was little to be gained from this alternative
  Fix bug where we were return undefined instead of the empty object
  Default the derivation path to that found in the Ledger subprovider
  Add browser data to dialog info
  Add Rinkeby support
  Pass in whether we want the personal message prefix appended and never append it for Ledger. This fixes signing when Ledger is used and the backing node is not Parity
  Wholesale replace the tokenByAddress and de-dup properly
  ...
2018-01-31 15:30:09 -08:00
Brandon Millman
3a1ca32ff1 Fix lint errors 2018-01-30 12:10:06 -08:00
Brandon Millman
44162811bd Add order signing and dispensing ability to faucet 2018-01-30 11:36:39 -08:00
235 changed files with 2574 additions and 2259 deletions

View File

@@ -1,6 +0,0 @@
.*
tsconfig.json
tslint.json
webpack.config.js
yarn.lock
docs

View File

@@ -1 +1 @@
* @abandeali1 @BMillman19 @dekz @fabioberger @LogvinovLeon @Remco
* @abandeali1 @BMillman19 @dekz @fabioberger @LogvinovLeon @Recmo

View File

@@ -36,3 +36,7 @@
* [ ] Change requires a change to the documentation.
* [ ] Added tests to cover my changes.
* [ ] Added new entries to the relevant CHANGELOGs.
* [ ] Updated the new versions of the changed packages in the relevant CHANGELOGs.
* [ ] Labeled this PR with the 'WIP' label if it is a work in progress.
* [ ] Labeled this PR with the labels corresponding to the changed package.

View File

@@ -16,7 +16,7 @@
"mnemonic": "concert load couple harbor equip island argue ramp clarify fence smart topic"
},
"devDependencies": {
"@0xproject/utils": "^0.2.0",
"@0xproject/utils": "^0.3.1",
"async-child-process": "^1.1.1",
"ethereumjs-testrpc": "^6.0.3",
"lerna": "^2.5.1",

10
packages/0x.js/.npmignore Normal file
View File

@@ -0,0 +1,10 @@
.*
tsconfig.json
webpack.config.js
yarn-error.log
test/
/src/
/_bundles/
/contract_templates/
/generated_docs/
/scripts/

View File

@@ -1,5 +1,14 @@
# CHANGELOG
## v0.32.2 - _February 9, 2018_
* Fix publishing issue where .npmignore was not properly excluding undesired content (#389)
## v0.32.1 - _February 7, 2018_
* Reorganized `BlockParamLiteral` export into `@0xproject/types` package (#355)
* Now using `abi-gen` package to generate ContractEventArgs types (#371)
## v0.32.0 - _February 5, 2018_
* Add `zeroEx.etherToken.getContractAddressIfExists` (#350)

View File

@@ -1,7 +1,8 @@
/**
* This file is auto-generated using abi-gen. Don't edit directly.
* Templates can be found at https://github.com/0xProject/0x.js/tree/development/packages/abi-gen-templates.
* Templates can be found at https://github.com/0xProject/0x.js/tree/development/packages/0x.js/contract_templates.
*/
// tslint:disable:no-consecutive-blank-lines
// tslint:disable-next-line:no-unused-variable
import { TxData, TxDataPayable } from '@0xproject/types';
import { BigNumber, classUtils, promisify } from '@0xproject/utils';
@@ -9,6 +10,24 @@ import * as Web3 from 'web3';
import {BaseContract} from './base_contract';
{{#if events}}
export type {{contractName}}ContractEventArgs =
{{#each events}}
| {{name}}ContractEventArgs{{#if @last}};{{/if}}
{{/each}}
export enum {{contractName}}Events {
{{#each events}}
{{name}} = '{{name}}',
{{/each}}
}
{{#each events}}
{{> event}}
{{/each}}
{{/if}}
export class {{contractName}}Contract extends BaseContract {
{{#each methods}}
{{#this.constant}}

View File

@@ -0,0 +1,5 @@
export interface {{name}}ContractEventArgs {
{{#each inputs}}
{{name}}: {{#returnType type}}{{/returnType}};
{{/each}}
}

View File

@@ -1,6 +1,6 @@
{
"name": "0x.js",
"version": "0.31.1",
"version": "0.32.1",
"description": "A javascript library for interacting with the 0x protocol",
"keywords": [
"0x.js",
@@ -42,9 +42,9 @@
"node": ">=6.0.0"
},
"devDependencies": {
"@0xproject/abi-gen": "^0.1.6",
"@0xproject/dev-utils": "^0.0.9",
"@0xproject/tslint-config": "^0.4.6",
"@0xproject/abi-gen": "^0.2.0",
"@0xproject/dev-utils": "^0.0.11",
"@0xproject/tslint-config": "^0.4.7",
"@types/bintrees": "^1.0.2",
"@types/jsonschema": "^1.1.1",
"@types/lodash": "^4.14.86",
@@ -74,17 +74,18 @@
"truffle-hdwallet-provider": "^0.0.3",
"tslint": "5.8.0",
"typedoc": "~0.8.0",
"types-bn": "^0.0.1",
"typescript": "2.7.1",
"web3-provider-engine": "^13.0.1",
"web3-typescript-typings": "^0.9.8",
"web3-typescript-typings": "^0.9.9",
"webpack": "^3.1.0"
},
"dependencies": {
"@0xproject/assert": "^0.0.15",
"@0xproject/json-schemas": "^0.7.7",
"@0xproject/types": "^0.1.8",
"@0xproject/utils": "^0.2.4",
"@0xproject/web3-wrapper": "^0.1.9",
"@0xproject/assert": "^0.0.17",
"@0xproject/json-schemas": "^0.7.9",
"@0xproject/types": "^0.2.0",
"@0xproject/utils": "^0.3.1",
"@0xproject/web3-wrapper": "^0.1.11",
"bintrees": "^1.0.2",
"bn.js": "^4.11.8",
"ethereumjs-abi": "^0.6.4",

View File

@@ -15,7 +15,7 @@ postpublish_utils
version = result.version;
const releaseName = postpublish_utils.getReleaseName(subPackageName, version);
const assets = [__dirname + '/../_bundles/index.js', __dirname + '/../_bundles/index.min.js'];
return postpublish_utils.publishReleaseNotes(tag, releaseName, assets);
return postpublish_utils.publishReleaseNotesAsync(tag, releaseName, assets);
})
.then(function(release) {
console.log('POSTPUBLISH: Release successful, generating docs...');

View File

@@ -1,4 +1,4 @@
import { LogWithDecodedArgs, RawLog } from '@0xproject/types';
import { BlockParamLiteral, LogWithDecodedArgs, RawLog } from '@0xproject/types';
import { AbiDecoder, intervalUtils } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { Block, BlockAndLogStreamer } from 'ethereumjs-blockstream';
@@ -7,7 +7,6 @@ import * as Web3 from 'web3';
import {
Artifact,
BlockParamLiteral,
BlockRange,
ContractEventArgs,
ContractEvents,
@@ -196,7 +195,6 @@ export class ContractWrapper {
}
private async _reconcileBlockAsync(): Promise<void> {
const latestBlock = await this._web3Wrapper.getBlockAsync(BlockParamLiteral.Latest);
console.log('latestBlock', latestBlock.number);
// We need to coerce to Block type cause Web3.Block includes types for mempool blocks
if (!_.isUndefined(this._blockAndLogStreamerIfExists)) {
// If we clear the interval while fetching the block - this._blockAndLogStreamer will be undefined

View File

@@ -5,19 +5,11 @@ import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash';
import { artifacts } from '../artifacts';
import {
BlockRange,
EtherTokenContractEventArgs,
EtherTokenEvents,
EventCallback,
IndexedFilterValues,
TransactionOpts,
ZeroExError,
} from '../types';
import { BlockRange, EventCallback, IndexedFilterValues, TransactionOpts, ZeroExError } from '../types';
import { assert } from '../utils/assert';
import { ContractWrapper } from './contract_wrapper';
import { EtherTokenContract } from './generated/ether_token';
import { EtherTokenContract, EtherTokenContractEventArgs, EtherTokenEvents } from './generated/ether_token';
import { TokenWrapper } from './token_wrapper';
/**

View File

@@ -1,5 +1,5 @@
import { schemas } from '@0xproject/json-schemas';
import { DecodedLogArgs, LogWithDecodedArgs } from '@0xproject/types';
import { BlockParamLiteral, DecodedLogArgs, LogWithDecodedArgs } from '@0xproject/types';
import { AbiDecoder, BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash';
@@ -7,16 +7,12 @@ import * as Web3 from 'web3';
import { artifacts } from '../artifacts';
import {
BlockParamLiteral,
BlockRange,
ECSignature,
EventCallback,
ExchangeContractErrCodes,
ExchangeContractErrs,
ExchangeContractEventArgs,
ExchangeEvents,
IndexedFilterValues,
LogErrorContractEventArgs,
MethodOpts,
Order,
OrderAddresses,
@@ -34,7 +30,12 @@ import { OrderValidationUtils } from '../utils/order_validation_utils';
import { utils } from '../utils/utils';
import { ContractWrapper } from './contract_wrapper';
import { ExchangeContract } from './generated/exchange';
import {
ExchangeContract,
ExchangeContractEventArgs,
ExchangeEvents,
LogErrorContractEventArgs,
} from './generated/exchange';
import { TokenWrapper } from './token_wrapper';
const SHOULD_VALIDATE_BY_DEFAULT = true;

View File

@@ -5,21 +5,12 @@ import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash';
import { artifacts } from '../artifacts';
import {
BlockRange,
EventCallback,
IndexedFilterValues,
MethodOpts,
TokenContractEventArgs,
TokenEvents,
TransactionOpts,
ZeroExError,
} from '../types';
import { BlockRange, EventCallback, IndexedFilterValues, MethodOpts, TransactionOpts, ZeroExError } from '../types';
import { assert } from '../utils/assert';
import { constants } from '../utils/constants';
import { ContractWrapper } from './contract_wrapper';
import { TokenContract } from './generated/token';
import { TokenContract, TokenContractEventArgs, TokenEvents } from './generated/token';
import { TokenTransferProxyWrapper } from './token_transfer_proxy_wrapper';
/**

View File

@@ -2,7 +2,6 @@ export { ZeroEx } from './0x';
export {
Order,
BlockParamLiteral,
SignedOrder,
ECSignature,
ZeroExError,
@@ -10,27 +9,13 @@ export {
ExchangeContractErrs,
ContractEvent,
Token,
ExchangeEvents,
TokenEvents,
IndexedFilterValues,
BlockRange,
BlockParam,
OrderCancellationRequest,
OrderFillRequest,
LogErrorContractEventArgs,
LogCancelContractEventArgs,
LogFillContractEventArgs,
ExchangeContractEventArgs,
TransferContractEventArgs,
ApprovalContractEventArgs,
TokenContractEventArgs,
EtherTokenContractEventArgs,
WithdrawalContractEventArgs,
DepositContractEventArgs,
ContractEventArgs,
Web3Provider,
ZeroExConfig,
EtherTokenEvents,
MethodOpts,
OrderTransactionOpts,
TransactionOpts,
@@ -44,6 +29,34 @@ export {
OrderState,
} from './types';
export { ContractEventArg, LogWithDecodedArgs, TransactionReceiptWithDecodedLogs } from '@0xproject/types';
export {
BlockParamLiteral,
BlockParam,
ContractEventArg,
LogWithDecodedArgs,
TransactionReceiptWithDecodedLogs,
} from '@0xproject/types';
export {
EtherTokenContractEventArgs,
WithdrawalContractEventArgs,
DepositContractEventArgs,
EtherTokenEvents,
} from './contract_wrappers/generated/ether_token';
export {
TransferContractEventArgs,
ApprovalContractEventArgs,
TokenContractEventArgs,
TokenEvents,
} from './contract_wrappers/generated/token';
export {
LogErrorContractEventArgs,
LogCancelContractEventArgs,
LogFillContractEventArgs,
ExchangeContractEventArgs,
ExchangeEvents,
} from './contract_wrappers/generated/exchange';
export { TransactionReceipt } from '@0xproject/types';

View File

@@ -3,7 +3,9 @@ import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash';
import * as Web3 from 'web3';
import { BlockParamLiteral, EventWatcherCallback, ZeroExError } from '../types';
import { BlockParamLiteral } from '@0xproject/types';
import { EventWatcherCallback, ZeroExError } from '../types';
import { assert } from '../utils/assert';
const DEFAULT_EVENT_POLLING_INTERVAL_MS = 200;

View File

@@ -1,32 +1,37 @@
import { schemas } from '@0xproject/json-schemas';
import { LogWithDecodedArgs } from '@0xproject/types';
import { BlockParamLiteral, LogWithDecodedArgs } from '@0xproject/types';
import { AbiDecoder, intervalUtils } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash';
import { ZeroEx } from '../0x';
import { ExchangeWrapper } from '../contract_wrappers/exchange_wrapper';
import {
DepositContractEventArgs,
EtherTokenEvents,
WithdrawalContractEventArgs,
} from '../contract_wrappers/generated/ether_token';
import {
ExchangeEvents,
LogCancelContractEventArgs,
LogFillContractEventArgs,
} from '../contract_wrappers/generated/exchange';
import {
ApprovalContractEventArgs,
TokenEvents,
TransferContractEventArgs,
} from '../contract_wrappers/generated/token';
import { TokenWrapper } from '../contract_wrappers/token_wrapper';
import { BalanceAndProxyAllowanceLazyStore } from '../stores/balance_proxy_allowance_lazy_store';
import { OrderFilledCancelledLazyStore } from '../stores/order_filled_cancelled_lazy_store';
import {
ApprovalContractEventArgs,
BlockParamLiteral,
ContractEventArgs,
DepositContractEventArgs,
EtherTokenEvents,
ExchangeContractErrs,
ExchangeEvents,
LogCancelContractEventArgs,
LogEvent,
LogFillContractEventArgs,
OnOrderStateChangeCallback,
OrderState,
OrderStateWatcherConfig,
SignedOrder,
TokenEvents,
TransferContractEventArgs,
WithdrawalContractEventArgs,
ZeroExError,
} from '../types';
import { assert } from '../utils/assert';

View File

@@ -1,8 +1,8 @@
import { BlockParamLiteral } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
import { TokenWrapper } from '../contract_wrappers/token_wrapper';
import { BlockParamLiteral } from '../types';
/**
* Copy on read store for balances/proxyAllowances of tokens/accounts

View File

@@ -1,8 +1,8 @@
import { BlockParamLiteral } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
import { ExchangeWrapper } from '../contract_wrappers/exchange_wrapper';
import { BlockParamLiteral } from '../types';
/**
* Copy on read store for filled/cancelled taker amounts

View File

@@ -1,7 +1,13 @@
import { ContractEventArg, LogWithDecodedArgs } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import { BlockParam, BlockParamLiteral, ContractEventArg, LogWithDecodedArgs } from '@0xproject/types';
import * as Web3 from 'web3';
import { EtherTokenContractEventArgs, EtherTokenEvents } from './contract_wrappers/generated/ether_token';
import { ExchangeContractEventArgs, ExchangeEvents } from './contract_wrappers/generated/exchange';
import { TokenContractEventArgs, TokenEvents } from './contract_wrappers/generated/token';
export enum ZeroExError {
ExchangeContractDoesNotExist = 'EXCHANGE_CONTRACT_DOES_NOT_EXIST',
ZRXContractDoesNotExist = 'ZRX_CONTRACT_DOES_NOT_EXIST',
@@ -99,60 +105,6 @@ export interface ContractEvent {
args: ContractEventArgs;
}
export interface LogFillContractEventArgs {
maker: string;
taker: string;
feeRecipient: string;
makerToken: string;
takerToken: string;
filledMakerTokenAmount: BigNumber;
filledTakerTokenAmount: BigNumber;
paidMakerFee: BigNumber;
paidTakerFee: BigNumber;
tokens: string;
orderHash: string;
}
export interface LogCancelContractEventArgs {
maker: string;
feeRecipient: string;
makerToken: string;
takerToken: string;
cancelledMakerTokenAmount: BigNumber;
cancelledTakerTokenAmount: BigNumber;
tokens: string;
orderHash: string;
}
export interface LogErrorContractEventArgs {
errorId: BigNumber;
orderHash: string;
}
export type ExchangeContractEventArgs =
| LogFillContractEventArgs
| LogCancelContractEventArgs
| LogErrorContractEventArgs;
export interface TransferContractEventArgs {
_from: string;
_to: string;
_value: BigNumber;
}
export interface ApprovalContractEventArgs {
_owner: string;
_spender: string;
_value: BigNumber;
}
export interface DepositContractEventArgs {
_owner: string;
_value: BigNumber;
}
export interface WithdrawalContractEventArgs {
_owner: string;
_value: BigNumber;
}
export type TokenContractEventArgs = TransferContractEventArgs | ApprovalContractEventArgs;
export type EtherTokenContractEventArgs =
| TokenContractEventArgs
| DepositContractEventArgs
| WithdrawalContractEventArgs;
export type ContractEventArgs = ExchangeContractEventArgs | TokenContractEventArgs | EtherTokenContractEventArgs;
export interface Order {
@@ -195,40 +147,12 @@ export interface TokenAddressBySymbol {
[symbol: string]: string;
}
export enum ExchangeEvents {
LogFill = 'LogFill',
LogCancel = 'LogCancel',
LogError = 'LogError',
}
export enum TokenEvents {
Transfer = 'Transfer',
Approval = 'Approval',
}
export enum EtherTokenEvents {
Transfer = 'Transfer',
Approval = 'Approval',
Deposit = 'Deposit',
Withdrawal = 'Withdrawal',
}
export type ContractEvents = TokenEvents | ExchangeEvents | EtherTokenEvents;
export interface IndexedFilterValues {
[index: string]: ContractEventArg;
}
// Earliest is omitted by design. It is simply an alias for the `0` constant and
// is thus not very helpful. Moreover, this type is used in places that only accept
// `latest` or `pending`.
export enum BlockParamLiteral {
Latest = 'latest',
Pending = 'pending',
}
export type BlockParam = BlockParamLiteral | number;
export interface BlockRange {
fromBlock: BlockParam;
toBlock: BlockParam;

View File

@@ -1,9 +1,10 @@
import { BlockParamLiteral } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
import { TokenWrapper } from '../contract_wrappers/token_wrapper';
import { BalanceAndProxyAllowanceLazyStore } from '../stores/balance_proxy_allowance_lazy_store';
import { BlockParamLiteral, ExchangeContractErrs, TradeSide, TransferType } from '../types';
import { ExchangeContractErrs, TradeSide, TransferType } from '../types';
enum FailureReason {
Balance = 'balance',

View File

@@ -1,9 +1,10 @@
import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
import { BlockParamLiteral } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import { ExchangeContractErrs, Token, ZeroEx } from '../src';
import { BlockParamLiteral, TradeSide, TransferType } from '../src/types';
import { TradeSide, TransferType } from '../src/types';
import { ExchangeTransferSimulator } from '../src/utils/exchange_transfer_simulator';
import { chaiSetup } from './utils/chai_setup';

View File

@@ -1,4 +1,5 @@
import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
import { BlockParamLiteral } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import * as _ from 'lodash';
@@ -18,7 +19,7 @@ import {
Token,
ZeroEx,
} from '../src';
import { BlockParamLiteral, DoneCallback } from '../src/types';
import { DoneCallback } from '../src/types';
import { chaiSetup } from './utils/chai_setup';
import { constants } from './utils/constants';

View File

@@ -1,11 +1,12 @@
import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
import { BlockParamLiteral } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import * as Sinon from 'sinon';
import * as Web3 from 'web3';
import { ExchangeContractErrs, SignedOrder, Token, ZeroEx, ZeroExError } from '../src';
import { BlockParamLiteral, TradeSide, TransferType } from '../src/types';
import { TradeSide, TransferType } from '../src/types';
import { ExchangeTransferSimulator } from '../src/utils/exchange_transfer_simulator';
import { OrderValidationUtils } from '../src/utils/order_validation_utils';

View File

@@ -0,0 +1,5 @@
.*
yarn-error.log
/src/
/scripts/
tsconfig.json

View File

@@ -1,11 +1,16 @@
# CHANGELOG
## v0.2.0 - _???_
## v0.2.1 - _February 9, 2018_
* Added CLI options for explicit specifying location of partials and main template (#346)
* Fix publishing issue where .npmignore was not properly excluding undesired content (#389)
## v0.2.0 - _February 7, 2018_
* Added CLI options for explicit specifying location of partials and main template (#346)
* Added CLI option to specify networkId, adding support for the JSON artifact format found in @0xproject/contracts (#388)
## v0.1.0 - _January 11, 2018_
* Fixed array typings with union types (#295)
* Add event ABIs to context data passed to templates (#302)
* Add constructor ABIs to context data passed to templates (#304)
* Fixed array typings with union types (#295)
* Add event ABIs to context data passed to templates (#302)
* Add constructor ABIs to context data passed to templates (#304)

View File

@@ -1,6 +1,6 @@
{
"name": "@0xproject/abi-gen",
"version": "0.1.6",
"version": "0.2.0",
"description": "Generate contract wrappers from ABI and handlebars templates",
"main": "lib/index.js",
"types": "lib/index.d.ts",
@@ -23,7 +23,7 @@
},
"homepage": "https://github.com/0xProject/0x.js/packages/abi-gen/README.md",
"dependencies": {
"@0xproject/utils": "^0.2.4",
"@0xproject/utils": "^0.3.1",
"chalk": "^2.3.0",
"glob": "^7.1.2",
"handlebars": "^4.0.11",
@@ -34,7 +34,7 @@
"yargs": "^10.0.3"
},
"devDependencies": {
"@0xproject/tslint-config": "^0.4.6",
"@0xproject/tslint-config": "^0.4.7",
"@types/glob": "^5.0.33",
"@types/handlebars": "^4.0.36",
"@types/mkdirp": "^0.5.1",
@@ -44,6 +44,6 @@
"shx": "^0.2.2",
"tslint": "5.8.0",
"typescript": "2.7.1",
"web3-typescript-typings": "^0.9.8"
"web3-typescript-typings": "^0.9.9"
}
}

View File

@@ -2,14 +2,4 @@ const postpublish_utils = require('../../../scripts/postpublish_utils');
const packageJSON = require('../package.json');
const subPackageName = packageJSON.name;
postpublish_utils
.getLatestTagAndVersionAsync(subPackageName)
.then(function(result) {
const releaseName = postpublish_utils.getReleaseName(subPackageName, result.version);
const assets = [];
return postpublish_utils.publishReleaseNotes(result.tag, releaseName, assets);
})
.catch(function(err) {
throw err;
});
postpublish_utils.standardPostPublishAsync(subPackageName);

View File

@@ -17,6 +17,7 @@ import { utils } from './utils';
const ABI_TYPE_CONSTRUCTOR = 'constructor';
const ABI_TYPE_METHOD = 'function';
const ABI_TYPE_EVENT = 'event';
const DEFAULT_NETWORK_ID = 50;
const args = yargs
.option('abis', {
@@ -42,6 +43,11 @@ const args = yargs
demandOption: true,
normalize: true,
})
.option('network-id', {
describe: 'ID of the network where contract ABIs are nested in artifacts',
type: 'number',
default: DEFAULT_NETWORK_ID,
})
.example(
"$0 --abis 'src/artifacts/**/*.json' --out 'src/contracts/generated/' --partials 'src/templates/partials/**/*.handlebars' --template 'src/templates/contract.handlebars'",
'Full usage example',
@@ -58,7 +64,10 @@ function registerPartials(partialsGlob: string) {
}
function writeOutputFile(name: string, renderedTsCode: string): void {
const fileName = toSnakeCase(name);
let fileName = toSnakeCase(name);
if (fileName === 'z_r_x_token') {
fileName = 'zrx_token';
}
const filePath = `${args.output}/${fileName}.ts`;
fs.writeFileSync(filePath, renderedTsCode);
utils.log(`Created: ${chalk.bold(filePath)}`);
@@ -87,12 +96,19 @@ for (const abiFileName of abiFileNames) {
const namedContent = utils.getNamedContent(abiFileName);
utils.log(`Processing: ${chalk.bold(namedContent.name)}...`);
const parsedContent = JSON.parse(namedContent.content);
const ABI = _.isArray(parsedContent)
? parsedContent // ABI file
: parsedContent.abi; // Truffle contracts file
let ABI;
if (_.isArray(parsedContent)) {
ABI = parsedContent; // ABI file
} else if (!_.isUndefined(parsedContent.abi)) {
ABI = parsedContent.abi; // Truffle artifact
} else if (!_.isUndefined(parsedContent.networks) && !_.isUndefined(parsedContent.networks[args.networkId])) {
ABI = parsedContent.networks[args.networkId].abi; // 0x contracts package artifact
}
if (_.isUndefined(ABI)) {
utils.log(`${chalk.red(`ABI not found in ${abiFileName}.`)}`);
utils.log(`Please make sure your ABI file is either an array with ABI entries or an object with the abi key`);
utils.log(
`Please make sure your ABI file is either an array with ABI entries or a truffle artifact or 0x deployer artifact`,
);
process.exit(1);
}
@@ -103,10 +119,10 @@ for (const abiFileName of abiFileNames) {
const methodAbis = ABI.filter((abi: Web3.AbiDefinition) => abi.type === ABI_TYPE_METHOD) as Web3.MethodAbi[];
const methodsData = _.map(methodAbis, methodAbi => {
_.map(methodAbi.inputs, input => {
_.map(methodAbi.inputs, (input, i: number) => {
if (_.isEmpty(input.name)) {
// Auto-generated getters don't have parameter names
input.name = 'index';
input.name = `index_${i}`;
}
});
// This will make templates simpler

View File

@@ -0,0 +1,6 @@
.*
yarn-error.log
/src/
/scripts/
test/
tsconfig.json

View File

@@ -1,6 +1,10 @@
# CHANGELOG
## v0.0.4 - _Nov. 14, 2017_
## v0.0.18 - _February 9, 2017_
* Fix publishing issue where .npmignore was not properly excluding undesired content (#389)
## v0.0.4 - _November 14, 2017_
* Re-publish Assert previously published under NPM package @0xproject/0x-assert
* Added assertion isValidBaseUnitAmount which checks both that the value is a valid bigNumber and that it does not contain decimals.

View File

@@ -1,6 +1,6 @@
{
"name": "@0xproject/assert",
"version": "0.0.15",
"version": "0.0.17",
"description": "Provides a standard way of performing type and schema validation across 0x projects",
"main": "lib/src/index.js",
"types": "lib/src/index.d.ts",
@@ -24,7 +24,7 @@
},
"homepage": "https://github.com/0xProject/0x.js/packages/assert/README.md",
"devDependencies": {
"@0xproject/tslint-config": "^0.4.6",
"@0xproject/tslint-config": "^0.4.7",
"@types/lodash": "^4.14.86",
"@types/mocha": "^2.2.42",
"@types/valid-url": "^1.0.2",
@@ -38,8 +38,8 @@
"typescript": "2.7.1"
},
"dependencies": {
"@0xproject/json-schemas": "^0.7.7",
"@0xproject/utils": "^0.2.4",
"@0xproject/json-schemas": "^0.7.9",
"@0xproject/utils": "^0.3.1",
"lodash": "^4.17.4",
"valid-url": "^1.0.9"
}

View File

@@ -2,14 +2,4 @@ const postpublish_utils = require('../../../scripts/postpublish_utils');
const packageJSON = require('../package.json');
const subPackageName = packageJSON.name;
postpublish_utils
.getLatestTagAndVersionAsync(subPackageName)
.then(function(result) {
const releaseName = postpublish_utils.getReleaseName(subPackageName, result.version);
const assets = [];
return postpublish_utils.publishReleaseNotes(result.tag, releaseName, assets);
})
.catch(function(err) {
throw err;
});
postpublish_utils.standardPostPublishAsync(subPackageName);

View File

@@ -0,0 +1,3 @@
.*
yarn-error.log
/scripts/

View File

@@ -2,14 +2,4 @@ const postpublish_utils = require('../../../scripts/postpublish_utils');
const packageJSON = require('../package.json');
const subPackageName = packageJSON.name;
postpublish_utils
.getLatestTagAndVersionAsync(subPackageName)
.then(function(result) {
const releaseName = postpublish_utils.getReleaseName(subPackageName, result.version);
const assets = [];
return postpublish_utils.publishReleaseNotes(result.tag, releaseName, assets);
})
.catch(function(err) {
throw err;
});
postpublish_utils.standardPostPublishAsync(subPackageName);

View File

@@ -0,0 +1,3 @@
.*
yarn-error.log
/scripts/

View File

@@ -2,14 +2,4 @@ const postpublish_utils = require('../../../scripts/postpublish_utils');
const packageJSON = require('../package.json');
const subPackageName = packageJSON.name;
postpublish_utils
.getLatestTagAndVersionAsync(subPackageName)
.then(function(result) {
const releaseName = postpublish_utils.getReleaseName(subPackageName, result.version);
const assets = [];
return postpublish_utils.publishReleaseNotes(result.tag, releaseName, assets);
})
.catch(function(err) {
throw err;
});
postpublish_utils.standardPostPublishAsync(subPackageName);

View File

@@ -0,0 +1,7 @@
.*
yarn-error.log
/src/
/scripts/
/generated_docs/
test/
tsconfig.json

View File

@@ -1,5 +1,9 @@
# CHANGELOG
## v0.5.7 - _February 9, 2018_
* Fix publishing issue where .npmignore was not properly excluding undesired content (#389)
## v0.5.0 - _January 17, 2018_
* Sanitize api endpoint url and remove trailing slashes (#318)

View File

@@ -1,6 +1,6 @@
{
"name": "@0xproject/connect",
"version": "0.5.4",
"version": "0.5.6",
"description": "A javascript library for interacting with the standard relayer api",
"keywords": [
"connect",
@@ -37,16 +37,16 @@
},
"homepage": "https://github.com/0xProject/0x.js/packages/connect/README.md",
"dependencies": {
"@0xproject/assert": "^0.0.15",
"@0xproject/json-schemas": "^0.7.7",
"@0xproject/utils": "^0.2.4",
"@0xproject/assert": "^0.0.17",
"@0xproject/json-schemas": "^0.7.9",
"@0xproject/utils": "^0.3.1",
"isomorphic-fetch": "^2.2.1",
"lodash": "^4.17.4",
"query-string": "^5.0.1",
"websocket": "^1.0.25"
},
"devDependencies": {
"@0xproject/tslint-config": "^0.4.6",
"@0xproject/tslint-config": "^0.4.7",
"@types/fetch-mock": "^5.12.1",
"@types/lodash": "^4.14.86",
"@types/mocha": "^2.2.42",
@@ -65,6 +65,6 @@
"tslint": "5.8.0",
"typedoc": "~0.8.0",
"typescript": "2.7.1",
"web3-typescript-typings": "^0.9.8"
"web3-typescript-typings": "^0.9.9"
}
}

View File

@@ -0,0 +1,26 @@
/**
* This file is auto-generated using abi-gen. Don't edit directly.
* Templates can be found at https://github.com/0xProject/0x.js/tree/development/packages/abi-gen-templates.
*/
// tslint:disable:async-suffix member-ordering no-consecutive-blank-lines
// tslint:disable-next-line:no-unused-variable
import { TxData, TxDataPayable } from '@0xproject/types';
import { BigNumber, classUtils, promisify } from '@0xproject/utils';
import * as Web3 from 'web3';
import {BaseContract} from './base_contract';
export class {{contractName}}Contract extends BaseContract {
{{#each methods}}
{{#this.constant}}
{{> call contractName=../contractName}}
{{/this.constant}}
{{^this.constant}}
{{> tx contractName=../contractName}}
{{/this.constant}}
{{/each}}
constructor(web3ContractInstance: Web3.ContractInstance, defaults?: Partial<TxData>) {
super(web3ContractInstance, defaults);
classUtils.bindAll(this, ['_web3ContractInstance', '_defaults']);
}
} // tslint:disable:max-file-line-count

View File

@@ -0,0 +1,10 @@
public async {{this.name}}(
{{> typed_params inputs=inputs}}
defaultBlock?: Web3.BlockParam,
): Promise<{{> return_type outputs=outputs}}> {
const self = this as {{contractName}}Contract;
const result = await self._web3ContractInstance.{{this.name}}.call(
{{> params inputs=inputs}}
);
return result;
}

View File

@@ -0,0 +1,3 @@
{{#each inputs}}
{{name}},
{{/each}}

View File

@@ -0,0 +1,10 @@
{{#if outputs.length}}
{{#singleReturnValue}}
{{#returnType outputs.0.type}}{{/returnType}}
{{/singleReturnValue}}
{{^singleReturnValue}}
[{{#each outputs}}{{#returnType type}}{{/returnType}}{{#unless @last}}, {{/unless}}{{/each}}]
{{/singleReturnValue}}
{{else}}
void
{{/if}}

View File

@@ -0,0 +1,36 @@
public {{this.name}} = {
async sendTransactionAsync(
{{> typed_params inputs=inputs}}
{{#this.payable}}
txData: TxDataPayable = {},
{{/this.payable}}
{{^this.payable}}
txData: TxData = {},
{{/this.payable}}
): Promise<string> {
const self = this as {{contractName}}Contract;
const txDataWithDefaults = await self._applyDefaultsToTxDataAsync(txData);
const txHash = await self._web3ContractInstance.{{this.name}}(
{{> params inputs=inputs}}
txDataWithDefaults,
);
return txHash;
},
async callAsync(
{{> typed_params inputs=inputs}}
{{#this.payable}}
txData: TxDataPayable = {},
{{/this.payable}}
{{^this.payable}}
txData: TxData = {},
{{/this.payable}}
): Promise<{{> return_type outputs=outputs}}> {
const self = this as {{contractName}}Contract;
const txDataWithDefaults = await self._applyDefaultsToTxDataAsync(txData);
const returnValue = await self._web3ContractInstance.{{this.name}}.call(
{{> params inputs=inputs}}
txDataWithDefaults,
);
return returnValue;
},
};

View File

@@ -0,0 +1,3 @@
{{#each inputs}}
{{name}}: {{#parameterType type}}{{/parameterType}},
{{/each}}

View File

@@ -1,7 +1,7 @@
{
"private": true,
"name": "contracts",
"version": "2.1.8",
"version": "2.1.10",
"description": "Smart contract components of 0x protocol",
"main": "index.js",
"directories": {
@@ -9,14 +9,15 @@
},
"scripts": {
"build:watch": "tsc -w",
"prebuild": "run-s clean copy_artifacts",
"copy_artifacts": "copyfiles './artifacts/**/*' ./lib",
"prebuild": "run-s clean copy_artifacts generate_contract_wrappers",
"copy_artifacts": "copyfiles './src/artifacts/**/*' ./lib",
"build": "tsc",
"test": "run-s compile build run_mocha",
"run_mocha": "mocha 'lib/test/**/*.js' --timeout 10000 --bail --exit",
"compile:comment": "Yarn workspaces do not link binaries correctly so we need to reference them directly https://github.com/yarnpkg/yarn/issues/3846",
"compile": "node ../deployer/lib/src/cli.js compile",
"compile": "node ../deployer/lib/src/cli.js compile --contracts-dir src/contracts --artifacts-dir src/artifacts",
"clean": "rm -rf ./lib",
"generate_contract_wrappers": "node ../abi-gen/lib/index.js --abis 'src/artifacts/@(DummyToken|TokenTransferProxy|Exchange|TokenRegistry|MultiSigWallet|MultiSigWalletWithTimeLock|MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress|TokenRegistry|ZRXToken).json' --template contract_templates/contract.handlebars --partials 'contract_templates/partials/**/*.handlebars' --output src/contract_wrappers/generated",
"migrate": "node ../deployer/lib/src/cli.js migrate",
"lint": "tslint --project . 'migrations/**/*.ts' 'test/**/*.ts' 'util/**/*.ts' 'deploy/**/*.ts'",
"test:circleci": "yarn test"
@@ -32,9 +33,9 @@
},
"homepage": "https://github.com/0xProject/0x.js/packages/contracts/README.md",
"devDependencies": {
"@0xproject/dev-utils": "^0.0.9",
"@0xproject/tslint-config": "^0.4.6",
"@0xproject/types": "^0.1.8",
"@0xproject/dev-utils": "^0.0.11",
"@0xproject/tslint-config": "^0.4.7",
"@0xproject/types": "^0.2.0",
"@types/bluebird": "^3.5.3",
"@types/lodash": "^4.14.86",
"@types/node": "^8.0.53",
@@ -52,17 +53,17 @@
"solc": "^0.4.18",
"tslint": "5.8.0",
"types-bn": "^0.0.1",
"types-ethereumjs-util": "0xproject/types-ethereumjs-util",
"types-ethereumjs-util": "0xProject/types-ethereumjs-util",
"typescript": "2.7.1",
"web3-typescript-typings": "^0.9.8",
"web3-typescript-typings": "^0.9.9",
"yargs": "^10.0.3"
},
"dependencies": {
"0x.js": "^0.31.1",
"@0xproject/deployer": "^0.0.5",
"@0xproject/json-schemas": "^0.7.7",
"@0xproject/utils": "^0.2.4",
"@0xproject/web3-wrapper": "^0.1.9",
"0x.js": "^0.32.1",
"@0xproject/deployer": "^0.0.7",
"@0xproject/json-schemas": "^0.7.9",
"@0xproject/utils": "^0.3.1",
"@0xproject/web3-wrapper": "^0.1.11",
"bluebird": "^3.5.0",
"bn.js": "^4.11.8",
"ethereumjs-abi": "^0.6.4",

View File

@@ -0,0 +1,8 @@
dummy_token.ts
exchange.ts
multi_sig_wallet_with_time_lock_except_remove_authorized_address.ts
multi_sig_wallet_with_time_lock.ts
multi_sig_wallet.ts
token_registry.ts
token_transfer_proxy.ts
zrx_token.ts

View File

@@ -0,0 +1,35 @@
import {TxData, TxDataPayable} from '@0xproject/types';
import * as _ from 'lodash';
import * as Web3 from 'web3';
export class BaseContract {
public address: string;
protected _web3ContractInstance: Web3.ContractInstance;
protected _defaults: Partial<TxData>;
protected async _applyDefaultsToTxDataAsync<T extends TxData|TxDataPayable>(
txData: T,
estimateGasAsync?: (txData: T) => Promise<number>,
): Promise<TxData> {
// Gas amount sourced with the following priorities:
// 1. Optional param passed in to public method call
// 2. Global config passed in at library instantiation
// 3. Gas estimate calculation + safety margin
const removeUndefinedProperties = _.pickBy;
const txDataWithDefaults = {
...removeUndefinedProperties(this._defaults),
...removeUndefinedProperties(txData as any),
// HACK: TS can't prove that T is spreadable.
// Awaiting https://github.com/Microsoft/TypeScript/pull/13288 to be merged
};
if (_.isUndefined(txDataWithDefaults.gas) && !_.isUndefined(estimateGasAsync)) {
const estimatedGas = await estimateGasAsync(txData);
txDataWithDefaults.gas = estimatedGas;
}
return txDataWithDefaults;
}
constructor(web3ContractInstance: Web3.ContractInstance, defaults?: Partial<TxData>) {
this.address = web3ContractInstance.address;
this._web3ContractInstance = web3ContractInstance;
this._defaults = defaults || {};
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,13 +1,13 @@
import { ZeroEx } from '0x.js';
import { SignedOrder, ZeroEx } from '0x.js';
import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
import ethUtil = require('ethereumjs-util');
import { ExchangeContract } from '../../src/contract_wrappers/generated/exchange';
import { constants } from '../../util/constants';
import { ExchangeWrapper } from '../../util/exchange_wrapper';
import { Order } from '../../util/order';
import { OrderFactory } from '../../util/order_factory';
import { ContractName } from '../../util/types';
import { chaiSetup } from '../utils/chai_setup';
@@ -24,7 +24,7 @@ describe('Exchange', () => {
let maker: string;
let feeRecipient: string;
let order: Order;
let signedOrder: SignedOrder;
let exchangeWrapper: ExchangeWrapper;
let orderFactory: OrderFactory;
@@ -38,7 +38,11 @@ describe('Exchange', () => {
deployer.deployAsync(ContractName.DummyToken),
deployer.deployAsync(ContractName.DummyToken),
]);
const exchange = await deployer.deployAsync(ContractName.Exchange, [zrx.address, tokenTransferProxy.address]);
const exchangeInstance = await deployer.deployAsync(ContractName.Exchange, [
zrx.address,
tokenTransferProxy.address,
]);
const exchange = new ExchangeContract(exchangeInstance);
await tokenTransferProxy.addAuthorizedAddress(exchange.address, { from: accounts[0] });
const zeroEx = new ZeroEx(web3.currentProvider, { networkId: constants.TESTRPC_NETWORK_ID });
exchangeWrapper = new ExchangeWrapper(exchange, zeroEx);
@@ -53,8 +57,8 @@ describe('Exchange', () => {
makerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
takerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
};
orderFactory = new OrderFactory(web3Wrapper, defaultOrderParams);
order = await orderFactory.newSignedOrderAsync();
orderFactory = new OrderFactory(zeroEx, defaultOrderParams);
signedOrder = await orderFactory.newSignedOrderAsync();
});
beforeEach(async () => {
@@ -65,28 +69,31 @@ describe('Exchange', () => {
});
describe('getOrderHash', () => {
it('should output the correct orderHash', async () => {
const orderHashHex = await exchangeWrapper.getOrderHashAsync(order);
expect(order.params.orderHashHex).to.be.equal(orderHashHex);
const orderHashHex = await exchangeWrapper.getOrderHashAsync(signedOrder);
expect(ZeroEx.getOrderHashHex(signedOrder)).to.be.equal(orderHashHex);
});
});
describe('isValidSignature', () => {
beforeEach(async () => {
order = await orderFactory.newSignedOrderAsync();
signedOrder = await orderFactory.newSignedOrderAsync();
});
it('should return true with a valid signature', async () => {
const success = await exchangeWrapper.isValidSignatureAsync(order);
const isValidSignature = order.isValidSignature();
const success = await exchangeWrapper.isValidSignatureAsync(signedOrder);
const orderHashHex = ZeroEx.getOrderHashHex(signedOrder);
const isValidSignature = ZeroEx.isValidSignature(orderHashHex, signedOrder.ecSignature, signedOrder.maker);
expect(isValidSignature).to.be.true();
expect(success).to.be.true();
});
it('should return false with an invalid signature', async () => {
order.params.r = ethUtil.bufferToHex(ethUtil.sha3('invalidR'));
order.params.s = ethUtil.bufferToHex(ethUtil.sha3('invalidS'));
const success = await exchangeWrapper.isValidSignatureAsync(order);
expect(order.isValidSignature()).to.be.false();
signedOrder.ecSignature.r = ethUtil.bufferToHex(ethUtil.sha3('invalidR'));
signedOrder.ecSignature.s = ethUtil.bufferToHex(ethUtil.sha3('invalidS'));
const success = await exchangeWrapper.isValidSignatureAsync(signedOrder);
const orderHashHex = ZeroEx.getOrderHashHex(signedOrder);
const isValidSignature = ZeroEx.isValidSignature(orderHashHex, signedOrder.ecSignature, signedOrder.maker);
expect(isValidSignature).to.be.false();
expect(success).to.be.false();
});
});

View File

@@ -1,4 +1,4 @@
import { ZeroEx } from '0x.js';
import { SignedOrder, ZeroEx } from '0x.js';
import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
@@ -6,10 +6,13 @@ import * as chai from 'chai';
import * as _ from 'lodash';
import * as Web3 from 'web3';
import { DummyTokenContract } from '../../src/contract_wrappers/generated/dummy_token';
import { ExchangeContract } from '../../src/contract_wrappers/generated/exchange';
import { TokenRegistryContract } from '../../src/contract_wrappers/generated/token_registry';
import { TokenTransferProxyContract } from '../../src/contract_wrappers/generated/token_transfer_proxy';
import { Balances } from '../../util/balances';
import { constants } from '../../util/constants';
import { ExchangeWrapper } from '../../util/exchange_wrapper';
import { Order } from '../../util/order';
import { OrderFactory } from '../../util/order_factory';
import { BalancesByOwner, ContractName } from '../../util/types';
import { chaiSetup } from '../utils/chai_setup';
@@ -30,12 +33,12 @@ describe('Exchange', () => {
const INIT_BAL = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18);
const INIT_ALLOW = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18);
let rep: Web3.ContractInstance;
let dgd: Web3.ContractInstance;
let zrx: Web3.ContractInstance;
let exchange: Web3.ContractInstance;
let tokenRegistry: Web3.ContractInstance;
let tokenTransferProxy: Web3.ContractInstance;
let rep: DummyTokenContract;
let dgd: DummyTokenContract;
let zrx: DummyTokenContract;
let exchange: ExchangeContract;
let tokenRegistry: TokenRegistryContract;
let tokenTransferProxy: TokenTransferProxyContract;
let balances: BalancesByOwner;
@@ -47,15 +50,24 @@ describe('Exchange', () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync();
tokenOwner = accounts[0];
[maker, taker, feeRecipient] = accounts;
[rep, dgd, zrx] = await Promise.all([
const [repInstance, dgdInstance, zrxInstance] = await Promise.all([
deployer.deployAsync(ContractName.DummyToken),
deployer.deployAsync(ContractName.DummyToken),
deployer.deployAsync(ContractName.DummyToken),
]);
tokenRegistry = await deployer.deployAsync(ContractName.TokenRegistry);
tokenTransferProxy = await deployer.deployAsync(ContractName.TokenTransferProxy);
exchange = await deployer.deployAsync(ContractName.Exchange, [zrx.address, tokenTransferProxy.address]);
await tokenTransferProxy.addAuthorizedAddress(exchange.address, { from: accounts[0] });
rep = new DummyTokenContract(repInstance);
dgd = new DummyTokenContract(dgdInstance);
zrx = new DummyTokenContract(zrxInstance);
const tokenRegistryInstance = await deployer.deployAsync(ContractName.TokenRegistry);
tokenRegistry = new TokenRegistryContract(tokenRegistryInstance);
const tokenTransferProxyInstance = await deployer.deployAsync(ContractName.TokenTransferProxy);
tokenTransferProxy = new TokenTransferProxyContract(tokenTransferProxyInstance);
const exchangeInstance = await deployer.deployAsync(ContractName.Exchange, [
zrx.address,
tokenTransferProxy.address,
]);
exchange = new ExchangeContract(exchangeInstance);
await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: accounts[0] });
const zeroEx = new ZeroEx(web3.currentProvider, { networkId: constants.TESTRPC_NETWORK_ID });
exWrapper = new ExchangeWrapper(exchange, zeroEx);
@@ -63,29 +75,29 @@ describe('Exchange', () => {
exchangeContractAddress: exchange.address,
maker,
feeRecipient,
makerToken: rep.address,
takerToken: dgd.address,
makerTokenAddress: rep.address,
takerTokenAddress: dgd.address,
makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
makerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
takerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
};
orderFactory = new OrderFactory(web3Wrapper, defaultOrderParams);
orderFactory = new OrderFactory(zeroEx, defaultOrderParams);
dmyBalances = new Balances([rep, dgd, zrx], [maker, taker, feeRecipient]);
await Promise.all([
rep.approve(tokenTransferProxy.address, INIT_ALLOW, { from: maker }),
rep.approve(tokenTransferProxy.address, INIT_ALLOW, { from: taker }),
rep.setBalance(maker, INIT_BAL, { from: tokenOwner }),
rep.setBalance(taker, INIT_BAL, { from: tokenOwner }),
dgd.approve(tokenTransferProxy.address, INIT_ALLOW, { from: maker }),
dgd.approve(tokenTransferProxy.address, INIT_ALLOW, { from: taker }),
dgd.setBalance(maker, INIT_BAL, { from: tokenOwner }),
dgd.setBalance(taker, INIT_BAL, { from: tokenOwner }),
zrx.approve(tokenTransferProxy.address, INIT_ALLOW, { from: maker }),
zrx.approve(tokenTransferProxy.address, INIT_ALLOW, { from: taker }),
zrx.setBalance(maker, INIT_BAL, { from: tokenOwner }),
zrx.setBalance(taker, INIT_BAL, { from: tokenOwner }),
rep.approve.sendTransactionAsync(tokenTransferProxy.address, INIT_ALLOW, { from: maker }),
rep.approve.sendTransactionAsync(tokenTransferProxy.address, INIT_ALLOW, { from: taker }),
rep.setBalance.sendTransactionAsync(maker, INIT_BAL, { from: tokenOwner }),
rep.setBalance.sendTransactionAsync(taker, INIT_BAL, { from: tokenOwner }),
dgd.approve.sendTransactionAsync(tokenTransferProxy.address, INIT_ALLOW, { from: maker }),
dgd.approve.sendTransactionAsync(tokenTransferProxy.address, INIT_ALLOW, { from: taker }),
dgd.setBalance.sendTransactionAsync(maker, INIT_BAL, { from: tokenOwner }),
dgd.setBalance.sendTransactionAsync(taker, INIT_BAL, { from: tokenOwner }),
zrx.approve.sendTransactionAsync(tokenTransferProxy.address, INIT_ALLOW, { from: maker }),
zrx.approve.sendTransactionAsync(tokenTransferProxy.address, INIT_ALLOW, { from: taker }),
zrx.setBalance.sendTransactionAsync(maker, INIT_BAL, { from: tokenOwner }),
zrx.setBalance.sendTransactionAsync(taker, INIT_BAL, { from: tokenOwner }),
]);
});
beforeEach(async () => {
@@ -100,38 +112,38 @@ describe('Exchange', () => {
});
it('should transfer the correct amounts', async () => {
const order = await orderFactory.newSignedOrderAsync({
const signedOrder = await orderFactory.newSignedOrderAsync({
makerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(100), 18),
takerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(200), 18),
});
const fillTakerTokenAmount = order.params.takerTokenAmount.div(2);
await exWrapper.fillOrKillOrderAsync(order, taker, {
const fillTakerTokenAmount = signedOrder.takerTokenAmount.div(2);
await exWrapper.fillOrKillOrderAsync(signedOrder, taker, {
fillTakerTokenAmount,
});
const newBalances = await dmyBalances.getAsync();
const fillMakerTokenAmount = fillTakerTokenAmount
.times(order.params.makerTokenAmount)
.dividedToIntegerBy(order.params.takerTokenAmount);
const makerFee = order.params.makerFee
.times(signedOrder.makerTokenAmount)
.dividedToIntegerBy(signedOrder.takerTokenAmount);
const makerFee = signedOrder.makerFee
.times(fillMakerTokenAmount)
.dividedToIntegerBy(order.params.makerTokenAmount);
const takerFee = order.params.takerFee
.dividedToIntegerBy(signedOrder.makerTokenAmount);
const takerFee = signedOrder.takerFee
.times(fillMakerTokenAmount)
.dividedToIntegerBy(order.params.makerTokenAmount);
expect(newBalances[maker][order.params.makerToken]).to.be.bignumber.equal(
balances[maker][order.params.makerToken].minus(fillMakerTokenAmount),
.dividedToIntegerBy(signedOrder.makerTokenAmount);
expect(newBalances[maker][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
balances[maker][signedOrder.makerTokenAddress].minus(fillMakerTokenAmount),
);
expect(newBalances[maker][order.params.takerToken]).to.be.bignumber.equal(
balances[maker][order.params.takerToken].add(fillTakerTokenAmount),
expect(newBalances[maker][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
balances[maker][signedOrder.takerTokenAddress].add(fillTakerTokenAmount),
);
expect(newBalances[maker][zrx.address]).to.be.bignumber.equal(balances[maker][zrx.address].minus(makerFee));
expect(newBalances[taker][order.params.takerToken]).to.be.bignumber.equal(
balances[taker][order.params.takerToken].minus(fillTakerTokenAmount),
expect(newBalances[taker][signedOrder.takerTokenAddress]).to.be.bignumber.equal(
balances[taker][signedOrder.takerTokenAddress].minus(fillTakerTokenAmount),
);
expect(newBalances[taker][order.params.makerToken]).to.be.bignumber.equal(
balances[taker][order.params.makerToken].add(fillMakerTokenAmount),
expect(newBalances[taker][signedOrder.makerTokenAddress]).to.be.bignumber.equal(
balances[taker][signedOrder.makerTokenAddress].add(fillMakerTokenAmount),
);
expect(newBalances[taker][zrx.address]).to.be.bignumber.equal(balances[taker][zrx.address].minus(takerFee));
expect(newBalances[feeRecipient][zrx.address]).to.be.bignumber.equal(
@@ -139,30 +151,30 @@ describe('Exchange', () => {
);
});
it('should throw if an order is expired', async () => {
const order = await orderFactory.newSignedOrderAsync({
expirationTimestampInSec: new BigNumber(Math.floor((Date.now() - 10000) / 1000)),
it('should throw if an signedOrder is expired', async () => {
const signedOrder = await orderFactory.newSignedOrderAsync({
expirationUnixTimestampSec: new BigNumber(Math.floor((Date.now() - 10000) / 1000)),
});
return expect(exWrapper.fillOrKillOrderAsync(order, taker)).to.be.rejectedWith(constants.REVERT);
return expect(exWrapper.fillOrKillOrderAsync(signedOrder, taker)).to.be.rejectedWith(constants.REVERT);
});
it('should throw if entire fillTakerTokenAmount not filled', async () => {
const order = await orderFactory.newSignedOrderAsync();
const signedOrder = await orderFactory.newSignedOrderAsync();
const from = taker;
await exWrapper.fillOrderAsync(order, from, {
fillTakerTokenAmount: order.params.takerTokenAmount.div(2),
await exWrapper.fillOrderAsync(signedOrder, from, {
fillTakerTokenAmount: signedOrder.takerTokenAmount.div(2),
});
return expect(exWrapper.fillOrKillOrderAsync(order, taker)).to.be.rejectedWith(constants.REVERT);
return expect(exWrapper.fillOrKillOrderAsync(signedOrder, taker)).to.be.rejectedWith(constants.REVERT);
});
});
describe('batch functions', () => {
let orders: Order[];
let signedOrders: SignedOrder[];
beforeEach(async () => {
orders = await Promise.all([
signedOrders = await Promise.all([
orderFactory.newSignedOrderAsync(),
orderFactory.newSignedOrderAsync(),
orderFactory.newSignedOrderAsync(),
@@ -173,32 +185,32 @@ describe('Exchange', () => {
describe('batchFillOrders', () => {
it('should transfer the correct amounts', async () => {
const fillTakerTokenAmounts: BigNumber[] = [];
const makerToken = rep.address;
const takerToken = dgd.address;
orders.forEach(order => {
const fillTakerTokenAmount = order.params.takerTokenAmount.div(2);
const makerTokenAddress = rep.address;
const takerTokenAddress = dgd.address;
signedOrders.forEach(signedOrder => {
const fillTakerTokenAmount = signedOrder.takerTokenAmount.div(2);
const fillMakerTokenAmount = fillTakerTokenAmount
.times(order.params.makerTokenAmount)
.dividedToIntegerBy(order.params.takerTokenAmount);
const makerFee = order.params.makerFee
.times(signedOrder.makerTokenAmount)
.dividedToIntegerBy(signedOrder.takerTokenAmount);
const makerFee = signedOrder.makerFee
.times(fillMakerTokenAmount)
.dividedToIntegerBy(order.params.makerTokenAmount);
const takerFee = order.params.takerFee
.dividedToIntegerBy(signedOrder.makerTokenAmount);
const takerFee = signedOrder.takerFee
.times(fillMakerTokenAmount)
.dividedToIntegerBy(order.params.makerTokenAmount);
.dividedToIntegerBy(signedOrder.makerTokenAmount);
fillTakerTokenAmounts.push(fillTakerTokenAmount);
balances[maker][makerToken] = balances[maker][makerToken].minus(fillMakerTokenAmount);
balances[maker][takerToken] = balances[maker][takerToken].add(fillTakerTokenAmount);
balances[maker][makerTokenAddress] = balances[maker][makerTokenAddress].minus(fillMakerTokenAmount);
balances[maker][takerTokenAddress] = balances[maker][takerTokenAddress].add(fillTakerTokenAmount);
balances[maker][zrx.address] = balances[maker][zrx.address].minus(makerFee);
balances[taker][makerToken] = balances[taker][makerToken].add(fillMakerTokenAmount);
balances[taker][takerToken] = balances[taker][takerToken].minus(fillTakerTokenAmount);
balances[taker][makerTokenAddress] = balances[taker][makerTokenAddress].add(fillMakerTokenAmount);
balances[taker][takerTokenAddress] = balances[taker][takerTokenAddress].minus(fillTakerTokenAmount);
balances[taker][zrx.address] = balances[taker][zrx.address].minus(takerFee);
balances[feeRecipient][zrx.address] = balances[feeRecipient][zrx.address].add(
makerFee.add(takerFee),
);
});
await exWrapper.batchFillOrdersAsync(orders, taker, {
await exWrapper.batchFillOrdersAsync(signedOrders, taker, {
fillTakerTokenAmounts,
});
@@ -210,32 +222,32 @@ describe('Exchange', () => {
describe('batchFillOrKillOrders', () => {
it('should transfer the correct amounts', async () => {
const fillTakerTokenAmounts: BigNumber[] = [];
const makerToken = rep.address;
const takerToken = dgd.address;
orders.forEach(order => {
const fillTakerTokenAmount = order.params.takerTokenAmount.div(2);
const makerTokenAddress = rep.address;
const takerTokenAddress = dgd.address;
signedOrders.forEach(signedOrder => {
const fillTakerTokenAmount = signedOrder.takerTokenAmount.div(2);
const fillMakerTokenAmount = fillTakerTokenAmount
.times(order.params.makerTokenAmount)
.dividedToIntegerBy(order.params.takerTokenAmount);
const makerFee = order.params.makerFee
.times(signedOrder.makerTokenAmount)
.dividedToIntegerBy(signedOrder.takerTokenAmount);
const makerFee = signedOrder.makerFee
.times(fillMakerTokenAmount)
.dividedToIntegerBy(order.params.makerTokenAmount);
const takerFee = order.params.takerFee
.dividedToIntegerBy(signedOrder.makerTokenAmount);
const takerFee = signedOrder.takerFee
.times(fillMakerTokenAmount)
.dividedToIntegerBy(order.params.makerTokenAmount);
.dividedToIntegerBy(signedOrder.makerTokenAmount);
fillTakerTokenAmounts.push(fillTakerTokenAmount);
balances[maker][makerToken] = balances[maker][makerToken].minus(fillMakerTokenAmount);
balances[maker][takerToken] = balances[maker][takerToken].add(fillTakerTokenAmount);
balances[maker][makerTokenAddress] = balances[maker][makerTokenAddress].minus(fillMakerTokenAmount);
balances[maker][takerTokenAddress] = balances[maker][takerTokenAddress].add(fillTakerTokenAmount);
balances[maker][zrx.address] = balances[maker][zrx.address].minus(makerFee);
balances[taker][makerToken] = balances[taker][makerToken].add(fillMakerTokenAmount);
balances[taker][takerToken] = balances[taker][takerToken].minus(fillTakerTokenAmount);
balances[taker][makerTokenAddress] = balances[taker][makerTokenAddress].add(fillMakerTokenAmount);
balances[taker][takerTokenAddress] = balances[taker][takerTokenAddress].minus(fillTakerTokenAmount);
balances[taker][zrx.address] = balances[taker][zrx.address].minus(takerFee);
balances[feeRecipient][zrx.address] = balances[feeRecipient][zrx.address].add(
makerFee.add(takerFee),
);
});
await exWrapper.batchFillOrKillOrdersAsync(orders, taker, {
await exWrapper.batchFillOrKillOrdersAsync(signedOrders, taker, {
fillTakerTokenAmounts,
});
@@ -243,17 +255,17 @@ describe('Exchange', () => {
expect(newBalances).to.be.deep.equal(balances);
});
it('should throw if a single order does not fill the expected amount', async () => {
it('should throw if a single signedOrder does not fill the expected amount', async () => {
const fillTakerTokenAmounts: BigNumber[] = [];
orders.forEach(order => {
const fillTakerTokenAmount = order.params.takerTokenAmount.div(2);
signedOrders.forEach(signedOrder => {
const fillTakerTokenAmount = signedOrder.takerTokenAmount.div(2);
fillTakerTokenAmounts.push(fillTakerTokenAmount);
});
await exWrapper.fillOrKillOrderAsync(orders[0], taker);
await exWrapper.fillOrKillOrderAsync(signedOrders[0], taker);
return expect(
exWrapper.batchFillOrKillOrdersAsync(orders, taker, {
exWrapper.batchFillOrKillOrdersAsync(signedOrders, taker, {
fillTakerTokenAmounts,
}),
).to.be.rejectedWith(constants.REVERT);
@@ -262,34 +274,34 @@ describe('Exchange', () => {
describe('fillOrdersUpTo', () => {
it('should stop when the entire fillTakerTokenAmount is filled', async () => {
const fillTakerTokenAmount = orders[0].params.takerTokenAmount.plus(
orders[1].params.takerTokenAmount.div(2),
const fillTakerTokenAmount = signedOrders[0].takerTokenAmount.plus(
signedOrders[1].takerTokenAmount.div(2),
);
await exWrapper.fillOrdersUpToAsync(orders, taker, {
await exWrapper.fillOrdersUpToAsync(signedOrders, taker, {
fillTakerTokenAmount,
});
const newBalances = await dmyBalances.getAsync();
const fillMakerTokenAmount = orders[0].params.makerTokenAmount.add(
orders[1].params.makerTokenAmount.dividedToIntegerBy(2),
const fillMakerTokenAmount = signedOrders[0].makerTokenAmount.add(
signedOrders[1].makerTokenAmount.dividedToIntegerBy(2),
);
const makerFee = orders[0].params.makerFee.add(orders[1].params.makerFee.dividedToIntegerBy(2));
const takerFee = orders[0].params.takerFee.add(orders[1].params.takerFee.dividedToIntegerBy(2));
expect(newBalances[maker][orders[0].params.makerToken]).to.be.bignumber.equal(
balances[maker][orders[0].params.makerToken].minus(fillMakerTokenAmount),
const makerFee = signedOrders[0].makerFee.add(signedOrders[1].makerFee.dividedToIntegerBy(2));
const takerFee = signedOrders[0].takerFee.add(signedOrders[1].takerFee.dividedToIntegerBy(2));
expect(newBalances[maker][signedOrders[0].makerTokenAddress]).to.be.bignumber.equal(
balances[maker][signedOrders[0].makerTokenAddress].minus(fillMakerTokenAmount),
);
expect(newBalances[maker][orders[0].params.takerToken]).to.be.bignumber.equal(
balances[maker][orders[0].params.takerToken].add(fillTakerTokenAmount),
expect(newBalances[maker][signedOrders[0].takerTokenAddress]).to.be.bignumber.equal(
balances[maker][signedOrders[0].takerTokenAddress].add(fillTakerTokenAmount),
);
expect(newBalances[maker][zrx.address]).to.be.bignumber.equal(
balances[maker][zrx.address].minus(makerFee),
);
expect(newBalances[taker][orders[0].params.takerToken]).to.be.bignumber.equal(
balances[taker][orders[0].params.takerToken].minus(fillTakerTokenAmount),
expect(newBalances[taker][signedOrders[0].takerTokenAddress]).to.be.bignumber.equal(
balances[taker][signedOrders[0].takerTokenAddress].minus(fillTakerTokenAmount),
);
expect(newBalances[taker][orders[0].params.makerToken]).to.be.bignumber.equal(
balances[taker][orders[0].params.makerToken].add(fillMakerTokenAmount),
expect(newBalances[taker][signedOrders[0].makerTokenAddress]).to.be.bignumber.equal(
balances[taker][signedOrders[0].makerTokenAddress].add(fillMakerTokenAmount),
);
expect(newBalances[taker][zrx.address]).to.be.bignumber.equal(
balances[taker][zrx.address].minus(takerFee),
@@ -299,28 +311,28 @@ describe('Exchange', () => {
);
});
it('should fill all orders if cannot fill entire fillTakerTokenAmount', async () => {
it('should fill all signedOrders if cannot fill entire fillTakerTokenAmount', async () => {
const fillTakerTokenAmount = ZeroEx.toBaseUnitAmount(new BigNumber(100000), 18);
orders.forEach(order => {
balances[maker][order.params.makerToken] = balances[maker][order.params.makerToken].minus(
order.params.makerTokenAmount,
signedOrders.forEach(signedOrder => {
balances[maker][signedOrder.makerTokenAddress] = balances[maker][
signedOrder.makerTokenAddress
].minus(signedOrder.makerTokenAmount);
balances[maker][signedOrder.takerTokenAddress] = balances[maker][signedOrder.takerTokenAddress].add(
signedOrder.takerTokenAmount,
);
balances[maker][order.params.takerToken] = balances[maker][order.params.takerToken].add(
order.params.takerTokenAmount,
balances[maker][zrx.address] = balances[maker][zrx.address].minus(signedOrder.makerFee);
balances[taker][signedOrder.makerTokenAddress] = balances[taker][signedOrder.makerTokenAddress].add(
signedOrder.makerTokenAmount,
);
balances[maker][zrx.address] = balances[maker][zrx.address].minus(order.params.makerFee);
balances[taker][order.params.makerToken] = balances[taker][order.params.makerToken].add(
order.params.makerTokenAmount,
);
balances[taker][order.params.takerToken] = balances[taker][order.params.takerToken].minus(
order.params.takerTokenAmount,
);
balances[taker][zrx.address] = balances[taker][zrx.address].minus(order.params.takerFee);
balances[taker][signedOrder.takerTokenAddress] = balances[taker][
signedOrder.takerTokenAddress
].minus(signedOrder.takerTokenAmount);
balances[taker][zrx.address] = balances[taker][zrx.address].minus(signedOrder.takerFee);
balances[feeRecipient][zrx.address] = balances[feeRecipient][zrx.address].add(
order.params.makerFee.add(order.params.takerFee),
signedOrder.makerFee.add(signedOrder.takerFee),
);
});
await exWrapper.fillOrdersUpToAsync(orders, taker, {
await exWrapper.fillOrdersUpToAsync(signedOrders, taker, {
fillTakerTokenAmount,
});
@@ -328,15 +340,15 @@ describe('Exchange', () => {
expect(newBalances).to.be.deep.equal(balances);
});
it('should throw when an order does not use the same takerToken', async () => {
orders = await Promise.all([
it('should throw when an signedOrder does not use the same takerTokenAddress', async () => {
signedOrders = await Promise.all([
orderFactory.newSignedOrderAsync(),
orderFactory.newSignedOrderAsync({ takerToken: zrx.address }),
orderFactory.newSignedOrderAsync({ takerTokenAddress: zrx.address }),
orderFactory.newSignedOrderAsync(),
]);
return expect(
exWrapper.fillOrdersUpToAsync(orders, taker, {
exWrapper.fillOrdersUpToAsync(signedOrders, taker, {
fillTakerTokenAmount: ZeroEx.toBaseUnitAmount(new BigNumber(1000), 18),
}),
).to.be.rejectedWith(constants.REVERT);
@@ -344,13 +356,13 @@ describe('Exchange', () => {
});
describe('batchCancelOrders', () => {
it('should be able to cancel multiple orders', async () => {
const cancelTakerTokenAmounts = _.map(orders, order => order.params.takerTokenAmount);
await exWrapper.batchCancelOrdersAsync(orders, maker, {
it('should be able to cancel multiple signedOrders', async () => {
const cancelTakerTokenAmounts = _.map(signedOrders, signedOrder => signedOrder.takerTokenAmount);
await exWrapper.batchCancelOrdersAsync(signedOrders, maker, {
cancelTakerTokenAmounts,
});
await exWrapper.batchFillOrdersAsync(orders, taker, {
await exWrapper.batchFillOrdersAsync(signedOrders, taker, {
fillTakerTokenAmounts: cancelTakerTokenAmounts,
});
const newBalances = await dmyBalances.getAsync();

View File

@@ -6,6 +6,8 @@ import * as chai from 'chai';
import * as Web3 from 'web3';
import * as multiSigWalletJSON from '../../build/contracts/MultiSigWalletWithTimeLock.json';
import { MultiSigWalletContract } from '../src/contract_wrappers/generated/multi_sig_wallet';
import { MultiSigWalletWithTimeLockContract } from '../src/contract_wrappers/generated/multi_sig_wallet_with_time_lock';
import { artifacts } from '../util/artifacts';
import { constants } from '../util/constants';
import { MultiSigWrapper } from '../util/multi_sig_wrapper';
@@ -30,12 +32,12 @@ describe('MultiSigWalletWithTimeLock', () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync();
owners = [accounts[0], accounts[1]];
});
const SIGNATURES_REQUIRED = 2;
const SECONDS_TIME_LOCKED = 10000;
const SIGNATURES_REQUIRED = new BigNumber(2);
const SECONDS_TIME_LOCKED = new BigNumber(10000);
let multiSig: Web3.ContractInstance;
let multiSig: MultiSigWalletWithTimeLockContract;
let multiSigWrapper: MultiSigWrapper;
let txId: number;
let txId: BigNumber;
let initialSecondsTimeLocked: number;
let rpc: RPC;
@@ -52,20 +54,21 @@ describe('MultiSigWalletWithTimeLock', () => {
describe('changeTimeLock', () => {
describe('initially non-time-locked', async () => {
before('deploy a walet', async () => {
multiSig = await deployer.deployAsync(ContractName.MultiSigWalletWithTimeLock, [
const multiSigInstance = await deployer.deployAsync(ContractName.MultiSigWalletWithTimeLock, [
owners,
SIGNATURES_REQUIRED,
0,
]);
multiSigWrapper = new MultiSigWrapper(multiSig);
multiSig = new MultiSigWalletWithTimeLockContract(multiSigInstance);
multiSigWrapper = new MultiSigWrapper((multiSig as any) as MultiSigWalletContract);
const secondsTimeLocked = await multiSig.secondsTimeLocked();
initialSecondsTimeLocked = secondsTimeLocked.toNumber();
});
it('should throw when not called by wallet', async () => {
return expect(multiSig.changeTimeLock(SECONDS_TIME_LOCKED, { from: owners[0] })).to.be.rejectedWith(
constants.REVERT,
);
return expect(
multiSig.changeTimeLock.sendTransactionAsync(SECONDS_TIME_LOCKED, { from: owners[0] }),
).to.be.rejectedWith(constants.REVERT);
});
it('should throw without enough confirmations', async () => {
@@ -74,7 +77,7 @@ describe('MultiSigWalletWithTimeLock', () => {
const dataParams = {
name: 'changeTimeLock',
abi: MULTI_SIG_ABI,
args: [SECONDS_TIME_LOCKED],
args: [SECONDS_TIME_LOCKED.toNumber()],
};
const txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams);
const subRes = await zeroEx.awaitTransactionMinedAsync(txHash);
@@ -82,10 +85,10 @@ describe('MultiSigWalletWithTimeLock', () => {
SubmissionContractEventArgs
>;
txId = log.args.transactionId.toNumber();
return expect(multiSig.executeTransaction(txId, { from: owners[0] })).to.be.rejectedWith(
constants.REVERT,
);
txId = log.args.transactionId;
return expect(
multiSig.executeTransaction.sendTransactionAsync(txId, { from: owners[0] }),
).to.be.rejectedWith(constants.REVERT);
});
it('should set confirmation time with enough confirmations', async () => {
@@ -94,7 +97,7 @@ describe('MultiSigWalletWithTimeLock', () => {
const dataParams = {
name: 'changeTimeLock',
abi: MULTI_SIG_ABI,
args: [SECONDS_TIME_LOCKED],
args: [SECONDS_TIME_LOCKED.toNumber()],
};
let txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams);
const subRes = await zeroEx.awaitTransactionMinedAsync(txHash);
@@ -102,15 +105,15 @@ describe('MultiSigWalletWithTimeLock', () => {
SubmissionContractEventArgs
>;
txId = log.args.transactionId.toNumber();
txHash = await multiSig.confirmTransaction(txId, { from: owners[1] });
txId = log.args.transactionId;
txHash = await multiSig.confirmTransaction.sendTransactionAsync(txId, { from: owners[1] });
const res = await zeroEx.awaitTransactionMinedAsync(txHash);
expect(res.logs).to.have.length(2);
const blockNum = await web3Wrapper.getBlockNumberAsync();
const blockInfo = await web3Wrapper.getBlockAsync(blockNum);
const timestamp = new BigNumber(blockInfo.timestamp);
const confirmationTimeBigNum = new BigNumber(await multiSig.confirmationTimes.call(txId));
const confirmationTimeBigNum = new BigNumber(await multiSig.confirmationTimes(txId));
expect(timestamp).to.be.bignumber.equal(confirmationTimeBigNum);
});
@@ -121,7 +124,7 @@ describe('MultiSigWalletWithTimeLock', () => {
const dataParams = {
name: 'changeTimeLock',
abi: MULTI_SIG_ABI,
args: [SECONDS_TIME_LOCKED],
args: [SECONDS_TIME_LOCKED.toNumber()],
};
let txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams);
const subRes = await zeroEx.awaitTransactionMinedAsync(txHash);
@@ -129,27 +132,28 @@ describe('MultiSigWalletWithTimeLock', () => {
SubmissionContractEventArgs
>;
txId = log.args.transactionId.toNumber();
txHash = await multiSig.confirmTransaction(txId, { from: owners[1] });
txId = log.args.transactionId;
txHash = await multiSig.confirmTransaction.sendTransactionAsync(txId, { from: owners[1] });
expect(initialSecondsTimeLocked).to.be.equal(0);
txHash = await multiSig.executeTransaction(txId, { from: owners[0] });
txHash = await multiSig.executeTransaction.sendTransactionAsync(txId, { from: owners[0] });
const res = await zeroEx.awaitTransactionMinedAsync(txHash);
expect(res.logs).to.have.length(2);
const secondsTimeLocked = new BigNumber(await multiSig.secondsTimeLocked.call());
const secondsTimeLocked = new BigNumber(await multiSig.secondsTimeLocked());
expect(secondsTimeLocked).to.be.bignumber.equal(SECONDS_TIME_LOCKED);
});
});
describe('initially time-locked', async () => {
before('deploy a walet', async () => {
multiSig = await deployer.deployAsync(ContractName.MultiSigWalletWithTimeLock, [
const multiSigInstance = await deployer.deployAsync(ContractName.MultiSigWalletWithTimeLock, [
owners,
SIGNATURES_REQUIRED,
SECONDS_TIME_LOCKED,
]);
multiSigWrapper = new MultiSigWrapper(multiSig);
multiSig = new MultiSigWalletWithTimeLockContract(multiSigInstance);
multiSigWrapper = new MultiSigWrapper((multiSig as any) as MultiSigWalletContract);
const secondsTimeLocked = await multiSig.secondsTimeLocked();
initialSecondsTimeLocked = secondsTimeLocked.toNumber();
@@ -165,8 +169,8 @@ describe('MultiSigWalletWithTimeLock', () => {
const log = abiDecoder.tryToDecodeLogOrNoop(subRes.logs[0]) as LogWithDecodedArgs<
SubmissionContractEventArgs
>;
txId = log.args.transactionId.toNumber();
txHash = await multiSig.confirmTransaction(txId, {
txId = log.args.transactionId;
txHash = await multiSig.confirmTransaction.sendTransactionAsync(txId, {
from: owners[1],
});
const confRes = await zeroEx.awaitTransactionMinedAsync(txHash);
@@ -174,16 +178,16 @@ describe('MultiSigWalletWithTimeLock', () => {
});
const newSecondsTimeLocked = 0;
it('should throw if it has enough confirmations but is not past the time lock', async () => {
return expect(multiSig.executeTransaction(txId, { from: owners[0] })).to.be.rejectedWith(
constants.REVERT,
);
return expect(
multiSig.executeTransaction.sendTransactionAsync(txId, { from: owners[0] }),
).to.be.rejectedWith(constants.REVERT);
});
it('should execute if it has enough confirmations and is past the time lock', async () => {
await rpc.increaseTimeAsync(SECONDS_TIME_LOCKED);
await multiSig.executeTransaction(txId, { from: owners[0] });
await rpc.increaseTimeAsync(SECONDS_TIME_LOCKED.toNumber());
await multiSig.executeTransaction.sendTransactionAsync(txId, { from: owners[0] });
const secondsTimeLocked = new BigNumber(await multiSig.secondsTimeLocked.call());
const secondsTimeLocked = new BigNumber(await multiSig.secondsTimeLocked());
expect(secondsTimeLocked).to.be.bignumber.equal(newSecondsTimeLocked);
});
});

View File

@@ -5,6 +5,9 @@ import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
import * as Web3 from 'web3';
import { MultiSigWalletContract } from '../src/contract_wrappers/generated/multi_sig_wallet';
import { MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract } from '../src/contract_wrappers/generated/multi_sig_wallet_with_time_lock_except_remove_authorized_address';
import { TokenTransferProxyContract } from '../src/contract_wrappers/generated/token_transfer_proxy';
import { artifacts } from '../util/artifacts';
import { constants } from '../util/constants';
import { crypto } from '../util/crypto';
@@ -35,8 +38,8 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => {
let authorizedAddress: string;
let unauthorizedAddress: string;
let tokenTransferProxy: Web3.ContractInstance;
let multiSig: Web3.ContractInstance;
let tokenTransferProxy: TokenTransferProxyContract;
let multiSig: MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract;
let multiSigWrapper: MultiSigWrapper;
let validDestination: string;
@@ -45,20 +48,20 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => {
owners = [accounts[0], accounts[1]];
[authorizedAddress, unauthorizedAddress] = accounts;
const initialOwner = accounts[0];
tokenTransferProxy = await deployer.deployAsync(ContractName.TokenTransferProxy);
await tokenTransferProxy.addAuthorizedAddress(authorizedAddress, {
const tokenTransferProxyInstance = await deployer.deployAsync(ContractName.TokenTransferProxy);
tokenTransferProxy = new TokenTransferProxyContract(tokenTransferProxyInstance);
await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(authorizedAddress, {
from: initialOwner,
});
multiSig = await deployer.deployAsync(ContractName.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress, [
owners,
requiredApprovals,
SECONDS_TIME_LOCKED,
tokenTransferProxy.address,
]);
await tokenTransferProxy.transferOwnership(multiSig.address, {
const multiSigInstance = await deployer.deployAsync(
ContractName.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress,
[owners, requiredApprovals, SECONDS_TIME_LOCKED, tokenTransferProxy.address],
);
multiSig = new MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract(multiSigInstance);
await tokenTransferProxy.transferOwnership.sendTransactionAsync(multiSig.address, {
from: initialOwner,
});
multiSigWrapper = new MultiSigWrapper(multiSig);
multiSigWrapper = new MultiSigWrapper((multiSig as any) as MultiSigWalletContract);
validDestination = tokenTransferProxy.address;
});
beforeEach(async () => {
@@ -71,12 +74,12 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => {
describe('isFunctionRemoveAuthorizedAddress', () => {
it('should throw if data is not for removeAuthorizedAddress', async () => {
const data = MultiSigWrapper.encodeFnArgs('addAuthorizedAddress', PROXY_ABI, [owners[0]]);
return expect(multiSig.isFunctionRemoveAuthorizedAddress.call(data)).to.be.rejectedWith(constants.REVERT);
return expect(multiSig.isFunctionRemoveAuthorizedAddress(data)).to.be.rejectedWith(constants.REVERT);
});
it('should return true if data is for removeAuthorizedAddress', async () => {
const data = MultiSigWrapper.encodeFnArgs('removeAuthorizedAddress', PROXY_ABI, [owners[0]]);
const isFunctionRemoveAuthorizedAddress = await multiSig.isFunctionRemoveAuthorizedAddress.call(data);
const isFunctionRemoveAuthorizedAddress = await multiSig.isFunctionRemoveAuthorizedAddress(data);
expect(isFunctionRemoveAuthorizedAddress).to.be.true();
});
});
@@ -91,11 +94,11 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => {
const txHash = await multiSigWrapper.submitTransactionAsync(validDestination, owners[0], dataParams);
const res = await zeroEx.awaitTransactionMinedAsync(txHash);
const log = abiDecoder.tryToDecodeLogOrNoop(res.logs[0]) as LogWithDecodedArgs<SubmissionContractEventArgs>;
const txId = log.args.transactionId.toString();
const txId = log.args.transactionId;
return expect(multiSig.executeRemoveAuthorizedAddress(txId, { from: owners[1] })).to.be.rejectedWith(
constants.REVERT,
);
return expect(
multiSig.executeRemoveAuthorizedAddress.sendTransactionAsync(txId, { from: owners[1] }),
).to.be.rejectedWith(constants.REVERT);
});
it('should throw if tx destination is not the tokenTransferProxy', async () => {
@@ -109,14 +112,14 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => {
const txHash = await multiSigWrapper.submitTransactionAsync(invalidDestination, owners[0], dataParams);
const res = await zeroEx.awaitTransactionMinedAsync(txHash);
const log = abiDecoder.tryToDecodeLogOrNoop(res.logs[0]) as LogWithDecodedArgs<SubmissionContractEventArgs>;
const txId = log.args.transactionId.toString();
await multiSig.confirmTransaction(txId, { from: owners[1] });
const isConfirmed = await multiSig.isConfirmed.call(txId);
const txId = log.args.transactionId;
await multiSig.confirmTransaction.sendTransactionAsync(txId, { from: owners[1] });
const isConfirmed = await multiSig.isConfirmed(txId);
expect(isConfirmed).to.be.true();
return expect(multiSig.executeRemoveAuthorizedAddress(txId, { from: owners[1] })).to.be.rejectedWith(
constants.REVERT,
);
return expect(
multiSig.executeRemoveAuthorizedAddress.sendTransactionAsync(txId, { from: owners[1] }),
).to.be.rejectedWith(constants.REVERT);
});
it('should throw if tx data is not for removeAuthorizedAddress', async () => {
@@ -128,14 +131,14 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => {
const txHash = await multiSigWrapper.submitTransactionAsync(validDestination, owners[0], dataParams);
const res = await zeroEx.awaitTransactionMinedAsync(txHash);
const log = abiDecoder.tryToDecodeLogOrNoop(res.logs[0]) as LogWithDecodedArgs<SubmissionContractEventArgs>;
const txId = log.args.transactionId.toString();
await multiSig.confirmTransaction(txId, { from: owners[1] });
const isConfirmed = await multiSig.isConfirmed.call(txId);
const txId = log.args.transactionId;
await multiSig.confirmTransaction.sendTransactionAsync(txId, { from: owners[1] });
const isConfirmed = await multiSig.isConfirmed(txId);
expect(isConfirmed).to.be.true();
return expect(multiSig.executeRemoveAuthorizedAddress(txId, { from: owners[1] })).to.be.rejectedWith(
constants.REVERT,
);
return expect(
multiSig.executeRemoveAuthorizedAddress.sendTransactionAsync(txId, { from: owners[1] }),
).to.be.rejectedWith(constants.REVERT);
});
it('should execute removeAuthorizedAddress for valid tokenTransferProxy if fully confirmed', async () => {
@@ -147,12 +150,12 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => {
const txHash = await multiSigWrapper.submitTransactionAsync(validDestination, owners[0], dataParams);
const res = await zeroEx.awaitTransactionMinedAsync(txHash);
const log = abiDecoder.tryToDecodeLogOrNoop(res.logs[0]) as LogWithDecodedArgs<SubmissionContractEventArgs>;
const txId = log.args.transactionId.toString();
await multiSig.confirmTransaction(txId, { from: owners[1] });
const isConfirmed = await multiSig.isConfirmed.call(txId);
const txId = log.args.transactionId;
await multiSig.confirmTransaction.sendTransactionAsync(txId, { from: owners[1] });
const isConfirmed = await multiSig.isConfirmed(txId);
expect(isConfirmed).to.be.true();
await multiSig.executeRemoveAuthorizedAddress(txId, { from: owners[1] });
const isAuthorized = await tokenTransferProxy.authorized.call(authorizedAddress);
await multiSig.executeRemoveAuthorizedAddress.sendTransactionAsync(txId, { from: owners[1] });
const isAuthorized = await tokenTransferProxy.authorized(authorizedAddress);
expect(isAuthorized).to.be.false();
});
@@ -165,17 +168,17 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => {
const txHash = await multiSigWrapper.submitTransactionAsync(validDestination, owners[0], dataParams);
const res = await zeroEx.awaitTransactionMinedAsync(txHash);
const log = abiDecoder.tryToDecodeLogOrNoop(res.logs[0]) as LogWithDecodedArgs<SubmissionContractEventArgs>;
const txId = log.args.transactionId.toString();
await multiSig.confirmTransaction(txId, { from: owners[1] });
const txId = log.args.transactionId;
await multiSig.confirmTransaction.sendTransactionAsync(txId, { from: owners[1] });
const isConfirmed = await multiSig.isConfirmed(txId);
expect(isConfirmed).to.be.true();
await multiSig.executeRemoveAuthorizedAddress(txId, { from: owners[1] });
await multiSig.executeRemoveAuthorizedAddress.sendTransactionAsync(txId, { from: owners[1] });
const tx = await multiSig.transactions(txId);
const isExecuted = tx[3];
expect(isExecuted).to.be.true();
return expect(multiSig.executeRemoveAuthorizedAddress(txId, { from: owners[1] })).to.be.rejectedWith(
constants.REVERT,
);
return expect(
multiSig.executeRemoveAuthorizedAddress.sendTransactionAsync(txId, { from: owners[1] }),
).to.be.rejectedWith(constants.REVERT);
});
});
});

View File

@@ -1,11 +1,13 @@
import { ZeroEx } from '0x.js';
import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
import ethUtil = require('ethereumjs-util');
import * as _ from 'lodash';
import * as Web3 from 'web3';
import { TokenRegistryContract } from '../src/contract_wrappers/generated/token_registry';
import { constants } from '../util/constants';
import { TokenRegWrapper } from '../util/token_registry_wrapper';
import { ContractName } from '../util/types';
@@ -22,13 +24,14 @@ const blockchainLifecycle = new BlockchainLifecycle();
describe('TokenRegistry', () => {
let owner: string;
let notOwner: string;
let tokenReg: Web3.ContractInstance;
let tokenReg: TokenRegistryContract;
let tokenRegWrapper: TokenRegWrapper;
before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync();
owner = accounts[0];
notOwner = accounts[1];
tokenReg = await deployer.deployAsync(ContractName.TokenRegistry);
const tokenRegInstance = await deployer.deployAsync(ContractName.TokenRegistry);
tokenReg = new TokenRegistryContract(tokenRegInstance);
tokenRegWrapper = new TokenRegWrapper(tokenReg);
});
beforeEach(async () => {
@@ -132,12 +135,12 @@ describe('TokenRegistry', () => {
describe('setTokenName', () => {
it('should throw when not called by owner', async () => {
return expect(
tokenReg.setTokenName(token1.address, token2.name, { from: notOwner }),
tokenReg.setTokenName.sendTransactionAsync(token1.address, token2.name, { from: notOwner }),
).to.be.rejectedWith(constants.REVERT);
});
it('should change the token name when called by owner', async () => {
await tokenReg.setTokenName(token1.address, token2.name, {
await tokenReg.setTokenName.sendTransactionAsync(token1.address, token2.name, {
from: owner,
});
const [newData, oldData] = await Promise.all([
@@ -154,14 +157,14 @@ describe('TokenRegistry', () => {
it('should throw if the name already exists', async () => {
await tokenRegWrapper.addTokenAsync(token2, owner);
return expect(tokenReg.setTokenName(token1.address, token2.name, { from: owner })).to.be.rejectedWith(
constants.REVERT,
);
return expect(
tokenReg.setTokenName.sendTransactionAsync(token1.address, token2.name, { from: owner }),
).to.be.rejectedWith(constants.REVERT);
});
it('should throw if token does not exist', async () => {
return expect(
tokenReg.setTokenName(nullToken.address, token2.name, { from: owner }),
tokenReg.setTokenName.sendTransactionAsync(nullToken.address, token2.name, { from: owner }),
).to.be.rejectedWith(constants.REVERT);
});
});
@@ -169,14 +172,14 @@ describe('TokenRegistry', () => {
describe('setTokenSymbol', () => {
it('should throw when not called by owner', async () => {
return expect(
tokenReg.setTokenSymbol(token1.address, token2.symbol, {
tokenReg.setTokenSymbol.sendTransactionAsync(token1.address, token2.symbol, {
from: notOwner,
}),
).to.be.rejectedWith(constants.REVERT);
});
it('should change the token symbol when called by owner', async () => {
await tokenReg.setTokenSymbol(token1.address, token2.symbol, { from: owner });
await tokenReg.setTokenSymbol.sendTransactionAsync(token1.address, token2.symbol, { from: owner });
const [newData, oldData] = await Promise.all([
tokenRegWrapper.getTokenBySymbolAsync(token2.symbol),
tokenRegWrapper.getTokenBySymbolAsync(token1.symbol),
@@ -192,7 +195,7 @@ describe('TokenRegistry', () => {
await tokenRegWrapper.addTokenAsync(token2, owner);
return expect(
tokenReg.setTokenSymbol(token1.address, token2.symbol, {
tokenReg.setTokenSymbol.sendTransactionAsync(token1.address, token2.symbol, {
from: owner,
}),
).to.be.rejectedWith(constants.REVERT);
@@ -200,7 +203,7 @@ describe('TokenRegistry', () => {
it('should throw if token does not exist', async () => {
return expect(
tokenReg.setTokenSymbol(nullToken.address, token2.symbol, {
tokenReg.setTokenSymbol.sendTransactionAsync(nullToken.address, token2.symbol, {
from: owner,
}),
).to.be.rejectedWith(constants.REVERT);
@@ -209,15 +212,15 @@ describe('TokenRegistry', () => {
describe('removeToken', () => {
it('should throw if not called by owner', async () => {
const index = 0;
return expect(tokenReg.removeToken(token1.address, index, { from: notOwner })).to.be.rejectedWith(
constants.REVERT,
);
const index = new BigNumber(0);
return expect(
tokenReg.removeToken.sendTransactionAsync(token1.address, index, { from: notOwner }),
).to.be.rejectedWith(constants.REVERT);
});
it('should remove token metadata when called by owner', async () => {
const index = 0;
await tokenReg.removeToken(token1.address, index, {
const index = new BigNumber(0);
await tokenReg.removeToken.sendTransactionAsync(token1.address, index, {
from: owner,
});
const tokenData = await tokenRegWrapper.getTokenMetaDataAsync(token1.address);
@@ -225,18 +228,18 @@ describe('TokenRegistry', () => {
});
it('should throw if token does not exist', async () => {
const index = 0;
return expect(tokenReg.removeToken(nullToken.address, index, { from: owner })).to.be.rejectedWith(
constants.REVERT,
);
const index = new BigNumber(0);
return expect(
tokenReg.removeToken.sendTransactionAsync(nullToken.address, index, { from: owner }),
).to.be.rejectedWith(constants.REVERT);
});
it('should throw if token at given index does not match address', async () => {
await tokenRegWrapper.addTokenAsync(token2, owner);
const incorrectIndex = 0;
return expect(tokenReg.removeToken(token2.address, incorrectIndex, { from: owner })).to.be.rejectedWith(
constants.REVERT,
);
const incorrectIndex = new BigNumber(0);
return expect(
tokenReg.removeToken.sendTransactionAsync(token2.address, incorrectIndex, { from: owner }),
).to.be.rejectedWith(constants.REVERT);
});
});
});

View File

@@ -3,6 +3,7 @@ import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
import * as Web3 from 'web3';
import { TokenTransferProxyContract } from '../../src/contract_wrappers/generated/token_transfer_proxy';
import { constants } from '../../util/constants';
import { ContractName } from '../../util/types';
import { chaiSetup } from '../utils/chai_setup';
@@ -18,12 +19,13 @@ describe('TokenTransferProxy', () => {
let owner: string;
let notOwner: string;
let address: string;
let tokenTransferProxy: Web3.ContractInstance;
let tokenTransferProxy: TokenTransferProxyContract;
before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync();
owner = address = accounts[0];
notOwner = accounts[1];
tokenTransferProxy = await deployer.deployAsync(ContractName.TokenTransferProxy);
const tokenTransferProxyInstance = await deployer.deployAsync(ContractName.TokenTransferProxy);
tokenTransferProxy = new TokenTransferProxyContract(tokenTransferProxyInstance);
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
@@ -33,36 +35,36 @@ describe('TokenTransferProxy', () => {
});
describe('addAuthorizedAddress', () => {
it('should throw if not called by owner', async () => {
return expect(tokenTransferProxy.addAuthorizedAddress(notOwner, { from: notOwner })).to.be.rejectedWith(
constants.REVERT,
);
return expect(
tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(notOwner, { from: notOwner }),
).to.be.rejectedWith(constants.REVERT);
});
it('should allow owner to add an authorized address', async () => {
await tokenTransferProxy.addAuthorizedAddress(address, { from: owner });
await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(address, { from: owner });
const isAuthorized = await tokenTransferProxy.authorized(address);
expect(isAuthorized).to.be.true();
});
it('should throw if owner attempts to authorize a duplicate address', async () => {
await tokenTransferProxy.addAuthorizedAddress(address, { from: owner });
return expect(tokenTransferProxy.addAuthorizedAddress(address, { from: owner })).to.be.rejectedWith(
constants.REVERT,
);
await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(address, { from: owner });
return expect(
tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }),
).to.be.rejectedWith(constants.REVERT);
});
});
describe('removeAuthorizedAddress', () => {
it('should throw if not called by owner', async () => {
await tokenTransferProxy.addAuthorizedAddress(address, { from: owner });
await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(address, { from: owner });
return expect(
tokenTransferProxy.removeAuthorizedAddress(address, {
tokenTransferProxy.removeAuthorizedAddress.sendTransactionAsync(address, {
from: notOwner,
}),
).to.be.rejectedWith(constants.REVERT);
});
it('should allow owner to remove an authorized address', async () => {
await tokenTransferProxy.addAuthorizedAddress(address, { from: owner });
await tokenTransferProxy.removeAuthorizedAddress(address, {
await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(address, { from: owner });
await tokenTransferProxy.removeAuthorizedAddress.sendTransactionAsync(address, {
from: owner,
});
const isAuthorized = await tokenTransferProxy.authorized(address);
@@ -71,7 +73,7 @@ describe('TokenTransferProxy', () => {
it('should throw if owner attempts to remove an address that is not authorized', async () => {
return expect(
tokenTransferProxy.removeAuthorizedAddress(address, {
tokenTransferProxy.removeAuthorizedAddress.sendTransactionAsync(address, {
from: owner,
}),
).to.be.rejectedWith(constants.REVERT);
@@ -82,14 +84,14 @@ describe('TokenTransferProxy', () => {
it('should return all authorized addresses', async () => {
const initial = await tokenTransferProxy.getAuthorizedAddresses();
expect(initial).to.have.length(0);
await tokenTransferProxy.addAuthorizedAddress(address, {
await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(address, {
from: owner,
});
const afterAdd = await tokenTransferProxy.getAuthorizedAddresses();
expect(afterAdd).to.have.length(1);
expect(afterAdd).to.include(address);
await tokenTransferProxy.removeAuthorizedAddress(address, {
await tokenTransferProxy.removeAuthorizedAddress.sendTransactionAsync(address, {
from: owner,
});
const afterRemove = await tokenTransferProxy.getAuthorizedAddresses();

View File

@@ -1,8 +1,11 @@
import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
import * as Web3 from 'web3';
import { DummyTokenContract } from '../../src/contract_wrappers/generated/dummy_token';
import { TokenTransferProxyContract } from '../../src/contract_wrappers/generated/token_transfer_proxy';
import { Balances } from '../../util/balances';
import { constants } from '../../util/constants';
import { ContractName } from '../../util/types';
@@ -19,29 +22,31 @@ describe('TokenTransferProxy', () => {
let accounts: string[];
let owner: string;
let notAuthorized: string;
const INIT_BAL = 100000000;
const INIT_ALLOW = 100000000;
const INIT_BAL = new BigNumber(100000000);
const INIT_ALLOW = new BigNumber(100000000);
let tokenTransferProxy: Web3.ContractInstance;
let rep: Web3.ContractInstance;
let tokenTransferProxy: TokenTransferProxyContract;
let rep: DummyTokenContract;
let dmyBalances: Balances;
before(async () => {
accounts = await web3Wrapper.getAvailableAddressesAsync();
owner = notAuthorized = accounts[0];
tokenTransferProxy = await deployer.deployAsync(ContractName.TokenTransferProxy);
rep = await deployer.deployAsync(ContractName.DummyToken);
const tokenTransferProxyInstance = await deployer.deployAsync(ContractName.TokenTransferProxy);
tokenTransferProxy = new TokenTransferProxyContract(tokenTransferProxyInstance);
const repInstance = await deployer.deployAsync(ContractName.DummyToken);
rep = new DummyTokenContract(repInstance);
dmyBalances = new Balances([rep], [accounts[0], accounts[1]]);
await Promise.all([
rep.approve(tokenTransferProxy.address, INIT_ALLOW, {
rep.approve.sendTransactionAsync(tokenTransferProxy.address, INIT_ALLOW, {
from: accounts[0],
}),
rep.setBalance(accounts[0], INIT_BAL, { from: owner }),
rep.approve(tokenTransferProxy.address, INIT_ALLOW, {
rep.setBalance.sendTransactionAsync(accounts[0], INIT_BAL, { from: owner }),
rep.approve.sendTransactionAsync(tokenTransferProxy.address, INIT_ALLOW, {
from: accounts[1],
}),
rep.setBalance(accounts[1], INIT_BAL, { from: owner }),
rep.setBalance.sendTransactionAsync(accounts[1], INIT_BAL, { from: owner }),
]);
});
beforeEach(async () => {
@@ -54,20 +59,34 @@ describe('TokenTransferProxy', () => {
describe('transferFrom', () => {
it('should throw when called by an unauthorized address', async () => {
expect(
tokenTransferProxy.transferFrom(rep.address, accounts[0], accounts[1], 1000, { from: notAuthorized }),
tokenTransferProxy.transferFrom.sendTransactionAsync(
rep.address,
accounts[0],
accounts[1],
new BigNumber(1000),
{
from: notAuthorized,
},
),
).to.be.rejectedWith(constants.REVERT);
});
it('should allow an authorized address to transfer', async () => {
const balances = await dmyBalances.getAsync();
await tokenTransferProxy.addAuthorizedAddress(notAuthorized, {
await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(notAuthorized, {
from: owner,
});
const transferAmt = 10000;
await tokenTransferProxy.transferFrom(rep.address, accounts[0], accounts[1], transferAmt, {
from: notAuthorized,
});
const transferAmt = new BigNumber(10000);
await tokenTransferProxy.transferFrom.sendTransactionAsync(
rep.address,
accounts[0],
accounts[1],
transferAmt,
{
from: notAuthorized,
},
);
const newBalances = await dmyBalances.getAsync();
expect(newBalances[accounts[0]][rep.address]).to.be.bignumber.equal(

View File

@@ -5,6 +5,7 @@ import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
import * as Web3 from 'web3';
import { DummyTokenContract } from '../src/contract_wrappers/generated/dummy_token';
import { constants } from '../util/constants';
import { ContractName } from '../util/types';
@@ -27,14 +28,15 @@ describe('UnlimitedAllowanceToken', () => {
const MAX_MINT_VALUE = new BigNumber(100000000000000000000);
let tokenAddress: string;
let token: Web3.ContractInstance;
let token: DummyTokenContract;
before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync();
owner = accounts[0];
spender = accounts[1];
token = await deployer.deployAsync(ContractName.DummyToken);
await token.mint(MAX_MINT_VALUE, { from: owner });
const tokenInstance = await deployer.deployAsync(ContractName.DummyToken);
token = new DummyTokenContract(tokenInstance);
await token.mint.sendTransactionAsync(MAX_MINT_VALUE, { from: owner });
tokenAddress = token.address;
});
beforeEach(async () => {
@@ -47,7 +49,7 @@ describe('UnlimitedAllowanceToken', () => {
it('should throw if owner has insufficient balance', async () => {
const ownerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner);
const amountToTransfer = ownerBalance.plus(1);
return expect(token.transfer.call(spender, amountToTransfer, { from: owner })).to.be.rejectedWith(
return expect(token.transfer.callAsync(spender, amountToTransfer, { from: owner })).to.be.rejectedWith(
constants.REVERT,
);
});
@@ -67,7 +69,7 @@ describe('UnlimitedAllowanceToken', () => {
});
it('should return true on a 0 value transfer', async () => {
const didReturnTrue = await token.transfer.call(spender, 0, {
const didReturnTrue = await token.transfer.callAsync(spender, new BigNumber(0), {
from: owner,
});
expect(didReturnTrue).to.be.true();
@@ -80,7 +82,7 @@ describe('UnlimitedAllowanceToken', () => {
const amountToTransfer = ownerBalance.plus(1);
await zeroEx.token.setAllowanceAsync(tokenAddress, owner, spender, amountToTransfer);
return expect(
token.transferFrom.call(owner, spender, amountToTransfer, {
token.transferFrom.callAsync(owner, spender, amountToTransfer, {
from: spender,
}),
).to.be.rejectedWith(constants.REVERT);
@@ -95,15 +97,17 @@ describe('UnlimitedAllowanceToken', () => {
expect(spenderAllowanceIsInsufficient).to.be.true();
return expect(
token.transferFrom.call(owner, spender, amountToTransfer, {
token.transferFrom.callAsync(owner, spender, amountToTransfer, {
from: spender,
}),
).to.be.rejectedWith(constants.REVERT);
});
it('should return true on a 0 value transfer', async () => {
const amountToTransfer = 0;
const didReturnTrue = await token.transferFrom.call(owner, spender, amountToTransfer, { from: spender });
const amountToTransfer = new BigNumber(0);
const didReturnTrue = await token.transferFrom.callAsync(owner, spender, amountToTransfer, {
from: spender,
});
expect(didReturnTrue).to.be.true();
});

Some files were not shown because too many files have changed in this diff Show More