"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"
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)
prevHeight func() uint64
timestamp func() uint64
prevHash func() *bc.Hash
- 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,
- 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,
- solve: true,
valid: true,
},
{
prevHeight: func() uint64 { return chain.BestBlockHeight() + 1 },
timestamp: func() uint64 { return chain.BestBlockHeader().Timestamp + 1 },
prevHash: chain.BestBlockHash,
- solve: true,
valid: false,
},
{
prevHeight: chain.BestBlockHeight,
timestamp: func() uint64 { return chain.BestBlockHeader().Timestamp + 1 },
prevHash: func() *bc.Hash { hash := genesisHeader.Hash(); return &hash },
- solve: true,
valid: false,
},
{
- desc: "invalid timestamp, greater than MaxTimeOffsetSeconds from system time",
+ desc: "invalid timestamp, greater than MaxTimeOffsetMs 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,
- solve: true,
valid: false,
},
{
prevHeight: chain.BestBlockHeight,
timestamp: func() uint64 { return chain.BestBlockHeader().Timestamp + 3 },
prevHash: chain.BestBlockHash,
- solve: true,
valid: true,
},
{
prevHeight: chain.BestBlockHeight,
timestamp: func() uint64 { return chain.BestBlockHeader().Timestamp - 1 },
prevHash: chain.BestBlockHash,
- solve: true,
valid: true,
},
{
prevHeight: chain.BestBlockHeight,
timestamp: func() uint64 { return genesisHeader.Timestamp },
prevHash: chain.BestBlockHash,
- solve: true,
valid: false,
},
}
t.Fatal(err)
}
- if err := SolveAndUpdate(chain, block); err == nil {
+ if _, err := chain.ProcessBlock(block); err == nil {
t.Fatalf("test max block gas failed")
}
}