(t *testing.T)
| 412 | } |
| 413 | |
| 414 | func TestAddEvent(t *testing.T) { |
| 415 | tests := []struct { |
| 416 | name string |
| 417 | detail string |
| 418 | eventType lib.EventType |
| 419 | msg proto.Message |
| 420 | address []byte |
| 421 | chainId []uint64 |
| 422 | error string |
| 423 | }{ |
| 424 | { |
| 425 | name: "valid event with chain id", |
| 426 | detail: "successfully adds an event with chain id", |
| 427 | eventType: lib.EventTypeReward, |
| 428 | msg: &lib.EventReward{Amount: 100}, |
| 429 | address: newTestAddressBytes(t), |
| 430 | chainId: []uint64{1}, |
| 431 | }, |
| 432 | { |
| 433 | name: "valid event without chain id", |
| 434 | detail: "successfully adds an event without chain id", |
| 435 | eventType: lib.EventTypeSlash, |
| 436 | msg: &lib.EventSlash{Amount: 50}, |
| 437 | address: newTestAddressBytes(t), |
| 438 | chainId: nil, |
| 439 | }, |
| 440 | } |
| 441 | for _, test := range tests { |
| 442 | t.Run(test.name, func(t *testing.T) { |
| 443 | // create a state machine instance with default parameters |
| 444 | sm := newTestStateMachine(t) |
| 445 | // execute the function call |
| 446 | err := sm.addEvent(test.eventType, test.msg, test.address, test.chainId...) |
| 447 | // validate the expected error |
| 448 | require.Equal(t, test.error != "", err != nil, err) |
| 449 | if err != nil { |
| 450 | require.ErrorContains(t, err, test.error) |
| 451 | return |
| 452 | } |
| 453 | // verify event was added |
| 454 | events := sm.events.Events |
| 455 | require.Len(t, events, 1) |
| 456 | require.Equal(t, string(test.eventType), events[0].EventType) |
| 457 | require.Equal(t, test.address, events[0].Address) |
| 458 | require.Equal(t, sm.Height(), events[0].Height) |
| 459 | if len(test.chainId) > 0 { |
| 460 | require.Equal(t, test.chainId[0], events[0].ChainId) |
| 461 | } else { |
| 462 | require.Equal(t, uint64(0), events[0].ChainId) |
| 463 | } |
| 464 | }) |
| 465 | } |
| 466 | } |
nothing calls this directly
no test coverage detected