@@ -2,24 +2,31 @@ const {RelayProvider} = require('@opengsn/provider')
22const { GsnTestEnvironment} = require ( '@opengsn/dev' )
33
44const CaptureTheFlag = artifacts . require ( 'CaptureTheFlag' )
5+ const WhitelistPaymaster = artifacts . require ( 'WhitelistPaymaster' )
56
67const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
78
89contract ( "CaptureTheFlag" , async accounts => {
910
1011 let account
1112 let captureFlagContract
13+ let whitelistPaymaster
1214
1315 before ( async ( ) => {
14- const { forwarderAddress, paymasterAddress} = GsnTestEnvironment . loadDeployment ( )
16+ const { forwarderAddress, relayHubAddress} = GsnTestEnvironment . loadDeployment ( )
17+
18+ const whitelistPaymaster = await WhitelistPaymaster . new ( )
19+ await whitelistPaymaster . setTrustedForwarder ( forwarderAddress )
20+ await whitelistPaymaster . setRelayHub ( relayHubAddress )
21+ await web3 . eth . sendTransaction ( { from : accounts [ 0 ] , to : whitelistPaymaster . address , value : 1e18 } )
1522
1623 captureFlagContract = await CaptureTheFlag . new ( forwarderAddress ) ;
1724
1825 const gsnProvider = await RelayProvider . newProvider ( {
1926 provider : web3 . currentProvider ,
2027 config : {
2128 loggerConfiguration : { logLevel : 'error' } ,
22- paymasterAddress,
29+ paymasterAddress : whitelistPaymaster . address ,
2330 //these 2 params are needed only for ganache:
2431 methodSuffix : '' ,
2532 jsonStringifyRequest : false ,
@@ -33,6 +40,8 @@ contract("CaptureTheFlag", async accounts => {
3340 // default ganache accounts all have eth.
3441 // test from a different account, without any eth
3542 account = gsnProvider . newAccount ( ) . address
43+
44+ await whitelistPaymaster . whitelistSender ( account )
3645 } )
3746
3847 it ( 'Runs with GSN' , async ( ) => {
@@ -41,4 +50,13 @@ contract("CaptureTheFlag", async accounts => {
4150 assert . equal ( res . logs [ 0 ] . args . previousHolder , ZERO_ADDRESS , "Wrong previous flag holder" ) ;
4251 assert . equal ( res . logs [ 0 ] . args . currentHolder , account , "Wrong current flag holder" ) ;
4352 } ) ;
53+
54+ it ( 'Paymaster should reject different account' , async ( ) => {
55+ await captureFlagContract . captureTheFlag ( { from : accounts [ 2 ] } )
56+ . then ( ( ) => {
57+ throw new Error ( 'should revert' )
58+ } )
59+ . catch ( ( ) => {
60+ } )
61+ } ) ;
4462} ) ;
0 commit comments