/
test.go
65 lines (51 loc) · 1.7 KB
/
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
// Provide test utilities for the common package
package common
import (
"reflect"
"testing"
"github.com/ethereum/go-ethereum/rlp"
"github.com/stretchr/testify/require"
)
// Initialize a new config object for unittests
func NewTestConfig() Config {
p := Config{}
p.TimeoutINIT = DefaultTimeoutINIT
p.TimeoutSIGN = DefaultTimeoutSIGN
p.TimeoutACCEPT = DefaultTimeoutACCEPT
p.TimeoutALLCONFIRM = DefaultTimeoutALLCONFIRM
p.BlockTime = 0
p.BlockTimeDelta = DefaultBlockTimeDelta
p.TxsLimit = DefaultTransactionsInBallotLimit
p.OpsLimit = DefaultOperationsInTransactionLimit
p.OpsInBallotLimit = DefaultOperationsInBallotLimit
p.NetworkID = []byte("sebak-unittest")
p.InitialBalance = MaximumBalance
p.TxPoolClientLimit = DefaultTxPoolLimit
p.TxPoolNodeLimit = 0 // unlimited
p.RateLimitRuleAPI = NewRateLimitRule(RateLimitAPI)
p.RateLimitRuleNode = NewRateLimitRule(RateLimitNode)
p.HTTPCachePoolSize = HTTPCachePoolSize
return p
}
// Test that a record that gets serialized to RLP deserialize to the same data
//
// Params:
// t = The testing object
// record = A pointer to the record to serialize
func CheckRoundTripRLP(t *testing.T, record interface{}) {
binary, err := rlp.EncodeToBytes(record)
require.NoError(t, err)
result := reflect.New(reflect.TypeOf(record))
err = rlp.DecodeBytes(binary, result.Interface())
require.NoError(t, err)
require.Equal(t, record, result.Elem().Interface())
require.Equal(t, MustMakeObjectHash(record), MustMakeObjectHash(result.Elem().Interface()))
}
// Utility to get a new `common.Endpoint` from a string
func MustParseEndpoint(endpoint string) *Endpoint {
if ret, err := ParseEndpoint(endpoint); err != nil {
panic(err)
} else {
return ret
}
}