17
17
package core
18
18
19
19
import (
20
+ "bytes"
20
21
"crypto/ecdsa"
22
+ "fmt"
21
23
"math/big"
24
+ "os"
22
25
"testing"
23
26
24
27
"github.com/ethereum/go-ethereum/common"
@@ -31,6 +34,7 @@ import (
31
34
"github.com/ethereum/go-ethereum/core/vm"
32
35
"github.com/ethereum/go-ethereum/crypto"
33
36
"github.com/ethereum/go-ethereum/params"
37
+ "github.com/ethereum/go-ethereum/rlp"
34
38
"github.com/ethereum/go-ethereum/trie"
35
39
"golang.org/x/crypto/sha3"
36
40
)
@@ -377,32 +381,38 @@ func TestProcessStateless(t *testing.T) {
377
381
genesis := gspec .MustCommit (db )
378
382
blockchain , _ := NewBlockChain (db , nil , gspec .Config , ethash .NewFaker (), vm.Config {}, nil , nil )
379
383
defer blockchain .Stop ()
380
- var blockGasUsedExpected uint64
381
- chain , _ := GenerateVerkleChain (gspec .Config , genesis , ethash .NewFaker (), db , 1 , func (i int , gen * BlockGen ) {
384
+ txCost1 := params .WitnessBranchWriteCost * 2 + params .WitnessBranchReadCost * 2 + params .WitnessChunkWriteCost * 3 + params .WitnessChunkReadCost * 12 + params .TxGas
385
+ txCost2 := params .WitnessBranchWriteCost + params .WitnessBranchReadCost * 2 + params .WitnessChunkWriteCost * 2 + params .WitnessChunkReadCost * 10 + params .TxGas
386
+ blockGasUsedExpected := txCost1 * 2 + txCost2
387
+ chain , _ := GenerateVerkleChain (gspec .Config , genesis , ethash .NewFaker (), db , 2 , func (i int , gen * BlockGen ) {
382
388
// TODO need to check that the tx cost provided is the exact amount used (no remaining left-over)
383
- txCost := params .WitnessBranchWriteCost * 2 + params .WitnessBranchReadCost * 2 + params .WitnessChunkWriteCost * 3 + params .WitnessChunkReadCost * 12 + params .TxGas
384
- blockGasUsedExpected += txCost * 2
385
- tx , _ := types .SignTx (types .NewTransaction (uint64 (i ) * 3 , common.Address {1 , 2 , 3 }, big .NewInt (999 ), txCost , big .NewInt (875000000 ), nil ), signer , testKey )
389
+ tx , _ := types .SignTx (types .NewTransaction (uint64 (i )* 3 , common.Address {1 , 2 , 3 }, big .NewInt (999 ), txCost1 , big .NewInt (875000000 ), nil ), signer , testKey )
386
390
gen .AddTx (tx )
387
- tx , _ = types .SignTx (types .NewTransaction (uint64 (i ) * 3 + 1 , common.Address {}, big .NewInt (999 ), txCost , big .NewInt (875000000 ), nil ), signer , testKey )
391
+ tx , _ = types .SignTx (types .NewTransaction (uint64 (i )* 3 + 1 , common.Address {}, big .NewInt (999 ), txCost1 , big .NewInt (875000000 ), nil ), signer , testKey )
388
392
gen .AddTx (tx )
389
- txCost = params .WitnessBranchWriteCost + params .WitnessBranchReadCost * 2 + params .WitnessChunkWriteCost * 2 + params .WitnessChunkReadCost * 10 + params .TxGas
390
- blockGasUsedExpected += txCost
391
- tx , _ = types .SignTx (types .NewTransaction (uint64 (i ) * 3 + 2 , common.Address {}, big .NewInt (0 ), txCost , big .NewInt (875000000 ), nil ), signer , testKey )
393
+ tx , _ = types .SignTx (types .NewTransaction (uint64 (i )* 3 + 2 , common.Address {}, big .NewInt (0 ), txCost2 , big .NewInt (875000000 ), nil ), signer , testKey )
392
394
gen .AddTx (tx )
393
395
})
394
396
397
+ f , _ := os .Create ("block2.rlp" )
398
+ defer f .Close ()
399
+ var buf bytes.Buffer
400
+ rlp .Encode (& buf , chain [1 ])
401
+ f .Write (buf .Bytes ())
402
+ fmt .Printf ("%x\n " , chain [0 ].Root ())
403
+
395
404
_ , err := blockchain .InsertChain (chain )
396
405
if err != nil {
397
406
t .Fatalf ("block imported with error: %v" , err )
398
407
}
399
408
400
- b := blockchain .GetBlockByNumber (1 )
401
- if b == nil {
402
- t .Fatalf ("expected block 1 to be present in chain" )
403
- }
404
-
405
- if b .GasUsed () != blockGasUsedExpected {
406
- t .Fatalf ("expected block txs to use %d, got %d\n " , blockGasUsedExpected , b .GasUsed ())
409
+ for i := 0 ; i < 2 ; i ++ {
410
+ b := blockchain .GetBlockByNumber (uint64 (i ) + 1 )
411
+ if b == nil {
412
+ t .Fatalf ("expected block %d to be present in chain" , i + 1 )
413
+ }
414
+ if b .GasUsed () != blockGasUsedExpected {
415
+ t .Fatalf ("expected block txs to use %d, got %d\n " , blockGasUsedExpected , b .GasUsed ())
416
+ }
407
417
}
408
418
}
0 commit comments