"time"
"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/protocol/vm"
"github.com/vapor/protocol/vm/vmutil"
- "github.com/vapor/testutil"
)
func TestCheckBlockTime(t *testing.T) {
}
func TestValidateBlockHeader(t *testing.T) {
- iniTtensority()
-
cases := []struct {
desc string
block *bc.Block
err: errMisorderedBlockHeight,
},
{
- desc: "the difficulty of the block is not equals to the next difficulty of parent block (blocktest#1008)",
- block: &bc.Block{BlockHeader: &bc.BlockHeader{
- Version: 1,
- Height: 20,
- Bits: 0,
- }},
- parent: &state.BlockNode{
- Version: 1,
- Height: 19,
- Bits: 2305843009214532812,
- },
- err: errBadBits,
- },
- {
desc: "the prev block hash not equals to the hash of parent (blocktest#1004)",
block: &bc.Block{BlockHeader: &bc.BlockHeader{
Version: 1,
err: errMismatchedBlock,
},
{
- desc: "check work proof fail (blocktest#1011)",
- block: &bc.Block{
- ID: bc.Hash{V0: 0},
- BlockHeader: &bc.BlockHeader{
- Version: 1,
- Height: 1,
- Timestamp: 1523352601,
- PreviousBlockId: &bc.Hash{V0: 0},
- Bits: 2305843009214532812,
- },
- },
- parent: &state.BlockNode{
- Version: 1,
- 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,
},
// TestValidateBlock test the ValidateBlock function
func TestValidateBlock(t *testing.T) {
- iniTtensority()
-
cp, _ := vmutil.DefaultCoinbaseProgram()
cases := []struct {
desc string
Height: 1,
Timestamp: 1523352601,
PreviousBlockId: &bc.Hash{V0: 0},
- Bits: 2305843009214532812,
TransactionsRoot: &bc.Hash{V0: 1},
},
Transactions: []*bc.Tx{
Height: 0,
Timestamp: 1523352600,
Hash: bc.Hash{V0: 0},
- Seed: &bc.Hash{V1: 1},
- Bits: 2305843009214532812,
},
err: errMismatchedMerkleRoot,
},
Height: 1,
Timestamp: 1523352601,
PreviousBlockId: &bc.Hash{V0: 0},
- Bits: 2305843009214532812,
TransactionsRoot: &bc.Hash{V0: 6294987741126419124, V1: 12520373106916389157, V2: 5040806596198303681, V3: 1151748423853876189},
TransactionStatusHash: &bc.Hash{V0: 1},
},
Height: 0,
Timestamp: 1523352600,
Hash: bc.Hash{V0: 0},
- Seed: &bc.Hash{V1: 1},
- Bits: 2305843009214532812,
},
err: errMismatchedMerkleRoot,
},
Height: 1,
Timestamp: 1523352601,
PreviousBlockId: &bc.Hash{V0: 0},
- Bits: 2305843009214532812,
},
Transactions: []*bc.Tx{
types.MapTx(&types.TxData{
Height: 0,
Timestamp: 1523352600,
Hash: bc.Hash{V0: 0},
- Seed: &bc.Hash{V1: 1},
- Bits: 2305843009214532812,
},
err: ErrWrongCoinbaseTransaction,
},
// TestGasOverBlockLimit check if the gas of the block has the max limit (blocktest#1012)
func TestGasOverBlockLimit(t *testing.T) {
- iniTtensority()
-
cp, _ := vmutil.DefaultCoinbaseProgram()
parent := &state.BlockNode{
Version: 1,
Height: 0,
Timestamp: 1523352600,
Hash: bc.Hash{V0: 0},
- Seed: &bc.Hash{V1: 1},
- Bits: 2305843009214532812,
}
block := &bc.Block{
ID: bc.Hash{V0: 1},
Height: 1,
Timestamp: 1523352601,
PreviousBlockId: &bc.Hash{V0: 0},
- Bits: 2305843009214532812,
TransactionsRoot: &bc.Hash{V0: 1},
},
Transactions: []*bc.Tx{
// TestSetTransactionStatus verify the transaction status is set correctly (blocktest#1010)
func TestSetTransactionStatus(t *testing.T) {
- iniTtensority()
-
cp, _ := vmutil.DefaultCoinbaseProgram()
parent := &state.BlockNode{
Version: 1,
Height: 0,
Timestamp: 1523352600,
Hash: bc.Hash{V0: 0},
- Seed: &bc.Hash{V1: 1},
- Bits: 2305843009214532812,
}
block := &bc.Block{
ID: bc.Hash{V0: 1},
Height: 1,
Timestamp: 1523352601,
PreviousBlockId: &bc.Hash{V0: 0},
- Bits: 2305843009214532812,
TransactionsRoot: &bc.Hash{V0: 3413931728524254295, V1: 300490676707850231, V2: 1886132055969225110, V3: 10216139531293906088},
TransactionStatusHash: &bc.Hash{V0: 8682965660674182538, V1: 8424137560837623409, V2: 6979974817894224946, V3: 4673809519342015041},
},
}
}
}
-
-func iniTtensority() {
- // 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)
-}