aboutsummaryrefslogtreecommitdiffstats
path: root/test/assert_test.ts
blob: f72956eb373ec30a6e2b7493d7f7ef80928d8b05 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import * as chai from 'chai';
import 'mocha';
import {ZeroEx} from '../src/0x.js';
import {assert} from '../src/utils/assert';
import {web3Factory} from './utils/web3_factory';

const expect = chai.expect;

describe('Assertion library', () => {
    const web3 = web3Factory.create();
    const zeroEx = new ZeroEx(web3);
    describe('#isSenderAccountHexAsync', () => {
        it('throws when address is invalid', async () => {
            const address = '0xdeadbeef';
            const varName = 'account';
            return expect(assert.isSenderAddressHexAsync(varName, address, (zeroEx as any).web3Wrapper))
                .to.be.rejectedWith(`Expected ${varName} to be of type ETHAddressHex, encountered: ${address}`);
        });
        it('throws when address is unavailable', async () => {
            const validUnrelatedAddress = '0x8b0292b11a196601eddce54b665cafeca0347d42';
            const varName = 'account';
            return expect(assert.isSenderAddressHexAsync(varName, validUnrelatedAddress, (zeroEx as any).web3Wrapper))
                .to.be.rejectedWith(`Specified sender account ${validUnrelatedAddress} \
                isn't available through the supplied web3 instance`);
        });
        it('doesn\'t throw if account is available', async () => {
            const availableAccount = (await zeroEx.getAvailableAccountsAsync())[0];
            const varName = 'account';
            return expect(assert.isSenderAddressHexAsync(varName, availableAccount, (zeroEx as any).web3Wrapper))
                .to.become(undefined);
        });
    });
});