@@ -65,9 +65,10 @@ func TestMinimumGasConsumption(t *testing.T) {
6565	// All transactions will be basic transfers so consume [params.TxGas] by 
6666	// default. 
6767	tests  :=  []struct  {
68- 		name                      string 
69- 		gasLimit , minConsumption  uint64 
70- 		wantUsed                  uint64 
68+ 		name              string 
69+ 		gasLimit , refund  uint64 
70+ 		minConsumption    uint64 
71+ 		wantUsed          uint64 
7172	}{
7273		{
7374			name :           "consume_extra" ,
@@ -105,6 +106,21 @@ func TestMinimumGasConsumption(t *testing.T) {
105106			minConsumption : 2e6 ,
106107			wantUsed :       1e6 ,
107108		},
109+ 		{
110+ 			// Although this doesn't test minimum consumption, it demonstrates 
111+ 			// the expected outcome for comparison with the next test. 
112+ 			name :     "refund_without_min_consumption" ,
113+ 			gasLimit : 1e6 ,
114+ 			refund :   1 ,
115+ 			wantUsed : params .TxGas  -  1 ,
116+ 		},
117+ 		{
118+ 			name :           "refund_with_min_consumption" ,
119+ 			gasLimit :       1e6 ,
120+ 			refund :         1 ,
121+ 			minConsumption : params .TxGas ,
122+ 			wantUsed :       params .TxGas ,
123+ 		},
108124	}
109125
110126	// Very low gas price so we can calculate the expected balance in a uint64, 
@@ -136,18 +152,18 @@ func TestMinimumGasConsumption(t *testing.T) {
136152					Value :    big .NewInt (0 ),
137153				},
138154			)
139- 			msg , err  :=  core .TransactionToMessage (tx , signer , big .NewInt (gasPrice ))
140- 			require .NoError (t , err , "core.TransactionToMessage(types.MustSignNewTx(...))" )
141155
142156			const  startingBalance  =  10  *  params .Ether 
143- 			stateDB .SetNonce (msg .From , 0 )
144- 			stateDB .SetBalance (msg .From , uint256 .NewInt (startingBalance ))
157+ 			from  :=  crypto .PubkeyToAddress (key .PublicKey )
158+ 			stateDB .SetNonce (from , 0 )
159+ 			stateDB .SetBalance (from , uint256 .NewInt (startingBalance ))
160+ 			stateDB .AddRefund (tt .refund )
145161
146162			var  (
147163				// Both variables are passed as pointers to 
148164				// [core.ApplyTransaction], which will modify them. 
149165				gotUsed  uint64 
150- 				gotPool  =  core .GasPool (1e9 )  // modified when passed as pointer 
166+ 				gotPool  =  core .GasPool (1e9 )
151167			)
152168			wantPool  :=  gotPool  -  core .GasPool (tt .wantUsed )
153169
@@ -177,7 +193,7 @@ func TestMinimumGasConsumption(t *testing.T) {
177193			}
178194
179195			wantBalance  :=  startingBalance  -  tt .wantUsed * gasPrice 
180- 			if  got  :=  stateDB .GetBalance (msg . From ); ! got .IsUint64 () ||  got .Uint64 () !=  wantBalance  {
196+ 			if  got  :=  stateDB .GetBalance (from ); ! got .IsUint64 () ||  got .Uint64 () !=  wantBalance  {
181197				t .Errorf ("got remaining balance %s; want %d" , got .String (), wantBalance )
182198			}
183199		})
0 commit comments