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

Function TestHandleMessageStake

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

Source from the content-addressed store, hash-verified

700}
701
702func TestHandleMessageStake(t *testing.T) {
703 tests := []struct {
704 name string
705 detail string
706 presetSender uint64
707 presetValidator bool
708 msg *MessageStake
709 expected *Validator
710 error string
711 }{
712 {
713 name: "invalid public key",
714 detail: "the sender public key is invalid",
715 msg: &MessageStake{PublicKey: newTestAddressBytes(t)},
716 error: "public key is invalid",
717 },
718 {
719 name: "invalid net address",
720 detail: "the validator net address is invalid",
721 msg: &MessageStake{PublicKey: newTestPublicKeyBytes(t)},
722 expected: &Validator{Address: newTestAddressBytes(t)},
723 presetValidator: true,
724 error: "net address has invalid length",
725 },
726 {
727 name: "validator already exists",
728 detail: "the validator already exists in state",
729 msg: &MessageStake{PublicKey: newTestPublicKeyBytes(t), NetAddress: "tcp://example.com"},
730 expected: &Validator{Address: newTestAddressBytes(t), NetAddress: "tcp://example.com"},
731 presetValidator: true,
732 error: "validator exists",
733 },
734 {
735 name: "insufficient amount",
736 detail: "the sender doesn't have enough tokens",
737 presetSender: 0,
738 msg: &MessageStake{
739 PublicKey: newTestPublicKeyBytes(t),
740 NetAddress: "tcp://example.com",
741 Amount: 1,
742 },
743 error: "insufficient funds",
744 },
745 {
746 name: "stake all funds as committee member",
747 detail: "the sender stakes all funds as committee member",
748 presetSender: 1,
749 msg: &MessageStake{
750 PublicKey: newTestPublicKeyBytes(t),
751 Amount: 1,
752 Committees: []uint64{0, 1},
753 NetAddress: "tcp://example.com",
754 OutputAddress: newTestAddressBytes(t, 1),
755 Delegate: false,
756 Compound: true,
757 Signer: newTestAddressBytes(t),
758 },
759 expected: &Validator{

Callers

nothing calls this directly

Calls 15

NewPublicKeyFromBytesFunction · 0.92
newTestStateMachineFunction · 0.85
RunMethod · 0.80
AccountAddMethod · 0.80
SetValidatorMethod · 0.80
HandleMessageStakeMethod · 0.80
EqualMethod · 0.80
GetAccountMethod · 0.80
GetDelegatesPaginatedMethod · 0.80
GetCommitteePaginatedMethod · 0.80

Tested by

no test coverage detected