(t *testing.T)
| 700 | } |
| 701 | |
| 702 | func 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{ |
nothing calls this directly
no test coverage detected