-
Notifications
You must be signed in to change notification settings - Fork 16
/
mock.go
45 lines (37 loc) · 1.14 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
package wallet
import (
"context"
"github.com/tonkeeper/tongo/tlb"
"github.com/tonkeeper/tongo/ton"
)
// SimpleMockBlockchain
// Very simple mock. It does not provide blockchain logic for calculating state and seqno for different addresses.
// Only for internal tests and demonstration purposes.
type SimpleMockBlockchain struct {
seqno uint32
state tlb.ShardAccount
messages chan []byte
}
func NewMockBlockchain(seqno uint32, state tlb.ShardAccount) (*SimpleMockBlockchain, chan []byte) {
c := make(chan []byte, 100)
return &SimpleMockBlockchain{
seqno: seqno,
state: state,
messages: c,
}, c
}
func (b *SimpleMockBlockchain) GetSeqno(ctx context.Context, account ton.AccountID) (uint32, error) {
return b.seqno, nil
}
func (b *SimpleMockBlockchain) SendMessage(ctx context.Context, payload []byte) (uint32, error) {
select {
case b.messages <- payload:
default:
}
b.seqno++ // it does not check message, address and seqno logic
// it does not modify account state
return 0, nil
}
func (b *SimpleMockBlockchain) GetAccountState(ctx context.Context, accountID ton.AccountID) (tlb.ShardAccount, error) {
return b.state, nil
}