aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-doc/test/solidity_doc_generator_test.ts
blob: 7f11fcdfd2b8208b56b981a0c9ddb14c5130f17b (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import * as _ from 'lodash';

import * as chai from 'chai';
import 'mocha';

import { SolidityMethod } from '@0xproject/types';

import { generateSolDocAsync } from '../src/solidity_doc_generator';

import { chaiSetup } from './util/chai_setup';

chaiSetup.configure();
const expect = chai.expect;

describe('#SolidityDocGenerator', () => {
    it('should generate a doc object that matches the TokenTransferProxy fixture', async () => {
        const doc = await generateSolDocAsync(['TokenTransferProxy'], `${__dirname}/../../test/fixtures/contracts`);

        expect(doc).to.not.be.undefined();

        const tokenTransferProxyConstructorCount = 0;
        const tokenTransferProxyMethodCount = 8;
        const tokenTransferProxyEventCount = 3;
        expect(doc.TokenTransferProxy.constructors.length).to.equal(tokenTransferProxyConstructorCount);
        expect(doc.TokenTransferProxy.methods.length).to.equal(tokenTransferProxyMethodCount);
        if (_.isUndefined(doc.TokenTransferProxy.events)) {
            throw new Error('events should never be undefined');
        }
        expect(doc.TokenTransferProxy.events.length).to.equal(tokenTransferProxyEventCount);

        const ownableConstructorCount = 1;
        const ownableMethodCount = 2;
        const ownableEventCount = 1;
        expect(doc.Ownable.constructors.length).to.equal(ownableConstructorCount);
        expect(doc.Ownable.methods.length).to.equal(ownableMethodCount);
        if (_.isUndefined(doc.Ownable.events)) {
            throw new Error('events should never be undefined');
        }
        expect(doc.Ownable.events.length).to.equal(ownableEventCount);

        const erc20ConstructorCount = 0;
        const erc20MethodCount = 6;
        const erc20EventCount = 2;
        expect(doc.ERC20.constructors.length).to.equal(erc20ConstructorCount);
        expect(doc.ERC20.methods.length).to.equal(erc20MethodCount);
        if (_.isUndefined(doc.ERC20.events)) {
            throw new Error('events should never be undefined');
        }
        expect(doc.ERC20.events.length).to.equal(erc20EventCount);

        const erc20BasicConstructorCount = 0;
        const erc20BasicMethodCount = 3;
        const erc20BasicEventCount = 1;
        expect(doc.ERC20Basic.constructors.length).to.equal(erc20BasicConstructorCount);
        expect(doc.ERC20Basic.methods.length).to.equal(erc20BasicMethodCount);
        if (_.isUndefined(doc.ERC20Basic.events)) {
            throw new Error('events should never be undefined');
        }
        expect(doc.ERC20Basic.events.length).to.equal(erc20BasicEventCount);

        let addAuthorizedAddressMethod: SolidityMethod | undefined;
        for (const method of doc.TokenTransferProxy.methods) {
            if (method.name === 'addAuthorizedAddress') {
                addAuthorizedAddressMethod = method;
            }
        }
        expect(
            addAuthorizedAddressMethod,
            `method addAuthorizedAddress not found in ${JSON.stringify(doc.TokenTransferProxy.methods)}`,
        ).to.not.be.undefined();
        const tokenTransferProxyAddAuthorizedAddressComment = 'Authorizes an address.';
        expect((addAuthorizedAddressMethod as SolidityMethod).comment).to.equal(
            tokenTransferProxyAddAuthorizedAddressComment,
        );
    });
});