X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=test%2Fblock_test.go;h=eeb6c95ff5fba3cccffccedd2de15d428e2f7f79;hb=51100c2a5afb320a9b16674f8c66b067fe760eb3;hp=b837c94c6b016c14a838886033435b9cd7938d92;hpb=08281341c2cb02ba11d4218576256688854790fc;p=bytom%2Fvapor.git diff --git a/test/block_test.go b/test/block_test.go index b837c94c..eeb6c95f 100644 --- a/test/block_test.go +++ b/test/block_test.go @@ -7,9 +7,8 @@ import ( "testing" "time" - dbm "github.com/tendermint/tmlibs/db" - "github.com/vapor/consensus" + dbm "github.com/vapor/database/leveldb" "github.com/vapor/protocol/bc" "github.com/vapor/protocol/bc/types" "github.com/vapor/protocol/vm" @@ -18,7 +17,11 @@ import ( func TestBlockHeader(t *testing.T) { db := dbm.NewDB("block_test_db", "leveldb", "block_test_db") defer os.RemoveAll("block_test_db") - chain, _, _, _ := MockChain(db) + chain, _, _, err := MockChain(db) + if err != nil { + t.Fatal(err) + } + genesisHeader := chain.BestBlockHeader() if err := AppendBlocks(chain, 1); err != nil { t.Fatal(err) @@ -30,28 +33,14 @@ func TestBlockHeader(t *testing.T) { prevHeight func() uint64 timestamp func() uint64 prevHash func() *bc.Hash - bits func() uint64 - solve bool valid bool }{ { - desc: "block version is 0", - version: func() uint64 { return 0 }, - prevHeight: chain.BestBlockHeight, - timestamp: func() uint64 { return chain.BestBlockHeader().Timestamp + 1 }, - prevHash: chain.BestBlockHash, - bits: func() uint64 { return chain.BestBlockHeader().Bits }, - solve: true, - valid: false, - }, - { - desc: "block version grater than prevBlock.Version", - version: func() uint64 { return chain.BestBlockHeader().Version + 10 }, + desc: "block version is 1", + version: func() uint64 { return 1 }, prevHeight: chain.BestBlockHeight, timestamp: func() uint64 { return chain.BestBlockHeader().Timestamp + 1 }, prevHash: chain.BestBlockHash, - bits: func() uint64 { return chain.BestBlockHeader().Bits }, - solve: true, valid: true, }, { @@ -60,8 +49,6 @@ func TestBlockHeader(t *testing.T) { prevHeight: func() uint64 { return chain.BestBlockHeight() + 1 }, timestamp: func() uint64 { return chain.BestBlockHeader().Timestamp + 1 }, prevHash: chain.BestBlockHash, - bits: func() uint64 { return chain.BestBlockHeader().Bits }, - solve: true, valid: false, }, { @@ -70,28 +57,14 @@ func TestBlockHeader(t *testing.T) { prevHeight: chain.BestBlockHeight, timestamp: func() uint64 { return chain.BestBlockHeader().Timestamp + 1 }, prevHash: func() *bc.Hash { hash := genesisHeader.Hash(); return &hash }, - bits: func() uint64 { return chain.BestBlockHeader().Bits }, - solve: true, valid: false, }, { - desc: "invalid bits", + desc: "invalid timestamp, greater than MaxTimeOffsetMs from system time", version: func() uint64 { return chain.BestBlockHeader().Version }, prevHeight: chain.BestBlockHeight, - timestamp: func() uint64 { return chain.BestBlockHeader().Timestamp + 1 }, - prevHash: chain.BestBlockHash, - bits: func() uint64 { return chain.BestBlockHeader().Bits + 100 }, - solve: true, - valid: false, - }, - { - desc: "invalid timestamp, greater than MaxTimeOffsetSeconds from system time", - version: func() uint64 { return chain.BestBlockHeader().Version }, - prevHeight: chain.BestBlockHeight, - timestamp: func() uint64 { return uint64(time.Now().Unix()) + consensus.MaxTimeOffsetSeconds + 60 }, + timestamp: func() uint64 { return uint64(time.Now().Unix()) + consensus.ActiveNetParams.MaxTimeOffsetMs + 60 }, prevHash: chain.BestBlockHash, - bits: func() uint64 { return chain.BestBlockHeader().Bits }, - solve: true, valid: false, }, { @@ -100,8 +73,6 @@ func TestBlockHeader(t *testing.T) { prevHeight: chain.BestBlockHeight, timestamp: func() uint64 { return chain.BestBlockHeader().Timestamp + 3 }, prevHash: chain.BestBlockHash, - bits: func() uint64 { return chain.BestBlockHeader().Bits }, - solve: true, valid: true, }, { @@ -110,8 +81,6 @@ func TestBlockHeader(t *testing.T) { prevHeight: chain.BestBlockHeight, timestamp: func() uint64 { return chain.BestBlockHeader().Timestamp - 1 }, prevHash: chain.BestBlockHash, - bits: func() uint64 { return chain.BestBlockHeader().Bits }, - solve: true, valid: true, }, { @@ -120,8 +89,6 @@ func TestBlockHeader(t *testing.T) { prevHeight: chain.BestBlockHeight, timestamp: func() uint64 { return genesisHeader.Timestamp }, prevHash: chain.BestBlockHash, - bits: func() uint64 { return chain.BestBlockHeader().Bits }, - solve: true, valid: false, }, } @@ -136,15 +103,7 @@ func TestBlockHeader(t *testing.T) { block.Height = c.prevHeight() + 1 block.Timestamp = c.timestamp() block.PreviousBlockHash = *c.prevHash() - block.Bits = c.bits() - seed, err := chain.CalcNextSeed(&block.PreviousBlockHash) - if err != nil && c.valid { - t.Fatal(err) - } - if c.solve { - Solve(seed, block) - } _, err = chain.ProcessBlock(block) result := err == nil if result != c.valid { @@ -191,7 +150,7 @@ func TestMaxBlockGas(t *testing.T) { t.Fatal(err) } - if err := SolveAndUpdate(chain, block); err == nil { + if _, err := chain.ProcessBlock(block); err == nil { t.Fatalf("test max block gas failed") } }