@@ -4,7 +4,6 @@ import { assert } from 'chai'
4
4
import { mint , prepareTests , stake } from './lib/utils'
5
5
6
6
const amountToStake = parseEther ( '20' )
7
- const amountToMint = parseEther ( '1' )
8
7
9
8
describe ( 'EthereumStaker.buildMintTx' , ( ) => {
10
9
let delegatorAddress : Hex
@@ -34,11 +33,12 @@ describe('EthereumStaker.buildMintTx', () => {
34
33
} )
35
34
} )
36
35
37
- it ( 'should build a minting tx' , async ( ) => {
36
+ it ( 'builds a minting tx' , async ( ) => {
38
37
const { maxMint } = await staker . getMint ( {
39
38
delegatorAddress,
40
39
validatorAddress
41
40
} )
41
+ const amountToMint = parseEther ( '2' )
42
42
43
43
assert ( parseEther ( maxMint ) > 0n )
44
44
assert ( parseEther ( maxMint ) > amountToMint )
@@ -72,4 +72,71 @@ describe('EthereumStaker.buildMintTx', () => {
72
72
} )
73
73
assert . equal ( osEthBalance , amountToMint )
74
74
} )
75
+
76
+ it ( 'allows minting max value' , async ( ) => {
77
+ const { maxMint } = await staker . getMint ( {
78
+ delegatorAddress,
79
+ validatorAddress
80
+ } )
81
+
82
+ assert ( parseEther ( maxMint ) > 0n )
83
+ const amountToMint = parseEther ( maxMint )
84
+
85
+ await mint ( {
86
+ delegatorAddress,
87
+ validatorAddress,
88
+ amountToMint,
89
+ publicClient,
90
+ walletClient,
91
+ staker
92
+ } )
93
+
94
+ const { maxMint : maxMintAfter } = await staker . getMint ( {
95
+ delegatorAddress,
96
+ validatorAddress
97
+ } )
98
+
99
+ // Take into account vault fees
100
+ assert . closeTo (
101
+ Number ( parseEther ( maxMintAfter ) ) ,
102
+ Number ( parseEther ( maxMint ) - amountToMint ) ,
103
+ Number ( parseEther ( '0.001' ) )
104
+ )
105
+
106
+ const osEthBalance = await publicClient . readContract ( {
107
+ abi : erc20Abi ,
108
+ address : osEthTokenAddress ,
109
+ functionName : 'balanceOf' ,
110
+ args : [ delegatorAddress ]
111
+ } )
112
+ assert . equal ( osEthBalance , amountToMint )
113
+ } )
114
+
115
+ it ( 'does not allow minting more than max value' , async ( ) => {
116
+ const { maxMint } = await staker . getMint ( {
117
+ delegatorAddress,
118
+ validatorAddress
119
+ } )
120
+
121
+ assert ( parseEther ( maxMint ) > 0n )
122
+ // Add 2 wei above max
123
+ // 2 instead of 1 is to avoid conversion issues
124
+ const amountToMint = parseEther ( maxMint ) + 2n
125
+
126
+ let error = undefined
127
+ try {
128
+ await mint ( {
129
+ delegatorAddress,
130
+ validatorAddress,
131
+ amountToMint,
132
+ publicClient,
133
+ walletClient,
134
+ staker
135
+ } )
136
+ } catch ( e ) {
137
+ error = e
138
+ }
139
+
140
+ assert ( error !== undefined )
141
+ } )
75
142
} )
0 commit comments