aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-07-04 13:32:24 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-07-05 01:05:45 +0800
commitf39a2134b946ab2c7f24b9fcc49f95156e7682d5 (patch)
tree964403241e02bd074f619a8b2427f2bc9eebd253
parent551b6db35e07907ad4dec767c8e76953fe98bb72 (diff)
downloaddexon-sol-tools-f39a2134b946ab2c7f24b9fcc49f95156e7682d5.tar
dexon-sol-tools-f39a2134b946ab2c7f24b9fcc49f95156e7682d5.tar.gz
dexon-sol-tools-f39a2134b946ab2c7f24b9fcc49f95156e7682d5.tar.bz2
dexon-sol-tools-f39a2134b946ab2c7f24b9fcc49f95156e7682d5.tar.lz
dexon-sol-tools-f39a2134b946ab2c7f24b9fcc49f95156e7682d5.tar.xz
dexon-sol-tools-f39a2134b946ab2c7f24b9fcc49f95156e7682d5.tar.zst
dexon-sol-tools-f39a2134b946ab2c7f24b9fcc49f95156e7682d5.zip
Add tests for order hash Schema
-rw-r--r--src/contract_wrappers/token_wrapper.ts6
-rw-r--r--test/schema_test.ts21
2 files changed, 26 insertions, 1 deletions
diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts
index 85592a106..1e087e8b0 100644
--- a/src/contract_wrappers/token_wrapper.ts
+++ b/src/contract_wrappers/token_wrapper.ts
@@ -8,6 +8,8 @@ import {constants} from '../utils/constants';
import {ContractWrapper} from './contract_wrapper';
import * as TokenArtifacts from '../artifacts/Token.json';
import * as ProxyArtifacts from '../artifacts/Proxy.json';
+import {subscriptionOptsSchema} from '../schemas/subscription_opts_schema';
+import {indexFilterValuesSchema} from '../schemas/index_filter_values_schema';
import {
TokenContract,
ZeroExError,
@@ -203,6 +205,10 @@ export class TokenWrapper extends ContractWrapper {
*/
public async subscribeAsync(tokenAddress: string, eventName: TokenEvents, subscriptionOpts: SubscriptionOpts,
indexFilterValues: IndexedFilterValues): Promise<ContractEventEmitter> {
+ assert.isETHAddressHex('tokenAddress', tokenAddress);
+ // assert.isEventName('eventName', eventName);
+ assert.doesConformToSchema('subscriptionOpts', subscriptionOpts, subscriptionOptsSchema);
+ assert.doesConformToSchema('indexFilterValues', indexFilterValues, indexFilterValuesSchema);
const tokenContract = await this._getTokenContractAsync(tokenAddress);
let createLogEvent: CreateContractEvent;
switch (eventName) {
diff --git a/test/schema_test.ts b/test/schema_test.ts
index 7f9a66ae3..4746c7949 100644
--- a/test/schema_test.ts
+++ b/test/schema_test.ts
@@ -6,7 +6,7 @@ import promisify = require('es6-promisify');
import {constants} from './utils/constants';
import {SchemaValidator} from '../src/utils/schema_validator';
import {tokenSchema} from '../src/schemas/token_schema';
-import {orderSchema, signedOrderSchema} from '../src/schemas/order_schemas';
+import {orderSchema, signedOrderSchema, orderHashSchema} from '../src/schemas/order_schemas';
import {addressSchema, numberSchema} from '../src/schemas/basic_type_schemas';
import {orderFillOrKillRequestsSchema} from '../src/schemas/order_fill_or_kill_requests_schema';
import {ecSignatureParameterSchema, ecSignatureSchema} from '../src/schemas/ec_signature_schema';
@@ -97,6 +97,25 @@ describe('Schema', () => {
validateAgainstSchema(testCases, ecSignatureSchema, shouldFail);
});
});
+ describe('#orderHashSchema', () => {
+ it('should validate valid order hash', () => {
+ const testCases = [
+ '0x61a3ed31B43c8780e905a260a35faefEc527be7516aa11c0256729b5b351bc33',
+ '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254',
+ ];
+ validateAgainstSchema(testCases, orderHashSchema);
+ });
+ it('should fail for invalid order hash', () => {
+ const testCases = [
+ {},
+ '0x',
+ '0x8b0292B11a196601eD2ce54B665CaFEca0347D42',
+ '61a3ed31B43c8780e905a260a35faefEc527be7516aa11c0256729b5b351bc33',
+ ];
+ const shouldFail = true;
+ validateAgainstSchema(testCases, orderHashSchema, shouldFail);
+ });
+ });
describe('#blockParamSchema', () => {
it('should validate valid block param', () => {
const testCases = [