(t *testing.T)
| 8 | ) |
| 9 | |
| 10 | func 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, |
nothing calls this directly
no test coverage detected