-
Notifications
You must be signed in to change notification settings - Fork 168
/
Copy pathpayable-fallback.js
56 lines (41 loc) · 1.71 KB
/
payable-fallback.js
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
const { assertNoWarnings, assertErrorMessage, assertWarnsCount } = require('../../common/asserts')
const linter = require('../../../lib/index')
const { contractWith } = require('../../common/contract-builder')
describe('Linter - payable-fallback', () => {
it('should raise warn when fallback is not payable and no receive function is present', () => {
const code = contractWith('function() public {}')
const report = linter.processStr(code, {
rules: { 'payable-fallback': 'warn' },
})
assertWarnsCount(report, 1)
assertErrorMessage(report, 'payable')
})
it('should not raise warn when fallback is payable and no receive function is present', () => {
const code = contractWith('fallback() public payable {}')
const report = linter.processStr(code, {
rules: { 'payable-fallback': 'warn' },
})
assertNoWarnings(report)
})
it('should not raise warn when fallback is not payable but receive function is present', () => {
const code = contractWith('fallback() external {} receive() {}')
const report = linter.processStr(code, {
rules: { 'payable-fallback': 'warn' },
})
assertNoWarnings(report)
})
it('should not raise warn when fallback is payable and receive function is present', () => {
const code = contractWith('fallback() external payable {} receive() {}')
const report = linter.processStr(code, {
rules: { 'payable-fallback': 'warn' },
})
assertNoWarnings(report)
})
it('should ignore non-fallback functions', () => {
const code = contractWith('function f() {} function g() payable {}')
const report = linter.processStr(code, {
rules: { 'payable-fallback': 'warn' },
})
assertNoWarnings(report)
})
})