it('should return the token added to the tokenRegistry during the migration', async () => {
            const aToken = tokens[0];

            const token = await zeroEx.tokenRegistry.getTokenIfExistsAsync(aToken.address);
            const schemaValidator = new SchemaValidator();
            const validationResult = schemaValidator.validate(token, schemas.tokenSchema);
            expect(validationResult.errors).to.have.lengthOf(0);
        });
        it('should return all the tokens added to the tokenRegistry during the migration', async () => {
            expect(tokens).to.have.lengthOf(TOKEN_REGISTRY_SIZE_AFTER_MIGRATION);

            const schemaValidator = new SchemaValidator();
            _.each(tokens, token => {
                const validationResult = schemaValidator.validate(token, schemas.tokenSchema);
                expect(validationResult.errors).to.have.lengthOf(0);
            });
        });
        it('should return all the token addresses added to the tokenRegistry during the migration', async () => {
            const tokenAddresses = await zeroEx.tokenRegistry.getTokenAddressesAsync();
            expect(tokenAddresses).to.have.lengthOf(TOKEN_REGISTRY_SIZE_AFTER_MIGRATION);

            const schemaValidator = new SchemaValidator();
            _.each(tokenAddresses, tokenAddress => {
                const validationResult = schemaValidator.validate(tokenAddress, schemas.addressSchema);
                expect(validationResult.errors).to.have.lengthOf(0);
                expect(tokenAddress).to.not.be.equal(ZeroEx.NULL_ADDRESS);
            });
        });
 _.each(tokenAddresses, tokenAddress => {
     const validationResult = schemaValidator.validate(tokenAddress, schemas.addressSchema);
     expect(validationResult.errors).to.have.lengthOf(0);
     expect(tokenAddress).to.not.be.equal(ZeroEx.NULL_ADDRESS);
 });
 _.each(tokens, token => {
     const validationResult = schemaValidator.validate(token, schemas.tokenSchema);
     expect(validationResult.errors).to.have.lengthOf(0);
 });
Example #6
0
 private isTxData(lastArg: any): boolean {
     const isValid = this.validator.isValid(lastArg, schemas.txDataSchema);
     return isValid;
 }
Example #7
0
    },
    hasAtMostOneUniqueValue(value: any[], errMsg: string): void {
        this.assert(_.uniq(value).length <= 1, errMsg);
    },
    isNumber(variableName: string, value: number): void {
        this.assert(_.isFinite(value), this.typeAssertionMessage(variableName, 'number', value));
    },
    isBoolean(variableName: string, value: boolean): void {
        this.assert(_.isBoolean(value), this.typeAssertionMessage(variableName, 'boolean', value));
    },
    isWeb3Provider(variableName: string, value: Web3.Provider): void {
        const isWeb3Provider = _.isFunction((value as any).send) || _.isFunction((value as any).sendAsync);
        this.assert(isWeb3Provider, this.typeAssertionMessage(variableName, 'Web3.Provider', value));
    },
    doesConformToSchema(variableName: string, value: any, schema: Schema): void {
        const schemaValidator = new SchemaValidator();
        const validationResult = schemaValidator.validate(value, schema);
        const hasValidationErrors = validationResult.errors.length > 0;
        const msg = `Expected ${variableName} to conform to schema ${schema.id}
Encountered: ${JSON.stringify(value, null, '\t')}
Validation errors: ${validationResult.errors.join(', ')}`;
        this.assert(!hasValidationErrors, msg);
    },
    assert(condition: boolean, message: string): void {
        if (!condition) {
            throw new Error(message);
        }
    },
    typeAssertionMessage(variableName: string, type: string, value: any): string {
        return `Expected ${variableName} to be of type ${type}, encountered: ${value}`;
    },