diff --git a/ledger/common/certs.go b/ledger/common/certs.go index 43c7cf7a..7165bf0f 100644 --- a/ledger/common/certs.go +++ b/ledger/common/certs.go @@ -117,6 +117,7 @@ type Certificate interface { isCertificate() Cbor() []byte Utxorpc() *utxorpc.Certificate + Type() uint } const ( @@ -177,6 +178,10 @@ func (c *StakeRegistrationCertificate) Utxorpc() *utxorpc.Certificate { } } +func (c *StakeRegistrationCertificate) Type() uint { + return c.CertType +} + type StakeDeregistrationCertificate struct { cbor.StructAsArray cbor.DecodeStoreCbor @@ -198,6 +203,10 @@ func (c *StakeDeregistrationCertificate) Utxorpc() *utxorpc.Certificate { } } +func (c *StakeDeregistrationCertificate) Type() uint { + return c.CertType +} + type StakeDelegationCertificate struct { cbor.StructAsArray cbor.DecodeStoreCbor @@ -223,6 +232,10 @@ func (c *StakeDelegationCertificate) Utxorpc() *utxorpc.Certificate { } } +func (c *StakeDelegationCertificate) Type() uint { + return c.CertType +} + type ( PoolKeyHash Blake2b224 PoolMetadataHash Blake2b256 @@ -373,6 +386,10 @@ func (c *PoolRegistrationCertificate) Utxorpc() *utxorpc.Certificate { } } +func (c *PoolRegistrationCertificate) Type() uint { + return c.CertType +} + type PoolRetirementCertificate struct { cbor.StructAsArray cbor.DecodeStoreCbor @@ -398,6 +415,10 @@ func (c *PoolRetirementCertificate) Utxorpc() *utxorpc.Certificate { } } +func (c *PoolRetirementCertificate) Type() uint { + return c.CertType +} + type GenesisKeyDelegationCertificate struct { cbor.StructAsArray cbor.DecodeStoreCbor @@ -425,6 +446,10 @@ func (c *GenesisKeyDelegationCertificate) Utxorpc() *utxorpc.Certificate { } } +func (c *GenesisKeyDelegationCertificate) Type() uint { + return c.CertType +} + type MirSource int32 const ( @@ -508,6 +533,10 @@ func (c *MoveInstantaneousRewardsCertificate) Utxorpc() *utxorpc.Certificate { } } +func (c *MoveInstantaneousRewardsCertificate) Type() uint { + return c.CertType +} + type RegistrationCertificate struct { cbor.StructAsArray cbor.DecodeStoreCbor @@ -529,6 +558,10 @@ func (c *RegistrationCertificate) Utxorpc() *utxorpc.Certificate { return nil } +func (c *RegistrationCertificate) Type() uint { + return c.CertType +} + type DeregistrationCertificate struct { cbor.StructAsArray cbor.DecodeStoreCbor @@ -550,6 +583,10 @@ func (c *DeregistrationCertificate) Utxorpc() *utxorpc.Certificate { return nil } +func (c *DeregistrationCertificate) Type() uint { + return c.CertType +} + type VoteDelegationCertificate struct { cbor.StructAsArray cbor.DecodeStoreCbor @@ -571,6 +608,10 @@ func (c *VoteDelegationCertificate) Utxorpc() *utxorpc.Certificate { return nil } +func (c *VoteDelegationCertificate) Type() uint { + return c.CertType +} + type StakeVoteDelegationCertificate struct { cbor.StructAsArray cbor.DecodeStoreCbor @@ -593,6 +634,10 @@ func (c *StakeVoteDelegationCertificate) Utxorpc() *utxorpc.Certificate { return nil } +func (c *StakeVoteDelegationCertificate) Type() uint { + return c.CertType +} + type StakeRegistrationDelegationCertificate struct { cbor.StructAsArray cbor.DecodeStoreCbor @@ -615,6 +660,10 @@ func (c *StakeRegistrationDelegationCertificate) Utxorpc() *utxorpc.Certificate return nil } +func (c *StakeRegistrationDelegationCertificate) Type() uint { + return c.CertType +} + type VoteRegistrationDelegationCertificate struct { cbor.StructAsArray cbor.DecodeStoreCbor @@ -637,6 +686,10 @@ func (c *VoteRegistrationDelegationCertificate) Utxorpc() *utxorpc.Certificate { return nil } +func (c *VoteRegistrationDelegationCertificate) Type() uint { + return c.CertType +} + type StakeVoteRegistrationDelegationCertificate struct { cbor.StructAsArray cbor.DecodeStoreCbor @@ -660,6 +713,10 @@ func (c *StakeVoteRegistrationDelegationCertificate) Utxorpc() *utxorpc.Certific return nil } +func (c *StakeVoteRegistrationDelegationCertificate) Type() uint { + return c.CertType +} + type AuthCommitteeHotCertificate struct { cbor.StructAsArray cbor.DecodeStoreCbor @@ -681,6 +738,10 @@ func (c *AuthCommitteeHotCertificate) Utxorpc() *utxorpc.Certificate { return nil } +func (c *AuthCommitteeHotCertificate) Type() uint { + return c.CertType +} + type ResignCommitteeColdCertificate struct { cbor.StructAsArray cbor.DecodeStoreCbor @@ -702,6 +763,10 @@ func (c *ResignCommitteeColdCertificate) Utxorpc() *utxorpc.Certificate { return nil } +func (c *ResignCommitteeColdCertificate) Type() uint { + return c.CertType +} + type RegistrationDrepCertificate struct { cbor.StructAsArray cbor.DecodeStoreCbor @@ -724,6 +789,10 @@ func (c *RegistrationDrepCertificate) Utxorpc() *utxorpc.Certificate { return nil } +func (c *RegistrationDrepCertificate) Type() uint { + return c.CertType +} + type DeregistrationDrepCertificate struct { cbor.StructAsArray cbor.DecodeStoreCbor @@ -745,6 +814,10 @@ func (c *DeregistrationDrepCertificate) Utxorpc() *utxorpc.Certificate { return nil } +func (c *DeregistrationDrepCertificate) Type() uint { + return c.CertType +} + type UpdateDrepCertificate struct { cbor.StructAsArray cbor.DecodeStoreCbor @@ -765,3 +838,7 @@ func (c *UpdateDrepCertificate) Utxorpc() *utxorpc.Certificate { // TODO (#850) return nil } + +func (c *UpdateDrepCertificate) Type() uint { + return c.CertType +} diff --git a/ledger/common/common_test.go b/ledger/common/common_test.go index ffc152e6..b76fdbde 100644 --- a/ledger/common/common_test.go +++ b/ledger/common/common_test.go @@ -243,3 +243,42 @@ func TestBlake2b224_String(t *testing.T) { t.Errorf("expected %s but got %s", expected, hash.String()) } } + +func TestCertificateTypeMethods(t *testing.T) { + tests := []struct { + name string + cert Certificate + expected uint + }{ + {"StakeRegistration", &StakeRegistrationCertificate{CertType: CertificateTypeStakeRegistration}, CertificateTypeStakeRegistration}, + {"StakeDeregistration", &StakeDeregistrationCertificate{CertType: CertificateTypeStakeDeregistration}, CertificateTypeStakeDeregistration}, + {"StakeDelegation", &StakeDelegationCertificate{CertType: CertificateTypeStakeDelegation}, CertificateTypeStakeDelegation}, + {"PoolRegistration", &PoolRegistrationCertificate{CertType: CertificateTypePoolRegistration}, CertificateTypePoolRegistration}, + {"PoolRetirement", &PoolRetirementCertificate{CertType: CertificateTypePoolRetirement}, CertificateTypePoolRetirement}, + {"GenesisKeyDelegation", &GenesisKeyDelegationCertificate{CertType: CertificateTypeGenesisKeyDelegation}, CertificateTypeGenesisKeyDelegation}, + {"MoveInstantaneousRewards", &MoveInstantaneousRewardsCertificate{CertType: CertificateTypeMoveInstantaneousRewards}, CertificateTypeMoveInstantaneousRewards}, + {"Registration", &RegistrationCertificate{CertType: CertificateTypeRegistration}, CertificateTypeRegistration}, + {"Deregistration", &DeregistrationCertificate{CertType: CertificateTypeDeregistration}, CertificateTypeDeregistration}, + {"VoteDelegation", &VoteDelegationCertificate{CertType: CertificateTypeVoteDelegation}, CertificateTypeVoteDelegation}, + {"StakeVoteDelegation", &StakeVoteDelegationCertificate{CertType: CertificateTypeStakeVoteDelegation}, CertificateTypeStakeVoteDelegation}, + {"StakeRegistrationDelegation", &StakeRegistrationDelegationCertificate{CertType: CertificateTypeStakeRegistrationDelegation}, CertificateTypeStakeRegistrationDelegation}, + {"VoteRegistrationDelegation", &VoteRegistrationDelegationCertificate{CertType: CertificateTypeVoteRegistrationDelegation}, CertificateTypeVoteRegistrationDelegation}, + {"StakeVoteRegistrationDelegation", &StakeVoteRegistrationDelegationCertificate{CertType: CertificateTypeStakeVoteRegistrationDelegation}, CertificateTypeStakeVoteRegistrationDelegation}, + {"AuthCommitteeHot", &AuthCommitteeHotCertificate{CertType: CertificateTypeAuthCommitteeHot}, CertificateTypeAuthCommitteeHot}, + {"ResignCommitteeCold", &ResignCommitteeColdCertificate{CertType: CertificateTypeResignCommitteeCold}, CertificateTypeResignCommitteeCold}, + {"RegistrationDrep", &RegistrationDrepCertificate{CertType: CertificateTypeRegistrationDrep}, CertificateTypeRegistrationDrep}, + {"DeregistrationDrep", &DeregistrationDrepCertificate{CertType: CertificateTypeDeregistrationDrep}, CertificateTypeDeregistrationDrep}, + {"UpdateDrep", &UpdateDrepCertificate{CertType: CertificateTypeUpdateDrep}, CertificateTypeUpdateDrep}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := tt.cert.Type() + if got != tt.expected { + t.Errorf("FAIL: %s -> Type() = %d, expected = %d", tt.name, got, tt.expected) + } else { + t.Logf("PASS: %s -> Type() = %d, expected = %d \n", tt.name, got, tt.expected) + } + }) + } +}