1- import { getFirstSigner , waitForTx } from '@aave/deploy-v3 ' ;
1+ import { HardhatRuntimeEnvironment } from 'hardhat/types ' ;
22import { expect } from 'chai' ;
33import { parseEther } from 'ethers/lib/utils' ;
4- import { HardhatRuntimeEnvironment } from 'hardhat/types ' ;
4+ import { ONE_ADDRESS , evmRevert , evmSnapshot , waitForTx } from '@aave/deploy-v3 ' ;
55import { makeSuite , TestEnv } from './helpers/make-suite' ;
6+ import { Ownable__factory , TestnetERC20__factory } from '../types' ;
67
78declare let hre : HardhatRuntimeEnvironment ;
89
910makeSuite ( 'Faucet' , ( testEnv : TestEnv ) => {
1011 const mintAmount = parseEther ( '100' ) ;
12+
1113 let faucetOwnable ;
14+
1215 before ( async ( ) => {
1316 // Enforce permissioned mode as disabled for deterministic test suite
1417
@@ -19,6 +22,7 @@ makeSuite('Faucet', (testEnv: TestEnv) => {
1922
2023 await waitForTx ( await faucetOwnable . setPermissioned ( false ) ) ;
2124 } ) ;
25+
2226 describe ( 'Permissioned mode: disabled' , ( ) => {
2327 before ( async ( ) => {
2428 // Enforce permissioned mode as disabled for deterministic test suite
@@ -40,6 +44,39 @@ makeSuite('Faucet', (testEnv: TestEnv) => {
4044 it ( 'Getter isPermissioned should return false' , async ( ) => {
4145 await expect ( await faucetOwnable . isPermissioned ( ) ) . is . equal ( false ) ;
4246 } ) ;
47+
48+ it ( 'Mint function should mint tokens within limit' , async ( ) => {
49+ const {
50+ users : [ , , , user ] ,
51+ dai,
52+ deployer,
53+ } = testEnv ;
54+
55+ const threshold = await faucetOwnable . connect ( deployer . signer ) . MAX_MINT_AMOUNT ( ) ;
56+ const thresholdValue = threshold . toNumber ( ) ;
57+ const withinLimitThreshold = parseEther ( ( thresholdValue ) . toString ( ) ) ;
58+
59+ await faucetOwnable
60+ . connect ( deployer . signer )
61+ . mint ( dai . address , user . address , withinLimitThreshold ) ;
62+ await expect ( await dai . balanceOf ( user . address ) ) . eq ( withinLimitThreshold ) ;
63+ } ) ;
64+
65+ it ( 'Mint function should revert with values over the limit' , async ( ) => {
66+ const {
67+ users : [ , , , user ] ,
68+ dai,
69+ deployer,
70+ } = testEnv ;
71+
72+ const threshold = await faucetOwnable . connect ( deployer . signer ) . MAX_MINT_AMOUNT ( ) ;
73+ const thresholdValue = threshold . toNumber ( ) ;
74+ const maxLimitThreshold = parseEther ( ( thresholdValue + 1 ) . toString ( ) ) ;
75+
76+ await expect (
77+ faucetOwnable . connect ( deployer . signer ) . mint ( dai . address , user . address , maxLimitThreshold )
78+ ) . to . be . revertedWith ( 'Error: Mint limit transaction exceeded' ) ;
79+ } ) ;
4380 } ) ;
4481
4582 describe ( 'Permissioned mode: enabled' , ( ) => {
@@ -59,17 +96,20 @@ makeSuite('Faucet', (testEnv: TestEnv) => {
5996 } ) ;
6097
6198 it ( 'Mint function can only be called by owner' , async ( ) => {
99+ const mintAmount = parseEther ( '100' ) ;
62100 const {
63101 users : [ , , , user ] ,
64102 dai,
65103 deployer,
66104 } = testEnv ;
67105
106+ const initialBalance = await dai . balanceOf ( user . address ) ;
107+
68108 await waitForTx (
69109 await faucetOwnable . connect ( deployer . signer ) . mint ( dai . address , user . address , mintAmount )
70110 ) ;
71111
72- await expect ( await dai . balanceOf ( user . address ) ) . eq ( mintAmount ) ;
112+ await expect ( await dai . balanceOf ( user . address ) ) . eq ( initialBalance . add ( mintAmount ) ) ;
73113 } ) ;
74114
75115 it ( 'Getter isPermissioned should return true' , async ( ) => {
@@ -102,4 +142,41 @@ makeSuite('Faucet', (testEnv: TestEnv) => {
102142
103143 expect ( await faucetOwnable . isPermissioned ( ) ) . equal ( true ) ;
104144 } ) ;
145+
146+ it ( 'Transfer ownership should revert if not owner' , async ( ) => {
147+ const {
148+ deployer,
149+ users : [ user1 ] ,
150+ } = testEnv ;
151+
152+ const childContract = await new TestnetERC20__factory ( deployer . signer ) . deploy (
153+ 'CHILD' ,
154+ 'CHILD' ,
155+ 18 ,
156+ faucetOwnable . address
157+ ) ;
158+ expect ( await childContract . owner ( ) ) . to . be . eq ( faucetOwnable . address ) ;
159+ await expect (
160+ faucetOwnable
161+ . connect ( user1 . signer )
162+ . transferOwnershipOfChild ( [ childContract . address ] , ONE_ADDRESS )
163+ ) . to . be . revertedWith ( 'Ownable: caller is not the owner' ) ;
164+ expect ( await childContract . owner ( ) ) . to . be . eq ( faucetOwnable . address ) ;
165+ } ) ;
166+
167+ it ( 'Transfer ownership of child to another address' , async ( ) => {
168+ const { deployer } = testEnv ;
169+
170+ const childContract = await new TestnetERC20__factory ( deployer . signer ) . deploy (
171+ 'CHILD' ,
172+ 'CHILD' ,
173+ 18 ,
174+ faucetOwnable . address
175+ ) ;
176+ expect ( await childContract . owner ( ) ) . to . be . eq ( faucetOwnable . address ) ;
177+ await faucetOwnable
178+ . connect ( deployer . signer )
179+ . transferOwnershipOfChild ( [ childContract . address ] , ONE_ADDRESS ) ;
180+ expect ( await childContract . owner ( ) ) . to . be . eq ( ONE_ADDRESS ) ;
181+ } ) ;
105182} ) ;
0 commit comments