This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
forked from 0xPolygon/polygon-edge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmock_test.go
91 lines (68 loc) · 1.88 KB
/
mock_test.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package txpool
import (
"fmt"
"math/big"
"github.com/0xPolygon/polygon-edge/types"
)
var mockHeader = &types.Header{
GasLimit: 4712388,
}
/* MOCK */
type defaultMockStore struct {
DefaultHeader *types.Header
getBlockByHashFn func(types.Hash, bool) (*types.Block, bool)
calculateBaseFeeFn func(*types.Header) uint64
nonce uint64
}
func NewDefaultMockStore(header *types.Header) defaultMockStore {
return defaultMockStore{
DefaultHeader: header,
calculateBaseFeeFn: func(h *types.Header) uint64 {
return h.BaseFee
},
}
}
func (m defaultMockStore) Header() *types.Header {
return m.DefaultHeader
}
func (m defaultMockStore) GetNonce(types.Hash, types.Address) uint64 {
return m.nonce
}
func (m defaultMockStore) GetBlockByHash(hash types.Hash, full bool) (*types.Block, bool) {
if m.getBlockByHashFn != nil {
return m.getBlockByHashFn(hash, full)
}
return nil, false
}
func (m defaultMockStore) GetBalance(types.Hash, types.Address) (*big.Int, error) {
balance := big.NewInt(0).SetUint64(100000000000000)
return balance, nil
}
func (m defaultMockStore) CalculateBaseFee(header *types.Header) uint64 {
if m.calculateBaseFeeFn != nil {
return m.calculateBaseFeeFn(header)
}
return 0
}
type faultyMockStore struct {
}
func (fms faultyMockStore) Header() *types.Header {
return &types.Header{}
}
func (fms faultyMockStore) GetNonce(root types.Hash, addr types.Address) uint64 {
return 99999
}
func (fms faultyMockStore) GetBlockByHash(hash types.Hash, b bool) (*types.Block, bool) {
return nil, false
}
func (fms faultyMockStore) GetBalance(root types.Hash, addr types.Address) (*big.Int, error) {
return nil, fmt.Errorf("unable to fetch account state")
}
func (fms faultyMockStore) CalculateBaseFee(*types.Header) uint64 {
return 0
}
type mockSigner struct {
}
func (s *mockSigner) Sender(tx *types.Transaction) (types.Address, error) {
return tx.From, nil
}