-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_helpers.go
67 lines (50 loc) · 1.31 KB
/
test_helpers.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
package tests
// ----- ---- --- -- -
// Copyright 2019, 2020 The Axiom Foundation. All Rights Reserved.
//
// Licensed under the Apache License 2.0 (the "License"). You may not use
// this file except in compliance with the License. You can obtain a copy
// in the file LICENSE in the source distribution or at
// https://www.apache.org/licenses/LICENSE-2.0.txt
// - -- --- ---- -----
import (
"encoding/binary"
"fmt"
tx "github.com/ndau/metanode/pkg/meta/transaction"
)
//go:generate msgp -tests=0
// set up some example structs which implement Transactable
// the goal is to ensure that serialization and deserialization
// all work as expected
var _ tx.Transactable = (*Stringy)(nil)
type Stringy struct {
S string
}
func (Stringy) Validate(interface{}) error {
return nil
}
func (Stringy) Apply(interface{}) error {
return nil
}
func (s Stringy) SignableBytes() []byte {
return []byte(s.S)
}
var _ tx.Transactable = (*Inty)(nil)
type Inty struct {
I int
}
func (Inty) Validate(interface{}) error {
return fmt.Errorf("Intys are never valid")
}
func (Inty) Apply(interface{}) error {
return nil
}
func (i Inty) SignableBytes() []byte {
bytes := make([]byte, 8)
binary.BigEndian.PutUint64(bytes, uint64(i.I))
return bytes
}
var Tmap = map[tx.TxID]tx.Transactable{
tx.TxID(1): &Stringy{},
tx.TxID(2): &Inty{},
}