UNPKG

3.25 kBJavaScriptView Raw
1const assert = require('assert')
2const linter = require('./../../../lib/index')
3const contractWith = require('./../../common/contract-builder').contractWith
4
5describe('Linter - func-order', () => {
6 it('should raise incorrect function order error I', () => {
7 const code = contractWith(`
8 function b() private {}
9 function () public payable {}
10 `)
11
12 const report = linter.processStr(code, {
13 rules: { 'func-order': 'error' }
14 })
15
16 assert.equal(report.errorCount, 1)
17 assert.ok(report.messages[0].message.includes('Function order is incorrect'))
18 })
19
20 it('should raise incorrect function order error for external constant funcs', () => {
21 const code = contractWith(`
22 function b() external pure {}
23 function c() external {}
24 `)
25
26 const report = linter.processStr(code, {
27 rules: { 'func-order': 'error' }
28 })
29
30 assert.equal(report.errorCount, 1)
31 assert.ok(report.messages[0].message.includes('Function order is incorrect'))
32 })
33
34 it('should raise incorrect function order error for public constant funcs', () => {
35 const code = contractWith(`
36 function b() public pure {}
37 function c() public {}
38 `)
39
40 const report = linter.processStr(code, {
41 rules: { 'func-order': 'error' }
42 })
43
44 assert.equal(report.errorCount, 1)
45 assert.ok(report.messages[0].message.includes('Function order is incorrect'))
46 })
47
48 it('should raise incorrect function order error for internal function', () => {
49 const code = contractWith(`
50 function c() internal {}
51 function b() external view {}
52 `)
53
54 const report = linter.processStr(code, {
55 rules: { 'func-order': 'error' }
56 })
57
58 assert.equal(report.errorCount, 1)
59 assert.ok(report.messages[0].message.includes('Function order is incorrect'))
60 })
61
62 it('should not raise incorrect function order error', () => {
63 const code = contractWith(`
64 function A() public {}
65 function () public payable {}
66 `)
67
68 const report = linter.processStr(code, {
69 rules: { 'func-order': 'error' }
70 })
71
72 assert.equal(report.errorCount, 0)
73 })
74
75 it('should not raise incorrect function order error I', () => {
76 const code = require('../../fixtures/order/func-order-constructor-first')
77
78 const report = linter.processStr(code, {
79 rules: { 'func-order': 'error' }
80 })
81
82 assert.equal(report.errorCount, 0)
83 })
84
85 it('should raise incorrect function order error', () => {
86 const code = require('../../fixtures/order/func-order-constructor-not-first')
87
88 const report = linter.processStr(code, {
89 rules: { 'func-order': 'error' }
90 })
91 assert.equal(report.errorCount, 1)
92 assert.ok(report.messages[0].message.includes('Function order is incorrect'))
93 })
94
95 it('should not raise error when external const goes before public ', () => {
96 const code = contractWith(`
97 function a() external view {}
98 function b() public {}
99 `)
100
101 const report = linter.processStr(code, {
102 rules: { 'func-order': 'error' }
103 })
104
105 assert.equal(report.errorCount, 0)
106 })
107})