@@ -59,9 +59,12 @@ func TestSimulatedBackend(t *testing.T) {
5959 }
6060
6161 // generate a transaction and confirm you can retrieve it
62+ head , _ := sim .HeaderByNumber (context .Background (), nil ) // Should be child's, good enough
63+ gasPrice := new (big.Int ).Add (head .BaseFee , big .NewInt (1 ))
64+
6265 code := `6060604052600a8060106000396000f360606040526008565b00`
6366 var gas uint64 = 3000000
64- tx := types .NewContractCreation (0 , big .NewInt (0 ), gas , big . NewInt ( 1 ) , common .FromHex (code ))
67+ tx := types .NewContractCreation (0 , big .NewInt (0 ), gas , gasPrice , common .FromHex (code ))
6568 tx , _ = types .SignTx (tx , types.HomesteadSigner {}, key )
6669
6770 err = sim .SendTransaction (context .Background (), tx )
@@ -111,14 +114,14 @@ var expectedReturn = []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
111114func simTestBackend (testAddr common.Address ) * SimulatedBackend {
112115 return NewSimulatedBackend (
113116 core.GenesisAlloc {
114- testAddr : {Balance : big .NewInt (10000000000 )},
117+ testAddr : {Balance : big .NewInt (10000000000000000 )},
115118 }, 10000000 ,
116119 )
117120}
118121
119122func TestNewSimulatedBackend (t * testing.T ) {
120123 testAddr := crypto .PubkeyToAddress (testKey .PublicKey )
121- expectedBal := big .NewInt (10000000000 )
124+ expectedBal := big .NewInt (10000000000000000 )
122125 sim := simTestBackend (testAddr )
123126 defer sim .Close ()
124127
@@ -157,8 +160,12 @@ func TestAdjustTime(t *testing.T) {
157160func TestNewAdjustTimeFail (t * testing.T ) {
158161 testAddr := crypto .PubkeyToAddress (testKey .PublicKey )
159162 sim := simTestBackend (testAddr )
163+
160164 // Create tx and send
161- tx := types .NewTransaction (0 , testAddr , big .NewInt (1000 ), params .TxGas , big .NewInt (1 ), nil )
165+ head , _ := sim .HeaderByNumber (context .Background (), nil ) // Should be child's, good enough
166+ gasPrice := new (big.Int ).Add (head .BaseFee , big .NewInt (1 ))
167+
168+ tx := types .NewTransaction (0 , testAddr , big .NewInt (1000 ), params .TxGas , gasPrice , nil )
162169 signedTx , err := types .SignTx (tx , types.HomesteadSigner {}, testKey )
163170 if err != nil {
164171 t .Errorf ("could not sign tx: %v" , err )
@@ -179,7 +186,7 @@ func TestNewAdjustTimeFail(t *testing.T) {
179186 t .Errorf ("adjusted time not equal to a minute. prev: %v, new: %v" , prevTime , newTime )
180187 }
181188 // Put a transaction after adjusting time
182- tx2 := types .NewTransaction (1 , testAddr , big .NewInt (1000 ), params .TxGas , big . NewInt ( 1 ) , nil )
189+ tx2 := types .NewTransaction (1 , testAddr , big .NewInt (1000 ), params .TxGas , gasPrice , nil )
183190 signedTx2 , err := types .SignTx (tx2 , types.HomesteadSigner {}, testKey )
184191 if err != nil {
185192 t .Errorf ("could not sign tx: %v" , err )
@@ -194,7 +201,7 @@ func TestNewAdjustTimeFail(t *testing.T) {
194201
195202func TestBalanceAt (t * testing.T ) {
196203 testAddr := crypto .PubkeyToAddress (testKey .PublicKey )
197- expectedBal := big .NewInt (10000000000 )
204+ expectedBal := big .NewInt (10000000000000000 )
198205 sim := simTestBackend (testAddr )
199206 defer sim .Close ()
200207 bgCtx := context .Background ()
@@ -282,7 +289,10 @@ func TestNonceAt(t *testing.T) {
282289 }
283290
284291 // create a signed transaction to send
285- tx := types .NewTransaction (nonce , testAddr , big .NewInt (1000 ), params .TxGas , big .NewInt (1 ), nil )
292+ head , _ := sim .HeaderByNumber (context .Background (), nil ) // Should be child's, good enough
293+ gasPrice := new (big.Int ).Add (head .BaseFee , big .NewInt (1 ))
294+
295+ tx := types .NewTransaction (nonce , testAddr , big .NewInt (1000 ), params .TxGas , gasPrice , nil )
286296 signedTx , err := types .SignTx (tx , types.HomesteadSigner {}, testKey )
287297 if err != nil {
288298 t .Errorf ("could not sign tx: %v" , err )
@@ -323,7 +333,10 @@ func TestSendTransaction(t *testing.T) {
323333 bgCtx := context .Background ()
324334
325335 // create a signed transaction to send
326- tx := types .NewTransaction (uint64 (0 ), testAddr , big .NewInt (1000 ), params .TxGas , big .NewInt (1 ), nil )
336+ head , _ := sim .HeaderByNumber (context .Background (), nil ) // Should be child's, good enough
337+ gasPrice := new (big.Int ).Add (head .BaseFee , big .NewInt (1 ))
338+
339+ tx := types .NewTransaction (uint64 (0 ), testAddr , big .NewInt (1000 ), params .TxGas , gasPrice , nil )
327340 signedTx , err := types .SignTx (tx , types.HomesteadSigner {}, testKey )
328341 if err != nil {
329342 t .Errorf ("could not sign tx: %v" , err )
@@ -351,14 +364,17 @@ func TestTransactionByHash(t *testing.T) {
351364
352365 sim := NewSimulatedBackend (
353366 core.GenesisAlloc {
354- testAddr : {Balance : big .NewInt (10000000000 )},
367+ testAddr : {Balance : big .NewInt (10000000000000000 )},
355368 }, 10000000 ,
356369 )
357370 defer sim .Close ()
358371 bgCtx := context .Background ()
359372
360373 // create a signed transaction to send
361- tx := types .NewTransaction (uint64 (0 ), testAddr , big .NewInt (1000 ), params .TxGas , big .NewInt (1 ), nil )
374+ head , _ := sim .HeaderByNumber (context .Background (), nil ) // Should be child's, good enough
375+ gasPrice := new (big.Int ).Add (head .BaseFee , big .NewInt (1 ))
376+
377+ tx := types .NewTransaction (uint64 (0 ), testAddr , big .NewInt (1000 ), params .TxGas , gasPrice , nil )
362378 signedTx , err := types .SignTx (tx , types.HomesteadSigner {}, testKey )
363379 if err != nil {
364380 t .Errorf ("could not sign tx: %v" , err )
@@ -534,16 +550,16 @@ func TestEstimateGasWithPrice(t *testing.T) {
534550 To : & recipient ,
535551 Gas : 0 ,
536552 GasPrice : big .NewInt (0 ),
537- Value : big .NewInt (1000 ),
553+ Value : big .NewInt (100000000000 ),
538554 Data : nil ,
539555 }, 21000 , nil },
540556
541557 {"EstimateWithPrice" , ethereum.CallMsg {
542558 From : addr ,
543559 To : & recipient ,
544560 Gas : 0 ,
545- GasPrice : big .NewInt (1000 ),
546- Value : big .NewInt (1000 ),
561+ GasPrice : big .NewInt (100000000000 ),
562+ Value : big .NewInt (100000000000 ),
547563 Data : nil ,
548564 }, 21000 , nil },
549565
@@ -561,23 +577,23 @@ func TestEstimateGasWithPrice(t *testing.T) {
561577 To : & recipient ,
562578 Gas : 0 ,
563579 GasPrice : big .NewInt (2e14 ), // gascost = 4.2ether
564- Value : big .NewInt (1000 ),
580+ Value : big .NewInt (100000000000 ),
565581 Data : nil ,
566582 }, 21000 , errors .New ("gas required exceeds allowance (10999)" )}, // 10999=(2.2ether-1000wei)/(2e14)
567583 }
568- for _ , c := range cases {
584+ for i , c := range cases {
569585 got , err := sim .EstimateGas (context .Background (), c .message )
570586 if c .expectError != nil {
571587 if err == nil {
572- t .Fatalf ("Expect error, got nil" )
588+ t .Fatalf ("test %d: expect error, got nil" , i )
573589 }
574590 if c .expectError .Error () != err .Error () {
575- t .Fatalf ("Expect error, want %v, got %v" , c .expectError , err )
591+ t .Fatalf ("test %d: expect error, want %v, got %v" , i , c .expectError , err )
576592 }
577593 continue
578594 }
579595 if got != c .expect {
580- t .Fatalf ("Gas estimation mismatch, want %d, got %d" , c .expect , got )
596+ t .Fatalf ("test %d: gas estimation mismatch, want %d, got %d" , i , c .expect , got )
581597 }
582598 }
583599}
@@ -669,9 +685,11 @@ func TestTransactionCount(t *testing.T) {
669685 if count != 0 {
670686 t .Errorf ("expected transaction count of %v does not match actual count of %v" , 0 , count )
671687 }
672-
673688 // create a signed transaction to send
674- tx := types .NewTransaction (uint64 (0 ), testAddr , big .NewInt (1000 ), params .TxGas , big .NewInt (1 ), nil )
689+ head , _ := sim .HeaderByNumber (context .Background (), nil ) // Should be child's, good enough
690+ gasPrice := new (big.Int ).Add (head .BaseFee , big .NewInt (1 ))
691+
692+ tx := types .NewTransaction (uint64 (0 ), testAddr , big .NewInt (1000 ), params .TxGas , gasPrice , nil )
675693 signedTx , err := types .SignTx (tx , types.HomesteadSigner {}, testKey )
676694 if err != nil {
677695 t .Errorf ("could not sign tx: %v" , err )
@@ -724,9 +742,11 @@ func TestTransactionInBlock(t *testing.T) {
724742 if pendingNonce != uint64 (0 ) {
725743 t .Errorf ("expected pending nonce of 0 got %v" , pendingNonce )
726744 }
727-
728745 // create a signed transaction to send
729- tx := types .NewTransaction (uint64 (0 ), testAddr , big .NewInt (1000 ), params .TxGas , big .NewInt (1 ), nil )
746+ head , _ := sim .HeaderByNumber (context .Background (), nil ) // Should be child's, good enough
747+ gasPrice := new (big.Int ).Add (head .BaseFee , big .NewInt (1 ))
748+
749+ tx := types .NewTransaction (uint64 (0 ), testAddr , big .NewInt (1000 ), params .TxGas , gasPrice , nil )
730750 signedTx , err := types .SignTx (tx , types.HomesteadSigner {}, testKey )
731751 if err != nil {
732752 t .Errorf ("could not sign tx: %v" , err )
@@ -781,7 +801,10 @@ func TestPendingNonceAt(t *testing.T) {
781801 }
782802
783803 // create a signed transaction to send
784- tx := types .NewTransaction (uint64 (0 ), testAddr , big .NewInt (1000 ), params .TxGas , big .NewInt (1 ), nil )
804+ head , _ := sim .HeaderByNumber (context .Background (), nil ) // Should be child's, good enough
805+ gasPrice := new (big.Int ).Add (head .BaseFee , big .NewInt (1 ))
806+
807+ tx := types .NewTransaction (uint64 (0 ), testAddr , big .NewInt (1000 ), params .TxGas , gasPrice , nil )
785808 signedTx , err := types .SignTx (tx , types.HomesteadSigner {}, testKey )
786809 if err != nil {
787810 t .Errorf ("could not sign tx: %v" , err )
@@ -804,7 +827,7 @@ func TestPendingNonceAt(t *testing.T) {
804827 }
805828
806829 // make a new transaction with a nonce of 1
807- tx = types .NewTransaction (uint64 (1 ), testAddr , big .NewInt (1000 ), params .TxGas , big . NewInt ( 1 ) , nil )
830+ tx = types .NewTransaction (uint64 (1 ), testAddr , big .NewInt (1000 ), params .TxGas , gasPrice , nil )
808831 signedTx , err = types .SignTx (tx , types.HomesteadSigner {}, testKey )
809832 if err != nil {
810833 t .Errorf ("could not sign tx: %v" , err )
@@ -833,7 +856,10 @@ func TestTransactionReceipt(t *testing.T) {
833856 bgCtx := context .Background ()
834857
835858 // create a signed transaction to send
836- tx := types .NewTransaction (uint64 (0 ), testAddr , big .NewInt (1000 ), params .TxGas , big .NewInt (1 ), nil )
859+ head , _ := sim .HeaderByNumber (context .Background (), nil ) // Should be child's, good enough
860+ gasPrice := new (big.Int ).Add (head .BaseFee , big .NewInt (1 ))
861+
862+ tx := types .NewTransaction (uint64 (0 ), testAddr , big .NewInt (1000 ), params .TxGas , gasPrice , nil )
837863 signedTx , err := types .SignTx (tx , types.HomesteadSigner {}, testKey )
838864 if err != nil {
839865 t .Errorf ("could not sign tx: %v" , err )
@@ -1259,7 +1285,10 @@ func TestForkResendTx(t *testing.T) {
12591285 // 1.
12601286 parent := sim .blockchain .CurrentBlock ()
12611287 // 2.
1262- _tx := types .NewTransaction (0 , testAddr , big .NewInt (1000 ), params .TxGas , big .NewInt (1 ), nil )
1288+ head , _ := sim .HeaderByNumber (context .Background (), nil ) // Should be child's, good enough
1289+ gasPrice := new (big.Int ).Add (head .BaseFee , big .NewInt (1 ))
1290+
1291+ _tx := types .NewTransaction (0 , testAddr , big .NewInt (1000 ), params .TxGas , gasPrice , nil )
12631292 tx , _ := types .SignTx (_tx , types.HomesteadSigner {}, testKey )
12641293 sim .SendTransaction (context .Background (), tx )
12651294 sim .Commit ()
0 commit comments