1
1
const { ethGetBalance, ethSendTransaction } = require ( './helpers/web3' ) ;
2
+ const { ether } = require ( './helpers/ether' ) ;
2
3
const { sendEther } = require ( './helpers/sendTransaction' ) ;
3
4
const { balanceDifference } = require ( './helpers/balanceDiff' ) ;
4
5
const expectEvent = require ( './helpers/expectEvent' ) ;
@@ -11,7 +12,7 @@ require('chai')
11
12
. use ( require ( 'chai-bignumber' ) ( web3 . BigNumber ) )
12
13
. should ( ) ;
13
14
14
- const reward = new web3 . BigNumber ( web3 . toWei ( 1 , 'ether' ) ) ;
15
+ const reward = ether ( 1 ) ;
15
16
16
17
contract ( 'BreakInvariantBounty' , function ( [ _ , owner , researcher , anyone , nonTarget ] ) {
17
18
beforeEach ( async function ( ) {
@@ -28,24 +29,9 @@ contract('BreakInvariantBounty', function ([_, owner, researcher, anyone, nonTar
28
29
await sendEther ( owner , this . bounty . address , reward ) ;
29
30
} ) ;
30
31
31
- describe ( 'destroy' , function ( ) {
32
- it ( 'returns all balance to the owner' , async function ( ) {
33
- const ownerPreBalance = await ethGetBalance ( owner ) ;
34
- await this . bounty . destroy ( { from : owner , gasPrice : 0 } ) ;
35
- const ownerPostBalance = await ethGetBalance ( owner ) ;
36
-
37
- ( await ethGetBalance ( this . bounty . address ) ) . should . be . bignumber . equal ( 0 ) ;
38
- ownerPostBalance . sub ( ownerPreBalance ) . should . be . bignumber . equal ( reward ) ;
39
- } ) ;
40
-
41
- it ( 'reverts when called by anyone' , async function ( ) {
42
- await assertRevert ( this . bounty . destroy ( { from : anyone } ) ) ;
43
- } ) ;
44
- } ) ;
45
-
46
32
describe ( 'claim' , function ( ) {
47
- it ( 'is initially unclaimed ' , async function ( ) {
48
- ( await this . bounty . claimed ( ) ) . should . equal ( false ) ;
33
+ it ( 'is initially claimable ' , async function ( ) {
34
+ ( await this . bounty . claimable ( ) ) . should . equal ( true ) ;
49
35
} ) ;
50
36
51
37
it ( 'can create claimable target' , async function ( ) {
@@ -83,8 +69,8 @@ contract('BreakInvariantBounty', function ([_, owner, researcher, anyone, nonTar
83
69
await this . bounty . claim ( this . target . address , { from : researcher } ) ;
84
70
} ) ;
85
71
86
- it ( 'is claimed ' , async function ( ) {
87
- ( await this . bounty . claimed ( ) ) . should . equal ( true ) ;
72
+ it ( 'is not claimable ' , async function ( ) {
73
+ ( await this . bounty . claimable ( ) ) . should . equal ( false ) ;
88
74
} ) ;
89
75
90
76
it ( 'no longer accepts rewards' , async function ( ) {
@@ -104,5 +90,42 @@ contract('BreakInvariantBounty', function ([_, owner, researcher, anyone, nonTar
104
90
} ) ;
105
91
} ) ;
106
92
} ) ;
93
+
94
+ describe ( 'cancelBounty' , function ( ) {
95
+ context ( 'before canceling' , function ( ) {
96
+ it ( 'is claimable' , async function ( ) {
97
+ ( await this . bounty . claimable ( ) ) . should . equal ( true ) ;
98
+ } ) ;
99
+
100
+ it ( 'can be canceled by the owner' , async function ( ) {
101
+ const { logs } = await this . bounty . cancelBounty ( { from : owner } ) ;
102
+ expectEvent . inLogs ( logs , 'BountyCanceled' ) ;
103
+ ( await balanceDifference ( owner , ( ) => this . bounty . withdrawPayments ( owner ) ) )
104
+ . should . be . bignumber . equal ( reward ) ;
105
+ } ) ;
106
+
107
+ it ( 'reverts when canceled by anyone' , async function ( ) {
108
+ await assertRevert ( this . bounty . cancelBounty ( { from : anyone } ) ) ;
109
+ } ) ;
110
+ } ) ;
111
+
112
+ context ( 'after canceling' , async function ( ) {
113
+ beforeEach ( async function ( ) {
114
+ await this . bounty . cancelBounty ( { from : owner } ) ;
115
+ } ) ;
116
+
117
+ it ( 'is not claimable' , async function ( ) {
118
+ ( await this . bounty . claimable ( ) ) . should . equal ( false ) ;
119
+ } ) ;
120
+
121
+ it ( 'no longer accepts rewards' , async function ( ) {
122
+ await assertRevert ( ethSendTransaction ( { from : owner , to : this . bounty . address , value : reward } ) ) ;
123
+ } ) ;
124
+
125
+ it ( 'reverts when recanceled' , async function ( ) {
126
+ await assertRevert ( this . bounty . cancelBounty ( { from : owner } ) ) ;
127
+ } ) ;
128
+ } ) ;
129
+ } ) ;
107
130
} ) ;
108
131
} ) ;
0 commit comments