@@ -12,26 +12,36 @@ const assert = chai.assert;
1212
1313const Profile = artifacts . require ( "GSNProfile" ) ;
1414const ArtistToken = artifacts . require ( "ArtistToken" ) ;
15+ const FundingPool = artifacts . require ( "FundingPool" ) ;
1516const WPHT = artifacts . require ( "WPHT" ) ;
1617
1718const Web3 = require ( '../src/web3' ) ;
1819const {
1920 buyArtistToken,
20- transferArtistTokens ,
21+ transferIERC20Token ,
2122 hatchArtistToken,
2223 refundArtistToken,
2324 claimArtistToken,
2425} = require ( '../src/contracts/profile' ) ;
2526
2627const {
27- remainingHatchingAmount
28+ allocateFunds,
29+ } = require ( '../src/contracts/fundingPool' ) ;
30+
31+ const {
32+ getWPHTBalanceOf,
33+ } = require ( '../src/contracts/wpht' ) ;
34+
35+ const {
36+ remainingHatchingAmount,
2837} = require ( '../migrations/03_deploy_artist_token' ) ;
2938
3039const {
3140 getBalanceOf,
3241} = require ( '../src/contracts/artist_token' ) ;
3342
34- contract ( 'Profile' , ( accounts ) => {
43+ // @IMPORTANT : Require redeploy migration `03_deploy_artist_token.js`
44+ contract ( 'ArtistToken' , ( accounts ) => {
3545 const ROOT_ACCOUNT = process . env . NETWORK === 'ganache' ? accounts [ 0 ] : process . env . ACCOUNT ;
3646 let FAN_ACCOUNT ;
3747 const ACCOUNT_DEFAULT_PASSWORD = 'test123' ;
@@ -131,12 +141,12 @@ contract('Profile', (accounts) => {
131141 assert . equal ( bougthAmount , balanceOfContract ) ;
132142
133143 // Withdraw artist tokens back to user
134- await transferArtistTokens ( web3 , {
144+ await transferIERC20Token ( web3 , {
135145 from : FAN_ACCOUNT ,
136146 beneficiary : FAN_ACCOUNT ,
137147 contractAddr : fanProfileInstance . address ,
138- amount : balanceOfContract ,
139- artistToken : artistTokenInstance . address
148+ amount : Web3 . utils . toBN ( balanceOfContract ) ,
149+ tokenAddr : artistTokenInstance . address
140150 } ) ;
141151
142152 const balanceOfUser = await getBalanceOf ( web3 , {
@@ -147,7 +157,7 @@ contract('Profile', (accounts) => {
147157 assert . equal ( bougthAmount , balanceOfUser ) ;
148158 } ) ;
149159
150- it ( 'should claim ArtistToken hatch amount' , async ( ) => {
160+ it ( 'should claim ArtistToken contributor hatch amount' , async ( ) => {
151161 const artistTokenInstance = await ArtistToken . deployed ( ) ;
152162
153163 console . log ( `Claiming artist tokens...` ) ;
@@ -165,4 +175,70 @@ contract('Profile', (accounts) => {
165175 assert . equal ( claimedTotal , balanceOfContract ) ;
166176 } ) ;
167177
178+ it ( 'should claim accumulated WPHT from hatching' , async ( ) => {
179+ const wphtInstance = await WPHT . deployed ( ) ;
180+ const artistTokenInstance = await ArtistToken . deployed ( ) ;
181+ const fundingPoolInstance = await FundingPool . deployed ( ) ;
182+ // We are using fan profile contract as beneficiary because it is the only profile deployed
183+ // within the scope of this test
184+ const beneficiaryAddr = fanProfileInstance . address ;
185+
186+ const fundingPoolWPHTBalanceInWei = await getWPHTBalanceOf ( web3 , {
187+ wphtAddr : wphtInstance . address ,
188+ accountAddr : fundingPoolInstance . address ,
189+ } ) ;
190+
191+ const beforeWPHTBalanceInWei = await getWPHTBalanceOf ( web3 , {
192+ wphtAddr : wphtInstance . address ,
193+ accountAddr : beneficiaryAddr ,
194+ } ) ;
195+
196+ console . log ( `Claiming ${ Web3 . utils . toPht ( fundingPoolWPHTBalanceInWei ) } WPHT from hatching of artist tokens...` ) ;
197+ await allocateFunds ( web3 , {
198+ from : ROOT_ACCOUNT ,
199+ contractAddr : fundingPoolInstance . address ,
200+ artistTokenAddr : artistTokenInstance . address ,
201+ beneficiary : beneficiaryAddr ,
202+ amount : fundingPoolWPHTBalanceInWei
203+ } ) ;
204+
205+ const afterWPHTBalanceInWei = await getWPHTBalanceOf ( web3 , {
206+ wphtAddr : wphtInstance . address ,
207+ accountAddr : beneficiaryAddr ,
208+ } ) ;
209+
210+ assert . equal ( afterWPHTBalanceInWei . toString ( ) , beforeWPHTBalanceInWei . add ( fundingPoolWPHTBalanceInWei ) . toString ( ) ) ;
211+ } ) ;
212+
213+ it ( 'should pull WPHT from holded by profile contract' , async ( ) => {
214+ const wphtInstance = await WPHT . deployed ( ) ;
215+ const beneficiaryAddr = ROOT_ACCOUNT ;
216+
217+ const profileWPHTBalanceInWei = await getWPHTBalanceOf ( web3 , {
218+ wphtAddr : wphtInstance . address ,
219+ accountAddr : fanProfileInstance . address ,
220+ } ) ;
221+
222+ const beforeWPHTBalanceInWei = await getWPHTBalanceOf ( web3 , {
223+ wphtAddr : wphtInstance . address ,
224+ accountAddr : beneficiaryAddr ,
225+ } ) ;
226+
227+ // Withdraw artist tokens back to user
228+ await transferIERC20Token ( web3 , {
229+ from : FAN_ACCOUNT ,
230+ beneficiary : beneficiaryAddr ,
231+ contractAddr : fanProfileInstance . address ,
232+ amount : profileWPHTBalanceInWei ,
233+ tokenAddr : wphtInstance . address
234+ } ) ;
235+
236+ const afterWPHTBalanceInWei = await getWPHTBalanceOf ( web3 , {
237+ wphtAddr : wphtInstance . address ,
238+ accountAddr : beneficiaryAddr ,
239+ } ) ;
240+
241+ assert . equal ( afterWPHTBalanceInWei . toString ( ) , beforeWPHTBalanceInWei . add ( profileWPHTBalanceInWei ) . toString ( ) ) ;
242+ } ) ;
243+
168244} ) ;
0 commit comments