-
Notifications
You must be signed in to change notification settings - Fork 47
/
mock.go
71 lines (57 loc) · 1.96 KB
/
mock.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT License was not distributed with this
// file, you can obtain one at https://opensource.org/licenses/MIT.
//
// Copyright (c) DUSK NETWORK. All rights reserved.
package chain
import (
"github.com/dusk-network/dusk-blockchain/pkg/core/data/block"
)
// MockVerifier is a mock for the chain.Verifier interface.
type MockVerifier struct{}
// SanityCheckBlockchain on first N blocks and M last blocks.
func (v *MockVerifier) SanityCheckBlockchain(uint64, uint64) error {
return nil
}
// SanityCheckBlock will verify whether a block is valid according to the rules of the consensus.
func (v *MockVerifier) SanityCheckBlock(prevBlock block.Block, blk block.Block) error {
return nil
}
// MockLoader is the mock of the DB loader to help testing the chain.
type MockLoader struct {
blockchain []block.Block
}
// NewMockLoader creates a Mockup of the Loader interface.
func NewMockLoader() Loader {
mockchain := make([]block.Block, 0)
return &MockLoader{mockchain}
}
// Height returns the height currently known by the Loader.
func (m *MockLoader) Height() (uint64, error) {
return uint64(len(m.blockchain)), nil
}
// LoadTip of the chain.
func (m *MockLoader) LoadTip() (*block.Block, []byte, error) {
return &m.blockchain[len(m.blockchain)], nil, nil
}
// SanityCheckBlockchain on first N blocks and M last blocks.
func (m *MockLoader) SanityCheckBlockchain(uint64, uint64, uint64) error {
return nil
}
// Clear the mock.
func (m *MockLoader) Clear() error {
return nil
}
// Close the mock.
func (m *MockLoader) Close(driver string) error {
return nil
}
// Append the block to the internal blockchain representation.
func (m *MockLoader) Append(blk *block.Block) error {
m.blockchain = append(m.blockchain, *blk)
return nil
}
// BlockAt the block to the internal blockchain representation.
func (m *MockLoader) BlockAt(index uint64) (block.Block, error) {
return m.blockchain[index], nil
}