MCPcopy
hub / github.com/canopy-network/canopy / TestHandleMessage

Function TestHandleMessage

fsm/message_test.go:10–381  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestHandleMessage(t *testing.T) {
11 const amount = uint64(100)
12 // pre-create a 'change parameter' proposal to use during testing
13 a, err := lib.NewAny(&lib.StringWrapper{Value: NewProtocolVersion(3, 2)})
14 require.NoError(t, err)
15 msgChangeParam := &MessageChangeParameter{
16 ParameterSpace: "cons",
17 ParameterKey: ParamProtocolVersion,
18 ParameterValue: a,
19 StartHeight: 1,
20 EndHeight: 2,
21 Signer: newTestAddressBytes(t),
22 }
23 // run test cases
24 tests := []struct {
25 name string
26 detail string
27 preset func(sm StateMachine) // required state pre-set for message to be accepted
28 msg lib.MessageI
29 validate func(sm StateMachine) // 'very basic' validation that the correct message was handled
30 error string
31 }{
32 {
33 name: "message send",
34 detail: "basic 'happy path' handling for message send",
35 preset: func(sm StateMachine) {
36 require.NoError(t, sm.AccountAdd(newTestAddress(t), 100))
37 },
38 msg: &MessageSend{
39 FromAddress: newTestAddressBytes(t),
40 ToAddress: newTestAddressBytes(t, 1),
41 Amount: amount,
42 },
43 validate: func(sm StateMachine) {
44 // ensure the sender account was subtracted from
45 got, e := sm.GetAccountBalance(newTestAddress(t))
46 require.NoError(t, e)
47 require.Zero(t, got)
48 // ensure the receiver account was added to
49 got, e = sm.GetAccountBalance(newTestAddress(t, 1))
50 require.NoError(t, e)
51 require.Equal(t, amount, got)
52 },
53 },
54 {
55 name: "message stake",
56 detail: "basic 'happy path' handling for message stake",
57 preset: func(sm StateMachine) {
58 require.NoError(t, sm.AccountAdd(newTestAddress(t), 100))
59 },
60 msg: &MessageStake{
61 PublicKey: newTestPublicKeyBytes(t),
62 Amount: amount,
63 Committees: []uint64{lib.CanopyChainId},
64 NetAddress: "tcp://example.com",
65 OutputAddress: newTestAddressBytes(t),
66 Delegate: false,
67 Compound: false,

Callers

nothing calls this directly

Calls 15

NewAnyFunction · 0.92
NewAddressFunction · 0.92
NewProtocolVersionFunction · 0.85
newTestStateMachineFunction · 0.85
AccountAddMethod · 0.80
GetAccountBalanceMethod · 0.80
EqualMethod · 0.80
GetValidatorExistsMethod · 0.80
AddToTotalSupplyMethod · 0.80
AddToStakedSupplyMethod · 0.80
SetValidatorMethod · 0.80
SetCommitteesMethod · 0.80

Tested by

no test coverage detected