X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=blobdiff_plain;f=protocol%2Fvalidation%2Fblock_test.go;h=6cc0427e612040963c77159b0bc82a484b49b08f;hp=01df93c4dbdf508bc251703af4ce4836292c2e52;hb=f6ec2b987c394f065e527bcdf5942d1f9f0dad66;hpb=bcb18f4ce26ec40aefb2b84107274b6aa9efabfd;ds=sidebyside diff --git a/protocol/validation/block_test.go b/protocol/validation/block_test.go index 01df93c4..6cc0427e 100644 --- a/protocol/validation/block_test.go +++ b/protocol/validation/block_test.go @@ -4,11 +4,9 @@ import ( "testing" "github.com/vapor/consensus" - "github.com/vapor/mining/tensority" "github.com/vapor/protocol/bc" "github.com/vapor/protocol/bc/types" "github.com/vapor/protocol/state" - "github.com/vapor/testutil" ) func TestCheckBlockTime(t *testing.T) { @@ -89,102 +87,3 @@ func TestCheckCoinbaseAmount(t *testing.T) { } } } - -func TestValidateBlockHeader(t *testing.T) { - // add (hash, seed) --> (tensority hash) to the tensority cache for avoid - // real matrix calculate cost. - tensority.AIHash.AddCache(&bc.Hash{V0: 0}, &bc.Hash{}, testutil.MaxHash) - tensority.AIHash.AddCache(&bc.Hash{V0: 1}, &bc.Hash{}, testutil.MinHash) - tensority.AIHash.AddCache(&bc.Hash{V0: 1}, consensus.InitialSeed, testutil.MinHash) - - cases := []struct { - block *bc.Block - parent *state.BlockNode - err error - }{ - { - block: &bc.Block{BlockHeader: &bc.BlockHeader{ - Version: 1, - }}, - parent: &state.BlockNode{ - Version: 2, - }, - err: errVersionRegression, - }, - { - block: &bc.Block{BlockHeader: &bc.BlockHeader{ - Height: 20, - }}, - parent: &state.BlockNode{ - Height: 18, - }, - err: errMisorderedBlockHeight, - }, - { - block: &bc.Block{BlockHeader: &bc.BlockHeader{ - Height: 20, - Bits: 0, - }}, - parent: &state.BlockNode{ - Height: 19, - Bits: 2305843009214532812, - }, - err: errBadBits, - }, - { - block: &bc.Block{BlockHeader: &bc.BlockHeader{ - Height: 20, - PreviousBlockId: &bc.Hash{V0: 18}, - }}, - parent: &state.BlockNode{ - Height: 19, - Hash: bc.Hash{V0: 19}, - }, - err: errMismatchedBlock, - }, - { - block: &bc.Block{ - ID: bc.Hash{V0: 0}, - BlockHeader: &bc.BlockHeader{ - Height: 1, - Timestamp: 1523352601, - PreviousBlockId: &bc.Hash{V0: 0}, - Bits: 2305843009214532812, - }, - }, - parent: &state.BlockNode{ - Height: 0, - Timestamp: 1523352600, - Hash: bc.Hash{V0: 0}, - Seed: &bc.Hash{V1: 1}, - Bits: 2305843009214532812, - }, - err: errWorkProof, - }, - { - block: &bc.Block{ - ID: bc.Hash{V0: 1}, - BlockHeader: &bc.BlockHeader{ - Height: 1, - Timestamp: 1523352601, - PreviousBlockId: &bc.Hash{V0: 0}, - Bits: 2305843009214532812, - }, - }, - parent: &state.BlockNode{ - Height: 0, - Timestamp: 1523352600, - Hash: bc.Hash{V0: 0}, - Seed: &bc.Hash{V1: 1}, - Bits: 2305843009214532812, - }, - err: nil, - }, - } - - for i, c := range cases { - if err := ValidateBlockHeader(c.block, c.parent); rootErr(err) != c.err { - t.Errorf("case %d got error %s, want %s", i, err, c.err) - } - } -}